Merge pull request #177 from yenatch/split-main

split out a bunch of bank 0 from main.asm
This commit is contained in:
Bryan Bishop 2013-08-30 13:06:57 -07:00
commit 9152664ca5
14 changed files with 3027 additions and 2683 deletions

431
engine/copy.asm Normal file
View File

@ -0,0 +1,431 @@
; Functions to copy data from ROM.
Functiondc9: ; dc9
ld a, [rLCDC]
bit 7, a
jp z, Copy2bpp
ld a, [hROMBank]
push af
ld a, BANK(Function104284)
rst Bankswitch
call Function104284
pop af
rst Bankswitch
ret
; ddc
Functionddc: ; ddc
ld a, [rLCDC]
bit 7, a
jp z, Copy1bpp
ld a, [hROMBank]
push af
ld a, BANK(Function1042b2)
rst Bankswitch
call Function1042b2
pop af
rst Bankswitch
ret
; def
Functiondef: ; def
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call FarCopyBytesDouble
pop af
rst Bankswitch
ret
; dfd
Functiondfd: ; dfd
dec c
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
.asm_e09
ld a, d
ld [rHDMA1], a
ld a, e
and $f0
ld [rHDMA2], a
ld a, h
and $1f
ld [rHDMA3], a
ld a, l
and $f0
ld [rHDMA4], a
ld a, c
cp $8
jr c, .asm_e3c
sub $8
ld c, a
ld a, $f
ld [hDMATransfer], a
call DelayFrame
ld a, l
add $0
ld l, a
ld a, h
adc $1
ld h, a
ld a, e
add $0
ld e, a
ld a, d
adc $1
ld d, a
jr .asm_e09
.asm_e3c
ld a, c
and $7f
ld [hDMATransfer], a
call DelayFrame
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
; e4a
Functione4a: ; e4a
ld a, $5
ld hl, $4135
rst FarCall
ret
; e51
Functione51: ; e51
ld a, $3e
ld hl, $7449
rst FarCall
ret
; e58
Functione58: ; e58
ld a, $3e
ld hl, $74be
rst FarCall
ret
; e5f
Functione5f: ; e5f
ld a, $3e
ld hl, $748a
rst FarCall
ld a, $3e
ld hl, $74b0
rst FarCall
ret
; e6c
Functione6c: ; e6c
ld a, $3e
ld hl, $74b0
rst FarCall
ret
; e73
Functione73: ; e73
push de
ld a, $0
call GetSRAMBank
push bc
ld de, $a000
ld a, b
call FarDecompress
pop bc
pop hl
ld de, $a000
call Request2bpp
call CloseSRAM
ret
; e8d
FarCopyBytes: ; e8d
; copy bc bytes from a:hl to de
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call CopyBytes
pop af
rst Bankswitch
ret
; 0xe9b
FarCopyBytesDouble: ; e9b
; Copy bc bytes from a:hl to bc*2 bytes at de,
; doubling each byte in the process.
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
; switcheroo, de <> hl
ld a, h
ld h, d
ld d, a
ld a, l
ld l, e
ld e, a
inc b
inc c
jr .dec
.loop
ld a, [de]
inc de
ld [hli], a
ld [hli], a
.dec
dec c
jr nz, .loop
dec b
jr nz, .loop
pop af
rst Bankswitch
ret
; 0xeba
Request2bpp: ; eba
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
ld a, [$ffd3]
push af
ld a, $8
ld [$ffd3], a
ld a, [InLinkBattle]
cp $4
jr nz, .asm_edc
ld a, [$ffe9]
and a
jr nz, .asm_edc
ld a, $6
ld [$ffd3], a
.asm_edc
ld a, e
ld [$cf68], a
ld a, d
ld [$cf69], a
ld a, l
ld [$cf6a], a
ld a, h
ld [$cf6b], a
.asm_eec
ld a, c
ld hl, $ffd3
cp [hl]
jr nc, .asm_f08
ld [$cf67], a
.wait
call DelayFrame
ld a, [$cf67]
and a
jr nz, .wait
pop af
ld [$ffd3], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.asm_f08
ld a, [$ffd3]
ld [$cf67], a
.asm_f0d
call DelayFrame
ld a, [$cf67]
and a
jr nz, .asm_f0d
ld a, c
ld hl, $ffd3
sub [hl]
ld c, a
jr .asm_eec
; f1e
Request1bpp: ; f1e
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
ld a, [$ffd3]
push af
ld a, $8
ld [$ffd3], a
ld a, [InLinkBattle]
cp $4
jr nz, .asm_f40
ld a, [$ffe9]
and a
jr nz, .asm_f40
ld a, $6
ld [$ffd3], a
.asm_f40
ld a, e
ld [$cf6d], a
ld a, d
ld [$cf6e], a
ld a, l
ld [$cf6f], a
ld a, h
ld [$cf70], a
.asm_f50
ld a, c
ld hl, $ffd3
cp [hl]
jr nc, .asm_f6c
ld [$cf6c], a
.wait
call DelayFrame
ld a, [$cf6c]
and a
jr nz, .wait
pop af
ld [$ffd3], a
pop af
rst Bankswitch
pop af
ld [hBGMapMode], a
ret
.asm_f6c
ld a, [$ffd3]
ld [$cf6c], a
.asm_f71
call DelayFrame
ld a, [$cf6c]
and a
jr nz, .asm_f71
ld a, c
ld hl, $ffd3
sub [hl]
ld c, a
jr .asm_f50
; f82
Get2bpp: ; f82
ld a, [rLCDC]
bit 7, a
jp nz, Request2bpp
Copy2bpp: ; f89
; copy c 2bpp tiles from b:de to hl
push hl
ld h, d
ld l, e
pop de
; bank
ld a, b
; bc = c * $10
push af
swap c
ld a, $f
and c
ld b, a
ld a, $f0
and c
ld c, a
pop af
jp FarCopyBytes
; f9d
Get1bpp: ; f9d
ld a, [rLCDC]
bit 7, a
jp nz, Request1bpp
Copy1bpp: ; fa4
; copy c 1bpp tiles from b:de to hl
push de
ld d, h
ld e, l
; bank
ld a, b
; bc = c * $10 / 2
push af
ld h, 0
ld l, c
add hl, hl
add hl, hl
add hl, hl
ld b, h
ld c, l
pop af
pop hl
jp FarCopyBytesDouble
; fb6

134
engine/fade.asm Normal file
View File

