diff options
Diffstat (limited to 'home')
-rw-r--r-- | home/audio.asm | 6 | ||||
-rw-r--r-- | home/battle.asm | 4 | ||||
-rw-r--r-- | home/copy.asm | 12 | ||||
-rw-r--r-- | home/flag.asm | 16 | ||||
-rw-r--r-- | home/hm_moves.asm | 27 | ||||
-rw-r--r-- | home/init.asm | 8 | ||||
-rw-r--r-- | home/item.asm | 4 | ||||
-rw-r--r-- | home/joypad.asm | 8 | ||||
-rw-r--r-- | home/map.asm | 239 | ||||
-rw-r--r-- | home/map_objects.asm | 84 | ||||
-rw-r--r-- | home/math.asm | 2 | ||||
-rw-r--r-- | home/menu.asm | 6 | ||||
-rw-r--r-- | home/movement.asm | 12 | ||||
-rw-r--r-- | home/names.asm | 278 | ||||
-rw-r--r-- | home/rtc.asm | 4 | ||||
-rw-r--r-- | home/serial.asm | 4 | ||||
-rw-r--r-- | home/text.asm | 84 | ||||
-rw-r--r-- | home/tilemap.asm | 6 | ||||
-rw-r--r-- | home/time.asm | 7 | ||||
-rw-r--r-- | home/trainers.asm | 263 | ||||
-rw-r--r-- | home/window.asm | 6 |
21 files changed, 821 insertions, 259 deletions
diff --git a/home/audio.asm b/home/audio.asm index 5e6eafe9a..98e1fc40c 100644 --- a/home/audio.asm +++ b/home/audio.asm @@ -295,7 +295,7 @@ IsSFXPlaying:: ; 3c74 ; 3c97 MaxVolume:: ; 3c97 - ld a, $77 ; max + ld a, MAX_VOLUME ld [Volume], a ret ; 3c9d @@ -348,9 +348,9 @@ FadeToMapMusic:: ; 3cbc ld a, 8 ld [MusicFade], a ld a, e - ld [MusicFadeIDLo], a + ld [MusicFadeID], a ld a, d - ld [MusicFadeIDHi], a + ld [MusicFadeID + 1], a ld a, e ld [wMapMusic], a diff --git a/home/battle.asm b/home/battle.asm index 3c2e4de43..30096fd4a 100644 --- a/home/battle.asm +++ b/home/battle.asm @@ -130,8 +130,8 @@ RefreshBattleHuds:: ; 39c9 ; 39d4 UpdateBattleHuds:: ; 39d4 - callba UpdatePlayerHUD - callba UpdateEnemyHUD + farcall UpdatePlayerHUD + farcall UpdateEnemyHUD ret ; 39e1 diff --git a/home/copy.asm b/home/copy.asm index 8a307b3df..8ee1c90f9 100644 --- a/home/copy.asm +++ b/home/copy.asm @@ -101,32 +101,32 @@ OldDMATransfer:: ; dfd ReplaceKrisSprite:: ; e4a - callba _ReplaceKrisSprite + farcall _ReplaceKrisSprite ret ; e51 LoadStandardFont:: ; e51 - callba _LoadStandardFont + farcall _LoadStandardFont ret ; e58 LoadFontsBattleExtra:: ; e58 - callba _LoadFontsBattleExtra + farcall _LoadFontsBattleExtra ret ; e5f LoadFontsExtra:: ; e5f - callba _LoadFontsExtra1 - callba _LoadFontsExtra2 + farcall _LoadFontsExtra1 + farcall _LoadFontsExtra2 ret ; e6c LoadFontsExtra2:: ; e6c - callba _LoadFontsExtra2 + farcall _LoadFontsExtra2 ret ; e73 diff --git a/home/flag.asm b/home/flag.asm index 099f4bf00..442c811c2 100644 --- a/home/flag.asm +++ b/home/flag.asm @@ -14,7 +14,7 @@ ResetBikeFlags:: ; 2e56 ; 2e5d ResetFlashIfOutOfCave:: ; 2e5d - ld a, [wPermission] + ld a, [wEnvironment] cp $2 jr z, .asm_2e69 cp $1 @@ -38,9 +38,9 @@ FlagAction:: ; 0x2e76 ; 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 @@ -75,9 +75,9 @@ FlagAction:: ; 0x2e76 ; 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] @@ -105,7 +105,7 @@ FlagAction:: ; 0x2e76 CheckReceivedDex:: ; 2ead ld de, ENGINE_POKEDEX ld b, CHECK_FLAG - callba EngineFlagAction + farcall EngineFlagAction ld a, c and a ret diff --git a/home/hm_moves.asm b/home/hm_moves.asm new file mode 100644 index 000000000..c4233d094 --- /dev/null +++ b/home/hm_moves.asm @@ -0,0 +1,27 @@ +; HM moves can't be forgotten + +IsHM:: ; 34df + cp HM01 + jr c, .NotHM + scf + ret +.NotHM: + and a + ret +; 34e7 + +IsHMMove:: ; 34e7 + ld hl, .HMMoves + ld de, 1 + jp IsInArray + +.HMMoves: ; 34f0 + db CUT + db FLY + db SURF + db STRENGTH + db FLASH + db WATERFALL + db WHIRLPOOL + db -1 ; end +; 34f8 diff --git a/home/init.asm b/home/init.asm index b983ce826..630cfe622 100644 --- a/home/init.asm +++ b/home/init.asm @@ -69,8 +69,8 @@ Init:: ; 17d ld [rLCDC], a ; Clear WRAM bank 0 - ld hl, wc000 - ld bc, wd000 - wc000 + ld hl, wRAM0Start + ld bc, wRAM1Start - wRAM0Start .ByteFill: ld [hl], 0 inc hl @@ -139,14 +139,14 @@ Init:: ; 17d ld a, -1 ld [hLinkPlayerNumber], a - callba InitCGBPals + farcall InitCGBPals ld a, VBGMap1 / $100 ld [hBGMapAddress + 1], a xor a ; VBGMap1 % $100 ld [hBGMapAddress], a - callba StartClock + farcall StartClock xor a ld [MBC3LatchClock], a diff --git a/home/item.asm b/home/item.asm index 92d74c350..2f550a200 100644 --- a/home/item.asm +++ b/home/item.asm @@ -1,5 +1,5 @@ DoItemEffect:: ; 2f3f - callba _DoItemEffect + farcall _DoItemEffect ret ; 2f46 @@ -7,7 +7,7 @@ CheckTossableItem:: ; 2f46 push hl push de push bc - callba _CheckTossableItem + farcall _CheckTossableItem pop bc pop de pop hl diff --git a/home/joypad.asm b/home/joypad.asm index 0cb2f6206..3d5f0aed5 100644 --- a/home/joypad.asm +++ b/home/joypad.asm @@ -130,7 +130,7 @@ GetJoypad:: ; 984 ; The player input can be automated using an input stream. ; See more below. ld a, [InputType] - cp a, AUTO_INPUT + cp AUTO_INPUT jr z, .auto ; To get deltas, take this and last frame's input. @@ -197,14 +197,14 @@ GetJoypad:: ; 984 .updateauto ; An input of $ff will end the stream. ld a, [hli] - cp a, -1 + cp -1 jr z, .stopauto ld b, a ; A duration of $ff will end the stream indefinitely. ld a, [hli] ld [AutoInputLength], a - cp a, -1 + cp -1 jr nz, .next ; The current input is overwritten. @@ -414,7 +414,7 @@ ButtonSound:: ; aaf ld a, [InputType] or a jr z, .input_wait_loop - callba _DudeAutoInput_A + farcall _DudeAutoInput_A .input_wait_loop call .blink_cursor diff --git a/home/map.asm b/home/map.asm index 967d13af5..37022e234 100644 --- a/home/map.asm +++ b/home/map.asm @@ -8,61 +8,61 @@ Clearwc7e8:: ; 210f ret ; 211b -CheckTriggers:: ; 211b -; Checks wCurrentMapTriggerPointer. If it's empty, returns -1 in a. Otherwise, returns the active trigger ID in a. +CheckScenes:: ; 211b +; Checks wCurrMapSceneScriptPointer. If it's empty, returns -1 in a. Otherwise, returns the active scene ID in a. push hl - ld hl, wCurrentMapTriggerPointer + ld hl, wCurrMapSceneScriptPointer ld a, [hli] ld h, [hl] ld l, a or h ld a, [hl] - jr nz, .triggerexists + jr nz, .scene_exists ld a, -1 -.triggerexists +.scene_exists pop hl ret ; 212a -GetCurrentMapTrigger:: ; 212a -; Grabs the wram map trigger pointer for the current map and loads it into wCurrentMapTriggerPointer. -; If there are no triggers, both bytes of wCurrentMapTriggerPointer are wiped clean. -; Copy the current map group and number into bc. This is needed for GetMapTrigger. +GetCurrentMapSceneID:: ; 212a +; Grabs the wram map scene script pointer for the current map and loads it into wCurrMapSceneScriptPointer. +; If there is no scene, both bytes of wCurrMapSceneScriptPointer are wiped clean. +; Copy the current map group and number into bc. This is needed for GetMapSceneID. ld a, [MapGroup] ld b, a ld a, [MapNumber] ld c, a -; Blank out wCurrentMapTriggerPointer; this is the default scenario. +; Blank out wCurrMapSceneScriptPointer; this is the default scenario. xor a - ld [wCurrentMapTriggerPointer], a - ld [wCurrentMapTriggerPointer + 1], a - call GetMapTrigger - ret c ; The map is not in the trigger table -; Load the trigger table pointer from de into wCurrentMapTriggerPointer + ld [wCurrMapSceneScriptPointer], a + ld [wCurrMapSceneScriptPointer + 1], a + call GetMapSceneID + ret c ; The map is not in the scene script table +; Load the scene script pointer from de into wCurrMapSceneScriptPointer ld a, e - ld [wCurrentMapTriggerPointer], a + ld [wCurrMapSceneScriptPointer], a ld a, d - ld [wCurrentMapTriggerPointer + 1], a + ld [wCurrMapSceneScriptPointer + 1], a xor a ret ; 2147 -GetMapTrigger:: ; 2147 -; Searches the trigger table for the map group and number loaded in bc, and returns the wram pointer in de. -; If the map is not in the trigger table, returns carry. +GetMapSceneID:: ; 2147 +; Searches the scene script table for the map group and number loaded in bc, and returns the wram pointer in de. +; If the map is not in the scene script table, returns carry. push bc ld a, [hROMBank] push af - ld a, BANK(MapTriggers) + ld a, BANK(MapScenes) rst Bankswitch - ld hl, MapTriggers + ld hl, MapScenes .loop push hl ld a, [hli] ; map group, or terminator cp -1 - jr z, .end ; the current map is not in the trigger table + jr z, .end ; the current map is not in the scene script table cp b jr nz, .next ; map group did not match ld a, [hli] ; map number @@ -72,7 +72,7 @@ GetMapTrigger:: ; 2147 .next pop hl - ld de, 4 ; size of an entry in the trigger table + ld de, 4 ; size of an entry in the scene script table add hl, de jr .loop @@ -152,9 +152,12 @@ LoadMetatiles:: ; 2198 ld e, l ld d, h ; Set hl to the address of the current metatile data ([TilesetBlocksAddress] + (a) tiles). - add a + ; This is buggy; it wraps around past 128 blocks. + ; To fix, uncomment the line below. + add a ; Comment or delete this line to fix the above bug. ld l, a ld h, 0 + ; add hl, hl add hl, hl add hl, hl add hl, hl @@ -212,7 +215,7 @@ endr ReturnToMapFromSubmenu:: ; 222a ld a, MAPSETUP_SUBMENU ld [hMapEntryMethod], a - callba RunMapSetupScript + farcall RunMapSetupScript xor a ld [hMapEntryMethod], a ret @@ -223,7 +226,7 @@ CheckWarpTile:: ; 2238 ret nc push bc - callba CheckDirectionalWarp + farcall CheckDirectionalWarp pop bc ret nc @@ -240,7 +243,7 @@ WarpCheck:: ; 224a ; 2252 GetDestinationWarpNumber:: ; 2252 - callba CheckWarpCollision + farcall CheckWarpCollision ret nc ld a, [hROMBank] @@ -386,7 +389,7 @@ CheckIndoorMap:: ; 22f4 ret z cp GATE ret z - cp PERM_5 + cp ENVIRONMENT_5 ret ; 2309 @@ -427,7 +430,7 @@ ReadMapEventHeader:: ; 2336 inc hl call ReadWarps call ReadCoordEvents - call ReadSignposts + call ReadBGEvents pop af and a @@ -442,7 +445,7 @@ ReadMapScripts:: ; 234f ld a, [hli] ld h, [hl] ld l, a - call ReadMapTriggers + call ReadMapSceneScripts call ReadMapCallbacks ret ; 235c @@ -508,19 +511,19 @@ GetMapConnection:: ; 23a3 ret ; 23ac -ReadMapTriggers:: ; 23ac - ld a, [hli] ; trigger count +ReadMapSceneScripts:: ; 23ac + ld a, [hli] ; scene script count ld c, a - ld [wCurrMapTriggerCount], a ; current map trigger count + ld [wCurrMapSceneScriptCount], a ; current map scene script count ld a, l - ld [wCurrMapTriggerHeaderPointer], a ; map trigger pointer + ld [wCurrMapSceneScriptHeaderPointer], a ; map scene script pointer ld a, h - ld [wCurrMapTriggerHeaderPointer + 1], a + ld [wCurrMapSceneScriptHeaderPointer + 1], a ld a, c and a ret z - ld bc, 4 ; size of a map trigger header entry + ld bc, 4 ; size of a map scene script header entry call AddNTimes ret ; 23c3 @@ -561,11 +564,11 @@ ReadWarps:: ; 23da ReadCoordEvents:: ; 23f1 ld a, [hli] ld c, a - ld [wCurrentMapXYTriggerCount], a + ld [wCurrMapCoordEventCount], a ld a, l - ld [wCurrentMapXYTriggerHeaderPointer], a + ld [wCurrMapCoordEventHeaderPointer], a ld a, h - ld [wCurrentMapXYTriggerHeaderPointer + 1], a + ld [wCurrMapCoordEventHeaderPointer + 1], a ld a, c and a @@ -576,14 +579,14 @@ ReadCoordEvents:: ; 23f1 ret ; 2408 -ReadSignposts:: ; 2408 +ReadBGEvents:: ; 2408 ld a, [hli] ld c, a - ld [wCurrentMapSignpostCount], a + ld [wCurrMapBGEventCount], a ld a, l - ld [wCurrentMapSignpostHeaderPointer], a + ld [wCurrMapBGEventHeaderPointer], a ld a, h - ld [wCurrentMapSignpostHeaderPointer + 1], a + ld [wCurrMapBGEventHeaderPointer + 1], a ld a, c and a @@ -601,17 +604,17 @@ ReadObjectEvents:: ; 241f ld hl, Map1Object ld a, [de] inc de - ld [wCurrentMapPersonEventCount], a + ld [wCurrMapObjectEventCount], a ld a, e - ld [wCurrentMapPersonEventHeaderPointer], a + ld [wCurrMapObjectEventHeaderPointer], a ld a, d - ld [wCurrentMapPersonEventHeaderPointer + 1], a + ld [wCurrMapObjectEventHeaderPointer + 1], a - ld a, [wCurrentMapPersonEventCount] + ld a, [wCurrMapObjectEventCount] call CopyMapObjectHeaders -; get NUM_OBJECTS - [wCurrentMapPersonEventCount] - ld a, [wCurrentMapPersonEventCount] +; get NUM_OBJECTS - [wCurrMapObjectEventCount] + ld a, [wCurrMapObjectEventCount] ld c, a ld a, NUM_OBJECTS ; - 1 sub c @@ -714,7 +717,7 @@ RestoreFacingAfterWarp:: ; 248a call .backup .skip - callba GetCoordOfUpperLeftCorner + farcall GetCoordOfUpperLeftCorner ret ; 24ba @@ -1047,15 +1050,15 @@ RunMapCallback:: ; 263b ExecuteCallbackScript:: ; 2674 ; Do map callback de and return to script bank b. - callba CallCallback + farcall CallCallback ld a, [ScriptMode] push af ld hl, ScriptFlags ld a, [hl] push af set 1, [hl] - callba EnableScriptMode - callba ScriptEvents + farcall EnableScriptMode + farcall ScriptEvents pop af ld [ScriptFlags], a pop af @@ -1107,7 +1110,7 @@ Call_a_de:: ; 26b7 ; 26c7 GetMovementData:: ; 26c7 -; Initialize the movement data for person c at b:hl +; Initialize the movement data for object c at b:hl ld a, [hROMBank] push af ld a, b @@ -1415,7 +1418,7 @@ LoadTileset:: ; 2821 ld a, $1 ld [rVBK], a - ld hl, w6_d600 + ld hl, wDecompressScratch + $60 tiles ld de, VTiles2 ld bc, $60 tiles call CopyBytes @@ -1436,7 +1439,7 @@ LoadTileset:: ; 2821 jr .skip_roof .load_roof - callba LoadMapGroupRoof + farcall LoadMapGroupRoof .skip_roof xor a @@ -1593,14 +1596,14 @@ GetMovementPermissions:: ; 2914 ; 2945 .MovementPermissionsData: ; 2945 - db 1 << DOWN - db 1 << UP - db 1 << LEFT - db 1 << RIGHT - db (1 << DOWN) | (1 << RIGHT) - db (1 << UP) | (1 << RIGHT) - db (1 << DOWN) | (1 << LEFT) - db (1 << UP) | (1 << LEFT) + db DOWN_MASK + db UP_MASK + db LEFT_MASK + db RIGHT_MASK + db DOWN_MASK | RIGHT_MASK + db UP_MASK | RIGHT_MASK + db DOWN_MASK | LEFT_MASK + db UP_MASK | LEFT_MASK ; 294d .UpDown: @@ -1837,7 +1840,7 @@ GetBlockLocation:: ; 2a66 ret ; 2a8b -CheckFacingSign:: ; 2a8b +CheckFacingBGEvent:: ; 2a8b call GetFacingTileCoord ; Load facing into b. ld b, a @@ -1848,8 +1851,8 @@ CheckFacingSign:: ; 2a8b ld a, e sub 4 ld e, a -; If there are no signposts, we don't need to be here. - ld a, [wCurrentMapSignpostCount] +; If there are no BG events, we don't need to be here. + ld a, [wCurrMapBGEventCount] and a ret z @@ -1857,16 +1860,16 @@ CheckFacingSign:: ; 2a8b ld a, [hROMBank] push af call SwitchToMapScriptHeaderBank - call CheckIfFacingTileCoordIsSign + call CheckIfFacingTileCoordIsBGEvent pop hl ld a, h rst Bankswitch ret ; 2aaa -CheckIfFacingTileCoordIsSign:: ; 2aaa -; Checks to see if you are facing a signpost. If so, copies it into EngineBuffer1 and sets carry. - ld hl, wCurrentMapSignpostHeaderPointer +CheckIfFacingTileCoordIsBGEvent:: ; 2aaa +; Checks to see if you are facing a BG event. If so, copies it into EngineBuffer1 and sets carry. + ld hl, wCurrMapBGEventHeaderPointer ld a, [hli] ld h, [hl] ld l, a @@ -1882,7 +1885,7 @@ CheckIfFacingTileCoordIsSign:: ; 2aaa .next pop hl - ld a, 5 ; signpost event length + ld a, 5 ; BG event event length add l ld l, a jr nc, .nocarry @@ -1896,39 +1899,39 @@ CheckIfFacingTileCoordIsSign:: ; 2aaa .copysign pop hl - ld de, wCurSignpostYCoord - ld bc, 5 ; signpost event length + ld de, wCurBGEventYCoord + ld bc, 5 ; BG event event length call CopyBytes scf ret ; 2ad4 -CheckCurrentMapXYTriggers:: ; 2ad4 -; If there are no xy triggers, we don't need to be here. - ld a, [wCurrentMapXYTriggerCount] +CheckCurrentMapCoordEvents:: ; 2ad4 +; If there are no coord events, we don't need to be here. + ld a, [wCurrMapCoordEventCount] and a ret z -; Copy the trigger count into c. +; Copy the coord event count into c. ld c, a ld a, [hROMBank] push af call SwitchToMapScriptHeaderBank - call .TriggerCheck + call .CoordEventCheck pop hl ld a, h rst Bankswitch ret -.TriggerCheck: -; Checks to see if you are standing on an xy-trigger. If yes, copies the trigger to EngineBuffer1 and sets carry. - ld hl, wCurrentMapXYTriggerHeaderPointer +.CoordEventCheck: +; Checks to see if you are standing on a coord event. If yes, copies the event to EngineBuffer1 and sets carry. + ld hl, wCurrMapCoordEventHeaderPointer ld a, [hli] ld h, [hl] ld l, a -; Load the active trigger ID into b - call CheckTriggers +; Load the active scene ID into b + call CheckScenes ld b, a -; Load your current coordinates into de. This will be used to check if your position is in the xy-trigger table for the current map. +; Load your current coordinates into de. This will be used to check if your position is in the coord event table for the current map. ld a, [PlayerStandingMapX] sub 4 ld d, a @@ -1951,11 +1954,11 @@ CheckCurrentMapXYTriggers:: ; 2ad4 ld a, [hli] cp d jr nz, .next - jr .copytrigger + jr .copy_coord_event .next pop hl - ld a, $8 ; xy-trigger size + ld a, $8 ; coord event size add l ld l, a jr nc, .nocarry @@ -1967,10 +1970,10 @@ CheckCurrentMapXYTriggers:: ; 2ad4 xor a ret -.copytrigger +.copy_coord_event pop hl - ld de, wCurCoordEventTriggerID - ld bc, 8 ; xy-trigger size + ld de, wCurCoordEventSceneID + ld bc, 8 ; coord event size call CopyBytes scf ret @@ -1980,7 +1983,7 @@ FadeToMenu:: ; 2b29 xor a ld [hBGMapMode], a call LoadStandardMenuDataHeader - callba FadeOutPalettes + farcall FadeOutPalettes call ClearSprites call DisableSpriteUpdates ret @@ -2004,9 +2007,9 @@ ExitAllMenus:: ; 2b4d FinishExitMenu:: ; 2b5c ld b, SCGB_MAPPALS call GetSGBLayout - callba LoadOW_BGPal7 + farcall LoadOW_BGPal7 call WaitBGMap2 - callba FadeInPalettes + farcall FadeInPalettes call EnableSpriteUpdates ret ; 2b74 @@ -2027,7 +2030,7 @@ ReturnToMapWithSpeechTextbox:: ; 0x2b74 call WaitBGMap2 ld b, SCGB_MAPPALS call GetSGBLayout - callba LoadOW_BGPal7 + farcall LoadOW_BGPal7 call UpdateTimePals call DelayFrame ld a, $1 @@ -2039,7 +2042,7 @@ ReturnToMapWithSpeechTextbox:: ; 0x2b74 ReloadTilesetAndPalettes:: ; 2bae call DisableLCD call ClearSprites - callba RefreshSprites + farcall RefreshSprites call LoadStandardFont call LoadFontsExtra ld a, [hROMBank] @@ -2049,7 +2052,7 @@ ReloadTilesetAndPalettes:: ; 2bae ld a, [MapNumber] ld c, a call SwitchToAnyMapBank - callba UpdateTimeOfDayPal + farcall UpdateTimeOfDayPal call OverworldTextModeSwitch call LoadTileset ld a, 9 @@ -2151,7 +2154,7 @@ GetMapBank:: ; 2c29 GetAnyMapBank:: ; 2c31 push hl push de - ld de, 0 + ld de, MAPHEADER_MAPHEADER2_BANK call GetAnyMapHeaderMember ld a, c pop de @@ -2160,7 +2163,7 @@ GetAnyMapBank:: ; 2c31 ; 2c3d PartiallyCopyMapHeader:: ; 2c3d -; Copy second map header bank, tileset, permission, and second map header address +; Copy second map header bank, tileset, environment, and second map header address ; from the current map's map header. ld a, [hROMBank] push af @@ -2195,18 +2198,18 @@ GetAnyMapBlockdataBank:: ; 2c5b push bc push bc - ld de, 3 ; second map header pointer + ld de, MAPHEADER_MAPHEADER2 call GetAnyMapHeaderMember ld l, c ld h, b pop bc push hl - ld de, 0 ; second map header bank + ld de, MAPHEADER_MAPHEADER2_BANK call GetAnyMapHeaderMember pop hl - ld de, 3 ; blockdata bank + ld de, MAPHEADER_MAPHEADER2 ; blockdata bank add hl, de ld a, c call GetFarByte @@ -2222,7 +2225,7 @@ GetSecondaryMapHeaderPointer:: ; 0x2c7d ; returns the current map's secondary map header pointer in hl. push bc push de - ld de, 3 ; secondary map header pointer (offset within header) + ld de, MAPHEADER_MAPHEADER2 call GetMapHeaderMember ld l, c ld h, b @@ -2231,11 +2234,11 @@ GetSecondaryMapHeaderPointer:: ; 0x2c7d ret ; 2c8a -GetMapPermission:: ; 2c8a +GetMapEnvironment:: ; 2c8a push hl push de push bc - ld de, 2 ; permission + ld de, MAPHEADER_ENVIRONMENT call GetMapHeaderMember ld a, c pop bc @@ -2247,11 +2250,11 @@ GetMapPermission:: ; 2c8a ret ; XXX ; 2c99 -GetAnyMapPermission:: ; 2c99 +GetAnyMapEnvironment:: ; 2c99 push hl push de push bc - ld de, 2 ; permission + ld de, MAPHEADER_ENVIRONMENT call GetAnyMapHeaderMember ld a, c pop bc @@ -2261,7 +2264,7 @@ GetAnyMapPermission:: ; 2c99 ; 2ca7 GetAnyMapTileset:: ; 2ca7 - ld de, 1 ; tileset + ld de, MAPHEADER_TILESET call GetAnyMapHeaderMember ld a, c ret @@ -2273,7 +2276,7 @@ GetWorldMapLocation:: ; 0x2caf push de push bc - ld de, 5 ; landmark + ld de, MAPHEADER_LOCATION call GetAnyMapHeaderMember ld a, c @@ -2284,18 +2287,16 @@ GetWorldMapLocation:: ; 0x2caf ; 0x2cbd GetMapHeaderMusic:: ; 2cbd -RADIO_TOWER_MUSIC EQU 7 - push hl push bc - ld de, 6 ; music + ld de, MAPHEADER_MUSIC call GetMapHeaderMember ld a, c cp MUSIC_MAHOGANY_MART jr z, .mahoganymart - bit RADIO_TOWER_MUSIC, c + bit RADIO_TOWER_MUSIC_F, c jr nz, .radiotower - callba Function8b342 + farcall Function8b342 ld e, c ld d, 0 .done @@ -2313,7 +2314,7 @@ RADIO_TOWER_MUSIC EQU 7 .clearedradiotower ; the rest of the byte ld a, c - and 1 << RADIO_TOWER_MUSIC - 1 + and RADIO_TOWER_MUSIC - 1 ld e, a ld d, 0 jr .done @@ -2347,7 +2348,7 @@ GetPhoneServiceTimeOfDayByte:: ; 2d0d push hl push bc - ld de, 7 ; phone service and time of day + ld de, MAPHEADER_PALETTE call GetMapHeaderMember ld a, c @@ -2361,7 +2362,7 @@ GetFishingGroup:: ; 2d19 push hl push bc - ld de, 8 ; fishing group + ld de, MAPHEADER_FISHGROUP call GetMapHeaderMember ld a, c @@ -2376,12 +2377,12 @@ LoadTilesetHeader:: ; 2d27 push bc ld hl, Tilesets - ld bc, Tileset01 - Tileset00 + ld bc, TilesetHeaderEnd - TilesetHeader ld a, [wTileset] call AddNTimes ld de, TilesetBank - ld bc, Tileset01 - Tileset00 + ld bc, TilesetHeaderEnd - TilesetHeader ld a, BANK(Tilesets) call FarCopyBytes diff --git a/home/map_objects.asm b/home/map_objects.asm index 4c896c7d7..3857bef0c 100644 --- a/home/map_objects.asm +++ b/home/map_objects.asm @@ -6,7 +6,7 @@ GetSpritePalette:: ; 17ff push bc ld c, a - callba _GetSpritePalette + farcall _GetSpritePalette ld a, c pop bc @@ -120,67 +120,67 @@ GetTileCollision:: ; 185d CheckGrassTile:: ; 1875 ld d, a and $f0 - cp $10 - jr z, .ok_10 - cp $20 - jr z, .ok_20 + cp HI_NYBBLE_TALL_GRASS + jr z, .grass + cp HI_NYBBLE_WATER + jr z, .water scf ret -.ok_10 +.grass ld a, d - and 7 + and LO_NYBBLE_GRASS ret z scf ret ; For some reason, the above code is duplicated down here. -.ok_20 +.water ld a, d - and 7 + and LO_NYBBLE_GRASS ret z scf ret ; 188e CheckSuperTallGrassTile:: ; 188e - cp $14 + cp COLL_LONG_GRASS ret z - cp $1c + cp COLL_LONG_GRASS_1C ret ; 1894 CheckCutTreeTile:: ; 1894 - cp $12 + cp COLL_CUT_TREE ret z - cp $1a + cp COLL_CUT_TREE_1A ret ; 189a CheckHeadbuttTreeTile:: ; 189a - cp $15 + cp COLL_HEADBUTT_TREE ret z - cp $1d + cp COLL_HEADBUTT_TREE_1D ret ; 18a0 CheckCounterTile:: ; 18a0 - cp $90 + cp COLL_COUNTER ret z - cp $98 + cp COLL_COUNTER_98 ret ; 18a6 CheckPitTile:: ; 18a6 - cp $60 + cp COLL_PIT ret z - cp $68 + cp COLL_PIT_68 ret ; 18ac CheckIceTile:: ; 18ac - cp $23 + cp COLL_ICE ret z - cp $2b + cp COLL_ICE_2B ret z scf ret @@ -188,30 +188,30 @@ CheckIceTile:: ; 18ac CheckWhirlpoolTile:: ; 18b4 nop - cp $24 + cp COLL_WHIRLPOOL ret z - cp $2c + cp COLL_WHIRLPOOL_2C ret z scf ret ; 18bd CheckWaterfallTile:: ; 18bd - cp $33 + cp COLL_WATERFALL ret z - cp $3b + cp COLL_CURRENT_DOWN ret ; 18c3 CheckStandingOnEntrance:: ; 18c3 ld a, [PlayerStandingTile] - cp $71 ; door + cp COLL_DOOR ret z - cp $79 + cp COLL_DOOR_79 ret z - cp $7a ; stairs + cp COLL_STAIRCASE ret z - cp $7b ; cave + cp COLL_CAVE ret ; 18d2 @@ -276,9 +276,7 @@ CheckObjectTime:: ; 18f5 ret .TimeOfDayValues_191e: - db 1 << MORN ; 1 - db 1 << DAY ; 2 - db 1 << NITE ; 4 + db MORN, DAY, NITE .check_hour ld hl, MAPOBJECT_HOUR @@ -330,7 +328,7 @@ _CopyObjectStruct:: ; 1956 call UnmaskObject ld a, [hMapObjectIndexBuffer] call GetMapObject - callba CopyObjectStruct + farcall CopyObjectStruct ret ; 1967 @@ -347,7 +345,7 @@ ApplyDeletionToMapObject:: ; 1967 call .CheckStopFollow pop af call GetObjectStruct - callba DeleteMapObject + farcall DeleteMapObject ret .CheckStopFollow: @@ -358,7 +356,7 @@ ApplyDeletionToMapObject:: ; 1967 cp [hl] ret nz .ok - callba StopFollow + farcall StopFollow ld a, -1 ld [wObjectFollow_Leader], a ld [wObjectFollow_Follower], a @@ -411,20 +409,20 @@ CopyPlayerObjectTemplate:: ; 19a6 .ok ld a, b call GetObjectStruct - callba DeleteMapObject + farcall DeleteMapObject ret ; 19e9 LoadMovementDataPointer:: ; 19e9 -; Load the movement data pointer for person a. - ld [wMovementPerson], a +; Load the movement data pointer for object a. + ld [wMovementObject], a ld a, [hROMBank] ld [wMovementDataPointer], a ld a, l ld [wMovementDataPointer + 1], a ld a, h ld [wMovementDataPointer + 2], a - ld a, [wMovementPerson] + ld a, [wMovementObject] call CheckObjectVisibility ret c @@ -485,7 +483,7 @@ GetSpriteMovementFunction:: ; 1a2f ld e, a ld d, 0 rept SPRITEMOVEDATA_FIELDS - add hl,de + add hl, de endr ld a, [hl] ret @@ -498,7 +496,7 @@ GetInitialFacing:: ; 1a47 ld d, 0 ld hl, SpriteMovementData + 1 ; init facing rept SPRITEMOVEDATA_FIELDS - add hl,de + add hl, de endr ld a, BANK(SpriteMovementData) call GetFarByte @@ -622,8 +620,8 @@ UpdateSprites:: ; 1ad2 bit 0, a ret z - callba Function55e0 - callba _UpdateSprites + farcall Function55e0 + farcall _UpdateSprites ret ; 1ae5 diff --git a/home/math.asm b/home/math.asm index 01aea6b72..6a779e378 100644 --- a/home/math.asm +++ b/home/math.asm @@ -45,7 +45,7 @@ Multiply:: ; 3119 push hl push bc - callab _Multiply + callfar _Multiply pop bc pop hl diff --git a/home/menu.asm b/home/menu.asm index 53e4457e3..ba1b568c1 100644 --- a/home/menu.asm +++ b/home/menu.asm @@ -569,7 +569,7 @@ Place2DMenuItemName:: ; 201c _2DMenu:: ; 202a ld a, [hROMBank] ld [wMenuData2_2DMenuItemStringsBank], a - callba _2DMenu_ + farcall _2DMenu_ ld a, [wMenuCursorBuffer] ret ; 2039 @@ -577,7 +577,7 @@ _2DMenu:: ; 202a InterpretBattleMenu:: ; 2039 ld a, [hROMBank] ld [wMenuData2_2DMenuItemStringsBank], a - callba _InterpretBattleMenu + farcall _InterpretBattleMenu ld a, [wMenuCursorBuffer] ret ; 2048 @@ -585,7 +585,7 @@ InterpretBattleMenu:: ; 2039 InterpretMobileMenu:: ; 2048 ld a, [hROMBank] ld [wMenuData2_2DMenuItemStringsBank], a - callba _InterpretMobileMenu + farcall _InterpretMobileMenu ld a, [wMenuCursorBuffer] ret ; 2057 diff --git a/home/movement.asm b/home/movement.asm index c4b5b578d..0a2623a09 100644 --- a/home/movement.asm +++ b/home/movement.asm @@ -1,13 +1,13 @@ InitMovementBuffer:: ; 1b1e - ld [wMovementBufferPerson], a + ld [wMovementBufferObject], a xor a ld [wMovementBufferCount], a ld a, $0 ; useless - ld [wd004], a + ld [wUnusedMovementBufferBank], a ld a, MovementBuffer % $100 - ld [wd005], a + ld [wUnusedMovementBufferPointer], a ld a, MovementBuffer / $100 - ld [wd006], a + ld [wUnusedMovementBufferPointer + 1], a ret ; 1b35 @@ -159,13 +159,13 @@ SetMenuAttributes:: ; 1bb1 ; 1bc9 StaticMenuJoypad:: ; 1bc9 - callab _StaticMenuJoypad + callfar _StaticMenuJoypad call GetMenuJoypad ret ; 1bd3 ScrollingMenuJoypad:: ; 1bd3 - callab _ScrollingMenuJoypad + callfar _ScrollingMenuJoypad call GetMenuJoypad ret ; 1bdd diff --git a/home/names.asm b/home/names.asm new file mode 100644 index 000000000..c8f873c3f --- /dev/null +++ b/home/names.asm @@ -0,0 +1,278 @@ +NamesPointers:: ; 33ab +; entries correspond to GetName constants (see constants/misc_constants.asm) + dba PokemonNames + dba MoveNames + dbw 0, 0 + dba ItemNames + dbw 0, PartyMonOT + dbw 0, OTPartyMonOT + dba TrainerClassNames + dbw $4, $4b52 ; within PackMenuGFX +; 33c3 + +GetName:: ; 33c3 +; Return name CurSpecies from name list wNamedObjectTypeBuffer in StringBuffer1. + + ld a, [hROMBank] + push af + push hl + push bc + push de + + ld a, [wNamedObjectTypeBuffer] + cp PKMN_NAME + jr nz, .NotPokeName + + ld a, [CurSpecies] + ld [wd265], a + call GetPokemonName + ld hl, PKMN_NAME_LENGTH + add hl, de + ld e, l + ld d, h + jr .done + +.NotPokeName: + ld a, [wNamedObjectTypeBuffer] + dec a + ld e, a + ld d, 0 + ld hl, NamesPointers + add hl, de + add hl, de + add hl, de + ld a, [hli] + rst Bankswitch + ld a, [hli] + ld h, [hl] + ld l, a + + ld a, [CurSpecies] + dec a + call GetNthString + + ld de, StringBuffer1 + ld bc, ITEM_NAME_LENGTH + call CopyBytes + +.done + ld a, e + ld [wUnusedD102], a + ld a, d + ld [wUnusedD102 + 1], a + + pop de + pop bc + pop hl + pop af + rst Bankswitch + ret +; 3411 + +GetNthString:: ; 3411 +; Return the address of the +; ath string starting from hl. + + and a + ret z + + push bc + ld b, a + ld c, "@" +.readChar + ld a, [hli] + cp c + jr nz, .readChar + dec b + jr nz, .readChar + pop bc + ret +; 3420 + +GetBasePokemonName:: ; 3420 +; Discards gender (Nidoran). + + push hl + call GetPokemonName + + ld hl, StringBuffer1 +.loop + ld a, [hl] + cp "@" + jr z, .quit + cp "♂" + jr z, .end + cp "♀" + jr z, .end + inc hl + jr .loop +.end + ld [hl], "@" +.quit + pop hl + ret + +; 343b + +GetPokemonName:: ; 343b +; Get Pokemon name wd265. + + ld a, [hROMBank] + push af + push hl + ld a, BANK(PokemonNames) + rst Bankswitch + +; Each name is ten characters + ld a, [wd265] + dec a + ld d, 0 + ld e, a + ld h, 0 + ld l, a + add hl, hl ; hl = hl * 4 + add hl, hl ; hl = hl * 4 + add hl, de ; hl = (hl*4) + de + add hl, hl ; hl = (5*hl) + (5*hl) + ld de, PokemonNames + add hl, de + +; Terminator + ld de, StringBuffer1 + push de + ld bc, PKMN_NAME_LENGTH - 1 + call CopyBytes + ld hl, StringBuffer1 + PKMN_NAME_LENGTH - 1 + ld [hl], "@" + pop de + + pop hl + pop af + rst Bankswitch + ret +; 3468 + +GetItemName:: ; 3468 +; Get item name wd265. + + push hl + push bc + ld a, [wd265] + + cp TM01 + jr nc, .TM + + ld [CurSpecies], a + ld a, ITEM_NAME + ld [wNamedObjectTypeBuffer], a + call GetName + jr .Copied +.TM: + call GetTMHMName +.Copied: + ld de, StringBuffer1 + pop bc + pop hl + ret +; 3487 + +GetTMHMName:: ; 3487 +; Get TM/HM name by item id wd265. + + push hl + push de + push bc + ld a, [wd265] + push af + +; TM/HM prefix + cp HM01 + push af + jr c, .TM + + ld hl, .HMText + ld bc, .HMTextEnd - .HMText + jr .asm_34a1 + +.TM: + ld hl, .TMText + ld bc, .TMTextEnd - .TMText + +.asm_34a1 + ld de, StringBuffer1 + call CopyBytes + +; TM/HM number + push de + ld a, [wd265] + ld c, a + callfar GetTMHMNumber + pop de + +; HM numbers start from 51, not 1 + pop af + ld a, c + jr c, .asm_34b9 + sub NUM_TMS +.asm_34b9 + +; Divide and mod by 10 to get the top and bottom digits respectively + ld b, "0" +.mod10 + sub 10 + jr c, .asm_34c2 + inc b + jr .mod10 +.asm_34c2 + add 10 + + push af + ld a, b + ld [de], a + inc de + pop af + + ld b, "0" + add b + ld [de], a + +; End the string + inc de + ld a, "@" + ld [de], a + + pop af + ld [wd265], a + pop bc + pop de + pop hl + ret + +.TMText: + db "TM" +.TMTextEnd: + db "@" + +.HMText: + db "HM" +.HMTextEnd: + db "@" +; 34df + +INCLUDE "home/hm_moves.asm" + +GetMoveName:: ; 34f8 + push hl + + ld a, MOVE_NAME + ld [wNamedObjectTypeBuffer], a + + ld a, [wNamedObjectIndexBuffer] ; move id + ld [CurSpecies], a + + call GetName + ld de, StringBuffer1 + + pop hl + ret +; 350c diff --git a/home/rtc.asm b/home/rtc.asm index d343d118d..5b83f1079 100644 --- a/home/rtc.asm +++ b/home/rtc.asm @@ -14,11 +14,11 @@ RTC:: ; 46f ret z TimeOfDayPals:: ; 47e - callab _TimeOfDayPals + callfar _TimeOfDayPals ret ; 485 UpdateTimePals:: ; 485 - callab _UpdateTimePals + callfar _UpdateTimePals ret ; 48c diff --git a/home/serial.asm b/home/serial.asm index e60704f3d..b0151eae2 100644 --- a/home/serial.asm +++ b/home/serial.asm @@ -277,7 +277,7 @@ Function83b:: ; 83b Function862:: ; 862 call LoadTileMapToTempTileMap - callab PlaceWaitingText + callfar PlaceWaitingText call WaitLinkTransfer jp Call_LoadTempTileMapToTileMap ; 871 @@ -285,7 +285,7 @@ Function862:: ; 862 Function871:: ; 871 call LoadTileMapToTempTileMap - callab PlaceWaitingText + callfar PlaceWaitingText jp WaitLinkTransfer ; 87d diff --git a/home/text.asm b/home/text.asm index f7730319a..4b0d0d5df 100644 --- a/home/text.asm +++ b/home/text.asm @@ -8,9 +8,6 @@ TEXTBOX_INNERX EQU TEXTBOX_X + 1 TEXTBOX_Y EQU SCREEN_HEIGHT - TEXTBOX_HEIGHT TEXTBOX_INNERY EQU TEXTBOX_Y + 2 -TEXTBOX_PAL EQU 7 - - ClearBox:: ; fb6 ; Fill a c*b box at hl with blank tiles. @@ -51,7 +48,7 @@ ClearTileMap:: ; fc8 ClearScreen:: ; fdb - ld a, TEXTBOX_PAL + ld a, PAL_BG_TEXT hlcoord 0, 0, AttrMap ld bc, SCREEN_WIDTH * SCREEN_HEIGHT call ByteFill @@ -133,7 +130,7 @@ TextBoxPalette:: ; 1024 inc b inc c inc c - ld a, TEXTBOX_PAL + ld a, PAL_BG_TEXT .col push bc push hl @@ -230,42 +227,42 @@ dict2: macro ._\@: endm - dict "<DAY>", Char15 - dict "<LINE>", LineChar - dict "<NEXT>", NextLineChar - dict TX_FAR, TextFar - dict $00, NullChar - dict $4c, Char4C - dict $4b, Char4B - dict "<PARA>", Paragraph - dict "<MOM>", PrintMomsName - dict "<PLAYER>", PrintPlayerName - dict "<RIVAL>", PrintRivalName - dict $35, Char35 - dict $36, Char36 - dict $37, Char37 - dict "<RED>", PrintRedsName - dict "<GREEN>", PrintGreensName - dict "#", PlacePOKe - dict "<PC>", PCChar - dict "<ROCKET>", RocketChar - dict "<TM>", TMChar - dict "<TRNER>", TrainerChar - dict $23, PlaceKougeki - dict "<LNBRK>", Char22 - dict "<CONT>", ContText - dict "<......>", SixDotsChar - dict "<DONE>", DoneText - dict "<PROMPT>", PromptText - dict "<PKMN>", PlacePKMN - dict "<POKE>", PlacePOKE - dict $25, NextChar - dict2 $1f, " " - dict "<DEXEND>", PlaceDexEnd - dict "<TARGET>", PlaceMoveTargetsName - dict "<USER>", PlaceMoveUsersName - dict "<ENEMY>", PlaceEnemysName - dict "<PLAY_G>", PlaceGenderedPlayerName + dict "<DAY>", Char15 + dict "<LINE>", LineChar + dict "<NEXT>", NextLineChar + dict TX_FAR, TextFar + dict $00, NullChar + dict $4c, Char4C + dict $4b, Char4B + dict "<PARA>", Paragraph + dict "<MOM>", PrintMomsName + dict "<PLAYER>", PrintPlayerName + dict "<RIVAL>", PrintRivalName + dict $35, Char35 + dict $36, Char36 + dict $37, Char37 + dict "<RED>", PrintRedsName + dict "<GREEN>", PrintGreensName + dict "#", PlacePOKe + dict "<PC>", PCChar + dict "<ROCKET>", RocketChar + dict "<TM>", TMChar + dict "<TRNER>", TrainerChar + dict "<KOUGEKI>", PlaceKougeki + dict "<LNBRK>", Char22 + dict "<CONT>", ContText + dict "<......>", SixDotsChar + dict "<DONE>", DoneText + dict "<PROMPT>", PromptText + dict "<PKMN>", PlacePKMN + dict "<POKE>", PlacePOKE + dict "%", NextChar + dict2 "¯", " " + dict "<DEXEND>", PlaceDexEnd + dict "<TARGET>", PlaceMoveTargetsName + dict "<USER>", PlaceMoveUsersName + dict "<ENEMY>", PlaceEnemysName + dict "<PLAY_G>", PlaceGenderedPlayerName cp "゚" jr z, .place ; should be .diacritic @@ -318,7 +315,7 @@ endm Char15:: ; 117b ld c, l ld b, h - callba Function17f036 + farcall Function17f036 jp PlaceNextChar ; 1186 @@ -394,7 +391,7 @@ PlaceEnemysName:: ; 121b ld de, String12a2 call PlaceString push bc - callab Battle_GetTrainerName + callfar Battle_GetTrainerName pop hl ld de, StringBuffer1 jr PlaceCommandCharacter @@ -748,6 +745,7 @@ DoTextUntilTerminator:: ; 13f6 ; 1410 TextCommands:: ; 1410 +; entries correspond to macros/text.asm enumeration dw Text_TX dw Text_TX_RAM dw Text_TX_BCD diff --git a/home/tilemap.asm b/home/tilemap.asm index 1d7998130..9e15ed85b 100644 --- a/home/tilemap.asm +++ b/home/tilemap.asm @@ -1,16 +1,16 @@ PushWindow:: ; 1c00 - callab _PushWindow + callfar _PushWindow ret ; 1c07 ExitMenu:: ; 0x1c07 push af - callab _ExitMenu + callfar _ExitMenu pop af ret InitVerticalMenuCursor:: ; 0x1c10 - callab _InitVerticalMenuCursor + callfar _InitVerticalMenuCursor ret CloseWindow:: ; 0x1c17 diff --git a/home/time.asm b/home/time.asm index 338168752..9ed703686 100644 --- a/home/time.asm +++ b/home/time.asm @@ -28,7 +28,7 @@ UpdateTime:: ; 5a7 call GetClock call FixDays call FixTime - callba GetTimeOfDay + farcall GetTimeOfDay ret ; 5b7 @@ -49,19 +49,16 @@ GetClock:: ; 5b7 ld [hl], RTC_S ld a, [de] maskbits 60 - and x ld [hRTCSeconds], a ld [hl], RTC_M ld a, [de] maskbits 60 - and x ld [hRTCMinutes], a ld [hl], RTC_H ld a, [de] maskbits 24 - and x ld [hRTCHours], a ld [hl], RTC_DL @@ -208,7 +205,7 @@ SetDayOfWeek:: ; 663 jr InitTime ; useless InitTime:: ; 677 - callba _InitTime + farcall _InitTime ret ; 67e diff --git a/home/trainers.asm b/home/trainers.asm new file mode 100644 index 000000000..857a95629 --- /dev/null +++ b/home/trainers.asm @@ -0,0 +1,263 @@ +CheckTrainerBattle2:: ; 3600 + ld a, [hROMBank] + push af + + call SwitchToMapScriptHeaderBank + call CheckTrainerBattle + + pop bc + ld a, b + rst Bankswitch + ret +; 360d + +CheckTrainerBattle:: ; 360d +; Check if any trainer on the map sees the player and wants to battle. + +; Skip the player object. + ld a, 1 + ld de, MapObjects + OBJECT_LENGTH + +.loop + +; Start a battle if the object: + + push af + push de + +; Has a sprite + ld hl, MAPOBJECT_SPRITE + add hl, de + ld a, [hl] + and a + jr z, .next + +; Is a trainer + ld hl, MAPOBJECT_COLOR + add hl, de + ld a, [hl] + and $f + cp $2 + jr nz, .next + +; Is visible on the map + ld hl, MAPOBJECT_OBJECT_STRUCT_ID + add hl, de + ld a, [hl] + cp -1 + jr z, .next + +; Is facing the player... + call GetObjectStruct + call FacingPlayerDistance_bc + jr nc, .next + +; ...within their sight range + ld hl, MAPOBJECT_RANGE + add hl, de + ld a, [hl] + cp b + jr c, .next + +; And hasn't already been beaten + push bc + push de + ld hl, MAPOBJECT_SCRIPT_POINTER + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + ld e, [hl] + inc hl + ld d, [hl] + ld b, CHECK_FLAG + call EventFlagAction + ld a, c + pop de + pop bc + and a + jr z, .startbattle + +.next + pop de + ld hl, OBJECT_LENGTH + add hl, de + ld d, h + ld e, l + + pop af + inc a + cp NUM_OBJECTS + jr nz, .loop + xor a + ret + +.startbattle + pop de + pop af + ld [hLastTalked], a + ld a, b + ld [EngineBuffer2], a + ld a, c + ld [EngineBuffer3], a + jr LoadTrainer_continue +; 3674 + +TalkToTrainer:: ; 3674 + ld a, 1 + ld [EngineBuffer2], a + ld a, -1 + ld [EngineBuffer3], a + +LoadTrainer_continue:: ; 367e + call GetMapScriptHeaderBank + ld [EngineBuffer1], a + + ld a, [hLastTalked] + call GetMapObject + + ld hl, MAPOBJECT_SCRIPT_POINTER + add hl, bc + ld a, [EngineBuffer1] + call GetFarHalfword + ld de, wTempTrainerHeader + ld bc, wTempTrainerHeaderEnd - wTempTrainerHeader + ld a, [EngineBuffer1] + call FarCopyBytes + xor a + ld [wRunningTrainerBattleScript], a + scf + ret +; 36a5 + +FacingPlayerDistance_bc:: ; 36a5 + + push de + call FacingPlayerDistance + ld b, d + ld c, e + pop de + ret +; 36ad + +FacingPlayerDistance:: ; 36ad +; Return carry if the sprite at bc is facing the player, +; and its distance in d. + + ld hl, OBJECT_NEXT_MAP_X ; x + add hl, bc + ld d, [hl] + + ld hl, OBJECT_NEXT_MAP_Y ; y + add hl, bc + ld e, [hl] + + ld a, [PlayerStandingMapX] + cp d + jr z, .CheckY + + ld a, [PlayerStandingMapY] + cp e + jr z, .CheckX + + and a + ret + +.CheckY: + ld a, [PlayerStandingMapY] + sub e + jr z, .NotFacing + jr nc, .Above + +; Below + cpl + inc a + ld d, a + ld e, OW_UP + jr .CheckFacing + +.Above: + ld d, a + ld e, OW_DOWN + jr .CheckFacing + +.CheckX: + ld a, [PlayerStandingMapX] + sub d + jr z, .NotFacing + jr nc, .Left + +; Right + cpl + inc a + ld d, a + ld e, OW_LEFT + jr .CheckFacing + +.Left: + ld d, a + ld e, OW_RIGHT + +.CheckFacing: + call GetSpriteDirection + cp e + jr nz, .NotFacing + scf + ret + +.NotFacing: + and a + ret +; 36f5 + +CheckTrainerFlag:: ; 36f5 + push bc + ld hl, OBJECT_MAP_OBJECT_INDEX + add hl, bc + ld a, [hl] + call GetMapObject + ld hl, MAPOBJECT_SCRIPT_POINTER + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + call GetMapScriptHeaderBank + call GetFarHalfword + ld d, h + ld e, l + push de + ld b, CHECK_FLAG + call EventFlagAction + pop de + ld a, c + and a + pop bc + ret +; 3718 + +PrintWinLossText:: ; 3718 + ld a, [BattleType] + cp BATTLETYPE_CANLOSE + jr .canlose ; ?????????? + +; unreferenced + ld hl, wWinTextPointer + jr .ok + +.canlose + ld a, [wBattleResult] + ld hl, wWinTextPointer + and $f + jr z, .ok + ld hl, wLossTextPointer + +.ok + ld a, [hli] + ld h, [hl] + ld l, a + call GetMapScriptHeaderBank + call FarPrintText + call WaitBGMap + call WaitPressAorB_BlinkCursor + ret +; 3741 diff --git a/home/window.asm b/home/window.asm index ff7d766e2..0570bbb01 100644 --- a/home/window.asm +++ b/home/window.asm @@ -43,8 +43,8 @@ CloseText:: ; 2dcf ld a, $90 ld [hWY], a call ReplaceKrisSprite - callba ReturnFromMapSetupScript - callba LoadOverworldFont + farcall ReturnFromMapSetupScript + farcall LoadOverworldFont ret ; 2e08 @@ -71,7 +71,7 @@ _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap:: ; 2e20 ld a, $1 ld [hOAMUpdate], a - callba OpenAndCloseMenu_HDMATransferTileMapAndAttrMap + farcall OpenAndCloseMenu_HDMATransferTileMapAndAttrMap pop af ld [hOAMUpdate], a |