ref: dd690920c9f8502b649f1022fadbb99fab67a44a
parent: 4b64b146e4d723980d26470d171fb18e63f4a215
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Sat Apr 17 15:06:56 EDT 2021
Use rgbds 0.5.0 features: - FOR loops - {interpolation} - REDEF EQUS - \# for all macro args
--- a/constants/item_constants.asm
+++ b/constants/item_constants.asm
@@ -29,8 +29,8 @@
const POTION ; $14
const BOULDERBADGE ; $15
const CASCADEBADGE ; $16
-SAFARI_BAIT EQU $15 ; overload
-SAFARI_ROCK EQU $16 ; overload
+SAFARI_BAIT EQU $15 ; overload
+SAFARI_ROCK EQU $16 ; overload
const THUNDERBADGE ; $17
const RAINBOWBADGE ; $18
const SOULBADGE ; $19
@@ -128,17 +128,10 @@
HM01 EQU const_value
__tmhm_value__ = NUM_TMS + 1
ENDC
-HM_VALUE EQU __tmhm_value__ - NUM_TMS
-IF HM_VALUE < 10
-MOVE_FOR_HM EQUS "HM0{d:HM_VALUE}_MOVE"
-ELSE
-MOVE_FOR_HM EQUS "HM{d:HM_VALUE}_MOVE"
-ENDC
-MOVE_FOR_HM = \1
-PURGE MOVE_FOR_HM
-PURGE HM_VALUE
const HM_\1
\1_TMNUM EQU __tmhm_value__
+__HM_VALUE = __tmhm_value__ - NUM_TMS
+HM{02d:__HM_VALUE}_MOVE EQU \1
__tmhm_value__ = __tmhm_value__ + 1
ENDM
@@ -159,15 +152,9 @@
TM01 EQU const_value
__tmhm_value__ = 1
ENDC
-IF __tmhm_value__ < 10
-MOVE_FOR_TM EQUS "TM0{d:__tmhm_value__}_MOVE"
-ELSE
-MOVE_FOR_TM EQUS "TM{d:__tmhm_value__}_MOVE"
-ENDC
-MOVE_FOR_TM = \1
-PURGE MOVE_FOR_TM
const TM_\1
\1_TMNUM EQU __tmhm_value__
+TM{02d:__tmhm_value__}_MOVE EQU \1
__tmhm_value__ = __tmhm_value__ + 1
ENDM
--- a/data/moves/tmhm_moves.asm
+++ b/data/moves/tmhm_moves.asm
@@ -4,28 +4,12 @@
TechnicalMachines:
table_width 1, TechnicalMachines
-n = 1
-REPT NUM_TMS
-IF n < 10
-MOVE_FOR_TM EQUS "TM0{d:n}_MOVE"
-ELSE
-MOVE_FOR_TM EQUS "TM{d:n}_MOVE"
-ENDC
- db MOVE_FOR_TM
-PURGE MOVE_FOR_TM
-n = n + 1
+FOR n, 1, NUM_TMS + 1
+ db TM{02d:n}_MOVE
ENDR
assert_table_length NUM_TMS
-n = 1
-REPT NUM_HMS
-IF n < 10
-MOVE_FOR_HM EQUS "HM0{d:n}_MOVE"
-ELSE
-MOVE_FOR_HM EQUS "HM{d:n}_MOVE"
-ENDC
- db MOVE_FOR_HM
-PURGE MOVE_FOR_HM
-n = n + 1
+FOR n, 1, NUM_HMS + 1
+ db HM{02d:n}_MOVE
ENDR
assert_table_length NUM_TM_HM
--- a/data/tilesets/collision_tile_ids.asm
+++ b/data/tilesets/collision_tile_ids.asm
@@ -1,8 +1,7 @@
coll_tiles: MACRO
-REPT _NARG
- db \1
- shift
-ENDR
+ IF _NARG
+ db \# ; all args
+ ENDC
db -1 ; end
ENDM
--- a/data/tilesets/door_tile_ids.asm
+++ b/data/tilesets/door_tile_ids.asm
@@ -15,10 +15,9 @@
db -1 ; end
door_tiles: MACRO
-REPT _NARG
- db \1
- shift
-ENDR
+ IF _NARG
+ db \# ; all args
+ ENDC
db 0 ; end
ENDM
--- a/data/tilesets/warp_carpet_tile_ids.asm
+++ b/data/tilesets/warp_carpet_tile_ids.asm
@@ -5,10 +5,9 @@
dw .FacingRightWarpTiles
warp_carpet_tiles: MACRO
-REPT _NARG
- db \1
- shift
-ENDR
+ IF _NARG
+ db \# ; all args
+ ENDC
db -1 ; end
ENDM
--- a/data/tilesets/warp_tile_ids.asm
+++ b/data/tilesets/warp_tile_ids.asm
@@ -27,10 +27,9 @@
assert_table_length NUM_TILESETS
warp_tiles: MACRO
-REPT _NARG
- db \1
- shift
-ENDR
+ IF _NARG
+ db \# ; all args
+ ENDC
db -1 ; end
ENDM
--- a/data/trainers/move_choices.asm
+++ b/data/trainers/move_choices.asm
@@ -1,8 +1,7 @@
move_choices: MACRO
-REPT _NARG
- db \1
- shift
-ENDR
+ IF _NARG
+ db \# ; all args
+ ENDC
db 0 ; end
list_index = list_index + 1
ENDM
--- a/engine/overworld/healing_machine.asm
+++ b/engine/overworld/healing_machine.asm
@@ -91,9 +91,9 @@
CopyHealingMachineOAM:
; copy one OAM entry and advance the pointers
- REPT 4
+REPT 4
ld a, [de]
inc de
ld [hli], a
- ENDR
+ENDR
ret
--- a/home/vcopy.asm
+++ b/home/vcopy.asm
@@ -23,7 +23,7 @@
jr .next
ld a, l
.next
- ld de, $400 ; size of VRAM background map
+ ld de, BG_MAP_WIDTH * BG_MAP_HEIGHT
ld l, e
.loop
ld [hli], a
@@ -69,7 +69,7 @@
.noCarry
; the following 4 lines wrap us from bottom to top if necessary
ld a, d
- and $03
+ and $3
or $98
ld d, a
dec c
@@ -169,21 +169,19 @@
TransferBgRows::
; unrolled loop and using pop for speed
-
- REPT 20 / 2 - 1
+REPT SCREEN_WIDTH / 2 - 1
pop de
ld [hl], e
inc l
ld [hl], d
inc l
- ENDR
-
+ENDR
pop de
ld [hl], e
inc l
ld [hl], d
- ld a, 32 - (20 - 1)
+ ld a, BG_MAP_WIDTH - (SCREEN_WIDTH - 1)
add l
ld l, a
jr nc, .ok
@@ -261,7 +259,7 @@
ldh [hVBlankCopyDoubleSize], a
.loop
- REPT 3
+REPT LEN_2BPP_TILE / 4 - 1
pop de
ld [hl], e
inc l
@@ -271,8 +269,7 @@
inc l
ld [hl], d
inc l
- ENDR
-
+ENDR
pop de
ld [hl], e
inc l
@@ -339,14 +336,13 @@
ldh [hVBlankCopySize], a
.loop
- REPT 7
+REPT LEN_2BPP_TILE / 2 - 1
pop de
ld [hl], e
inc l
ld [hl], d
inc l
- ENDR
-
+ENDR
pop de
ld [hl], e
inc l
--- a/macros/asserts.asm
+++ b/macros/asserts.asm
@@ -2,33 +2,27 @@
table_width: MACRO
CURRENT_TABLE_WIDTH = \1
-IF DEF(CURRENT_TABLE_START)
-PURGE CURRENT_TABLE_START
-ENDC
IF _NARG == 2
-CURRENT_TABLE_START EQUS "\2"
+REDEF CURRENT_TABLE_START EQUS "\2"
ELSE
-CURRENT_TABLE_START EQUS "._table_width\@"
-CURRENT_TABLE_START:
+REDEF CURRENT_TABLE_START EQUS "._table_width\@"
+{CURRENT_TABLE_START}:
ENDC
ENDM
assert_table_length: MACRO
x = \1
- ASSERT x * CURRENT_TABLE_WIDTH == @ - CURRENT_TABLE_START, \
+ ASSERT x * CURRENT_TABLE_WIDTH == @ - {CURRENT_TABLE_START}, \
"{CURRENT_TABLE_START}: expected {d:x} entries, each {d:CURRENT_TABLE_WIDTH} bytes"
ENDM
list_start: MACRO
list_index = 0
-IF DEF(CURRENT_LIST_START)
-PURGE CURRENT_LIST_START
-ENDC
IF _NARG == 1
-CURRENT_LIST_START EQUS "\1"
+REDEF CURRENT_LIST_START EQUS "\1"
ELSE
-CURRENT_LIST_START EQUS "._list_start\@"
-CURRENT_LIST_START:
+REDEF CURRENT_LIST_START EQUS "._list_start\@"
+{CURRENT_LIST_START}:
ENDC
ENDM
@@ -46,21 +40,18 @@
def_grass_wildmons: MACRO
;\1: encounter rate
-if DEF(CURRENT_GRASS_WILDMONS_LABEL)
-PURGE CURRENT_GRASS_WILDMONS_LABEL
-endc
CURRENT_GRASS_WILDMONS_RATE = \1
-CURRENT_GRASS_WILDMONS_LABEL EQUS "._def_grass_wildmons_\1"
-CURRENT_GRASS_WILDMONS_LABEL:
+REDEF CURRENT_GRASS_WILDMONS_LABEL EQUS "._def_grass_wildmons_\1"
+{CURRENT_GRASS_WILDMONS_LABEL}:
db \1
ENDM
end_grass_wildmons: MACRO
IF CURRENT_GRASS_WILDMONS_RATE == 0
- assert 1 == @ - CURRENT_GRASS_WILDMONS_LABEL, \
+ assert 1 == @ - {CURRENT_GRASS_WILDMONS_LABEL}, \
"def_grass_wildmons {d:CURRENT_GRASS_WILDMONS_RATE}: expected 1 byte"
ELSE
- assert WILDDATA_LENGTH == @ - CURRENT_GRASS_WILDMONS_LABEL, \
+ assert WILDDATA_LENGTH == @ - {CURRENT_GRASS_WILDMONS_LABEL}, \
"def_grass_wildmons {d:CURRENT_GRASS_WILDMONS_RATE}: expected {d:WILDDATA_LENGTH} bytes"
ENDC
ENDM
@@ -67,21 +58,18 @@
def_water_wildmons: MACRO
;\1: encounter rate
-if DEF(CURRENT_WATER_WILDMONS_LABEL)
-PURGE CURRENT_WATER_WILDMONS_LABEL
-endc
CURRENT_WATER_WILDMONS_RATE = \1
-CURRENT_WATER_WILDMONS_LABEL EQUS "._def_water_wildmons_\1"
-CURRENT_WATER_WILDMONS_LABEL:
+REDEF CURRENT_WATER_WILDMONS_LABEL EQUS "._def_water_wildmons_\1"
+{CURRENT_WATER_WILDMONS_LABEL}:
db \1
ENDM
end_water_wildmons: MACRO
IF CURRENT_WATER_WILDMONS_RATE == 0
- assert 1 == @ - CURRENT_WATER_WILDMONS_LABEL, \
+ assert 1 == @ - {CURRENT_WATER_WILDMONS_LABEL}, \
"def_water_wildmons {d:CURRENT_WATER_WILDMONS_RATE}: expected 1 byte"
ELSE
- assert WILDDATA_LENGTH == @ - CURRENT_WATER_WILDMONS_LABEL, \
+ assert WILDDATA_LENGTH == @ - {CURRENT_WATER_WILDMONS_LABEL}, \
"def_water_wildmons {d:CURRENT_WATER_WILDMONS_RATE}: expected {d:WILDDATA_LENGTH} bytes"
ENDC
ENDM
--- a/macros/data.asm
+++ b/macros/data.asm
@@ -19,12 +19,8 @@
; used in data/pokemon/base_stats/*.asm
tmhm: MACRO
; initialize bytes to 0
-n = 0
-REPT (NUM_TM_HM + 7) / 8
-_TM_BYTE EQUS "_tm{d:n}"
-_TM_BYTE = 0
-PURGE _TM_BYTE
-n = n + 1
+FOR n, (NUM_TM_HM + 7) / 8
+_tm{d:n} = 0
ENDR
; set bits of bytes
REPT _NARG
@@ -31,9 +27,7 @@
IF DEF(\1_TMNUM)
n = (\1_TMNUM - 1) / 8
i = (\1_TMNUM - 1) % 8
-_TM_BYTE EQUS "_tm{d:n}"
-_TM_BYTE = _TM_BYTE | (1 << i)
-PURGE _TM_BYTE
+_tm{d:n} = _tm{d:n} | (1 << i)
ELSE
FAIL "\1 is not a TM or HM move"
ENDC
@@ -40,12 +34,8 @@
SHIFT
ENDR
; output bytes
-n = 0
-REPT (NUM_TM_HM + 7) / 8
-_TM_BYTE EQUS "_tm{d:n}"
- db _TM_BYTE
-PURGE _TM_BYTE
-n = n + 1
+FOR n, (NUM_TM_HM + 7) / 8
+ db _tm{d:n}
ENDR
ENDM
--- a/macros/scripts/events.asm
+++ b/macros/scripts/events.asm
@@ -184,8 +184,8 @@
SetEvents: MACRO
SetEvent \1
REPT _NARG - 1
- SetEventReuseHL \2
- SHIFT
+ SetEventReuseHL \2
+ SHIFT
ENDR
ENDM
@@ -236,8 +236,8 @@
ResetEvents: MACRO
ResetEvent \1
REPT _NARG - 1
- ResetEventReuseHL \2
- SHIFT
+ ResetEventReuseHL \2
+ SHIFT
ENDR
ENDM
--- a/macros/scripts/maps.asm
+++ b/macros/scripts/maps.asm
@@ -1,10 +1,7 @@
def_objects: MACRO
- IF DEF(_NUM_OBJECTS)
- PURGE _NUM_OBJECTS
- ENDC
-_NUM_OBJECTS EQUS "_NUM_OBJECTS_\@"
- db _NUM_OBJECTS
-_NUM_OBJECTS = 0
+REDEF _NUM_OBJECTS EQUS "_NUM_OBJECTS_\@"
+ db {_NUM_OBJECTS}
+{_NUM_OBJECTS} = 0
ENDM
;\1 sprite id
@@ -32,16 +29,13 @@
ELSE
db \6
ENDC
-_NUM_OBJECTS = _NUM_OBJECTS + 1
+{_NUM_OBJECTS} = {_NUM_OBJECTS} + 1
ENDM
def_warps: MACRO
- IF DEF(_NUM_WARPS)
- PURGE _NUM_WARPS
- ENDC
-_NUM_WARPS EQUS "_NUM_WARPS_\@"
- db _NUM_WARPS
-_NUM_WARPS = 0
+REDEF _NUM_WARPS EQUS "_NUM_WARPS_\@"
+ db {_NUM_WARPS}
+{_NUM_WARPS} = 0
ENDM
;\1 x position
@@ -50,19 +44,15 @@
;\4 destination map (-1 = wLastMap)
warp: MACRO
db \2, \1, \3, \4
-_TMP EQUS "\n_WARP_{d:{_NUM_WARPS}}_X = \1\n_WARP_{d:{_NUM_WARPS}}_Y = \2"
- _TMP
- PURGE _TMP
-_NUM_WARPS = _NUM_WARPS + 1
+_WARP_{d:{_NUM_WARPS}}_X = \1
+_WARP_{d:{_NUM_WARPS}}_Y = \2
+{_NUM_WARPS} = {_NUM_WARPS} + 1
ENDM
def_signs: MACRO
- IF DEF(_NUM_SIGNS)
- PURGE _NUM_SIGNS
- ENDC
-_NUM_SIGNS EQUS "_NUM_SIGNS_\@"
- db _NUM_SIGNS
-_NUM_SIGNS = 0
+REDEF _NUM_SIGNS EQUS "_NUM_SIGNS_\@"
+ db {_NUM_SIGNS}
+{_NUM_SIGNS} = 0
ENDM
;\1 x position
@@ -70,17 +60,13 @@
;\3 sign id
sign: MACRO
db \2, \1, \3
-_NUM_SIGNS = _NUM_SIGNS + 1
+{_NUM_SIGNS} = {_NUM_SIGNS} + 1
ENDM
;\1 source map
def_warps_to: MACRO
-N = 0
- REPT _NUM_WARPS
-_TMP EQUS "warp_to _WARP_{d:N}_X, _WARP_{d:N}_Y, \1_WIDTH"
- _TMP
- PURGE _TMP
-N = N + 1
+ FOR n, _NUM_WARPS
+ warp_to _WARP_{d:n}_X, _WARP_{d:n}_Y, \1_WIDTH
ENDR
ENDM
@@ -146,10 +132,8 @@
; 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
+ dw {CURRENT_MAP_OBJECT}
+ PURGE CURRENT_MAP_WIDTH, CURRENT_MAP_HEIGHT, CURRENT_MAP_OBJECT
ENDM
; Connections go in order: north, south, west, east
--- a/macros/scripts/text.asm
+++ b/macros/scripts/text.asm
@@ -169,10 +169,9 @@
script_mart: MACRO
db TX_SCRIPT_MART
db _NARG ; number of items
-REPT _NARG
- db \1 ; item id
- SHIFT
-ENDR
+ IF _NARG
+ db \# ; all item ids
+ ENDC
db -1 ; end
ENDM
--- a/rgbdscheck.asm
+++ b/rgbdscheck.asm
@@ -1,14 +1,18 @@
-; pokered requires rgbds 0.4.2 or newer.
MAJOR EQU 0
-MINOR EQU 4
-PATCH EQU 2
+MINOR EQU 5
+PATCH EQU 0
+wrong_rgbds: MACRO
+ fail "pokered requires rgbds v0.5.0 or newer."
+ENDM
+
IF !DEF(__RGBDS_MAJOR__) || !DEF(__RGBDS_MINOR__) || !DEF(__RGBDS_PATCH__)
- fail "pokered requires rgbds 0.4.2 or newer."
+ wrong_rgbds
ELSE
IF (__RGBDS_MAJOR__ < MAJOR) || \
(__RGBDS_MAJOR__ == MAJOR && __RGBDS_MINOR__ < MINOR) || \
- (__RGBDS_MAJOR__ == MAJOR && __RGBDS_MINOR__ == MINOR && __RGBDS_PATCH__ < PATCH)
- fail "pokered requires rgbds 0.4.2 or newer."
+ (__RGBDS_MAJOR__ == MAJOR && __RGBDS_MINOR__ == MINOR && __RGBDS_PATCH__ < PATCH) || \
+ (__RGBDS_MAJOR__ == MAJOR && __RGBDS_MINOR__ == MINOR && __RGBDS_PATCH__ == PATCH && DEF(__RGBDS_RC__))
+ wrong_rgbds
ENDC
ENDC