@ -0,0 +1,134 @@
; Functions to fade the screen in and out.
Function48c: ; 48c
ld a, [TimeOfDayPal]
ld b, a
ld hl, IncGradGBPalTable_11
ld a, l
sub b
ld l, a
jr nc, .asm_499
dec h
.asm_499
ld a, [hli]
ld [rBGP], a
ld a, [hli]
ld [rOBP0], a
ld a, [hli]
ld [rOBP1], a
ret
; 4a3
Function4a3: ; 4a3
ld a, [hCGB]
and a
jr z, .asm_4af
ld hl, IncGradGBPalTable_00
ld b, 4
jr FadeOut
.asm_4af
ld hl, IncGradGBPalTable_08
ld b, 4
jr FadeOut
; 4b6
Function4b6: ; 4b6
ld a, [hCGB]
and a
jr z, .asm_4c2
ld hl, IncGradGBPalTable_05
ld b, 3
jr FadeOut
.asm_4c2
ld hl, IncGradGBPalTable_13
ld b, 3
; 4c7
FadeOut: ; 4c7
push de
ld a, [hli]
call DmgToCgbBGPals
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
call DmgToCgbObjPals
ld c, 8
call DelayFrames
pop de
dec b
jr nz, FadeOut
ret
; 4dd
Function4dd: ; 4dd
ld a, [hCGB]
and a
jr z, .asm_4e9
ld hl, IncGradGBPalTable_04 - 1
ld b, 4
jr FadeIn
.asm_4e9
ld hl, IncGradGBPalTable_12 - 1
ld b, 4
jr FadeIn
; 4f0
Function4f0: ; 4f0
ld a, [hCGB]
and a
jr z, .asm_4fc
ld hl, IncGradGBPalTable_07 - 1
ld b, 3
jr FadeIn
.asm_4fc
ld hl, IncGradGBPalTable_15 - 1
ld b, 3
; fallthrough
; 501
FadeIn: ; 501
push de
ld a, [hld]
ld d, a
ld a, [hld]
ld e, a
call DmgToCgbObjPals
ld a, [hld]
call DmgToCgbBGPals
ld c, 8
call DelayFrames
pop de
dec b
jr nz, FadeIn
ret
; 517
; 517
IncGradGBPalTable_00: db %11111111, %11111111, %11111111
IncGradGBPalTable_01: db %11111110, %11111110, %11111110
IncGradGBPalTable_02: db %11111001, %11111001, %11111001
IncGradGBPalTable_03: db %11100100, %11100100, %11100100
IncGradGBPalTable_04: db %11100100, %11100100, %11100100
IncGradGBPalTable_05: db %10010000, %10010000, %10010000
IncGradGBPalTable_06: db %01000000, %01000000, %01000000
IncGradGBPalTable_07: db %00000000, %00000000, %00000000
; bgp obp1 obp2
IncGradGBPalTable_08: db %11111111, %11111111, %11111111
IncGradGBPalTable_09: db %11111110, %11111110, %11111000
IncGradGBPalTable_10: db %11111001, %11100100, %11100100
IncGradGBPalTable_11: db %11100100, %11010000, %11100000
IncGradGBPalTable_12: db %11100100, %11010000, %11100000
IncGradGBPalTable_13: db %10010000, %10000000, %10010000
IncGradGBPalTable_14: db %01000000, %01000000, %01000000
IncGradGBPalTable_15: db %00000000, %00000000, %00000000
; 547

View File

@ -79,7 +79,7 @@ Init: ; 17d
or c or c
jr nz, .asm_1b1 jr nz, .asm_1b1
ld sp, Stack - 1 ld sp, Stack
; Clear HRAM ; Clear HRAM
ld a, [hCGB] ld a, [hCGB]

View File

@ -273,3 +273,219 @@ StopAutoInput: ; a0a
ret ret
; a1b ; a1b
Functiona1b: ; a1b
call DelayFrame
push bc
call Functiona57
pop bc
ld a, [hJoyDown]
cp D_UP | SELECT | BUTTON_B
jr z, .asm_a34
ld a, [$ffa9]
and START | BUTTON_A
jr nz, .asm_a34
dec c
jr nz, Functiona1b
and a
ret
.asm_a34
scf
ret
; a36
Functiona36: ; a36
call DelayFrame
call GetJoypadPublic
ld a, [hJoyPressed]
and BUTTON_A | BUTTON_B
ret nz
call RTC
jr Functiona36
; a46
Functiona46: ; a46
ld a, [hOAMUpdate]
push af
ld a, 1
ld [hOAMUpdate], a
call WaitBGMap
call Functiona36
pop af
ld [hOAMUpdate], a
ret
; a57
Functiona57: ; a57
call GetJoypadPublic
ld a, [$ffaa]
and a
ld a, [hJoyPressed]
jr z, .asm_a63
ld a, [hJoyDown]
.asm_a63
ld [$ffa9], a
ld a, [hJoyPressed]
and a
jr z, .asm_a70
ld a, 15
ld [TextDelayFrames], a
ret
.asm_a70
ld a, [TextDelayFrames]
and a
jr z, .asm_a7a
xor a
ld [$ffa9], a
ret
.asm_a7a
ld a, 5
ld [TextDelayFrames], a
ret
; a80
Functiona80: ; a80
ld a, [$ffaf]
push af
ld a, [$ffb0]
push af
xor a
ld [$ffaf], a
ld a, $6
ld [$ffb0], a
.asm_a8d
push hl
ld hl, $c606
call Functionb06
pop hl
call Functiona57
ld a, [$ffa9]
and $3
jr z, .asm_a8d
pop af
ld [$ffb0], a
pop af
ld [$ffaf], a
ret
; aa5
Functionaa5: ; aa5
call Functiona57
ld a, [$ffa9]
and BUTTON_A | BUTTON_B
jr z, Functionaa5
ret
; aaf
Functionaaf: ; aaf
ld a, [InLinkBattle]
and a
jr nz, .asm_ac1
call Functionac6
push de
ld de, SFX_READ_TEXT_2
call StartSFX
pop de
ret
.asm_ac1
ld c, 65
jp DelayFrames
; ac6
Functionac6: ; ac6
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
ld a, [InputType]
or a
jr z, .asm_ad9
callba Function1de28a
.asm_ad9
call Functionaf5
call Functiona57
ld a, [hJoyPressed]
and $3
jr nz, .asm_af1
call RTC
ld a, $1
ld [hBGMapMode], a
call DelayFrame
jr .asm_ad9
.asm_af1
pop af
ld [hOAMUpdate], a
ret
; af5
Functionaf5: ; af5
ld a, [$ff9b]
and $10
jr z, .asm_aff
ld a, $ee
jr .asm_b02
.asm_aff
ld a, [$c605]
.asm_b02
ld [$c606], a
ret
; b06
Functionb06: ; b06
push bc
ld a, [hl]
ld b, a
ld a, $ee
cp b
pop bc
jr nz, .asm_b27
ld a, [$ffaf]
dec a
ld [$ffaf], a
ret nz
ld a, [$ffb0]
dec a
ld [$ffb0], a
ret nz
ld a, $7a
ld [hl], a
ld a, $ff
ld [$ffaf], a
ld a, $6
ld [$ffb0], a
ret
.asm_b27
ld a, [$ffaf]
and a
ret z
dec a
ld [$ffaf], a
ret nz
dec a
ld [$ffaf], a
ld a, [$ffb0]
dec a
ld [$ffb0], a
ret nz
ld a, $6
ld [$ffb0], a
ld a, $ee
ld [hl], a
ret
; b40

81
engine/lcd.asm Normal file
View File

@ -0,0 +1,81 @@
; LCD handling
Function547: ; 547
ld a, [hLCDStatCustom]
cp rSCX & $ff
ret nz
ld c, a
ld a, [LYOverrides]
ld [$ff00+c], a
ret
; 552
LCD: ; 552
push af
ld a, [hLCDStatCustom]
and a
jr z, .done
; At this point it's assumed we're in WRAM bank 5!
push bc
ld a, [rLY]
ld c, a
ld b, LYOverrides >> 8
ld a, [bc]
ld b, a
ld a, [hLCDStatCustom]
ld c, a
ld a, b
ld [$ff00+c], a
pop bc
.done
pop af
reti
; 568
DisableLCD: ; 568
; Turn the LCD off
; Don't need to do anything if the LCD is already off
ld a, [rLCDC]
bit 7, a ; lcd enable
ret z
xor a
ld [rIF], a
ld a, [rIE]
ld b, a
; Disable VBlank
res 0, a ; vblank
ld [rIE], a
.wait
; Wait until VBlank would normally happen
ld a, [rLY]
cp 145
jr nz, .wait
ld a, [rLCDC]
and %01111111 ; lcd enable off
ld [rLCDC], a
xor a
ld [rIF], a
ld a, b
ld [rIE], a
ret
; 58a
EnableLCD: ; 58a
ld a, [rLCDC]
set 7, a ; lcd enable
ld [rLCDC], a
ret
; 591

347
engine/palettes.asm Normal file
View File

