Comment some more bank 0 functions.

This commit is contained in:
yenatch 2014-05-23 15:34:35 -07:00
parent 955b53047c
commit 8f8281fe6e
20 changed files with 597 additions and 557 deletions

View file

@ -1,5 +1,7 @@
; From http://nocash.emubase.de/pandocs.htm.
GBC EQU $11
; MBC3
MBC3SRamEnable EQU $0000
MBC3RomBank EQU $2000
@ -28,6 +30,8 @@ TIMER EQU 2
SERIAL EQU 3
JOYPAD EQU 4
LY_VBLANK EQU 145
; OAM attribute flags
OAM_PALETTE EQU %111
OAM_TILE_BANK EQU 3
@ -76,6 +80,8 @@ rNR50 EQU $ff24 ; Channel control / ON-OFF / Volume (R/W)
rNR51 EQU $ff25 ; Selection of Sound output terminal (R/W)
rNR52 EQU $ff26 ; Sound on/off
rLCDC EQU $ff40 ; LCD Control (R/W)
rLCDC_ENABLE EQU 7
rLCDC_ENABLE_MASK EQU 1 << rLCDC_ENABLE
rSTAT EQU $ff41 ; LCDC Status (R/W)
rSCY EQU $ff42 ; Scroll Y (R/W)
rSCX EQU $ff43 ; Scroll X (R/W)

View file

@ -24,7 +24,7 @@ Func_708ca: ; 708ca (1c:48ca)
sla a
ld [rOBP1], a ; $ff49
jr nz, .asm_708f6
call CleanLCD_OAM
call ClearSprites
call Func_7092a
ld b, $e4
.asm_7090d
@ -42,7 +42,7 @@ Func_708ca: ; 708ca (1c:48ca)
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
call Delay3
jp CleanLCD_OAM
jp ClearSprites
Func_7092a: ; 7092a (1c:492a)
ld de, $9000

View file

@ -616,7 +616,7 @@ AnimationCleanOAM: ; 78ec8 (1e:4ec8)
push bc
push af
call DelayFrame
call CleanLCD_OAM
call ClearSprites
pop af
pop bc
pop de
@ -2616,7 +2616,7 @@ AnimationPetalsFalling: ; 79c8a (1e:5c8a)
ld a, $14
ld [W_SUBANIMTRANSFORM], a
call Func_79c97
jp CleanLCD_OAM
jp ClearSprites
Func_79c97: ; 79c97 (1e:5c97)
ld c, a
@ -2773,7 +2773,7 @@ AnimationShakeEnemyHUD: ; 79d77 (1e:5d77)
ld de, $0208
call Func_79de9
call AnimationShowMonPic
call CleanLCD_OAM
call ClearSprites
ld a, $90
ld [$ffb0], a
ld hl, $9c00

View file

@ -183,7 +183,7 @@ Func_3c04c: ; 3c04c (f:404c)
call Delay3
ld b, $1
call GoPAL_SET
call ResetLCD_OAM
call HideSprites
ld hl, PrintBeginningBattleText
ld b, BANK(PrintBeginningBattleText)
jp Bankswitch
@ -1146,7 +1146,7 @@ Func_3c7d8: ; 3c7d8 (f:47d8)
.asm_3c7fa
xor a
ld [$cd6a], a
call CleanLCD_OAM
call ClearSprites
ld a, [wWhichPokemon] ; $cf92
ld [wPlayerMonNumber], a ; $cc2f
ld c, a
@ -1449,7 +1449,7 @@ Func_3c92a: ; 3c92a (f:492a)
call Func_3ee5b
call LoadScreenTilesFromBuffer1
.next4
call CleanLCD_OAM
call ClearSprites
ld hl,wTileMap
ld bc,$040B
call ClearScreenArea
@ -2271,7 +2271,7 @@ asm_3d05f: ; 3d05f (f:505f)
ld [$d152], a
call UseItem
call Func_3ee5b
call CleanLCD_OAM
call ClearSprites
xor a
ld [wCurrentMenuItem], a ; $cc26
ld a, [W_BATTLETYPE] ; $d05a
@ -2335,7 +2335,7 @@ Func_3d0e0: ; 3d0e0 (f:50e0)
asm_3d0ed: ; 3d0ed (f:50ed)
jp nc, Func_3d119
asm_3d0f0: ; 3d0f0 (f:50f0)
call CleanLCD_OAM
call ClearSprites
call GBPalWhiteOut
call Func_3ee5b
call LoadScreenTilesFromBuffer2
@ -2383,7 +2383,7 @@ Func_3d119: ; 3d119 (f:5119)
xor a
ld [$cc49], a
ld hl, W_PARTYMON1_NUM ; $d16b (aliases: W_PARTYMON1DATA)
call CleanLCD_OAM
call ClearSprites
ld a, $36
call Predef ; indirect jump to StatusScreen (12953 (4:6953))
ld a, $37
@ -2423,7 +2423,7 @@ Func_3d119: ; 3d119 (f:5119)
ld a, $1
ld [$cd6a], a
call GBPalWhiteOut
call CleanLCD_OAM
call ClearSprites
call Func_3ee5b
call LoadScreenTilesFromBuffer1
call GoPAL_SET_CF1C
@ -6219,7 +6219,7 @@ Func_3ec32: ; 3ec32 (f:6c32)
ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
ld a, $ff
ld [$cfcb], a
call CleanLCD_OAM
call ClearSprites
call ClearScreen
xor a
ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
@ -6787,7 +6787,7 @@ Func_3efeb: ; 3efeb (f:6feb)
ld hl, Coord
ld bc, $40a
call ClearScreenArea
call CleanLCD_OAM
call ClearSprites
ld a, [W_ISINBATTLE] ; $d057
dec a
call z, Func_3cdec

