First Commit

Upload literally everything from the pokecrystal16 expand-move-ID branch
This commit is contained in:
Zeta_Null 2023-09-10 12:35:35 -04:00
commit 2f8a41f833
4618 changed files with 480386 additions and 0 deletions

65
macros/asserts.asm Normal file
View file

@ -0,0 +1,65 @@
; Macros to verify assumptions about the data or code
MACRO table_width
DEF CURRENT_TABLE_WIDTH = \1
if _NARG == 2
REDEF CURRENT_TABLE_START EQUS "\2"
else
REDEF CURRENT_TABLE_START EQUS "._table_width\@"
{CURRENT_TABLE_START}:
endc
ENDM
MACRO assert_table_length
DEF x = \1
assert x * CURRENT_TABLE_WIDTH == @ - {CURRENT_TABLE_START}, \
"{CURRENT_TABLE_START}: expected {d:x} entries, each {d:CURRENT_TABLE_WIDTH} bytes"
ENDM
MACRO list_start
DEF list_index = 0
if _NARG == 1
REDEF CURRENT_LIST_START EQUS "\1"
else
REDEF CURRENT_LIST_START EQUS "._list_start\@"
{CURRENT_LIST_START}:
endc
ENDM
MACRO li
assert !STRIN(\1, "@"), STRCAT("String terminator \"@\" in list entry: ", \1)
db \1, "@"
DEF list_index += 1
ENDM
MACRO assert_list_length
DEF x = \1
assert x == list_index, \
"{CURRENT_LIST_START}: expected {d:x} entries, got {d:list_index}"
ENDM
MACRO def_grass_wildmons
;\1: map id
REDEF CURRENT_GRASS_WILDMONS_MAP EQUS "\1"
REDEF CURRENT_GRASS_WILDMONS_LABEL EQUS "._def_grass_wildmons_\1"
{CURRENT_GRASS_WILDMONS_LABEL}:
map_id \1
ENDM
MACRO end_grass_wildmons
assert GRASS_WILDDATA_LENGTH == @ - {CURRENT_GRASS_WILDMONS_LABEL}, \
"def_grass_wildmons {CURRENT_GRASS_WILDMONS_MAP}: expected {d:GRASS_WILDDATA_LENGTH} bytes"
ENDM
MACRO def_water_wildmons
;\1: map id
REDEF CURRENT_WATER_WILDMONS_MAP EQUS "\1"
REDEF CURRENT_WATER_WILDMONS_LABEL EQUS "._def_water_wildmons_\1"
{CURRENT_WATER_WILDMONS_LABEL}:
map_id \1
ENDM
MACRO end_water_wildmons
assert WATER_WILDDATA_LENGTH == @ - {CURRENT_WATER_WILDMONS_LABEL}, \
"def_water_wildmons {CURRENT_WATER_WILDMONS_MAP}: expected {d:WATER_WILDDATA_LENGTH} bytes"
ENDM

96
macros/code.asm Normal file
View file

@ -0,0 +1,96 @@
; Syntactic sugar macros
MACRO lb ; r, hi, lo
ld \1, ((\2) & $ff) << 8 | ((\3) & $ff)
ENDM
MACRO ln ; r, hi, lo
ld \1, ((\2) & $f) << 4 | ((\3) & $f)
ENDM
; Design patterns
MACRO jumptable
ld a, [\2]
ld e, a
ld d, 0
ld hl, \1
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
ENDM
MACRO maskbits
; masks just enough bits to cover values 0 to \1 - 1
; \2 is an optional shift amount
; e.g. "maskbits 26" becomes "and %00011111" (since 26 - 1 = %00011001)
; and "maskbits 3, 2" becomes "and %00001100" (since "maskbits 3" becomes %00000011)
; example usage in rejection sampling:
; .loop
; call Random
; maskbits 26
; cp 26
; jr nc, .loop
assert 0 < (\1) && (\1) <= $100, "bitmask must be 8-bit"
DEF x = 1
rept 8
if x + 1 < (\1)
DEF x = (x << 1) | 1
endc
endr
if _NARG == 2
and x << (\2)
else
and x
endc
ENDM
MACRO calc_sine_wave
; input: a = a signed 6-bit value
; output: a = d * sin(a * pi/32)
and %111111
cp %100000
jr nc, .negative\@
call .apply\@
ld a, h
ret
.negative\@
and %011111
call .apply\@
ld a, h
xor $ff
inc a
ret
.apply\@
ld e, a
ld a, d
ld d, 0
if _NARG == 1
ld hl, \1
else
ld hl, .sinetable\@
endc
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ld hl, 0
.multiply\@ ; factor amplitude
srl a
jr nc, .even\@
add hl, de
.even\@
sla e
rl d
and a
jr nz, .multiply\@
ret
if _NARG == 0
.sinetable\@
sine_table 32
endc
ENDM

48
macros/const.asm Normal file
View file

@ -0,0 +1,48 @@
; Enumerate constants
MACRO const_def
if _NARG >= 1
DEF const_value = \1
else
DEF const_value = 0
endc
if _NARG >= 2
DEF const_inc = \2
else
DEF const_inc = 1
endc
ENDM
MACRO const
DEF \1 EQU const_value
DEF const_value += const_inc
ENDM
MACRO shift_const
DEF \1 EQU 1 << const_value
DEF const_value += const_inc
ENDM
MACRO const_skip
if _NARG >= 1
DEF const_value += const_inc * (\1)
else
DEF const_value += const_inc
endc
ENDM
MACRO const_next
if (const_value > 0 && \1 < const_value) || (const_value < 0 && \1 > const_value)
fail "const_next cannot go backwards from {const_value} to \1"
else
DEF const_value = \1
endc
ENDM
MACRO rb_skip
if _NARG == 1
rsset _RS + \1
else
rsset _RS + 1
endc
ENDM

59
macros/coords.asm Normal file
View file

@ -0,0 +1,59 @@
; Coordinate macros
DEF hlcoord EQUS "coord hl,"
DEF bccoord EQUS "coord bc,"
DEF decoord EQUS "coord de,"
MACRO coord
; register, x, y[, origin]
if _NARG < 4
ld \1, (\3) * SCREEN_WIDTH + (\2) + wTilemap
else
ld \1, (\3) * SCREEN_WIDTH + (\2) + \4
endc
ENDM
DEF hlbgcoord EQUS "bgcoord hl,"
DEF bcbgcoord EQUS "bgcoord bc,"
DEF debgcoord EQUS "bgcoord de,"
MACRO bgcoord
; register, x, y[, origin]
if _NARG < 4
ld \1, (\3) * BG_MAP_WIDTH + (\2) + vBGMap0
else
ld \1, (\3) * BG_MAP_WIDTH + (\2) + \4
endc
ENDM
MACRO dwcoord
; x, y
rept _NARG / 2
dw (\2) * SCREEN_WIDTH + (\1) + wTilemap
shift 2
endr
ENDM
MACRO ldcoord_a
; x, y[, origin]
if _NARG < 3
ld [(\2) * SCREEN_WIDTH + (\1) + wTilemap], a
else
ld [(\2) * SCREEN_WIDTH + (\1) + \3], a
endc
ENDM
MACRO lda_coord
; x, y[, origin]
if _NARG < 3
ld a, [(\2) * SCREEN_WIDTH + (\1) + wTilemap]
else
ld a, [(\2) * SCREEN_WIDTH + (\1) + \3]
endc
ENDM
MACRO menu_coords
; x1, y1, x2, y2
db \2, \1 ; start coords
db \4, \3 ; end coords
ENDM

114
macros/data.asm Normal file
View file

@ -0,0 +1,114 @@
; Value macros
; Many arbitrary percentages are simple base-10 or base-16 values:
; - 10 = 4 percent
; - 15 = 6 percent
; - $10 = 6 percent + 1 = 7 percent - 1
; - 20 = 8 percent
; - 25 = 10 percent
; - 30 = 12 percent
; - 40 = 16 percent
; - 50 = 20 percent - 1
; - 60 = 24 percent - 1
; - 70 = 28 percent - 1
; - 80 = 31 percent + 1 = 32 percent - 1
; - 85 = 33 percent + 1 = 34 percent - 1
; - 100 = 39 percent + 1 = 40 percent - 2
; - 120 = 47 percent + 1
; - 123 = 49 percent - 1
; - 160 = 63 percent
; - 180 = 71 percent - 1 = 70 percent + 2
; - 200 = 79 percent - 1
; - 230 = 90 percent + 1
DEF percent EQUS "* $ff / 100"
; e.g. 1 out_of 2 == 50 percent + 1 == $80
DEF out_of EQUS "* $100 /"
MACRO assert_power_of_2
assert (\1) & ((\1) - 1) == 0, "\1 must be a power of 2"
ENDM
; Constant data (db, dw, dl) macros
MACRO dwb
dw \1
db \2
ENDM
MACRO dbw
db \1
dw \2
ENDM
MACRO dbbbw
db \1, \2, \3
dw \4
ENDM
MACRO dbwbb
db \1
dw \2
db \3, \4
ENDM
MACRO dbwbw
db \1
dw \2
db \3
dw \4
ENDM
MACRO dn ; nybbles
rept _NARG / 2
db ((\1) << 4) | (\2)
shift 2
endr
ENDM
MACRO dc ; "crumbs"
rept _NARG / 4
db ((\1) << 6) | ((\2) << 4) | ((\3) << 2) | (\4)
shift 4
endr
ENDM
MACRO dt ; three-byte (big-endian)
db LOW((\1) >> 16), HIGH(\1), LOW(\1)
ENDM
MACRO dd ; four-byte (big-endian)
db HIGH((\1) >> 16), LOW((\1) >> 16), HIGH(\1), LOW(\1)
ENDM
MACRO bigdw ; big-endian word
db HIGH(\1), LOW(\1)
ENDM
MACRO dba ; dbw bank, address
rept _NARG
dbw BANK(\1), \1
shift
endr
ENDM
MACRO dab ; dwb address, bank
rept _NARG
dwb \1, BANK(\1)
shift
endr
ENDM
MACRO bcd
rept _NARG
dn ((\1) % 100) / 10, (\1) % 10
shift
endr
ENDM
MACRO sine_table
; \1 samples of sin(x) from x=0 to x<0.5 turns (pi radians)
for x, \1
dw sin(x * 0.5 / (\1))
endr
ENDM

