diff --git a/home.asm b/home.asm index 6aa8777cb..dc03faa2c 100644 --- a/home.asm +++ b/home.asm @@ -46,9 +46,9 @@ INCLUDE "home/map.asm" InexplicablyEmptyFunction:: ; 2d43 ; Inexplicably empty. ; Seen in PredefPointers. - rept 16 +rept 16 nop - endr +endr ret ; 2d54 @@ -771,295 +771,7 @@ GetWeekday:: ; 3376 INCLUDE "home/pokedex_flags.asm" -NamesPointers:: ; 33ab - 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 - callab 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 - -IsHM:: ; 34df - cp HM01 - jr c, .NotHM - scf - ret -.NotHM: - and a - ret -; 34e7 - - -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 +INCLUDE "home/names.asm" ScrollingMenu:: ; 350c call CopyMenuData2 @@ -1271,270 +983,7 @@ HandleStoneQueue:: ; 3567 ret ; 3600 -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 +INCLUDE "home/trainers.asm" IsAPokemon:: ; 3741 ; Return carry if species a is not a Pokemon. diff --git a/home/names.asm b/home/names.asm new file mode 100644 index 000000000..7aa02f8ad --- /dev/null +++ b/home/names.asm @@ -0,0 +1,287 @@ +NamesPointers:: ; 33ab + 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 + callab 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 + +IsHM:: ; 34df + cp HM01 + jr c, .NotHM + scf + ret +.NotHM: + and a + ret +; 34e7 + +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/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