@ -0,0 +1,347 @@
; Functions dealing with palettes.
UpdatePalsIfCGB: ; c2f
; update bgp data from BGPals
; update obp data from OBPals
; return carry if successful
; check cgb
ld a, [hCGB]
and a
ret z
UpdateCGBPals: ; c33
; return carry if successful
; any pals to update?
ld a, [hCGBPalUpdate]
and a
ret z
ForceUpdateCGBPals: ; c37
ld a, [rSVBK]
push af
ld a, 5 ; BANK(BGPals)
ld [rSVBK], a
ld hl, BGPals ; 5:d080
; copy 8 pals to bgpd
ld a, %10000000 ; auto increment, index 0
ld [rBGPI], a
ld c, rBGPD % $100
ld b, 4 ; NUM_PALS / 2
.bgp
rept $10
ld a, [hli]
ld [$ff00+c], a
endr
dec b
jr nz, .bgp
; hl is now 5:d0c0 OBPals
; copy 8 pals to obpd
ld a, %10000000 ; auto increment, index 0
ld [rOBPI], a
ld c, rOBPD - rJOYP
ld b, 4 ; NUM_PALS / 2
.obp
rept $10
ld a, [hli]
ld [$ff00+c], a
endr
dec b
jr nz, .obp
pop af
ld [rSVBK], a
; clear pal update queue
xor a
ld [hCGBPalUpdate], a
scf
ret
; c9f
DmgToCgbBGPals: ; c9f
; exists to forego reinserting cgb-converted image data
; input: a -> bgp
ld [rBGP], a
push af
ld a, [hCGB]
and a
jr z, .end
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, 5
ld [rSVBK], a
; copy & reorder bg pal buffer
ld hl, BGPals ; to
ld de, Unkn1Pals ; from
; order
ld a, [rBGP]
ld b, a
; all pals
ld c, 8
call CopyPals
; request pal update
ld a, 1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.end
pop af
ret
; ccb
DmgToCgbObjPals: ; ccb
; exists to forego reinserting cgb-converted image data
; input: d -> obp1
; e -> obp2
ld a, e
ld [rOBP0], a
ld a, d
ld [rOBP1], a
ld a, [hCGB]
and a
ret z
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, 5
ld [rSVBK], a
; copy & reorder obj pal buffer
ld hl, OBPals ; to
ld de, Unkn2Pals ; from
; order
ld a, [rOBP0]
ld b, a
; all pals
ld c, 8
call CopyPals
; request pal update
ld a, 1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
ret
; cf8
Functioncf8: ; cf8
ld [rOBP0], a
push af
ld a, [hCGB]
and a
jr z, .asm_d22
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, $5
ld [rSVBK], a
ld hl, $d0c0
ld de, MartPointer
ld a, [rOBP0]
ld b, a
ld c, $1
call CopyPals
ld a, $1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.asm_d22
pop af
ret
; d24
Functiond24: ; d24
ld [rOBP1], a
push af
ld a, [hCGB]
and a
jr z, .asm_d4e
push hl
push de
push bc
ld a, [rSVBK]
push af
ld a, $5
ld [rSVBK], a
ld hl, $d0c8
ld de, $d048
ld a, [rOBP1]
ld b, a
ld c, $1
call CopyPals
ld a, $1
ld [hCGBPalUpdate], a
pop af
ld [rSVBK], a
pop bc
pop de
pop hl
.asm_d4e
pop af
ret
; d50
CopyPals: ; d50
; copy c palettes in order b from de to hl
push bc
ld c, 4 ; NUM_PAL_COLORS
.loop
push de
push hl
; get pal color
ld a, b
and %11 ; color
; 2 bytes per color
add a
ld l, a
ld h, 0
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
; dest
pop hl
; write color
ld [hl], e
inc hl
ld [hl], d
inc hl
; next pal color
srl b
srl b
; source
pop de
; done pal?
dec c
jr nz, .loop
; de += 8 (next pal)
ld a, 8 ; NUM_PAL_COLORS * 2 ; bytes per pal
add e
jr nc, .ok
inc d
.ok
ld e, a
; how many more pals?
pop bc
dec c
jr nz, CopyPals
ret
; d79
Functiond79: ; d79
ld a, [hCGB]
and a
ret z
ld a, 1
ld [rVBK], a
ld hl, VTiles0
ld bc, $2000
xor a
call ByteFill
ld a, 0
ld [rVBK], a
ret
; d90
Functiond90: ; d90
ret
; d91
Functiond91: ; d91
ld a, [hCGB]
and a
ret z
ld a, [rSVBK]
push af
ld a, 5 ; BANK(BGPals)
ld [rSVBK], a
ld hl, BGPals
ld bc, $40 + $10
xor a
call ByteFill
pop af
ld [rSVBK], a
ld a, 1
ld [hCGBPalUpdate], a
call DelayFrame
ret
; db1
Functiondb1: ; db1
ld a, [hROMBank]
push af
ld a, BANK(Function4c000)
rst Bankswitch
call Function4c000
pop af
rst Bankswitch
ret
; dbd
Functiondbd: ; dbd
ld a, [hROMBank]
push af
ld a, BANK(Function4c03f)
rst Bankswitch
call Function4c03f
pop af
rst Bankswitch
ret
; dc9

View File