23
macros/farcall.asm Normal file
View file

@ -0,0 +1,23 @@
; Far calls to another bank
MACRO farcall ; bank, address
ld a, BANK(\1)
ld hl, \1
rst FarCall
ENDM
MACRO callfar ; address, bank
ld hl, \1
ld a, BANK(\1)
rst FarCall
ENDM
MACRO homecall
ldh a, [hROMBank]
push af
ld a, BANK(\1)
rst Bankswitch
call \1
pop af
rst Bankswitch
ENDM

60
macros/gfx.asm Normal file
View file

@ -0,0 +1,60 @@
; Graphics macros
MACRO assert_valid_rgb
rept _NARG
assert 0 <= (\1) && (\1) <= 31, "RGB channel must be 0-31"
shift
endr
ENDM
MACRO RGB
rept _NARG / 3
assert_valid_rgb \1, \2, \3
dw palred (\1) + palgreen (\2) + palblue (\3)
shift 3
endr
ENDM
DEF palred EQUS "(1 << 0) *"
DEF palgreen EQUS "(1 << 5) *"
DEF palblue EQUS "(1 << 10) *"
DEF palettes EQUS "* PALETTE_SIZE"
DEF palette EQUS "+ PALETTE_SIZE *"
DEF color EQUS "+ PAL_COLOR_SIZE *"
DEF tiles EQUS "* LEN_2BPP_TILE"
DEF tile EQUS "+ LEN_2BPP_TILE *"
; extracts the middle two colors from a 2bpp binary palette
; example usage:
; INCBIN "foo.gbcpal", middle_colors
DEF middle_colors EQUS "PAL_COLOR_SIZE, PAL_COLOR_SIZE * 2"
MACRO dbpixel
if _NARG >= 4
; x tile, y tile, x pixel, y pixel
db \1 * TILE_WIDTH + \3, \2 * TILE_WIDTH + \4
else
; x tile, y tile
db \1 * TILE_WIDTH, \2 * TILE_WIDTH
endc
ENDM
MACRO ldpixel
if _NARG >= 5
; register, x tile, y tile, x pixel, y pixel
lb \1, \2 * TILE_WIDTH + \4, \3 * TILE_WIDTH + \5
else
; register, x tile, y tile
lb \1, \2 * TILE_WIDTH, \3 * TILE_WIDTH
endc
ENDM
DEF depixel EQUS "ldpixel de,"
DEF bcpixel EQUS "ldpixel bc,"
MACRO dbsprite
; x tile, y tile, x pixel, y pixel, vtile offset, attributes
db (\2 * TILE_WIDTH) % $100 + \4, (\1 * TILE_WIDTH) % $100 + \3, \5, \6
ENDM

76
macros/indirection.asm Normal file
View file

@ -0,0 +1,76 @@
DEF ___current_indirect_size = 0
; usage:
; Table:
; indirect_table <entry size>, <start index> (0-1)
; indirect_entries <max index>, <optional far label>
; (repeat as many times as necessary)
; indirect_table_end
MACRO indirect_table
; arguments: entry size, initial index (0 or 1)
assert ((\2) * (\2)) == (\2), \
"indirect table error: invalid initial index (must be 0 or 1)"
assert !___current_indirect_size, \
"indirect table error: there's already an active indirect table"
assert (\1) > 0, \
"indirect table error: the entry size must be positive"
assert (\1) <= $7FFF, \
"indirect table error: entry size is set to an invalid value"
DEF ___current_indirect_index = \2
DEF ___current_indirect_size = \1
dw (\1) | ((\2) << 15)
ENDM
MACRO indirect_entries
; arguments: next max index, far label (omit for zero/no data), far bank (if different from label)
assert ___current_indirect_size != 0, \
"indirect table error: there's no active indirect table"
assert (\1) >= ___current_indirect_index, \
"indirect table error: attempted to move backwards"
DEF ___current_indirect_count = (\1) + 1 - ___current_indirect_index
DEF ___current_indirect_index = (\1) + 1
DEF ___current_indirect_iteration_limit = ___current_indirect_count / $FF
DEF ___current_indirect_count = ___current_indirect_count % $FF
DEF ___current_indirect_count_total = ((___current_indirect_iteration_limit * $FF) + ___current_indirect_count)
if _NARG > 1
assert (\2.IndirectEnd - \2) == ___current_indirect_size * ___current_indirect_count_total, \
"\2: expected {d:___current_indirect_count_total} entries, each {d:___current_indirect_size} bytes"
endc
if ___current_indirect_iteration_limit
FOR ___current_indirect_iteration, ___current_indirect_iteration_limit
db $FF
if _NARG == 1
db 0, 0, 0
else
if _NARG == 2
db BANK(\2)
else
db \3
endc
dw (\2) + $FF * ___current_indirect_size * ___current_indirect_iteration
endc
endr
endc
if ___current_indirect_count
db ___current_indirect_count
if _NARG == 1
db 0, 0, 0
else
if _NARG == 2
db BANK(\2)
else
db \3
endc
dw (\2) + $FF * ___current_indirect_size * ___current_indirect_iteration_limit
endc
endc
ENDM
MACRO indirect_table_end
; no arguments
assert ___current_indirect_size != 0, \
"indirect table error: there's no active indirect table"
db 0
DEF ___current_indirect_size = 0
ENDM

407
macros/legacy.asm Normal file
View file