View file

@ -887,7 +887,7 @@ Func_5a5f: ; 5a5f (1:5a5f)
ret nz
ld a, $4d
call Predef ; indirect jump to Func_5aaf (5aaf (1:5aaf))
jp InitGame
jp Init
.asm_5a75
call Func_5317
ld hl, Club_GFX

View file

@ -15,9 +15,9 @@ Func_1c98a: ; 1c98a (7:498a)
call DisplayTextBoxID
ld a, [wCurrentMenuItem] ; $cc26
and a
jp z, InitGame
jp z, Init
callba Func_73b6a
jp InitGame
jp Init
ClearSaveDataText: ; 1c9c1 (7:49c1)
TX_FAR _ClearSaveDataText

View file

@ -123,7 +123,7 @@ Func_3ad71: ; 3ad71 (e:6d71)
ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
ld a, $ff
ld [$cfcb], a
call CleanLCD_OAM
call ClearSprites
callab Func_7bde9
jp c, Func_3af2e
ld hl, EvolvedText

View file

@ -9,7 +9,7 @@ PlayIntro: ; 41682 (10:5682)
xor a
ld [$ffae], a
ld [H_AUTOBGTRANSFERENABLED], a
call CleanLCD_OAM
call ClearSprites
call DelayFrame
ret
@ -329,7 +329,7 @@ PlayShootingStar: ; 4188a (10:588a)
ld [$c0ee], a
call PlaySound
call Func_417f8
call CleanLCD_OAM
call ClearSprites
jp Delay3
Func_418e9: ; 418e9 (10:58e9)

View file

@ -419,7 +419,7 @@ ItemUseBall: ; d687 (3:5687)
jr nz,.checkParty
ld hl,ItemUseBallText06
call PrintText
call CleanLCD_OAM
call ClearSprites
ld a,[$cfe5] ;caught mon_ID
ld [$d11e],a
ld a,$3d
@ -430,11 +430,11 @@ ItemUseBall: ; d687 (3:5687)
jr z,.sendToBox
xor a
ld [$cc49],a
call CleanLCD_OAM
call ClearSprites
call AddPokemonToParty ;add mon to Party
jr .End
.sendToBox ;$5907
call CleanLCD_OAM
call ClearSprites
call Func_e7a4
ld hl,ItemUseBallText07
ld a,[$d7f1]
@ -448,7 +448,7 @@ ItemUseBall: ; d687 (3:5687)
ld hl,ItemUseBallText05
.printText0 ;$5922
call PrintText
call CleanLCD_OAM
call ClearSprites
.End ;$5928
ld a,[W_BATTLETYPE]
and a
@ -2148,7 +2148,7 @@ ItemUseTMHM: ; e479 (3:6479)
pop af
pop af
call GBPalWhiteOutWithDelay3
call CleanLCD_OAM
call ClearSprites
call GoPAL_SET_CF1C
jp LoadScreenTilesFromBuffer1 ; restore saved screen
.checkIfAbleToLearnMove

View file

@ -163,7 +163,7 @@ DisplayNamingScreen: ; 6596 (1:6596)
call CopyData
call GBPalWhiteOutWithDelay3
call ClearScreen
call CleanLCD_OAM
call ClearSprites
call GoPAL_SET_CF1C
call GBPalNormal
xor a

View file

@ -95,7 +95,7 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
call GoBackToPartyMenu
jp .checkIfPokemonChosen
.choseStats
call CleanLCD_OAM
call ClearSprites
xor a
ld [$cc49],a
ld a,$36
@ -710,7 +710,7 @@ TrainerInfo_DrawVerticalLine: ; 135d8 (4:75d8)
StartMenu_SaveReset: ; 135e3 (4:75e3)
ld a,[$d72e]
bit 6,a ; is the player using the link feature?
jp nz,InitGame
jp nz,Init
ld a,$3f
call Predef ; save the game
call LoadScreenTilesFromBuffer2 ; restore saved screen

View file

@ -35,7 +35,7 @@ asm_ef82: ; ef82 (3:6f82)
ld hl, $d730
set 6, [hl]
call GBPalWhiteOutWithDelay3
call CleanLCD_OAM
call ClearSprites
call Func_3dbe
ld a, $90
ld [$ffb0], a