@ -308,7 +308,7 @@ Script_2writetext: ; 0x96e9b
ld h, a ld h, a
ld a, [ScriptBank] ld a, [ScriptBank]
ld b, a ld b, a
call $269a call Function269a
ret ret
; 0x96eab ; 0x96eab
@ -323,7 +323,7 @@ Script_3writetext: ; 0x96eab
ld l, a ld l, a
call GetScriptByte call GetScriptByte
ld h, a ld h, a
call $269a call Function269a
ret ret
; 0x96ebb ; 0x96ebb
@ -348,7 +348,7 @@ Script_repeattext: ; 0x96ebb
ld a, [hli] ld a, [hli]
ld h, [hl] ld h, [hl]
ld l, a ld l, a
call $269a call Function269a
ret ret
.asm_96ed8 .asm_96ed8
ret ret
@ -357,7 +357,7 @@ Script_repeattext: ; 0x96ebb
Script_closetext: ; 0x96ed9 Script_closetext: ; 0x96ed9
; script command 0x54 ; script command 0x54
jp $0a46 jp Functiona46
; 0x96edc ; 0x96edc
Script_keeptextopen: ; 0x96edc Script_keeptextopen: ; 0x96edc
@ -367,8 +367,8 @@ Script_keeptextopen: ; 0x96edc
push af push af
ld a, $1 ld a, $1
ld [$ffd8], a ld [$ffd8], a
call $31f6 call WaitBGMap
call $0aaf call Functionaaf
pop af pop af
ld [$ffd8], a ld [$ffd8], a
ret ret
@ -377,7 +377,7 @@ Script_keeptextopen: ; 0x96edc
Script_yesorno: ; 0x96eed Script_yesorno: ; 0x96eed
; script command 0x4e ; script command 0x4e
call $1dcf call Function1dcf
ld a, $0 ld a, $0
jr c, .asm_96ef6 ; 0x96ef2 $2 jr c, .asm_96ef6 ; 0x96ef2 $2
ld a, $1 ld a, $1
@ -397,16 +397,16 @@ Script_loadmenudata: ; 0x96efa
ld h, a ld h, a
ld de, $1d35 ld de, $1d35
ld a, [ScriptBank] ld a, [ScriptBank]
call $26b7 call Function26b7
call $1ad2 call Function1ad2
ret ret
; 0x96f0f ; 0x96f0f
Script_writebackup: ; 0x96f0f Script_writebackup: ; 0x96f0f
; script command 0x50 ; script command 0x50
call $1c17 call Function1c17
call $1ad2 call Function1ad2
ret ret
; 0x96f16 ; 0x96f16
@ -470,7 +470,7 @@ Script_storetext: ; 0x96f52
; pointer (PointerLabelBeforeBank) ; pointer (PointerLabelBeforeBank)
; memory (SingleByteParam) ; memory (SingleByteParam)
call $106c call Function106c
call GetScriptByte call GetScriptByte
ld c, a ld c, a
ld a, $47 ld a, $47
@ -539,7 +539,7 @@ Script_verbosegiveitem2: ; 0x96f8e
ld a, [de] ld a, [de]
ld [$d10c], a ld [$d10c], a
ld hl, $d892 ld hl, $d892
call $2f66 call Function2f66
ld a, $1 ld a, $1
jr c, .asm_96fb0 ; 0x96fad $1 jr c, .asm_96fb0 ; 0x96fad $1
xor a xor a
@ -561,7 +561,7 @@ Script_itemnotify: ; 0x96fc6
call CurItemName call CurItemName
ld b, BANK(PutItemInPocketText) ld b, BANK(PutItemInPocketText)
ld hl, PutItemInPocketText ld hl, PutItemInPocketText
call $269a call Function269a
ret ret
; 0x96fd5 ; 0x96fd5
@ -572,7 +572,7 @@ Script_pocketisfull: ; 0x96fd5
call CurItemName call CurItemName
ld b, BANK(PocketIsFullText) ld b, BANK(PocketIsFullText)
ld hl, PocketIsFullText ld hl, PocketIsFullText
call $269a call Function269a
ret ret
; 0x96fe4 ; 0x96fe4
@ -732,7 +732,7 @@ Script_askforphonenumber: ; 0x970be
; parameters: ; parameters:
; number (SingleByteParam) ; number (SingleByteParam)
call $1dcf call Function1dcf
jr c, .asm_970d6 ; 0x970c1 $13 jr c, .asm_970d6 ; 0x970c1 $13
call GetScriptByte call GetScriptByte
ld c, a ld c, a
@ -814,7 +814,7 @@ Script_trainertext: ; 0x9710f
ld l, a ld l, a
ld a, [$d03e] ld a, [$d03e]
ld b, a ld b, a
call $269a call Function269a
ret ret
; 0x97125 ; 0x97125
@ -907,7 +907,7 @@ Script_playrammusic: ; 0x9717a
Script_playmapmusic: ; 0x97185 Script_playmapmusic: ; 0x97185
; script command 0x82 ; script command 0x82
call $3cdf call Function3cdf
ret ret
; 0x97189 ; 0x97189
@ -988,7 +988,7 @@ Script_cry: ; 0x971d1
jr nz, .asm_971df ; 0x971da $3 jr nz, .asm_971df ; 0x971da $3
ld a, [$c2dd] ld a, [$c2dd]
.asm_971df .asm_971df
call $37ce call Function37ce
ret ret
; 0x971e3 ; 0x971e3
@ -1039,7 +1039,7 @@ Function971fa: ; 971fa
ld h, a ld h, a
ld a, [ScriptBank] ld a, [ScriptBank]
ld b, a ld b, a
call $26c7 call Function26c7
ret c ret c
ld a, SCRIPT_WAIT_MOVEMENT ld a, SCRIPT_WAIT_MOVEMENT
ld [ScriptMode], a ld [ScriptMode], a
@ -1145,13 +1145,13 @@ Script_spriteface: ; 0x97274
Unknown_0x9728b: ; 0x9728b Unknown_0x9728b: ; 0x9728b
ld a, d ld a, d
push de push de
call $18de call Function18de
jr c, .asm_972b9 ; 0x97290 $27 jr c, .asm_972b9 ; 0x97290 $27
ld hl, $0000 ld hl, $0000
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
push bc push bc
call $1836 call Function1836
pop bc pop bc
jr c, .asm_972b9 ; 0x9729c $1b jr c, .asm_972b9 ; 0x9729c $1b
ld hl, $0004 ld hl, $0004
@ -1160,13 +1160,13 @@ Unknown_0x9728b: ; 0x9728b
jr nz, .asm_972b9 ; 0x972a4 $13 jr nz, .asm_972b9 ; 0x972a4 $13
pop de pop de
ld a, e ld a, e
call $1af8 call Function1af8
ld hl, $d0ed ld hl, $d0ed
bit 6, [hl] bit 6, [hl]
jr nz, .asm_972b5 ; 0x972b0 $3 jr nz, .asm_972b5 ; 0x972b0 $3
call Unknown_0x972bc call Unknown_0x972bc
.asm_972b5 .asm_972b5
call $1ad2 call Function1ad2
ret ret
.asm_972b9 .asm_972b9
pop de pop de
@ -1175,7 +1175,7 @@ Unknown_0x9728b: ; 0x9728b
; 0x972bc ; 0x972bc
Unknown_0x972bc: ; 0x972bc Unknown_0x972bc: ; 0x972bc
call $217a call Function217a
ld hl, TileMap ld hl, TileMap
ld bc, $0168 ld bc, $0168
.asm_972c5 .asm_972c5
@ -1211,7 +1211,7 @@ Script_appear: ; 0x972dd
call GetScriptByte call GetScriptByte
call Unknown_0x971e3 call Unknown_0x971e3
call $1956 call Function1956
ld a, [$ffaf] ld a, [$ffaf]
ld b, $0 ld b, $0
call Unknown_0x9730b call Unknown_0x9730b
@ -1229,7 +1229,7 @@ Script_disappear: ; 0x972ee
jr nz, .asm_972fa ; 0x972f6 $2 jr nz, .asm_972fa ; 0x972f6 $2
ld a, [$ffe0] ld a, [$ffe0]
.asm_972fa .asm_972fa
call $199f call Function199f
ld a, [$ffaf] ld a, [$ffaf]
ld b, $1 ld b, $1
call Unknown_0x9730b call Unknown_0x9730b
@ -1241,7 +1241,7 @@ Script_disappear: ; 0x972ee
Unknown_0x9730b: ; 0x9730b Unknown_0x9730b: ; 0x9730b
push bc push bc
call $18d2 call GetMapObject
ld hl, $000c ld hl, $000c
add hl, bc add hl, bc
pop bc pop bc
@ -1513,7 +1513,7 @@ Script_catchtutorial: ; 0x97447
call GetScriptByte call GetScriptByte
ld [$d230], a ld [$d230], a
call $2879 call Function2879
ld a, $13 ld a, $13
ld hl, $6554 ld hl, $6554
rst $8 rst $8
@ -1559,7 +1559,7 @@ Script_reloadmap: ; 0x97491
ld a, $f3 ld a, $f3
ld [$ff9f], a ld [$ff9f], a
ld a, $1 ld a, $1
call $261b call Function261b
call StopScript call StopScript
ret ret
; 0x974a2 ; 0x974a2
@ -1835,7 +1835,7 @@ Script_priorityjump: ; 0x975aa
Script_checktriggers: ; 0x975c2 Script_checktriggers: ; 0x975c2
; script command 0x13 ; script command 0x13
call $211b call Function211b
jr z, .asm_975cb ; 0x975c5 $4 jr z, .asm_975cb ; 0x975c5 $4
ld [$c2dd], a ld [$c2dd], a
ret ret
@ -1855,7 +1855,7 @@ Script_checkmaptriggers: ; 0x975d1
ld b, a ld b, a
call GetScriptByte call GetScriptByte
ld c, a ld c, a
call $2147 call Function2147
ld a, d ld a, d
or e or e
jr z, .asm_975e5 ; 0x975de $5 jr z, .asm_975e5 ; 0x975de $5
@ -1894,7 +1894,7 @@ Script_domaptrigger: ; 0x975f5
; fallthrough ; fallthrough
Unknown_975fd: ; 0x975fd Unknown_975fd: ; 0x975fd
call $2147 call Function2147
ld a, d ld a, d
or e or e
jr z, .asm_97608 ; 0x97602 $4 jr z, .asm_97608 ; 0x97602 $4
@ -1988,7 +1988,7 @@ Script_random: ; 0x97640
ld b, a ld b, a
.asm_97653 .asm_97653
push bc push bc
call $2f8c call RNG
pop bc pop bc
ld a, [$ffe1] ld a, [$ffe1]
cp b cp b
@ -1996,7 +1996,7 @@ Script_random: ; 0x97640
jr .asm_97666 ; 0x9765d $7 jr .asm_97666 ; 0x9765d $7
.asm_9765f .asm_9765f
push bc push bc
call $2f8c call RNG
pop bc pop bc
ld a, [$ffe1] ld a, [$ffe1]
.asm_97666 .asm_97666
@ -2004,7 +2004,7 @@ Script_random: ; 0x97640
ld a, [$c2dd] ld a, [$c2dd]
ld c, a ld c, a
pop af pop af
call $3110 call SimpleDivide
ld [$c2dd], a ld [$c2dd], a
ret ret
; 0x97673 ; 0x97673
@ -2091,7 +2091,7 @@ Script_pokenamemem: ; 0x976ae
ld a, [$c2dd] ld a, [$c2dd]
.asm_976b7 .asm_976b7
ld [$d265], a ld [$d265], a
call $343b call GetPokemonName
ld de, StringBuffer1 ld de, StringBuffer1
Unknown_976c0: ; 0x976c0 Unknown_976c0: ; 0x976c0
@ -2205,7 +2205,7 @@ Script_readmoney: ; 0x97732
call Unknown_0x97861 call Unknown_0x97861
ld hl, StringBuffer1 ld hl, StringBuffer1
ld bc, $4306 ld bc, $4306
call $3198 call PrintNum
ld de, StringBuffer1 ld de, StringBuffer1
jp Unknown_976c0 jp Unknown_976c0
; 0x97747 ; 0x97747
@ -2219,7 +2219,7 @@ Script_readcoins: ; 0x97747
ld hl, StringBuffer1 ld hl, StringBuffer1
ld de, $d855 ld de, $d855
ld bc, $4206 ld bc, $4206
call $3198 call PrintNum
ld de, StringBuffer1 ld de, StringBuffer1
jp Unknown_976c0 jp Unknown_976c0
; 0x9775c ; 0x9775c
@ -2233,7 +2233,7 @@ Script_RAM2MEM: ; 0x9775c
ld de, $c2dd ld de, $c2dd
ld hl, StringBuffer1 ld hl, StringBuffer1
ld bc, $4103 ld bc, $4103
call $3198 call PrintNum
ld de, StringBuffer1 ld de, StringBuffer1
jp Unknown_976c0 jp Unknown_976c0
; 0x97771 ; 0x97771
@ -2320,7 +2320,7 @@ Script_giveitem: ; 0x977ca
call GetScriptByte call GetScriptByte
ld [$d10c], a ld [$d10c], a
ld hl, $d892 ld hl, $d892
call $2f66 call Function2f66
jr nc, .asm_977eb ; 0x977e3 $6 jr nc, .asm_977eb ; 0x977e3 $6
ld a, $1 ld a, $1
ld [$c2dd], a ld [$c2dd], a
@ -2346,7 +2346,7 @@ Script_takeitem: ; 0x977f0
ld a, $ff ld a, $ff
ld [$d107], a ld [$d107], a
ld hl, $d892 ld hl, $d892
call $2f53 call Function2f53
ret nc ret nc
ld a, $1 ld a, $1
ld [$c2dd], a ld [$c2dd], a
@ -2363,7 +2363,7 @@ Script_checkitem: ; 0x97812
call GetScriptByte call GetScriptByte
ld [$d106], a ld [$d106], a
ld hl, $d892 ld hl, $d892
call $2f79 call Function2f79
ret nc ret nc
ld a, $1 ld a, $1
ld [$c2dd], a ld [$c2dd], a
@ -2839,7 +2839,7 @@ Script_warp: ; 0x97a1d
ld a, $f1 ld a, $f1
ld [$ff9f], a ld [$ff9f], a
ld a, $1 ld a, $1
call $261b call Function261b
call StopScript call StopScript
ret ret
.asm_97a4a .asm_97a4a
@ -2851,7 +2851,7 @@ Script_warp: ; 0x97a1d
ld a, $fb ld a, $fb
ld [$ff9f], a ld [$ff9f], a
ld a, $1 ld a, $1
call $261b call Function261b
call StopScript call StopScript
ret ret
; 0x97a65 ; 0x97a65
@ -2935,8 +2935,8 @@ Script_changemap: ; 0x97ab3
ld [$d1a1], a ld [$d1a1], a
call GetScriptByte call GetScriptByte
ld [$d1a2], a ld [$d1a2], a
call $24e4 call Function24e4
call $2879 call Function2879
ret ret
; 0x97acc ; 0x97acc
@ -2953,10 +2953,10 @@ Script_changeblock: ; 0x97acc
call GetScriptByte call GetScriptByte
add $4 add $4
ld e, a ld e, a
call $2a66 call Function2a66
call GetScriptByte call GetScriptByte
ld [hl], a ld [hl], a
call $2879 call Function2879
ret ret
; 0x97ae3 ; 0x97ae3
@ -2965,19 +2965,19 @@ Script_reloadmappart: ; 0x97ae3
xor a xor a
ld [$ffd4], a ld [$ffd4], a
call $2173 call Function2173
call $2914 call Function2914
ld a, $41 ld a, $41
ld hl, $4061 ld hl, $4061
rst $8 rst $8
call $1ad2 call Function1ad2
ret ret
; 0x97af6 ; 0x97af6
Script_warpcheck: ; 0x97af6 Script_warpcheck: ; 0x97af6
; script command 0x8e ; script command 0x8e
call $224a call Function224a
ret nc ret nc
callba Function966d0 callba Function966d0
ret ret
@ -2996,7 +2996,7 @@ Script_newloadmap: ; 0x97b08
call GetScriptByte call GetScriptByte
ld [$ff9f], a ld [$ff9f], a
ld a, $1 ld a, $1
call $261b call Function261b
call StopScript call StopScript
ret ret
; 0x97b16 ; 0x97b16
@ -3011,7 +3011,7 @@ Script_reloadandreturn: ; 0x97b16
Script_loadfont: ; 0x97b1c Script_loadfont: ; 0x97b1c
; script command 0x47 ; script command 0x47
call $2e08 call Function2e08
ret ret
; 0x97b20 ; 0x97b20
@ -3020,7 +3020,7 @@ Script_refreshscreen: ; 0x97b20
; parameters: ; parameters:
; dummy (SingleByteParam) ; dummy (SingleByteParam)
call $2dba call ResetWindow
call GetScriptByte call GetScriptByte
ret ret
; 0x97b27 ; 0x97b27
@ -3043,8 +3043,8 @@ LoadMoveSpritesScript: ; 97b2e
Script_loadmovesprites: ; 0x97b2f Script_loadmovesprites: ; 0x97b2f
; script command 0x49 ; script command 0x49
call $2e20 call Function2e20
call $2dcf call Function2dcf
ret ret
; 0x97b36 ; 0x97b36
@ -3206,7 +3206,7 @@ Script_credits: ; 0x97bf3
DisplayCredits: DisplayCredits:
call Script_resetfuncs call Script_resetfuncs
ld a, $3 ld a, $3
call $261b call Function261b
call StopScript call StopScript
ret ret
; 0x97c05 ; 0x97c05