@ -0,0 +1,407 @@
; Legacy support for old pokecrystal.
; Allows porting scripts with as few edits as possible.
; Legacy support not in this file can be found by looking for the keyword: "LEGACY"
; macros/farcall.asm
DEF callba EQUS "farcall"
DEF callab EQUS "callfar"
; macros/gfx.asm
MACRO dsprite
dbsprite \3, \1, \4, \2, \5, \6
ENDM
; macros/data.asm
MACRO dbbw
db \1, \2
dw \3
ENDM
MACRO dbww
db \1
dw \2, \3
ENDM
MACRO dbwww
db \1
dw \2, \3, \4
ENDM
; macros/scripts/audio.asm
DEF __ EQU 0
DEF CC EQU 13
MACRO musicheader
channel_count \1
channel \2, \3
ENDM
MACRO sound
note \1, \2
db \3
dw \4
ENDM
MACRO noise
note \1, \2
db \3
db \4
ENDM
MACRO notetype
if _NARG >= 2
note_type \1, \2 >> 4, \2 & $0f
else
note_type \1
endc
ENDM
MACRO pitchoffset
transpose \1, \2 - 1
ENDM
DEF dutycycle EQUS "duty_cycle"
MACRO intensity
volume_envelope \1 >> 4, \1 & $0f
ENDM
MACRO soundinput
pitch_sweep \1 >> 4, \1 & $0f
ENDM
DEF unknownmusic0xde EQUS "sound_duty"
MACRO sound_duty
db duty_cycle_pattern_cmd
if _NARG == 4
db \1 | (\2 << 2) | (\3 << 4) | (\4 << 6)
else
db \1
endc
ENDM
DEF togglesfx EQUS "toggle_sfx"
MACRO slidepitchto
pitch_slide \1, (8 - \2), \3
ENDM
DEF togglenoise EQUS "toggle_noise"
MACRO panning
force_stereo_panning ((\1 >> 4) & 1), (\1 & 1)
ENDM
DEF tone EQUS "pitch_offset"
DEF restartchannel EQUS "restart_channel"
DEF newsong EQUS "new_song"
DEF sfxpriorityon EQUS "sfx_priority_on"
DEF sfxpriorityoff EQUS "sfx_priority_off"
MACRO stereopanning
stereo_panning ((\1 >> 4) & 1), (\1 & 1)
ENDM
DEF sfxtogglenoise EQUS "sfx_toggle_noise"
DEF setcondition EQUS "set_condition"
DEF jumpif EQUS "sound_jump_if"
DEF jumpchannel EQUS "sound_jump"
DEF loopchannel EQUS "sound_loop"
DEF callchannel EQUS "sound_call"
DEF endchannel EQUS "sound_ret"
; macros/scripts/events.asm
DEF checkmorn EQUS "checktime MORN"
DEF checkday EQUS "checktime DAY"
DEF checknite EQUS "checktime NITE"
DEF jump EQUS "sjump"
DEF farjump EQUS "farsjump"
DEF priorityjump EQUS "sdefer"
DEF prioritysjump EQUS "sdefer"
DEF ptcall EQUS "memcall"
DEF ptjump EQUS "memjump"
DEF ptpriorityjump EQUS "stopandsjump"
DEF ptcallasm EQUS "memcallasm"
DEF if_equal EQUS "ifequal"
DEF if_not_equal EQUS "ifnotequal"
DEF if_greater_than EQUS "ifgreater"
DEF if_less_than EQUS "ifless"
DEF end_all EQUS "endall"
DEF return EQUS "endcallback"
DEF reloadandreturn EQUS "reloadend"
DEF checkmaptriggers EQUS "checkmapscene"
DEF domaptrigger EQUS "setmapscene"
DEF checktriggers EQUS "checkscene"
DEF dotrigger EQUS "setscene"
DEF faceperson EQUS "faceobject"
DEF moveperson EQUS "moveobject"
DEF writepersonxy EQUS "writeobjectxy"
DEF spriteface EQUS "turnobject"
DEF objectface EQUS "turnobject"
DEF applymovement2 EQUS "applymovementlasttalked"
DEF writebyte EQUS "setval"
DEF addvar EQUS "addval"
DEF copybytetovar EQUS "readmem"
DEF copyvartobyte EQUS "writemem"
DEF checkcode EQUS "readvar"
DEF writevarcode EQUS "writevar"
DEF writecode EQUS "loadvar"
DEF MEM_BUFFER_0 EQUS "STRING_BUFFER_3"
DEF MEM_BUFFER_1 EQUS "STRING_BUFFER_4"
DEF MEM_BUFFER_2 EQUS "STRING_BUFFER_5"
DEF vartomem EQUS "getnum"
DEF mapnametotext EQUS "getcurlandmarkname"
DEF readcoins EQUS "getcoins"
MACRO pokenamemem
getmonname \2, \1
ENDM
MACRO itemtotext
getitemname \2, \1
ENDM
MACRO landmarktotext
getlandmarkname \2, \1
ENDM
MACRO trainertotext
gettrainername \3, \1, \2
ENDM
MACRO trainerclassname
gettrainerclassname \2, \1
ENDM
MACRO name
getname \3, \1, \2
ENDM
MACRO stringtotext
getstring \2, \1
ENDM
MACRO readmoney
getmoney \2, \1
ENDM
DEF RAM2MEM EQUS "getnum"
DEF loadfont EQUS "opentext"
DEF loadmenudata EQUS "loadmenu"
DEF loadmenuheader EQUS "loadmenu"
DEF writebackup EQUS "closewindow"
DEF interpretmenu EQUS "_2dmenu"
DEF interpretmenu2 EQUS "verticalmenu"
DEF buttonsound EQUS "promptbutton"
DEF battlecheck EQUS "randomwildmon"
DEF loadtrainerdata EQUS "loadtemptrainer"
DEF loadpokedata EQUS "loadwildmon"
DEF returnafterbattle EQUS "reloadmapafterbattle"
DEF trainerstatus EQUS "trainerflagaction"
DEF talkaftercancel EQUS "endifjustbattled"
DEF talkaftercheck EQUS "checkjustbattled"
DEF playrammusic EQUS "encountermusic"
DEF reloadmapmusic EQUS "dontrestartmapmusic"
DEF resetfuncs EQUS "endall"
DEF storetext EQUS "battletowertext"
DEF displaylocation EQUS "landmarktotext"
DEF givepokeitem EQUS "givepokemail"
DEF checkpokeitem EQUS "checkpokemail"
DEF passtoengine EQUS "autoinput"
DEF verbosegiveitem2 EQUS "verbosegiveitemvar"
DEF loadbytec2cf EQUS "writeunusedbyte"
DEF writeunusedbytebuffer EQUS "writeunusedbyte"
; macros/scripts/maps.asm
MACRO mapconst
map_const \1, \3, \2
ENDM
DEF maptrigger EQUS "scene_script"
MACRO warp_def
warp_event \2, \1, \4, \3
ENDM
MACRO xy_trigger
coord_event \3, \2, \1, \5
ENDM
MACRO signpost
bg_event \2, \1, \3, \4
ENDM
MACRO person_event
object_event \3, \2, \1, \4, \5, \6, \7, \8, \9, \<10>, \<11>, \<12>, \<13>
ENDM
DEF PERSONTYPE_SCRIPT EQUS "OBJECTTYPE_SCRIPT"
DEF PERSONTYPE_ITEMBALL EQUS "OBJECTTYPE_ITEMBALL"
DEF PERSONTYPE_TRAINER EQUS "OBJECTTYPE_TRAINER"
DEF SCENE_DEFAULT EQU 0
DEF SCENE_FINISHED EQU 1
; macros/scripts/movement.asm
DEF show_person EQUS "show_object"
DEF hide_person EQUS "hide_object"
DEF remove_person EQUS "remove_object"
DEF turn_head_down EQUS "turn_head DOWN"
DEF turn_head_up EQUS "turn_head UP"
DEF turn_head_left EQUS "turn_head LEFT"
DEF turn_head_right EQUS "turn_head RIGHT"
DEF turn_step_down EQUS "turn_step DOWN"
DEF turn_step_up EQUS "turn_step UP"
DEF turn_step_left EQUS "turn_step LEFT"
DEF turn_step_right EQUS "turn_step RIGHT"
DEF slow_step_down EQUS "slow_step DOWN"
DEF slow_step_up EQUS "slow_step UP"
DEF slow_step_left EQUS "slow_step LEFT"
DEF slow_step_right EQUS "slow_step RIGHT"
DEF step_down EQUS "step DOWN"
DEF step_up EQUS "step UP"
DEF step_left EQUS "step LEFT"
DEF step_right EQUS "step RIGHT"
DEF big_step_down EQUS "big_step DOWN"
DEF big_step_up EQUS "big_step UP"
DEF big_step_left EQUS "big_step LEFT"
DEF big_step_right EQUS "big_step RIGHT"
DEF slow_slide_step_down EQUS "slow_slide_step DOWN"
DEF slow_slide_step_up EQUS "slow_slide_step UP"
DEF slow_slide_step_left EQUS "slow_slide_step LEFT"
DEF slow_slide_step_right EQUS "slow_slide_step RIGHT"
DEF slide_step_down EQUS "slide_step DOWN"
DEF slide_step_up EQUS "slide_step UP"
DEF slide_step_left EQUS "slide_step LEFT"
DEF slide_step_right EQUS "slide_step RIGHT"
DEF fast_slide_step_down EQUS "fast_slide_step DOWN"
DEF fast_slide_step_up EQUS "fast_slide_step UP"
DEF fast_slide_step_left EQUS "fast_slide_step LEFT"
DEF fast_slide_step_right EQUS "fast_slide_step RIGHT"
DEF turn_away_down EQUS "turn_away DOWN"
DEF turn_away_up EQUS "turn_away UP"
DEF turn_away_left EQUS "turn_away LEFT"
DEF turn_away_right EQUS "turn_away RIGHT"
DEF turn_in_down EQUS "turn_in DOWN"
DEF turn_in_up EQUS "turn_in UP"
DEF turn_in_left EQUS "turn_in LEFT"
DEF turn_in_right EQUS "turn_in RIGHT"
DEF turn_waterfall_down EQUS "turn_waterfall DOWN"
DEF turn_waterfall_up EQUS "turn_waterfall UP"
DEF turn_waterfall_left EQUS "turn_waterfall LEFT"
DEF turn_waterfall_right EQUS "turn_waterfall RIGHT"
DEF slow_jump_step_down EQUS "slow_jump_step DOWN"
DEF slow_jump_step_up EQUS "slow_jump_step UP"
DEF slow_jump_step_left EQUS "slow_jump_step LEFT"
DEF slow_jump_step_right EQUS "slow_jump_step RIGHT"
DEF jump_step_down EQUS "jump_step DOWN"
DEF jump_step_up EQUS "jump_step UP"
DEF jump_step_left EQUS "jump_step LEFT"
DEF jump_step_right EQUS "jump_step RIGHT"
DEF fast_jump_step_down EQUS "fast_jump_step DOWN"
DEF fast_jump_step_up EQUS "fast_jump_step UP"
DEF fast_jump_step_left EQUS "fast_jump_step LEFT"
DEF fast_jump_step_right EQUS "fast_jump_step RIGHT"
DEF step_sleep_1 EQUS "step_sleep 1"
DEF step_sleep_2 EQUS "step_sleep 2"
DEF step_sleep_3 EQUS "step_sleep 3"
DEF step_sleep_4 EQUS "step_sleep 4"
DEF step_sleep_5 EQUS "step_sleep 5"
DEF step_sleep_6 EQUS "step_sleep 6"
DEF step_sleep_7 EQUS "step_sleep 7"
DEF step_sleep_8 EQUS "step_sleep 8"
; macros/scripts/text.asm
DEF text_from_ram EQUS "text_ram"
DEF start_asm EQUS "text_asm"
DEF deciram EQUS "text_decimal"
DEF interpret_data EQUS "text_pause"
DEF limited_interpret_data EQUS "text_dots"
DEF link_wait_button EQUS "text_waitbutton"
DEF text_linkwaitbutton EQUS "text_waitbutton"
DEF text_linkpromptbutton EQUS "text_waitbutton"
DEF current_day EQUS "text_today"
DEF text_jump EQUS "text_far"
; macros/scripts/battle_anims.asm
DEF anim_enemyfeetobj EQUS "anim_battlergfx_2row"
DEF anim_playerheadobj EQUS "anim_battlergfx_1row"
DEF anim_clearsprites EQUS "anim_keepsprites"
; macros/scripts/oam_anims.asm
DEF dorestart EQUS "oamrestart"
DEF dowait EQUS "oamwait"
DEF delanim EQUS "oamdel"
; engine/events/std_scripts.asm
DEF pokecenternurse EQUS "PokecenterNurseScript"
DEF difficultbookshelf EQUS "DifficultBookshelfScript"
DEF picturebookshelf EQUS "PictureBookshelfScript"
DEF magazinebookshelf EQUS "MagazineBookshelfScript"
DEF teamrocketoath EQUS "TeamRocketOathScript"
DEF incenseburner EQUS "IncenseBurnerScript"
DEF merchandiseshelf EQUS "MerchandiseShelfScript"
DEF townmap EQUS "TownMapScript"
DEF window EQUS "WindowScript"
DEF tv EQUS "TVScript"
DEF homepage EQUS "HomepageScript"
DEF radio1 EQUS "Radio1Script"
DEF radio2 EQUS "Radio2Script"
DEF trashcan EQUS "TrashCanScript"
DEF strengthboulder EQUS "StrengthBoulderScript"
DEF smashrock EQUS "SmashRockScript"
DEF pokecentersign EQUS "PokecenterSignScript"
DEF martsign EQUS "MartSignScript"
DEF goldenrodrockets EQUS "GoldenrodRocketsScript"
DEF radiotowerrockets EQUS "RadioTowerRocketsScript"
DEF elevatorbutton EQUS "ElevatorButtonScript"
DEF daytotext EQUS "DayToTextScript"
DEF bugcontestresultswarp EQUS "BugContestResultsWarpScript"
DEF bugcontestresults EQUS "BugContestResultsScript"
DEF initializeevents EQUS "InitializeEventsScript"
DEF asknumber1m EQUS "AskNumber1MScript"
DEF asknumber2m EQUS "AskNumber2MScript"
DEF registerednumberm EQUS "RegisteredNumberMScript"
DEF numberacceptedm EQUS "NumberAcceptedMScript"
DEF numberdeclinedm EQUS "NumberDeclinedMScript"
DEF phonefullm EQUS "PhoneFullMScript"
DEF rematchm EQUS "RematchMScript"
DEF giftm EQUS "GiftMScript"
DEF packfullm EQUS "PackFullMScript"
DEF rematchgiftm EQUS "RematchGiftMScript"
DEF asknumber1f EQUS "AskNumber1FScript"
DEF asknumber2f EQUS "AskNumber2FScript"
DEF registerednumberf EQUS "RegisteredNumberFScript"
DEF numberacceptedf EQUS "NumberAcceptedFScript"
DEF numberdeclinedf EQUS "NumberDeclinedFScript"
DEF phonefullf EQUS "PhoneFullFScript"
DEF rematchf EQUS "RematchFScript"
DEF giftf EQUS "GiftFScript"
DEF packfullf EQUS "PackFullFScript"
DEF rematchgiftf EQUS "RematchGiftFScript"
DEF gymstatue1 EQUS "GymStatue1Script"
DEF gymstatue2 EQUS "GymStatue2Script"
DEF receiveitem EQUS "ReceiveItemScript"
DEF receivetogepiegg EQUS "ReceiveTogepiEggScript"
DEF pcscript EQUS "PCScript"
DEF gamecornercoinvendor EQUS "GameCornerCoinVendorScript"
DEF happinesschecknpc EQUS "HappinessCheckScript"
; constants/sprite_constants.asm
DEF SPRITE_BUENA EQUS "SPRITE_BEAUTY"
DEF PAL_NPC_SILVER EQUS "PAL_NPC_EMOTE"
DEF PAL_OW_SILVER EQUS "PAL_OW_EMOTE"

