Skip to content

Commit

Permalink
Assert some more table widths
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Mar 17, 2021
1 parent 3684296 commit 6c8f860
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 59 deletions.
4 changes: 3 additions & 1 deletion constants/pokemon_data_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ MON_STATUS rb
rb_skip
MON_HP rw
MON_MAXHP rw
MON_STATS rw NUM_BATTLE_STATS
rsset MON_STATS
MON_ATK rw
MON_DEF rw
MON_SPD rw
Expand Down Expand Up @@ -190,7 +192,7 @@ NUM_TREEMON_SETS EQU const_value
const TREEMON_SCORE_GOOD ; 1
const TREEMON_SCORE_RARE ; 2

; ChangeHappiness arguments (see data/happiness_changes.asm)
; ChangeHappiness arguments (see data/events/happiness_changes.asm)
const_def 1
const HAPPINESS_GAINLEVEL ; 01
const HAPPINESS_USEDITEM ; 02
Expand Down
53 changes: 28 additions & 25 deletions constants/script_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ STRING_BUFFER_LENGTH EQU 19
const VAR_BLUECARDBALANCE ; 18
const VAR_BUENASPASSWORD ; 19
const VAR_KENJI_BREAK ; 1a
NUM_VARS EQU const_value ; 1b
NUM_VARS EQU const_value ; 1b

; variable action types
RETVAR_STRBUF2 EQU (0 << 6)
RETVAR_ADDR_DE EQU (1 << 6)
RETVAR_EXECUTE EQU (2 << 6)
RETVAR_STRBUF2 EQU 0 << 6
RETVAR_ADDR_DE EQU 1 << 6
RETVAR_EXECUTE EQU 2 << 6

; PlayerEventScriptPointers indexes (see engine/overworld/events.asm)
const_def -1
Expand All @@ -94,7 +94,7 @@ RETVAR_EXECUTE EQU (2 << 6)
const PLAYEREVENT_JOYCHANGEFACING
NUM_PLAYER_EVENTS EQU const_value

; PlayerMovement.pointers indexes (see engine/overworld/events.asm)
; PlayerMovementPointers indexes (see engine/overworld/events.asm)
const_def
const PLAYERMOVEMENT_NORMAL
const PLAYERMOVEMENT_WARP
Expand All @@ -104,17 +104,18 @@ NUM_PLAYER_EVENTS EQU const_value
const PLAYERMOVEMENT_CONTINUE
const PLAYERMOVEMENT_EXIT_WATER
const PLAYERMOVEMENT_JUMP
NUM_PLAYER_MOVEMENTS EQU const_value

; script data sizes (see macros/scripts/maps.asm)
SCENE_SCRIPT_SIZE EQU 4 ; scene_script
CALLBACK_SIZE EQU 3 ; callback
WARP_EVENT_SIZE EQU 5 ; warp_event
COORD_EVENT_SIZE EQU 8 ; coord_event
BG_EVENT_SIZE EQU 5 ; bg_event
SCENE_SCRIPT_SIZE EQU 4 ; scene_script
CALLBACK_SIZE EQU 3 ; callback
WARP_EVENT_SIZE EQU 5 ; warp_event
COORD_EVENT_SIZE EQU 8 ; coord_event
BG_EVENT_SIZE EQU 5 ; bg_event
OBJECT_EVENT_SIZE EQU 13 ; object_event

; bg_event types
; TryBGEvent arguments (see engine/overworld/events.asm)
; BGEventJumptable indexes (see engine/overworld/events.asm)
const_def
const BGEVENT_READ
const BGEVENT_UP
Expand All @@ -125,9 +126,10 @@ OBJECT_EVENT_SIZE EQU 13 ; object_event
const BGEVENT_IFNOTSET
const BGEVENT_ITEM
const BGEVENT_COPY
NUM_BGEVENTS EQU const_value

; object_event types
; TryObjectEvent arguments (see engine/overworld/events.asm)
; ObjectEventTypeArray indexes (see engine/overworld/events.asm)
const_def
const OBJECTTYPE_SCRIPT
const OBJECTTYPE_ITEMBALL
Expand All @@ -136,6 +138,7 @@ OBJECT_EVENT_SIZE EQU 13 ; object_event
const OBJECTTYPE_4
const OBJECTTYPE_5
const OBJECTTYPE_6
NUM_OBJECT_TYPES EQU const_value

