summaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
Diffstat (limited to 'macros')
-rwxr-xr-xmacros/asm_macros.asm192
-rwxr-xr-xmacros/code.asm9
-rw-r--r--macros/coords.asm65
-rwxr-xr-xmacros/data.asm62
-rwxr-xr-xmacros/data_macros.asm242
-rw-r--r--macros/enum.asm43
-rw-r--r--macros/farcall.asm37
-rw-r--r--macros/predef.asm32
-rwxr-xr-xmacros/scripts/audio.asm (renamed from macros/audio_macros.asm)28
-rwxr-xr-xmacros/scripts/events.asm (renamed from macros/event_macros.asm)102
-rw-r--r--macros/scripts/maps.asm184
-rwxr-xr-xmacros/scripts/text.asm (renamed from macros/text_macros.asm)2
-rw-r--r--macros/wram.asm92
13 files changed, 590 insertions, 500 deletions
diff --git a/macros/asm_macros.asm b/macros/asm_macros.asm
deleted file mode 100755
index d3f00b0c..00000000
--- a/macros/asm_macros.asm
+++ /dev/null
@@ -1,192 +0,0 @@
-
-lb: MACRO ; r, hi, lo
- ld \1, ((\2) & $ff) << 8 + ((\3) & $ff)
-ENDM
-
-homecall: MACRO
- ld a, [H_LOADEDROMBANK]
- push af
- ld a, BANK(\1)
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
- call \1
- pop af
- ld [H_LOADEDROMBANK], a
- ld [MBC1RomBank], a
-ENDM
-
-farcall EQUS "callba"
-
-callba: MACRO
- ld b, BANK(\1)
- ld hl, \1
- call Bankswitch
-ENDM
-
-callab: MACRO
- ld hl, \1
- ld b, BANK(\1)
- call Bankswitch
-ENDM
-
-jpba: MACRO
- ld b, BANK(\1)
- ld hl, \1
- jp Bankswitch
-ENDM
-
-jpab: MACRO
- ld hl, \1
- ld b, BANK(\1)
- jp Bankswitch
-ENDM
-
-validateCoords: MACRO
- IF \1 >= SCREEN_WIDTH
- fail "x coord out of range"
- ENDC
- IF \2 >= SCREEN_HEIGHT
- fail "y coord out of range"
- ENDC
-ENDM
-
-;\1 = r
-;\2 = X
-;\3 = Y
-;\4 = which tilemap (optional)
-coord: MACRO
- validateCoords \2, \3
- IF _NARG >= 4
- ld \1, \4 + SCREEN_WIDTH * \3 + \2
- ELSE
- ld \1, wTileMap + SCREEN_WIDTH * \3 + \2
- ENDC
-ENDM
-
-;\1 = X
-;\2 = Y
-;\3 = which tilemap (optional)
-aCoord: MACRO
- validateCoords \1, \2
- IF _NARG >= 3
- ld a, [\3 + SCREEN_WIDTH * \2 + \1]
- ELSE
- ld a, [wTileMap + SCREEN_WIDTH * \2 + \1]
- ENDC
-ENDM
-
-;\1 = X
-;\2 = Y
-;\3 = which tilemap (optional)
-Coorda: MACRO
- validateCoords \1, \2
- IF _NARG >= 3
- ld [\3 + SCREEN_WIDTH * \2 + \1], a
- ELSE
- ld [wTileMap + SCREEN_WIDTH * \2 + \1], a
- ENDC
-ENDM
-
-;\1 = X
-;\2 = Y
-;\3 = which tilemap (optional)
-dwCoord: MACRO
- validateCoords \1, \2
- IF _NARG >= 3
- dw \3 + SCREEN_WIDTH * \2 + \1
- ELSE
- dw wTileMap + SCREEN_WIDTH * \2 + \1
- ENDC
-ENDM
-
-;\1 = r
-;\2 = X
-;\3 = Y
-;\4 = map width
-overworldMapCoord: MACRO
- ld \1, wOverworldMap + ((\2) + 3) + (((\3) + 3) * ((\4) + (3 * 2)))
-ENDM
-
-; macro for two nibbles
-dn: MACRO
- db (\1 << 4 | \2)
-ENDM
-
-; macro for putting a byte then a word
-dbw: MACRO
- db \1
- dw \2
-ENDM
-
-dba: MACRO
- dbw BANK(\1), \1
-ENDM
-
-dwb: MACRO
- dw \1
- db \2
-ENDM
-
-dab: MACRO
- dwb \1, BANK(\1)
-ENDM
-
-dbbw: MACRO
- db \1, \2
- dw \3
-ENDM
-
-; Predef macro.
-predef_const: MACRO
- const \1PredefID
-ENDM
-
-add_predef: MACRO
-\1Predef::
- db BANK(\1)
- dw \1
-ENDM
-
-predef_id: MACRO
- ld a, (\1Predef - PredefPointers) / 3
-ENDM
-
-predef: MACRO
- predef_id \1
- call Predef
-ENDM
-
-predef_jump: MACRO
- predef_id \1
- jp Predef
-ENDM
-
-tx_pre_const: MACRO
- const \1_id
-ENDM
-
-add_tx_pre: MACRO
-\1_id:: dw \1
-ENDM
-
-db_tx_pre: MACRO
- db (\1_id - TextPredefs) / 2 + 1
-ENDM
-
-tx_pre_id: MACRO
- ld a, (\1_id - TextPredefs) / 2 + 1
-ENDM
-
-tx_pre: MACRO
- tx_pre_id \1
- call PrintPredefTextID
-ENDM
-
-tx_pre_jump: MACRO
- tx_pre_id \1
- jp PrintPredefTextID
-ENDM
-
-ldPal: MACRO
- ld \1, \2 << 6 | \3 << 4 | \4 << 2 | \5
-ENDM
diff --git a/macros/code.asm b/macros/code.asm
new file mode 100755
index 00000000..8b7d6184
--- /dev/null
+++ b/macros/code.asm
@@ -0,0 +1,9 @@
+; Syntactic sugar macros
+
+lb: MACRO ; r, hi, lo
+ ld \1, ((\2) & $ff) << 8 + ((\3) & $ff)
+ENDM
+
+ldPal: MACRO
+ ld \1, \2 << 6 | \3 << 4 | \4 << 2 | \5
+ENDM
diff --git a/macros/coords.asm b/macros/coords.asm
new file mode 100644
index 00000000..302260d7
--- /dev/null
+++ b/macros/coords.asm
@@ -0,0 +1,65 @@
+validateCoords: MACRO
+ IF \1 >= SCREEN_WIDTH
+ fail "x coord out of range"
+ ENDC
+ IF \2 >= SCREEN_HEIGHT
+ fail "y coord out of range"
+ ENDC
+ENDM
+
+;\1 = r
+;\2 = X
+;\3 = Y
+;\4 = which tilemap (optional)
+coord: MACRO
+ validateCoords \2, \3
+ IF _NARG >= 4
+ ld \1, \4 + SCREEN_WIDTH * \3 + \2
+ ELSE
+ ld \1, wTileMap + SCREEN_WIDTH * \3 + \2
+ ENDC
+ENDM
+
+;\1 = X
+;\2 = Y
+;\3 = which tilemap (optional)
+aCoord: MACRO
+ validateCoords \1, \2
+ IF _NARG >= 3
+ ld a, [\3 + SCREEN_WIDTH * \2 + \1]
+ ELSE
+ ld a, [wTileMap + SCREEN_WIDTH * \2 + \1]
+ ENDC
+ENDM
+
+;\1 = X
+;\2 = Y
+;\3 = which tilemap (optional)
+Coorda: MACRO
+ validateCoords \1, \2
+ IF _NARG >= 3
+ ld [\3 + SCREEN_WIDTH * \2 + \1], a
+ ELSE
+ ld [wTileMap + SCREEN_WIDTH * \2 + \1], a
+ ENDC
+ENDM
+
+;\1 = X
+;\2 = Y
+;\3 = which tilemap (optional)
+dwCoord: MACRO
+ validateCoords \1, \2
+ IF _NARG >= 3
+ dw \3 + SCREEN_WIDTH * \2 + \1
+ ELSE
+ dw wTileMap + SCREEN_WIDTH * \2 + \1
+ ENDC
+ENDM
+
+;\1 = r
+;\2 = X
+;\3 = Y
+;\4 = map width
+overworldMapCoord: MACRO
+ ld \1, wOverworldMap + ((\2) + 3) + (((\3) + 3) * ((\4) + (3 * 2)))
+ENDM
diff --git a/macros/data.asm b/macros/data.asm
new file mode 100755
index 00000000..54d1d561
--- /dev/null
+++ b/macros/data.asm
@@ -0,0 +1,62 @@
+; Value macros
+
+percent EQUS "* $ff / 100"
+
+bcd2: MACRO
+ dn ((\1) / 1000) % 10, ((\1) / 100) % 10
+ dn ((\1) / 10) % 10, (\1) % 10
+ENDM
+
+bcd3: MACRO
+ dn ((\1) / 100000) % 10, ((\1) / 10000) % 10
+ dn ((\1) / 1000) % 10, ((\1) / 100) % 10
+ dn ((\1) / 10) % 10, (\1) % 10
+ENDM
+
+coins equs "bcd2"
+money equs "bcd3"
+
+RGB: MACRO
+ dw (\3 << 10 | \2 << 5 | \1)
+ENDM
+
+tmlearn: MACRO
+x = 0
+ REPT _NARG
+IF \1 != 0
+x = x | (1 << ((\1 - 1) % 8))
+ENDC
+ SHIFT
+ ENDR
+ db x
+ENDM
+
+
+; Constant data (db, dw, dl) macros
+
+dn: MACRO ; nybbles
+ db (\1 << 4 | \2)
+ENDM
+
+dbw: MACRO
+ db \1
+ dw \2
+ENDM
+
+dba: MACRO
+ dbw BANK(\1), \1
+ENDM
+
+dwb: MACRO
+ dw \1
+ db \2
+ENDM
+
+dab: MACRO
+ dwb \1, BANK(\1)
+ENDM
+
+dbbw: MACRO
+ db \1, \2
+ dw \3
+ENDM
diff --git a/macros/data_macros.asm b/macros/data_macros.asm
deleted file mode 100755
index ee5cb8f0..00000000
--- a/macros/data_macros.asm
+++ /dev/null
@@ -1,242 +0,0 @@
-
-; Constant enumeration is useful for monsters, items, moves, etc.
-const_def: MACRO
-const_value = 0
-ENDM
-
-const: MACRO
-\1 EQU const_value
-const_value = const_value + 1
-ENDM
-
-; data format macros
-
-percent EQUS "* $ff / 100"
-
-bcd2: MACRO
- dn ((\1) / 1000) % 10, ((\1) / 100) % 10
- dn ((\1) / 10) % 10, (\1) % 10
-ENDM
-
-bcd3: MACRO
- dn ((\1) / 100000) % 10, ((\1) / 10000) % 10
- dn ((\1) / 1000) % 10, ((\1) / 100) % 10
- dn ((\1) / 10) % 10, (\1) % 10
-ENDM
-
-coins equs "bcd2"
-money equs "bcd3"
-
-;\1 = Map Width
-;\2 = Rows above (Y-blocks)
-;\3 = X movement (X-blocks)
-EVENT_DISP: MACRO
- dw (wOverworldMap + 7 + (\1) + ((\1) + 6) * ((\2) >> 1) + ((\3) >> 1)) ; Ev.Disp
- db \2,\3 ;Y,X
-ENDM
-
-FLYWARP_DATA: MACRO
- EVENT_DISP \1,\2,\3
- db ((\2) & $01) ;sub-block Y
- db ((\3) & $01) ;sub-block X
-ENDM
-
-; external map entry macro
-EMAP: MACRO ; emap x-coordinate,y-coordinate,textpointer
-; the appearance of towns and routes in the town map, indexed by map id
- ; nybble: y-coordinate
- ; nybble: x-coordinate
- ; word : pointer to map name
- dn \2, \1
- dw \3
-ENDM
-
-; internal map entry macro
-IMAP: MACRO ; imap mapid_less_than,x-coordinate,y-coordinate,textpointer
-; the appearance of buildings and dungeons in the town map
- ; byte : maximum map id subject to this rule
- ; nybble: y-coordinate
- ; nybble: x-coordinate
- ; word : pointer to map name
- db \1 + 1
- dn \3, \2
- dw \4
-ENDM
-
-; tilesets' headers macro
-tileset: MACRO
- db BANK(\2) ; BANK(GFX)
- dw \1, \2, \3 ; Block, GFX, Coll
- db \4, \5, \6 ; counter tiles
- db \7 ; grass tile
- db \8 ; permission (indoor, cave, outdoor)
-ENDM
-
-INDOOR EQU 0
-CAVE EQU 1
-OUTDOOR EQU 2
-
-RGB: MACRO
- dw (\3 << 10 | \2 << 5 | \1)
-ENDM
-
-WALK EQU $FE
-STAY EQU $FF
-
-DOWN EQU $D0
-UP EQU $D1
-LEFT EQU $D2
-RIGHT EQU $D3
-NONE EQU $FF
-
-;\1 sprite id
-;\2 x position
-;\3 y position
-;\4 movement (WALK/STAY)
-;\5 range or direction
-;\6 text id
-;\7 items only: item id
-;\7 trainers only: trainer class/pokemon id
-;\8 trainers only: trainer number/pokemon level
-object: MACRO
- db \1
- db \3 + 4
- db \2 + 4
- db \4
- db \5
- IF (_NARG > 7)
- db TRAINER | \6
- db \7
- db \8
- ELSE
- IF (_NARG > 6)
- db ITEM | \6
- db \7
- ELSE
- db \6
- ENDC
- ENDC
-ENDM
-
-;\1 x position
-;\2 y position
-;\3 destination warp id
-;\4 destination map (-1 = wLastMap)
-warp: MACRO
- db \2, \1, \3, \4
-ENDM
-
-;\1 x position
-;\2 y position
-;\3 sign id
-sign: MACRO
- db \2, \1, \3
-ENDM
-
-;\1 x position
-;\2 y position
-;\3 map width
-warp_to: MACRO
- EVENT_DISP \3, \2, \1
-ENDM
-
-;\1 (byte) = current map id
-;\2 (byte) = connected map id
-;\3 (byte) = x movement of connection strip
-;\4 (byte) = connection strip offset
-;\5 (word) = connected map blocks pointer
-NORTH_MAP_CONNECTION: MACRO
- db \2 ; map id
- dw \5 + (\2_WIDTH * (\2_HEIGHT - 3)) + \4; "Connection Strip" location
- dw wOverworldMap + 3 + \3 ; current map position
- IF (\1_WIDTH < \2_WIDTH)
- db \1_WIDTH - \3 + 3 ; width of connection strip
- ELSE
- db \2_WIDTH - \4 ; width of connection strip
- ENDC
- db \2_WIDTH ; map width
- db (\2_HEIGHT * 2) - 1 ; y alignment (y coordinate of player when entering map)
- db (\3 - \4) * -2 ; x alignment (x coordinate of player when entering map)
- dw wOverworldMap + 1 + (\2_HEIGHT * (\2_WIDTH + 6)) ; window (position of the upper left block after entering the map)
-ENDM
-
-;\1 (byte) = current map id
-;\2 (byte) = connected map id
-;\3 (byte) = x movement of connection strip
-;\4 (byte) = connection strip offset
-;\5 (word) = connected map blocks pointer
-;\6 (flag) = add 3 to width of connection strip (why?)
-SOUTH_MAP_CONNECTION: MACRO
- db \2 ; map id
- dw \5 + \4 ; "Connection Strip" location
- dw wOverworldMap + 3 + (\1_HEIGHT + 3) * (\1_WIDTH + 6) + \3 ; current map position
- IF (\1_WIDTH < \2_WIDTH)
- IF (_NARG > 5)
- db \1_WIDTH - \3 + 3 ; width of connection strip
- ELSE
- db \1_WIDTH - \3 ; width of connection strip
- ENDC
- ELSE
- db \2_WIDTH - \4 ; width of connection strip
- ENDC
- db \2_WIDTH ; map width
- db 0 ; y alignment (y coordinate of player when entering map)
- db (\3 - \4) * -2 ; x alignment (x coordinate of player when entering map)
- dw wOverworldMap + 7 + \2_WIDTH ; window (position of the upper left block after entering the map)
-ENDM
-
-;\1 (byte) = current map id
-;\2 (byte) = connected map id
-;\3 (byte) = y movement of connection strip
-;\4 (byte) = connection strip offset
-;\5 (word) = connected map blocks pointer
-WEST_MAP_CONNECTION: MACRO
- db \2 ; map id
- dw \5 + (\2_WIDTH * \4) + \2_WIDTH - 3 ; "Connection Strip" location
- dw wOverworldMap + (\1_WIDTH + 6) * (\3 + 3) ; current map position
- IF (\1_HEIGHT < \2_HEIGHT)
- db \1_HEIGHT - \3 + 3 ; height of connection strip
- ELSE
- db \2_HEIGHT - \4 ; height of connection strip
- ENDC
- db \2_WIDTH ; map width
- db (\3 - \4) * -2 ; y alignment
- db (\2_WIDTH * 2) - 1 ; x alignment
- dw wOverworldMap + 6 + (2 * \2_WIDTH) ; window (position of the upper left block after entering the map)
-ENDM
-
-;\1 (byte) = current map id
-;\2 (byte) = connected map id
-;\3 (byte) = y movement of connection strip
-;\4 (byte) = connection strip offset
-;\5 (word) = connected map blocks pointer
-;\6 (flag) = add 3 to height of connection strip (why?)
-EAST_MAP_CONNECTION: MACRO
- db \2 ; map id
- dw \5 + (\2_WIDTH * \4) ; "Connection Strip" location
- dw wOverworldMap - 3 + (\1_WIDTH + 6) * (\3 + 4) ; current map position
- IF (\1_HEIGHT < \2_HEIGHT)
- IF (_NARG > 5)
- db \1_HEIGHT - \3 + 3 ; height of connection strip
- ELSE
- db \1_HEIGHT - \3 ; height of connection strip
- ENDC
- ELSE
- db \2_HEIGHT - \4 ; height of connection strip
- ENDC
- db \2_WIDTH ; map width
- db (\3 - \4) * -2 ; y alignment
- db 0 ; x alignment
- dw wOverworldMap + 7 + \2_WIDTH ; window (position of the upper left block after entering the map)
-ENDM
-
-tmlearn: MACRO
-x = 0
- REPT _NARG
-IF \1 != 0
-x = x | (1 << ((\1 - 1) % 8))
-ENDC
- SHIFT
- ENDR
- db x
-ENDM
diff --git a/macros/enum.asm b/macros/enum.asm
new file mode 100644
index 00000000..8fe5b534
--- /dev/null
+++ b/macros/enum.asm
@@ -0,0 +1,43 @@
+; Enumerate variables
+
+enum_start: MACRO
+if _NARG >= 1
+__enum__ = \1
+else
+__enum__ = 0
+endc
+if _NARG >= 2
+__enumdir__ = \2
+else
+__enumdir__ = 1
+endc
+ENDM
+
+enum: MACRO
+\1 EQU __enum__
+__enum__ = __enum__ + __enumdir__
+ENDM
+
+enum_set: MACRO
+__enum__ = \1
+ENDM
+
+; Enumerate constants
+
+const_def: MACRO
+if _NARG >= 1
+const_value = \1
+else
+const_value = 0
+endc
+ENDM
+
+const: MACRO
+\1 EQU const_value
+const_value = const_value + 1
+ENDM
+
+shift_const: MACRO
+\1 EQU (1 << const_value)
+const_value = const_value + 1
+ENDM
diff --git a/macros/farcall.asm b/macros/farcall.asm
new file mode 100644
index 00000000..885f8c66
--- /dev/null
+++ b/macros/farcall.asm
@@ -0,0 +1,37 @@
+farcall EQUS "callba"
+
+callba: MACRO
+ ld b, BANK(\1)
+ ld hl, \1
+ call Bankswitch
+ENDM
+
+callab: MACRO
+ ld hl, \1
+ ld b, BANK(\1)
+ call Bankswitch
+ENDM
+
+jpba: MACRO
+ ld b, BANK(\1)
+ ld hl, \1
+ jp Bankswitch
+ENDM
+
+jpab: MACRO
+ ld hl, \1
+ ld b, BANK(\1)
+ jp Bankswitch
+ENDM
+
+homecall: MACRO
+ ld a, [hLoadedROMBank]
+ push af
+ ld a, BANK(\1)
+ ld [hLoadedROMBank], a
+ ld [MBC1RomBank], a
+ call \1
+ pop af
+ ld [hLoadedROMBank], a
+ ld [MBC1RomBank], a
+ENDM
diff --git a/macros/predef.asm b/macros/predef.asm
new file mode 100644
index 00000000..d86582d1
--- /dev/null
+++ b/macros/predef.asm
@@ -0,0 +1,32 @@
+predef_id: MACRO
+ ld a, (\1Predef - PredefPointers) / 3
+ENDM
+
+predef: MACRO
+ predef_id \1
+ call Predef
+ENDM
+
+predef_jump: MACRO
+ predef_id \1
+ jp Predef
+ENDM
+
+
+tx_pre_id: MACRO
+ ld a, (\1_id - TextPredefs) / 2 + 1
+ENDM
+
+tx_pre: MACRO
+ tx_pre_id \1
+ call PrintPredefTextID
+ENDM
+
+tx_pre_jump: MACRO
+ tx_pre_id \1
+ jp PrintPredefTextID
+ENDM
+
+db_tx_pre: MACRO
+ db (\1_id - TextPredefs) / 2 + 1
+ENDM
diff --git a/macros/audio_macros.asm b/macros/scripts/audio.asm
index 95b9ecbc..8a250c63 100755
--- a/macros/audio_macros.asm
+++ b/macros/scripts/audio.asm
@@ -1,18 +1,3 @@
-
-StopAllMusic: MACRO
- ld a, $ff
- call PlaySound
-ENDM
-
-Ch1 EQU 0
-Ch2 EQU 1
-Ch3 EQU 2
-Ch4 EQU 3
-Ch5 EQU 4
-Ch6 EQU 5
-Ch7 EQU 6
-Ch8 EQU 7
-
audio_header: MACRO
db (_NARG - 2) << 6 | \2
dw \1_\2
@@ -73,19 +58,6 @@ noise_note: MACRO
db \4
ENDM
-C_ EQU $0
-C# EQU $1
-D_ EQU $2
-D# EQU $3
-E_ EQU $4
-F_ EQU $5
-F# EQU $6
-G_ EQU $7
-G# EQU $8
-A_ EQU $9
-A# EQU $A
-B_ EQU $B
-
; arguments: pitch, length [1, 16]
note: MACRO
db (\1 << 4) | (\2 - 1)
diff --git a/macros/event_macros.asm b/macros/scripts/events.asm
index 20027209..c5f90107 100755
--- a/macros/event_macros.asm
+++ b/macros/scripts/events.asm
@@ -15,7 +15,8 @@ event_byte = ((\1) / 8)
ELSE
bit (\1) % 8, a
ENDC
- ENDM
+ENDM
+
;\1 = event index
CheckEventReuseA: MACRO
@@ -25,7 +26,8 @@ event_byte = ((\1) / 8)
ENDC
bit (\1) % 8, a
- ENDM
+ENDM
+
;\1 = event index
;\2 = event index of the last event used before the branch
@@ -37,7 +39,8 @@ event_byte = ((\1) / 8)
ENDC
bit (\1) % 8, a
- ENDM
+ENDM
+
;\1 = reg
;\2 = event index
@@ -48,21 +51,24 @@ EventFlagBit: MACRO
ELSE
ld \1, (\2) % 8
ENDC
- ENDM
+ENDM
+
;\1 = reg
;\2 = event index
EventFlagAddress: MACRO
event_byte = ((\2) / 8)
ld \1, wEventFlags + event_byte
- ENDM
+ENDM
+
;\1 = event index
CheckEventHL: MACRO
event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte
bit (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
CheckEventReuseHL: MACRO
@@ -72,14 +78,16 @@ event_byte = ((\1) / 8)
ENDC
bit (\1) % 8, [hl]
- ENDM
+ENDM
+
; dangerous, only use when HL is guaranteed to be the desired value
;\1 = event index
CheckEventForceReuseHL: MACRO
event_byte = ((\1) / 8)
bit (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
;\2 = event index of the last event used before the branch
@@ -91,7 +99,8 @@ event_byte = ((\1) / 8)
ENDC
bit (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
CheckAndSetEvent: MACRO
@@ -99,7 +108,8 @@ event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte
bit (\1) % 8, [hl]
set (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
CheckAndResetEvent: MACRO
@@ -107,7 +117,8 @@ event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte
bit (\1) % 8, [hl]
res (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
CheckAndSetEventA: MACRO
@@ -115,7 +126,8 @@ CheckAndSetEventA: MACRO
bit (\1) % 8, a
set (\1) % 8, a
ld [wEventFlags + ((\1) / 8)], a
- ENDM
+ENDM
+
;\1 = event index
CheckAndResetEventA: MACRO
@@ -123,14 +135,16 @@ CheckAndResetEventA: MACRO
bit (\1) % 8, a
res (\1) % 8, a
ld [wEventFlags + ((\1) / 8)], a
- ENDM
+ENDM
+
;\1 = event index
SetEvent: MACRO
event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte
set (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
SetEventReuseHL: MACRO
@@ -140,7 +154,8 @@ event_byte = ((\1) / 8)
ENDC
set (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
;\2 = event index of the last event used before the branch
@@ -152,32 +167,36 @@ event_byte = ((\1) / 8)
ENDC
set (\1) % 8, [hl]
- ENDM
+ENDM
+
; dangerous, only use when HL is guaranteed to be the desired value
;\1 = event index
SetEventForceReuseHL: MACRO
event_byte = ((\1) / 8)
set (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
;\2 = event index
;\3, \4, ... = additional (optional) event indices
SetEvents: MACRO
SetEvent \1
- rept (_NARG + -1)
+ rept _NARG - 1
SetEventReuseHL \2
shift
endr
- ENDM
+ENDM
+
;\1 = event index
ResetEvent: MACRO
event_byte = ((\1) / 8)
ld hl, wEventFlags + event_byte
res (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
ResetEventReuseHL: MACRO
@@ -187,7 +206,8 @@ event_byte = ((\1) / 8)
ENDC
res (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
;\2 = event index of the last event used before the branch
@@ -199,25 +219,28 @@ event_byte = ((\1) / 8)
ENDC
res (\1) % 8, [hl]
- ENDM
+ENDM
+
; dangerous, only use when HL is guaranteed to be the desired value
;\1 = event index
ResetEventForceReuseHL: MACRO
event_byte = ((\1) / 8)
res (\1) % 8, [hl]
- ENDM
+ENDM
+
;\1 = event index
;\2 = event index
;\3 = event index (optional)
ResetEvents: MACRO
ResetEvent \1
- rept (_NARG + -1)
+ rept _NARG - 1
ResetEventReuseHL \2
shift
endr
- ENDM
+ENDM
+
;\1 = event index
;\2 = number of bytes away from the base address (optional, for matching the ROM)
@@ -227,7 +250,8 @@ dbEventFlagBit: MACRO
ELSE
db ((\1) % 8)
ENDC
- ENDM
+ENDM
+
;\1 = event index
;\2 = number of bytes away from the base address (optional, for matching the ROM)
@@ -237,7 +261,8 @@ dwEventFlagAddress: MACRO
ELSE
dw wEventFlags + ((\1) / 8)
ENDC
- ENDM
+ENDM
+
;\1 = start
;\2 = end
@@ -258,7 +283,7 @@ event_fill_start = event_start_byte + 1
event_fill_count = event_end_byte - event_start_byte - 1
IF ((\1) % 8) == 0
-event_fill_start = event_fill_start + -1
+event_fill_start = event_fill_start - 1
event_fill_count = event_fill_count + 1
ELSE
ld a, [wEventFlags + event_start_byte]
@@ -279,7 +304,7 @@ event_fill_count = event_fill_count + 1
ld a, $ff
ld hl, wEventFlags + event_fill_start
- REPT event_fill_count + -1
+ REPT event_fill_count - 1
ld [hli], a
ENDR
@@ -297,7 +322,8 @@ event_fill_count = event_fill_count + 1
ENDC
ENDC
ENDC
- ENDM
+ENDM
+
;\1 = start
;\2 = end
@@ -319,7 +345,7 @@ event_fill_start = event_start_byte + 1
event_fill_count = event_end_byte - event_start_byte - 1
IF ((\1) % 8) == 0
-event_fill_start = event_fill_start + -1
+event_fill_start = event_fill_start - 1
event_fill_count = event_fill_count + 1
ELSE
ld a, [wEventFlags + event_start_byte]
@@ -344,7 +370,7 @@ event_fill_count = event_fill_count + 1
xor a
ENDC
- REPT event_fill_count + -1
+ REPT event_fill_count - 1
ld [hli], a
ENDR
@@ -362,7 +388,8 @@ event_fill_count = event_fill_count + 1
ENDC
ENDC
ENDC
- ENDM
+ENDM
+
; returns whether both events are set in Z flag
; This is counter-intuitive because the other event checks set the Z flag when
@@ -400,7 +427,8 @@ event_byte = ((\1) / 8)
pop bc
ENDC
ENDC
- ENDM
+ENDM
+
; returns the complement of whether either event is set in Z flag
;\1 = event index 1
@@ -429,7 +457,8 @@ CheckEitherEventSet: MACRO
pop bc
ENDC
ENDC
- ENDM
+ENDM
+
; for handling fixed event bits when events are inserted/removed
;\1 = event index
@@ -438,4 +467,5 @@ AdjustEventBit: MACRO
IF ((\1) % 8) != (\2)
add ((\1) % 8) - (\2)
ENDC
- ENDM
+ENDM
+
diff --git a/macros/scripts/maps.asm b/macros/scripts/maps.asm
new file mode 100644
index 00000000..a30561b9
--- /dev/null
+++ b/macros/scripts/maps.asm
@@ -0,0 +1,184 @@
+;\1 map width
+;\2 Rows above (Y-blocks)
+;\3 X movement (X-blocks)
+EVENT_DISP: MACRO
+ dw (wOverworldMap + 7 + (\1) + ((\1) + 6) * ((\2) >> 1) + ((\3) >> 1)) ; Ev.Disp
+ db \2,\3 ;Y,X
+ENDM
+
+FLYWARP_DATA: MACRO
+ EVENT_DISP \1,\2,\3
+ db ((\2) & $01) ;sub-block Y
+ db ((\3) & $01) ;sub-block X
+ENDM
+
+; external map entry macro
+EMAP: MACRO ; emap x-coordinate,y-coordinate,textpointer
+; the appearance of towns and routes in the town map, indexed by map id
+ ; nybble: y-coordinate
+ ; nybble: x-coordinate
+ ; word : pointer to map name
+ dn \2, \1
+ dw \3
+ENDM
+
+; internal map entry macro
+IMAP: MACRO ; imap mapid_less_than,x-coordinate,y-coordinate,textpointer
+; the appearance of buildings and dungeons in the town map
+ ; byte : maximum map id subject to this rule
+ ; nybble: y-coordinate
+ ; nybble: x-coordinate
+ ; word : pointer to map name
+ db \1 + 1
+ dn \3, \2
+ dw \4
+ENDM
+
+;\1 sprite id
+;\2 x position
+;\3 y position
+;\4 movement (WALK/STAY)
+;\5 range or direction
+;\6 text id
+;\7 items only: item id
+;\7 trainers only: trainer class/pokemon id
+;\8 trainers only: trainer number/pokemon level
+object: MACRO
+ db \1
+ db \3 + 4
+ db \2 + 4
+ db \4
+ db \5
+ IF (_NARG > 7)
+ db TRAINER | \6
+ db \7
+ db \8
+ ELSE
+ IF (_NARG > 6)
+ db ITEM | \6
+ db \7
+ ELSE
+ db \6
+ ENDC
+ ENDC
+ENDM
+
+;\1 x position
+;\2 y position
+;\3 destination warp id
+;\4 destination map (-1 = wLastMap)
+warp: MACRO
+ db \2, \1, \3, \4
+ENDM
+
+;\1 x position
+;\2 y position
+;\3 sign id
+sign: MACRO
+ db \2, \1, \3
+ENDM
+
+;\1 x position
+;\2 y position
+;\3 map width
+warp_to: MACRO
+ EVENT_DISP \3, \2, \1
+ENDM
+
+;\1 map name
+;\2 map id
+;\3 tileset
+;\4 connections: combo of NORTH, SOUTH, WEST, and/or EAST, or 0 for none
+map_header: MACRO
+CURRENT_MAP_WIDTH = \2_WIDTH
+CURRENT_MAP_HEIGHT = \2_HEIGHT
+CURRENT_MAP_OBJECT EQUS "\1_Object"
+\1_h::
+ db \3
+ db CURRENT_MAP_HEIGHT, CURRENT_MAP_WIDTH
+ dw \1_Blocks
+ dw \1_TextPointers
+ dw \1_Script
+ db \4
+ENDM
+
+; Comes after map_header and connection macros
+end_map_header: MACRO
+ dw CURRENT_MAP_OBJECT
+PURGE CURRENT_MAP_WIDTH
+PURGE CURRENT_MAP_HEIGHT
+PURGE CURRENT_MAP_OBJECT
+ENDM
+
+; Connections go in order: north, south, west, east
+;\1 direction
+;\2 map name
+;\3 map id
+;\4 offset of the target map relative to the current map
+; (x offset for east/west, y offset for north/south)
+connection: MACRO
+
+; Calculate tile offsets for source (current) and target maps
+_src = 0
+_tgt = (\4) + 3
+if _tgt < 2
+_src = -_tgt
+_tgt = 0
+endc
+
+if "\1" == "north"
+_blk = \3_WIDTH * (\3_HEIGHT - 3) + _src
+_map = _tgt
+_win = (\3_WIDTH + 6) * \3_HEIGHT + 1
+_y = \3_HEIGHT * 2 - 1
+_x = (\4) * -2
+_len = CURRENT_MAP_WIDTH + 3 - (\4)
+if _len > \3_WIDTH
+_len = \3_WIDTH
+endc
+
+elif "\1" == "south"
+_blk = _src
+_map = (CURRENT_MAP_WIDTH + 6) * (CURRENT_MAP_HEIGHT + 3) + _tgt
+_win = \3_WIDTH + 7
+_y = 0
+_x = (\4) * -2
+_len = CURRENT_MAP_WIDTH + 3 - (\4)
+if _len > \3_WIDTH
+_len = \3_WIDTH
+endc
+
+elif "\1" == "west"
+_blk = (\3_WIDTH * _src) + \3_WIDTH - 3
+_map = (CURRENT_MAP_WIDTH + 6) * _tgt
+_win = (\3_WIDTH + 6) * 2 - 6
+_y = (\4) * -2
+_x = \3_WIDTH * 2 - 1
+_len = CURRENT_MAP_HEIGHT + 3 - (\4)
+if _len > \3_HEIGHT
+_len = \3_HEIGHT
+endc
+
+elif "\1" == "east"
+_blk = (\3_WIDTH * _src)
+_map = (CURRENT_MAP_WIDTH + 6) * _tgt + CURRENT_MAP_WIDTH + 3
+_win = \3_WIDTH + 7
+_y = (\4) * -2
+_x = 0
+_len = CURRENT_MAP_HEIGHT + 3 - (\4)
+if _len > \3_HEIGHT
+_len = \3_HEIGHT
+endc
+
+else
+fail "Invalid direction for 'connection'."
+endc
+
+ db \3
+ dw \2_Blocks + _blk
+ dw wOverworldMap + _map
+ db _len - _src
+ db \3_WIDTH
+ db _y, _x
+ dw wOverworldMap + _win
+ENDM
diff --git a/macros/text_macros.asm b/macros/scripts/text.asm
index 21e02634..732a22d4 100755
--- a/macros/text_macros.asm
+++ b/macros/scripts/text.asm
@@ -1,5 +1,3 @@
-
-; text macros
text EQUS "db $00," ; Start writing text.
next EQUS "db $4e," ; Move a line down.
line EQUS "db $4f," ; Start writing at the bottom line.
diff --git a/macros/wram.asm b/macros/wram.asm
new file mode 100644
index 00000000..7a9b4a6a
--- /dev/null
+++ b/macros/wram.asm
@@ -0,0 +1,92 @@
+; Used in wram.asm
+
+flag_array: MACRO
+ ds ((\1) + 7) / 8
+ENDM
+
+BOX_STRUCT_LENGTH EQU 25 + NUM_MOVES * 2
+
+box_struct: MACRO
+\1Species:: db
+\1HP:: dw
+\1BoxLevel:: db
+\1Status:: db
+\1Type::
+\1Type1:: db
+\1Type2:: db
+\1CatchRate:: db
+\1Moves:: ds NUM_MOVES
+\1OTID:: dw
+\1Exp:: ds 3
+\1HPExp:: dw
+\1AttackExp:: dw
+\1DefenseExp:: dw
+\1SpeedExp:: dw
+\1SpecialExp:: dw
+\1DVs:: ds 2
+\1PP:: ds NUM_MOVES
+ENDM
+
+party_struct: MACRO
+ box_struct \1
+\1Level:: db
+\1Stats::
+\1MaxHP:: dw
+\1Attack:: dw
+\1Defense:: dw
+\1Speed:: dw
+\1Special:: dw
+ENDM
+
+battle_struct: MACRO
+\1Species:: db
+\1HP:: dw
+\1PartyPos::
+\1BoxLevel:: db
+\1Status:: db
+\1Type::
+\1Type1:: db
+\1Type2:: db
+\1CatchRate:: db
+\1Moves:: ds NUM_MOVES
+\1DVs:: ds 2
+\1Level:: db
+\1Stats::
+\1MaxHP:: dw
+\1Attack:: dw
+\1Defense:: dw
+\1Speed:: dw
+\1Special:: dw
+\1PP:: ds NUM_MOVES
+ENDM
+
+spritestatedata1: MACRO
+\1PictureID:: db
+\1MovementStatus:: db
+\1ImageIndex:: db
+\1YStepVector:: db
+\1YPixels:: db
+\1XStepVector:: db
+\1XPixels:: db
+\1IntraAnimFrameCounter:: db
+\1AnimFrameCounter:: db
+\1FacingDirection:: db
+ ds 6
+\1End::
+ENDM
+
+spritestatedata2: MACRO
+\1WalkAnimationCounter:: db
+ ds 1
+\1YDisplacement:: db
+\1XDisplacement:: db
+\1MapY:: db
+\1MapX:: db
+\1MovementByte1:: db
+\1GrassPriority:: db
+\1MovementDelay:: db
+ ds 5
+\1ImageBaseOffset:: db
+ ds 1
+\1End::
+ENDM