19
macros/lists.asm Normal file
View file

@ -0,0 +1,19 @@
MACRO list_item
.__item\1
if (_NARG > 1)
db .__item\2 - .__item\1
endc
ENDM
DEF current_list_item = 0
MACRO next_list_item
DEF next_list_item_index = current_list_item + 1
list_item {d:current_list_item}, {d:next_list_item_index}
DEF current_list_item = next_list_item_index
ENDM
MACRO end_list_items
list_item {d:current_list_item}
DEF current_list_item = 0
ENDM

17
macros/predef.asm Normal file
View file

@ -0,0 +1,17 @@
; Predef function calls
MACRO lda_predef
; Some functions load the predef id
; without immediately calling Predef.
ld a, (\1Predef - PredefPointers) / 3
ENDM
MACRO predef
lda_predef \1
call Predef
ENDM
MACRO predef_jump
lda_predef \1
jp Predef
ENDM

408
macros/ram.asm Normal file
View file

@ -0,0 +1,408 @@
; Structures in RAM
MACRO flag_array
ds ((\1) + 7) / 8
ENDM
MACRO box_struct
\1Species:: db
\1Item:: db
\1Moves:: ds NUM_MOVES
\1ID:: dw
\1Exp:: ds 3
\1StatExp::
\1HPExp:: dw
\1AtkExp:: dw
\1DefExp:: dw
\1SpdExp:: dw
\1SpcExp:: dw
\1DVs:: dw
\1PP:: ds NUM_MOVES
\1Happiness:: db
\1PokerusStatus:: db
\1CaughtData::
\1CaughtTime::
\1CaughtLevel:: db
\1CaughtGender::
\1CaughtLocation:: db
\1Level:: db
\1BoxEnd::
ENDM
MACRO party_struct
box_struct \1
\1Status:: db
\1Unused:: db
\1HP:: dw
\1MaxHP:: dw
\1Stats:: ; big endian
\1Attack:: dw
\1Defense:: dw
\1Speed:: dw
\1SpclAtk:: dw
\1SpclDef:: dw
\1StructEnd::
ENDM
MACRO red_box_struct
\1Species:: db
\1HP:: dw
\1BoxLevel:: db
\1Status:: db
\1Type::
\1Type1:: db
\1Type2:: db
\1CatchRate:: db
\1Moves:: ds NUM_MOVES
\1ID:: dw
\1Exp:: ds 3
\1HPExp:: dw
\1AttackExp:: dw
\1DefenseExp:: dw
\1SpeedExp:: dw
\1SpecialExp:: dw
\1DVs:: dw
\1PP:: ds NUM_MOVES
ENDM
MACRO red_party_struct
red_box_struct \1
\1Level:: db
\1Stats::
\1MaxHP:: dw
\1Attack:: dw
\1Defense:: dw
\1Speed:: dw
\1Special:: dw
ENDM
MACRO battle_struct
\1Species:: db
\1Item:: db
\1Moves:: ds NUM_MOVES
\1DVs:: dw
\1PP:: ds NUM_MOVES
\1Happiness:: db
\1Level:: db
\1Status:: ds 2
\1HP:: dw
\1MaxHP:: dw
\1Stats:: ; big endian
\1Attack:: dw
\1Defense:: dw
\1Speed:: dw
\1SpclAtk:: dw
\1SpclDef:: dw
\1Type::
\1Type1:: db
\1Type2:: db
\1StructEnd::
ENDM
MACRO box
\1Count:: db
\1Species:: ds MONS_PER_BOX + 1
\1Mons::
; \1Mon1 - \1Mon20
for n, 1, MONS_PER_BOX + 1
\1Mon{d:n}:: box_struct \1Mon{d:n}
endr
\1MonOTs::
; \1Mon1OT - \1Mon20OT
for n, 1, MONS_PER_BOX + 1
\1Mon{d:n}OT:: ds NAME_LENGTH
endr
\1MonNicknames::
; \1Mon1Nickname - \1Mon20Nickname
for n, 1, MONS_PER_BOX + 1
\1Mon{d:n}Nickname:: ds MON_NAME_LENGTH
endr
\1MonNicknamesEnd::
\1End::
ds 2 ; padding
ENDM
MACRO map_connection_struct
\1ConnectedMapGroup:: db
\1ConnectedMapNumber:: db
\1ConnectionStripPointer:: dw
\1ConnectionStripLocation:: dw
\1ConnectionStripLength:: db
\1ConnectedMapWidth:: db
\1ConnectionStripYOffset:: db
\1ConnectionStripXOffset:: db
\1ConnectionWindow:: dw
ENDM
MACRO channel_struct
\1MusicID:: dw
\1MusicBank:: db
\1Flags1:: db ; 0:on/off 1:subroutine 2:looping 3:sfx 4:noise 5:rest
\1Flags2:: db ; 0:vibrato on/off 1:pitch slide 2:duty cycle pattern 4:pitch offset
\1Flags3:: db ; 0:vibrato up/down 1:pitch slide direction
\1MusicAddress:: dw
\1LastMusicAddress:: dw
dw
\1NoteFlags:: db ; 5:rest
\1Condition:: db ; conditional jumps
\1DutyCycle:: db ; bits 6-7 (0:12.5% 1:25% 2:50% 3:75%)
\1VolumeEnvelope:: db ; hi:volume lo:fade
\1Frequency:: dw ; 11 bits
\1Pitch:: db ; 0:rest 1-c:note
\1Octave:: db ; 7-0 (0 is highest)
\1Transposition:: db ; raises existing octaves (to repeat phrases)
\1NoteDuration:: db ; frames remaining for the current note
\1Field16:: ds 1
ds 1
\1LoopCount:: db
\1Tempo:: dw
\1Tracks:: db ; hi:left lo:right
\1DutyCyclePattern:: db
\1VibratoDelayCount:: db ; initialized by \1VibratoDelay
\1VibratoDelay:: db ; number of frames a note plays until vibrato starts
\1VibratoExtent:: db
\1VibratoRate:: db ; hi:frames for each alt lo:frames to the next alt
\1PitchSlideTarget:: dw ; frequency endpoint for pitch slide
\1PitchSlideAmount:: db
\1PitchSlideAmountFraction:: db
\1Field25:: db
ds 1
\1PitchOffset:: dw
\1Field29:: ds 1
\1Field2a:: ds 2
\1Field2c:: ds 1
\1NoteLength:: db ; frames per 16th note
\1Field2e:: ds 1
\1Field2f:: ds 1
\1Field30:: ds 1
ds 1
ENDM
MACRO battle_tower_struct
\1Name:: ds NAME_LENGTH - 1
\1TrainerClass:: db
; \1Mon1 - \1Mon3 and \1Mon1Name - \1Mon3Name
for n, 1, BATTLETOWER_PARTY_LENGTH + 1
\1Mon{d:n}:: party_struct \1Mon{d:n}
\1Mon{d:n}Name:: ds MON_NAME_LENGTH
endr
\1TrainerData:: ds BATTLETOWER_TRAINERDATALENGTH
\1TrainerEnd::
ENDM
MACRO mailmsg
\1Message:: ds MAIL_MSG_LENGTH
\1MessageEnd:: db
\1Author:: ds PLAYER_NAME_LENGTH
\1Nationality:: dw
\1AuthorID:: dw
\1Species:: db
\1Type:: db
\1End::
ENDM
MACRO mailmsg_jp
\1Message:: ds MAIL_MSG_LENGTH
\1MessageEnd:: db
\1Author:: ds NAME_LENGTH_JAPANESE - 1
\1AuthorID:: dw
\1Species:: db
\1Type:: db
\1End::
ENDM
MACRO roam_struct
\1Species:: db
\1Level:: db
\1MapGroup:: db
\1MapNumber:: db
\1HP:: db
\1DVs:: dw
ENDM
MACRO bugcontestwinner
\1WinnerID:: db
\1Mon:: db
\1Score:: dw
ENDM
MACRO hof_mon
\1Species:: dw
\1ID:: dw
\1DVs:: dw
\1Level:: db
\1Nickname:: ds MON_NAME_LENGTH - 1
\1End::
ENDM
MACRO hall_of_fame
\1WinCount:: db
; \1Mon1 - \1Mon6
for n, 1, PARTY_LENGTH + 1
\1Mon{d:n}:: hof_mon \1Mon{d:n}
endr
\1End:: dw
ENDM
MACRO link_battle_record
\1ID:: dw
\1Name:: ds NAME_LENGTH - 1
\1Wins:: dw
\1Losses:: dw
\1Draws:: dw
\1End::
ENDM
MACRO trademon
\1Species:: db
\1SpeciesName:: ds MON_NAME_LENGTH
\1Nickname:: ds MON_NAME_LENGTH
\1SenderName:: ds NAME_LENGTH
\1OTName:: ds NAME_LENGTH
\1DVs:: dw
\1ID:: dw
\1CaughtData:: db
\1End::
ENDM
MACRO move_struct
\1Animation:: db
\1Effect:: db
\1Power:: db
\1Type:: db
\1Accuracy:: db
\1PP:: db
\1EffectChance:: db
ENDM
MACRO slot_reel
\1ReelAction:: db
\1TilemapAddr:: dw
\1Position:: db
\1SpinDistance:: db
\1SpinRate:: db
\1OAMAddr:: dw
\1XCoord:: db
\1ManipCounter:: db
\1ManipDelay:: db
\1Field0b:: ds 1
\1Field0c:: ds 1
\1Field0d:: ds 1
\1Field0e:: ds 1
\1StopDelay:: db
ENDM
MACRO object_struct
\1Sprite:: db
\1MapObjectIndex:: db
\1SpriteTile:: db
\1MovementType:: db
\1Flags:: dw
\1Palette:: db
\1Walking:: db
\1Direction:: db
\1StepType:: db
\1StepDuration:: db
\1Action:: db
\1StepFrame:: db
\1Facing:: db
\1Tile:: db
\1LastTile:: db
\1MapX:: db
\1MapY:: db
\1LastMapX:: db
\1LastMapY:: db
\1InitX:: db
\1InitY:: db
\1Radius:: db
\1SpriteX:: db
\1SpriteY:: db
\1SpriteXOffset:: db
\1SpriteYOffset:: db
\1MovementIndex:: db
\1StepIndex:: db
\1Field1d:: ds 1
\1Field1e:: ds 1
\1JumpHeight:: db
\1Range:: db
ds 7
\1StructEnd::
ENDM
MACRO map_object
\1ObjectStructID:: db
\1ObjectSprite:: db
\1ObjectYCoord:: db
\1ObjectXCoord:: db
\1ObjectMovement:: db
\1ObjectRadius:: db
\1ObjectHour1:: db
\1ObjectHour2::
\1ObjectTimeOfDay:: db
\1ObjectPalette::
\1ObjectType:: db
\1ObjectSightRange:: db
\1ObjectScript:: dw
\1ObjectEventFlag:: dw
ds 2
ENDM
MACRO sprite_oam_struct
\1YCoord:: db
\1XCoord:: db
\1TileID:: db
\1Attributes:: db
; bit 7: priority
; bit 6: y flip
; bit 5: x flip
; bit 4: pal # (non-cgb)
; bit 3: vram bank (cgb only)
; bit 2-0: pal # (cgb only)
ENDM
MACRO sprite_anim_struct
\1Index:: db
\1FramesetID:: db
\1AnimSeqID:: db
\1TileID:: db
\1XCoord:: db
\1YCoord:: db
\1XOffset:: db
\1YOffset:: db
\1Duration:: db
\1DurationOffset:: db
\1FrameIndex:: db
\1JumptableIndex:: db
\1Var1:: ds 1
\1Var2:: ds 1
\1Var3:: ds 1
\1Var4:: ds 1
ENDM
MACRO battle_anim_struct
\1Index:: db
\1OAMFlags:: db
\1FixY:: db
\1FramesetID:: db
\1Function:: db
\1Palette:: db
\1TileID:: db
\1XCoord:: db
\1YCoord:: db
\1XOffset:: db
\1YOffset:: db
\1Param:: db
\1Duration:: db
\1Frame:: db
\1JumptableIndex:: db
\1Var1:: db
\1Var2:: db
ds 7
ENDM
MACRO battle_bg_effect
\1Function:: db
\1JumptableIndex:: db
\1BattleTurn:: db
\1Param:: db
ENDM