; command queue members
CMDQUEUE_TYPE EQU 0
Expand Down Expand Up @@ -180,18 +183,18 @@ NUM_FLOORS EQU const_value
; showemote arguments
; Emotes indexes (see data/sprites/emotes.asm)
const_def
const EMOTE_SHOCK ; 0
const EMOTE_QUESTION ; 1
const EMOTE_HAPPY ; 2
const EMOTE_SAD ; 3
const EMOTE_HEART ; 4
const EMOTE_BOLT ; 5
const EMOTE_SLEEP ; 6
const EMOTE_FISH ; 7
const EMOTE_SHADOW ; 8
const EMOTE_ROD ; 9
const EMOTE_BOULDER_DUST ; 10
const EMOTE_GRASS_RUSTLE ; 11
const EMOTE_SHOCK
const EMOTE_QUESTION
const EMOTE_HAPPY
const EMOTE_SAD
const EMOTE_HEART
const EMOTE_BOLT
const EMOTE_SLEEP
const EMOTE_FISH
const EMOTE_SHADOW
const EMOTE_ROD
const EMOTE_BOULDER_DUST
const EMOTE_GRASS_RUSTLE
NUM_EMOTES EQU const_value
EMOTE_FROM_MEM EQU -1
EMOTE_LENGTH EQU 6
Expand Down Expand Up @@ -266,7 +269,7 @@ NUM_DECODESCS EQU const_value
const MAGIKARPLENGTH_TOO_SHORT ; 2
const MAGIKARPLENGTH_BEAT_RECORD ; 3

; SpecialReturnShuckle return values
; ReturnShuckie return values
const_def
const SHUCKIE_WRONG_MON ; 0
const SHUCKIE_REFUSED ; 1
Expand Down
6 changes: 3 additions & 3 deletions constants/wram_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GAME_TIMER_MOBILE_F EQU 7
JOYPAD_DISABLE_MON_FAINT_F EQU 6
JOYPAD_DISABLE_SGB_TRANSFER_F EQU 7

; wOptions::
; wOptions1::
TEXT_DELAY_MASK EQU %111
const_def 4
const NO_TEXT_SCROLL ; 4
Expand Down Expand Up @@ -245,8 +245,8 @@ NUM_BADGES EQU NUM_JOHTO_BADGES + NUM_KANTO_BADGES
const POKEGEAR_RADIO_CARD_F ; 1
const POKEGEAR_PHONE_CARD_F ; 2
const POKEGEAR_EXPN_CARD_F ; 3

POKEGEAR_OBTAINED_F EQU 7
const_skip 3
const POKEGEAR_OBTAINED_F ; 7

; wWhichRegisteredItem::
REGISTERED_POCKET EQU %11000000
Expand Down
2 changes: 1 addition & 1 deletion data/events/special_pointers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ SpecialsPointers::
add_special ToggleMaptileDecorations
add_special ToggleDecorationsVisibility
add_special GiveShuckle
add_special ReturnShuckle
add_special ReturnShuckie
add_special BillsGrandfather
add_special CheckPokerus
add_special DisplayCoinCaseBalance
Expand Down
2 changes: 1 addition & 1 deletion engine/events/shuckle.asm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SpecialShuckleOT:
SpecialShuckleNick:
db "SHUCKIE@"

ReturnShuckle:
ReturnShuckie:
farcall SelectMonFromParty
jr c, .refused

Expand Down
63 changes: 36 additions & 27 deletions engine/overworld/events.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ OverworldLoop::
ld [wMapStatus], a
.loop
ld a, [wMapStatus]
ld hl, .jumps
ld hl, .Jumptable
rst JumpTable
ld a, [wMapStatus]
cp MAPSTATUS_DONE
jr nz, .loop
.done
ret

.jumps
.Jumptable:
; entries correspond to MAPSTATUS_* constants
dw StartMap
dw EnterMap
Expand Down Expand Up @@ -159,22 +159,22 @@ HandleMap:

MapEvents:
ld a, [wMapEventStatus]
ld hl, .jumps
ld hl, .Jumptable
rst JumpTable
ret

.jumps
.Jumptable:
; entries correspond to MAPEVENTS_* constants
dw .events
dw .no_events

.events
.events:
call PlayerEvents
call DisableEvents
farcall ScriptEvents
ret

.no_events
.no_events:
ret

MaxOverworldDelay:
Expand Down Expand Up @@ -557,7 +557,7 @@ TryObjectEvent:
; Bug: If IsInArray returns nc, data at bc will be executed as code.
push bc
ld de, 3
ld hl, .pointers
ld hl, ObjectEventTypeArray
call IsInArray
jr nc, .nope
pop bc
Expand All @@ -573,7 +573,8 @@ TryObjectEvent:
xor a
ret

