diff options
62 files changed, 1650 insertions, 1005 deletions
diff --git a/audio/engine.asm b/audio/engine.asm index 6b0fe1a6..d749bdb4 100644 --- a/audio/engine.asm +++ b/audio/engine.asm @@ -2797,7 +2797,7 @@ ChannelPointers: ClearChannels:: ; runs ClearChannel for all 4 channels -; doesn't seem to be used, but functionally identical to MapSetup_Sound_Off +; doesn't seem to be used, but functionally identical to InitSound ld hl, rNR50 xor a ld [hli], a diff --git a/constants/map_object_constants.asm b/constants/map_object_constants.asm index 2c28dd7e..6a6cec59 100644 --- a/constants/map_object_constants.asm +++ b/constants/map_object_constants.asm @@ -34,7 +34,7 @@ const OBJECT_1F ; 1f const OBJECT_RANGE ; 20 ; 21-27 are not used -OBJECT_STRUCT_LENGTH EQU 40 +OBJECT_LENGTH EQU 40 NUM_OBJECT_STRUCTS EQU 13 ; see wObjectStructs ; object_struct OBJECT_FACING values diff --git a/constants/wram_constants.asm b/constants/wram_constants.asm index 6b739c6c..7cdebc05 100644 --- a/constants/wram_constants.asm +++ b/constants/wram_constants.asm @@ -14,6 +14,10 @@ AUTO_INPUT EQU $ff const TEMPMON ; 3 const WILDMON ; 4 +; wGameTimerPause:: ; cfbc +GAMETIMERPAUSE_TIMER_PAUSED_F EQU 0 +GAMETIMERPAUSE_MOBILE_7_F EQU 7 + ; wOptions:: ; cfcc TEXT_DELAY_MASK EQU %111 const_def 4 @@ -43,11 +47,18 @@ PRINT_DARKER EQU $60 PRINT_DARKEST EQU $7f ; WalkingDirection: ; d043 -STANDING EQU -1 -DOWN EQU 0 -UP EQU 1 -LEFT EQU 2 -RIGHT EQU 3 + const_def -1 + const STANDING ; -1 + const DOWN ; 0 + const UP ; 1 + const LEFT ; 2 + const RIGHT ; 3 +NUM_DIRECTIONS EQU const_value + +DOWN_MASK EQU 1 << DOWN +UP_MASK EQU 1 << UP +LEFT_MASK EQU 1 << LEFT +RIGHT_MASK EQU 1 << RIGHT ; FacingDirection: ; d044 FACE_CURRENT EQU 0 diff --git a/engine/color.asm b/engine/color.asm index 2d959df5..05c13b2b 100755 --- a/engine/color.asm +++ b/engine/color.asm @@ -227,7 +227,7 @@ Function91b4: ld a, [wc606] ld c, a ld a, [wc607] - ld hl, wAttrMap + ld hl, wAttrmap ld de, $14 .asm_91cc and a @@ -299,7 +299,7 @@ ApplyHPBarPals: .asm_9236 ld e, c inc e - hlcoord 11, 1, wAttrMap + hlcoord 11, 1, wAttrmap ld bc, 2 * SCREEN_WIDTH ld a, [wCurPartyMon] .asm_9241 @@ -543,7 +543,7 @@ Function9b01: ; 9b01 (2:5b01) ret Function9b1d: ; 9b1d (2:5b1d) - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap ld bc, SCREEN_HEIGHT * SCREEN_WIDTH xor a call ByteFill @@ -573,7 +573,7 @@ Function9b35: ; 9b35 (2:5b35) ret .asm_9b52 - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap ld de, $9800 ld b, $12 ld a, $1 @@ -609,7 +609,7 @@ Function9b75: ; 9b75 (2:5b75) ld a, [de] inc a ld e, a - hlcoord 11, 2, wAttrMap + hlcoord 11, 2, wAttrmap ld bc, $28 ld a, [wcca9] .asm_9b8d diff --git a/engine/events/whiteout.asm b/engine/events/whiteout.asm index 075274a4..01d7b388 100755 --- a/engine/events/whiteout.asm +++ b/engine/events/whiteout.asm @@ -31,7 +31,7 @@ Script_Whiteout: OverworldBGMap: call ClearPalettes - call FillScreenWithTextboxPal + call ClearScreen call WaitBGMap2 call HideSprites call RotateThreePalettesLeft diff --git a/engine/learn.asm b/engine/learn.asm index 8f599208..f61b0c6c 100644 --- a/engine/learn.asm +++ b/engine/learn.asm @@ -1,5 +1,5 @@ LearnMove: - call LoadTileMapToTempTileMap + call LoadTilemapToTempTilemap ld a, [wCurPartyMon] ld hl, wPartyMon1Nickname call GetNick @@ -147,7 +147,7 @@ LearnMove: ld [wcede], a call StaticMenuJoypad push af - call Call_LoadTempTileMapToTileMap + call SafeLoadTempTilemapToTilemap pop af pop hl bit 1, a diff --git a/engine/main_menu.asm b/engine/main_menu.asm index 7b01ff59..6f460a5c 100755 --- a/engine/main_menu.asm +++ b/engine/main_menu.asm @@ -22,7 +22,7 @@ MainMenu_: call Function5b0a call CloseWindow jr c, .asm_5a94 - call ClearTileMap + call ClearTilemap ld a, [wMenuSelection] ld hl, .Jumptable rst JumpTable @@ -230,7 +230,7 @@ Function5bb8: ; 5bb8 (1:5bb8) Function5bf7: ; 5bf7 (1:5bf7) xor a ldh [hMapAnims], a - call ClearTileMap + call ClearTilemap call LoadFontsExtra call Functiond9e call ClearWindowData @@ -504,7 +504,7 @@ MainMenu_Continue: ld [wMusicFadeID + 1], a call ClearBGPalettes call CloseWindow - call ClearTileMap + call ClearTilemap ld c, 20 call DelayFrames farcall JumpRoamMons @@ -724,7 +724,7 @@ OakSpeech: ; 5fa5 (1:5fa5) farcall InitClock ; What time is it? call RotateFourPalettesLeft - call ClearTileMap + call ClearTilemap ld de, MUSIC_ROUTE_30 call PlayMusic @@ -747,7 +747,7 @@ OakSpeech: ; 5fa5 (1:5fa5) call PrintText call RotateThreePalettesRight - call ClearTileMap + call ClearTilemap ld a, MARILL ld [wCurSpecies], a @@ -772,7 +772,7 @@ OakSpeech: ; 5fa5 (1:5fa5) call PrintText call RotateThreePalettesRight - call ClearTileMap + call ClearTilemap xor a ld [wCurPartySpecies], a @@ -789,7 +789,7 @@ OakSpeech: ; 5fa5 (1:5fa5) call PrintText call RotateThreePalettesRight - call ClearTileMap + call ClearTilemap xor a ld [wCurPartySpecies], a @@ -862,7 +862,7 @@ NamePlayer: ; 6085 (1:6085) ld de, wPlayerName farcall NamingScreen call RotateThreePalettesRight - call ClearTileMap + call ClearTilemap call LoadFontsExtra call WaitBGMap xor a @@ -968,7 +968,7 @@ ShrinkPlayer: ; 6123 (1:6123) call DelayFrames call RotateThreePalettesRight - call ClearTileMap + call ClearTilemap ret MovePlayerPicRight: ; 617e (1:617e) diff --git a/engine/movie/gamefreak_presents.asm b/engine/movie/gamefreak_presents.asm index a52413c4..7e9519f4 100644 --- a/engine/movie/gamefreak_presents.asm +++ b/engine/movie/gamefreak_presents.asm @@ -3,7 +3,7 @@ Copyright_GFPresents: ; e49a8 (39:49a8) ; Return carry if user cancels animation by pressing a button. call ClearBGPalettes - call ClearTileMap + call ClearTilemap ld a, HIGH(vBGMap0) ldh [hBGMapAddress + 1], a @@ -34,7 +34,7 @@ Copyright_GFPresents: ; e49a8 (39:49a8) ld c, 100 call DelayFrames - call ClearTileMap + call ClearTilemap call GFPresents_Init .loop @@ -124,7 +124,7 @@ GFPresents_PlayFrame: ; e4a37 (39:4a37) .finish callfar ClearAnimatedObjectBuffer - call ClearTileMap + call ClearTilemap call ClearSprites ld c, 16 @@ -175,7 +175,7 @@ GFPresents_Star: ; e4a96 (39:4a96) depixel 10, 11, 4, 0 ld a, $16 - call InitAnimatedObjectStruct + call InitSpriteAnimStruct ; TODO set some flag in the struct? ld hl, $c @@ -199,7 +199,7 @@ GFPresents_PlaceLogo: ; e4ab2 (39:4ab2) depixel 10, 11, 4, 0 ld a, $15 - call InitAnimatedObjectStruct + call InitSpriteAnimStruct call GFPresents_NextScene @@ -315,7 +315,7 @@ GFPresents_Sparkle: ; e4b33 (39:4b33) push af depixel 11, 11 ld a, $17 - call InitAnimatedObjectStruct + call InitSpriteAnimStruct pop af ; take the bottom 4 bits of a as an index into diff --git a/engine/namingscreen.asm b/engine/namingscreen.asm index 3a68626d..f907c463 100644 --- a/engine/namingscreen.asm +++ b/engine/namingscreen.asm @@ -158,7 +158,7 @@ Function11bda: ld [hl], a lb de, $24, $20 ld a, $1c - call InitAnimatedObjectStruct + call InitSpriteAnimStruct ld hl, $1 add hl, bc ld [hl], $0 @@ -190,7 +190,7 @@ Function11c11: ; 11c11 (4:5c11) ld [hl], a lb de, $24, $20 ld a, $1c - call InitAnimatedObjectStruct + call InitSpriteAnimStruct ret Function11c3a: ; 11c3a (4:5c3a) @@ -351,7 +351,7 @@ Function11d3a: ld d, $40 .asm_11d44 ld a, $14 - call InitAnimatedObjectStruct + call InitSpriteAnimStruct ld a, c ld [wc5d5], a ld a, b @@ -926,12 +926,12 @@ Function12267: ; 12267 (4:6267) ld a, BANK(MailIcon) call FarCopyBytes xor a - ld hl, wTileMapEnd + ld hl, wTilemapEnd ld [hli], a ld [hl], a lb de, $18, $10 ld a, $0 - call InitAnimatedObjectStruct + call InitSpriteAnimStruct ld hl, $2 add hl, bc ld [hl], $0 @@ -1055,7 +1055,7 @@ Function123d5: ; 123d5 (4:63d5) Function123e8: lb de, $48, $10 ld a, $1b - call InitAnimatedObjectStruct + call InitSpriteAnimStruct ld a, c ld [wc5d5], a ld a, b diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 6c344d31..887fb753 100755 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -673,7 +673,7 @@ Function55a1 jr z, .asm_55b8 call Function55bc .asm_55b8 - call UpdateSprites_ + call _UpdateSprites ret Function55bc: ; 55bc (1:55bc) @@ -1154,7 +1154,7 @@ Function5879: ; 5879 (1:5879) .data db 6,7,8,9 -UpdateSprites_:: ; 5896 (1:5896) +_UpdateSprites:: ; 5896 (1:5896) ld a, [wVramState] bit 0, a ret z diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm index 5a299571..d98b47ee 100755 --- a/engine/overworld/movement.asm +++ b/engine/overworld/movement.asm @@ -1,6 +1,6 @@ GetMovementByte: - ld hl, wMovementDataPointerBank - call GetMovementByte_ + ld hl, wMovementDataBank + call _GetMovementByte ret Function4fbd: @@ -9,7 +9,7 @@ Function4fbd: ld e, [hl] inc [hl] ld d, $0 - ld hl, wMovementPerson + ld hl, wMovementObject ld a, [hli] ld h, [hl] ld l, a @@ -36,7 +36,7 @@ Function4fdf: ; 4fdf (1:4fdf) jp Function4fe9 GetMovementPerson - ld a, [wMovementPerson] + ld a, [wMovementObject] ret Function4fe9: ; 4fe9 (1:4fe9) diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm index 06b38e94..0865dbf8 100755 --- a/engine/overworld/player_object.asm +++ b/engine/overworld/player_object.asm @@ -4,11 +4,11 @@ BlankScreen: ldh [hBGMapMode], a call ClearBGPalettes call ClearSprites - ld hl, wTileMap + ld hl, wTilemap ld bc, SCREEN_HEIGHT * SCREEN_WIDTH ld a, " " call ByteFill - ld hl, wAttrMap + ld hl, wAttrmap ld bc, SCREEN_HEIGHT * SCREEN_WIDTH ld a, $7 call ByteFill @@ -122,7 +122,7 @@ SpawnPlayer2: .PlayerObjectTemplate: object_event -4, -4, SPRITE_CHRIS, SPRITEMOVEDATA_12, 15, 15, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, 0, -1 -CopyObjectStruct_:: ; 86d7 (2:46d7) +CopyObjectStruct:: ; 86d7 (2:46d7) call CheckObjectMask and a ret nz @@ -242,7 +242,7 @@ InitializeVariableSprites: cp $b jr nc, .asm_87ab push bc - call CopyObjectStruct_ + call CopyObjectStruct pop bc jp c, Function87b9 .asm_87ab @@ -315,7 +315,7 @@ asm_87da jr nc, .asm_8814 push de push bc - call CopyObjectStruct_ + call CopyObjectStruct pop bc pop de .asm_8814 @@ -370,7 +370,7 @@ asm_882e jr nc, .asm_8868 push de push bc - call CopyObjectStruct_ + call CopyObjectStruct pop bc pop de .asm_8868 diff --git a/engine/pack.asm b/engine/pack.asm index 23a17c36..620976a9 100755 --- a/engine/pack.asm +++ b/engine/pack.asm @@ -1308,7 +1308,7 @@ Function10cef: ; 10cef (4:4cef) Function10d70: ; 10d70 (4:4d70) call ClearBGPalettes - call ClearTileMap + call ClearTilemap call ClearSprites call DisableLCD ld hl, PackMenuGFX diff --git a/engine/sine.asm b/engine/sine.asm index 9a730219..e22d785a 100644 --- a/engine/sine.asm +++ b/engine/sine.asm @@ -1,4 +1,4 @@ -Sine_e:: ; 8ac9 (2:4ac9) +_Sine:: ; 8ac9 (2:4ac9) ld a, e and $3f cp $20 diff --git a/engine/specials.asm b/engine/specials.asm index c12198bf..ad6c2085 100755 --- a/engine/specials.asm +++ b/engine/specials.asm @@ -83,7 +83,7 @@ SpecialsPointers: add_special ReloadSpritesNoPalettes, $02 add_special ClearBGPalettes add_special UpdateTimePals - add_special ClearTileMap + add_special ClearTilemap add_special UpdateSprites add_special ReplacePlayerSprite add_special GameCornerPrizeMonCheckDex diff --git a/engine/sprites.asm b/engine/sprites.asm index eb9b2fd5..b9267d66 100755 --- a/engine/sprites.asm +++ b/engine/sprites.asm @@ -101,7 +101,7 @@ DoNextFrameForFirst16Sprites: ; 8d1c9 .cancel ret ; 23:51f6 -InitAnimatedObjectStruct_:: ; 8d1f7 +_InitSpriteAnimStruct:: ; 8d1f7 push de ; 23:51f7 push af ; 23:51f8 ld hl, $c51c ; 23:51f9 diff --git a/engine/title.asm b/engine/title.asm index 16737cc4..94863c56 100755 --- a/engine/title.asm +++ b/engine/title.asm @@ -12,7 +12,7 @@ StartTitleScreen: call ClearBGPalettes ld hl, rLCDC res 2, [hl] - call ClearTileMap + call ClearTilemap xor a ldh [hLCDCPointer], a ld b, $8 @@ -46,7 +46,7 @@ InitTitleScreen: ; 6291 (1:6291) ld [wTimeOfDayPal], a ld de, MUSIC_NONE call PlayMusic - call ClearTileMap + call ClearTilemap call DisableLCD call ClearSprites xor a @@ -98,7 +98,7 @@ InitTitleScreen: ; 6291 (1:6291) ld [hl], a ld de, $6058 ld a, $2c ; HO-OH - call InitAnimatedObjectStruct + call InitSpriteAnimStruct ld hl, wAnimatedObjectStruct1 ld de, wAnimatedObjectStruct10 ld bc, $a @@ -409,7 +409,7 @@ IF DEF(SILVER) ld de, $7c58 ENDC ld a, $f - call InitAnimatedObjectStruct + call InitSpriteAnimStruct ret IF DEF(GOLD) @@ -423,7 +423,7 @@ IF DEF(GOLD) ENDC Copyright: - call ClearTileMap + call ClearTilemap call LoadFontsExtra ld de, CopyrightGFX ld hl, vTiles2 tile $60 @@ -56,7 +56,6 @@ INCLUDE "home/stone_queue.asm" INCLUDE "home/trainers.asm" INCLUDE "home/pokemon.asm" INCLUDE "home/print_bcd.asm" -INCLUDE "home/mon_party.asm" INCLUDE "home/battle.asm" INCLUDE "home/sprite_anims.asm" INCLUDE "home/audio.asm" diff --git a/home/audio.asm b/home/audio.asm index d57a126b..5ce77bd6 100644 --- a/home/audio.asm +++ b/home/audio.asm @@ -1,6 +1,6 @@ ; Audio interfaces. -MapSetup_Sound_Off:: +InitSound:: push hl push de push bc @@ -439,7 +439,7 @@ GetMapMusic_MaybeSpecial:: call GetMapMusic ret -Unreferenced_Function3d9f:: +Unreferenced_Function3f7d:: ; Places a BCD number at the ; upper center of the screen. ld a, 4 * TILE_WIDTH diff --git a/home/battle.asm b/home/battle.asm index eac378e0..9d63a5fe 100644 --- a/home/battle.asm +++ b/home/battle.asm @@ -1,12 +1,47 @@ -UserPartyAttr:: ; 3b69 +GetPartyParamLocation:: +; Get the location of parameter a from wCurPartyMon in hl + push bc + ld hl, wPartyMons + ld c, a + ld b, 0 + add hl, bc + ld a, [wCurPartyMon] + call GetPartyLocation + pop bc + ret + +GetPartyLocation:: +; Add the length of a PartyMon struct to hl a times. + ld bc, PARTYMON_STRUCT_LENGTH + jp AddNTimes + +Unreferenced_GetDexNumber:: +; Probably used in gen 1 to convert index number to dex number +; Not required in gen 2 because index number == dex number + push hl + ld a, b + dec a + ld b, 0 + add hl, bc + ld hl, BaseData + BASE_DEX_NO + ld bc, BASE_DATA_SIZE + call AddNTimes + pop bc + ld a, BANK(BaseData) + call GetFarHalfword + ld b, l + ld c, h + pop hl + ret + +UserPartyAttr:: push af ldh a, [hBattleTurn] and a - jr nz, .asm_3b72 + jr nz, .ot pop af jr BattlePartyAttr - -.asm_3b72 +.ot pop af jr OTPartyAttr @@ -14,19 +49,19 @@ OpponentPartyAttr:: push af ldh a, [hBattleTurn] and a - jr z, .asm_3b7e + jr z, .ot pop af jr BattlePartyAttr - -.asm_3b7e +.ot pop af jr OTPartyAttr BattlePartyAttr:: +; Get attribute a from the party struct of the active battle mon. push bc ld c, a - ld b, $0 - ld hl, wPartyMon1Species + ld b, 0 + ld hl, wPartyMons add hl, bc ld a, [wCurBattleMon] call GetPartyLocation @@ -34,9 +69,10 @@ BattlePartyAttr:: ret OTPartyAttr:: +; Get attribute a from the party struct of the active enemy mon. push bc ld c, a - ld b, $0 + ld b, 0 ld hl, wOTPartyMon1Species add hl, bc ld a, [wCurOTMon] @@ -56,7 +92,7 @@ SetPlayerTurn:: ret SetEnemyTurn:: - ld a, $1 + ld a, 1 ldh [hBattleTurn], a ret @@ -66,126 +102,60 @@ UpdateOpponentInParty:: jr z, UpdateEnemyMonInParty jr UpdateBattleMonInParty +UpdateUserInParty:: ldh a, [hBattleTurn] and a jr z, UpdateBattleMonInParty jr UpdateEnemyMonInParty UpdateBattleMonInParty:: +; Update level, status, current HP + ld a, [wCurBattleMon] + +UpdateBattleMon:: ld hl, wPartyMon1Level call GetPartyLocation + ld d, h ld e, l ld hl, wBattleMonLevel - ld bc, 5 + ld bc, wBattleMonMaxHP - wBattleMonLevel jp CopyBytes UpdateEnemyMonInParty:: +; Update level, status, current HP + +; No wildmons. ld a, [wBattleMode] dec a ret z + ld a, [wCurOTMon] ld hl, wOTPartyMon1Level call GetPartyLocation + ld d, h ld e, l ld hl, wEnemyMonLevel - ld bc, 5 + ld bc, wEnemyMonMaxHP - wEnemyMonLevel jp CopyBytes RefreshBattleHuds:: call UpdateBattleHuds - ld c, $3 + ld c, 3 call DelayFrames jp WaitBGMap -UpdateBattleHuds:: ; 3bf8 (0:3bf8) +UpdateBattleHuds:: farcall UpdatePlayerHUD farcall UpdateEnemyHUD ret -GetBattleVar:: - push hl - call GetBattleVarAddr - pop hl - ret - -GetBattleVarAddr:: ; 3c0b (0:3c0b) - push bc - ld hl, .battlevarpairs ; $3c2c - ld c, a - ld b, $0 - add hl, bc - add hl, bc - ld a, [hli] - ld h, [hl] - ld l, a - ldh a, [hBattleTurn] - and a - jr z, .asm_3c1d - inc hl -.asm_3c1d - ld a, [hl] - ld c, a - ld b, $0 - ld hl, .vars - add hl, bc - add hl, bc - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [hl] - pop bc - ret - -.battlevarpairs - dw .substatus1, .substatus2, .substatus3, .substatus4, .substatus5 - dw .substatus1opp, .substatus2opp, .substatus3opp, .substatus4opp, .substatus5opp - dw .status, .statusopp, .animation, .effect, .power, .type - dw .curmove, .lastcounter, .lastcounteropp, .lastmove, .lastmoveopp - -; player enemy -.substatus1 db PLAYER_SUBSTATUS_1, ENEMY_SUBSTATUS_1 -.substatus1opp db ENEMY_SUBSTATUS_1, PLAYER_SUBSTATUS_1 -.substatus2 db PLAYER_SUBSTATUS_2, ENEMY_SUBSTATUS_2 -.substatus2opp db ENEMY_SUBSTATUS_2, PLAYER_SUBSTATUS_2 -.substatus3 db PLAYER_SUBSTATUS_3, ENEMY_SUBSTATUS_3 -.substatus3opp db ENEMY_SUBSTATUS_3, PLAYER_SUBSTATUS_3 -.substatus4 db PLAYER_SUBSTATUS_4, ENEMY_SUBSTATUS_4 -.substatus4opp db ENEMY_SUBSTATUS_4, PLAYER_SUBSTATUS_4 -.substatus5 db PLAYER_SUBSTATUS_5, ENEMY_SUBSTATUS_5 -.substatus5opp db ENEMY_SUBSTATUS_5, PLAYER_SUBSTATUS_5 -.status db PLAYER_STATUS, ENEMY_STATUS -.statusopp db ENEMY_STATUS, PLAYER_STATUS -.animation db PLAYER_MOVE_ANIMATION, ENEMY_MOVE_ANIMATION -.effect db PLAYER_MOVE_EFFECT, ENEMY_MOVE_EFFECT -.power db PLAYER_MOVE_POWER, ENEMY_MOVE_POWER -.type db PLAYER_MOVE_TYPE, ENEMY_MOVE_TYPE -.curmove db PLAYER_CUR_MOVE, ENEMY_CUR_MOVE -.lastcounter db PLAYER_COUNTER_MOVE, ENEMY_COUNTER_MOVE -.lastcounteropp db ENEMY_COUNTER_MOVE, PLAYER_COUNTER_MOVE -.lastmove db PLAYER_LAST_MOVE, ENEMY_LAST_MOVE -.lastmoveopp db ENEMY_LAST_MOVE, PLAYER_LAST_MOVE - -.vars - dw wPlayerSubStatus1, wEnemySubStatus1 - dw wPlayerSubStatus2, wEnemySubStatus2 - dw wPlayerSubStatus3, wEnemySubStatus3 - dw wPlayerSubStatus4, wEnemySubStatus4 - dw wPlayerSubStatus5, wEnemySubStatus5 - dw wBattleMonStatus, wEnemyMonStatus - dw wPlayerMoveStructAnimation, wEnemyMoveStructAnimation - dw wPlayerMoveStructEffect, wEnemyMoveStructEffect - dw wPlayerMoveStructPower, wEnemyMoveStructPower - dw wPlayerMoveStructType, wEnemyMoveStructType - dw wCurPlayerMove, wCurEnemyMove - dw wLastEnemyCounterMove, wLastPlayerCounterMove - dw wLastPlayerMove, wLastEnemyMove - - db $23 ; ??? +INCLUDE "home/battle_vars.asm" FarCopyRadioText:: + inc hl ldh a, [hROMBank] push af ld a, [hli] @@ -200,62 +170,70 @@ FarCopyRadioText:: ld a, d ld h, a ld de, wcef7 - ld bc, $28 + ld bc, 2 * SCREEN_WIDTH call CopyBytes pop af ldh [hROMBank], a ld [MBC3RomBank], a ret -StdBattleTextBox:: -GLOBAL BattleText + +StdBattleTextbox:: +; Open a textbox and print battle text at 20:hl. + ldh a, [hROMBank] push af - ld a, BANK(BattleText) ; $40 + + ld a, BANK(BattleText) rst Bankswitch + call PrintText + pop af rst Bankswitch ret GetBattleAnimPointer:: - -GLOBAL BattleAnimations -GLOBAL BattleAnimCommands - - ld a, BANK(BattleAnimations) ; $32 + ld a, BANK(BattleAnimations) rst Bankswitch + ld a, [hli] ld [wca10], a ld a, [hl] ld [wca11], a - ld a, BANK(BattleAnimCommands) ; $33 + + ; ClearBattleAnims is the only function that calls this... + ld a, BANK(ClearBattleAnims) rst Bankswitch + ret GetBattleAnimByte:: push hl push de + ld hl, wca10 ld e, [hl] inc hl ld d, [hl] - ld a, BANK(BattleAnimations) ; $32 + ld a, BANK(BattleAnimations) rst Bankswitch ld a, [de] ld [wca17], a inc de - ld a, BANK(BattleAnimCommands) ; $33 + ld a, BANK(ClearBattleAnims) rst Bankswitch ld [hl], d dec hl ld [hl], e + pop de pop hl + ld a, [wca17] ret diff --git a/home/battle_vars.asm b/home/battle_vars.asm new file mode 100755 index 00000000..29acb040 --- /dev/null +++ b/home/battle_vars.asm @@ -0,0 +1,111 @@ +GetBattleVar:: +; Preserves hl. + push hl + call GetBattleVarAddr + pop hl + ret + +GetBattleVarAddr:: +; Get variable from pair a, depending on whose turn it is. +; There are 21 variable pairs. + + push bc + + ld hl, BattleVarPairs + ld c, a + ld b, 0 + add hl, bc + add hl, bc + + ld a, [hli] + ld h, [hl] + ld l, a + +; Enemy turn uses the second byte instead. +; This lets battle variable calls be side-neutral. + ldh a, [hBattleTurn] + and a + jr z, .getvar + inc hl + +.getvar +; var id + ld a, [hl] + ld c, a + ld b, 0 + + ld hl, BattleVarLocations + add hl, bc + add hl, bc + + ld a, [hli] + ld h, [hl] + ld l, a + + ld a, [hl] + + pop bc + ret + +BattleVarPairs: +; entries correspond to BATTLE_VARS_* constants + dw .Substatus1 + dw .Substatus2 + dw .Substatus3 + dw .Substatus4 + dw .Substatus5 + dw .Substatus1Opp + dw .Substatus2Opp + dw .Substatus3Opp + dw .Substatus4Opp + dw .Substatus5Opp + dw .Status + dw .StatusOpp + dw .MoveAnim + dw .MoveEffect + dw .MovePower + dw .MoveType + dw .CurMove + dw .LastCounter + dw .LastCounterOpp + dw .LastMove + dw .LastMoveOpp + +; player enemy +.Substatus1: db PLAYER_SUBSTATUS_1, ENEMY_SUBSTATUS_1 +.Substatus1Opp: db ENEMY_SUBSTATUS_1, PLAYER_SUBSTATUS_1 +.Substatus2: db PLAYER_SUBSTATUS_2, ENEMY_SUBSTATUS_2 +.Substatus2Opp: db ENEMY_SUBSTATUS_2, PLAYER_SUBSTATUS_2 +.Substatus3: db PLAYER_SUBSTATUS_3, ENEMY_SUBSTATUS_3 +.Substatus3Opp: db ENEMY_SUBSTATUS_3, PLAYER_SUBSTATUS_3 +.Substatus4: db PLAYER_SUBSTATUS_4, ENEMY_SUBSTATUS_4 +.Substatus4Opp: db ENEMY_SUBSTATUS_4, PLAYER_SUBSTATUS_4 +.Substatus5: db PLAYER_SUBSTATUS_5, ENEMY_SUBSTATUS_5 +.Substatus5Opp: db ENEMY_SUBSTATUS_5, PLAYER_SUBSTATUS_5 +.Status: db PLAYER_STATUS, ENEMY_STATUS +.StatusOpp: db ENEMY_STATUS, PLAYER_STATUS +.MoveAnim: db PLAYER_MOVE_ANIMATION, ENEMY_MOVE_ANIMATION +.MoveEffect: db PLAYER_MOVE_EFFECT, ENEMY_MOVE_EFFECT +.MovePower: db PLAYER_MOVE_POWER, ENEMY_MOVE_POWER +.MoveType: db PLAYER_MOVE_TYPE, ENEMY_MOVE_TYPE +.CurMove: db PLAYER_CUR_MOVE, ENEMY_CUR_MOVE +.LastCounter: db PLAYER_COUNTER_MOVE, ENEMY_COUNTER_MOVE +.LastCounterOpp: db ENEMY_COUNTER_MOVE, PLAYER_COUNTER_MOVE +.LastMove: db PLAYER_LAST_MOVE, ENEMY_LAST_MOVE +.LastMoveOpp: db ENEMY_LAST_MOVE, PLAYER_LAST_MOVE + +BattleVarLocations: +; entries correspond to PLAYER_* and ENEMY_* constants + dw wPlayerSubStatus1, wEnemySubStatus1 + dw wPlayerSubStatus2, wEnemySubStatus2 + dw wPlayerSubStatus3, wEnemySubStatus3 + dw wPlayerSubStatus4, wEnemySubStatus4 + dw wPlayerSubStatus5, wEnemySubStatus5 + dw wBattleMonStatus, wEnemyMonStatus + dw wPlayerMoveStructAnimation, wEnemyMoveStructAnimation + dw wPlayerMoveStructEffect, wEnemyMoveStructEffect + dw wPlayerMoveStructPower, wEnemyMoveStructPower + dw wPlayerMoveStructType, wEnemyMoveStructType + dw wCurPlayerMove, wCurEnemyMove + dw wLastEnemyCounterMove, wLastPlayerCounterMove + dw wLastPlayerMove, wLastEnemyMove diff --git a/home/copy.asm b/home/copy.asm index e319cd6b..838bb52d 100644 --- a/home/copy.asm +++ b/home/copy.asm @@ -1,53 +1,70 @@ -CopyBytes:: ; 311a (0:311a) - inc b - inc c - jr .asm_3121 -.asm_311e +CopyBytes:: +; copy bc bytes from hl to de + inc b ; we bail the moment b hits 0, so include the last run + inc c ; same thing; include last byte + jr .HandleLoop +.CopyByte: ld a, [hli] ld [de], a inc de -.asm_3121 +.HandleLoop: dec c - jr nz, .asm_311e + jr nz, .CopyByte dec b - jr nz, .asm_311e + jr nz, .CopyByte ret -GetFarByte:: ; 3128 (0:3128) +GetFarByte:: +; retrieve a single byte from a:hl, and return it in a. + ; bankswitch to new bank ld [wBuffer], a ldh a, [hROMBank] push af ld a, [wBuffer] rst Bankswitch + + ; get byte from new bank ld a, [hl] ld [wBuffer], a + + ; bankswitch to previous bank pop af rst Bankswitch + + ; return retrieved value in a ld a, [wBuffer] ret -GetFarHalfword:: ; 313c (0:313c) +GetFarHalfword:: +; retrieve a halfword from a:hl, and return it in hl. + ; bankswitch to new bank ld [wBuffer], a ldh a, [hROMBank] push af ld a, [wBuffer] rst Bankswitch + + ; get halfword from new bank, put it in hl ld a, [hli] ld h, [hl] ld l, a + + ; bankswitch to previous bank and return pop af rst Bankswitch ret -ByteFill:: ; 314c (0:314c) - inc b - inc c - jr .asm_3151 -.asm_3150 + +ByteFill:: +; fill bc bytes with the value of a, starting at hl + inc b ; we bail the moment b hits 0, so include the last run + inc c ; same thing; include last byte + jr .HandleLoop +.PutByte: ld [hli], a -.asm_3151 +.HandleLoop: dec c - jr nz, .asm_3150 + jr nz, .PutByte dec b - jr nz, .asm_3150 + jr nz, .PutByte ret diff --git a/home/copy_tilemap.asm b/home/copy_tilemap.asm index c63023e6..9ebcc04c 100755 --- a/home/copy_tilemap.asm +++ b/home/copy_tilemap.asm @@ -1,20 +1,21 @@ -LoadTileMapToTempTileMap:: -; Load wTileMap into wTempTileMap +LoadTilemapToTempTilemap:: +; Load wTilemap into wTempTileMap hlcoord 0, 0 decoord 0, 0, wTempTileMap - ld bc, wTileMapEnd - wTileMap + ld bc, wTilemapEnd - wTilemap jp CopyBytes -Call_LoadTempTileMapToTileMap:: +SafeLoadTempTilemapToTilemap:: xor a ldh [hBGMapMode], a - call LoadTempTileMapToTileMap + call LoadTempTilemapToTilemap ld a, 1 ldh [hBGMapMode], a ret -LoadTempTileMapToTileMap:: +LoadTempTilemapToTilemap:: +; Load wTempTilemap into wTilemap hlcoord 0, 0, wTempTileMap decoord 0, 0 - ld bc, wTileMapEnd - wTileMap + ld bc, wTilemapEnd - wTilemap jp CopyBytes
\ No newline at end of file diff --git a/home/decompress.asm b/home/decompress.asm index 5e36d828..1d555529 100644 --- a/home/decompress.asm +++ b/home/decompress.asm @@ -1,4 +1,4 @@ -FarDecompress:: ; b40 +FarDecompress:: ; Decompress graphics data from a:hl to de. ld [wLZBank], a @@ -12,10 +12,8 @@ FarDecompress:: ; b40 pop af rst Bankswitch ret -; b50 - -Decompress:: ; b50 +Decompress:: ; Pokemon Gold and Silver use an lz variant for compression. ; This is mainly (but not necessarily) used for graphics. @@ -34,13 +32,11 @@ LZ_LEN EQU %00011111 ; length n (bits 0-4) ; Commands: - LZ_LITERAL EQU 0 << 5 ; Read literal data for n bytes. LZ_ITERATE EQU 1 << 5 ; Write the same byte for n bytes. LZ_ALTERNATE EQU 2 << 5 ; Alternate two bytes for n bytes. LZ_ZERO EQU 3 << 5 ; Write 0 for n bytes. - ; Another class of commands reuses data from the decompressed output. LZ_RW EQU 2 + 5 ; bit @@ -125,7 +121,6 @@ LZ_LONG_HI EQU %00000011 ; read at least 1 byte inc c - .command ; Increment loop counts. ; We bail the moment they hit 0. @@ -144,7 +139,6 @@ LZ_LONG_HI EQU %00000011 cp LZ_ZERO jr z, .Zero - .Literal ; Read literal data for bc bytes. .lloop @@ -159,8 +153,7 @@ LZ_LONG_HI EQU %00000011 inc de jr .lloop - -.Iter +.Iter: ; Write the same byte for bc bytes. ld a, [hli] @@ -175,8 +168,7 @@ LZ_LONG_HI EQU %00000011 inc de jr .iloop - -.Alt +.Alt: ; Alternate two bytes for bc bytes. dec c jr nz, .anext1 @@ -205,8 +197,7 @@ LZ_LONG_HI EQU %00000011 inc hl jr .Main - -.Zero +.Zero: ; Write 0 for bc bytes. xor a @@ -221,7 +212,6 @@ LZ_LONG_HI EQU %00000011 inc de jr .zloop - .rewrite ; Repeat decompressed data from output. push hl @@ -275,8 +265,7 @@ LZ_LONG_HI EQU %00000011 ; More practically, LZ_LONG is not recursive. ; For now, it defaults to LZ_REPEAT. - -.Repeat +.Repeat: ; Copy decompressed data for bc bytes. dec c jr nz, .rnext @@ -289,8 +278,7 @@ LZ_LONG_HI EQU %00000011 inc de jr .Repeat - -.Flip +.Flip: ; Copy bitflipped decompressed data for bc bytes. dec c jr nz, .fnext @@ -315,8 +303,7 @@ LZ_LONG_HI EQU %00000011 inc de jr .Flip - -.Reverse +.Reverse: ; Copy reversed decompressed data for bc bytes. dec c jr nz, .rvnext @@ -330,7 +317,6 @@ LZ_LONG_HI EQU %00000011 inc de jr .Reverse - .donerw pop hl @@ -340,4 +326,3 @@ LZ_LONG_HI EQU %00000011 .next inc hl jp .Main -; c2f diff --git a/home/fade.asm b/home/fade.asm index f5851099..357047b6 100644 --- a/home/fade.asm +++ b/home/fade.asm @@ -1,6 +1,6 @@ ; Functions to fade the screen in and out. -Unreferenced_Function48c:: +Unreferenced_Function360:: ; TimeOfDayFade ld a, [wTimeOfDayPal] ld b, a diff --git a/home/farcall.asm b/home/farcall.asm index f42133b3..1c8b6f3f 100644 --- a/home/farcall.asm +++ b/home/farcall.asm @@ -1,22 +1,33 @@ -FarCall_hl:: ; 2e27 (0:2e27) +FarCall_hl:: +; Call a:hl. +; Preserves other registers. + ld [wBuffer], a ldh a, [hROMBank] push af ld a, [wBuffer] rst Bankswitch - call ._hl_ + call FarCall_JumpToHL + +ReturnFarCall:: +; We want to retain the contents of f. +; To do this, we can pop to bc instead of af. + ld a, b ld [wFarCallBCBuffer], a ld a, c ld [wFarCallBCBuffer + 1], a + +; Restore the working bank. pop bc ld a, b rst Bankswitch + ld a, [wFarCallBCBuffer] ld b, a ld a, [wFarCallBCBuffer + 1] ld c, a ret -._hl_ +FarCall_JumpToHL:: jp hl diff --git a/home/flag.asm b/home/flag.asm index 5eef8fe1..95117377 100644 --- a/home/flag.asm +++ b/home/flag.asm @@ -1,27 +1,27 @@ -ResetMapBufferEventFlags:: ; 2f10 (0:2f10) +ResetMapBufferEventFlags:: xor a ld hl, wEventFlags ld [hli], a ret -ResetBikeFlags:: ; 2f16 (0:2f16) +ResetBikeFlags:: xor a ld hl, wBikeFlags ld [hli], a ld [hl], a ret -ResetFlashIfOutOfCave:: ; 2f1d (0:2f1d) +ResetFlashIfOutOfCave:: ld a, [wPermission] - cp $2 - jr z, .turn_off_lights - cp $1 - jr z, .turn_off_lights + cp ROUTE + jr z, .outdoors + cp TOWN + jr z, .outdoors ret -.turn_off_lights +.outdoors ld hl, wStatusFlags - res 2, [hl] ; FLASH + res STATUSFLAGS_FLASH_F, [hl] ret EventFlagAction:: @@ -29,28 +29,26 @@ EventFlagAction:: call FlagAction ret -FlagAction:: ; 2f36 (0:2f36) +FlagAction:: ; Perform action b on bit de in flag array hl. ; inputs: ; b: function -; 0 clear bit -; 1 set bit -; 2 check bit +; 0 RESET_FLAG clear bit +; 1 SET_FLAG set bit +; 2 CHECK_FLAG check bit ; de: bit number -; hl: index within bit table +; hl: pointer to the flag array ; get index within the byte ld a, e and 7 ; shift de right by three bits (get the index within memory) +rept 3 srl d rr e - srl d - rr e - srl d - rr e +endr add hl, de ; implement a decoder @@ -71,9 +69,9 @@ FlagAction:: ; 2f36 (0:2f36) ; check b's value: 0, 1, 2 ld a, b - cp 1 - jr c, .clearbit ; 0 - jr z, .setbit ; 1 + cp SET_FLAG + jr c, .clearbit ; RESET_FLAG + jr z, .setbit ; SET_FLAG ; check bit ld a, [hl] @@ -108,11 +106,11 @@ Unreferenced_CheckBPressedDebug:: ; Used in debug ROMs to walk through walls and avoid encounters. ld a, [wDebugFlags] - bit 1, a + bit DEBUG_FIELD_F, a ret z - + ldh a, [hJoyDown] - bit 1, a + bit B_BUTTON_F, a ret xor_a:: @@ -129,4 +127,4 @@ Unreferenced_CheckFieldDebug:: ld hl, wDebugFlags bit DEBUG_FIELD_F, [hl] pop hl - ret
\ No newline at end of file + ret diff --git a/home/game_time.asm b/home/game_time.asm index 01ad750b..86435991 100644 --- a/home/game_time.asm +++ b/home/game_time.asm @@ -1,4 +1,4 @@ -ResetGameTime:: ; 1ee6 (0:1ee6) +ResetGameTime:: xor a ld [wGameTimeCap], a ld [wGameTimeHours], a @@ -8,67 +8,93 @@ ResetGameTime:: ; 1ee6 (0:1ee6) ld [wGameTimeFrames], a ret -GameTimer:: ; 1efa (0:1efa) +GameTimer:: nop + +UpdateGameTimer:: +; Increment the game timer by one frame. +; The game timer is capped at 999:59:59.00. + +; Don't update if game logic is paused. ld a, [wGameLogicPaused] and a ret nz +; Is the timer paused? ld hl, wGameTimerPause - bit 0, [hl] + bit GAMETIMERPAUSE_TIMER_PAUSED_F, [hl] ret z +; Is the timer already capped? ld hl, wGameTimeCap bit 0, [hl] ret nz +; +1 frame ld hl, wGameTimeFrames ld a, [hl] inc a - cp 60 + + cp 60 ; frames/second jr nc, .second + ld [hl], a ret .second xor a ld [hl], a + +; +1 second ld hl, wGameTimeSeconds ld a, [hl] inc a - cp 60 + + cp 60 ; seconds/minute jr nc, .minute + ld [hl], a ret .minute xor a ld [hl], a + +; +1 minute ld hl, wGameTimeMinutes ld a, [hl] inc a - cp 60 + + cp 60 ; minutes/hour jr nc, .hour + ld [hl], a ret .hour xor a ld [hl], a + +; +1 hour ld a, [wGameTimeHours] ld h, a ld a, [wGameTimeHours + 1] ld l, a inc hl + +; Cap the timer after 1000 hours. ld a, h - cp 1000 / $100 + cp HIGH(1000) jr c, .ok + ld a, l - cp 1000 % $100 + cp LOW(1000) jr c, .ok + ld hl, wGameTimeCap set 0, [hl] - ld a, 59 + + ld a, 59 ; 999:59:59.00 ld [wGameTimeMinutes], a ld [wGameTimeSeconds], a ret diff --git a/home/gfx.asm b/home/gfx.asm index 0067c85f..14a46844 100644 --- a/home/gfx.asm +++ b/home/gfx.asm @@ -58,56 +58,71 @@ DecompressRequest2bpp:: call CloseSRAM ret -FarCopyBytes:: ; dcd (0:0dcd) +FarCopyBytes:: +; copy bc bytes from a:hl to de + ld [wBuffer], a ldh a, [hROMBank] push af ld a, [wBuffer] rst Bankswitch + call CopyBytes + pop af rst Bankswitch ret -FarCopyBytesDouble:: ; ddd (0:0ddd) + +FarCopyBytesDouble: +; Copy bc bytes from a:hl to bc*2 bytes at de, +; doubling each byte in the process. + ld [wBuffer], a ldh a, [hROMBank] push af ld a, [wBuffer] 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 .enter_loop + jr .dec -.copy +.loop ld a, [de] inc de ld [hli], a ld [hli], a -.enter_loop +.dec dec c - jr nz, .copy + jr nz, .loop dec b - jr nz, .copy + jr nz, .loop + pop af rst Bankswitch ret -Request2bpp:: ; dfe (0:0dfe) +Request2bpp:: +; Load 2bpp at b:de to occupy c tiles of hl. ldh a, [hBGMapMode] push af xor a ldh [hBGMapMode], a + ldh a, [hROMBank] push af ld a, b rst Bankswitch + ld a, e ld [wRequested2bppSource], a ld a, d @@ -118,34 +133,41 @@ Request2bpp:: ; dfe (0:0dfe) ld [wRequested2bppDest + 1], a .check ld a, c - cp $8 ; TilesPerCycle + cp 8 ; TilesPerCycle jr nc, .cycle + ld [wRequested2bpp], a call DelayFrame + pop af rst Bankswitch + pop af ldh [hBGMapMode], a ret .cycle - ld a, $8 ; TilesPerCycle + ld a, 8 ; TilesPerCycle ld [wRequested2bpp], a + call DelayFrame ld a, c - sub $8 ; TilesPerCycle + sub 8 ; TilesPerCycle ld c, a jr .check -Request1bpp:: ; e38 (0:0e38) +Request1bpp:: +; Load 1bpp at b:de to occupy c tiles of hl. ldh a, [hBGMapMode] push af xor a ldh [hBGMapMode], a + ldh a, [hROMBank] push af ld a, b rst Bankswitch + ld a, e ld [wRequested1bppSource], a ld a, d @@ -156,35 +178,46 @@ Request1bpp:: ; e38 (0:0e38) ld [wRequested1bppDest + 1], a .check ld a, c - cp $8 ; TilesPerCycle + cp 8 ; TilesPerCycle jr nc, .cycle + ld [wRequested1bpp], a call DelayFrame + pop af rst Bankswitch + pop af ldh [hBGMapMode], a ret .cycle - ld a, $8 ; TilesPerCycle + ld a, 8 ; TilesPerCycle ld [wRequested1bpp], a + call DelayFrame ld a, c - sub $8 ; TilesPerCycle + sub 8 ; TilesPerCycle ld c, a jr .check Get2bpp:: ldh a, [rLCDC] - bit 7, a + bit rLCDC_ENABLE, a jp nz, Request2bpp -Copy2bpp:: + +Copy2bpp: +; 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 @@ -194,19 +227,27 @@ Copy2bpp:: and c ld c, a pop af + jp FarCopyBytes Get1bpp:: ldh a, [rLCDC] - bit 7, a + bit rLCDC_ENABLE, a jp nz, Request1bpp + Copy1bpp:: +; 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 h, 0 ld l, c add hl, hl add hl, hl @@ -214,18 +255,24 @@ Copy1bpp:: ld b, h ld c, l pop af + pop hl jp FarCopyBytesDouble -Functionea6:: +Function_ea6:: ldh a, [rLCDC] add a jp c, Request2bpp -Functioneac:: + +Function_eac:: push de push hl + +; bank ld a, b - ld h, $0 + +; bc = c * $10 + ld h, 0 ld l, c add hl, hl add hl, hl @@ -234,5 +281,6 @@ Functioneac:: ld b, h ld c, l pop de + pop hl jp FarCopyBytes diff --git a/home/init.asm b/home/init.asm index b06820f0..82b3cf7e 100644 --- a/home/init.asm +++ b/home/init.asm @@ -1,25 +1,33 @@ -Reset:: ; 5b0 (0:05b0) - call MapSetup_Sound_Off +Reset:: + call InitSound xor a ldh [hMapAnims], a call ClearPalettes ei + ld hl, wd8ba set 7, [hl] + ld c, 32 call DelayFrames + jr Init -_Start:: ; 5c6 (0:05c6) + +_Start:: cp $11 jr z, .cgb xor a jr .load + .cgb ld a, $1 + .load ldh [hCGB], a -Init:: ; 5d1 (0:05d1) + +Init:: di + xor a ldh [rIF], a ldh [rIE], a @@ -36,21 +44,23 @@ Init:: ; 5d1 (0:05d1) ldh [rTMA], a ldh [rTAC], a ld [wceeb], a - ld a, $4 + + ld a, %100 ; Start timer at 4096Hz ldh [rTAC], a + .wait ldh a, [rLY] - cp 145 + cp LY_VBLANK + 1 jr nz, .wait xor a ldh [rLCDC], a -; Clear WRAM - ld hl, wMusicPlaying +; Clear WRAM bank 0 + ld hl, WRAM0_Begin ld bc, $2000 -.ByteFill - ld [hl], $0 +.ByteFill: + ld [hl], 0 inc hl dec bc ld a, b @@ -71,10 +81,10 @@ Init:: ; 5d1 (0:05d1) call ClearSprites - ld a, BANK(LoadPushOAM) + ld a, BANK(WriteOAMDMACodeToHRAM) rst Bankswitch - call LoadPushOAM + call WriteOAMDMACodeToHRAM xor a ldh [hMapAnims], a @@ -89,11 +99,11 @@ Init:: ; 5d1 (0:05d1) ldh [hWY], a ldh [rWY], a - ld a, $7 + ld a, 7 ldh [hWX], a ldh [rWX], a - ld a, -1 + ld a, CONNECTION_NOT_ESTABLISHED ldh [hLinkPlayerNumber], a ld h, $98 @@ -103,9 +113,9 @@ Init:: ; 5d1 (0:05d1) callfar InitCGBPals - ld a, $9c + ld a, HIGH(vBGMap1) ldh [hBGMapAddress + 1], a - xor a + xor a ; LOW(vBGMap1) ldh [hBGMapAddress], a farcall StartClock @@ -116,7 +126,7 @@ Init:: ; 5d1 (0:05d1) ld [MBC3LatchClock], a ld [MBC3SRamEnable], a - ld a, %11100011 + ld a, LCDC_DEFAULT ; %11100011 ; LCD on ; Win tilemap 1 ; Win on @@ -133,26 +143,25 @@ Init:: ; 5d1 (0:05d1) call DelayFrame - ld a, $30 - call Predef + predef InitSGBBorder ; SGB init - call MapSetup_Sound_Off + call InitSound xor a ld [wMapMusic], a jp GameInit -ClearVRAM:: ; 68e (0:068e) - ld hl, $8000 - ld bc, $2000 +ClearVRAM:: + ld hl, VRAM_Begin + ld bc, VRAM_End - VRAM_Begin xor a call ByteFill ret -BlankBGMap:: ; 699 (0:0699) +BlankBGMap:: ld a, $7f jr asm_69e -FillBGMap:: ; 69d +FillBGMap:: ld a, l asm_69e ld de, $400 diff --git a/home/item.asm b/home/item.asm index 3c1d3357..9e15879d 100644 --- a/home/item.asm +++ b/home/item.asm @@ -67,4 +67,4 @@ CheckItem:: pop bc pop de pop hl - ret
\ No newline at end of file + ret diff --git a/home/joypad.asm b/home/joypad.asm index 8f8e9b2f..c9b9e56f 100644 --- a/home/joypad.asm +++ b/home/joypad.asm @@ -1,83 +1,159 @@ -Joypad:: ; 8df (0:08df) +Joypad:: +; Replaced by Joypad, called from VBlank instead of the useless +; joypad interrupt. + +; This is a placeholder in case the interrupt is somehow enabled. reti ClearJoypad:: xor a +; Pressed this frame (delta) ldh [hJoyPressed], a +; Currently pressed ldh [hJoyDown], a ret -UpdateJoypad:: ; 8e6 (0:08e6) +UpdateJoypad:: +; This is called automatically every frame in VBlank. +; Read the joypad register and translate it to something more +; workable for use in-game. There are 8 buttons, so we can use +; one byte to contain all player input. + +; Updates: + +; hJoypadReleased: released this frame (delta) +; hJoypadPressed: pressed this frame (delta) +; hJoypadDown: currently pressed +; hJoypadSum: pressed so far + +; Any of these three bits can be used to disable input. ld a, [wd8ba] - and $d0 + and %11010000 ret nz + +; If we're saving, input is disabled. ld a, [wGameLogicPaused] and a ret nz - ld a, $20 + +; We can only get four inputs at a time. +; We take d-pad first for no particular reason. + ld a, R_DPAD ldh [rJOYP], a +; Read twice to give the request time to take. ldh a, [rJOYP] ldh a, [rJOYP] + +; The Joypad register output is in the lo nybble (inversed). +; We make the hi nybble of our new container d-pad input. cpl and $f swap a + +; We'll keep this in b for now. ld b, a - ld a, $10 + +; Buttons make 8 total inputs (A, B, Select, Start). +; We can fit this into one byte. + ld a, R_BUTTONS ldh [rJOYP], a +; Wait for input to stabilize. +rept 6 ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] - ldh a, [rJOYP] +endr +; Buttons take the lo nybble. cpl and $f or b ld b, a + +; Reset the joypad register since we're done with it. ld a, $30 ldh [rJOYP], a - ldh a, [hJoypadDown] + +; To get the delta we xor the last frame's input with the new one. + ldh a, [hJoypadDown] ; last frame ld e, a xor b ld d, a +; Released this frame: and e ldh [hJoypadReleased], a +; Pressed this frame: ld a, d and b ldh [hJoypadPressed], a + +; Add any new presses to the list of collective presses: ld c, a ldh a, [hJoypadSum] or c ldh [hJoypadSum], a + +; Currently pressed: ld a, b ldh [hJoypadDown], a - and $f - cp $f + +; Now that we have the input, we can do stuff with it. + +; For example, soft reset: + and A_BUTTON | B_BUTTON | SELECT | START + cp A_BUTTON | B_BUTTON | SELECT | START jp z, Reset + ret -GetJoypad:: ; 935 (0:0935) +GetJoypad:: +; Update mirror joypad input from hJoypadDown (real input) + +; hJoyReleased: released this frame (delta) +; hJoyPressed: pressed this frame (delta) +; hJoyDown: currently pressed + +; bit 0 A +; 1 B +; 2 SELECT +; 3 START +; 4 RIGHT +; 5 LEFT +; 6 UP +; 7 DOWN + push af push hl push de push bc + +; The player input can be automated using an input stream. +; See more below. ld a, [wInputType] - cp $ff + cp AUTO_INPUT jr z, .auto - ldh a, [hJoypadDown] + +; To get deltas, take this and last frame's input. + ldh a, [hJoypadDown] ; real input ld b, a - ldh a, [hJoyDown] + ldh a, [hJoyDown] ; last frame mirror ld e, a + +; Released this frame: xor b ld d, a and e ldh [hJoyReleased], a + +; Pressed this frame: ld a, d and b ldh [hJoyPressed], a + +; It looks like the collective presses got commented out here. ld c, a + +; Currently pressed: ld a, b - ldh [hJoyDown], a + ldh [hJoyDown], a ; frame input + .quit pop bc pop de @@ -86,17 +162,28 @@ GetJoypad:: ; 935 (0:0935) ret .auto +; Use a predetermined input stream (used in the catching tutorial). + +; Stream format: [input][duration] +; A value of $ff will immediately end the stream. + +; Read from the input stream. ldh a, [hROMBank] push af ld a, [wAutoInputBank] rst Bankswitch + ld hl, wAutoInputAddress ld a, [hli] ld h, [hl] ld l, a + +; We only update when the input duration has expired. ld a, [wAutoInputLength] and a jr z, .updateauto + +; Until then, don't change anything. dec a ld [wAutoInputLength], a pop af @@ -104,20 +191,26 @@ GetJoypad:: ; 935 (0:0935) jr .quit .updateauto +; An input of $ff will end the stream. ld a, [hli] - cp $ff + cp -1 jr z, .stopauto ld b, a + +; A duration of $ff will end the stream indefinitely. ld a, [hli] ld [wAutoInputLength], a - cp $ff + cp -1 jr nz, .next + +; The current input is overwritten. dec hl dec hl - ld b, $0 + ld b, NO_INPUT jr .finishauto .next +; On to the next input... ld a, l ld [wAutoInputAddress], a ld a, h @@ -126,43 +219,53 @@ GetJoypad:: ; 935 (0:0935) .stopauto call StopAutoInput - ld b, $0 + ld b, NO_INPUT + .finishauto pop af rst Bankswitch ld a, b - ldh [hJoyPressed], a - ldh [hJoyDown], a + ldh [hJoyPressed], a ; pressed + ldh [hJoyDown], a ; input jr .quit StartAutoInput:: +; Start reading automated input stream at a:hl. + ld [wAutoInputBank], a ld a, l ld [wAutoInputAddress], a ld a, h ld [wAutoInputAddress + 1], a +; Start reading the stream immediately. xor a ld [wAutoInputLength], a +; Reset input mirrors. xor a - ldh [hJoyPressed], a - ldh [hJoyReleased], a - ldh [hJoyDown], a - ld a, $ff + ldh [hJoyPressed], a ; pressed this frame + ldh [hJoyReleased], a ; released this frame + ldh [hJoyDown], a ; currently pressed + + ld a, AUTO_INPUT ld [wInputType], a ret -StopAutoInput:: ; 9bb (0:09bb) +StopAutoInput:: +; Clear variables related to automated input. xor a ld [wAutoInputBank], a ld [wAutoInputAddress], a ld [wAutoInputAddress + 1], a ld [wAutoInputLength], a +; Back to normal input. ld [wInputType], a ret JoyTitleScreenInput:: .loop + call DelayFrame + push bc call JoyTextDelay pop bc @@ -186,18 +289,19 @@ JoyTitleScreenInput:: ret JoyWaitAorB:: +.loop call DelayFrame call GetJoypad ldh a, [hJoyPressed] and A_BUTTON | B_BUTTON ret nz - call RTC - jr JoyWaitAorB + call UpdateTimeAndPals + jr .loop WaitButton:: ldh a, [hOAMUpdate] push af - ld a, $1 + ld a, 1 ldh [hOAMUpdate], a call WaitBGMap call JoyWaitAorB @@ -205,7 +309,7 @@ WaitButton:: ldh [hOAMUpdate], a ret -JoyTextDelay:: ; a08 (0:0a08) +JoyTextDelay:: call GetJoypad ldh a, [hInMenu] and a @@ -235,23 +339,32 @@ JoyTextDelay:: ; a08 (0:0a08) ret WaitPressAorB_BlinkCursor:: +; Show a blinking cursor in the lower right-hand +; corner of a textbox and wait until A or B is +; pressed. +; +; NOTE: The cursor has to be shown before calling +; this function or no cursor will be shown at all. ldh a, [hMapObjectIndexBuffer] push af ldh a, [hObjectStructIndexBuffer] push af xor a ldh [hMapObjectIndexBuffer], a - ld a, $6 + ld a, 6 ldh [hObjectStructIndexBuffer], a + .loop push hl hlcoord 18, 17 call BlinkCursor pop hl + call JoyTextDelay ldh a, [hJoyLast] and A_BUTTON | B_BUTTON jr z, .loop + pop af ldh [hObjectStructIndexBuffer], a pop af @@ -266,62 +379,66 @@ SimpleWaitPressAorB:: jr z, .loop ret -ButtonSound:: +PromptButton:: +; Show a blinking cursor in the lower right-hand +; corner of a textbox and wait until A or B is +; pressed, afterwards, play a sound. ld a, [wLinkMode] and a - jr nz, .link_delay - call JoyWaitInput + jr nz, .link + call .wait_input push de ld de, SFX_READ_TEXT_2 call PlaySFX pop de ret -.link_delay +.link ld c, 65 jp DelayFrames -JoyWaitInput:: ; a77 (0:0a77) +.wait_input ldh a, [hOAMUpdate] push af ld a, $1 ldh [hOAMUpdate], a ld a, [wInputType] or a - jr z, .wait_loop - farcall DudeAutoInput_A + jr z, .input_wait_loop + farcall _DudeAutoInput_A -.wait_loop - call JoyBlinkCursor +.input_wait_loop + call .blink_cursor call JoyTextDelay ldh a, [hJoyPressed] and A_BUTTON | B_BUTTON jr nz, .received_input - call RTC + call UpdateTimeAndPals ld a, $1 ldh [hBGMapMode], a call DelayFrame - jr .wait_loop + jr .input_wait_loop .received_input pop af ldh [hOAMUpdate], a ret -JoyBlinkCursor:: ; aa6 (0:0aa6) +.blink_cursor ldh a, [hVBlankCounter] - and $10 + and %00010000 ; bit 4, a jr z, .cursor_off ld a, "▼" jr .load_cursor_state .cursor_off ld a, "─" + .load_cursor_state ldcoord_a 18, 17 ret -BlinkCursor:: ; ab6 (0:0ab6) +BlinkCursor:: push bc ld a, [hl] ld b, a diff --git a/home/lcd.asm b/home/lcd.asm index 6ccfaece..4ab79019 100644 --- a/home/lcd.asm +++ b/home/lcd.asm @@ -1,19 +1,24 @@ -LCD:: ; 41b (0:041b) +; LCD handling + +LCD:: push af ldh a, [hLCDCPointer] and a jr z, .done + +; At this point it's assumed we're in WRAM bank 5! push hl ldh a, [rLY] ld l, a - ld h, wLYOverrides >> 8 + ld h, HIGH(wLYOverrides) ld h, [hl] ldh a, [hLCDCPointer] ld l, a ld a, h - ld h, rSCY >> 8 + ld h, HIGH(rSCY) ld [hl], a pop hl + .done pop af reti @@ -23,7 +28,7 @@ DisableLCD:: ; Don't need to do anything if the LCD is already off ldh a, [rLCDC] - bit 7, a + bit rLCDC_ENABLE, a ret z xor a @@ -32,17 +37,17 @@ DisableLCD:: ld b, a ; Disable VBlank - res 0, a + res VBLANK, a ldh [rIE], a .wait ; Wait until VBlank would normally happen ldh a, [rLY] - cp 145 + cp LY_VBLANK + 1 jr nz, .wait ldh a, [rLCDC] - and %01111111 + and $ff ^ (1 << rLCDC_ENABLE) ldh [rLCDC], a xor a @@ -53,6 +58,6 @@ DisableLCD:: EnableLCD:: ldh a, [rLCDC] - set 7, a + set rLCDC_ENABLE, a ldh [rLCDC], a - ret + ret
\ No newline at end of file diff --git a/home/map.asm b/home/map.asm index e961c0ff..036969e1 100644 --- a/home/map.asm +++ b/home/map.asm @@ -79,7 +79,7 @@ GetMapTrigger:: ; 1f95 (0:1f95) OverworldTextModeSwitch:: ; 1fc1 (0:1fc1) call LoadMapPart - call FarCallSwapTextboxPalettes + call SwapTextboxPalettes ret LoadMapPart:: ; 1fc8 (0:1fc8) @@ -89,7 +89,7 @@ LoadMapPart:: ; 1fc8 (0:1fc8) rst Bankswitch call LoadMetatiles ld a, $60 - ld hl, wTileMap + ld hl, wTilemap ld bc, $168 call ByteFill ld a, $5 @@ -237,7 +237,7 @@ Function20e6:: ; 20e6 (0:20e6) ldh a, [hCGB] and a ret z - decoord 0, 0, wAttrMap + decoord 0, 0, wAttrmap ld a, $1 ldh [rVBK], a Function20f7:: ; 20f7 (0:20f7) @@ -1441,7 +1441,7 @@ ScrollMapDown:: ld de, wBGMapBuffer call BackupBGMapRow ld c, $28 - call FarCallScrollBGMapPalettes + call ScrollBGMapPalettes ld a, [wd05b] ld e, a ld a, [wd05c] @@ -1456,7 +1456,7 @@ ScrollMapUp:: ld de, wBGMapBuffer call BackupBGMapRow ld c, $28 - call FarCallScrollBGMapPalettes + call ScrollBGMapPalettes ld a, [wd05b] ld l, a ld a, [wd05c] @@ -1474,11 +1474,11 @@ ScrollMapUp:: ret ScrollMapRight:: - ld hl, wTileMap + ld hl, wTilemap ld de, wBGMapBuffer call BackupBGMapColumn ld c, $24 - call FarCallScrollBGMapPalettes + call ScrollBGMapPalettes ld a, [wd05b] ld e, a ld a, [wd05c] @@ -1493,7 +1493,7 @@ ScrollMapLeft:: ld de, wBGMapBuffer call BackupBGMapColumn ld c, $24 - call FarCallScrollBGMapPalettes + call ScrollBGMapPalettes ld a, [wd05b] ld e, a and $e0 diff --git a/home/map_objects.asm b/home/map_objects.asm index 874346f5..d9cebf48 100644 --- a/home/map_objects.asm +++ b/home/map_objects.asm @@ -1,9 +1,13 @@ -GetSpritePalette:: ; 169c +; Functions handling map objects. + +GetSpritePalette:: push hl push de push bc ld c, a - farcall GetSpritePalette_ + + farcall _GetSpritePalette + ld a, c pop bc pop de @@ -17,29 +21,30 @@ GetSpriteVTile:: ld c, $b ld b, a ldh a, [hMapObjectIndexBuffer] - cp $0 - jr z, .asm_16c8 + cp 0 + jr z, .nope ld a, b -.asm_16ba +.loop cp [hl] - jr z, .asm_16cd + jr z, .found inc hl inc hl dec c - jr nz, .asm_16ba + jr nz, .loop ld a, [wUsedSprites + 1] scf - jr .asm_16d0 + jr .done -.asm_16c8 +.nope ld a, [wUsedSprites + 1] - jr .asm_16d0 + jr .done -.asm_16cd +.found inc hl xor a ld a, [hl] -.asm_16d0 + +.done pop bc pop hl ret @@ -47,17 +52,21 @@ GetSpriteVTile:: DoesSpriteHaveFacings:: push de push hl + ld b, a ldh a, [hROMBank] push af - ld a, BANK(DoesSpriteHaveFacings_) + ld a, BANK(_DoesSpriteHaveFacings) rst Bankswitch + ld a, b - call DoesSpriteHaveFacings_ + call _DoesSpriteHaveFacings ld c, a + pop de ld a, d rst Bankswitch + pop hl pop de ret @@ -71,18 +80,22 @@ GetPlayerStandingTile:: CheckOnWater:: ld a, [wPlayerStandingTile] call GetTileCollision - sub $1 + sub WATERTILE ret z and a ret -GetTileCollision:: ; 16fa (0:16fa) +GetTileCollision:: +; Get the collision type of tile a. + push de push hl + ld hl, TileCollisionTable ld e, a - ld d, $0 + ld d, 0 add hl, de + ldh a, [hROMBank] push af ld a, BANK(TileCollisionTable) @@ -90,8 +103,10 @@ GetTileCollision:: ; 16fa (0:16fa) ld e, [hl] pop af rst Bankswitch + ld a, e - and $f + and $f ; lo nybble only + pop hl pop de ret @@ -99,228 +114,232 @@ GetTileCollision:: ; 16fa (0:16fa) CheckGrassTile:: ld d, a and $f0 - cp $10 - jr z, .asm_171f - cp $20 - jr z, .asm_1725 + cp HI_NYBBLE_TALL_GRASS + jr z, .grass + cp HI_NYBBLE_WATER + jr z, .water scf ret -.asm_171f +.grass ld a, d - and $7 + and LO_NYBBLE_GRASS ret z scf ret - -.asm_1725 +; For some reason, the above code is duplicated down here. +.water ld a, d - and $7 + and LO_NYBBLE_GRASS ret z scf ret CheckSuperTallGrassTile:: - cp $14 + cp COLL_LONG_GRASS ret z - cp $1c + cp COLL_LONG_GRASS_1C ret CheckCutTreeTile:: - cp $12 + cp COLL_CUT_TREE ret z - cp $1a + cp COLL_CUT_TREE_1A ret CheckHeadbuttTreeTile:: - cp $15 + cp COLL_HEADBUTT_TREE ret z - cp $1d + cp COLL_HEADBUTT_TREE_1D ret CheckCounterTile:: - cp $90 + cp COLL_COUNTER ret z - cp $98 + cp COLL_COUNTER_98 ret CheckPitTile:: - cp $60 + cp COLL_PIT ret z - cp $68 + cp COLL_PIT_68 ret CheckIceTile:: - cp $23 + cp COLL_ICE ret z - cp $2b + cp COLL_ICE_2B ret z scf ret CheckWhirlpoolTile:: nop - cp $24 + cp COLL_WHIRLPOOL ret z - cp $2c + cp COLL_WHIRLPOOL_2C ret z scf ret CheckWaterfallTile:: - cp $33 + cp COLL_WATERFALL ret z - cp $3b + cp COLL_CURRENT_DOWN ret CheckStandingOnEntrance:: ld a, [wPlayerStandingTile] - cp $71 + cp COLL_DOOR ret z - cp $79 + cp COLL_DOOR_79 ret z - cp $7a + cp COLL_STAIRCASE ret z - cp $7b + cp COLL_CAVE ret -GetMapObject:: ; 176f (0:176f) +GetMapObject:: +; Return the location of map object a in bc. ld hl, wMapObjects - ld bc, $10 + ld bc, MAPOBJECT_LENGTH call AddNTimes ld b, h ld c, l ret -CheckObjectVisibility:: ; 177b (0:177b) - ldh [hConnectionStripLength], a +CheckObjectVisibility:: +; Sets carry if the object is not visible on the screen. + ldh [hMapObjectIndexBuffer], a call GetMapObject - ld hl, 0 + ld hl, MAPOBJECT_OBJECT_STRUCT_ID add hl, bc ld a, [hl] - cp $ff - jr z, .asm_1790 + cp -1 + jr z, .not_visible ldh [hObjectStructIndexBuffer], a call GetObjectStruct and a ret -.asm_1790 +.not_visible scf ret CheckObjectTime:: - ld hl, $6 + ld hl, MAPOBJECT_HOUR add hl, bc ld a, [hl] - cp $ff - jr nz, .asm_17be - ld hl, $7 + cp -1 + jr nz, .check_hour + ld hl, MAPOBJECT_TIMEOFDAY add hl, bc ld a, [hl] - cp $ff - jr z, .asm_17b9 - ld hl, .TimeOfDayValues_17bb + cp -1 + jr z, .timeofday_always + ld hl, .TimeOfDayValues_191e ld a, [wTimeOfDay] add l ld l, a - jr nc, .asm_17af + jr nc, .ok inc h -.asm_17af + +.ok ld a, [hl] - ld hl, $7 + ld hl, MAPOBJECT_TIMEOFDAY add hl, bc and [hl] - jr nz, .asm_17b9 + jr nz, .timeofday_always scf ret -.asm_17b9 +.timeofday_always and a ret -.TimeOfDayValues_17bb: +.TimeOfDayValues_191e: +; entries correspond to TimeOfDay values db MORN db DAY db NITE -.asm_17be - ld hl, $6 +.check_hour + ld hl, MAPOBJECT_HOUR add hl, bc ld d, [hl] - ld hl, $7 + ld hl, MAPOBJECT_TIMEOFDAY add hl, bc ld e, [hl] ld hl, hHours ld a, d cp e - jr z, .asm_17e6 - jr c, .asm_17dc + jr z, .yes + jr c, .check_timeofday ld a, [hl] cp d - jr nc, .asm_17e6 + jr nc, .yes cp e - jr c, .asm_17e6 - jr z, .asm_17e6 - jr .asm_17e8 + jr c, .yes + jr z, .yes + jr .no -.asm_17dc +.check_timeofday ld a, e cp [hl] - jr c, .asm_17e8 + jr c, .no ld a, [hl] cp d - jr nc, .asm_17e6 - jr .asm_17e8 + jr nc, .yes + jr .no -.asm_17e6 +.yes and a ret -.asm_17e8 +.no scf ret -Function17ea:: +; unused ldh [hMapObjectIndexBuffer], a call GetMapObject - call CopyObjectStruct_ + call CopyObjectStruct ret -CopyObjectStruct:: +_CopyObjectStruct:: ldh [hMapObjectIndexBuffer], a call UnmaskObject - ldh a, [hConnectionStripLength] + ldh a, [hMapObjectIndexBuffer] call GetMapObject - farcall CopyObjectStruct_ + farcall CopyObjectStruct ret -ApplyDeletionToMapObject:: ; 1804 (0:1804) - ldh [hConnectionStripLength], a +ApplyDeletionToMapObject:: + ldh [hMapObjectIndexBuffer], a call GetMapObject - ld hl, 0 + ld hl, MAPOBJECT_OBJECT_STRUCT_ID add hl, bc ld a, [hl] - cp $ff - ret z - ld [hl], $ff + cp -1 + ret z ; already hidden + ld [hl], -1 push af - call DeleteOject_CheckStopFollow + call .CheckStopFollow pop af call GetObjectStruct farcall DeleteMapObject ret -DeleteOject_CheckStopFollow:: ; 1822 (0:1822) +.CheckStopFollow: ld hl, wObjectFollow_Leader cp [hl] - jr z, .asm_182d + jr z, .ok ld hl, wObjectFollow_Follower cp [hl] ret nz -.asm_182d +.ok farcall StopFollow - ld a, $ff + ld a, -1 ld [wObjectFollow_Leader], a ld [wObjectFollow_Follower], a ret @@ -335,106 +354,113 @@ CopyPlayerObjectTemplate:: call GetMapObject ld d, b ld e, c - ld a, $ff + ld a, -1 ld [de], a inc de pop hl - ld bc, $f + ld bc, MAPOBJECT_LENGTH - 1 call CopyBytes ret -Function1855:: +Unreferenced_Function19b8: call GetMapObject - ld hl, 0 + ld hl, MAPOBJECT_OBJECT_STRUCT_ID add hl, bc ld a, [hl] push af - ld [hl], $ff + ld [hl], -1 inc hl - ld bc, $f + ld bc, MAPOBJECT_LENGTH - 1 xor a call ByteFill pop af - cp $ff + cp -1 ret z cp $d ret nc ld b, a ld a, [wObjectFollow_Leader] cp b - jr nz, .asm_187b - ld a, $ff + jr nz, .ok + ld a, -1 ld [wObjectFollow_Leader], a -.asm_187b + +.ok ld a, b call GetObjectStruct farcall DeleteMapObject ret LoadMovementDataPointer:: - ld [wMovementPerson], a +; Load the movement data pointer for object a. + ld [wMovementObject], a ldh a, [hROMBank] - ld [wMovementDataPointerBank], a + ld [wMovementDataBank], a ld a, l - ld [wMovementDataPointerAddr], a + ld [wMovementDataAddress], a ld a, h - ld [wMovementDataPointerAddr + 1], a - ld a, [wMovementPerson] + ld [wMovementDataAddress + 1], a + ld a, [wMovementObject] call CheckObjectVisibility ret c - ld hl, $3 + + ld hl, OBJECT_MOVEMENTTYPE add hl, bc - ld [hl], $14 - ld hl, $9 + ld [hl], SPRITEMOVEDATA_SCRIPTED + + ld hl, OBJECT_STEP_TYPE add hl, bc - ld [hl], $0 + ld [hl], STEP_TYPE_00 + ld hl, wVramState set 7, [hl] and a ret FindFirstEmptyObjectStruct:: +; Returns the index of the first empty object struct in A and its address in HL, then sets carry. +; If all object structs are occupied, A = 0 and Z is set. +; Preserves BC and DE. push bc push de ld hl, wObjectStructs - ld de, $28 - ld c, $d -.asm_18ba + ld de, OBJECT_LENGTH + ld c, NUM_OBJECT_STRUCTS +.loop ld a, [hl] and a - jr z, .asm_18c5 + jr z, .break add hl, de dec c - jr nz, .asm_18ba + jr nz, .loop xor a - jr .asm_18c9 + jr .done -.asm_18c5 - ld a, $d +.break + ld a, NUM_OBJECT_STRUCTS sub c scf -.asm_18c9 + +.done pop de pop bc ret GetSpriteMovementFunction:: - ld hl, $3 + ld hl, OBJECT_MOVEMENTTYPE add hl, bc ld a, [hl] - cp $25 - jr c, .asm_18d6 + cp NUM_SPRITEMOVEDATA + jr c, .ok xor a -.asm_18d6 - ld hl, SpriteMovementData + +.ok + ld hl, SpriteMovementData + SPRITEMOVEATTR_MOVEMENT ld e, a - ld d, $0 - add hl, de - add hl, de - add hl, de - add hl, de - add hl, de + ld d, 0 +rept NUM_SPRITEMOVEDATA_FIELDS add hl, de +endr ld a, [hl] ret @@ -442,19 +468,16 @@ GetInitialFacing:: push bc push de ld e, a - ld d, $0 - ld hl, SpriteMovementData + 1 - add hl, de - add hl, de - add hl, de - add hl, de - add hl, de + ld d, 0 + ld hl, SpriteMovementData + SPRITEMOVEATTR_FACING +rept NUM_SPRITEMOVEDATA_FIELDS add hl, de +endr ld a, BANK(SpriteMovementData) call GetFarByte add a add a - and $c + maskbits NUM_DIRECTIONS, 2 pop de pop bc ret @@ -467,78 +490,87 @@ CopySpriteMovementData:: rst Bankswitch ld a, l push bc + call .CopyData + pop bc pop af rst Bankswitch + ret .CopyData: - ld hl, $3 + ld hl, OBJECT_MOVEMENTTYPE add hl, de ld [hl], a + push de ld e, a - ld d, $0 - ld hl, $4275 - add hl, de - add hl, de - add hl, de - add hl, de - add hl, de + ld d, 0 + ld hl, SpriteMovementData + SPRITEMOVEATTR_FACING +rept NUM_SPRITEMOVEDATA_FIELDS add hl, de +endr ld b, h ld c, l pop de + ld a, [bc] inc bc rlca rlca - and $c - ld hl, $8 + maskbits NUM_DIRECTIONS, 2 + ld hl, OBJECT_FACING add hl, de ld [hl], a + ld a, [bc] inc bc - ld hl, $b + ld hl, OBJECT_ACTION add hl, de ld [hl], a + ld a, [bc] inc bc - ld hl, $4 + ld hl, OBJECT_FLAGS1 add hl, de ld [hl], a + ld a, [bc] inc bc - ld hl, $5 + ld hl, OBJECT_FLAGS2 add hl, de ld [hl], a + ld a, [bc] inc bc - ld hl, $6 + ld hl, OBJECT_PALETTE add hl, de ld [hl], a ret -GetMovementByte_:: +_GetMovementByte:: +; Switch to the movement data bank ldh a, [hROMBank] push af ld a, [hli] rst Bankswitch +; Load the current script byte as given by OBJECT_MOVEMENT_BYTE_INDEX, and increment OBJECT_MOVEMENT_BYTE_INDEX ld a, [hli] ld d, [hl] - ld hl, $1b + ld hl, OBJECT_MOVEMENT_BYTE_INDEX add hl, bc add [hl] ld e, a ld a, d - adc $0 + adc 0 ld d, a inc [hl] ld a, [de] ld h, a pop af rst Bankswitch + ld a, h ret @@ -552,16 +584,17 @@ ResetVramState_Bit0:: res 0, [hl] ret -UpdateSprites:: ; 196f (0:196f) +UpdateSprites:: ld a, [wVramState] bit 0, a ret z + farcall Function557f - farcall UpdateSprites_ + farcall _UpdateSprites ret -GetObjectStruct:: ; 1982 (0:1982) - ld bc, $28 +GetObjectStruct:: + ld bc, OBJECT_LENGTH ld hl, wObjectStructs call AddNTimes ld b, h @@ -569,28 +602,29 @@ GetObjectStruct:: ; 1982 (0:1982) ret DoesObjectHaveASprite:: - ld hl, 0 + ld hl, OBJECT_SPRITE add hl, bc ld a, [hl] and a ret SetSpriteDirection:: + ; preserves other flags push af - ld hl, $8 + ld hl, OBJECT_FACING add hl, bc ld a, [hl] - and $f3 + and %11110011 ld e, a pop af - and $c + maskbits NUM_DIRECTIONS, 2 or e ld [hl], a ret GetSpriteDirection:: - ld hl, $8 + ld hl, OBJECT_FACING add hl, bc ld a, [hl] - and $c + maskbits NUM_DIRECTIONS, 2 ret diff --git a/home/menu.asm b/home/menu.asm index 9adbc65d..a82fa3a3 100644 --- a/home/menu.asm +++ b/home/menu.asm @@ -251,7 +251,7 @@ MenuBoxCoord2Tile:: ld b, a Coord2Tile:: -; Return the address of wTileMap(c, b) in hl. +; Return the address of wTilemap(c, b) in hl. xor a ld h, a ld l, b diff --git a/home/mon_party.asm b/home/mon_party.asm deleted file mode 100755 index 5da498c8..00000000 --- a/home/mon_party.asm +++ /dev/null @@ -1,35 +0,0 @@ -GetPartyParamLocation:: -; Get the location of parameter a from wCurPartyMon in hl - push bc - ld hl, wPartyMons - ld c, a - ld b, 0 - add hl, bc - ld a, [wCurPartyMon] - call GetPartyLocation - pop bc - ret - -GetPartyLocation:: -; Add the length of a PartyMon struct to hl a times. - ld bc, PARTYMON_STRUCT_LENGTH - jp AddNTimes - -Unreferenced_GetDexNumber:: -; Probably used in gen 1 to convert index number to dex number -; Not required in gen 2 because index number == dex number - push hl - ld a, b - dec a - ld b, 0 - add hl, bc - ld hl, BaseData + BASE_DEX_NO - ld bc, BASE_DATA_SIZE - call AddNTimes - pop bc - ld a, BANK(BaseData) - call GetFarHalfword - ld b, l - ld c, h - pop hl - ret
\ No newline at end of file diff --git a/home/movement.asm b/home/movement.asm index c15b6aa5..025fdeb6 100644 --- a/home/movement.asm +++ b/home/movement.asm @@ -1,12 +1,12 @@ InitMovementBuffer:: - ld [wMovementBufferPerson], a + ld [wMovementBufferObject], a xor a ld [wMovementBufferCount], a - ld a, $0 + ld a, $0 ; useless ld [wceef], a - ld a, wMovementBuffer % $100 + ld a, LOW(wMovementBuffer) ld [wcef0], a - ld a, wMovementBuffer / $100 + ld a, HIGH(wMovementBuffer) ld [wcef1], a ret @@ -18,13 +18,13 @@ DecrementMovementBufferCount:: ld [wMovementBufferCount], a ret -AppendToMovementBuffer:: ; 19dc (0:19dc) +AppendToMovementBuffer:: push hl push de ld hl, wMovementBufferCount ld e, [hl] inc [hl] - ld d, $0 + ld d, 0 ld hl, wMovementBuffer add hl, de ld [hl], a @@ -32,72 +32,80 @@ AppendToMovementBuffer:: ; 19dc (0:19dc) pop hl ret -AppendToMovementBufferNTimes:: ; 19ed (0:19ed) +AppendToMovementBufferNTimes:: push af ld a, c and a - jr nz, .asm_19f4 + jr nz, .okay pop af ret -.asm_19f4 +.okay pop af -.asm_19f5 +.loop call AppendToMovementBuffer dec c - jr nz, .asm_19f5 + jr nz, .loop ret ComputePathToWalkToPlayer:: push af +; compare x coords, load left/right into h, and x distance into d ld a, b sub d - ld h, $2 - jr nc, .asm_1a07 + ld h, LEFT + jr nc, .got_x_distance dec a cpl - ld h, $3 -.asm_1a07 + ld h, RIGHT + +.got_x_distance ld d, a +; compare y coords, load up/down into l, and y distance into e ld a, c sub e - ld l, $1 - jr nc, .asm_1a12 + ld l, UP + jr nc, .got_y_distance dec a cpl - ld l, $0 -.asm_1a12 + ld l, DOWN + +.got_y_distance ld e, a +; if the x distance is less than the y distance, swap h and l, and swap d and e cp d - jr nc, .asm_1a1c + jr nc, .done ld a, h ld h, l ld l, a ld a, d ld d, e ld e, a -.asm_1a1c + +.done pop af ld b, a +; Add movement in the longer direction first... ld a, h - call WalkToPlayer_GetMovementByte + call .GetMovementData ld c, d call AppendToMovementBufferNTimes +; ... then add the shorter direction. ld a, l - call WalkToPlayer_GetMovementByte + call .GetMovementData ld c, e call AppendToMovementBufferNTimes ret -WalkToPlayer_GetMovementByte:: ; 1a2f (0:1a2f) +.GetMovementData: push de push hl ld l, b - ld h, $0 + ld h, 0 add hl, hl add hl, hl ld e, a - ld d, $0 + ld d, 0 add hl, de ld de, .MovementData add hl, de diff --git a/home/names.asm b/home/names.asm index d5b2f55e..3461dc76 100755 --- a/home/names.asm +++ b/home/names.asm @@ -7,7 +7,7 @@ NamesPointers:: dbw 0, wPartyMonOT ; PARTY_OT_NAME dbw 0, wOTPartyMonOT ; ENEMY_OT_NAME dba TrainerClassNames ; TRAINER_NAME - dbw 4, MoveDescriptions ; MOVE_DESC_NAME_BROKEN (wrong bank) + dbw 4, MoveDescriptions ; MOVE_DESC_NAME_BROKEN (wrong bank) GetName:: ; Return name wCurSpecies from name list wNamedObjectTypeBuffer in wStringBuffer1. diff --git a/home/palettes.asm b/home/palettes.asm index df80d14e..131a7128 100644 --- a/home/palettes.asm +++ b/home/palettes.asm @@ -1,55 +1,90 @@ -UpdatePalsIfCGB:: ; bdf (0:0bdf) +; Functions dealing with palettes. + +UpdatePalsIfCGB:: +; update bgp data from wBGPals2 +; update obp data from wOBPals2 +; return carry if successful + +; check cgb ldh a, [hCGB] and a ret z -UpdateCGBPals:: ; be3 (0:0be3) + +UpdateCGBPals:: +; return carry if successful +; any pals to update? ldh a, [hCGBPalUpdate] and a ret z + ForceUpdateCGBPals:: ld hl, wBGPals - ld a, $80 + +; copy 8 pals to bgpd + ld a, 1 << rBGPI_AUTO_INCREMENT ldh [rBGPI], a ld c, 8 / 2 .bgp -rept 2 palettes +rept (1 palettes) * 2 ld a, [hli] ldh [rBGPD], a endr + dec c jr nz, .bgp - ld a, $80 + +; hl is now wOBPals2 + +; copy 8 pals to obpd + ld a, 1 << rOBPI_AUTO_INCREMENT ldh [rOBPI], a ld c, 8 / 2 .obp -rept 2 palettes +rept (1 palettes) * 2 ld a, [hli] ldh [rOBPD], a endr + dec c jr nz, .obp + +; clear pal update queue xor a ldh [hCGBPalUpdate], a + scf ret -DmgToCgbBGPals:: ; c61 (0:0c61) +DmgToCgbBGPals:: +; exists to forego reinserting cgb-converted image data + +; input: a -> bgp + ldh [rBGP], a push af + +; Don't need to be here if DMG ldh a, [hCGB] and a jr z, .end + push hl push de push bc - ld hl, wBGPals - ld de, wTempBGPals + +; copy & reorder bg pal buffer + ld hl, wBGPals ; to + ld de, wTempBGPals ; from +; order ldh a, [rBGP] ld b, a - ld c, $8 +; all pals + ld c, 8 call CopyPals - ld a, $1 +; request pal update + ld a, 1 ldh [hCGBPalUpdate], a + pop bc pop de pop hl @@ -57,25 +92,38 @@ DmgToCgbBGPals:: ; c61 (0:0c61) pop af ret -DmgToCgbObjPals:: ; c83 (0:0c83) +DmgToCgbObjPals:: +; exists to forego reinserting cgb-converted image data + +; input: d -> obp1 +; e -> obp2 + ld a, e ldh [rOBP0], a ld a, d ldh [rOBP1], a + ldh a, [hCGB] and a ret z + push hl push de push bc - ld hl, wOBPals - ld de, wTempOBPals + +; copy & reorder obj pal buffer + ld hl, wOBPals ; to + ld de, wTempOBPals ; from +; order ldh a, [rOBP0] ld b, a - ld c, $8 +; all pals + ld c, 8 call CopyPals - ld a, $1 +; request pal update + ld a, 1 ldh [hCGBPalUpdate], a + pop bc pop de pop hl @@ -84,82 +132,109 @@ DmgToCgbObjPals:: ; c83 (0:0c83) DmgToCgbObjPal0:: ldh [rOBP0], a push af + +; Don't need to be here if not CGB ldh a, [hCGB] and a - jr z, .end + jr z, .dmg + push hl push de push bc - ld hl, wOBPals - ld de, wTempOBPals + + ld hl, wOBPals palette 0 + ld de, wTempOBPals palette 0 ldh a, [rOBP0] ld b, a - ld c, $1 + ld c, 1 call CopyPals - ld a, $1 + ld a, 1 ldh [hCGBPalUpdate], a + pop bc pop de pop hl -.end + +.dmg pop af ret DmgToCgbObjPal1:: ldh [rOBP1], a push af + ldh a, [hCGB] and a - jr z, .end + jr z, .dmg + push hl push de push bc - ld hl, wOBPals + 1 palettes - ld de, wTempOBPals + 1 palettes + + ld hl, wOBPals palette 1 + ld de, wTempOBPals palette 1 ldh a, [rOBP1] ld b, a - ld c, $1 + ld c, 1 call CopyPals - ld a, $1 + ld a, 1 ldh [hCGBPalUpdate], a + pop bc pop de pop hl -.end + +.dmg pop af ret -CopyPals:: ; cea (0:0cea) +CopyPals:: +; copy c palettes in order b from de to hl + push bc - ld c, $4 + ld c, NUM_PAL_COLORS .loop push de push hl + +; get pal color ld a, b - and $3 + maskbits 1 << PAL_COLOR_SIZE +; 2 bytes per color add a ld l, a - ld h, $0 + 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 +rept PAL_COLOR_SIZE srl b - srl b +endr +; source pop de +; done pal? dec c jr nz, .loop - ld a, $8 + +; de += 8 (next pal) + ld a, PALETTE_SIZE add e jr nc, .ok inc d .ok ld e, a + +; how many more pals? pop bc dec c jr nz, CopyPals @@ -169,19 +244,22 @@ ClearVBank1:: ldh a, [hCGB] and a ret z - ld a, $1 + + ld a, 1 ldh [rVBK], a - ld hl, $8000 - ld bc, $2000 + + ld hl, VRAM_Begin + ld bc, VRAM_End - VRAM_Begin xor a call ByteFill - ld a, $0 + + ld a, 0 ldh [rVBK], a ret Functiond2a:: - ld hl, wTileMap - ld de, wAttrMap + ld hl, wTilemap + ld de, wAttrmap ld bc, SCREEN_WIDTH * SCREEN_HEIGHT .asm_d33 ld a, [hli] @@ -202,18 +280,18 @@ ReloadSpritesNoPalettes:: and a ret z ld hl, wBGPals - ld bc, $50 + ld bc, (8 palettes) + (2 palettes) xor a call ByteFill - ld a, $1 + ld a, 1 ldh [hCGBPalUpdate], a call DelayFrame ret -FarCallSwapTextboxPalettes:: - homecall SwapTextboxPalettes +SwapTextboxPalettes:: + homecall _SwapTextboxPalettes ret -FarCallScrollBGMapPalettes:: - homecall ScrollBGMapPalettes +ScrollBGMapPalettes:: + homecall _ScrollBGMapPalettes ret diff --git a/home/pokedex_flags.asm b/home/pokedex_flags.asm index fe866ba9..5c12da51 100644 --- a/home/pokedex_flags.asm +++ b/home/pokedex_flags.asm @@ -37,6 +37,8 @@ SetSeenAndCaughtMon:: ld b, SET_FLAG call PokedexFlagAction pop af + ; fallthrough + SetSeenMon:: ld c, a ld hl, wPokedexSeen @@ -53,10 +55,11 @@ CheckSeenMon:: ld c, a ld hl, wPokedexSeen ld b, CHECK_FLAG -PokedexFlagAction:: ; 35e4 (0:35e4) + ; fallthrough + +PokedexFlagAction:: ld d, 0 predef SmallFarFlagAction ld a, c and a ret - diff --git a/home/predef.asm b/home/predef.asm index 2796cb67..10550d12 100644 --- a/home/predef.asm +++ b/home/predef.asm @@ -49,4 +49,4 @@ Predef:: ld h, a ld a, [wPredefTemp + 1] ld l, a - ret
\ No newline at end of file + ret diff --git a/home/printer.asm b/home/printer.asm index f4e8c7d3..9747713c 100644 --- a/home/printer.asm +++ b/home/printer.asm @@ -1,8 +1,8 @@ -PrinterReceive:: ; 1eb3 (0:1eb3) - homecall PrinterReceive_ +PrinterReceive:: + homecall _PrinterReceive ret -AskSerial:: ; 1ebf (0:1ebf) +AskSerial:: ; send out a handshake while serial int is off ld a, [wPrinterConnectionOpen] bit 0, a @@ -31,11 +31,11 @@ AskSerial:: ; 1ebf (0:1ebf) ldh [rSB], a ; switch to internal clock - ld a, %00000001 + ld a, (0 << rSC_ON) | (1 << rSC_CLOCK) ldh [rSC], a ; start transfer - ld a, %10000001 + ld a, (1 << rSC_ON) | (1 << rSC_CLOCK) ldh [rSC], a ret diff --git a/home/random.asm b/home/random.asm index 5b2f4933..9d62b9b6 100644 --- a/home/random.asm +++ b/home/random.asm @@ -1,24 +1,46 @@ -Random:: ; 30a2 (0:30a2) +Random:: +; A simple hardware-based random number generator (RNG). + +; Two random numbers are generated by adding and subtracting +; the divider to the respective values every time it's called. + +; The divider is a register that increments at a rate of 16384Hz. +; For comparison, the Game Boy operates at a clock speed of 4.2MHz. + +; Additionally, an equivalent function is executed in VBlank. + +; This leaves a with the value in hRandomSub. + push bc + ldh a, [rDIV] ld b, a - ldh a, [hRandom] + ldh a, [hRandomAdd] adc b - ldh [hRandom], a + ldh [hRandomAdd], a + ldh a, [rDIV] ld b, a ldh a, [hRandomSub] sbc b ldh [hRandomSub], a + pop bc ret BattleRandom:: +; _BattleRandom lives in another bank. + +; It handles all RNG calls in the battle engine, allowing +; link battles to remain in sync using a shared PRNG. + ldh a, [hROMBank] push af - ld a, BANK(BattleRandom_) + ld a, BANK(_BattleRandom) rst Bankswitch - call BattleRandom_ + + call _BattleRandom + ld [wPredefTemp + 1], a pop af rst Bankswitch @@ -26,24 +48,33 @@ BattleRandom:: ret RandomRange:: +; Return a random number between 0 and a (non-inclusive). + push bc ld c, a + + ; b = $100 % c xor a sub c -.asm_30cb +.mod sub c - jr nc, .asm_30cb + jr nc, .mod add c ld b, a + + ; Get a random number + ; from 0 to $ff - b. push bc -.asm_30d1 +.loop call Random - ldh a, [hRandom] + ldh a, [hRandomAdd] ld c, a add b - jr c, .asm_30d1 + jr c, .loop ld a, c pop bc + call SimpleDivide + pop bc ret diff --git a/home/region.asm b/home/region.asm index b3242336..df5b3c27 100755 --- a/home/region.asm +++ b/home/region.asm @@ -31,7 +31,7 @@ IsInJohto:: ld a, 1 ret -Function2ffe:: ; 2ffe (0:2ffe) +Function2ffe:: push hl xor a ld hl, wd17c diff --git a/home/serial.asm b/home/serial.asm index bd51084e..0fb1750b 100644 --- a/home/serial.asm +++ b/home/serial.asm @@ -1,4 +1,6 @@ -Serial:: ; 6aa (0:06aa) +Serial:: +; The serial interrupt. + push af push bc push de @@ -9,18 +11,22 @@ Serial:: ; 6aa (0:06aa) jr nz, .printer ldh a, [hLinkPlayerNumber] - inc a - jr z, .init_player_number + inc a ; is it equal to CONNECTION_NOT_ESTABLISHED? + jr z, .establish_connection + ldh a, [rSB] ldh [hSerialReceive], a + ldh a, [hSerialSend] ldh [rSB], a + ldh a, [hLinkPlayerNumber] - cp $2 + cp USING_INTERNAL_CLOCK jr z, .player2 - ld a, 0 << rSC_ON + + ld a, (0 << rSC_ON) | (0 << rSC_CLOCK) ldh [rSC], a - ld a, 1 << rSC_ON + ld a, (1 << rSC_ON) | (0 << rSC_CLOCK) ldh [rSC], a jr .player2 @@ -28,22 +34,22 @@ Serial:: ; 6aa (0:06aa) call PrinterReceive jr .end -.init_player_number +.establish_connection ldh a, [rSB] - cp $1 + cp USING_EXTERNAL_CLOCK jr z, .player1 - cp $2 + cp USING_INTERNAL_CLOCK jr nz, .player2 .player1 ldh [hSerialReceive], a ldh [hLinkPlayerNumber], a - cp $2 + cp USING_INTERNAL_CLOCK jr z, ._player2 xor a ldh [rSB], a - ld a, $3 + ld a, 3 ldh [rDIV], a .wait_bit_7 @@ -51,18 +57,19 @@ Serial:: ; 6aa (0:06aa) bit 7, a jr nz, .wait_bit_7 - ; cycle the serial controller - ld a, 0 << rSC_ON + ; Cycle the serial controller + ld a, (0 << rSC_ON) | (0 << rSC_CLOCK) ldh [rSC], a - ld a, 1 << rSC_ON + ld a, (1 << rSC_ON) | (0 << rSC_CLOCK) ldh [rSC], a jr .player2 ._player2 xor a ldh [rSB], a + .player2 - ld a, $1 + ld a, TRUE ldh [hFFCC], a ld a, SERIAL_NO_DATA_BYTE ldh [hSerialSend], a @@ -74,13 +81,13 @@ Serial:: ; 6aa (0:06aa) pop af reti -Function710:: ; 710 - ld a, $1 +Serial_ExchangeBytes:: + ld a, 1 ldh [hFFCE], a .loop ld a, [hl] ldh [hSerialSend], a - call Function73b + call Serial_ExchangeByte push bc ld b, a inc hl @@ -109,27 +116,29 @@ Function710:: ; 710 jr nz, .loop ret -Function73b:: ; 73b (0:073b) +Serial_ExchangeByte:: .loop xor a ldh [hFFCC], a ldh a, [hLinkPlayerNumber] - cp $2 - jr nz, .loop2 - ld a, (1 << rSC_CLOCK) | (0 << rSC_ON) + cp 2 + jr nz, .not_player_2 + ld a, (0 << rSC_ON) | (1 << rSC_CLOCK) ldh [rSC], a - ld a, (1 << rSC_CLOCK) | (1 << rSC_ON) + ld a, (1 << rSC_ON) | (1 << rSC_CLOCK) ldh [rSC], a + +.not_player_2 .loop2 ldh a, [hFFCC] and a jr nz, .reset_ffcc ldh a, [hLinkPlayerNumber] - cp $1 + cp 1 jr nz, .not_player_1_or_wLinkTimeoutFrames_zero - call CheckLinkTimeout + call CheckwLinkTimeoutFramesNonzero jr z, .not_player_1_or_wLinkTimeoutFrames_zero - call Serial15CycleDelay + call .delay_15_cycles push hl ld hl, wLinkTimeoutFrames + 1 inc [hl] @@ -139,14 +148,14 @@ Function73b:: ; 73b (0:073b) .no_rollover_up pop hl - call CheckLinkTimeout + call CheckwLinkTimeoutFramesNonzero jr nz, .loop2 jp SerialDisconnected .not_player_1_or_wLinkTimeoutFrames_zero ldh a, [rIE] - and $f - cp $8 + and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK) + cp 1 << SERIAL jr nz, .loop2 ld a, [wce5d] dec a @@ -157,10 +166,10 @@ Function73b:: ; 73b (0:073b) ld [wce5d + 1], a jr nz, .loop2 ldh a, [hLinkPlayerNumber] - cp $1 + cp 1 jr z, .reset_ffcc - - ld a, $ff + + ld a, 255 .delay_255_cycles dec a jr nz, .delay_255_cycles @@ -169,20 +178,21 @@ Function73b:: ; 73b (0:073b) xor a ldh [hFFCC], a ldh a, [rIE] - and $f - sub $8 + and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK) + sub 1 << SERIAL jr nz, .rIE_not_equal_8 + ; LOW($5000) ld [wce5d], a - ld a, 80 + ld a, HIGH($5000) ld [wce5d + 1], a .rIE_not_equal_8 ldh a, [hSerialReceive] cp SERIAL_NO_DATA_BYTE ret nz - call CheckLinkTimeout - jr z, .link_timed_out + call CheckwLinkTimeoutFramesNonzero + jr z, .linkTimeoutFrames_zero push hl ld hl, wLinkTimeoutFrames + 1 ld a, [hl] @@ -194,13 +204,13 @@ Function73b:: ; 73b (0:073b) .no_rollover pop hl - call CheckLinkTimeout + call CheckwLinkTimeoutFramesNonzero jr z, SerialDisconnected -.link_timed_out +.linkTimeoutFrames_zero ldh a, [rIE] - and $f - cp $8 + and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK) + cp 1 << SERIAL ld a, SERIAL_NO_DATA_BYTE ret z ld a, [hl] @@ -208,14 +218,14 @@ Function73b:: ; 73b (0:073b) call DelayFrame jp .loop -Serial15CycleDelay:: ; 7d6 (0:07d6) - ld a, $f -.loop +.delay_15_cycles + ld a, 15 +.delay_cycles dec a - jr nz, .loop + jr nz, .delay_cycles ret -CheckLinkTimeout:: ; 7dc (0:07dc) +CheckwLinkTimeoutFramesNonzero:: push hl ld hl, wLinkTimeoutFrames ld a, [hli] @@ -223,28 +233,30 @@ CheckLinkTimeout:: ; 7dc (0:07dc) pop hl ret -SerialDisconnected:: ; 7e4 (0:07e4) - dec a +SerialDisconnected:: + dec a ; a is always 0 when this is called ld [wLinkTimeoutFrames], a ld [wLinkTimeoutFrames + 1], a ret -Function7ec:: ; 7ec +; This is used to exchange the button press and selected menu item on the link menu. +; The data is sent thrice and read twice to increase reliability. +Serial_ExchangeLinkMenuSelection:: ld hl, wPlayerLinkAction ld de, wOtherPlayerLinkMode - ld c, $2 - ld a, $1 + ld c, 2 + ld a, TRUE ldh [hFFCE], a .asm_7f8 call DelayFrame ld a, [hl] ldh [hSerialSend], a - call Function73b + call Serial_ExchangeByte ld b, a inc hl ldh a, [hFFCE] and a - ld a, $0 + ld a, 0 ldh [hFFCE], a jr nz, .asm_7f8 ld a, b @@ -254,26 +266,26 @@ Function7ec:: ; 7ec jr nz, .asm_7f8 ret -Function813:: ; 813 - call LoadTileMapToTempTileMap +Serial_PrintWaitingTextAndSyncAndExchangeNybble:: + call LoadTilemapToTempTilemap callfar PlaceWaitingText call WaitLinkTransfer - jp Call_LoadTempTileMapToTileMap + jp SafeLoadTempTilemapToTilemap -Function822:: ; 822 - call LoadTileMapToTempTileMap +Serial_SyncAndExchangeNybble:: + call LoadTilemapToTempTilemap callfar PlaceWaitingText jp WaitLinkTransfer ; One "giant" leap for machinekind -WaitLinkTransfer:: ; 82e (0:082e) +WaitLinkTransfer:: ld a, $ff ld [wOtherPlayerLinkAction], a .loop call LinkTransfer call DelayFrame - call CheckLinkTimeout + call CheckwLinkTimeoutFramesNonzero jr z, .check push hl ld hl, wLinkTimeoutFrames + 1 @@ -282,6 +294,7 @@ WaitLinkTransfer:: ; 82e (0:082e) dec hl dec [hl] jr nz, .skip + ; We might be disconnected pop hl xor a jp SerialDisconnected @@ -312,7 +325,7 @@ WaitLinkTransfer:: ; 82e (0:082e) ld [wOtherPlayerLinkMode], a ret -LinkTransfer:: ; 872 (0:0872) +LinkTransfer:: push bc ld b, SERIAL_TIMECAPSULE ld a, [wLinkMode] @@ -326,23 +339,24 @@ LinkTransfer:: ; 872 (0:0872) ld b, SERIAL_BATTLE .got_high_nybble - call LinkTransferReceive + call .Receive ld a, [wPlayerLinkAction] add b ldh [hSerialSend], a ldh a, [hLinkPlayerNumber] - cp $2 - jr nz, .asm_89f - ld a, $1 + cp USING_INTERNAL_CLOCK + jr nz, .player_1 + ld a, (0 << rSC_ON) | (1 << rSC_CLOCK) ldh [rSC], a - ld a, $81 + ld a, (1 << rSC_ON) | (1 << rSC_CLOCK) ldh [rSC], a -.asm_89f - call LinkTransferReceive + +.player_1 + call .Receive pop bc ret -LinkTransferReceive:: ; 8a4 (0:08a4) +.Receive: ldh a, [hSerialReceive] ld [wOtherPlayerLinkMode], a and $f0 @@ -355,28 +369,29 @@ LinkTransferReceive:: ; 8a4 (0:08a4) ld [wOtherPlayerLinkAction], a ret -LinkDataReceived:: ; 8b9 (0:08b9) +LinkDataReceived:: +; Let the other system know that the data has been received. xor a ldh [hSerialSend], a ldh a, [hLinkPlayerNumber] - cp $2 + cp USING_INTERNAL_CLOCK ret nz - ld a, $1 + ld a, (0 << rSC_ON) | (1 << rSC_CLOCK) ldh [rSC], a - ld a, $81 + ld a, (1 << rSC_ON) | (1 << rSC_CLOCK) ldh [rSC], a ret -Function8ca:: ; 8ca +Unreferenced_Function8ca:: ld a, [wLinkMode] and a ret nz - ld a, $2 + ld a, USING_INTERNAL_CLOCK ldh [rSB], a xor a ldh [hSerialReceive], a - ld a, $0 + ld a, (0 << rSC_ON) | (0 << rSC_CLOCK) ldh [rSC], a - ld a, $80 + ld a, (1 << rSC_ON) | (0 << rSC_CLOCK) ldh [rSC], a ret diff --git a/home/sine.asm b/home/sine.asm index 5965d497..821f7c47 100644 --- a/home/sine.asm +++ b/home/sine.asm @@ -1,6 +1,9 @@ -Cosine:: ; 19ac (0:19ac) - add $10 +Cosine:: +; a = d * cos(a * pi/32) + add %010000 ; cos(x) = sin(x + pi/2) + ; fallthrough Sine:: +; a = d * sin(a * pi/32) ld e, a - homecall Sine_e + homecall _Sine ret diff --git a/home/sprite_anims.asm b/home/sprite_anims.asm index 5f1d46f3..7b5b22d5 100755 --- a/home/sprite_anims.asm +++ b/home/sprite_anims.asm @@ -1,23 +1,31 @@ -InitAnimatedObjectStruct:: +InitSpriteAnimStruct:: ld [wAnimatedObjectStructIDBuffer], a ldh a, [hROMBank] push af - ld a, BANK(InitAnimatedObjectStruct_) ; $23 + + ld a, BANK(_InitSpriteAnimStruct) rst Bankswitch ld a, [wAnimatedObjectStructIDBuffer] - call InitAnimatedObjectStruct_ ; $51f7 + + call _InitSpriteAnimStruct + pop af rst Bankswitch + ret -ReinitAnimatedObjectFrame:: +ReinitSpriteAnimFrame:: ld [wAnimatedObjectStructIDBuffer], a ldh a, [hROMBank] push af - ld a, BANK(ReinitAnimatedObjectFrame_) ; $23 + + ld a, BANK(_ReinitSpriteAnimFrame) rst Bankswitch ld a, [wAnimatedObjectStructIDBuffer] - call ReinitAnimatedObjectFrame_ ; $5332 + + call _ReinitSpriteAnimFrame + pop af rst Bankswitch - ret
\ No newline at end of file + + ret diff --git a/home/sram.asm b/home/sram.asm index 6a0ed153..4d84c350 100644 --- a/home/sram.asm +++ b/home/sram.asm @@ -1,16 +1,23 @@ -OpenSRAM:: ; 30e1 (0:30e1) +OpenSRAM:: +; switch to sram bank a push af - ld a, $1 +; latch clock data + ld a, 1 ld [MBC3LatchClock], a - ld a, $a +; enable sram/clock write + ld a, SRAM_ENABLE ld [MBC3SRamEnable], a +; select sram bank pop af ld [MBC3SRamBank], a ret -CloseSRAM:: ; 30f1 (0:30f1) + +CloseSRAM:: push af - ld a, $0 + ld a, SRAM_DISABLE +; reset clock latch for next time ld [MBC3LatchClock], a +; disable sram/clock write ld [MBC3SRamEnable], a pop af ret diff --git a/home/string.asm b/home/string.asm index 6f804a96..86de2e27 100644 --- a/home/string.asm +++ b/home/string.asm @@ -1,31 +1,35 @@ InitString:: +; Init a string of length c. push hl - jr InitString_ + jr _InitString InitName:: +; Intended for names, so this function is limited to ten characters. push hl - ld c, $a -InitString_:: + ld c, NAME_LENGTH - 1 +_InitString:: +; if the string pointed to by hl is empty (defined as "zero or more spaces +; followed by a null"), then initialize it to the string pointed to by de. push bc -.asm_2fbd +.loop ld a, [hli] - cp $50 - jr z, .asm_2fc9 - cp $7f - jr nz, .asm_2fd4 + cp "@" + jr z, .blank + cp " " + jr nz, .notblank dec c - jr nz, .asm_2fbd -.asm_2fc9 + jr nz, .loop +.blank pop bc ld l, e ld h, d pop de - ld b, $0 + ld b, 0 inc c call CopyBytes ret -.asm_2fd4 +.notblank pop bc pop hl ret diff --git a/home/text.asm b/home/text.asm index 9c1104f5..1480dd92 100644 --- a/home/text.asm +++ b/home/text.asm @@ -1,7 +1,8 @@ -TEXTBOX_PAL EQU 7 - -ClearBox:: ; ebd (0:0ebd) +ClearBox:: +; Fill a c*b box at hl with blank tiles. ld a, " " + ; fallthrough + FillBoxWithByte:: ld de, SCREEN_WIDTH .row @@ -18,24 +19,31 @@ FillBoxWithByte:: jr nz, .row ret -ClearTileMap:: - ld hl, wTileMap +ClearTilemap:: +; Fill wTilemap with blank tiles. + + hlcoord 0, 0 ld a, " " - ld bc, SCREEN_WIDTH * SCREEN_HEIGHT + ld bc, wTilemapEnd - wTilemap call ByteFill + + ; Update the BG Map. ldh a, [rLCDC] - bit 7, a + bit rLCDC_ENABLE, a ret z jp WaitBGMap -FillScreenWithTextboxPal:: - ld a, TEXTBOX_PAL - hlcoord 0, 0, wAttrMap +ClearScreen:: + ld a, PAL_BG_TEXT + hlcoord 0, 0, wAttrmap ld bc, SCREEN_WIDTH * SCREEN_HEIGHT call ByteFill - jr ClearTileMap + jr ClearTilemap -Textbox:: ; eef (0:0eef) +Textbox:: +; Draw a text box at hl with room for b lines of c characters each. +; Places a border around the textbox, then switches the palette to the +; text black-and-white scheme. push bc push hl call TextboxBorder @@ -43,13 +51,14 @@ Textbox:: ; eef (0:0eef) pop bc jr TextboxPalette -TextboxBorder:: ; ef8 (0:0ef8) +TextboxBorder:: + ; Top push hl ld a, "┌" ld [hli], a - inc a - call TextboxBorder_PlaceTiles - inc a + inc a ; "─" + call .PlaceChars + inc a ; "┐" ld [hl], a pop hl @@ -61,7 +70,7 @@ TextboxBorder:: ; ef8 (0:0ef8) ld a, "│" ld [hli], a ld a, " " - call TextboxBorder_PlaceTiles + call .PlaceChars ld [hl], "│" pop hl @@ -74,11 +83,13 @@ TextboxBorder:: ; ef8 (0:0ef8) ld a, "└" ld [hli], a ld a, "─" - call TextboxBorder_PlaceTiles + call .PlaceChars ld [hl], "┘" + ret -TextboxBorder_PlaceTiles:: ; f25 (0:0f25) +.PlaceChars: +; Place char a c times. ld d, c .loop ld [hli], a @@ -86,14 +97,15 @@ TextboxBorder_PlaceTiles:: ; f25 (0:0f25) jr nz, .loop ret -TextboxPalette - ld de, wAttrMap - wTileMap +TextboxPalette:: +; Fill text box width c height b at hl with pal 7 + ld de, wAttrmap - wTilemap add hl, de inc b inc b inc c inc c - ld a, TEXTBOX_PAL + ld a, PAL_BG_TEXT .col push bc push hl @@ -109,7 +121,8 @@ TextboxPalette jr nz, .col ret -SpeechTextbox:: ; f45 (0:0f45) +SpeechTextbox:: +; Standard textbox. hlcoord TEXTBOX_X, TEXTBOX_Y ld b, TEXTBOX_INNERH ld c, TEXTBOX_INNERW @@ -119,20 +132,22 @@ TestText:: text "ゲームフりーク!" done -RadioTerminator:: ; 1052 +RadioTerminator:: ld hl, .stop ret -.stop db "@" +.stop: + text_end PrintText:: call SetUpTextbox + PrintTextboxText:: bccoord TEXTBOX_INNERX, TEXTBOX_INNERY call PlaceHLTextAtBC ret -SetUpTextbox:: ; f68 (0:0f68) +SetUpTextbox:: push hl call SpeechTextbox call UpdateSprites @@ -140,10 +155,10 @@ SetUpTextbox:: ; f68 (0:0f68) pop hl ret -PlaceString:: ; f74 (0:0f74) +PlaceString:: push hl -PlaceNextChar:: ; f75 (0:0f75) +PlaceNextChar:: ld a, [de] cp "@" jr nz, CheckDict @@ -151,32 +166,36 @@ PlaceNextChar:: ; f75 (0:0f75) ld c, l pop hl ret - pop de -NextChar:: ; f7f (0:0f7f) + +NextChar:: inc de jp PlaceNextChar -CheckDict -dict: macro -if \1 == 0 +CheckDict:: +dict: MACRO +if \1 == "<NULL>" and a else cp \1 endc - jp z, \2 -endm -dict2: macro - cp \1 +if STRSUB("\2", 1, 1) == "\"" +; Replace a character with another one jr nz, ._\@ ld a, \2 ._\@: -endm +elif STRSUB("\2", 1, 1) == "." +; Locals can use a short jump + jr z, \2 +else + jp z, \2 +endc +ENDM dict "<LINE>", LineChar dict "<NEXT>", NextLineChar - dict $00, NullChar + dict "<NULL>", NullChar dict $4c, Char4C dict $4b, Char4B dict "<PARA>", Paragraph @@ -201,60 +220,62 @@ endm dict "<PROMPT>", PromptText dict "<PKMN>", PlacePKMN dict "<POKE>", PlacePOKE - dict $25, NextChar - dict2 $1f, " " + dict "%", NextChar + dict "¯", " " dict "<DEXEND>", PlaceDexEnd dict "<TARGET>", PlaceMoveTargetsName dict "<USER>", PlaceMoveUsersName dict "<ENEMY>", PlaceEnemysName - cp $e4 jr z, .diacritic cp $e5 jr nz, .not_diacritic + .diacritic ld b, a call Diacritic jp NextChar .not_diacritic - cp $60 + cp FIRST_REGULAR_TEXT_CHAR jr nc, .place - cp $40 + + cp "パ" jr nc, .handakuten - cp $20 - jr nc, .daku1 - add $80 - jr .daku2 - -.daku1 - add $90 -.daku2 - ld b, $e5 + +.dakuten + cp FIRST_HIRAGANA_DAKUTEN_CHAR + jr nc, .hiragana_dakuten + add "カ" - "ガ" + jr .katakana_dakuten +.hiragana_dakuten + add "か" - "が" +.katakana_dakuten + ld b, "゙" ; dakuten call Diacritic jr .place .handakuten - cp $44 - jr nc, .han1 - add $59 - jr .han2 - -.han1 - add $86 -.han2 - ld b, $e4 + cp "ぱ" + jr nc, .hiragana_handakuten + add "ハ" - "パ" + jr .katakana_handakuten +.hiragana_handakuten + add "は" - "ぱ" +.katakana_handakuten + ld b, "゚" ; handakuten call Diacritic + .place ld [hli], a call PrintLetterDelay jp NextChar -print_name: macro +print_name: MACRO push de ld de, \1 jp PlaceCommandCharacter -endm +ENDM PrintMomsName:: print_name wMomsName ; 1066 (0:1066) PrintPlayerName:: print_name wPlayerName ; 106d (0:106d) @@ -402,7 +423,7 @@ Paragraph:: ; 1187 (0:1187) call LoadBlinkingCursor .asm_1192 call Text_WaitBGMap - call ButtonSound + call PromptButton hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY lb bc, TEXTBOX_INNERH - 1, TEXTBOX_INNERW call ClearBox @@ -421,7 +442,7 @@ Char4B:: ; 11b0 (0:11b0) .link_battle call Text_WaitBGMap push de - call ButtonSound + call PromptButton pop de ld a, [wLinkMode] or a @@ -460,7 +481,7 @@ PromptText:: ; 11eb (0:11eb) .ok call Text_WaitBGMap - call ButtonSound + call PromptButton ld a, [wLinkMode] cp $3 jr z, DoneText @@ -706,7 +727,7 @@ Text_WAIT_BUTTON:: ; 132c (0:132c) push hl call LoadBlinkingCursor push bc - call ButtonSound + call PromptButton pop bc call UnloadBlinkingCursor pop hl @@ -840,7 +861,7 @@ Text_TX_DOTS:: ; 13c3 (0:13c3) Text_TX_0D:: ; 13e2 (0:13e2) push hl push bc - call ButtonSound + call PromptButton pop bc pop hl ret diff --git a/home/tilemap.asm b/home/tilemap.asm index 04cbd474..ba251ec0 100755 --- a/home/tilemap.asm +++ b/home/tilemap.asm @@ -76,7 +76,7 @@ CopyTilemapAtOnce:: di ld a, BANK(vTiles3) ldh [rVBK], a - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap call .StackPointerMagic ld a, BANK(vTiles0) ldh [rVBK], a diff --git a/home/time.asm b/home/time.asm index ab03e930..8e935ed2 100644 --- a/home/time.asm +++ b/home/time.asm @@ -1,53 +1,78 @@ -AskTimer:: ; 45b (0:045b) +; Functions relating to the timer interrupt and the real-time-clock. + +Unreferenced_Timer:: reti -LatchClock:: ; 45c (0:045c) - ld a, $0 +LatchClock:: +; latch clock counter data + ld a, 0 ld [MBC3LatchClock], a - ld a, $1 + ld a, 1 ld [MBC3LatchClock], a ret -UpdateTime:: ; 467 (0:0467) +UpdateTime:: call GetClock call FixDays call FixTime farcall Function14032 ret -GetClock:: ; 477 (0:0477) +GetClock:: +; 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 + maskbits 60 ldh [hRTCSeconds], a + + ld [hl], RTC_M ld a, [de] - and $3f + maskbits 60 ldh [hRTCMinutes], a + ld [hl], RTC_H ld a, [de] - and $1f + maskbits 24 ldh [hRTCHours], a + ld [hl], RTC_DL ld a, [de] ldh [hRTCDayLo], a + ld [hl], RTC_DH ld a, [de] ldh [hRTCDayHi], a + +; unlatch clock / disable clock r/w call CloseSRAM ret -FixDays:: ; 4a8 (0:04a8) - ldh a, [hRTCDayHi] +FixDays:: +; fix day count +; mod by 140 + +; check if day count > 255 (bit 8 set) + ldh a, [hRTCDayHi] ; DH bit 0, a jr z, .daylo +; reset dh (bit 8) res 0, a ldh [hRTCDayHi], a + +; mod 140 +; mod twice since bit 8 (DH) was set ldh a, [hRTCDayLo] .modh sub 140 @@ -56,61 +81,86 @@ FixDays:: ; 4a8 (0:04a8) sub 140 jr nc, .modl add 140 + +; update dl ldh [hRTCDayLo], a - ld a, $40 + +; flag for sRTCStatusFlags + ld a, %01000000 jr .set + .daylo +; quit if fewer than 140 days have passed ldh a, [hRTCDayLo] cp 140 jr c, .quit + +; mod 140 .mod sub 140 jr nc, .mod add 140 + +; update dl ldh [hRTCDayLo], a - ld a, $20 + +; flag for sRTCStatusFlags + ld a, %00100000 + .set +; update clock with modded day value push af call SetClock pop af scf ret + .quit ccf xor a ret -FixTime:: ; 4de (0:04de) +FixTime:: +; add ingame time (set at newgame) to current time +; store time in wCurDay, hHours, hMinutes, hSeconds + +; second ldh a, [hRTCSeconds] ld c, a ld a, [wd1df] add c sub 60 - jr nc, .asm_4eb + jr nc, .updatesec add 60 -.asm_4eb +.updatesec ldh [hSeconds], a - ccf + +; minute + ccf ; carry is set, so turn it off ldh a, [hRTCMinutes] ld c, a ld a, [wd1de] adc c sub 60 - jr nc, .asm_4fb + jr nc, .updatemin add 60 -.asm_4fb +.updatemin ldh [hMinutes], a - ccf + +; hour + ccf ; carry is set, so turn it off ldh a, [hRTCHours] ld c, a ld a, [wd1dd] adc c sub 24 - jr nc, .asm_50b + jr nc, .updatehr add 24 -.asm_50b +.updatehr ldh [hHours], a - ccf + +; day + ccf ; carry is set, so turn it off ldh a, [hRTCDayLo] ld c, a ld a, [wd1dc] @@ -118,14 +168,14 @@ FixTime:: ; 4de (0:04de) ld [wCurDay], a ret -SetTimeOfDay:: +InitTimeOfDay:: xor a ld [wStringBuffer2], a - ld a, $0 + ld a, 0 ; useless ld [wStringBuffer2 + 3], a jr InitTime -SetDayOfWeek:: +InitDayOfWeek:: call UpdateTime ldh a, [hHours] ld [wStringBuffer2 + 1], a @@ -133,18 +183,18 @@ SetDayOfWeek:: ld [wStringBuffer2 + 2], a ldh a, [hSeconds] ld [wStringBuffer2 + 3], a - jr InitTime + jr InitTime ; useless InitTime:: farcall Function140ff ret PanicResetClock:: - call ClearhRTC + call .ClearhRTC call SetClock ret -ClearhRTC:: ; 546 (0:0546) +.ClearhRTC: xor a ldh [hRTCSeconds], a ldh [hRTCMinutes], a @@ -153,36 +203,55 @@ ClearhRTC:: ; 546 (0:0546) ldh [hRTCDayHi], a ret -SetClock:: ; 552 (0:0552) +SetClock:: +; 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 + bit 6, a ; halt ld [de], a + +; seconds ld [hl], RTC_S ldh a, [hRTCSeconds] ld [de], a +; minutes ld [hl], RTC_M ldh a, [hRTCMinutes] ld [de], a +; hours ld [hl], RTC_H ldh a, [hRTCHours] ld [de], a +; day lo ld [hl], RTC_DL ldh a, [hRTCDayLo] ld [de], a +; day hi ld [hl], RTC_DH ldh a, [hRTCDayHi] - res 6, a + res 6, a ; make sure timer is active ld [de], a - call CloseSRAM + +; cleanup + call CloseSRAM ; unlatch clock, disable clock r/w ret ClearRTCStatus:: +; clear sRTCStatusFlags xor a push af ld a, BANK(s0_ac60) @@ -193,6 +262,7 @@ ClearRTCStatus:: ret RecordRTCStatus:: +; append flags to sRTCStatusFlags ld hl, s0_ac60 push af ld a, BANK(s0_ac60) @@ -204,6 +274,7 @@ RecordRTCStatus:: ret CheckRTCStatus:: +; check sRTCStatusFlags ld a, BANK(s0_ac60) call OpenSRAM ld a, [s0_ac60] diff --git a/home/time_palettes.asm b/home/time_palettes.asm index 5cbd1f04..4140b34d 100644 --- a/home/time_palettes.asm +++ b/home/time_palettes.asm @@ -1,4 +1,4 @@ -RTC:: ; 343 +UpdateTimeAndPals:: ; update time and time-sensitive palettes ; rtc enabled? @@ -10,13 +10,13 @@ RTC:: ; 343 ; obj update on? ld a, [wVramState] - bit 0, a + bit 0, a ; obj update ret z -TimeOfDayPals:: ; 352 +TimeOfDayPals:: callfar _TimeOfDayPals ret -UpdateTimePals:: ; 359 +UpdateTimePals:: callfar _UpdateTimePals - ret + ret
\ No newline at end of file diff --git a/home/vblank.asm b/home/vblank.asm index 88923ee0..c32adcf6 100644 --- a/home/vblank.asm +++ b/home/vblank.asm @@ -102,13 +102,12 @@ VBlank0:: call Function1642 .done - ldh a, [hOAMUpdate] and a jr nz, .done_oam call hTransferVirtualOAM -.done_oam +.done_oam ; vblank-sensitive operations are done xor a @@ -119,15 +118,15 @@ VBlank0:: jr z, .ok dec a ld [wOverworldDelay], a -.ok +.ok ld a, [wTextDelayFrames] and a jr z, .ok2 dec a ld [wTextDelayFrames], a -.ok2 +.ok2 call UpdateJoypad ld a, BANK(_UpdateSound) @@ -161,6 +160,7 @@ VBlank1:: call Serve2bppRequest call hTransferVirtualOAM + .done ldh a, [hLCDCPointer] or a @@ -168,6 +168,7 @@ VBlank1:: ld c, a ld a, [wc700] ld [$ff00+c], a + .skip_lcd xor a ld [wVBlankOccurred], a @@ -266,8 +267,8 @@ VBlank5:: call UpdateBGMap call Serve2bppRequest -.done +.done xor a ld [wVBlankOccurred], a @@ -355,10 +356,8 @@ VBlank3:: call UpdateBGMapBuffer call Serve2bppRequest - call Serve1bppRequest call AnimateTileset - call hTransferVirtualOAM xor a @@ -369,8 +368,8 @@ VBlank3:: jr z, .okay dec a ld [wTextDelayFrames], a -.okay +.okay xor a ldh [rIF], a ld a, %10 ; lcd stat diff --git a/home/video.asm b/home/video.asm index aca44d2d..5b17ce44 100644 --- a/home/video.asm +++ b/home/video.asm @@ -1,4 +1,11 @@ -UpdateBGMapBuffer:: ; 1458 (0:1458) +UpdateBGMapBuffer:: +; Copy [hBGMapTileCount] 16x8 tiles from wBGMapBuffer +; to bg map addresses in wBGMapBufferPtrs. + +; [hBGMapTileCount] must be even since this is done in pairs. + +; Return carry on success. + ldh a, [hBGMapUpdate] and a ret z @@ -8,22 +15,34 @@ UpdateBGMapBuffer:: ; 1458 (0:1458) ld hl, wBGMapBufferPtrs ld sp, hl +; We can now pop the addresses of affected spots on the BG Map + ld hl, wBGMapPalBuffer ld de, wBGMapBuffer .next +; Copy a pair of 16x8 blocks (one 16x16 block) + + rept 2 +; Get our BG Map address pop bc - ld a, $1 + +; Palettes + ld a, 1 ldh [rVBK], a + ld a, [hli] ld [bc], a inc c ld a, [hli] ld [bc], a dec c - ld a, $0 + +; Tiles + ld a, 0 ldh [rVBK], a + ld a, [de] inc de ld [bc], a @@ -33,6 +52,7 @@ rept 2 ld [bc], a endr +; We've done 2 16x8 blocks ldh a, [hFFDE] dec a dec a @@ -52,12 +72,16 @@ endr ret WaitTop:: +; Wait until the top third of the BG Map is being updated. + ldh a, [hBGMapMode] and a ret z + ldh a, [hBGMapThird] and a jr z, .done + call DelayFrame jr WaitTop @@ -66,16 +90,20 @@ WaitTop:: ldh [hBGMapMode], a ret -UpdateBGMap:: ; 14bb (0:14bb) +UpdateBGMap:: +; Update the BG Map, in thirds, from wTilemap and wAttrmap. + ldh a, [hBGMapMode] and a ret z - dec a +; BG Map 0 + dec a ; 1 jr z, .Tiles - dec a + dec a ; 2 jr z, .Attr +; BG Map 1 dec a ldh a, [hBGMapAddress] @@ -84,17 +112,17 @@ UpdateBGMap:: ; 14bb (0:14bb) ld h, a push hl - xor a + xor a ; LOW(vBGMap1) ldh [hBGMapAddress], a - ld a, $9c + ld a, HIGH(vBGMap1) ldh [hBGMapAddress + 1], a ldh a, [hBGMapMode] push af - cp $3 + cp 3 call z, .Tiles pop af - cp $4 + cp 4 call z, .Attr pop hl @@ -104,28 +132,34 @@ UpdateBGMap:: ; 14bb (0:14bb) ldh [hBGMapAddress + 1], a ret -.Attr - ld a, $1 +.Attr: + ld a, 1 ldh [rVBK], a - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap call .update - ld a, $0 + + ld a, 0 ldh [rVBK], a ret -.Tiles +.Tiles: hlcoord 0, 0 + .update ld [hSPBuffer], sp +; Which third? ldh a, [hBGMapThird] - and a + and a ; 0 jr z, .top - dec a + dec a ; 1 jr z, .middle + ; 2 THIRD_HEIGHT EQU SCREEN_HEIGHT / 3 + +.bottom ld de, 2 * THIRD_HEIGHT * SCREEN_WIDTH add hl, de ld sp, hl @@ -133,11 +167,12 @@ THIRD_HEIGHT EQU SCREEN_HEIGHT / 3 ldh a, [hBGMapAddress + 1] ld h, a ldh a, [hBGMapAddress] - ld l, a + ld de, 2 * THIRD_HEIGHT * BG_MAP_WIDTH add hl, de +; Next time: top third xor a jr .start @@ -154,7 +189,8 @@ THIRD_HEIGHT EQU SCREEN_HEIGHT / 3 ld de, THIRD_HEIGHT * BG_MAP_WIDTH add hl, de - ld a, $2 +; Next time: bottom third + ld a, 2 jr .start .top @@ -165,16 +201,21 @@ THIRD_HEIGHT EQU SCREEN_HEIGHT / 3 ldh a, [hBGMapAddress] ld l, a - ld a, $1 +; Next time: middle third + ld a, 1 .start +; Which third to update next time ldh [hBGMapThird], a + +; Rows of tiles in a third ld a, SCREEN_HEIGHT / 3 -; Discrepancy between TileMap and BGMap +; Discrepancy between wTilemap and BGMap ld bc, BG_MAP_WIDTH - (SCREEN_WIDTH - 1) - + .row +; Copy a row of 20 tiles rept SCREEN_WIDTH / 2 - 1 pop de ld [hl], e @@ -198,24 +239,31 @@ endr ld sp, hl ret -Serve1bppRequest:: ; 1579 (0:1579) +Serve1bppRequest:: +; Only call during the first fifth of VBlank + ld a, [wRequested1bpp] and a ret z +; Copy [wRequested1bpp] 1bpp tiles from [wRequested1bppSource] to [wRequested1bppDest] + ld [hSPBuffer], sp +; Source ld hl, wRequested1bppSource ld a, [hli] ld h, [hl] ld l, a ld sp, hl +; Destination ld hl, wRequested1bppDest ld a, [hli] ld h, [hl] ld l, a +; # tiles to copy ld a, [wRequested1bpp] ld b, a @@ -223,6 +271,7 @@ Serve1bppRequest:: ; 1579 (0:1579) ld [wRequested1bpp], a .next + rept 3 pop de ld [hl], e @@ -261,25 +310,39 @@ endr ld sp, hl ret -Serve2bppRequest:: ; 15d0 (0:15d0) +Serve2bppRequest:: +; Only call during the first fifth of VBlank + ld a, [wRequested2bpp] and a ret z + +; Copy [wRequested2bpp] 2bpp tiles from [wRequested2bppSource] to [wRequested2bppDest] + ld [hSPBuffer], sp + +; Source ld hl, wRequested2bppSource ld a, [hli] ld h, [hl] ld l, a ld sp, hl + +; Destination ld hl, wRequested2bppDest ld a, [hli] ld h, [hl] ld l, a + +; # tiles to copy ld a, [wRequested2bpp] ld b, a + xor a ld [wRequested2bpp], a + .next + rept 7 pop de ld [hl], e @@ -310,33 +373,42 @@ endr ld sp, hl ret -AnimateTileset:: ; 162b (0:162b) +AnimateTileset:: +; Only call during the first fifth of VBlank + ldh a, [hMapAnims] and a ret z + ldh a, [hROMBank] push af ld a, $3f rst Bankswitch - call $4003 + + call $4003 ; ??? + pop af rst Bankswitch ret + ret + ld hl, rLCDC set 1, [hl] ret -Function1642:: ; 1642 (0:1642) +Function1642:: nop ldh a, [hVBlankCounter + 1] and a ret z + dec a jr z, .one dec a jr z, .two - ld a, $2 + + ld a, 2 ldh [hVBlankCounter + 1], a ld hl, hBGMapAddress ld a, [hli] @@ -356,13 +428,14 @@ endr ret .two - ld a, $1 + ld a, 1 ld de, $240 jr .go .one xor a ld de, $320 + .go ldh [hVBlankCounter + 1], a ld hl, hBGMapAddress diff --git a/home/window.asm b/home/window.asm index 20521b98..ac08375e 100644 --- a/home/window.asm +++ b/home/window.asm @@ -1,22 +1,26 @@ -Function2e80:: ; 2e80 (0:2e80) +RefreshScreen:: call ClearWindowData ldh a, [hROMBank] push af - ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; and BANK(LoadFonts_NoOAMUpdate) + ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; aka BANK(LoadFonts_NoOAMUpdate) rst Bankswitch + call ReanchorBGMap_NoOAMUpdate - call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap + call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap call LoadFonts_NoOAMUpdate + pop af rst Bankswitch ret -CloseText +CloseText:: ldh a, [hOAMUpdate] push af ld a, $1 ldh [hOAMUpdate], a + call .CloseText + pop af ldh [hOAMUpdate], a ret @@ -26,7 +30,7 @@ CloseText xor a ldh [hBGMapMode], a call OverworldTextModeSwitch - call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap + call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap xor a ldh [hBGMapMode], a call SafeUpdateSprites @@ -43,27 +47,31 @@ OpenText:: call ClearWindowData ldh a, [hROMBank] push af - ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; and BANK(LoadFonts_NoOAMUpdate) + ld a, BANK(ReanchorBGMap_NoOAMUpdate) ; aka BANK(LoadFonts_NoOAMUpdate) rst Bankswitch - call ReanchorBGMap_NoOAMUpdate + + call ReanchorBGMap_NoOAMUpdate ; clear bgmap call SpeechTextbox - call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap - call LoadFonts_NoOAMUpdate + call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap ; anchor bgmap + call LoadFonts_NoOAMUpdate ; load font pop af rst Bankswitch + ret -_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap:: ; 2ee3 (0:2ee3) +_OpenAndCloseMenu_HDMATransferTilemapAndAttrmap:: ldh a, [hOAMUpdate] push af - ld a, $1 + ld a, 1 ldh [hOAMUpdate], a + call CGBOnly_CopyTilemapAtOnce + pop af ldh [hOAMUpdate], a ret -SafeUpdateSprites:: ; 2ef1 (0:2ef1) +SafeUpdateSprites:: ldh a, [hOAMUpdate] push af ldh a, [hBGMapMode] @@ -72,7 +80,9 @@ SafeUpdateSprites:: ; 2ef1 (0:2ef1) ldh [hBGMapMode], a ld a, $1 ldh [hOAMUpdate], a + call UpdateSprites + xor a ldh [hOAMUpdate], a call DelayFrame @@ -82,7 +92,6 @@ SafeUpdateSprites:: ; 2ef1 (0:2ef1) ldh [hOAMUpdate], a ret -Function2f0e:: +; unused scf ret - diff --git a/items/item_effects.asm b/items/item_effects.asm index 3ab2de15..9c494885 100755 --- a/items/item_effects.asm +++ b/items/item_effects.asm @@ -634,7 +634,7 @@ UltraBall: ; e926 and a jr z, .toss call ClearBGPalettes - call ClearTileMap + call ClearTilemap .toss ld hl, wNumItems inc a @@ -1481,7 +1481,7 @@ BitterBerry: ; f1c0 ldh [hBattleTurn], a call Functionf7d0 ld hl, ConfusedNoMoreText - call StdBattleTextBox + call StdBattleTextbox ld a, $0 .asm_f1d9 jp Functionf0f4 diff --git a/macros/coords.asm b/macros/coords.asm index 0833c242..0fbf96cc 100755 --- a/macros/coords.asm +++ b/macros/coords.asm @@ -5,7 +5,7 @@ decoord EQUS "coord de," coord: MACRO ; register, x, y[, origin] if _NARG < 4 - ld \1, (\3) * SCREEN_WIDTH + (\2) + wTileMap + ld \1, (\3) * SCREEN_WIDTH + (\2) + wTilemap else ld \1, (\3) * SCREEN_WIDTH + (\2) + \4 endc @@ -27,7 +27,7 @@ ENDM dwcoord: MACRO ; x, y rept _NARG / 2 - dw (\2) * SCREEN_WIDTH + (\1) + wTileMap + dw (\2) * SCREEN_WIDTH + (\1) + wTilemap shift shift endr @@ -36,7 +36,7 @@ ENDM ldcoord_a: MACRO ; x, y[, origin] if _NARG < 3 - ld [(\2) * SCREEN_WIDTH + (\1) + wTileMap], a + ld [(\2) * SCREEN_WIDTH + (\1) + wTilemap], a else ld [(\2) * SCREEN_WIDTH + (\1) + \3], a endc @@ -45,7 +45,7 @@ ENDM lda_coord: MACRO ; x, y[, origin] if _NARG < 3 - ld a, [(\2) * SCREEN_WIDTH + (\1) + wTileMap] + ld a, [(\2) * SCREEN_WIDTH + (\1) + wTilemap] else ld a, [(\2) * SCREEN_WIDTH + (\1) + \3] endc @@ -8,7 +8,7 @@ INCLUDE "engine/link/place_waiting_text.asm" DummyPredef1: ret -LoadPushOAM:: ; 4032 (1:4032) +WriteOAMDMACodeToHRAM:: ; 4032 (1:4032) ld c, hTransferVirtualOAM - $ff00 ld b, PushOAMEnd - PushOAM ld hl, PushOAM @@ -64,7 +64,7 @@ Function656b: ; 656b (1:656b) call OverworldTextModeSwitch ld a, $9c call .LoadBGMapAddrIntoHRAM - call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap + call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap xor a ldh [hBGMapMode], a ldh [hWY], a @@ -192,9 +192,9 @@ INCLUDE "engine/events/shuckle.asm" INCLUDE "engine/events/haircut.asm" SECTION "bank2", ROMX, BANK[$2] -SwapTextboxPalettes:: - ld hl, wTileMap - ld de, wAttrMap +_SwapTextboxPalettes:: + ld hl, wTilemap + ld de, wAttrmap ld b, $12 .asm_8008 ld c, $14 @@ -247,7 +247,7 @@ SwapTextboxPalettes:: jr nz, .asm_8008 ret -ScrollBGMapPalettes:: ; 804f (2:404f) +_ScrollBGMapPalettes:: ; 804f (2:404f) ld hl, wBGMapBuffer ld de, wBGMapPalBuffer .asm_8055 @@ -667,9 +667,9 @@ Function1416d:: ; 1416d dr $1416d, $14226 LoadUsedSpritesGFX: dr $14226, $14317 -DoesSpriteHaveFacings_:: ; 14317 +_DoesSpriteHaveFacings:: ; 14317 dr $14317, $14334 -GetSpritePalette_:: ; 14334 +_GetSpritePalette:: ; 14334 dr $14334, $14a18 Function14a18:: ; 14a18 dr $14a18, $14a2d @@ -914,7 +914,7 @@ UpdateEnemyHUD:: LoadEnemyMon: dr $3e74b, $3ec11 -BattleRandom_:: ; 3ec11 +_BattleRandom:: ; 3ec11 dr $3ec11, $3f196 FillInExpBar:: @@ -1130,7 +1130,7 @@ SECTION "bank20", ROMX, BANK[$20] SECTION "bank21", ROMX, BANK[$21] dr $84000, $842db -PrinterReceive_:: ; 842db +_PrinterReceive:: ; 842db dr $842db, $84684 Function84684: @@ -1209,10 +1209,10 @@ AnimatedObjects_PlayFrameAndDelay: AnimatedObjects_PlayFrame: dr $8d18a, $8d1f7 -InitAnimatedObjectStruct_:: ; 8d1f7 +_InitSpriteAnimStruct:: ; 8d1f7 dr $8d1f7, $8d332 -ReinitAnimatedObjectFrame_:: ; 8d332 +_ReinitSpriteAnimFrame:: ; 8d332 IF DEF(GOLD) dr $8d332, $8e79f @@ -1375,7 +1375,7 @@ DummyPredef39:: PlayBattleAnim:: dr $cc0d7, $cc283 -BattleAnimCommands:: +ClearBattleAnims:: dr $cc283, $cfce3 SECTION "bank34", ROMX, BANK[$34] @@ -1517,7 +1517,7 @@ SECTION "bank70", ROMX, BANK[$70] dr $1c0000, $1c0a66 UpdateTimePredef:: dr $1c0a66, $1c0de9 -DudeAutoInput_A:: +_DudeAutoInput_A:: dr $1c0de9, $1c0dee DudeAutoInput_RightA:: diff --git a/predef/cgb.asm b/predef/cgb.asm index a0652401..a7baefe8 100755 --- a/predef/cgb.asm +++ b/predef/cgb.asm @@ -115,31 +115,31 @@ asm_93e1 ld de, wTempBGPal7 ld bc, $8 call CopyBytes - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap ld bc, SCREEN_HEIGHT * SCREEN_WIDTH ld a, $2 call ByteFill - hlcoord 0, 4, wAttrMap + hlcoord 0, 4, wAttrmap lb bc, $8, $a ld a, $0 call Function9af1 - hlcoord 10, 0, wAttrMap + hlcoord 10, 0, wAttrmap lb bc, $7, $a ld a, $1 call Function9af1 - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap lb bc, $4, $a ld a, $2 call Function9af1 - hlcoord 10, 7, wAttrMap + hlcoord 10, 7, wAttrmap lb bc, $5, $a ld a, $3 call Function9af1 - hlcoord 10, 11, wAttrMap + hlcoord 10, 11, wAttrmap lb bc, $1, $9 ld a, $4 call Function9af1 - hlcoord 0, 12, wAttrMap + hlcoord 0, 12, wAttrmap ld bc, $78 ld a, $7 call ByteFill @@ -181,23 +181,23 @@ Function945e: ; 945e (2:545e) ld bc, $18 call CopyBytes call Function9b1d - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap lb bc, $8, $14 ld a, $1 call Function9af1 - hlcoord 10, 16, wAttrMap + hlcoord 10, 16, wAttrmap ld bc, $a ld a, $2 call ByteFill - hlcoord 13, 5, wAttrMap + hlcoord 13, 5, wAttrmap lb bc, $2, $2 ld a, $3 call Function9af1 - hlcoord 15, 5, wAttrMap + hlcoord 15, 5, wAttrmap lb bc, $2, $2 ld a, $4 call Function9af1 - hlcoord 17, 5, wAttrMap + hlcoord 17, 5, wAttrmap lb bc, $2, $2 ld a, $5 call Function9af1 @@ -232,7 +232,7 @@ StatsScreenPals: Function94f1: ; 94f1 (2:54f1) call Function9513 - hlcoord 1, 1, wAttrMap + hlcoord 1, 1, wAttrmap lb bc, 7, 7 ld a, $1 call Function9af1 @@ -240,7 +240,7 @@ Function94f1: ; 94f1 (2:54f1) Function9502: ; 9502 (2:5502) call Function9513 - hlcoord 1, 1, wAttrMap + hlcoord 1, 1, wAttrmap lb bc, 5, 5 ld a, $1 call Function9af1 @@ -307,7 +307,7 @@ Function9561: ; 9561 (2:5561) call Function9adb .asm_9584 call Function9b1d - hlcoord 1, 4, wAttrMap + hlcoord 1, 4, wAttrmap lb bc, 7, 7 ld a, $1 call Function9af1 @@ -329,7 +329,7 @@ Function95a8: call Function9adb asm_95b1 call Function9b1d - hlcoord 1, 1, wAttrMap + hlcoord 1, 1, wAttrmap lb bc, 7, 7 ld a, $1 call Function9af1 @@ -355,7 +355,7 @@ Function95d5: ; 95d5 (2:55d5) call Function9be4 call Function9adb call Function9b1d - hlcoord 7, 5, wAttrMap + hlcoord 7, 5, wAttrmap lb bc, 7, 7 ld a, $1 call Function9af1 @@ -372,43 +372,43 @@ Function9605: ; 9605 (2:5605) ld bc, $80 call CopyBytes call Function9b1d - hlcoord 0, 2, wAttrMap + hlcoord 0, 2, wAttrmap lb bc, $a, $3 ld a, $2 call Function9af1 - hlcoord 17, 2, wAttrMap + hlcoord 17, 2, wAttrmap lb bc, $a, $3 ld a, $2 call Function9af1 - hlcoord 0, 4, wAttrMap + hlcoord 0, 4, wAttrmap lb bc, $6, $3 ld a, $3 call Function9af1 - hlcoord 17, 4, wAttrMap + hlcoord 17, 4, wAttrmap lb bc, $6, $3 ld a, $3 call Function9af1 - hlcoord 0, 6, wAttrMap + hlcoord 0, 6, wAttrmap lb bc, $2, $3 ld a, $4 call Function9af1 - hlcoord 17, 6, wAttrMap + hlcoord 17, 6, wAttrmap lb bc, $2, $3 ld a, $4 call Function9af1 - hlcoord 4, 2, wAttrMap + hlcoord 4, 2, wAttrmap lb bc, $2, $c ld a, $1 call Function9af1 - hlcoord 3, 2, wAttrMap + hlcoord 3, 2, wAttrmap lb bc, $a, $1 ld a, $1 call Function9af1 - hlcoord 16, 2, wAttrMap + hlcoord 16, 2, wAttrmap lb bc, $a, $1 ld a, $1 call Function9af1 - hlcoord 0, 12, wAttrMap + hlcoord 0, 12, wAttrmap ld bc, $78 ld a, $7 call ByteFill @@ -426,7 +426,7 @@ Function968d: ; 968d (2:568d) ld a, $3c call Function9ac7 call Function9ad2 - hlcoord 0, 6, wAttrMap + hlcoord 0, 6, wAttrmap lb bc, $c, $14 ld a, $1 call Function9af1 @@ -636,41 +636,41 @@ Function9802: ; 9802 (2:5802) ld a, $24 call Function9ac7 call Function9ad2 - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap ld bc, $168 ld a, $1 call ByteFill - hlcoord 14, 1, wAttrMap + hlcoord 14, 1, wAttrmap lb bc, $7, $5 xor a call Function9af1 - hlcoord 18, 1, wAttrMap + hlcoord 18, 1, wAttrmap ld [hl], $1 - hlcoord 2, 11, wAttrMap + hlcoord 2, 11, wAttrmap lb bc, $2, $4 ld a, $1 call Function9af1 - hlcoord 6, 11, wAttrMap + hlcoord 6, 11, wAttrmap lb bc, $2, $4 ld a, $2 call Function9af1 - hlcoord 10, 11, wAttrMap + hlcoord 10, 11, wAttrmap lb bc, $2, $4 ld a, $3 call Function9af1 - hlcoord 14, 11, wAttrMap + hlcoord 14, 11, wAttrmap lb bc, $2, $4 ld a, $4 call Function9af1 - hlcoord 2, 14, wAttrMap + hlcoord 2, 14, wAttrmap lb bc, $2, $4 ld a, $5 call Function9af1 - hlcoord 6, 14, wAttrMap + hlcoord 6, 14, wAttrmap lb bc, $2, $4 ld a, $6 call Function9af1 - hlcoord 10, 14, wAttrMap + hlcoord 10, 14, wAttrmap lb bc, $2, $4 ld a, $7 call Function9af1 @@ -694,7 +694,7 @@ Function98be: ; 98be (2:58be) add hl, bc call Function9adb call Function9b1d - hlcoord 11, 1, wAttrMap + hlcoord 11, 1, wAttrmap lb bc, $2, $9 ld a, $1 call Function9af1 @@ -732,23 +732,23 @@ Function991e: ; 991e (2:591e) ld bc, $40 call CopyBytes call Function9b1d - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap lb bc, $1, $a ld a, $1 call Function9af1 - hlcoord 10, 0, wAttrMap + hlcoord 10, 0, wAttrmap lb bc, $1, $a ld a, $2 call Function9af1 - hlcoord 7, 2, wAttrMap + hlcoord 7, 2, wAttrmap lb bc, $9, $1 ld a, $3 call Function9af1 - hlcoord 0, 7, wAttrMap + hlcoord 0, 7, wAttrmap lb bc, $3, $5 ld a, $4 call Function9af1 - hlcoord 0, 3, wAttrMap + hlcoord 0, 3, wAttrmap lb bc, $3, $5 ld a, $5 call Function9af1 @@ -791,9 +791,9 @@ Palettes_996f: Function999f: ; 999f (2:599f) call Function9757 - call FarCallSwapTextboxPalettes + call SwapTextboxPalettes ld de, $14 - hlcoord 0, 0, wAttrMap + hlcoord 0, 0, wAttrmap ld a, [wMenuBorderTopCoord] .asm_99ae and a @@ -828,11 +828,11 @@ Function99d9: ; 99d9 (2:59d9) ld hl, PalPacket_a015 + 1 call Function9ab2 call Function9b1d - hlcoord 0, 4, wAttrMap + hlcoord 0, 4, wAttrmap lb bc, $a, $14 ld a, $2 call Function9af1 - hlcoord 0, 6, wAttrMap + hlcoord 0, 6, wAttrmap lb bc, $6, $14 ld a, $1 call Function9af1 @@ -244,9 +244,9 @@ wVirtualOAMEnd:: SECTION "TileMap", WRAM0 -wTileMap:: ; c3a0 +wTilemap:: ; c3a0 ds SCREEN_HEIGHT * SCREEN_WIDTH -wTileMapEnd:: ; c508 +wTilemapEnd:: ; c508 SECTION "Animated Objects", WRAM0 wMisc:: ; c508 @@ -2064,9 +2064,9 @@ wccd6:: ds 1 ; ccd6 wccd7:: ds 1 ; ccd7 wccd8:: ds 1 ; ccd8 -wAttrMap:: ; ccd9 +wAttrmap:: ; ccd9 ds SCREEN_HEIGHT * SCREEN_WIDTH -wAttrMapEnd:: ; ce41 +wAttrmapEnd:: ; ce41 wce41:: ds 1 ; ce41 wce42:: ds 1 ; ce42 @@ -2145,9 +2145,9 @@ wce87:: ds 1 ; ce87 wce88:: ds 1 ; ce88 wce89:: ds 1 ; ce89 wce8a:: ds 1 ; ce8a -wMovementPerson:: ds 1 ; ce8b -wMovementDataPointerBank:: ds 1 ; ce8c -wMovementDataPointerAddr:: dw ; ce8d +wMovementObject:: ds 1 ; ce8b +wMovementDataBank:: ds 1 ; ce8c +wMovementDataAddress:: dw ; ce8d wce8f:: ds 1 ; ce8f wce90:: ds 1 ; ce90 wce91:: ds 1 ; ce91 @@ -2259,7 +2259,7 @@ wceec:: ds 1 ; ceec wMovementBufferCount:: ; ceed wceed:: ds 1 ; ceed -wMovementBufferPerson:: +wMovementBufferObject:: wceee:: ds 1 ; ceee wTemporaryBuffer:: |