320
macros/scripts/audio.asm Normal file
View file

@ -0,0 +1,320 @@
MACRO channel_count
assert 0 < (\1) && (\1) <= NUM_MUSIC_CHANS, \
"channel_count must be 1-{d:NUM_MUSIC_CHANS}"
DEF _num_channels = \1 - 1
ENDM
MACRO channel
assert 0 < (\1) && (\1) <= NUM_CHANNELS, \
"channel id must be 1-{d:NUM_CHANNELS}"
dn (_num_channels << 2), \1 - 1 ; channel id
dw \2 ; address
DEF _num_channels = 0
ENDM
MACRO note
dn (\1), (\2) - 1 ; pitch, length
ENDM
MACRO drum_note
note \1, \2 ; drum instrument, length
ENDM
MACRO rest
note 0, \1 ; length
ENDM
MACRO square_note
db \1 ; length
if \3 < 0
dn \2, %1000 | (\3 * -1) ; volume envelope
else
dn \2, \3 ; volume envelope
endc
dw \4 ; frequency
ENDM
MACRO noise_note
db \1 ; length
if \3 < 0
dn \2, %1000 | (\3 * -1) ; volume envelope
else
dn \2, \3 ; volume envelope
endc
db \4 ; frequency
ENDM
; MusicCommands indexes (see audio/engine.asm)
const_def $d0
DEF FIRST_MUSIC_CMD EQU const_value
const octave_cmd ; $d0
MACRO octave
assert 1 <= (\1) && (\1) <= 8, "octave must be 1-8"
db octave_cmd + 8 - (\1) ; octave
ENDM
const_skip 7 ; all octave values
const note_type_cmd ; $d8
MACRO note_type
db note_type_cmd
db \1 ; note length
if _NARG >= 2
if \3 < 0
dn \2, %1000 | (\3 * -1) ; volume envelope
else
dn \2, \3 ; volume envelope
endc
endc
ENDM
; only valid on the noise channel
MACRO drum_speed
note_type \1 ; note length
ENDM
const transpose_cmd ; $d9
MACRO transpose
db transpose_cmd
dn \1, \2 ; num octaves, num pitches
ENDM
const tempo_cmd ; $da
MACRO tempo
db tempo_cmd
bigdw \1 ; tempo
ENDM
const duty_cycle_cmd ; $db
MACRO duty_cycle
db duty_cycle_cmd
db \1 ; duty cycle
ENDM
const volume_envelope_cmd ; $dc
MACRO volume_envelope
db volume_envelope_cmd
if \2 < 0
dn \1, %1000 | (\2 * -1) ; volume envelope
else
dn \1, \2 ; volume envelope
endc
ENDM
const pitch_sweep_cmd ; $dd
MACRO pitch_sweep
db pitch_sweep_cmd
if \2 < 0
dn \1, %1000 | (\2 * -1) ; pitch sweep
else
dn \1, \2 ; pitch sweep
endc
ENDM
const duty_cycle_pattern_cmd ; $de
MACRO duty_cycle_pattern
db duty_cycle_pattern_cmd
db (\1 << 6) | (\2 << 4) | (\3 << 2) | (\4 << 0) ; duty cycle pattern
ENDM
const toggle_sfx_cmd ; $df
MACRO toggle_sfx
db toggle_sfx_cmd
ENDM
const pitch_slide_cmd ; $e0
MACRO pitch_slide
db pitch_slide_cmd
db \1 - 1 ; duration
dn 8 - \2, \3 % 12 ; octave, pitch
ENDM
const vibrato_cmd ; $e1
MACRO vibrato
db vibrato_cmd
db \1 ; delay
if _NARG > 2
dn \2, \3 ; extent, rate
else
db \2 ; LEGACY: Support for 1-arg extent
endc
ENDM
const unknownmusic0xe2_cmd ; $e2
MACRO unknownmusic0xe2
db unknownmusic0xe2_cmd
db \1 ; unknown
ENDM
const toggle_noise_cmd ; $e3
MACRO toggle_noise
db toggle_noise_cmd
if _NARG > 0
db \1 ; drum kit
endc
ENDM
const force_stereo_panning_cmd ; $e4
MACRO force_stereo_panning
db force_stereo_panning_cmd
dn %1111 * (1 && \1), %1111 * (1 && \2) ; left enable, right enable
ENDM
const volume_cmd ; $e5
MACRO volume
db volume_cmd
if _NARG > 1
dn \1, \2 ; left volume, right volume
else
db \1 ; LEGACY: Support for 1-arg volume
endc
ENDM
const pitch_offset_cmd ; $e6
MACRO pitch_offset
db pitch_offset_cmd
bigdw \1 ; pitch offset
ENDM
const unknownmusic0xe7_cmd ; $e7
MACRO unknownmusic0xe7
db unknownmusic0xe7_cmd
db \1 ; unknown
ENDM
const unknownmusic0xe8_cmd ; $e8
MACRO unknownmusic0xe8
db unknownmusic0xe8_cmd
db \1 ; unknown
ENDM
const tempo_relative_cmd ; $e9
MACRO tempo_relative
db tempo_relative_cmd
db \1 ; tempo adjustment
ENDM
const restart_channel_cmd ; $ea
MACRO restart_channel
db restart_channel_cmd
dw \1 ; address
ENDM
const new_song_cmd ; $eb
MACRO new_song
db new_song_cmd
dw \1 ; id
ENDM
const sfx_priority_on_cmd ; $ec
MACRO sfx_priority_on
db sfx_priority_on_cmd
ENDM
const sfx_priority_off_cmd ; $ed
MACRO sfx_priority_off
db sfx_priority_off_cmd
ENDM
const unknownmusic0xee_cmd ; $ee
MACRO unknownmusic0xee
db unknownmusic0xee_cmd
dw \1 ; address
ENDM
const stereo_panning_cmd ; $ef
MACRO stereo_panning
db stereo_panning_cmd
dn %1111 * (1 && \1), %1111 * (1 && \2) ; left enable, right enable
ENDM
const sfx_toggle_noise_cmd ; $f0
MACRO sfx_toggle_noise
db sfx_toggle_noise_cmd
if _NARG > 0
db \1 ; drum kit
endc
ENDM
const music0xf1_cmd ; $f1
MACRO music0xf1
db music0xf1_cmd
ENDM
const music0xf2_cmd ; $f2
MACRO music0xf2
db music0xf2_cmd
ENDM
const music0xf3_cmd ; $f3
MACRO music0xf3
db music0xf3_cmd
ENDM
const music0xf4_cmd ; $f4
MACRO music0xf4
db music0xf4_cmd
ENDM
const music0xf5_cmd ; $f5
MACRO music0xf5
db music0xf5_cmd
ENDM
const music0xf6_cmd ; $f6
MACRO music0xf6
db music0xf6_cmd
ENDM
const music0xf7_cmd ; $f7
MACRO music0xf7
db music0xf7_cmd
ENDM
const music0xf8_cmd ; $f8
MACRO music0xf8
db music0xf8_cmd
ENDM
const unknownmusic0xf9_cmd ; $f9
MACRO unknownmusic0xf9
db unknownmusic0xf9_cmd
ENDM
const set_condition_cmd ; $fa
MACRO set_condition
db set_condition_cmd
db \1 ; condition
ENDM
const sound_jump_if_cmd ; $fb
MACRO sound_jump_if
db sound_jump_if_cmd
db \1 ; condition
dw \2 ; address
ENDM
const sound_jump_cmd ; $fc
MACRO sound_jump
db sound_jump_cmd
dw \1 ; address
ENDM
const sound_loop_cmd ; $fd
MACRO sound_loop
db sound_loop_cmd
db \1 ; count
dw \2 ; address
ENDM
const sound_call_cmd ; $fe
MACRO sound_call
db sound_call_cmd
dw \1 ; address
ENDM
const sound_ret_cmd ; $ff
MACRO sound_ret
db sound_ret_cmd
ENDM