408
engine/serial.asm Normal file
View File

@ -0,0 +1,408 @@
Serial: ; 6ef
; The serial interrupt.
push af
push bc
push de
push hl
ld a, [$ffc9]
and a
jr nz, .asm_71c
ld a, [$c2d4]
bit 0, a
jr nz, .asm_721
ld a, [$ffcb]
inc a
jr z, .asm_726
ld a, [rSB]
ld [hSerialReceive], a
ld a, [hSerialSend]
ld [rSB], a
ld a, [$ffcb]
cp $2
jr z, .asm_752
ld a, 0 << rSC_ON
ld [rSC], a
ld a, 1 << rSC_ON
ld [rSC], a
jr .asm_752
.asm_71c
call Function3e80
jr .asm_75a
.asm_721
call Function2057
jr .asm_75a
.asm_726
ld a, [rSB]
cp $1
jr z, .asm_730
cp $2
jr nz, .asm_752
.asm_730
ld [hSerialReceive], a
ld [$ffcb], a
cp $2
jr z, .asm_74f
xor a
ld [rSB], a
ld a, $3
ld [rDIV], a
.asm_73f
ld a, [rDIV]
bit 7, a
jr nz, .asm_73f
ld a, 0 << rSC_ON
ld [rSC], a
ld a, 1 << rSC_ON
ld [rSC], a
jr .asm_752
.asm_74f
xor a
ld [rSB], a
.asm_752
ld a, $1
ld [$ffca], a
ld a, $fe
ld [hSerialSend], a
.asm_75a
pop hl
pop de
pop bc
pop af
reti
; 75f
Function75f: ; 75f
ld a, $1
ld [$ffcc], a
.asm_763
ld a, [hl]
ld [hSerialSend], a
call Function78a
push bc
ld b, a
inc hl
ld a, $30
.asm_76e
dec a
jr nz, .asm_76e
ld a, [$ffcc]
and a
ld a, b
pop bc
jr z, .asm_782
dec hl
cp $fd
jr nz, .asm_763
xor a
ld [$ffcc], a
jr .asm_763
.asm_782
ld [de], a
inc de
dec bc
ld a, b
or c
jr nz, .asm_763
ret
; 78a
Function78a: ; 78a
xor a
ld [$ffca], a
ld a, [$ffcb]
cp $2
jr nz, .asm_79b
ld a, $1
ld [rSC], a
ld a, $81
ld [rSC], a
.asm_79b
ld a, [$ffca]
and a
jr nz, .asm_7e5
ld a, [$ffcb]
cp $1
jr nz, .asm_7c0
call Function82b
jr z, .asm_7c0
call .asm_825
push hl
ld hl, $cf5c
inc [hl]
jr nz, .asm_7b7
dec hl
inc [hl]
.asm_7b7
pop hl
call Function82b
jr nz, .asm_79b
jp Function833
.asm_7c0
ld a, [rIE]
and $f
cp $8
jr nz, .asm_79b
ld a, [$cf5d]
dec a
ld [$cf5d], a
jr nz, .asm_79b
ld a, [$cf5e]
dec a
ld [$cf5e], a
jr nz, .asm_79b
ld a, [$ffcb]
cp $1
jr z, .asm_7e5
ld a, $ff
.asm_7e2
dec a
jr nz, .asm_7e2
.asm_7e5
xor a
ld [$ffca], a
ld a, [rIE]
and $f
sub $8
jr nz, .asm_7f8
ld [$cf5d], a
ld a, $50
ld [$cf5e], a
.asm_7f8
ld a, [hSerialReceive]
cp $fe
ret nz
call Function82b
jr z, .asm_813
push hl
ld hl, $cf5c
ld a, [hl]
dec a
ld [hld], a
inc a
jr nz, .asm_80d
dec [hl]
.asm_80d
pop hl
call Function82b
jr z, Function833
.asm_813
ld a, [rIE]
and $f
cp $8
ld a, $fe
ret z
ld a, [hl]
ld [hSerialSend], a
call DelayFrame
jp Function78a
.asm_825
ld a, $f
.asm_827
dec a
jr nz, .asm_827
ret
; 82b
Function82b: ; 82b
push hl
ld hl, $cf5b
ld a, [hli]
or [hl]
pop hl
ret
; 833
Function833: ; 833
dec a
ld [$cf5b], a
ld [$cf5c], a
ret
; 83b
Function83b: ; 83b
ld hl, $cf56
ld de, $cf51
ld c, $2
ld a, $1
ld [$ffcc], a
.asm_847
call DelayFrame
ld a, [hl]
ld [hSerialSend], a
call Function78a
ld b, a
inc hl
ld a, [$ffcc]
and a
ld a, $0
ld [$ffcc], a
jr nz, .asm_847
ld a, b
ld [de], a
inc de
dec c
jr nz, .asm_847
ret
; 862
Function862: ; 862
call Function309d
callab Function4000
call Function87d
jp Function30b4
; 871
Function871: ; 871
call Function309d
callab Function4000
jp Function87d
; 87d
Function87d: ; 87d
ld a, $ff
ld [$cf52], a
.asm_882
call Function8c1
call DelayFrame
call Function82b
jr z, .asm_89e
push hl
ld hl, $cf5c
dec [hl]
jr nz, .asm_89d
dec hl
dec [hl]
jr nz, .asm_89d
pop hl
xor a
jp Function833
.asm_89d
pop hl
.asm_89e
ld a, [$cf52]
inc a
jr z, .asm_882
ld b, $a
.asm_8a6
call DelayFrame
call Function8c1
dec b
jr nz, .asm_8a6
ld b, $a
.asm_8b1
call DelayFrame
call Function908
dec b
jr nz, .asm_8b1
ld a, [$cf52]
ld [$cf51], a
ret
; 8c1
Function8c1: ; 8c1
push bc
ld b, $60
ld a, [InLinkBattle]
cp $1
jr z, .asm_8d7
ld b, $60
jr c, .asm_8d7
cp $2
ld b, $70
jr z, .asm_8d7
ld b, $80
.asm_8d7
call Function8f3
ld a, [$cf56]
add b
ld [hSerialSend], a
ld a, [$ffcb]
cp $2
jr nz, .asm_8ee
ld a, $1
ld [rSC], a
ld a, $81
ld [rSC], a
.asm_8ee
call Function8f3
pop bc
ret
; 8f3
Function8f3: ; 8f3
ld a, [hSerialReceive]
ld [$cf51], a
and $f0
cp b
ret nz
xor a
ld [hSerialReceive], a
ld a, [$cf51]
and $f
ld [$cf52], a
ret
; 908
Function908: ; 908
xor a
ld [hSerialSend], a
ld a, [$ffcb]
cp $2
ret nz
ld a, $1
ld [rSC], a
ld a, $81
ld [rSC], a
ret
; 919
Function919: ; 919
ld a, [InLinkBattle]
and a
ret nz
ld a, $2
ld [rSB], a
xor a
ld [hSerialReceive], a
ld a, $0
ld [rSC], a
ld a, $80
ld [rSC], a
ret
; 92e

