diff options
author | entrpntr <entrpntr@gmail.com> | 2020-04-26 19:00:07 -0400 |
---|---|---|
committer | entrpntr <entrpntr@gmail.com> | 2020-04-26 19:11:18 -0400 |
commit | 0b33dabae2d43591a964774154f8bec5bf7194b1 (patch) | |
tree | b51d8de7de034c38081a679abf8c9a14efd8bfaa /engine | |
parent | 9ce922493398842b2e91383a08098f20249d44c7 (diff) |
Disassemble map scenes and events.
Diffstat (limited to 'engine')
-rwxr-xr-x | engine/events/happiness_egg.asm | 2 | ||||
-rwxr-xr-x | engine/events/overworld.asm | 8 | ||||
-rwxr-xr-x | engine/events/specials.asm | 13 | ||||
-rw-r--r-- | engine/events/trainer_scripts.asm | 31 | ||||
-rwxr-xr-x | engine/items/item_effects.asm | 4 | ||||
-rwxr-xr-x | engine/items/items.asm | 2 | ||||
-rw-r--r-- | engine/overworld/events.asm | 1585 | ||||
-rwxr-xr-x | engine/overworld/map_objects.asm | 8 | ||||
-rwxr-xr-x | engine/overworld/npc_movement.asm | 2 | ||||
-rwxr-xr-x | engine/overworld/player_movement.asm | 4 | ||||
-rwxr-xr-x | engine/overworld/player_object.asm | 14 | ||||
-rwxr-xr-x | engine/overworld/player_step.asm | 2 | ||||
-rw-r--r-- | engine/overworld/scripting.asm | 2673 | ||||
-rwxr-xr-x | engine/overworld/time.asm | 10 | ||||
-rwxr-xr-x | engine/overworld/variables.asm | 2 | ||||
-rwxr-xr-x | engine/pokemon/move_mon.asm | 4 |
16 files changed, 4327 insertions, 37 deletions
diff --git a/engine/events/happiness_egg.asm b/engine/events/happiness_egg.asm index 6c8b918c..6563c878 100755 --- a/engine/events/happiness_egg.asm +++ b/engine/events/happiness_egg.asm @@ -145,7 +145,7 @@ StepHappiness:: MAX_EXP EQU 5242880 -DaycareStep:: +DayCareStep:: CheckFlag ENGINE_DAY_CARE_MAN_HAS_MON jr z, .daycare_lady ld a, [wBreedMon1Level] diff --git a/engine/events/overworld.asm b/engine/events/overworld.asm index 179e8227..28b7c895 100755 --- a/engine/events/overworld.asm +++ b/engine/events/overworld.asm @@ -672,7 +672,7 @@ Text_UsedWaterfall: text_far Text_UsedWaterfall_ db "@" -TryWaterfallOW: +TryWaterfallOW:: ld d, WATERFALL call FieldMovePartyCheck jr c, .asm_cb7d @@ -1146,7 +1146,7 @@ DisappearWhirlpool: ; 4e20 call GetMovementPermissions ret -TryWhirlpoolOW: +TryWhirlpoolOW:: ld d, WHIRLPOOL call FieldMovePartyCheck jr c, .asm_ce5f @@ -1238,7 +1238,7 @@ HeadbuttScript: closetext end -TryHeadbuttOW: ; cecc +TryHeadbuttOW:: ld d, HEADBUTT call FieldMovePartyCheck jr c, .asm_cedd @@ -1711,7 +1711,7 @@ GotOffBikeText: text_end -TryCutOW: ; d193 +TryCutOW:: ld d, CUT call FieldMovePartyCheck jr c, .asm_d1ac diff --git a/engine/events/specials.asm b/engine/events/specials.asm index e030f68a..53b8ee5b 100755 --- a/engine/events/specials.asm +++ b/engine/events/specials.asm @@ -25,7 +25,7 @@ ELSE ENDC ENDM -SpecialsPointers: +SpecialsPointers:: add_special WarpToSpawnPoint ; Communications @@ -409,21 +409,22 @@ UnusedCheckUnusedTwoDayTimer: ; c549 (3:4549) ld [wScriptVar], a ret -ActivateFishingSwarm: ; c556 (3:4556) +ActivateFishingSwarm: ld a, [wScriptVar] ld [wFishingSwarmFlag], a - jr .asm_c566 + jr SetSwarmFlag -.asm_c55e +StoreSwarmMapIndices:: ld a, d ld [wDunsparceMapGroup], a ld a, e ld [wDunsparceMapNumber], a -.asm_c566 + ; fallthrough +SetSwarmFlag: SetFlag ENGINE_SPECIAL_WILDDATA ret -Functionc56c: +CheckSwarmFlag:: CheckFlagHL ENGINE_SPECIAL_WILDDATA jr z, .asm_c578 xor a diff --git a/engine/events/trainer_scripts.asm b/engine/events/trainer_scripts.asm new file mode 100644 index 00000000..1fb0d291 --- /dev/null +++ b/engine/events/trainer_scripts.asm @@ -0,0 +1,31 @@ +TalkToTrainerScript:: + faceplayer + trainerflagaction CHECK_FLAG + iftrue AlreadyBeatenTrainerScript + loadtemptrainer + encountermusic + sjump StartBattleWithMapTrainerScript + +SeenByTrainerScript:: + loadtemptrainer + encountermusic + showemote EMOTE_SHOCK, LAST_TALKED, 30 + callasm TrainerWalkToPlayer + applymovementlasttalked wMovementBuffer + writeobjectxy LAST_TALKED + faceobject PLAYER, LAST_TALKED + sjump StartBattleWithMapTrainerScript + +StartBattleWithMapTrainerScript: + opentext + trainertext TRAINERTEXT_SEEN + waitbutton + closetext + loadtemptrainer + startbattle + reloadmapafterbattle + trainerflagaction SET_FLAG + loadmem wRunningTrainerBattleScript, -1 + +AlreadyBeatenTrainerScript: + scripttalkafter diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index ac360409..dccbd51b 100755 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -1951,12 +1951,12 @@ MaxRepel: ; f4bc (3:74bc) Repel: ; f4c0 (3:74c0) ld b, 100 asm_f4c2: - ld a, [wRepelSteps] + ld a, [wRepelEffect] and a ld hl, Text_RepelsEffectsStillLinger jp nz, PrintText ld a, b - ld [wRepelSteps], a + ld [wRepelEffect], a jp Functionf7d0 Text_RepelsEffectsStillLinger: diff --git a/engine/items/items.asm b/engine/items/items.asm index c24d580b..748b3d46 100755 --- a/engine/items/items.asm +++ b/engine/items/items.asm @@ -489,7 +489,7 @@ CheckSelectableItem: and a ret -CheckItemPocket: ; d44a (3:544a) +CheckItemPocket:: ld a, $5 call GetItemAttr and $f diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm new file mode 100644 index 00000000..ba50fb25 --- /dev/null +++ b/engine/overworld/events.asm @@ -0,0 +1,1585 @@ +INCLUDE "constants.asm" + + +SECTION "Events", ROMX + +OverworldLoop:: + xor a ; MAPSTATUS_START + ld [wMapStatus], a +.loop + ld a, [wMapStatus] + ld hl, .jumps + rst JumpTable + ld a, [wMapStatus] + cp MAPSTATUS_DONE + jr nz, .loop +.done + ret + +.jumps +; entries correspond to MAPSTATUS_* constants + dw StartMap + dw EnterMap + dw HandleMap + dw .done + +DisableEvents: + xor a + ld [wScriptFlags3], a + ret + +EnableEvents:: + ld a, $ff + ld [wScriptFlags3], a + ret + +CheckBit5_ScriptFlags3: + ld hl, wScriptFlags3 + bit 5, [hl] + ret + +DisableWarpsConnxns: + ld hl, wScriptFlags3 + res 2, [hl] + ret + +DisableCoordEvents: + ld hl, wScriptFlags3 + res 1, [hl] + ret + +DisableStepCount: + ld hl, wScriptFlags3 + res 0, [hl] + ret + +DisableWildEncounters: + ld hl, wScriptFlags3 + res 4, [hl] + ret + +EnableWarpsConnxns: + ld hl, wScriptFlags3 + set 2, [hl] + ret + +EnableCoordEvents: + ld hl, wScriptFlags3 + set 1, [hl] + ret + +EnableStepCount: + ld hl, wScriptFlags3 + set 0, [hl] + ret + +EnableWildEncounters: + ld hl, wScriptFlags3 + set 4, [hl] + ret + +CheckWarpConnxnScriptFlag: + ld hl, wScriptFlags3 + bit 2, [hl] + ret + +CheckCoordEventScriptFlag: + ld hl, wScriptFlags3 + bit 1, [hl] + ret + +CheckStepCountScriptFlag: + ld hl, wScriptFlags3 + bit 0, [hl] + ret + +CheckWildEncountersScriptFlag: + ld hl, wScriptFlags3 + bit 4, [hl] + ret + +StartMap: + xor a + ld [wScriptRunning], a + ld hl, wMapStatus + ld bc, wMapStatusEnd - wMapStatus + call ByteFill + farcall InitCallReceiveDelay + call ClearJoypad +EnterMap: + xor a + ld [wXYComparePointer], a + ld [wXYComparePointer + 1], a + call SetUpFiveStepWildEncounterCooldown + farcall RunMapSetupScript + call DisableEvents + + ldh a, [hMapEntryMethod] + cp MAPSETUP_CONNECTION + jr nz, .dont_enable + call EnableEvents +.dont_enable + + ldh a, [hMapEntryMethod] + cp MAPSETUP_RELOADMAP + jr nz, .dontresetpoison + xor a + ld [wPoisonStepCount], a +.dontresetpoison + + xor a ; end map entry + ldh [hMapEntryMethod], a + ld a, MAPSTATUS_HANDLE + ld [wMapStatus], a + ret + +UnusedWait30Frames: + ld c, 30 + call DelayFrames + ret + +HandleMap: + call ResetOverworldDelay + call HandleMapTimeAndJoypad + farcall HandleCmdQueue ; no need to farcall + call MapEvents + +; Not immediately entering a connected map will cause problems. + ld a, [wMapStatus] + cp MAPSTATUS_HANDLE + ret nz + + call HandleMapObjects + call NextOverworldFrame + call HandleMapBackground + call CheckPlayerState + ret + +MapEvents: + ld a, [wMapEventStatus] + ld hl, .jumps + rst JumpTable + ret + +.jumps +; entries correspond to MAPEVENTS_* constants + dw .events + dw .no_events + +.events + call PlayerEvents + call DisableEvents + farcall ScriptEvents + ret + +.no_events + ret + +MaxOverworldDelay: + db 2 + +ResetOverworldDelay: + ld a, [MaxOverworldDelay] + ld [wOverworldDelay], a + ret + +NextOverworldFrame: + ld a, [wOverworldDelay] + and a + ret z + ld c, a + call DelayFrames + ret + +HandleMapTimeAndJoypad: + ld a, [wMapEventStatus] + cp MAPEVENTS_OFF + ret z + + call UpdateTime + call GetJoypad + call TimeOfDayPals + ret + +HandleMapObjects: + farcall HandleNPCStep ; engine/map_objects.asm + farcall _HandlePlayerStep + call _CheckObjectEnteringVisibleRange + ret + +HandleMapBackground: + farcall _UpdateSprites + farcall ScrollScreen + ret + +CheckPlayerState: + ld a, [wPlayerStepFlags] + bit PLAYERSTEP_CONTINUE_F, a + jr z, .events + bit PLAYERSTEP_STOP_F, a + jr z, .noevents + bit PLAYERSTEP_MIDAIR_F, a + jr nz, .noevents + call EnableEvents +.events + ld a, MAPEVENTS_ON + ld [wMapEventStatus], a + ret + +.noevents + ld a, MAPEVENTS_OFF + ld [wMapEventStatus], a + ret + +_CheckObjectEnteringVisibleRange: + ld hl, wPlayerStepFlags + bit PLAYERSTEP_STOP_F, [hl] + ret z + farcall CheckObjectEnteringVisibleRange + ret + +PlayerEvents: + xor a +; If there's already a player event, don't interrupt it. + ld a, [wScriptRunning] + and a + ret nz + + call Dummy_CheckScriptFlags3Bit5 ; This is a waste of time + + call CheckTrainerBattle_GetPlayerEvent + jr c, .ok + + call CheckTileEvent + jr c, .ok + + call RunMemScript + jr c, .ok + + call RunSceneScript + jr c, .ok + + call CheckTimeEvents + jr c, .ok + + call OWPlayerInput + jr c, .ok + + xor a + ret + +.ok + push af + farcall EnableScriptMode + pop af + ld [wScriptRunning], a + call DoPlayerEvent + scf + ret + +CheckTrainerBattle_GetPlayerEvent: + nop + nop + call CheckTrainerBattle + jr nc, .nope + + ld a, PLAYEREVENT_SEENBYTRAINER + scf + ret + +.nope + xor a + ret + +CheckTileEvent: +; Check for warps, coord events, or wild battles. + + call CheckWarpConnxnScriptFlag + jr z, .connections_disabled + + call CheckMovingOffEdgeOfMap + jr c, .map_connection + + call CheckWarpTile + jr c, .warp_tile + +.connections_disabled + call CheckCoordEventScriptFlag + jr z, .coord_events_disabled + + call CheckCurrentMapCoordEvents + jr c, .coord_event + +.coord_events_disabled + call CheckStepCountScriptFlag + jr z, .step_count_disabled + + call CountStep + ret c + +.step_count_disabled + call CheckWildEncountersScriptFlag + jr z, .ok + + call RandomEncounter + ret c + jr .ok ; pointless + +.ok + xor a + ret + +.map_connection + ld a, PLAYEREVENT_CONNECTION + scf + ret + +.warp_tile + ld a, [wPlayerStandingTile] + call CheckPitTile + jr nz, .not_pit + ld a, PLAYEREVENT_FALL + scf + ret + +.not_pit + ld a, PLAYEREVENT_WARP + scf + ret + +.coord_event + ld hl, wCurCoordEventScriptAddr + ld a, [hli] + ld h, [hl] + ld l, a + call GetMapScriptsBank + call CallScript + ret + +CheckWildEncounterCooldown:: + ld hl, wWildEncounterCooldown + ld a, [hl] + and a + ret z + dec [hl] + ret z + scf + ret + +SetUpFiveStepWildEncounterCooldown: + ld a, 5 + ld [wWildEncounterCooldown], a + ret + +ret_968d7: + ret + +SetMinTwoStepWildEncounterCooldown: + ld a, [wWildEncounterCooldown] + cp 2 + ret nc + ld a, 2 + ld [wWildEncounterCooldown], a + ret + +Dummy_CheckScriptFlags3Bit5: + call CheckBit5_ScriptFlags3 + ret z + call Function2ffe + ret + +RunSceneScript: + ld a, [wCurMapSceneScriptCount] + and a + jr z, .nope + + ld c, a + call CheckScenes + cp c + jr nc, .nope + + ld e, a + ld d, 0 + ld hl, wCurMapSceneScriptsPointer + ld a, [hli] + ld h, [hl] + ld l, a +rept SCENE_SCRIPT_SIZE + add hl, de +endr + + call GetMapScriptsBank + call GetFarHalfword + call GetMapScriptsBank + call CallScript + + ld hl, wScriptFlags + res 3, [hl] + + farcall EnableScriptMode + farcall ScriptEvents + + ld hl, wScriptFlags + bit 3, [hl] + jr z, .nope + + ld hl, wPriorityScriptAddr + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wPriorityScriptBank] + call CallScript + scf + ret + +.nope + xor a + ret + +CheckTimeEvents: + ld a, [wLinkMode] + and a + jr nz, .nothing + + ld hl, wStatusFlags2 + bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl] + jr z, .do_daily + + farcall CheckBugContestTimer + jr c, .end_bug_contest + xor a + ret + +.do_daily + farcall CheckDailyResetTimer + farcall CheckSwarmFlag + farcall CheckPokerusTick + farcall CheckPhoneCall + ret c + +.nothing + xor a + ret + +.end_bug_contest + ld a, BANK(BugCatchingContestOverScript) + ld hl, BugCatchingContestOverScript + call CallScript + scf + ret + +.unused + ld a, 8 + scf + ret + +OWPlayerInput: + call PlayerMovement + ret c + and a + jr nz, .NoAction + +; Can't perform button actions while sliding on ice. + farcall CheckStandingOnIce + jr c, .NoAction + + call CheckAPressOW + jr c, .Action + + call CheckMenuOW + jr c, .Action + +.NoAction: + xor a + ret + +.Action: + push af + farcall StopPlayerForEvent + pop af + scf + ret + +CheckAPressOW: + ldh a, [hJoyPressed] + and A_BUTTON + ret z + call TryObjectEvent + ret c + call TryBGEvent + ret c + call TryTileCollisionEvent + ret c + xor a + ret + +PlayTalkObject: + push de + ld de, SFX_READ_TEXT_2 + call PlaySFX + pop de + ret + +TryObjectEvent: + farcall CheckFacingObject + jr c, .IsObject + xor a + ret + +.IsObject: + call PlayTalkObject + ldh a, [hObjectStructIndexBuffer] + call GetObjectStruct + ld hl, OBJECT_MAP_OBJECT_INDEX + add hl, bc + ld a, [hl] + ldh [hLastTalked], a + + ldh a, [hLastTalked] + call GetMapObject + ld hl, MAPOBJECT_COLOR + add hl, bc + ld a, [hl] + and %00001111 + +; Bug: If IsInArray returns nc, data at bc will be executed as code. + push bc + ld de, 3 + ld hl, .pointers + call IsInArray + jr nc, .nope + pop bc + + inc hl + ld a, [hli] + ld h, [hl] + ld l, a + jp hl + +.nope + ; pop bc + xor a + ret + +.pointers + dbw OBJECTTYPE_SCRIPT, .script + dbw OBJECTTYPE_ITEMBALL, .itemball + dbw OBJECTTYPE_TRAINER, .trainer + ; the remaining four are dummy events + dbw OBJECTTYPE_3, .three + dbw OBJECTTYPE_4, .four + dbw OBJECTTYPE_5, .five + dbw OBJECTTYPE_6, .six + db -1 + +.script + ld hl, MAPOBJECT_SCRIPT_POINTER + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + call GetMapScriptsBank + call CallScript + ret + +.itemball + ld hl, MAPOBJECT_SCRIPT_POINTER + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + call GetMapScriptsBank + ld de, wItemBallData + ld bc, wItemBallDataEnd - wItemBallData + call FarCopyBytes + ld a, PLAYEREVENT_ITEMBALL + scf + ret + +.trainer + call TalkToTrainer + ld a, PLAYEREVENT_TALKTOTRAINER + scf + ret + +.three + xor a + ret + +.four + xor a + ret + +.five + xor a + ret + +.six + xor a + ret + +TryBGEvent: + call CheckFacingBGEvent + jr c, .is_bg_event + xor a + ret + +.is_bg_event: + ld a, [wCurBGEventType] + ld hl, .bg_events + rst JumpTable + ret + +.bg_events + dw .read + dw .up + dw .down + dw .right + dw .left + dw .ifset + dw .ifnotset + dw .itemifset + dw .copy + +.up + ld b, OW_UP + jr .checkdir +.down + ld b, OW_DOWN + jr .checkdir +.right + ld b, OW_RIGHT + jr .checkdir +.left + ld b, OW_LEFT + jr .checkdir + +.checkdir + ld a, [wPlayerDirection] + and %1100 + cp b + jp nz, .dontread + +.read + call PlayTalkObject + ld hl, wCurBGEventScriptAddr + ld a, [hli] + ld h, [hl] + ld l, a + call GetMapScriptsBank + call CallScript + scf + ret + +.itemifset + call CheckBGEventFlag + jp nz, .dontread + call PlayTalkObject + call GetMapScriptsBank + ld de, wHiddenItemData + ld bc, wHiddenItemDataEnd - wHiddenItemData + call FarCopyBytes + ld a, BANK(HiddenItemScript) + ld hl, HiddenItemScript + call CallScript + scf + ret + +.copy + call CheckBGEventFlag + jr nz, .dontread + call GetMapScriptsBank + ld de, wHiddenItemData + ld bc, wHiddenItemDataEnd - wHiddenItemData + call FarCopyBytes + jr .dontread + +.ifset + call CheckBGEventFlag + jr z, .dontread + jr .thenread + +.ifnotset + call CheckBGEventFlag + jr nz, .dontread + +.thenread + push hl + call PlayTalkObject + pop hl + inc hl + inc hl + call GetMapScriptsBank + call GetFarHalfword + call GetMapScriptsBank + call CallScript + scf + ret + +.dontread + xor a + ret + +CheckBGEventFlag: + ld hl, wCurBGEventScriptAddr + ld a, [hli] + ld h, [hl] + ld l, a + push hl + call GetMapScriptsBank + call GetFarHalfword + ld e, l + ld d, h + ld b, CHECK_FLAG + call EventFlagAction + ld a, c + and a + pop hl + ret + +PlayerMovement: + farcall DoPlayerMovement + ld a, c + ld hl, .pointers + rst JumpTable + ld a, c + ret + +.pointers +; entries correspond to PLAYERMOVEMENT_* constants + dw .normal + dw .warp + dw .turn + dw .force_turn + dw .finish + dw .continue + dw .exit_water + dw .jump + +.normal: +.finish: + xor a + ld c, a + ret + +.jump: + call ret_968d7 ; mobile + xor a + ld c, a + ret + +.warp: + ld a, PLAYEREVENT_WARP + ld c, a + scf + ret + +.turn: + ld a, PLAYEREVENT_JOYCHANGEFACING + ld c, a + scf + ret + +.force_turn: +; force the player to move in some direction + ld a, BANK(Script_ForcedMovement) + ld hl, Script_ForcedMovement + call CallScript +; ld a, -1 + ld c, a + scf + ret + +.continue: +.exit_water: + ld a, -1 + ld c, a + and a + ret + +CheckMenuOW: + xor a + ldh [hMenuReturn], a + ldh [hUnusedFFA3], a + ldh a, [hJoyPressed] + + bit SELECT_F, a + jr nz, .Select + + bit START_F, a + jr z, .NoMenu + + ld a, BANK(StartMenuScript) + ld hl, StartMenuScript + call CallScript + scf + ret + +.NoMenu: + xor a + ret + +.Select: + call PlayTalkObject + ld a, BANK(SelectMenuScript) + ld hl, SelectMenuScript + call CallScript + scf + ret + +StartMenuScript: + callasm StartMenu + sjump StartMenuCallback + +SelectMenuScript: + callasm SelectMenu + sjump SelectMenuCallback + +StartMenuCallback: +SelectMenuCallback: + readmem hMenuReturn + ifequal HMENURETURN_SCRIPT, .Script + ifequal HMENURETURN_ASM, .Asm + end + +.Script: + memjump wQueuedScriptBank + +.Asm: + memcallasm wQueuedScriptBank + end + +CountStep: + ; Don't count steps in link communication rooms. + ld a, [wLinkMode] + and a + jr nz, .done + + ; If there is a special phone call, don't count the step. + farcall CheckSpecialPhoneCall + jr c, .doscript + + ; If Repel wore off, don't count the step. + call DoRepelStep + jr c, .doscript + + ; Count the step for poison and total steps + ld hl, wPoisonStepCount + inc [hl] + ld hl, wStepCount + inc [hl] + ; Every 256 steps, increase the happiness of all your Pokemon. + jr nz, .skip_happiness + + farcall StepHappiness + +.skip_happiness + ; Every 256 steps, offset from the happiness incrementor by 128 steps, + ; decrease the hatch counter of all your eggs until you reach the first + ; one that is ready to hatch. + ld a, [wStepCount] + cp $80 + jr nz, .skip_egg + + farcall DoEggStep + jr nz, .hatch + +.skip_egg + ; Increase the EXP of (both) DayCare Pokemon by 1. + farcall DayCareStep + + ; Every four steps, deal damage to all Poisoned Pokemon + ld hl, wPoisonStepCount + ld a, [hl] + cp 4 + jr c, .skip_poison + ld [hl], 0 + + farcall DoPoisonStep + jr c, .doscript + +.skip_poison + farcall DoBikeStep + +.done + xor a + ret + +.doscript + ld a, -1 + scf + ret + +.hatch + ld a, PLAYEREVENT_HATCH + scf + ret + +; unused +.unreferenced + ld a, PLAYEREVENT_WHITEOUT + scf + ret + +DoRepelStep: + ld a, [wRepelEffect] + and a + ret z + + dec a + ld [wRepelEffect], a + ret nz + + ld a, BANK(RepelWoreOffScript) + ld hl, RepelWoreOffScript + call CallScript + scf + ret + +DoPlayerEvent: + ld a, [wScriptRunning] + and a + ret z + + cp PLAYEREVENT_MAPSCRIPT ; run script + ret z + + cp NUM_PLAYER_EVENTS + ret nc + + ld c, a + ld b, 0 + ld hl, PlayerEventScriptPointers + add hl, bc + add hl, bc + add hl, bc + ld a, [hli] + ld [wScriptBank], a + ld a, [hli] + ld [wScriptPos], a + ld a, [hl] + ld [wScriptPos + 1], a + ret + +PlayerEventScriptPointers: +; entries correspond to PLAYEREVENT_* constants + dba Invalid_0x96c2d ; PLAYEREVENT_NONE + dba SeenByTrainerScript ; PLAYEREVENT_SEENBYTRAINER + dba TalkToTrainerScript ; PLAYEREVENT_TALKTOTRAINER + dba FindItemInBallScript ; PLAYEREVENT_ITEMBALL + dba EdgeWarpScript ; PLAYEREVENT_CONNECTION + dba WarpToNewMapScript ; PLAYEREVENT_WARP + dba FallIntoMapScript ; PLAYEREVENT_FALL + dba Script_OverworldWhiteout ; PLAYEREVENT_WHITEOUT + dba HatchEggScript ; PLAYEREVENT_HATCH + dba ChangeDirectionScript ; PLAYEREVENT_JOYCHANGEFACING + dba Invalid_0x96c2d ; (NUM_PLAYER_EVENTS) + +Invalid_0x96c2d: + end + +; unused + end + +HatchEggScript: + callasm OverworldHatchEgg + end + +WarpToNewMapScript: + warpsound + newloadmap MAPSETUP_DOOR + end + +FallIntoMapScript: + newloadmap MAPSETUP_FALL + playsound SFX_KINESIS + applymovement PLAYER, MovementData_0x96c48 + playsound SFX_STRENGTH + scall LandAfterPitfallScript + end + +MovementData_0x96c48: + skyfall + step_end + +LandAfterPitfallScript: + earthquake 16 + end + +EdgeWarpScript: ; 4 + reloadandreturn MAPSETUP_CONNECTION + +ChangeDirectionScript: ; 9 + deactivatefacing 3 + callasm EnableWildEncounters + end + +INCLUDE "engine/overworld/scripting.asm" + +WarpToSpawnPoint:: + ld hl, wStatusFlags2 + res STATUSFLAGS2_SAFARI_GAME_F, [hl] + res STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl] + ret + +RunMemScript:: +; If there is no script here, we don't need to be here. + ld a, [wMapReentryScriptQueueFlag] + and a + ret z +; Execute the script at (wMapReentryScriptBank):(wMapReentryScriptAddress). + ld hl, wMapReentryScriptAddress + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wMapReentryScriptBank] + call CallScript + scf +; Clear the buffer for the next script. + push af + xor a + ld hl, wMapReentryScriptQueueFlag + ld bc, 8 + call ByteFill + pop af + ret + +LoadScriptBDE:: +; If there's already a script here, don't overwrite. + ld hl, wMapReentryScriptQueueFlag + ld a, [hl] + and a + ret nz +; Set the flag + ld [hl], 1 + inc hl +; Load the script pointer b:de into (wMapReentryScriptBank):(wMapReentryScriptAddress) + ld [hl], b + inc hl + ld [hl], e + inc hl + ld [hl], d + scf + ret + +TryTileCollisionEvent:: + call GetFacingTileCoord + ld [wFacingTileID], a + ld c, a + farcall CheckFacingTileForStdScript + jr c, .done + + call CheckCutTreeTile + jr nz, .whirlpool + farcall TryCutOW + jr .done + +.whirlpool + ld a, [wFacingTileID] + call CheckWhirlpoolTile + jr nz, .waterfall + farcall TryWhirlpoolOW + jr .done + +.waterfall + ld a, [wFacingTileID] + call CheckWaterfallTile + jr nz, .headbutt + farcall TryWaterfallOW + jr .done + +.headbutt + ld a, [wFacingTileID] + call CheckHeadbuttTreeTile + jr nz, .surf + farcall TryHeadbuttOW + jr c, .done + jr .noevent + +.surf + farcall TrySurfOW + jr nc, .noevent + jr .done + +.noevent + xor a + ret + +.done + call PlayClickSFX + ld a, $ff + scf + ret + +RandomEncounter:: +; Random encounter + + call CheckWildEncounterCooldown + jr c, .nope + call CanUseSweetScent + jr nc, .nope + ld hl, wStatusFlags2 + bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl] + jr nz, .bug_contest + farcall TryWildEncounter + jr nz, .nope + jr .ok + +.bug_contest + call _TryWildEncounter_BugContest + jr nc, .nope + jr .ok_bug_contest + +.nope + ld a, 1 + and a + ret + +.ok + ld a, BANK(WildBattleScript) + ld hl, WildBattleScript + jr .done + +.ok_bug_contest + ld a, BANK(BugCatchingContestBattleScript) + ld hl, BugCatchingContestBattleScript + jr .done + +.done + call CallScript + scf + ret + +WildBattleScript: + randomwildmon + startbattle + reloadmapafterbattle + end + +CanUseSweetScent:: + ld hl, wStatusFlags + bit STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl] + jr nz, .no + ld a, [wEnvironment] + cp CAVE + jr z, .ice_check + cp DUNGEON + jr z, .ice_check + farcall CheckGrassCollision + jr nc, .no + +.ice_check + ld a, [wPlayerStandingTile] + call CheckIceTile + jr z, .no + scf + ret + +.no + and a + ret + +_TryWildEncounter_BugContest: + call TryWildEncounter_BugContest + ret nc + call ChooseWildEncounter_BugContest + farcall CheckRepelEffect + ret + +ChooseWildEncounter_BugContest:: +; Pick a random mon out of ContestMons. + +.loop + call Random + cp 100 << 1 + jr nc, .loop + srl a + + ld hl, ContestMons + ld de, 4 +.CheckMon: + sub [hl] + jr c, .GotMon + add hl, de + jr .CheckMon + +.GotMon: + inc hl + +; Species + ld a, [hli] + ld [wTempWildMonSpecies], a + +; Min level + ld a, [hli] + ld d, a + +; Max level + ld a, [hl] + + sub d + jr nz, .RandomLevel + +; If min and max are the same. + ld a, d + jr .GotLevel + +.RandomLevel: +; Get a random level between the min and max. + ld c, a + inc c + call Random + ldh a, [hRandomAdd] + call SimpleDivide + add d + +.GotLevel: + ld [wCurPartyLevel], a + + xor a + ret + +TryWildEncounter_BugContest: + ld a, [wPlayerStandingTile] + call CheckSuperTallGrassTile + ld b, 40 percent + jr z, .ok + ld b, 20 percent + +.ok + farcall ApplyMusicEffectOnEncounterRate + farcall ApplyCleanseTagEffectOnEncounterRate + call Random + ldh a, [hRandomAdd] + cp b + ret c + ld a, 1 + and a + ret + +INCLUDE "data/wild/bug_contest_mons.asm" + +DoBikeStep:: + nop + nop + ; If the bike shop owner doesn't have our number, or + ; if we've already gotten the call, we don't have to + ; be here. + ld hl, wStatusFlags2 + bit STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl] + jr z, .NoCall + + ; If we're not on the bike, we don't have to be here. + ld a, [wPlayerState] + cp PLAYER_BIKE + jr nz, .NoCall + + ; If we're not in an area of phone service, we don't + ; have to be here. + call GetMapPhoneService + and a + jr nz, .NoCall + + ; Check the bike step count and check whether we've + ; taken 65536 of them yet. + ld hl, wBikeStep + ld a, [hli] + ld d, a + ld e, [hl] + cp 255 + jr nz, .increment + ld a, e + cp 255 + jr z, .dont_increment + +.increment + inc de + ld [hl], e + dec hl + ld [hl], d + +.dont_increment + ; If we've taken at least 1024 steps, have the bike + ; shop owner try to call us. + ld a, d + cp HIGH(1024) + jr c, .NoCall + + ; If a call has already been queued, don't overwrite + ; that call. + ld a, [wSpecialPhoneCallID] + and a + jr nz, .NoCall + + ; Queue the call. + ld a, SPECIALCALL_BIKESHOP + ld [wSpecialPhoneCallID], a + xor a + ld [wSpecialPhoneCallID + 1], a + ld hl, wStatusFlags2 + res STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl] + scf + ret + +.NoCall: + xor a + ret + +ClearCmdQueue:: + ld hl, wCmdQueue + ld de, CMDQUEUE_ENTRY_SIZE + ld c, CMDQUEUE_CAPACITY + xor a +.loop + ld [hl], a + add hl, de + dec c + jr nz, .loop + ret + +HandleCmdQueue:: + ld hl, wCmdQueue + xor a +.loop + ldh [hMapObjectIndexBuffer], a + ld a, [hl] + and a + jr z, .skip + push hl + ld b, h + ld c, l + call HandleQueuedCommand + pop hl + +.skip + ld de, CMDQUEUE_ENTRY_SIZE + add hl, de + ldh a, [hMapObjectIndexBuffer] + inc a + cp CMDQUEUE_CAPACITY + jr nz, .loop + ret + +Unreferenced_GetNthCmdQueueEntry: + ld hl, wCmdQueue + ld bc, CMDQUEUE_ENTRY_SIZE + call AddNTimes + ld b, h + ld c, l + ret + +WriteCmdQueue:: + push bc + push de + call .GetNextEmptyEntry + ld d, h + ld e, l + pop hl + pop bc + ret c + ld a, b + ld bc, CMDQUEUE_ENTRY_SIZE - 1 + call FarCopyBytes + xor a + ld [hl], a + ret + +.GetNextEmptyEntry: + ld hl, wCmdQueue + ld de, CMDQUEUE_ENTRY_SIZE + ld c, CMDQUEUE_CAPACITY +.loop + ld a, [hl] + and a + jr z, .done + add hl, de + dec c + jr nz, .loop + scf + ret + +.done + ld a, CMDQUEUE_CAPACITY + sub c + and a + ret + +DelCmdQueue:: + ld hl, wCmdQueue + ld de, CMDQUEUE_ENTRY_SIZE + ld c, CMDQUEUE_CAPACITY +.loop + ld a, [hl] + cp b + jr z, .done + add hl, de + dec c + jr nz, .loop + and a + ret + +.done + xor a + ld [hl], a + scf + ret + +_DelCmdQueue: + ld hl, CMDQUEUE_TYPE + add hl, bc + ld [hl], 0 + ret + +HandleQueuedCommand: + ld hl, CMDQUEUE_TYPE + add hl, bc + ld a, [hl] + cp NUM_CMDQUEUE_TYPES + jr c, .okay + xor a + +.okay + ld e, a + ld d, 0 + ld hl, .Jumptable + add hl, de + add hl, de + add hl, de + ld a, [hli] + push af + ld a, [hli] + ld h, [hl] + ld l, a + pop af + rst FarCall + ret + +.Jumptable: + dba CmdQueue_Null + dba CmdQueue_Type2 + dba CmdQueue_StoneTable + dba CmdQueue_Null2 + dba CmdQueue_Type4 + +CmdQueueAnonymousJumptable: + ld hl, CMDQUEUE_05 + add hl, bc + ld a, [hl] + pop hl + rst JumpTable + ret + +CmdQueueAnonJT_Increment: + ld hl, CMDQUEUE_05 + add hl, bc + inc [hl] + ret + +CmdQueueAnonJT_Decrement: + ld hl, CMDQUEUE_05 + add hl, bc + dec [hl] + ret + +CmdQueue_Null: + ret + +CmdQueue_Type2: + call Function2ffe + ret + +CmdQueue_Type4: + call CmdQueueAnonymousJumptable + ; anonymous dw + dw .zero + dw .one + +.zero + ldh a, [hSCY] + ld hl, CMDQUEUE_04 + add hl, bc + ld [hl], a + call CmdQueueAnonJT_Increment +.one + ld hl, CMDQUEUE_ADDR + add hl, bc + ld a, [hl] + dec a + ld [hl], a + jr z, .finish + and 1 + jr z, .add + ld hl, CMDQUEUE_02 + add hl, bc + ldh a, [hSCY] + sub [hl] + ldh [hSCY], a + ret + +.add + ld hl, CMDQUEUE_02 + add hl, bc + ldh a, [hSCY] + add [hl] + ldh [hSCY], a + ret + +.finish + ld hl, CMDQUEUE_04 + add hl, bc + ld a, [hl] + ldh [hSCY], a + call _DelCmdQueue + ret + +CmdQueue_Null2: + ret + +CmdQueue_StoneTable: + ld de, wPlayerStruct + ld a, NUM_OBJECT_STRUCTS +.loop + push af + + ld hl, OBJECT_SPRITE + add hl, de + ld a, [hl] + and a + jr z, .next + + ld hl, OBJECT_MOVEMENTTYPE + add hl, de + ld a, [hl] + cp SPRITEMOVEDATA_STRENGTH_BOULDER + jr nz, .next + + ld hl, OBJECT_NEXT_TILE + add hl, de + ld a, [hl] + call CheckPitTile + jr nz, .next + + ld hl, OBJECT_DIRECTION_WALKING + add hl, de + ld a, [hl] + cp STANDING + jr nz, .next + call HandleStoneQueue + jr c, .fall_down_hole + +.next + ld hl, OBJECT_LENGTH + add hl, de + ld d, h + ld e, l + + pop af + dec a + jr nz, .loop + ret + +.fall_down_hole + pop af + ret + +INCLUDE "engine/events/trainer_scripts.asm" diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 07b53007..a59be34f 100755 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -666,7 +666,7 @@ Function55a1: call Function55d8 ld a, $0 call Function55bc - ld a, [wd180] + ld a, [wBattleScriptFlags] bit 7, a jr z, .asm_55b8 ldh a, [hLastTalked] @@ -1021,7 +1021,7 @@ Function57bd: ; 57bd (1:57bd) ld [wObjectFollow_Follower], a ret -Function57d2: +SetFlagsForMovement_1:: ld a, c call CheckObjectVisibility ret c @@ -1064,7 +1064,7 @@ Function57f0: ; 57f0 (1:57f0) jr nz, .asm_57f4 ret -Function580d: +_SetFlagsForMovement_2:: ld a, [wObjectFollow_Leader] cp $ff ret z @@ -1085,7 +1085,7 @@ Function580d: res 5, [hl] ret -Function582f: +Function582f:: push bc ld bc, wPlayerSprite xor a diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm index 38fe15d0..e40f2b1c 100755 --- a/engine/overworld/npc_movement.asm +++ b/engine/overworld/npc_movement.asm @@ -205,7 +205,7 @@ Function7080: ; 7080 (1:7080) scf ret -CheckFacingObject: +CheckFacingObject:: call GetFacingTileCoord call CheckCounterTile jr nz, .asm_70d0 diff --git a/engine/overworld/player_movement.asm b/engine/overworld/player_movement.asm index 5fdca29c..98cce97d 100755 --- a/engine/overworld/player_movement.asm +++ b/engine/overworld/player_movement.asm @@ -483,7 +483,7 @@ Function102bf: ; 102bf (4:42bf) ret Function102cb: ; 102cb (4:42cb) - call Function10404 + call CheckStandingOnIce ret nc ld a, [wPlayerTurningDirection] .asm_102d2 @@ -704,7 +704,7 @@ Function103f9: ; 103f9 (4:43f9) pop bc ret -Function10404: ; 10404 (4:4404) +CheckStandingOnIce:: ld a, [wPlayerTurningDirection] cp $0 jr z, .asm_10420 diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm index 1ea552b5..ee8ebe1b 100755 --- a/engine/overworld/player_object.asm +++ b/engine/overworld/player_object.asm @@ -42,7 +42,7 @@ SpawnPlayer: ; 861a (2:461a) ; Said bytes seem to be unused. object_event -4, -4, SPRITE_CHRIS, SPRITEMOVEDATA_PLAYER, 15, 15, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, 0, -1 -CopyDECoordsToMapObject: ; 8653 (2:4653) +CopyDECoordsToMapObject:: push de ld a, b call GetMapObject @@ -55,7 +55,7 @@ CopyDECoordsToMapObject: ; 8653 (2:4653) ld [hl], e ret -PlayerSpawn_ConvertCoords: ; 8664 (2:4664) +PlayerSpawn_ConvertCoords: push bc ld a, [wXCoord] add $4 @@ -67,7 +67,7 @@ PlayerSpawn_ConvertCoords: ; 8664 (2:4664) call CopyDECoordsToMapObject ret -WritePersonXY: +WriteObjectXY:: ld a, b call CheckObjectVisibility ret c @@ -259,7 +259,7 @@ InitializeVisibleSprites: Function87b9: ; 87b9 (2:47b9) ret -CheckObjectEnteringVisibleRange: +CheckObjectEnteringVisibleRange:: nop ld a, [wPlayerStepDirection] cp $ff @@ -473,7 +473,7 @@ InitTempObjectRadius: ; 88fd (2:48fd) ld [hl], a ret -TrainerWalkToPlayer: +TrainerWalkToPlayer:: ldh a, [hLastTalked] call InitMovementBuffer ld a, movement_step_sleep @@ -554,7 +554,7 @@ GetInitialSurfStep: ; 8978 (2:4978) slow_step LEFT slow_step RIGHT -FollowNotExact: +FollowNotExact:: push bc ld a, c call CheckObjectVisibility @@ -636,7 +636,7 @@ FollowNotExact: ld [hl], $0 ret -GetRelativeFacing: +GetRelativeFacing:: ld a, d call GetMapObject ld hl, $0 diff --git a/engine/overworld/player_step.asm b/engine/overworld/player_step.asm index 8e250295..e55fc4e7 100755 --- a/engine/overworld/player_step.asm +++ b/engine/overworld/player_step.asm @@ -1,4 +1,4 @@ -HandlePlayerStep_:: +_HandlePlayerStep:: ld a, [wPlayerStepFlags] and a ret z diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm new file mode 100644 index 00000000..7c5bfe55 --- /dev/null +++ b/engine/overworld/scripting.asm @@ -0,0 +1,2673 @@ +; Event scripting commands. + +EnableScriptMode:: + push af + ld a, SCRIPT_READ + ld [wScriptMode], a + pop af + ret + +ScriptEvents:: + call StartScript +.loop + ld a, [wScriptMode] + ld hl, .modes + rst JumpTable + call CheckScript + jr nz, .loop + ret + +.modes + dw EndScript + dw RunScriptCommand + dw WaitScriptMovement + dw WaitScript + +EndScript: + call StopScript + ret + +WaitScript: + call StopScript + + ld hl, wScriptDelay + dec [hl] + ret nz + + farcall Function582f + + ld a, SCRIPT_READ + ld [wScriptMode], a + call StartScript + ret + +WaitScriptMovement: + call StopScript + + ld hl, wVramState + bit 7, [hl] + ret nz + + farcall Function582f + + ld a, SCRIPT_READ + ld [wScriptMode], a + call StartScript + ret + +RunScriptCommand: + call GetScriptByte + ld hl, ScriptCommandTable + rst JumpTable + ret + +ScriptCommandTable: +; entries correspond to macros/scripts/events.asm enumeration + dw Script_scall ; 00 + dw Script_farscall ; 01 + dw Script_memcall ; 02 + dw Script_sjump ; 03 + dw Script_farsjump ; 04 + dw Script_memjump ; 05 + dw Script_ifequal ; 06 + dw Script_ifnotequal ; 07 + dw Script_iffalse ; 08 + dw Script_iftrue ; 09 + dw Script_ifgreater ; 0a + dw Script_ifless ; 0b + dw Script_jumpstd ; 0c + dw Script_callstd ; 0d + dw Script_callasm ; 0e + dw Script_special ; 0f + dw Script_memcallasm ; 10 + dw Script_checkmapscene ; 11 + dw Script_setmapscene ; 12 + dw Script_checkscene ; 13 + dw Script_setscene ; 14 + dw Script_setval ; 15 + dw Script_addval ; 16 + dw Script_random ; 17 + dw Script_checkver ; 18 + dw Script_readmem ; 19 + dw Script_writemem ; 1a + dw Script_loadmem ; 1b + dw Script_readvar ; 1c + dw Script_writevar ; 1d + dw Script_loadvar ; 1e + dw Script_giveitem ; 1f + dw Script_takeitem ; 20 + dw Script_checkitem ; 21 + dw Script_givemoney ; 22 + dw Script_takemoney ; 23 + dw Script_checkmoney ; 24 + dw Script_givecoins ; 25 + dw Script_takecoins ; 26 + dw Script_checkcoins ; 27 + dw Script_addcellnum ; 28 + dw Script_delcellnum ; 29 + dw Script_checkcellnum ; 2a + dw Script_checktime ; 2b + dw Script_checkpoke ; 2c + dw Script_givepoke ; 2d + dw Script_giveegg ; 2e + dw Script_givepokemail ; 2f + dw Script_checkpokemail ; 30 + dw Script_checkevent ; 31 + dw Script_clearevent ; 32 + dw Script_setevent ; 33 + dw Script_checkflag ; 34 + dw Script_clearflag ; 35 + dw Script_setflag ; 36 + dw Script_wildon ; 37 + dw Script_wildoff ; 38 + dw Script_xycompare ; 39 + dw Script_warpmod ; 3a + dw Script_blackoutmod ; 3b + dw Script_warp ; 3c + dw Script_getmoney ; 3d + dw Script_getcoins ; 3e + dw Script_getnum ; 3f + dw Script_getmonname ; 40 + dw Script_getitemname ; 41 + dw Script_getcurlandmarkname ; 42 + dw Script_gettrainername ; 43 + dw Script_getstring ; 44 + dw Script_itemnotify ; 45 + dw Script_pocketisfull ; 46 + dw Script_opentext ; 47 + dw Script_refreshscreen ; 48 + dw Script_closetext ; 49 + dw Script_writeunusedbytebuffer ; 4a + dw Script_farwritetext ; 4b + dw Script_writetext ; 4c + dw Script_repeattext ; 4d + dw Script_yesorno ; 4e + dw Script_loadmenu ; 4f + dw Script_closewindow ; 50 + dw Script_jumptextfaceplayer ; 51 + dw Script_jumptext ; 52 + dw Script_waitbutton ; 53 + dw Script_promptbutton ; 54 + dw Script_pokepic ; 55 + dw Script_closepokepic ; 56 + dw Script__2dmenu ; 57 + dw Script_verticalmenu ; 58 + dw Script_loadpikachudata ; 59 + dw Script_randomwildmon ; 5a + dw Script_loadtemptrainer ; 5b + dw Script_loadwildmon ; 5c + dw Script_loadtrainer ; 5d + dw Script_startbattle ; 5e + dw Script_reloadmapafterbattle ; 5f + dw Script_catchtutorial ; 60 + dw Script_trainertext ; 61 + dw Script_trainerflagaction ; 62 + dw Script_winlosstext ; 63 + dw Script_scripttalkafter ; 64 + dw Script_endifjustbattled ; 65 + dw Script_checkjustbattled ; 66 + dw Script_setlasttalked ; 67 + dw Script_applymovement ; 68 + dw Script_applymovementlasttalked ; 69 + dw Script_faceplayer ; 6a + dw Script_faceobject ; 6b + dw Script_variablesprite ; 6c + dw Script_disappear ; 6d + dw Script_appear ; 6e + dw Script_follow ; 6f + dw Script_stopfollow ; 70 + dw Script_moveobject ; 71 + dw Script_writeobjectxy ; 72 + dw Script_loademote ; 73 + dw Script_showemote ; 74 + dw Script_turnobject ; 75 + dw Script_follownotexact ; 76 + dw Script_earthquake ; 77 + dw Script_changemapblocks ; 78 + dw Script_changeblock ; 79 + dw Script_reloadmap ; 7a + dw Script_reloadmappart ; 7b + dw Script_writecmdqueue ; 7c + dw Script_delcmdqueue ; 7d + dw Script_playmusic ; 7e + dw Script_encountermusic ; 7f + dw Script_musicfadeout ; 80 + dw Script_playmapmusic ; 81 + dw Script_dontrestartmapmusic ; 82 + dw Script_cry ; 83 + dw Script_playsound ; 84 + dw Script_waitsfx ; 85 + dw Script_warpsound ; 86 + dw Script_specialsound ; 87 + dw Script_autoinput ; 88 + dw Script_newloadmap ; 89 + dw Script_pause ; 8a + dw Script_deactivatefacing ; 8b + dw Script_prioritysjump ; 8c + dw Script_warpcheck ; 8d + dw Script_stopandsjump ; 8e + dw Script_return ; 8f + dw Script_end ; 90 + dw Script_reloadandreturn ; 91 + dw Script_endall ; 92 + dw Script_pokemart ; 93 + dw Script_elevator ; 94 + dw Script_trade ; 95 + dw Script_askforphonenumber ; 96 + dw Script_phonecall ; 97 + dw Script_hangup ; 98 + dw Script_describedecoration ; 99 + dw Script_fruittree ; 9a + dw Script_specialphonecall ; 9b + dw Script_checkphonecall ; 9c + dw Script_verbosegiveitem ; 9d + dw Script_swarm ; 9e + dw Script_halloffame ; 9f + dw Script_credits ; a0 + dw Script_warpfacing ; a1 + +StartScript: + ld hl, wScriptFlags + set SCRIPT_RUNNING, [hl] + ret + +CheckScript: + ld hl, wScriptFlags + bit SCRIPT_RUNNING, [hl] + ret + +StopScript: + ld hl, wScriptFlags + res SCRIPT_RUNNING, [hl] + ret + +Script_callasm: +; script command 0xe +; parameters: asm + + call GetScriptByte + ld b, a + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld a, b + rst FarCall + ret + +Script_special: +; script command 0xf +; parameters: predefined_script + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + farcall Special + ret + +Script_memcallasm: +; script command 0x10 +; parameters: asm + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld b, [hl] + inc hl + ld a, [hli] + ld h, [hl] + ld l, a + ld a, b + rst FarCall + ret + +Script_jumptextfaceplayer: +; script command 0x51 +; parameters: text_pointer + + ld a, [wScriptBank] + ld [wScriptTextBank], a + call GetScriptByte + ld [wScriptTextAddr], a + call GetScriptByte + ld [wScriptTextAddr + 1], a + ld b, BANK(JumpTextFacePlayerScript) + ld hl, JumpTextFacePlayerScript + jp ScriptJump + +Script_jumptext: +; script command 0x52 +; parameters: text_pointer + + ld a, [wScriptBank] + ld [wScriptTextBank], a + call GetScriptByte + ld [wScriptTextAddr], a + call GetScriptByte + ld [wScriptTextAddr + 1], a + ld b, BANK(JumpTextScript) + ld hl, JumpTextScript + jp ScriptJump + +JumpTextFacePlayerScript: + faceplayer +JumpTextScript: + opentext + repeattext -1, -1 + waitbutton + closetext + end + +Script_writetext: +; script command 0x4c +; parameters: text_pointer + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld a, [wScriptBank] + ld b, a + call MapTextbox + ret + +Script_farwritetext: +; script command 0x4b +; parameters: text_pointer + + call GetScriptByte + ld b, a + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + call MapTextbox + ret + +Script_repeattext: +; script command 0x4d +; parameters: byte, byte + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + cp -1 + jr nz, .done + ld a, l + cp -1 + jr nz, .done + ld hl, wScriptTextBank + ld a, [hli] + ld b, a + ld a, [hli] + ld h, [hl] + ld l, a + call MapTextbox + ret + +.done + ret + +Script_waitbutton: +; script command 0x53 + + jp WaitButton + +Script_promptbutton: +; script command 0x54 + + ldh a, [hOAMUpdate] + push af + ld a, $1 + ldh [hOAMUpdate], a + call WaitBGMap + call PromptButton + pop af + ldh [hOAMUpdate], a + ret + +Script_yesorno: +; script command 0x4e + + call YesNoBox + ld a, FALSE + jr c, .no + ld a, TRUE +.no + ld [wScriptVar], a + ret + +Script_loadmenu: +; script command 0x4f +; parameters: menu_header + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld de, LoadMenuHeader + ld a, [wScriptBank] + call Call_a_de + call UpdateSprites + ret + +Script_closewindow: +; script command 0x50 + + call CloseWindow + call UpdateSprites + ret + +Script_pokepic: +; script command 0x55 +; parameters: pokemon + + call GetScriptByte + and a + jr nz, .ok + ld a, [wScriptVar] +.ok + ld [wCurPartySpecies], a + farcall Pokepic + ret + +Script_closepokepic: +; script command 0x56 + + farcall ClosePokepic + ret + +Script_verticalmenu: +; script command 0x58 + + ld a, [wScriptBank] + ld hl, VerticalMenu + rst FarCall + ld a, [wMenuCursorY] + jr nc, .ok + xor a +.ok + ld [wScriptVar], a + ret + +Script__2dmenu: +; script command 0x57 + + ld a, [wScriptBank] + ld hl, _2DMenu + rst FarCall + ld a, [wMenuCursorBuffer] + jr nc, .ok + xor a +.ok + ld [wScriptVar], a + ret + +Script_verbosegiveitem: +; script command 0x9d +; parameters: item, quantity + + call Script_giveitem + call CurItemName + ld de, wStringBuffer1 + ld a, STRING_BUFFER_4 + call CopyConvertedText + ld b, BANK(GiveItemScript) + ld de, GiveItemScript + jp ScriptCall + +ret_96f76: + ret + +GiveItemScript: + callasm ret_96f76 + writetext ReceivedItemText + iffalse .Full + waitsfx + specialsound + waitbutton + itemnotify + end + +.Full: + promptbutton + pocketisfull + end + +ReceivedItemText: + text_far _ReceivedItemText + text_end + +Script_itemnotify: +; script command 0x45 + + call GetPocketName + call CurItemName + ld b, BANK(PutItemInPocketText) + ld hl, PutItemInPocketText + call MapTextbox + ret + +Script_pocketisfull: +; script command 0x46 + + call GetPocketName + call CurItemName + ld b, BANK(PocketIsFullText) + ld hl, PocketIsFullText + call MapTextbox + ret + +Script_specialsound: +; script command 0x87 + + farcall CheckItemPocket + ld a, [wItemAttributeParamBuffer] + cp TM_HM + ld de, SFX_GET_TM + jr z, .play + ld de, SFX_ITEM +.play + call PlaySFX + call WaitSFX + ret + +GetPocketName: + farcall CheckItemPocket + ld a, [wItemAttributeParamBuffer] + dec a + ld hl, ItemPocketNames + maskbits NUM_POCKETS + add a + ld e, a + ld d, 0 + add hl, de + ld a, [hli] + ld d, [hl] + ld e, a + ld hl, wStringBuffer3 + call CopyName2 + ret + +INCLUDE "data/items/pocket_names.asm" + +CurItemName: + ld a, [wCurItem] + ld [wNamedObjectIndexBuffer], a + call GetItemName + ret + +PutItemInPocketText: + text_far _PutItemInPocketText + text_end + +PocketIsFullText: + text_far _PocketIsFullText + text_end + +Script_pokemart: +; script command 0x93 +; parameters: mart_type, mart_id + + call GetScriptByte + ld c, a + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld a, [wScriptBank] + ld b, a + farcall OpenMartDialog + ret + +Script_elevator: +; script command 0x94 +; parameters: floor_list_pointer + + xor a + ld [wScriptVar], a + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld a, [wScriptBank] + ld b, a + farcall Elevator + ret c + ld a, TRUE + ld [wScriptVar], a + ret + +Script_trade: +; script command 0x95 +; parameters: trade_id + + call GetScriptByte + ld e, a + farcall NPCTrade + ret + +Script_phonecall: +; script command 0x97 +; parameters: caller_name + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld a, [wScriptBank] + ld b, a + farcall PhoneCall + ret + +Script_hangup: +; script command 0x98 + + farcall HangUp + ret + +Script_askforphonenumber: +; script command 0x96 +; parameters: number + + call YesNoBox + jr c, .refused + call GetScriptByte + ld c, a + farcall AddPhoneNumber + jr c, .phonefull + xor a ; PHONE_CONTACT_GOT + jr .done +.phonefull + ld a, PHONE_CONTACTS_FULL + jr .done +.refused + call GetScriptByte + ld a, PHONE_CONTACT_REFUSED +.done + ld [wScriptVar], a + ret + +Script_describedecoration: +; script command 0x99 +; parameters: byte + + call GetScriptByte + ld b, a + farcall DescribeDecoration + ld h, d + ld l, e + jp ScriptJump + +Script_fruittree: +; script command 0x9a +; parameters: tree_id + + call GetScriptByte + ld [wCurFruitTree], a + ld b, BANK(FruitTreeScript) + ld hl, FruitTreeScript + jp ScriptJump + +Script_swarm: +; script command 0x9e +; parameters: map_group, map_id + + call GetScriptByte + ld d, a + call GetScriptByte + ld e, a + farcall StoreSwarmMapIndices + ret + +Script_trainertext: +; script command 0x61 +; parameters: text_id + + call GetScriptByte + ld c, a + ld b, 0 + ld hl, wSeenTextPointer + add hl, bc + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wSeenTrainerBank] + ld b, a + call MapTextbox + ret + +Script_scripttalkafter: +; script command 0x64 + + ld hl, wScriptAfterPointer + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wSeenTrainerBank] + ld b, a + jp ScriptJump + +Script_trainerflagaction: +; script command 0x62 +; parameters: action + + xor a + ld [wScriptVar], a + ld hl, wTempTrainerEventFlag + ld e, [hl] + inc hl + ld d, [hl] + call GetScriptByte + ld b, a + call EventFlagAction + ld a, c + and a + ret z + ld a, TRUE + ld [wScriptVar], a + ret + +Script_winlosstext: +; script command 0x63 +; parameters: win_text_pointer, loss_text_pointer + + ld hl, wWinTextPointer + call GetScriptByte + ld [hli], a + call GetScriptByte + ld [hli], a + ld hl, wLossTextPointer + call GetScriptByte + ld [hli], a + call GetScriptByte + ld [hli], a + ret + +Script_endifjustbattled: +; script command 0x65 + + ld a, [wRunningTrainerBattleScript] + and a + ret z + jp Script_end + +Script_checkjustbattled: +; script command 0x66 + + ld a, TRUE + ld [wScriptVar], a + ld a, [wRunningTrainerBattleScript] + and a + ret nz + xor a + ld [wScriptVar], a + ret + +Script_encountermusic: +; script command 0x7f + + ld a, [wOtherTrainerClass] + ld e, a + farcall PlayTrainerEncounterMusic + ret + +Script_playmapmusic: +; script command 0x81 + + call PlayMapMusic + ret + +Script_playmusic: +; script command 0x7e +; parameters: music_pointer + + ld de, MUSIC_NONE + call PlayMusic + xor a + ld [wMusicFade], a + call MaxVolume + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + call PlayMusic + ret + +Script_musicfadeout: +; script command 0x80 +; parameters: music, fadetime + + call GetScriptByte + ld [wMusicFadeID], a + call GetScriptByte + ld [wMusicFadeID + 1], a + call GetScriptByte + and $ff ^ (1 << MUSIC_FADE_IN_F) + ld [wMusicFade], a + ret + +Script_playsound: +; script command 0x84 +; parameters: sound_pointer + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + call PlaySFX + ret + +Script_waitsfx: +; script command 0x85 + + call WaitSFX + ret + +Script_warpsound: +; script command 0x86 + + farcall GetWarpSFX + call PlaySFX + ret + +Script_cry: +; script command 0x83 +; parameters: cry_id + + call GetScriptByte + push af + call GetScriptByte + pop af + and a + jr nz, .ok + ld a, [wScriptVar] +.ok + call PlayMonCry + ret + +Script_setlasttalked: +; script command 0x67 +; parameters: object_id + + call GetScriptByte + ldh [hLastTalked], a + ret + +Script_applymovement: +; script command 0x68 +; parameters: object_id, data + + call GetScriptByte + ld c, a + +ApplyMovement: + push bc + ld a, c + farcall SetFlagsForMovement_1 + pop bc + + push bc + call SetFlagsForMovement_2 + pop bc + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld a, [wScriptBank] + ld b, a + call GetMovementData + ret c + + ld a, SCRIPT_WAIT_MOVEMENT + ld [wScriptMode], a + call StopScript + ret + +SetFlagsForMovement_2: + farcall _SetFlagsForMovement_2 + ret + +Script_applymovementlasttalked: +; script command 0x69 +; parameters: data +; apply movement to last talked + + ldh a, [hLastTalked] + ld c, a + jp ApplyMovement + +Script_faceplayer: +; script command 0x6a + + ldh a, [hLastTalked] + and a + ret z + ld d, $0 + ldh a, [hLastTalked] + ld e, a + farcall GetRelativeFacing + ld a, d + add a + add a + ld e, a + ldh a, [hLastTalked] + ld d, a + call ApplyObjectFacing + ret + +Script_faceobject: +; script command 0x6b +; parameters: object1, object2 + + call GetScriptByte + cp LAST_TALKED + jr c, .ok + ldh a, [hLastTalked] +.ok + ld e, a + call GetScriptByte + cp LAST_TALKED + jr nz, .ok2 + ldh a, [hLastTalked] +.ok2 + ld d, a + push de + farcall GetRelativeFacing + pop bc + ret c + ld a, d + add a + add a + ld e, a + ld d, c + call ApplyObjectFacing + ret + +Script_turnobject: +; script command 0x75 +; parameters: object_id, facing + + call GetScriptByte + cp LAST_TALKED + jr nz, .ok + ldh a, [hLastTalked] +.ok + ld d, a + call GetScriptByte + add a + add a + ld e, a + call ApplyObjectFacing + ret + +ApplyObjectFacing: + ld a, d + push de + call CheckObjectVisibility + jr c, .not_visible + ld hl, OBJECT_SPRITE + add hl, bc + ld a, [hl] + push bc + call DoesSpriteHaveFacings + pop bc + jr c, .not_visible ; STILL_SPRITE + ld hl, OBJECT_FLAGS1 + add hl, bc + bit FIXED_FACING_F, [hl] + jr nz, .not_visible + pop de + ld a, e + call SetSpriteDirection + call UpdateSprites + ret + +.not_visible + pop de + scf + ret + +Script_variablesprite: +; script command 0x6c +; parameters: byte, sprite + + call GetScriptByte + ld e, a + ld d, $0 + ld hl, wVariableSprites + add hl, de + call GetScriptByte + ld [hl], a + ret + +Script_appear: +; script command 0x6e +; parameters: object_id + + call GetScriptByte + call _CopyObjectStruct + ldh a, [hMapObjectIndexBuffer] + ld b, 0 ; clear + call ApplyEventActionAppearDisappear + ret + +Script_disappear: +; script command 0x6d +; parameters: object_id + + call GetScriptByte + cp LAST_TALKED + jr nz, .ok + ldh a, [hLastTalked] +.ok + call DeleteObjectStruct + ldh a, [hMapObjectIndexBuffer] + ld b, 1 ; set + call ApplyEventActionAppearDisappear + farcall _UpdateSprites + ret + +ApplyEventActionAppearDisappear: + push bc + call GetMapObject + ld hl, MAPOBJECT_EVENT_FLAG + add hl, bc + pop bc + ld e, [hl] + inc hl + ld d, [hl] + ld a, -1 + cp e + jr nz, .okay + cp d + jr nz, .okay + xor a + ret +.okay + call EventFlagAction + ret + +Script_follow: +; script command 0x6f +; parameters: object2, object1 + + call GetScriptByte + ld b, a + call GetScriptByte + ld c, a + farcall StartFollow + ret + +Script_stopfollow: +; script command 0x70 + + farcall StopFollow + ret + +Script_moveobject: +; script command 0x71 +; parameters: object id, x, y + + call GetScriptByte + ld b, a + call GetScriptByte + add 4 + ld d, a + call GetScriptByte + add 4 + ld e, a + farcall CopyDECoordsToMapObject + ret + +Script_writeobjectxy: +; script command 0x72 +; parameters: object_id + + call GetScriptByte + cp LAST_TALKED + jr nz, .ok + ldh a, [hLastTalked] +.ok + ld b, a + farcall WriteObjectXY + ret + +Script_follownotexact: +; script command 0x76 +; parameters: object2, object1 + + call GetScriptByte + ld b, a + call GetScriptByte + ld c, a + farcall FollowNotExact + ret + +Script_loademote: +; script command 0x73 +; parameters: bubble + + call GetScriptByte + cp EMOTE_FROM_MEM + jr nz, .not_var_emote + ld a, [wScriptVar] +.not_var_emote + ld c, a + farcall LoadEmote + ret + +Script_showemote: +; script command 0x74 +; parameters: bubble, object_id, time + + call GetScriptByte + ld [wScriptVar], a + call GetScriptByte + cp LAST_TALKED + jr z, .ok + ldh [hLastTalked], a +.ok + call GetScriptByte + ld [wScriptDelay], a + ld b, BANK(ShowEmoteScript) + ld de, ShowEmoteScript + jp ScriptCall + +ShowEmoteScript: + loademote EMOTE_FROM_MEM + applymovementlasttalked .Show + pause 0 + applymovementlasttalked .Hide + end + +.Show: + show_emote + step_sleep 1 + step_end + +.Hide: + hide_emote + step_sleep 1 + step_end + +Script_earthquake: +; script command 0x77 +; parameters: param + + ld hl, EarthquakeMovement + ld de, wEarthquakeMovementDataBuffer + ld bc, EarthquakeMovement.End - EarthquakeMovement + call CopyBytes + call GetScriptByte + ld [wEarthquakeMovementDataBuffer + 1], a + and %00111111 + ld [wEarthquakeMovementDataBuffer + 3], a + ld b, BANK(.script) + ld de, .script + jp ScriptCall + +.script + applymovement PLAYER, wEarthquakeMovementDataBuffer + end + +EarthquakeMovement: + step_shake 16 ; the 16 gets overwritten with the script byte + step_sleep 16 ; the 16 gets overwritten with the lower 6 bits of the script byte + step_end +.End + +Script_loadpikachudata: +; script command 0x59 + + ld a, PIKACHU + ld [wTempWildMonSpecies], a + ld a, 5 + ld [wCurPartyLevel], a + ret + +Script_randomwildmon: +; script command 0x5a + + xor a + ld [wBattleScriptFlags], a + ret + +Script_loadtemptrainer: +; script command 0x5b + + ld a, (1 << 7) | 1 + ld [wBattleScriptFlags], a + ld a, [wTempTrainerClass] + ld [wOtherTrainerClass], a + ld a, [wTempTrainerID] + ld [wOtherTrainerID], a + ret + +Script_loadwildmon: +; script command 0x5c +; parameters: pokemon, level + + ld a, (1 << 7) + ld [wBattleScriptFlags], a + call GetScriptByte + ld [wTempWildMonSpecies], a + call GetScriptByte + ld [wCurPartyLevel], a + ret + +Script_loadtrainer: +; script command 0x5d +; parameters: trainer_group, trainer_id + + ld a, (1 << 7) | 1 + ld [wBattleScriptFlags], a + call GetScriptByte + ld [wOtherTrainerClass], a + call GetScriptByte + ld [wOtherTrainerID], a + ret + +Script_startbattle: +; script command 0x5e + + call BufferScreen + predef StartBattle + ld a, [wBattleResult] + and $ff ^ BATTLERESULT_BITMASK + ld [wScriptVar], a + ret + +Script_catchtutorial: +; script command 0x60 +; parameters: byte + + call GetScriptByte + ld [wBattleType], a + call BufferScreen + farcall CatchTutorial + jp Script_reloadmap + +Script_reloadmapafterbattle: +; script command 0x5f + + ld hl, wBattleScriptFlags + ld d, [hl] + ld [hl], 0 + ld a, [wBattleResult] + and $ff ^ BATTLERESULT_BITMASK + cp LOSE + jr nz, .notblackedout + ld b, BANK(Script_BattleWhiteout) + ld hl, Script_BattleWhiteout + jp ScriptJump + +.notblackedout + bit 0, d + jr z, .was_wild + farcall MomTriesToBuySomething + jr .done + +.was_wild + ld a, [wBattleResult] + bit BATTLERESULT_BOX_FULL, a + jr z, .done + ld b, BANK(Script_SpecialBillCall) + ld de, Script_SpecialBillCall + farcall LoadScriptBDE +.done + jp Script_reloadmap + +Script_reloadmap: +; script command 0x7a + + xor a + ld [wBattleScriptFlags], a + ld a, MAPSETUP_RELOADMAP + ldh [hMapEntryMethod], a + ld a, MAPSTATUS_ENTER + call LoadMapStatus + call StopScript + ret + +Script_scall: +; script command 0x0 +; parameters: pointer + + ld a, [wScriptBank] + ld b, a + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + jr ScriptCall + +Script_farscall: +; script command 0x1 +; parameters: pointer + + call GetScriptByte + ld b, a + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + jr ScriptCall + +Script_memcall: +; script command 0x2 +; parameters: pointer + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld b, [hl] + inc hl + ld e, [hl] + inc hl + ld d, [hl] + ; fallthrough + +ScriptCall: +; Bug: The script stack has a capacity of 5 scripts, yet there is +; nothing to stop you from pushing a sixth script. The high part +; of the script address can then be overwritten by modifications +; to wScriptDelay, causing the script to return to the rst/interrupt +; space. + + push de + ld hl, wScriptStackSize + ld e, [hl] + inc [hl] + ld d, 0 + ld hl, wScriptStack + add hl, de + add hl, de + add hl, de + pop de + ld a, [wScriptBank] + ld [hli], a + ld a, [wScriptPos] + ld [hli], a + ld a, [wScriptPos + 1] + ld [hl], a + ld a, b + ld [wScriptBank], a + ld a, e + ld [wScriptPos], a + ld a, d + ld [wScriptPos + 1], a + ret + +CallCallback:: + ld a, [wScriptBank] + or $80 + ld [wScriptBank], a + jp ScriptCall + +Script_sjump: +; script command 0x3 +; parameters: pointer + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld a, [wScriptBank] + ld b, a + jp ScriptJump + +Script_farsjump: +; script command 0x4 +; parameters: pointer + + call GetScriptByte + ld b, a + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + jp ScriptJump + +Script_memjump: +; script command 0x5 +; parameters: pointer + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld b, [hl] + inc hl + ld a, [hli] + ld h, [hl] + ld l, a + jp ScriptJump + +Script_iffalse: +; script command 0x8 +; parameters: pointer + + ld a, [wScriptVar] + and a + jp nz, SkipTwoScriptBytes + jp Script_sjump + +Script_iftrue: +; script command 0x9 +; parameters: pointer + + ld a, [wScriptVar] + and a + jp nz, Script_sjump + jp SkipTwoScriptBytes + +Script_ifequal: +; script command 0x6 +; parameters: byte, pointer + + call GetScriptByte + ld hl, wScriptVar + cp [hl] + jr z, Script_sjump + jr SkipTwoScriptBytes + +Script_ifnotequal: +; script command 0x7 +; parameters: byte, pointer + + call GetScriptByte + ld hl, wScriptVar + cp [hl] + jr nz, Script_sjump + jr SkipTwoScriptBytes + +Script_ifgreater: +; script command 0xa +; parameters: byte, pointer + + ld a, [wScriptVar] + ld b, a + call GetScriptByte + cp b + jr c, Script_sjump + jr SkipTwoScriptBytes + +Script_ifless: +; script command 0xb +; parameters: byte, pointer + + call GetScriptByte + ld b, a + ld a, [wScriptVar] + cp b + jr c, Script_sjump + jr SkipTwoScriptBytes + +Script_jumpstd: +; script command 0xc +; parameters: predefined_script + + call StdScript + jr ScriptJump + +Script_callstd: +; script command 0xd +; parameters: predefined_script + + call StdScript + ld d, h + ld e, l + jp ScriptCall + +StdScript: + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld hl, StdScripts + add hl, de + add hl, de + add hl, de + ld a, BANK(StdScripts) + call GetFarByte + ld b, a + inc hl + ld a, BANK(StdScripts) + call GetFarHalfword + ret + +SkipTwoScriptBytes: + call GetScriptByte + call GetScriptByte + ret + +ScriptJump: + ld a, b + ld [wScriptBank], a + ld a, l + ld [wScriptPos], a + ld a, h + ld [wScriptPos + 1], a + ret + +Script_prioritysjump: +; script command 0x8c +; parameters: pointer + + ld a, [wScriptBank] + ld [wPriorityScriptBank], a + call GetScriptByte + ld [wPriorityScriptAddr], a + call GetScriptByte + ld [wPriorityScriptAddr + 1], a + ld hl, wScriptFlags + set 3, [hl] + ret + +Script_checkscene: +; script command 0x13 + + call CheckScenes + jr z, .no_scene + ld [wScriptVar], a + ret + +.no_scene + ld a, $ff + ld [wScriptVar], a + ret + +Script_checkmapscene: +; script command 0x11 +; parameters: map_group, map_id + + call GetScriptByte + ld b, a + call GetScriptByte + ld c, a + call GetMapSceneID + ld a, d + or e + jr z, .no_scene + ld a, [de] + ld [wScriptVar], a + ret + +.no_scene + ld a, $ff + ld [wScriptVar], a + ret + +Script_setscene: +; script command 0x14 +; parameters: scene_id + + ld a, [wMapGroup] + ld b, a + ld a, [wMapNumber] + ld c, a + jr DoScene + +Script_setmapscene: +; script command 0x12 +; parameters: map_group, map_id, scene_id + + call GetScriptByte + ld b, a + call GetScriptByte + ld c, a +DoScene: + call GetMapSceneID + ld a, d + or e + jr z, .no_scene + call GetScriptByte + ld [de], a +.no_scene + ret + +Script_readmem: +; script command 0x19 +; parameters: address + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld a, [hl] + ld [wScriptVar], a + ret + +Script_writemem: +; script command 0x1a +; parameters: address + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld a, [wScriptVar] + ld [hl], a + ret + +Script_loadmem: +; script command 0x1b +; parameters: address, value + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + call GetScriptByte + ld [hl], a + ret + +Script_setval: +; script command 0x15 +; parameters: value + + call GetScriptByte + ld [wScriptVar], a + ret + +Script_addval: +; script command 0x16 +; parameters: value + + call GetScriptByte + ld hl, wScriptVar + add [hl] + ld [hl], a + ret + +Script_random: +; script command 0x17 +; parameters: input + + call GetScriptByte + ld [wScriptVar], a + and a + ret z + + ld c, a + call .Divide256byC + and a + jr z, .no_restriction ; 256 % b == 0 + ld b, a + xor a + sub b + ld b, a +.loop + push bc + call Random + pop bc + ldh a, [hRandomAdd] + cp b + jr nc, .loop + jr .finish + +.no_restriction + push bc + call Random + pop bc + ldh a, [hRandomAdd] + +.finish + push af + ld a, [wScriptVar] + ld c, a + pop af + call SimpleDivide + ld [wScriptVar], a + ret + +.Divide256byC: + xor a + ld b, a + sub c +.mod_loop + inc b + sub c + jr nc, .mod_loop + dec b + add c + ret + +Script_readvar: +; script command 0x1c +; parameters: variable_id + + call GetScriptByte + call GetVarAction + ld a, [de] + ld [wScriptVar], a + ret + +Script_writevar: +; script command 0x1d +; parameters: variable_id + + call GetScriptByte + call GetVarAction + ld a, [wScriptVar] + ld [de], a + ret + +Script_loadvar: +; script command 0x1e +; parameters: variable_id, value + + call GetScriptByte + call GetVarAction + call GetScriptByte + ld [de], a + ret + +GetVarAction: + ld c, a + farcall _GetVarAction + ret + +Script_checkver: +; script command 0x18 + + ld a, [.gs_version] + ld [wScriptVar], a + ret + +.gs_version: + db GS_VERSION + +Script_getmonname: +; script command 0x40 +; parameters: string_buffer, mon_id (0 aka USE_SCRIPT_VAR to use wScriptVar) + + call GetScriptByte + and a + jr nz, .gotit + ld a, [wScriptVar] +.gotit + ld [wNamedObjectIndexBuffer], a + call GetPokemonName + ld de, wStringBuffer1 + +GetStringBuffer: + call GetScriptByte + cp NUM_STRING_BUFFERS + jr c, .ok + xor a +.ok + +CopyConvertedText: + ld hl, wStringBuffer3 + ld bc, wStringBuffer4 - wStringBuffer3 + call AddNTimes + call CopyName2 + ret + +Script_getitemname: +; script command 0x41 +; parameters: string_buffer, item_id (0 aka USE_SCRIPT_VAR to use wScriptVar) + + call GetScriptByte + and a ; USE_SCRIPT_VAR + jr nz, .ok + ld a, [wScriptVar] +.ok + ld [wNamedObjectIndexBuffer], a + call GetItemName + ld de, wStringBuffer1 + jr GetStringBuffer + +Script_getcurlandmarkname: +; script command 0x42 +; parameters: string_buffer + + ld a, [wMapGroup] + ld b, a + ld a, [wMapNumber] + ld c, a + call GetWorldMapLocation + +ConvertLandmarkToText: + ld e, a + farcall GetLandmarkName + ld de, wStringBuffer1 + jp GetStringBuffer + +Script_gettrainername: +; script command 0x43 +; parameters: string_buffer, trainer_group, trainer_id + + call GetScriptByte + ld c, a + call GetScriptByte + ld b, a + farcall GetTrainerName + jr GetStringBuffer + +Script_getmoney: +; script command 0x3d +; parameters: string_buffer, account + + call ResetStringBuffer1 + call GetMoneyAccount + ld hl, wStringBuffer1 + lb bc, PRINTNUM_LEFTALIGN | 3, 6 + call PrintNum + ld de, wStringBuffer1 + jp GetStringBuffer + +Script_getcoins: +; script command 0x3e +; parameters: string_buffer + + call ResetStringBuffer1 + ld hl, wStringBuffer1 + ld de, wCoins + lb bc, PRINTNUM_LEFTALIGN | 2, 6 + call PrintNum + ld de, wStringBuffer1 + jp GetStringBuffer + +Script_getnum: +; script command 0x3f +; parameters: string_buffer + + call ResetStringBuffer1 + ld de, wScriptVar + ld hl, wStringBuffer1 + lb bc, PRINTNUM_LEFTALIGN | 1, 3 + call PrintNum + ld de, wStringBuffer1 + jp GetStringBuffer + +ResetStringBuffer1: + ld hl, wStringBuffer1 + ld bc, NAME_LENGTH + 2 + ld a, "@" + call ByteFill + ret + +Script_getstring: +; script command 0x44 +; parameters: string_buffer, text_pointer + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld a, [wScriptBank] + ld hl, CopyName1 + rst FarCall + ld de, wStringBuffer2 + jp GetStringBuffer + +Script_givepokemail: +; script command 0x2f +; parameters: pointer + + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + ld a, [wScriptBank] + call GetFarByte + ld b, a + push bc + inc hl + ld bc, MAIL_MSG_LENGTH + ld de, wceed + ld a, [wScriptBank] + call FarCopyBytes + pop bc + farcall GivePokeMail + ret + +Script_checkpokemail: +; script command 0x30 +; parameters: pointer + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld a, [wScriptBank] + ld b, a + farcall CheckPokeMail + ret + +Script_giveitem: +; script command 0x1f +; parameters: item, quantity + + call GetScriptByte + cp ITEM_FROM_MEM + jr nz, .ok + ld a, [wScriptVar] +.ok + ld [wCurItem], a + call GetScriptByte + ld [wItemQuantityChangeBuffer], a + ld hl, wNumItems + call ReceiveItem + jr nc, .full + ld a, TRUE + ld [wScriptVar], a + ret +.full + xor a + ld [wScriptVar], a + ret + +Script_takeitem: +; script command 0x20 +; parameters: item, quantity + + xor a + ld [wScriptVar], a + call GetScriptByte + ld [wCurItem], a + call GetScriptByte + ld [wItemQuantityChangeBuffer], a + ld a, -1 + ld [wCurItemQuantity], a + ld hl, wNumItems + call TossItem + ret nc + ld a, TRUE + ld [wScriptVar], a + ret + +Script_checkitem: +; script command 0x21 +; parameters: item + + xor a + ld [wScriptVar], a + call GetScriptByte + ld [wCurItem], a + ld hl, wNumItems + call CheckItem + ret nc + ld a, TRUE + ld [wScriptVar], a + ret + +Script_givemoney: +; script command 0x22 +; parameters: account, money + + call GetMoneyAccount + call LoadMoneyAmountToMem + farcall GiveMoney + ret + +Script_takemoney: +; script command 0x23 +; parameters: account, money + + call GetMoneyAccount + call LoadMoneyAmountToMem + farcall TakeMoney + ret + +Script_checkmoney: +; script command 0x24 +; parameters: account, money + + call GetMoneyAccount + call LoadMoneyAmountToMem + farcall CompareMoney + +CompareMoneyAction: + jr c, .less + jr z, .exact + ld a, HAVE_MORE + jr .done +.exact + ld a, HAVE_AMOUNT + jr .done +.less + ld a, HAVE_LESS +.done + ld [wScriptVar], a + ret + +GetMoneyAccount: + call GetScriptByte + and a + ld de, wMoney ; YOUR_MONEY + ret z + ld de, wMomsMoney ; MOMS_MONEY + ret + +LoadMoneyAmountToMem: + ld bc, hMoneyTemp + push bc + call GetScriptByte + ld [bc], a + inc bc + call GetScriptByte + ld [bc], a + inc bc + call GetScriptByte + ld [bc], a + pop bc + ret + +Script_givecoins: +; script command 0x25 +; parameters: coins + + call LoadCoinAmountToMem + farcall GiveCoins + ret + +Script_takecoins: +; script command 0x26 +; parameters: coins + + call LoadCoinAmountToMem + farcall TakeCoins + ret + +Script_checkcoins: +; script command 0x27 +; parameters: coins + + call LoadCoinAmountToMem + farcall CheckCoins + jr CompareMoneyAction + +LoadCoinAmountToMem: + call GetScriptByte + ldh [hMoneyTemp + 1], a + call GetScriptByte + ldh [hMoneyTemp], a + ld bc, hMoneyTemp + ret + +Script_checktime: +; script command 0x2b +; parameters: time + + xor a + ld [wScriptVar], a + farcall CheckTime + call GetScriptByte + and c + ret z + ld a, TRUE + ld [wScriptVar], a + ret + +Script_checkpoke: +; script command 0x2c +; parameters: pokemon + + xor a + ld [wScriptVar], a + call GetScriptByte + ld hl, wPartySpecies + ld de, 1 + call IsInArray + ret nc + ld a, TRUE + ld [wScriptVar], a + ret + +Script_addcellnum: +; script command 0x28 +; parameters: person + + xor a + ld [wScriptVar], a + call GetScriptByte + ld c, a + farcall AddPhoneNumber + ret nc + ld a, TRUE + ld [wScriptVar], a + ret + +Script_delcellnum: +; script command 0x29 +; parameters: person + + xor a + ld [wScriptVar], a + call GetScriptByte + ld c, a + farcall DelCellNum + ret nc + ld a, TRUE + ld [wScriptVar], a + ret + +Script_checkcellnum: +; script command 0x2a +; parameters: person +; returns false if the cell number is not in your phone + + xor a + ld [wScriptVar], a + call GetScriptByte + ld c, a + farcall CheckCellNum + ret nc + ld a, TRUE + ld [wScriptVar], a + ret + +Script_specialphonecall: +; script command 0x9b +; parameters: call_id + + call GetScriptByte + ld [wSpecialPhoneCallID], a + call GetScriptByte + ld [wSpecialPhoneCallID + 1], a + ret + +Script_checkphonecall: +; script command 0x9c +; returns false if no special phone call is stored + + ld a, [wSpecialPhoneCallID] + and a + jr z, .ok + ld a, TRUE +.ok + ld [wScriptVar], a + ret + +Script_givepoke: +; script command 0x2d +; parameters: pokemon, level, item, trainer, trainer_name_pointer, pkmn_nickname + + call GetScriptByte + ld [wCurPartySpecies], a + call GetScriptByte + ld [wCurPartyLevel], a + call GetScriptByte + ld [wCurItem], a + call GetScriptByte + and a + ld b, a + jr z, .ok + ld hl, wScriptPos + ld e, [hl] + inc hl + ld d, [hl] + call GetScriptByte + call GetScriptByte + call GetScriptByte + call GetScriptByte +.ok + farcall GivePoke + ld a, b + ld [wScriptVar], a + ret + +Script_giveegg: +; script command 0x2e +; parameters: pokemon, level +; if no room in the party, return 0 in wScriptVar; else, return 2 + + xor a ; PARTYMON + ld [wScriptVar], a + ld [wMonType], a + call GetScriptByte + ld [wCurPartySpecies], a + call GetScriptByte + ld [wCurPartyLevel], a + farcall GiveEgg + ret nc + ld a, 2 + ld [wScriptVar], a + ret + +Script_setevent: +; script command 0x33 +; parameters: bit_number + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld b, SET_FLAG + call EventFlagAction + ret + +Script_clearevent: +; script command 0x32 +; parameters: bit_number + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld b, RESET_FLAG + call EventFlagAction + ret + +Script_checkevent: +; script command 0x31 +; parameters: bit_number + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld b, CHECK_FLAG + call EventFlagAction + ld a, c + and a + jr z, .false + ld a, TRUE +.false + ld [wScriptVar], a + ret + +Script_setflag: +; script command 0x36 +; parameters: bit_number + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld b, SET_FLAG + call _EngineFlagAction + ret + +Script_clearflag: +; script command 0x35 +; parameters: bit_number + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld b, RESET_FLAG + call _EngineFlagAction + ret + +Script_checkflag: +; script command 0x34 +; parameters: bit_number + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld b, CHECK_FLAG + call _EngineFlagAction + ld a, c + and a + jr z, .false + ld a, TRUE +.false + ld [wScriptVar], a + ret + +_EngineFlagAction: + farcall EngineFlagAction + ret + +Script_wildoff: +; script command 0x38 + + ld hl, wStatusFlags + set STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl] + ret + +Script_wildon: +; script command 0x37 + + ld hl, wStatusFlags + res STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl] + ret + +Script_xycompare: +; script command 0x39 +; parameters: pointer + + call GetScriptByte + ld [wXYComparePointer], a + call GetScriptByte + ld [wXYComparePointer + 1], a + ret + +Script_warpfacing: +; script command 0xa1 +; parameters: facing, map_group, map_id, x, y + + call GetScriptByte + maskbits NUM_DIRECTIONS + ld c, a + ld a, [wPlayerSpriteSetupFlags] + set PLAYERSPRITESETUP_CUSTOM_FACING_F, a + or c + ld [wPlayerSpriteSetupFlags], a +; fall through + +Script_warp: +; script command 0x3c +; parameters: map_group, map_id, x, y + +; This seems to be some sort of error handling case. + call GetScriptByte + and a + jr z, .not_ok + ld [wMapGroup], a + call GetScriptByte + ld [wMapNumber], a + call GetScriptByte + ld [wXCoord], a + call GetScriptByte + ld [wYCoord], a + ld a, SPAWN_N_A + ld [wDefaultSpawnpoint], a + ld a, MAPSETUP_WARP + ldh [hMapEntryMethod], a + ld a, MAPSTATUS_ENTER + call LoadMapStatus + call StopScript + ret + +.not_ok + call GetScriptByte + call GetScriptByte + call GetScriptByte + ld a, SPAWN_N_A + ld [wDefaultSpawnpoint], a + ld a, MAPSETUP_BADWARP + ldh [hMapEntryMethod], a + ld a, MAPSTATUS_ENTER + call LoadMapStatus + call StopScript + ret + +Script_warpmod: +; script command 0x3a +; parameters: warp_id, map_group, map_id + + call GetScriptByte + ld [wBackupWarpNumber], a + call GetScriptByte + ld [wBackupMapGroup], a + call GetScriptByte + ld [wBackupMapNumber], a + ret + +Script_blackoutmod: +; script command 0x3b +; parameters: map_group, map_id + + call GetScriptByte + ld [wLastSpawnMapGroup], a + call GetScriptByte + ld [wLastSpawnMapNumber], a + ret + +Script_dontrestartmapmusic: +; script command 0x82 + + ld a, TRUE + ld [wDontPlayMapMusicOnReload], a + ret + +Script_writecmdqueue: +; script command 0x7c +; parameters: queue_pointer + + call GetScriptByte + ld e, a + call GetScriptByte + ld d, a + ld a, [wScriptBank] + ld b, a + farcall WriteCmdQueue ; no need to farcall + ret + +Script_delcmdqueue: +; script command 0x7d +; parameters: byte + + xor a + ld [wScriptVar], a + call GetScriptByte + ld b, a + farcall DelCmdQueue ; no need to farcall + ret c + ld a, TRUE + ld [wScriptVar], a + ret + +Script_changemapblocks: +; script command 0x78 +; parameters: map_data_pointer + + call GetScriptByte + ld [wMapBlocksBank], a + call GetScriptByte + ld [wMapBlocksPointer], a + call GetScriptByte + ld [wMapBlocksPointer + 1], a + call ChangeMap + call BufferScreen + ret + +Script_changeblock: +; script command 0x79 +; parameters: x, y, block + + call GetScriptByte + add 4 + ld d, a + call GetScriptByte + add 4 + ld e, a + call GetBlockLocation + call GetScriptByte + ld [hl], a + call BufferScreen + ret + +Script_reloadmappart:: +; script command 0x7b + + xor a + ldh [hBGMapMode], a + call OverworldTextModeSwitch + call GetMovementPermissions + call ApplyTilemap + call UpdateSprites + ret + +Script_warpcheck: +; script command 0x8d + + call WarpCheck + ret nc + farcall EnableEvents + ret + +Script_enableevents: +; unused + farcall EnableEvents + ret + +Script_newloadmap: +; script command 0x89 +; parameters: which_method + + call GetScriptByte + ldh [hMapEntryMethod], a + ld a, MAPSTATUS_ENTER + call LoadMapStatus + call StopScript + ret + +Script_reloadandreturn: +; script command 0x91 + + call Script_newloadmap + jp Script_end + +Script_opentext: +; script command 0x47 + + call OpenText + ret + +Script_refreshscreen: +; script command 0x48 +; parameters: dummy + + call RefreshScreen + call GetScriptByte + ret + +Script_writeunusedbytebuffer: +; script command 0x4a +; parameters: byte + + call GetScriptByte + ld [wUnusedScriptByteBuffer], a + ret + + db closetext_command ; unused + +Script_closetext: +; script command 0x49 + + ldh a, [hOAMUpdate] + push af + ld a, $01 + ldh [hOAMUpdate], a + call WaitBGMap + pop af + ldh [hOAMUpdate], a + call CloseText + ret + +Script_autoinput: +; script command 0x88 +; parameters: input_pointer + + call GetScriptByte + push af + call GetScriptByte + ld l, a + call GetScriptByte + ld h, a + pop af + call StartAutoInput + ret + +Script_pause: +; script command 0x8a +; parameters: length + + call GetScriptByte + and a + jr z, .loop + ld [wScriptDelay], a +.loop + ld c, 2 + call DelayFrames + ld hl, wScriptDelay + dec [hl] + jr nz, .loop + ret + +Script_deactivatefacing: +; script command 0x8b +; parameters: time + + call GetScriptByte + and a + jr z, .no_time + ld [wScriptDelay], a +.no_time + ld a, SCRIPT_WAIT + ld [wScriptMode], a + call StopScript + ret + +Script_stopandsjump: +; script command 0x8e +; parameters: pointer + + call StopScript + jp Script_sjump + +Script_end: +; script command 0x90 + + call ExitScriptSubroutine + jr c, .resume + ret + +.resume + xor a + ld [wScriptRunning], a + ld a, SCRIPT_OFF + ld [wScriptMode], a + ld hl, wScriptFlags + res 0, [hl] + call StopScript + ret + +Script_return: +; script command 0x8f + + call ExitScriptSubroutine + jr c, .dummy +.dummy + ld hl, wScriptFlags + res 0, [hl] + call StopScript + ret + +ExitScriptSubroutine: +; Return carry if there's no parent to return to. + + ld hl, wScriptStackSize + ld a, [hl] + and a + jr z, .done + dec [hl] + ld e, [hl] + ld d, $0 + ld hl, wScriptStack + add hl, de + add hl, de + add hl, de + ld a, [hli] + ld b, a + and " " + ld [wScriptBank], a + ld a, [hli] + ld e, a + ld [wScriptPos], a + ld a, [hl] + ld d, a + ld [wScriptPos + 1], a + and a + ret +.done + scf + ret + +Script_endall: +; script command 0x92 + + xor a + ld [wScriptStackSize], a + ld [wScriptRunning], a + ld a, SCRIPT_OFF + ld [wScriptMode], a + ld hl, wScriptFlags + res 0, [hl] + call StopScript + ret + +Script_halloffame: +; script command 0x9f + + ld hl, wGameTimerPause + res GAMETIMERPAUSE_TIMER_PAUSED_F, [hl] + farcall HallOfFame + ld hl, wGameTimerPause + set GAMETIMERPAUSE_TIMER_PAUSED_F, [hl] + jr ReturnFromCredits + +Script_credits: +; script command 0xa0 + + farcall RedCredits +ReturnFromCredits: + call Script_endall + ld a, MAPSTATUS_DONE + call LoadMapStatus + call StopScript + ret + +; unused + ld a, [.gs_version] + ld [wScriptVar], a + ret + +.gs_version: + db GS_VERSION diff --git a/engine/overworld/time.asm b/engine/overworld/time.asm index 2ca7e101..5798ee20 100755 --- a/engine/overworld/time.asm +++ b/engine/overworld/time.asm @@ -9,10 +9,10 @@ ClearDailyTimers: ld [wDailyResetTimer], a ret -InitCallReceiveDelay: +InitCallReceiveDelay:: xor a ld [wTimeCyclesSinceLastCall], a -Function11804: ; 11804 (4:5804) +Function11804: ld a, [wTimeCyclesSinceLastCall] cp $3 jr c, .asm_1180d @@ -82,7 +82,7 @@ asm_11867: ld hl, wDailyResetTimer jp Function1182e -CheckDailyResetTimer: +CheckDailyResetTimer:: ld hl, wDailyResetTimer call Function1183b ret nc @@ -102,7 +102,7 @@ StartBugContestTimer: call CopyDayHourMinSecToHL ret -CheckBugContestTimer: +CheckBugContestTimer:: ld hl, wBugContestStartTime call CalcSecsMinsHoursDaysSince ld a, [wDaysSince] @@ -141,7 +141,7 @@ Function118c9: ; 118c9 (4:58c9) call CopyDayToHL ret -CheckPokerusTick: +CheckPokerusTick:: ld hl, wTimerEventStartDay call CalcDaysSince call Function119b4 diff --git a/engine/overworld/variables.asm b/engine/overworld/variables.asm index 445440d2..6483232e 100755 --- a/engine/overworld/variables.asm +++ b/engine/overworld/variables.asm @@ -1,4 +1,4 @@ -GetVarAction_:: +_GetVarAction:: ld a, c cp NUM_VARS jr c, .valid diff --git a/engine/pokemon/move_mon.asm b/engine/pokemon/move_mon.asm index 39e6ea47..c4ecbdc7 100755 --- a/engine/pokemon/move_mon.asm +++ b/engine/pokemon/move_mon.asm @@ -998,7 +998,7 @@ Functiondf65: ; df65 (3:5f65) jr nz, .asm_df89 ret -GiveEgg: ; df92 (3:5f92) +GiveEgg:: ld a, [wCurPartySpecies] push af callfar GetPreEvolution @@ -1482,7 +1482,7 @@ CalcMonStatC: ; e181 pop hl ret -GivePoke: ; Give a Pokemon from script +GivePoke:: push de push bc xor a |