View file

@ -0,0 +1,301 @@
; BattleAnimCommands indexes (see engine/battle_anims/anim_commands.asm)
const_def $d0
DEF FIRST_BATTLE_ANIM_CMD EQU const_value
MACRO anim_wait
assert (\1) < FIRST_BATTLE_ANIM_CMD, "anim_wait argument must be less than {FIRST_BATTLE_ANIM_CMD}"
db \1
ENDM
const anim_obj_command ; $d0
MACRO anim_obj
db anim_obj_command
if _NARG <= 4
db \1 ; object
db \2 ; x
db \3 ; y
db \4 ; param
else
; LEGACY: Support the tile+offset format
db \1 ; object
db (\2) * 8 + (\3) ; x_tile, x
db (\4) * 8 + (\5) ; y_tile, y
db \6 ; param
endc
ENDM
const anim_1gfx_command ; $d1
MACRO anim_1gfx
db anim_1gfx_command
db \1 ; gfx1
ENDM
const anim_2gfx_command ; $d2
MACRO anim_2gfx
db anim_2gfx_command
db \1 ; gfx1
db \2 ; gfx2
ENDM
const anim_3gfx_command ; $d3
MACRO anim_3gfx
db anim_3gfx_command
db \1 ; gfx1
db \2 ; gfx2
db \3 ; gfx3
ENDM
const anim_4gfx_command ; $d4
MACRO anim_4gfx
db anim_4gfx_command
db \1 ; gfx1
db \2 ; gfx2
db \3 ; gfx3
db \4 ; gfx4
ENDM
const anim_5gfx_command ; $d5
MACRO anim_5gfx
db anim_5gfx_command
db \1 ; gfx1
db \2 ; gfx2
db \3 ; gfx3
db \4 ; gfx4
db \5 ; gfx5
ENDM
const anim_incobj_command ; $d6
MACRO anim_incobj
db anim_incobj_command
db \1 ; object_id
ENDM
const anim_setobj_command ; $d7
MACRO anim_setobj
db anim_setobj_command
db \1 ; object_id
db \2 ; value
ENDM
const anim_incbgeffect_command ; $d8
MACRO anim_incbgeffect
db anim_incbgeffect_command
db \1 ; effect
ENDM
const anim_battlergfx_2row_command ; $d9
MACRO anim_battlergfx_2row
db anim_battlergfx_2row_command
ENDM
const anim_battlergfx_1row_command ; $da
MACRO anim_battlergfx_1row
db anim_battlergfx_1row_command
ENDM
const anim_checkpokeball_command ; $db
MACRO anim_checkpokeball
db anim_checkpokeball_command
ENDM
const anim_transform_command ; $dc
MACRO anim_transform
db anim_transform_command
ENDM
const anim_raisesub_command ; $dd
MACRO anim_raisesub
db anim_raisesub_command
ENDM
const anim_dropsub_command ; $de
MACRO anim_dropsub
db anim_dropsub_command
ENDM
const anim_resetobp0_command ; $df
MACRO anim_resetobp0
db anim_resetobp0_command
ENDM
const anim_sound_command ; $e0
MACRO anim_sound
db anim_sound_command
db (\1 << 2) | \2 ; duration, tracks
db \3 ; sound_id
ENDM
const anim_cry_command ; $e1
MACRO anim_cry
db anim_cry_command
db \1 ; pitch
ENDM
const anim_minimizeopp_command ; $e2
MACRO anim_minimizeopp
db anim_minimizeopp_command
ENDM
const anim_oamon_command ; $e3
MACRO anim_oamon
db anim_oamon_command
ENDM
const anim_oamoff_command ; $e4
MACRO anim_oamoff
db anim_oamoff_command
ENDM
const anim_clearobjs_command ; $e5
MACRO anim_clearobjs
db anim_clearobjs_command
ENDM
const anim_beatup_command ; $e6
MACRO anim_beatup
db anim_beatup_command
ENDM
const anim_0xe7_command ; $e7
MACRO anim_0xe7
db anim_0xe7_command
ENDM
const anim_updateactorpic_command ; $e8
MACRO anim_updateactorpic
db anim_updateactorpic_command
ENDM
const anim_minimize_command ; $e9
MACRO anim_minimize
db anim_minimize_command
ENDM
const anim_0xea_command ; $ea
MACRO anim_0xea
db anim_0xea_command
ENDM
const anim_0xeb_command ; $eb
MACRO anim_0xeb
db anim_0xeb_command
ENDM
const anim_0xec_command ; $ec
MACRO anim_0xec
db anim_0xec_command
ENDM
const anim_0xed_command ; $ed
MACRO anim_0xed
db anim_0xed_command
ENDM
const anim_if_param_and_command ; $ee
MACRO anim_if_param_and
db anim_if_param_and_command
db \1 ; value
dw \2 ; address
ENDM
const anim_jumpuntil_command ; $ef
MACRO anim_jumpuntil
db anim_jumpuntil_command
dw \1 ; address
ENDM
const anim_bgeffect_command ; $f0
MACRO anim_bgeffect
db anim_bgeffect_command
db \1 ; effect
db \2 ; jumptable index
db \3 ; battle turn
db \4 ; unknown
ENDM
const anim_bgp_command ; $f1
MACRO anim_bgp
db anim_bgp_command
db \1 ; colors
ENDM
const anim_obp0_command ; $f2
MACRO anim_obp0
db anim_obp0_command
db \1 ; colors
ENDM
const anim_obp1_command ; $f3
MACRO anim_obp1
db anim_obp1_command
db \1 ; colors
ENDM
const anim_keepsprites_command ; $f4
MACRO anim_keepsprites
db anim_keepsprites_command
ENDM
const anim_0xf5_command ; $f5
MACRO anim_0xf5
db anim_0xf5_command
ENDM
const anim_0xf6_command ; $f6
MACRO anim_0xf6
db anim_0xf6_command
ENDM
const anim_0xf7_command ; $f7
MACRO anim_0xf7
db anim_0xf7_command
ENDM
const anim_if_param_equal_command ; $f8
MACRO anim_if_param_equal
db anim_if_param_equal_command
db \1 ; value
dw \2 ; address
ENDM
const anim_setvar_command ; $f9
MACRO anim_setvar
db anim_setvar_command
db \1 ; value
ENDM
const anim_incvar_command ; $fa
MACRO anim_incvar
db anim_incvar_command
ENDM
const anim_if_var_equal_command ; $fb
MACRO anim_if_var_equal
db anim_if_var_equal_command
db \1 ; value
dw \2 ; address
ENDM
const anim_jump_command ; $fc
MACRO anim_jump
db anim_jump_command
dw \1 ; address
ENDM
const anim_loop_command ; $fd
MACRO anim_loop
db anim_loop_command
db \1 ; count
dw \2 ; address
ENDM
const anim_call_command ; $fe
MACRO anim_call
db anim_call_command
dw \1 ; address
ENDM
const anim_ret_command ; $ff
MACRO anim_ret
db anim_ret_command
ENDM

View file

@ -0,0 +1,187 @@
MACRO command
const \1_command
DEF \1 EQUS "db \1_command"
ENDM
; BattleCommandPointers indexes (see data/battle/effect_command_pointers.asm)
const_def 1
command checkturn ; 01
command checkobedience ; 02
command usedmovetext ; 03
command doturn ; 04
command critical ; 05
command damagestats ; 06
command stab ; 07
command damagevariation ; 08
command checkhit ; 09
command lowersub ; 0a
command moveanimnosub ; 0b
command raisesub ; 0c
command failuretext ; 0d
command applydamage ; 0e
command criticaltext ; 0f
command supereffectivetext ; 10
command checkfaint ; 11
command buildopponentrage ; 12
command poisontarget ; 13
command sleeptarget ; 14
command draintarget ; 15
command eatdream ; 16
command burntarget ; 17
command freezetarget ; 18
command paralyzetarget ; 19
command selfdestruct ; 1a
command mirrormove ; 1b
command statup ; 1c
command statdown ; 1d
command payday ; 1e
command conversion ; 1f
command resetstats ; 20
command storeenergy ; 21
command unleashenergy ; 22
command forceswitch ; 23
command endloop ; 24
command flinchtarget ; 25
command ohko ; 26
command recoil ; 27
command mist ; 28
command focusenergy ; 29
command confuse ; 2a
command confusetarget ; 2b
command heal ; 2c
command transform ; 2d
command screen ; 2e
command poison ; 2f
command paralyze ; 30
command substitute ; 31
command rechargenextturn ; 32
command mimic ; 33
command metronome ; 34
command leechseed ; 35
command splash ; 36
command disable ; 37
command cleartext ; 38
command charge ; 39
command checkcharge ; 3a
command traptarget ; 3b
command effect0x3c ; 3c
command rampage ; 3d
command checkrampage ; 3e
command constantdamage ; 3f
command counter ; 40
command encore ; 41
command painsplit ; 42
command snore ; 43
command conversion2 ; 44
command lockon ; 45
command sketch ; 46
command defrostopponent ; 47
command sleeptalk ; 48
command destinybond ; 49
command spite ; 4a
command falseswipe ; 4b
command healbell ; 4c
command kingsrock ; 4d
command triplekick ; 4e
command kickcounter ; 4f
command thief ; 50
command arenatrap ; 51
command nightmare ; 52
command defrost ; 53
command curse ; 54
command protect ; 55
command spikes ; 56
command foresight ; 57
command perishsong ; 58
command startsandstorm ; 59
command endure ; 5a
command checkcurl ; 5b
command rolloutpower ; 5c
command effect0x5d ; 5d
command furycutter ; 5e
command attract ; 5f
command happinesspower ; 60
command present ; 61
command damagecalc ; 62
command frustrationpower ; 63
command safeguard ; 64
command checksafeguard ; 65
command getmagnitude ; 66
command batonpass ; 67
command pursuit ; 68
command clearhazards ; 69
command healmorn ; 6a
command healday ; 6b
command healnite ; 6c
command hiddenpower ; 6d
command startrain ; 6e
command startsun ; 6f
command attackup ; 70
command defenseup ; 71
command speedup ; 72
command specialattackup ; 73
command specialdefenseup ; 74
command accuracyup ; 75
command evasionup ; 76
command attackup2 ; 77
command defenseup2 ; 78
command speedup2 ; 79
command specialattackup2 ; 7a
command specialdefenseup2 ; 7b
command accuracyup2 ; 7c
command evasionup2 ; 7d
command attackdown ; 7e
command defensedown ; 7f
command speeddown ; 80
command specialattackdown ; 81
command specialdefensedown ; 82
command accuracydown ; 83
command evasiondown ; 84
command attackdown2 ; 85
command defensedown2 ; 86
command speeddown2 ; 87
command specialattackdown2 ; 88
command specialdefensedown2 ; 89
command accuracydown2 ; 8a
command evasiondown2 ; 8b
command statupmessage ; 8c
command statdownmessage ; 8d
command statupfailtext ; 8e
command statdownfailtext ; 8f
command effectchance ; 90
command statdownanim ; 91
command statupanim ; 92
command switchturn ; 93
command fakeout ; 94
command bellydrum ; 95
command psychup ; 96
command rage ; 97
command doubleflyingdamage ; 98
command doubleundergrounddamage ; 99
command mirrorcoat ; 9a
command checkfuturesight ; 9b
command futuresight ; 9c
command doubleminimizedamage ; 9d
command skipsuncharge ; 9e
command thunderaccuracy ; 9f
command teleport ; a0
command beatup ; a1
command ragedamage ; a2
command resettypematchup ; a3
command allstatsup ; a4
command bidefailtext ; a5
command raisesubnoanim ; a6
command lowersubnoanim ; a7
command beatupfailtext ; a8
command clearmissdamage ; a9
command movedelay ; aa
command moveanim ; ab
command tristatuschance ; ac
command supereffectivelooptext ; ad
command startloop ; ae
command curl ; af
DEF NUM_EFFECT_COMMANDS EQU const_value - 1
const_def -1, -1
command endmove ; ff
command endturn ; fe

