Skip to content

Commit

Permalink
Use rgbds 0.5.0 features:
Browse files Browse the repository at this point in the history
- FOR loops
- {interpolation}
- REDEF EQUS
- \# for all macro args
  • Loading branch information
Rangi42 committed Apr 17, 2021
1 parent 4b64b14 commit dd69092
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 163 deletions.
23 changes: 5 additions & 18 deletions constants/item_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -128,17 +128,10 @@ IF !DEF(HM01)
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

Expand All @@ -159,15 +152,9 @@ IF !DEF(TM01)
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

Expand Down
24 changes: 4 additions & 20 deletions data/moves/tmhm_moves.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 3 additions & 4 deletions data/tilesets/collision_tile_ids.asm
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
coll_tiles: MACRO
REPT _NARG
db \1
shift
ENDR
IF _NARG
db \# ; all args
ENDC
db -1 ; end
ENDM

Expand Down
7 changes: 3 additions & 4 deletions data/tilesets/door_tile_ids.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ DoorTileIDPointers:
db -1 ; end

door_tiles: MACRO
REPT _NARG
db \1
shift
ENDR
IF _NARG
db \# ; all args
ENDC
db 0 ; end
ENDM

Expand Down
7 changes: 3 additions & 4 deletions data/tilesets/warp_carpet_tile_ids.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ WarpTileListPointers:
dw .FacingRightWarpTiles

warp_carpet_tiles: MACRO
REPT _NARG
db \1
shift
ENDR
IF _NARG
db \# ; all args
ENDC
db -1 ; end
ENDM

Expand Down
7 changes: 3 additions & 4 deletions data/tilesets/warp_tile_ids.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ WarpTileIDPointers:
assert_table_length NUM_TILESETS

warp_tiles: MACRO
REPT _NARG
db \1
shift
ENDR
IF _NARG
db \# ; all args
ENDC
db -1 ; end
ENDM

Expand Down
7 changes: 3 additions & 4 deletions data/trainers/move_choices.asm
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions engine/overworld/healing_machine.asm
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ FlashSprite8Times:

CopyHealingMachineOAM:
; copy one OAM entry and advance the pointers
REPT 4
REPT 4
ld a, [de]
inc de
ld [hli], a
ENDR
ENDR
ret
22 changes: 9 additions & 13 deletions home/vcopy.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ClearBgMap::
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
Expand Down Expand Up @@ -69,7 +69,7 @@ RedrawRowOrColumn::
.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
Expand Down Expand Up @@ -169,21 +169,19 @@ AutoBgMapTransfer::

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
Expand Down Expand Up @@ -261,7 +259,7 @@ VBlankCopyDouble::
ldh [hVBlankCopyDoubleSize], a

.loop
REPT 3
REPT LEN_2BPP_TILE / 4 - 1
pop de
ld [hl], e
inc l
Expand All @@ -271,8 +269,7 @@ VBlankCopyDouble::
inc l
ld [hl], d
inc l
ENDR

ENDR
pop de
ld [hl], e
inc l
Expand Down Expand Up @@ -339,14 +336,13 @@ VBlankCopy::
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
Expand Down
42 changes: 15 additions & 27 deletions macros/asserts.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -46,42 +40,36 @@ ENDM

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

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
20 changes: 5 additions & 15 deletions macros/data.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,23 @@ money EQUS "bcd3"
; 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
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
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

Expand Down
8 changes: 4 additions & 4 deletions macros/scripts/events.asm
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ ENDM
SetEvents: MACRO
SetEvent \1
REPT _NARG - 1
SetEventReuseHL \2
SHIFT
SetEventReuseHL \2
SHIFT
ENDR
ENDM

Expand Down Expand Up @@ -236,8 +236,8 @@ ENDM
ResetEvents: MACRO
ResetEvent \1
REPT _NARG - 1
ResetEventReuseHL \2
SHIFT
ResetEventReuseHL \2
SHIFT
ENDR
ENDM

Expand Down
Loading

0 comments on commit dd69092

Please sign in to comment.