View file

@ -409,7 +409,7 @@ LoadSGBBorderAndPalettes: ; 7202b (1c:602b)
ld de, PalPacket_724d8
ld hl, SuperPalettes
call Func_7210b
call ZeroVram
call ClearVram
ld hl, PalPacket_72538
jp SendSGBPacket

View file

@ -226,7 +226,7 @@ ENDC
call PlayCry
call WaitForSoundToFinish
call GBPalWhiteOutWithDelay3
call CleanLCD_OAM
call ClearSprites
xor a
ld [$ffb0], a
inc a
@ -306,7 +306,7 @@ Func_44dd: ; 44dd (1:44dd)
ld bc, $230
ld a, BANK(PlayerCharacterTitleGraphics)
call FarCopyData2
call CleanLCD_OAM
call ClearSprites
xor a
ld [wWhichTrade], a ; $cd3d
ld hl, wOAMBuffer

View file

@ -138,7 +138,7 @@ MonsNestText: ; 70f89 (1c:4f89)
db "'s NEST@"
LoadTownMap_Fly: ; 70f90 (1c:4f90)
call CleanLCD_OAM
call ClearSprites
call LoadTownMap
call LoadPlayerSpriteGraphics
call LoadFontTilePatterns
@ -343,7 +343,7 @@ Func_711ab: ; 711ab (1c:51ab)
ld [$d09b], a
call GBPalWhiteOut
call ClearScreen
call CleanLCD_OAM
call ClearSprites
call LoadPlayerSpriteGraphics
call LoadFontTilePatterns
call UpdateSprites

View file

@ -117,7 +117,7 @@ LoadTradingGFXAndMonNames: ; 411a1 (10:51a1)
ld bc, $800
ld a, $7f
call FillMemory
call CleanLCD_OAM
call ClearSprites
ld a, $ff
ld [$cfcb], a
ld hl, $d730
@ -281,7 +281,7 @@ Func_412d2: ; 412d2 (10:52d2)
call PlaySound
jr .asm_412e7
.asm_41318
call CleanLCD_OAM
call ClearSprites
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
call ClearScreen
@ -355,7 +355,7 @@ Func_41376: ; 41376 (10:5376)
xor a
ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
call Func_41525
jp CleanLCD_OAM
jp ClearSprites
Func_413c6: ; 413c6 (10:53c6)
call Func_41411
@ -386,7 +386,7 @@ Func_413c6: ; 413c6 (10:53c6)
call Func_414c5
xor a
ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
jp CleanLCD_OAM
jp ClearSprites
Func_41411: ; 41411 (10:5411)
ld a, $1

View file

@ -11,6 +11,18 @@ page EQUS "db $49," ; Start a new Pokedex page.
dex EQUS "db $5f, $50" ; End a Pokedex entry.
homecall: MACRO
ld a, [H_LOADEDROMBANK]
push af
ld a, BANK(\1)
ld [H_LOADEDROMBANK], a
ld [MBC3RomBank], a
call \1
pop af
ld [H_LOADEDROMBANK], a
ld [MBC3RomBank], a
ENDM
callba: MACRO
ld b, BANK(\1)
ld hl, \1

583
main.asm
View file