1080
macros/scripts/events.asm Normal file

File diff suppressed because it is too large Load diff

190
macros/scripts/maps.asm Normal file
View file

@ -0,0 +1,190 @@
MACRO map_id
;\1: map id
assert DEF(GROUP_\1) && DEF(MAP_\1), \
"Missing 'map_const \1' in constants/map_constants.asm"
db GROUP_\1, MAP_\1
ENDM
DEF object_const_def EQUS "const_def 2"
MACRO def_scene_scripts
REDEF _NUM_SCENE_SCRIPTS EQUS "_NUM_SCENE_SCRIPTS_\@"
db {_NUM_SCENE_SCRIPTS}
const_def
DEF {_NUM_SCENE_SCRIPTS} = 0
ENDM
MACRO scene_const
;\1: scene id constant
const \1
EXPORT \1
ENDM
MACRO scene_script
;\1: script pointer
;\2: scene id constant
dw \1
dw 0 ; filler
if _NARG == 2
scene_const \2
else
const_skip
endc
DEF {_NUM_SCENE_SCRIPTS} += 1
ENDM
MACRO def_callbacks
REDEF _NUM_CALLBACKS EQUS "_NUM_CALLBACKS_\@"
db {_NUM_CALLBACKS}
DEF {_NUM_CALLBACKS} = 0
ENDM
MACRO callback
;\1: type: a MAPCALLBACK_* constant
;\2: script pointer
dbw \1, \2
DEF {_NUM_CALLBACKS} += 1
ENDM
MACRO def_warp_events
REDEF _NUM_WARP_EVENTS EQUS "_NUM_WARP_EVENTS_\@"
db {_NUM_WARP_EVENTS}
DEF {_NUM_WARP_EVENTS} = 0
ENDM
MACRO warp_event
;\1: x: left to right, starts at 0
;\2: y: top to bottom, starts at 0
;\3: map id: from constants/map_constants.asm
;\4: warp destination: starts at 1
db \2, \1, \4
map_id \3
DEF {_NUM_WARP_EVENTS} += 1
ENDM
MACRO def_coord_events
REDEF _NUM_COORD_EVENTS EQUS "_NUM_COORD_EVENTS_\@"
db {_NUM_COORD_EVENTS}
DEF {_NUM_COORD_EVENTS} = 0
ENDM
MACRO coord_event
;\1: x: left to right, starts at 0
;\2: y: top to bottom, starts at 0
;\3: scene id: a SCENE_* constant; controlled by setscene/setmapscene
;\4: script pointer
db \3, \2, \1
db 0 ; filler
dw \4
dw 0 ; filler
DEF {_NUM_COORD_EVENTS} += 1
ENDM
MACRO def_bg_events
REDEF _NUM_BG_EVENTS EQUS "_NUM_BG_EVENTS_\@"
db {_NUM_BG_EVENTS}
DEF {_NUM_BG_EVENTS} = 0
ENDM
MACRO bg_event
;\1: x: left to right, starts at 0
;\2: y: top to bottom, starts at 0
;\3: function: a BGEVENT_* constant
;\4: script pointer
db \2, \1, \3
dw \4
DEF {_NUM_BG_EVENTS} += 1
ENDM
MACRO def_object_events
REDEF _NUM_OBJECT_EVENTS EQUS "_NUM_OBJECT_EVENTS_\@"
db {_NUM_OBJECT_EVENTS}
DEF {_NUM_OBJECT_EVENTS} = 0
ENDM
MACRO object_event
;\1: x: left to right, starts at 0
;\2: y: top to bottom, starts at 0
;\3: sprite: a SPRITE_* constant
;\4: movement function: a SPRITEMOVEDATA_* constant
;\5, \6: movement radius: x, y
;\7, \8: hour limits: h1, h2 (0-23)
; * if h1 < h2, the object_event will only appear from h1 to h2
; * if h1 > h2, the object_event will not appear from h2 to h1
; * if h1 == h2, the object_event will always appear
; * if h1 == -1, h2 is treated as a time-of-day value:
; a combo of MORN, DAY, and/or NITE, or -1 to always appear
;\9: palette: a PAL_NPC_* constant, or 0 for sprite default
;\<10>: function: a OBJECTTYPE_* constant
;\<11>: sight range: applies to OBJECTTYPE_TRAINER
;\<12>: script pointer
;\<13>: event flag: an EVENT_* constant, or -1 to always appear
db \3, \2 + 4, \1 + 4, \4
dn \6, \5
db \7, \8
dn \9, \<10>
db \<11>
dw \<12>, \<13>
; the dummy PlayerObjectTemplate object_event has no def_object_events
if DEF(_NUM_OBJECT_EVENTS)
DEF {_NUM_OBJECT_EVENTS} += 1
endc
ENDM
MACRO trainer
;\1: trainer group
;\2: trainer id
;\3: flag: an EVENT_BEAT_* constant
;\4: seen text
;\5: win text
;\6: loss text
;\7: after-battle text
dw \3
db \1, \2
dw \4, \5, \6, \7
ENDM
MACRO itemball
;\1: item: from constants/item_constants.asm
;\2: quantity: default 1
if _NARG == 1
itemball \1, 1
else
db \1, \2
endc
ENDM
MACRO hiddenitem
;\1: item: from constants/item_constants.asm
;\2: flag: an EVENT_* constant
dwb \2, \1
ENDM
MACRO elevfloor
;\1: floor: a FLOOR_* constant
;\2: warp destination: starts at 1
;\3: map id
db \1, \2
map_id \3
ENDM
MACRO conditional_event
;\1: flag: an EVENT_* constant
;\2: script pointer
dw \1, \2
ENDM
MACRO cmdqueue
;\1: type: a CMDQUEUE_* constant
;\2: data pointer
dbw \1, \2
dw 0 ; filler
ENDM
MACRO stonetable
;\1: warp id
;\2: object_event id
;\3: script pointer
db \1, \2
dw \3
ENDM

222
macros/scripts/movement.asm Normal file
View file

@ -0,0 +1,222 @@
; MovementPointers indexes (see engine/overworld/movement.asm)
const_def 0, 4
; Directional movements
const movement_turn_head ; $00
MACRO turn_head
db movement_turn_head | \1
ENDM
const movement_turn_step ; $04
MACRO turn_step
db movement_turn_step | \1
ENDM
const movement_slow_step ; $08
MACRO slow_step
db movement_slow_step | \1
ENDM
const movement_step ; $0c
MACRO step
db movement_step | \1
ENDM
const movement_big_step ; $10
MACRO big_step
db movement_big_step | \1
ENDM
const movement_slow_slide_step ; $14
MACRO slow_slide_step
db movement_slow_slide_step | \1
ENDM
const movement_slide_step ; $18
MACRO slide_step
db movement_slide_step | \1
ENDM
const movement_fast_slide_step ; $1c
MACRO fast_slide_step
db movement_fast_slide_step | \1
ENDM
const movement_turn_away ; $20
MACRO turn_away
db movement_turn_away | \1
ENDM
const movement_turn_in ; $24
MACRO turn_in
db movement_turn_in | \1
ENDM
const movement_turn_waterfall ; $28
MACRO turn_waterfall
db movement_turn_waterfall | \1
ENDM
const movement_slow_jump_step ; $2c
MACRO slow_jump_step
db movement_slow_jump_step | \1
ENDM
const movement_jump_step ; $30
MACRO jump_step
db movement_jump_step | \1
ENDM
const movement_fast_jump_step ; $34
MACRO fast_jump_step
db movement_fast_jump_step | \1
ENDM
DEF const_inc = 1
; Control
const movement_remove_sliding ; $38
MACRO remove_sliding
db movement_remove_sliding
ENDM
const movement_set_sliding ; $39
MACRO set_sliding
db movement_set_sliding
ENDM
const movement_remove_fixed_facing ; $3a
MACRO remove_fixed_facing
db movement_remove_fixed_facing
ENDM
const movement_fix_facing ; $3b
MACRO fix_facing
db movement_fix_facing
ENDM
const movement_show_object ; $3c
MACRO show_object
db movement_show_object
ENDM
const movement_hide_object ; $3d
MACRO hide_object
db movement_hide_object
ENDM
; Sleep
const movement_step_sleep ; $3e
MACRO step_sleep
if \1 <= 8
db movement_step_sleep + \1 - 1
else
db movement_step_sleep + 8, \1
endc
ENDM
const_skip 8 ; all step_sleep values
const movement_step_end ; $47
MACRO step_end
db movement_step_end
ENDM
const movement_step_48 ; $48
MACRO step_48
db movement_step_48
db \1 ; ???
ENDM
const movement_remove_object ; $49
MACRO remove_object
db movement_remove_object
ENDM
const movement_step_loop ; $4a
MACRO step_loop
db movement_step_loop
ENDM
const movement_step_4b ; $4b
MACRO step_4b
db movement_step_4b
ENDM
const movement_teleport_from ; $4c
MACRO teleport_from
db movement_teleport_from
ENDM
const movement_teleport_to ; $4d
MACRO teleport_to
db movement_teleport_to
ENDM
const movement_skyfall ; $4e
MACRO skyfall
db movement_skyfall
ENDM
const movement_step_dig ; $4f
MACRO step_dig
db movement_step_dig
db \1 ; length
ENDM
const movement_step_bump ; $50
MACRO step_bump
db movement_step_bump
ENDM
const movement_fish_got_bite ; $51
MACRO fish_got_bite
db movement_fish_got_bite
ENDM
const movement_fish_cast_rod ; $52
MACRO fish_cast_rod
db movement_fish_cast_rod
ENDM
const movement_hide_emote ; $53
MACRO hide_emote
db movement_hide_emote
ENDM
const movement_show_emote ; $54
MACRO show_emote
db movement_show_emote
ENDM
const movement_step_shake ; $55
MACRO step_shake
db movement_step_shake
db \1 ; displacement
ENDM
const movement_tree_shake ; $56
MACRO tree_shake
db movement_tree_shake
ENDM
const movement_rock_smash ; $57
MACRO rock_smash
db movement_rock_smash
db \1 ; length
ENDM
const movement_return_dig ; $58
MACRO return_dig
db movement_return_dig
db \1 ; length
ENDM
const movement_skyfall_top ; $59
MACRO skyfall_top
db movement_skyfall_top
ENDM
DEF NUM_MOVEMENT_CMDS EQU const_value