311
engine/time.asm Normal file
View File

@ -0,0 +1,311 @@
; Functions relating to the timer interrupt and the real-time-clock.
AskTimer: ; 591
push af
ld a, [$ffe9]
and a
jr z, .asm_59a
call Timer
.asm_59a
pop af
reti
; 59c
LatchClock: ; 59c
; latch clock counter data
ld a, 0
ld [MBC3LatchClock], a
ld a, 1
ld [MBC3LatchClock], a
ret
; 5a7
UpdateTime: ; 5a7
call GetClock
call FixDays
call FixTime
callba GetTimeOfDay
ret
; 5b7
GetClock: ; 5b7
; store clock data in hRTCDayHi-hRTCSeconds
; enable clock r/w
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
; clock data is 'backwards' in hram
call LatchClock
ld hl, MBC3SRamBank
ld de, MBC3RTC
ld [hl], RTC_S
ld a, [de]
and $3f
ld [hRTCSeconds], a
ld [hl], RTC_M
ld a, [de]
and $3f
ld [hRTCMinutes], a
ld [hl], RTC_H
ld a, [de]
and $1f
ld [hRTCHours], a
ld [hl], RTC_DL
ld a, [de]
ld [hRTCDayLo], a
ld [hl], RTC_DH
ld a, [de]
ld [hRTCDayHi], a
; unlatch clock / disable clock r/w
call CloseSRAM
ret
; 5e8
FixDays: ; 5e8
; fix day count
; mod by 140
; check if day count > 255 (bit 8 set)
ld a, [hRTCDayHi] ; DH
bit 0, a
jr z, .daylo
; reset dh (bit 8)
res 0, a
ld [hRTCDayHi], a ; DH
; mod 140
; mod twice since bit 8 (DH) was set
ld a, [hRTCDayLo] ; DL
.modh
sub 140
jr nc, .modh
.modl
sub 140
jr nc, .modl
add 140
; update dl
ld [hRTCDayLo], a ; DL
; unknown output
ld a, $40 ; %1000000
jr .set
.daylo
; quit if fewer than 140 days have passed
ld a, [hRTCDayLo] ; DL
cp 140
jr c, .quit
; mod 140
.mod
sub 140
jr nc, .mod
add 140
; update dl
ld [hRTCDayLo], a ; DL
; unknown output
ld a, $20 ; %100000
.set
; update clock with modded day value
push af
call SetClock
pop af
scf
ret
.quit
xor a
ret
; 61d
FixTime: ; 61d
; add ingame time (set at newgame) to current time
; day hr min sec
; store time in CurDay, hHours, hMinutes, hSeconds
; second
ld a, [hRTCSeconds] ; S
ld c, a
ld a, [StartSecond]
add c
sub 60
jr nc, .updatesec
add 60
.updatesec
ld [hSeconds], a
; minute
ccf ; carry is set, so turn it off
ld a, [hRTCMinutes] ; M
ld c, a
ld a, [StartMinute]
adc c
sub 60
jr nc, .updatemin
add 60
.updatemin
ld [hMinutes], a
; hour
ccf ; carry is set, so turn it off
ld a, [hRTCHours] ; H
ld c, a
ld a, [StartHour]
adc c
sub 24
jr nc, .updatehr
add 24
.updatehr
ld [hHours], a
; day
ccf ; carry is set, so turn it off
ld a, [hRTCDayLo] ; DL
ld c, a
ld a, [StartDay]
adc c
ld [CurDay], a
ret
; 658
Function658: ; 658
xor a
ld [StringBuffer2], a
ld a, $0
ld [$d089], a
jr .asm_677
call UpdateTime
ld a, [hHours]
ld [$d087], a
ld a, [hMinutes]
ld [$d088], a
ld a, [hSeconds]
ld [$d089], a
jr .asm_677
.asm_677
ld a, $5
ld hl, $40ed
rst FarCall
ret
; 67e
Function67e: ; 67e
call Function685
call SetClock
ret
; 685
Function685: ; 685
xor a
ld [hRTCSeconds], a
ld [hRTCMinutes], a
ld [hRTCHours], a
ld [hRTCDayLo], a
ld [hRTCDayHi], a
ret
; 691
SetClock: ; 691
; set clock data from hram
; enable clock r/w
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
; set clock data
; stored 'backwards' in hram
call LatchClock
ld hl, MBC3SRamBank
ld de, MBC3RTC
; seems to be a halt check that got partially commented out
; this block is totally pointless
ld [hl], RTC_DH
ld a, [de]
bit 6, a ; halt
ld [de], a
; seconds
ld [hl], RTC_S
ld a, [hRTCSeconds]
ld [de], a
; minutes
ld [hl], RTC_M
ld a, [hRTCMinutes]
ld [de], a
; hours
ld [hl], RTC_H
ld a, [hRTCHours]
ld [de], a
; day lo
ld [hl], RTC_DL
ld a, [hRTCDayLo]
ld [de], a
; day hi
ld [hl], RTC_DH
ld a, [hRTCDayHi]
res 6, a ; make sure timer is active
ld [de], a
; cleanup
call CloseSRAM ; unlatch clock, disable clock r/w
ret
; 6c4
Function6c4: ; 6c4
xor a
push af
ld a, $0
call GetSRAMBank
pop af
ld [$ac60], a
call CloseSRAM
ret
; 6d3
Function6d3: ; 6d3
ld hl, $ac60
push af
ld a, $0
call GetSRAMBank
pop af
or [hl]
ld [hl], a
call CloseSRAM
ret
; 6e3
Function6e3: ; 6e3
ld a, $0
call GetSRAMBank
ld a, [$ac60]
call CloseSRAM
ret
; 6ef