.pointers
ObjectEventTypeArray:
table_width 3, ObjectEventTypeArray
dbw OBJECTTYPE_SCRIPT, .script
dbw OBJECTTYPE_ITEMBALL, .itemball
dbw OBJECTTYPE_TRAINER, .trainer
Expand All @@ -582,7 +583,8 @@ TryObjectEvent:
dbw OBJECTTYPE_4, .four
dbw OBJECTTYPE_5, .five
dbw OBJECTTYPE_6, .six
db -1
assert_table_length NUM_OBJECT_TYPES
db -1 ; end

.script
ld hl, MAPOBJECT_SCRIPT_POINTER
Expand Down Expand Up @@ -638,11 +640,12 @@ TryBGEvent:

.is_bg_event:
ld a, [wCurBGEventType]
ld hl, .bg_events
ld hl, BGEventJumptable
rst JumpTable
ret

.bg_events
BGEventJumptable:
table_width 2, BGEventJumptable
dw .read
dw .up
dw .down
Expand All @@ -652,27 +655,30 @@ TryBGEvent:
dw .ifnotset
dw .itemifset
dw .copy
assert_table_length NUM_BGEVENTS

.up
.up:
ld b, OW_UP
jr .checkdir
.down

.down:
ld b, OW_DOWN
jr .checkdir
.right

.right:
ld b, OW_RIGHT
jr .checkdir
.left

.left:
ld b, OW_LEFT
jr .checkdir

.checkdir
.checkdir:
ld a, [wPlayerDirection]
and %1100
cp b
jp nz, .dontread

.read
.read:
call PlayTalkObject
ld hl, wCurBGEventScriptAddr
ld a, [hli]
Expand All @@ -683,7 +689,7 @@ TryBGEvent:
scf
ret

.itemifset
.itemifset:
call CheckBGEventFlag
jp nz, .dontread
call PlayTalkObject
Expand All @@ -697,7 +703,7 @@ TryBGEvent:
scf
ret

.copy
.copy:
call CheckBGEventFlag
jr nz, .dontread
call GetMapScriptsBank
Expand All @@ -706,16 +712,15 @@ TryBGEvent:
call FarCopyBytes
jr .dontread

.ifset
.ifset:
call CheckBGEventFlag
jr z, .dontread
jr .thenread

.ifnotset
.ifnotset:
call CheckBGEventFlag
jr nz, .dontread

.thenread
.thenread:
push hl
call PlayTalkObject
pop hl
Expand All @@ -728,7 +733,7 @@ TryBGEvent:
scf
ret

.dontread
.dontread:
xor a
ret

Expand All @@ -752,13 +757,14 @@ CheckBGEventFlag:
PlayerMovement:
farcall DoPlayerMovement
ld a, c
ld hl, .pointers
ld hl, PlayerMovementPointers
rst JumpTable
ld a, c
ret

.pointers
PlayerMovementPointers:
; entries correspond to PLAYERMOVEMENT_* constants
table_width 2, PlayerMovementPointers
dw .normal
dw .warp
dw .turn
Expand All @@ -767,6 +773,7 @@ PlayerMovement:
dw .continue
dw .exit_water
dw .jump
assert_table_length NUM_PLAYER_MOVEMENTS

.normal:
.finish:
Expand Down Expand Up @@ -974,6 +981,7 @@ DoPlayerEvent:

PlayerEventScriptPointers:
; entries correspond to PLAYEREVENT_* constants
table_width 3, PlayerEventScriptPointers
dba InvalidEventScript ; PLAYEREVENT_NONE
dba SeenByTrainerScript ; PLAYEREVENT_SEENBYTRAINER
dba TalkToTrainerScript ; PLAYEREVENT_TALKTOTRAINER
Expand All @@ -985,6 +993,7 @@ PlayerEventScriptPointers:
dba HatchEggScript ; PLAYEREVENT_HATCH
dba ChangeDirectionScript ; PLAYEREVENT_JOYCHANGEFACING
dba InvalidEventScript ; (NUM_PLAYER_EVENTS)
assert_table_length NUM_PLAYER_EVENTS + 1

InvalidEventScript:
end
Expand Down
2 changes: 1 addition & 1 deletion maps/ManiasHouse.asm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ManiaScript:
writetext ManiaText_CanIHaveMyMonBack
yesorno
iffalse .refused
special ReturnShuckle
special ReturnShuckie
ifequal SHUCKIE_WRONG_MON, .wrong
ifequal SHUCKIE_REFUSED, .refused
ifequal SHUCKIE_HAPPY, .superhappy
Expand Down

0 comments on commit 6c8f860

Please sign in to comment.