@ -22,7 +22,7 @@ SECTION "rst38",ROM0[$38]
SECTION "vblank", ROM0[$40]
jp VBlank
SECTION "lcdc", ROM0[$48]
db $FF
rst $38
SECTION "timer", ROM0[$50]
jp Timer
SECTION "serial", ROM0[$58]
@ -30,47 +30,50 @@ SECTION "serial",ROM0[$58]
SECTION "joypad", ROM0[$60]
reti
SECTION "bank0",ROM0[$61]
DisableLCD:: ; 0061 (0:0061)
DisableLCD::
xor a
ld [$ff0f],a
ld a,[$ffff]
ld [rIF], a
ld a, [rIE]
ld b, a
res 0, a
ld [$ffff],a
.waitVBlank
ld a,[$ff44]
cp a,$91
jr nz,.waitVBlank
ld a,[$ff40]
and a,$7f ; res 7,a
ld [$ff40],a
ld [rIE], a
.wait
ld a, [rLY]
cp LY_VBLANK
jr nz, .wait
ld a, [rLCDC]
and $ff ^ rLCDC_ENABLE_MASK
ld [rLCDC], a
ld a, b
ld [$ffff],a
ld [rIE], a
ret
EnableLCD:: ; 007b (0:007b)
ld a,[$ff40]
set 7,a
ld [$ff40],a
EnableLCD::
ld a, [rLCDC]
set rLCDC_ENABLE, a
ld [rLCDC], a
ret
CleanLCD_OAM:: ; 0082 (0:0082)
ClearSprites::
xor a
ld hl, wOAMBuffer
ld b,$a0
ld b, 40 * 4
.loop
ld [hli], a
dec b
jr nz, .loop
ret
ResetLCD_OAM:: ; 008d (0:008d)
ld a,$a0
HideSprites::
ld a, 160
ld hl, wOAMBuffer
ld de,$0004
ld b,$28
ld de, 4
ld b, 40
.loop
ld [hl], a
add hl, de
@ -78,21 +81,22 @@ ResetLCD_OAM:: ; 008d (0:008d)
jr nz, .loop
ret
FarCopyData:: ; 009d (0:009d)
; copy bc bytes of data from a:hl to de
ld [$CEE9],a ; save future bank # for later
ld a,[H_LOADEDROMBANK] ; get current bank #
FarCopyData::
; Copy bc bytes from a:hl to de.
ld [wBuffer], a
ld a, [H_LOADEDROMBANK]
push af
ld a,[$CEE9] ; get future bank #, switch
ld a, [wBuffer]
ld [H_LOADEDROMBANK], a
ld [$2000],a
ld [MBC3RomBank], a
call CopyData
pop af ; okay, done, time to switch back
pop af
ld [H_LOADEDROMBANK], a
ld [$2000],a
ld [MBC3RomBank], a
ret
CopyData:: ; 00b5 (0:00b5)
; copy bc bytes of data from hl to de
CopyData::
; Copy bc bytes from hl to de.
ld a, [hli]
ld [de], a
inc de
@ -102,106 +106,86 @@ CopyData:: ; 00b5 (0:00b5)
jr nz, CopyData
ret
SECTION "romheader",ROM0[$100]
SECTION "Entry", ROM0[$100]
nop
jp Start
SECTION "start",ROM0[$150]
Start:: ; 0150 (0:0150)
cp $11 ; value that indicates Gameboy Color
jr z,.gbcDetected
SECTION "Start", ROM0[$150]
Start::
cp GBC
jr z, .gbc
xor a
jr .storeValue
.gbcDetected
ld a,$00
.storeValue
ld [$cf1a],a ; same value ($00) either way
jp InitGame
jr .ok
.gbc
ld a, 0
.ok
ld [wGBC], a
jp Init
ReadJoypad::
; Poll joypad input.
; Unlike the hardware register, button
; presses are indicated by a set bit.
ld a, 1 << 5 ; select direction keys
ld c, 0
; this function directly reads the joypad I/O register
; it reads many times in order to give the joypad a chance to stabilize
; it saves a result in [$fff8] in the following format
; (set bit indicates pressed button)
; bit 0 - A button
; bit 1 - B button
; bit 2 - Select button
; bit 3 - Start button
; bit 4 - Right
; bit 5 - Left
; bit 6 - Up
; bit 7 - Down
ReadJoypadRegister:: ; 015f (0:015f)
ld a,%00100000 ; select direction keys
ld c,$00
ld [rJOYP], a
rept 6
ld a, [rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
cpl ; complement the result so that a set bit indicates a pressed key
and a,%00001111
swap a ; put direction keys in upper nibble
endr
cpl
and %1111
swap a
ld b, a
ld a,%00010000 ; select button keys
ld a, 1 << 4 ; select button keys
ld [rJOYP], a
rept 10
ld a, [rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
ld a,[rJOYP]
cpl ; complement the result so that a set bit indicates a pressed key
and a,%00001111
or b ; put button keys in lower nibble
ld [H_JOYPADSTATE],a ; save joypad state
ld a,%00110000 ; unselect all keys
endr
cpl
and %1111
or b
ld [H_JOYPADSTATE], a
ld a, 1 << 4 + 1 << 5 ; deselect keys
ld [rJOYP], a
ret
; function to update the joypad state variables
; output:
; [H_NEWLYRELEASEDBUTTONS] = keys released since last time
; [H_NEWLYPRESSEDBUTTONS] = keys pressed since last time
; [H_CURRENTPRESSEDBUTTONS] = currently pressed keys
GetJoypadState:: ; 019a (0:019a)
ld a, [H_LOADEDROMBANK]
push af
ld a,Bank(_GetJoypadState)
ld [H_LOADEDROMBANK],a
ld [$2000],a
call _GetJoypadState
pop af
ld [H_LOADEDROMBANK],a
ld [$2000],a
GetJoypadState::
; Update the joypad state variables:
; [H_NEWLYRELEASEDBUTTONS] keys released since last time
; [H_NEWLYPRESSEDBUTTONS] keys pressed since last time
; [H_CURRENTPRESSEDBUTTONS] currently pressed keys
homecall _GetJoypadState
ret
INCLUDE "data/map_header_pointers.asm"
; this function calls a function that takes necessary actions
; at the beginning of each overworld loop iteration as the player jumps
; down a ledge
; it also ends the jump when it's completed
HandleMidJump:: ; 039e (0:039e)
HandleMidJump::
; Handle the player jumping down
; a ledge in the overworld.
ld b, BANK(_HandleMidJump)
ld hl, _HandleMidJump
jp Bankswitch
; this is jumped to immediately after loading a save / starting a new game / loading a new map
EnterMap:: ; 03a6 (0:03a6)
EnterMap::
; Load a new map.
ld a, $ff
ld [wJoypadForbiddenButtonsMask], a
call LoadMapData ; load map data
callba Func_c335 ; initialize some variables
call LoadMapData
callba Func_c335 ; initialize map variables
ld hl, $d72c
bit 0, [hl]
jr z, .doNotCountSteps
ld a,$03
ld a, 3
ld [$d13c], a ; some kind of step counter (counts up to 3 steps?)
.doNotCountSteps
ld hl, $d72e
@ -211,25 +195,25 @@ EnterMap:: ; 03a6 (0:03a6)
call nz, MapEntryAfterBattle
ld hl, $d732
ld a, [hl]
and a,$18
and 1 << 4 | 1 << 3
jr z, .didNotFlyOrTeleportIn
res 3, [hl]
callba Func_70510 ; display fly/teleport in graphical effect
call UpdateSprites ; move sprites
call UpdateSprites
.didNotFlyOrTeleportIn
callba CheckForceBikeOrSurf ; handle currents in SF islands and forced bike riding in cycling road
ld hl, $d72d
res 5, [hl]
call UpdateSprites ; move sprites
call UpdateSprites
ld hl, $d126
set 5, [hl]
set 6, [hl]
xor a
ld [wJoypadForbiddenButtonsMask], a
OverworldLoop:: ; 03ff (0:03ff)
OverworldLoop::
call DelayFrame
OverworldLoopLessDelay:: ; 0402 (0:0402)
OverworldLoopLessDelay::
call DelayFrame
call LoadGBPal
ld a,[$d736]
@ -2826,7 +2810,7 @@ DisplayPartyMenu:: ; 13fc (0:13fc)
xor a
ld [$ffd7],a
call GBPalWhiteOutWithDelay3
call CleanLCD_OAM
call ClearSprites
call PartyMenuInit
call DrawPartyMenu
jp HandlePartyMenuInput
@ -4646,34 +4630,43 @@ VBlankCopyBgMap:: ; 1de1 (0:1de1)
ld [H_VBCOPYBGSRC],a ; disable transfer so it doesn't continue next V-blank
jr TransferBgRows
; This function copies ([H_VBCOPYDOUBLESIZE] * 8) source bytes
VBlankCopyDouble::
; Copy [H_VBCOPYDOUBLESIZE] 1bpp tiles
; from H_VBCOPYDOUBLESRC to H_VBCOPYDOUBLEDEST.
; It copies each source byte to the destination twice (next to each other).
; The function updates the source and destination addresses, so the transfer
; can be continued easily by repeatingly calling this function.
VBlankCopyDouble:: ; 1e02 (0:1e02)
; While we're here, convert to 2bpp.
; The process is straightforward:
; copy each byte twice.
ld a, [H_VBCOPYDOUBLESIZE]
and a ; are there any bytes to copy?
and a
ret z
ld hl, [sp + 0]
ld a, h
ld [H_SPTEMP], a
ld a, l
ld [H_SPTEMP + 1],a ; save stack pointer
ld [H_SPTEMP + 1], a
ld a, [H_VBCOPYDOUBLESRC]
ld l, a
ld a, [H_VBCOPYDOUBLESRC + 1]
ld h, a
ld sp, hl
ld a, [H_VBCOPYDOUBLEDEST]
ld l, a
ld a, [H_VBCOPYDOUBLEDEST + 1]
ld h, a
ld a, [H_VBCOPYDOUBLESIZE]
ld b, a
xor a
ld [H_VBCOPYDOUBLESIZE],a ; disable transfer so it doesn't continue next V-blank
xor a ; transferred
ld [H_VBCOPYDOUBLESIZE], a
.loop
rept 3
pop de
ld [hl], e
inc l
@ -4683,24 +4676,8 @@ VBlankCopyDouble:: ; 1e02 (0:1e02)
inc l
ld [hl], d
inc l
pop de
ld [hl],e
inc l
ld [hl],e
inc l
ld [hl],d
inc l
ld [hl],d
inc l
pop de
ld [hl],e
inc l
ld [hl],e
inc l
ld [hl],d
inc l
ld [hl],d
inc l
endr
pop de
ld [hl], e
inc l
@ -4712,83 +4689,70 @@ VBlankCopyDouble:: ; 1e02 (0:1e02)
inc hl
dec b
jr nz, .loop
ld a, l
ld [H_VBCOPYDOUBLEDEST], a
ld a, h
ld [H_VBCOPYDOUBLEDEST + 1],a ; update destination address
ld [H_VBCOPYDOUBLEDEST + 1], a
ld hl, [sp + 0]
ld a, l
ld [H_VBCOPYDOUBLESRC], a
ld a, h
ld [H_VBCOPYDOUBLESRC + 1],a ; update source address
ld [H_VBCOPYDOUBLESRC + 1], a
ld a, [H_SPTEMP]
ld h, a
ld a, [H_SPTEMP + 1]
ld l, a
ld sp,hl ; restore stack pointer
ld sp, hl
ret
; Copies ([H_VBCOPYSIZE] * 16) bytes from H_VBCOPYSRC to H_VBCOPYDEST.
; The function updates the source and destination addresses, so the transfer
; can be continued easily by repeatingly calling this function.
VBlankCopy:: ; 1e5e (0:1e5e)
VBlankCopy::
; Copy [H_VBCOPYSIZE] 2bpp tiles
; from H_VBCOPYSRC to H_VBCOPYDEST.
; Source and destination addresses
; are updated, so transfer can
; continue in subsequent calls.
ld a, [H_VBCOPYSIZE]
and a ; are there any bytes to copy?
and a
ret z
ld hl, [sp + 0]
ld a, h
ld [H_SPTEMP], a
ld a, l
ld [H_SPTEMP + 1],a ; save stack pointer
ld [H_SPTEMP + 1], a
ld a, [H_VBCOPYSRC]
ld l, a
ld a, [H_VBCOPYSRC + 1]
ld h, a
ld sp, hl
ld a, [H_VBCOPYDEST]
ld l, a
ld a, [H_VBCOPYDEST + 1]
ld h, a
ld a, [H_VBCOPYSIZE]
ld b, a
xor a
ld [H_VBCOPYSIZE],a ; disable transfer so it doesn't continue next V-blank
xor a ; transferred
ld [H_VBCOPYSIZE], a
.loop
rept 7
pop de
ld [hl], e
inc l
ld [hl], d
inc l
pop de
ld [hl],e
inc l
ld [hl],d
inc l
pop de
ld [hl],e
inc l
ld [hl],d
inc l
pop de
ld [hl],e
inc l
ld [hl],d
inc l
pop de
ld [hl],e
inc l
ld [hl],d
inc l
pop de
ld [hl],e
inc l
ld [hl],d
inc l
pop de
ld [hl],e
inc l
ld [hl],d
inc l
endr
pop de
ld [hl], e
inc l
@ -4796,55 +4760,66 @@ VBlankCopy:: ; 1e5e (0:1e5e)
inc hl
dec b
jr nz, .loop
ld a, l
ld [H_VBCOPYDEST], a
ld a, h
ld [H_VBCOPYDEST + 1], a
ld hl, [sp + 0]
ld a, l
ld [H_VBCOPYSRC], a
ld a, h
ld [H_VBCOPYSRC + 1], a
ld a, [H_SPTEMP]
ld h, a
ld a, [H_SPTEMP + 1]
ld l, a
ld sp,hl ; restore stack pointer
ld sp, hl
ret
; This function updates the moving water and flower background tiles.
UpdateMovingBgTiles:: ; 1ebe (0:1ebe)
UpdateMovingBgTiles::
; Animate water and flower
; tiles in the overworld.
ld a, [$ffd7]
and a
ret z
ld a, [$ffd8]
inc a
ld [$ffd8], a
cp a,20
cp 20
ret c
cp a,21
jr z,.updateFlowerTile
ld hl,$9140 ; water tile pattern VRAM location
ld c,16 ; number of bytes in a tile pattern
cp 21
jr z, .flower
ld hl, $9140
ld c, $10
ld a, [$d085]
inc a
and a,$07
and 7
ld [$d085], a
and a,$04
jr nz,.rotateWaterLeftLoop
.rotateWaterRightloop
and 4
jr nz, .left
.right
ld a, [hl]
rrca
ld [hli], a
dec c
jr nz,.rotateWaterRightloop
jr nz, .right
jr .done
.rotateWaterLeftLoop
.left
ld a, [hl]
rlca
ld [hli], a
dec c
jr nz,.rotateWaterLeftLoop
jr nz, .left
.done
ld a, [$ffd7]
rrca
@ -4852,46 +4827,46 @@ UpdateMovingBgTiles:: ; 1ebe (0:1ebe)
xor a
ld [$ffd8], a
ret
.updateFlowerTile
.flower
xor a
ld [$ffd8], a
ld a, [$d085]
and a,$03
cp a,2
ld hl,FlowerTilePattern1
jr c,.writeTilePatternToVram
ld hl,FlowerTilePattern2
jr z,.writeTilePatternToVram
ld hl,FlowerTilePattern3
.writeTilePatternToVram
ld de,$9030 ; flower tile pattern VRAM location
ld c,16 ; number of bytes in a tile pattern
.flowerTileLoop
and 3
cp 2
ld hl, FlowerTile1
jr c, .copy
ld hl, FlowerTile2
jr z, .copy
ld hl, FlowerTile3
.copy
ld de, $9030
ld c, $10
.loop
ld a, [hli]
ld [de], a
inc de
dec c
jr nz,.flowerTileLoop
jr nz, .loop
ret
FlowerTilePattern1:: ; 1f19 (0:1f19)
INCBIN "gfx/tilesets/flower/flower1.2bpp"
FlowerTile1: INCBIN "gfx/tilesets/flower/flower1.2bpp"
FlowerTile2: INCBIN "gfx/tilesets/flower/flower2.2bpp"
FlowerTile3: INCBIN "gfx/tilesets/flower/flower3.2bpp"
FlowerTilePattern2:: ; 1f29 (0:1f29)
INCBIN "gfx/tilesets/flower/flower2.2bpp"
FlowerTilePattern3:: ; 1f39 (0:1f39)
INCBIN "gfx/tilesets/flower/flower3.2bpp"
SoftReset:: ; 1f49 (0:1f49)
SoftReset::
call StopAllSounds
call GBPalWhiteOut
ld c, $20
call DelayFrames
; fallthrough
; initialization code
; explanation for %11100011 (value stored in rLCDC)
Init::
; Program init.
rLCDC_DEFAULT EQU %11100011
; * LCD enabled
; * Window tile map at $9C00
; * Window display enabled
@ -4900,12 +4875,12 @@ SoftReset:: ; 1f49 (0:1f49)
; * 8x8 OBJ size
; * OBJ display enabled
; * BG display enabled
InitGame:: ; 1f54 (0:1f54)
di
; zero I/O registers
xor a
ld [$ff0f],a
ld [$ffff],a
ld [rIF], a
ld [rIE], a
ld [$ff43], a
ld [$ff42], a
ld [$ff01], a
@ -4917,55 +4892,70 @@ InitGame:: ; 1f54 (0:1f54)
ld [$ff47], a
ld [$ff48], a
ld [$ff49], a
ld a,%10000000 ; enable LCD
ld a, rLCDC_ENABLE_MASK
ld [rLCDC], a
call DisableLCD ; why enable then disable?
ld sp,$dfff ; initialize stack pointer
call DisableLCD
ld sp, wStack
ld hl, $c000 ; start of WRAM
ld bc, $2000 ; size of WRAM
.zeroWramLoop
.loop
ld [hl], 0
inc hl
dec bc
ld a, b
or c
jr nz,.zeroWramLoop
call ZeroVram
jr nz, .loop
call ClearVram
ld hl, $ff80
ld bc,$007f
call FillMemory ; zero HRAM
call CleanLCD_OAM ; this is unnecessary since it was already cleared above
ld bc, $ffff - $ff80
call FillMemory
call ClearSprites
ld a, Bank(WriteDMACodeToHRAM)
ld [H_LOADEDROMBANK], a
ld [$2000],a
call WriteDMACodeToHRAM ; copy DMA code to HRAM
ld [MBC3RomBank], a
call WriteDMACodeToHRAM
xor a
ld [$ffd7], a
ld [$ff41], a
ld [$ffae], a
ld [$ffaf], a
ld [$ff0f], a
ld a,%00001101 ; enable V-blank, timer, and serial interrupts
ld a, 1 << VBLANK + 1 << TIMER + 1 << SERIAL
ld [rIE], a
ld a,$90 ; put the window off the screen
ld a, 144 ; move the window off-screen
ld [$ffb0], a
ld [rWY], a
ld a,$07
ld a, 7
ld [rWX], a
ld a, $ff
ld [$ffaa], a
ld h,$98
call ClearBgMap ; fill $9800-$9BFF (BG tile map) with $7F tiles
ld h,$9c
call ClearBgMap ; fill $9C00-$9FFF (Window tile map) with $7F tiles
ld a,%11100011
ld [rLCDC],a ; enabled LCD
ld h, $9800 / $100 ; bg map 0
call ClearBgMap
ld h, $9c00 / $100 ; bg map 1
call ClearBgMap
ld a, rLCDC_DEFAULT
ld [rLCDC], a
ld a, $10
ld [H_SOFTRESETCOUNTER], a
call StopAllSounds
ei
ld a,$40
call Predef ; SGB border
ld a, $40 ; PREDEF_SGB_BORDER
call Predef
ld a, $1f
ld [$c0ef], a
ld [$c0f0], a
@ -4975,25 +4965,27 @@ InitGame:: ; 1f54 (0:1f54)
ld [$ffbc], a
dec a
ld [$cfcb], a
ld a,$32
call Predef ; display the copyrights, GameFreak logo, and battle animation
ld a, $32 ; PREDEF_INTRO
call Predef
call DisableLCD
call ZeroVram
call ClearVram
call GBPalNormal
call CleanLCD_OAM
ld a,%11100011
ld [rLCDC],a ; enable LCD
call ClearSprites
ld a, rLCDC_DEFAULT
ld [rLCDC], a
jp SetDefaultNamesBeforeTitlescreen
; zeroes all VRAM
ZeroVram:: ; 2004 (0:2004)
ClearVram:
ld hl, $8000
ld bc, $2000
xor a
jp FillMemory
; immediately stops all sounds
StopAllSounds:: ; 200e (0:200e)
StopAllSounds::
ld a, Bank(Func_9876)
ld [$c0ef], a
ld [$c0f0], a
@ -5004,92 +4996,117 @@ StopAllSounds:: ; 200e (0:200e)
dec a
jp PlaySound
VBlank:: ; 2024 (0:2024)
VBlank::
push af
push bc
push de
push hl
ld a,[H_LOADEDROMBANK] ; current ROM bank
ld a, [H_LOADEDROMBANK]
ld [$d122], a
ld a, [$ffae]
ld [rSCX], a
ld a, [$ffaf]
ld [rSCY], a
ld a, [$d0a0]
and a
jr nz,.doVramTransfers
jr nz, .ok
ld a, [$ffb0]
ld [rWY], a
.doVramTransfers
.ok
call AutoBgMapTransfer
call VBlankCopyBgMap
call RedrawExposedScreenEdge
call VBlankCopy
call VBlankCopyDouble
call UpdateMovingBgTiles
call $ff80 ; OAM DMA
call $ff80 ; hOAMDMA
ld a, Bank(PrepareOAMData)
ld [H_LOADEDROMBANK], a
ld [$2000],a
call PrepareOAMData ; update OAM buffer with current sprite data
ld [MBC3RomBank], a
call PrepareOAMData
; VBlank-sensitive operations end.
call GenRandom
ld a, [H_VBLANKOCCURRED]
and a
jr z,.next
jr z, .vblanked
xor a
ld [H_VBLANKOCCURRED], a
.next
.vblanked
ld a, [H_FRAMECOUNTER]
and a
jr z,.handleMusic
jr z, .decced
dec a
ld [H_FRAMECOUNTER], a
.handleMusic
.decced
call Func_28cb
ld a, [$c0ef] ; music ROM bank
ld [H_LOADEDROMBANK], a
ld [$2000],a
cp a,$02
jr nz,.checkIfBank08
.bank02
ld [MBC3RomBank], a
cp BANK(Func_9103)
jr nz, .notbank2
.bank2
call Func_9103
jr .afterMusic
.checkIfBank08
cp a,$08
.notbank2
cp 8
jr nz, .bank1F
.bank08
.bank8
call Func_2136e
call Func_21879
jr .afterMusic
.bank1F
call Func_7d177
.afterMusic
callba Func_18dee ; keep track of time played
ld a, [$fff9]
and a
call z,ReadJoypadRegister
call z, ReadJoypad
ld a, [$d122]
ld [H_LOADEDROMBANK], a
ld [$2000],a
ld [MBC3RomBank], a
pop hl
pop de
pop bc
pop af
reti
DelayFrame:: ; 20af (0:20af)
; delay for one frame
ld a,1
ld [H_VBLANKOCCURRED],a
; wait for the next Vblank, halting to conserve battery
DelayFrame::
; Wait for the next vblank interrupt.
; As a bonus, this saves battery.
NOT_VBLANKED EQU 1
ld a, NOT_VBLANKED
ld [H_VBLANKOCCURRED], a
.halt
db $76 ; XXX this is a hack--rgbasm adds a nop after this instr even when ints are enabled
; XXX this is a hack--rgbasm adds
; a nop after halts by default.
db $76 ; halt
ld a, [H_VBLANKOCCURRED]
and a
jr nz, .halt
ret
; These routines manage gradual fading
; (e.g., entering a doorway)
LoadGBPal:: ; 20ba (0:20ba)
@ -9845,7 +9862,7 @@ IsInRestOfArray::
Func_3dbe:: ; 3dbe (0:3dbe)
call CleanLCD_OAM
call ClearSprites
ld a, $1
ld [$cfcb], a
call Func_3e08
@ -10352,7 +10369,7 @@ PrepareOAMData: ; 4b0f (1:4b0f)
cp $ff
ret nz
ld [$cfcb], a
jp ResetLCD_OAM
jp HideSprites
.asm_4b1e
xor a
ld [$ff90], a

View file

@ -58,7 +58,7 @@ HallofFameRoomScript2: ; 5a4bb (16:64bb)
dec b
jr nz, .asm_5a4ff ; 0x5a505 $f8
call WaitForTextScrollButtonPress
jp InitGame
jp Init
HallofFameRoomScript0: ; 5a50d (16:650d)
ld a, $ff

View file

@ -271,8 +271,7 @@ wTileMapBackup2:: ; cd81
ds 20 * 18
wBuffer:: ; cee9
; used for temporary things
; Temporary storage area of 30 bytes.
wHPBarMaxHP:: ; cee9
ds 2
wHPBarOldHP:: ; ceeb
@ -281,12 +280,9 @@ wHPBarNewHP:: ; ceed
ds 2
wHPBarDelta:: ; ceef
ds 1
ds 13
wHPBarHPDifference:: ; cefd
ds 1
ds 9
wAnimSoundID:: ; cf07
@ -304,7 +300,12 @@ wCurSpriteMovement2:: ; cf14
; movement byte 2 of current sprite
ds 1
ds 74
ds 5
wGBC:: ; cf1a
ds 1
ds 68
wGymCityName:: ; cf5f
wStringBuffer1:: ; cf5f
@ -1473,3 +1474,7 @@ W_BOXMON2NAME:: ; de11
ds 11 * 19
; dee2
SECTION "Stack", WRAMX[$dfff]
wStack:: ; dfff
ds -$100