View File

@ -6,6 +6,8 @@
; This prevents the display and audio output from lagging. ; This prevents the display and audio output from lagging.
VBlank: ; 283
push af push af
push bc push bc
push de push de

3296
main.asm

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,254 @@
Function1f8000: ; 1f8000
ld a, [rSVBK]
push af
ld a, $3
ld [rSVBK], a
xor a
ld hl, $d100
ld bc, $00e0
call ByteFill
ld a, $ff
ld [$d10c], a
ld [$d147], a
ld [$d182], a
ld de, $d100
ld a, [hRandomAdd]
ld b, a
.asm_1f8022
call RNG
ld a, [hRandomAdd]
add b
ld b, a
and $1f
cp $15
jr nc, .asm_1f8022
ld b, a
ld a, $1
call GetSRAMBank
ld c, $7
ld hl, $be48
.asm_1f803a
ld a, [hli]
cp b
jr z, .asm_1f8022
dec c
jr nz, .asm_1f803a
ld hl, $be48
ld a, [$be46]
ld c, a
ld a, b
ld b, 0
add hl, bc
ld [hl], a
call CloseSRAM
push af
ld hl, BattleTowerTrainers
ld bc, 11
call AddNTimes
ld bc, 11
call CopyBytes
call Function1f8081
pop af
ld hl, Function1f8000
ld bc, $0024
call AddNTimes
ld bc, $0024
.asm_1f8070
ld a, $7c
call GetFarByte
ld [de], a
inc hl
inc de
dec bc
ld a, b
or c
jr nz, .asm_1f8070
pop af
ld [rSVBK], a
ret
; 1f8081
Function1f8081: ; 1f8081
ld c, $3
push bc
ld a, $1
call GetSRAMBank
.asm_1f8089
ld a, [$d800]
dec a
ld hl, BattleTowerMons
ld bc, BattleTowerMons2 - BattleTowerMons1
call AddNTimes
ld a, [hRandomAdd]
ld b, a
.asm_1f8099
call RNG
ld a, [hRandomAdd]
add b
ld b, a
and $1f
cp (BattleTowerMons2 - BattleTowerMons1) / ($3b)
jr nc, .asm_1f8099
ld bc, $3b
call AddNTimes
ld a, [hli]
ld b, a
ld a, [hld]
ld c, a
ld a, [$d10b]
cp b
jr z, .asm_1f8089
ld a, [$d10c]
cp c
jr z, .asm_1f8089
ld a, [$d146]
cp b
jr z, .asm_1f8089
ld a, [$d147]
cp c
jr z, .asm_1f8089
ld a, [$d181]
cp b
jr z, .asm_1f8089
ld a, [$d182]
cp c
jr z, .asm_1f8089
ld a, [$be51]
cp b
jr z, .asm_1f8089
ld a, [$be52]
cp b
jr z, .asm_1f8089
ld a, [$be53]
cp b
jr z, .asm_1f8089
ld a, [$be54]
cp b
jr z, .asm_1f8089
ld a, [$be55]
cp b
jr z, .asm_1f8089
ld a, [$be56]
cp b
jr z, .asm_1f8089
ld bc, $3b
call CopyBytes
ld a, [$d265]
push af
push de
ld hl, -$3b
add hl, de
ld a, [hl]
ld [$d265], a
ld bc, $0030
add hl, bc
push hl
call GetPokemonName
ld h, d
ld l, e
pop de
ld bc, $000b
call CopyBytes
pop de
pop af
ld [$d265], a
pop bc
dec c
jp nz, $4083
ld a, [$be51]
ld [$be54], a
ld a, [$be52]
ld [$be55], a
ld a, [$be53]
ld [$be56], a
ld a, [$d10b]
ld [$be51], a
ld a, [$d146]
ld [$be52], a
ld a, [$d181]
ld [$be53], a
call CloseSRAM
ret
; 1f814e
BattleTowerTrainers: ; 1f814e
db "HANSON@@@@", FISHER
db "SAWYER@@@@", POKEMANIAC
db "MASUDA@@@@", GUITARIST
db "NICKEL@@@@", SCIENTIST
db "OLSON@@@@@", POKEFANM
db "ZABOROWSKI", LASS
db "WRIGHT@@@@", YOUNGSTER
db "ALEXANDER@", HIKER
db "KAWAKAMI@@", TEACHER
db "BICKETT@@@", POKEFANM
db "SAITO@@@@@", KIMONO_GIRL
db "CRAWFORD@@", BOARDER
db "DIAZ@@@@@@", PICNICKER
db "ERICKSON@@", BIKER
db "FAIRFIELD@", JUGGLER
db "HUNTER@@@@", POKEFANF
db "HILL@@@@@@", FIREBREATHER
db "JAVIER@@@@", SWIMMERF
db "KAUFMAN@@@", SWIMMERM
db "LANCASTER@", SKIER
db "McMAHILL@@", CAMPER
db "OBRIEN@@@@", GENTLEMAN
db "FROST@@@@@", BEAUTY
db "MORSE@@@@@", SUPER_NERD
db "YUFUNE@@@@", BLACKBELT_T
db "RAJAN@@@@@", COOLTRAINERF
db "RODRIGUEZ@", OFFICER
db "SANTIAGO@@", PSYCHIC_T
db "STOCK@@@@@", POKEFANM
db "THURMAN@@@", SCIENTIST
db "VALENTINO@", BEAUTY
db "WAGNER@@@@", CAMPER
db "YATES@@@@@", BIRD_KEEPER
db "ANDREWS@@@", PICNICKER
db "BAHN@@@@@@", POKEMANIAC
db "MORI@@@@@@", SCIENTIST
db "BUCKMAN@@@", SAGE
db "COBB@@@@@@", SCHOOLBOY
db "HUGHES@@@@", FISHER
db "ARITA@@@@@", KIMONO_GIRL
db "EASTON@@@@", PSYCHIC_T
db "FREEMAN@@@", CAMPER
db "GIESE@@@@@", LASS
db "HATCHER@@@", GENTLEMAN
db "JACKSON@@@", POKEFANF
db "KAHN@@@@@@", POKEMANIAC
db "LEONG@@@@@", YOUNGSTER
db "MARINO@@@@", TEACHER
db "NEWMAN@@@@", SAILOR
db "NGUYEN@@@@", BLACKBELT_T
db "OGDEN@@@@@", SUPER_NERD
db "PARK@@@@@@", COOLTRAINERF
db "RAINE@@@@@", SWIMMERM
db "SELLS@@@@@", BIRD_KEEPER
db "ROCKWELL@@", BOARDER
db "THORNTON@@", LASS
db "TURNER@@@@", OFFICER
db "VAN DYKE@@", SKIER
db "WALKER@@@@", SCHOOLBOY
db "MEYER@@@@@", SWIMMERF
db "JOHNSON@@@", YOUNGSTER
db "ADAMS@@@@@", GUITARIST
db "SMITH@@@@@", BUG_CATCHER
db "TAJIRI@@@@", BUG_CATCHER
db "BAKER@@@@@", POKEMANIAC
db "COLLINS@@@", SCIENTIST
db "SMART@@@@@", SUPER_NERD
db "DYKSTRA@@@", SWIMMERF
db "EATON@@@@@", BIKER
db "WONG@@@@@@", FIREBREATHER
; 1f8450
BattleTowerMons: ; 1f8450
BattleTowerMons1: BattleTowerMons1:

View File

@ -1,3 +1,102 @@
GiveOddEgg: ; 1fb4b6
; Figure out which egg to give.
call RNG
ld hl, .Probabilities
ld c, 0
ld b, c
.next
ld a, [hli]
ld e, a
ld a, [hli]
ld d, a
ld a, d
cp $ff
jr nz, .first
ld a, e
cp $ff
jr z, .done
.first
ld a, [hRandomSub]
cp d
jr c, .done
jr z, .second
jr .good
.second
ld a, [hRandomAdd]
cp e
jr c, .done
jr z, .done
.good
inc bc
jr .next
.done
ld hl, OddEggs
ld a, OddEgg2 - OddEgg1
call AddNTimes
ld de, EnemyMoveAnimation
ld bc, $0046
call CopyBytes
ld a, EGG_TICKET
ld [CurItem], a
ld a, $1
ld [$d10c], a
ld a, $ff
ld [$d107], a
ld hl, NumItems
call Function2f53
ld a, EGG
ld [$cd2a], a
ld a, $29
ld [$cd20], a
ld a, $cd
ld [$cd21], a
ld a, $8
ld [$cd22], a
ld a, $c6
ld [$cd23], a
ld hl, .Odd
ld de, $cd2b
ld bc, $000b
call CopyBytes
ld a, $2b
ld [$cd24], a
ld a, $cd
ld [$cd25], a
ld a, $38
ld [$cd26], a
ld a, $c6
ld [$cd27], a
callba Function11b98f
ret
; 1fb546
.Odd
db "ODD@@@@@@@@@"
.Probabilities
dw $147a ; 92% -> 8%
dw $170a ; 91% -> 1%
dw $3fff ; 75% -> 16%
dw $47ad ; 72% -> 3%
dw $70a3 ; 56% -> 16%
dw $7851 ; 53% -> 3%
dw $9c28 ; 39% -> 14%
dw $a147 ; 37% -> 2%
dw $bae0 ; 27% -> 10%
dw $bfff ; 25% -> 2%
dw $deb7 ; 13% -> 12%
dw $e3d6 ; 11% -> 2%
dw $fd6f ; 1% -> 10%
dw $ffff ; 0% -> 1%
; 1fb56e
OddEggs: ; 1fb56e
OddEgg1: OddEgg1:
db PICHU db PICHU
db NO_ITEM db NO_ITEM

View File

@ -13,9 +13,9 @@ VBGMap1:
SECTION "WRAMBank0",WRAM0[$c000] SECTION "WRAMBank0",WRAM0[$c000]
SECTION "stack",WRAM0[$c000] SECTION "stack",WRAM0[$c0ff]
ds $100 Stack: ; c0ff
Stack: ; c100 ds -$100
SECTION "audio",WRAM0[$c100] SECTION "audio",WRAM0[$c100]
@ -1642,8 +1642,8 @@ PlayerDirection: ; d4de
; $11 right ; $11 right
ds 1 ds 1
ds 2
SECTION "MapEngine",WRAMX[$d4e1],BANK[1]
PlayerAction: ; d4e1 PlayerAction: ; d4e1
; 1 standing ; 1 standing
; 2 walking ; 2 walking
@ -1742,7 +1742,12 @@ NumBalls: ; d8d7
Balls: ; d8d8 Balls: ; d8d8
ds 25 ds 25
BallsEnd BallsEnd
PCItems: ; d8f1
ds 101
PCItemsEnd
SECTION "overworld",WRAMX[$d95b],BANK[1] SECTION "overworld",WRAMX[$d95b],BANK[1]
WhichRegisteredItem: ; d95b WhichRegisteredItem: ; d95b
REGISTERED_POCKET EQU %11000000 REGISTERED_POCKET EQU %11000000