View file

@ -0,0 +1,38 @@
; Battle and sprite OAM animations
MACRO oamframe
db \1 ; duration
DEF x = \2
assert !(x & (1 << (OAM_X_FLIP + 1) | 1 << (OAM_Y_FLIP + 1))), \
"oamframe duration overflows into X/Y flip bits"
if _NARG > 2
rept _NARG - 2
DEF x |= 1 << (\3 + 1)
shift
endr
endc
db x ; flags
ENDM
const_def -1, -1
const oamend_command ; $ff
MACRO oamend
db oamend_command
ENDM
const oamrestart_command ; $fe
MACRO oamrestart
db oamrestart_command
ENDM
const oamwait_command ; $fd
MACRO oamwait
db oamwait_command
db \1 ; frames
ENDM
const oamdelete_command ; $fc
MACRO oamdelete
db oamdelete_command
ENDM

View file

@ -0,0 +1,28 @@
MACRO frame
if _NARG <= 2
db \1 ; index
db \2 ; duration
else
; LEGACY: Support for the old name of "oamanim"
oamanim \#
endc
ENDM
const_def -1, -1
const endanim_command ; $ff
MACRO endanim
db endanim_command
ENDM
const setrepeat_command ; $fe
MACRO setrepeat
db setrepeat_command
db \1 ; amount of times to repeat
ENDM
const dorepeat_command ; $fd
MACRO dorepeat
db dorepeat_command
db \1 ; command offset to jump to
ENDM

147
macros/scripts/text.asm Normal file
View file

@ -0,0 +1,147 @@
DEF text EQUS "db TX_START," ; Start writing text.
DEF next EQUS "db \"<NEXT>\"," ; Move a line down.
DEF line EQUS "db \"<LINE>\"," ; Start writing at the bottom line.
DEF page EQUS "db \"@\"," ; Start a new Pokédex page.
DEF para EQUS "db \"<PARA>\"," ; Start a new paragraph.
DEF cont EQUS "db \"<CONT>\"," ; Scroll to the next line.
DEF done EQUS "db \"<DONE>\"" ; End a text box.
DEF prompt EQUS "db \"<PROMPT>\"" ; Prompt the player to end a text box (initiating some other event).
; TextCommands indexes (see home/text.asm)
const_def
const TX_START ; $00
MACRO text_start
db TX_START
ENDM
const TX_RAM ; $01
MACRO text_ram
db TX_RAM
dw \1
ENDM
const TX_BCD ; $02
MACRO text_bcd
db TX_BCD
dw \1
db \2
ENDM
const TX_MOVE ; $03
MACRO text_move
db TX_MOVE
dw \1
ENDM
const TX_BOX ; $04
MACRO text_box
db TX_BOX
dw \1
db \2, \3
ENDM
const TX_LOW ; $05
MACRO text_low
db TX_LOW
ENDM
const TX_PROMPT_BUTTON ; $06
MACRO text_promptbutton
db TX_PROMPT_BUTTON
ENDM
const TX_SCROLL ; $07
MACRO text_scroll
db TX_SCROLL
ENDM
const TX_START_ASM ; $08
MACRO text_asm
db TX_START_ASM
ENDM
const TX_DECIMAL ; $09
MACRO text_decimal
db TX_DECIMAL
dw \1 ; address
dn \2, \3 ; bytes, digits
ENDM
const TX_PAUSE ; $0a
MACRO text_pause
db TX_PAUSE
ENDM
const TX_SOUND_DEX_FANFARE_50_79 ; $0b
MACRO sound_dex_fanfare_50_79
db TX_SOUND_DEX_FANFARE_50_79
ENDM
const TX_DOTS ; $0c
MACRO text_dots
db TX_DOTS
db \1
ENDM
const TX_WAIT_BUTTON ; $0d
MACRO text_waitbutton
db TX_WAIT_BUTTON
ENDM
const TX_SOUND_DEX_FANFARE_20_49 ; $0e
MACRO sound_dex_fanfare_20_49
db TX_SOUND_DEX_FANFARE_20_49
ENDM
const TX_SOUND_ITEM ; $0f
MACRO sound_item
db TX_SOUND_ITEM
ENDM
const TX_SOUND_CAUGHT_MON ; $10
MACRO sound_caught_mon
db TX_SOUND_CAUGHT_MON
ENDM
const TX_SOUND_DEX_FANFARE_80_109 ; $11
MACRO sound_dex_fanfare_80_109
db TX_SOUND_DEX_FANFARE_80_109
ENDM
const TX_SOUND_FANFARE ; $12
MACRO sound_fanfare
db TX_SOUND_FANFARE
ENDM
const TX_SOUND_SLOT_MACHINE_START ; $13
MACRO sound_slot_machine_start
db TX_SOUND_SLOT_MACHINE_START
ENDM
const TX_STRINGBUFFER ; $14
MACRO text_buffer
db TX_STRINGBUFFER
db \1
ENDM
const TX_DAY ; $15
MACRO text_today
db TX_DAY
ENDM
const TX_FAR ; $16
MACRO text_far
db TX_FAR
dw \1
db BANK(\1)
ENDM
DEF NUM_TEXT_CMDS EQU const_value
const_next $50
const TX_END ; $50
MACRO text_end
db TX_END
ENDM

29
macros/vc.asm Normal file
View file

@ -0,0 +1,29 @@
; Virtual Console macros
MACRO vc_hook
if DEF(_CRYSTAL_VC)
.VC_\1::
endc
ENDM
MACRO vc_patch
if DEF(_CRYSTAL_VC)
assert !DEF(CURRENT_VC_PATCH), "Already started a vc_patch"
DEF CURRENT_VC_PATCH EQUS "\1"
.VC_{CURRENT_VC_PATCH}::
endc
ENDM
MACRO vc_patch_end
if DEF(_CRYSTAL_VC)
assert DEF(CURRENT_VC_PATCH), "No vc_patch started"
.VC_{CURRENT_VC_PATCH}_End::
PURGE CURRENT_VC_PATCH
endc
ENDM
MACRO vc_assert
if DEF(_CRYSTAL_VC)
assert \#
endc
ENDM

65
macros/wram_16bit.asm Normal file
View file

@ -0,0 +1,65 @@
MACRO ___wram_conversion_table
; in:
; 1: name of the table; will be prefixed to all definitions
; 2: table size, in entries
; 3: locked ID table size
; 4: last allocations table size
; 5: cache size
assert (\2) <= $FE, \
"16-bit conversion table error: too many table entries"
assert (\2) >= $20, \
"16-bit conversion table error: too many table entries"
assert ((\3) + (\4)) <= (\2), \
"16-bit conversion table error: too many fixed indexes"
assert (\4) >= 2, \
"16-bit conversion table error: recent allocations table must contain at least two entries"
assert !((\5) & ((\5) - 1)), \
"16-bit conversion table error: invalid cache size"
assert ((\3) + (\4) + (\5)) <= $100, \
"16-bit conversion table error: cache would straddle a $100 alignment boundary"
\1::
\1UsedSlots:: db
\1LastAllocatedIndex:: db ; index into LastAllocated
\1Entries:: ds 2 * (\2)
\1EntriesEnd::
; pad to a multiple of $100; ensure that the remaining values share the same high byte
DEF ___total_bytes = 2 + (2 * (\2)) + (\3) + (\4) + (\5)
if LOW(___total_bytes)
ds $100 - LOW(___total_bytes)
endc
if \5
\1EntryCache:: ds \5
endc
if \3
\1LockedEntries:: ds \3
endc
\1LastAllocated:: ds \4
\1End::
ENDM
MACRO wram_conversion_table
; uses constants to invoke the macro above
; in: WRAM prefix, constant prefix
assert \2_MINIMUM_RESERVED_INDEX <= $FF, \
"16-bit conversion table error: $FF must be declared as a reserved index"
assert \2_ENTRIES < \2_MINIMUM_RESERVED_INDEX, \
"16-bit conversion table error: table entries and reserved indexes overlap"
___wram_conversion_table \1, \
\2_ENTRIES, \
\2_LOCKED_ENTRIES, \
\2_SAVED_RECENT_INDEXES, \
\2_CACHE_SIZE
ENDM