Update const.asm

This commit is contained in:
Engezerstorung 2026-01-09 13:50:00 +01:00
parent 83944eb126
commit f617232502
5 changed files with 146 additions and 75 deletions

View File

@ -49,7 +49,7 @@ DEF FIRST_SE_ID EQU const_value
; The 0 or 1 in the name of a subanim indicates whether to use tileset 0 or 1 data/moves/animations.asm.
; "Both" indicates either can be used for different images using the same animation.
const_def 0, 1, SUBANIM_CONST_LIMIT
max_const_def SUBANIM_CONST_LIMIT
const SUBANIM_0_STAR
const SUBANIM_0_STAR_TWICE
const SUBANIM_0_STAR_THRICE

View File

@ -5,7 +5,7 @@
; - CryData (see data/pokemon/cries.asm)
; - PokedexOrder (see data/pokemon/dex_order.asm)
; - PokedexEntryPointers (see data/pokemon/dex_entries.asm)
const_def 0, 1, OPP_ID_OFFSET - 1
max_const_def OPP_ID_OFFSET - 1
; Pokemons and trainers share ID values.
; Note : even without this limitation, they would be limited to $FD.
const NO_MON ; $00

View File

@ -1,15 +1,14 @@
; sprite facing directions
const_def 0, $04, $0C
const SPRITE_FACING_DOWN ; $00
const SPRITE_FACING_UP ; $04
const SPRITE_FACING_LEFT ; $08
const SPRITE_FACING_RIGHT ; $0C
MACRO sprite_facing_const
const \1
DEF \2 EQU \1 << 4
ENDM
const_def 0, $40, $C0
const NPC_MOVEMENT_DOWN ; $00
const NPC_MOVEMENT_UP ; $40
const NPC_MOVEMENT_LEFT ; $80
const NPC_MOVEMENT_RIGHT ; $C0
; sprite facing directions
nybble_const_def 0, $4
sprite_facing_const SPRITE_FACING_DOWN, NPC_MOVEMENT_DOWN ; $00, $00
sprite_facing_const SPRITE_FACING_UP, NPC_MOVEMENT_UP ; $04, $40
sprite_facing_const SPRITE_FACING_LEFT, NPC_MOVEMENT_LEFT ; $08, $80
sprite_facing_const SPRITE_FACING_RIGHT, NPC_MOVEMENT_RIGHT ; $0C, $C0
DEF NPC_CHANGE_FACING EQU $E0

View File

@ -6,7 +6,7 @@ DEF TILESET_CONST_LIMIT EQU $FF / 8
; tileset ids
; Tilesets indexes (see data/tilesets/tileset_headers.asm)
const_def 0, 1, TILESET_CONST_LIMIT
max_const_def TILESET_CONST_LIMIT
const OVERWORLD ; 0
const REDS_HOUSE_1 ; 1
const MART ; 2

View File

@ -1,5 +1,9 @@
; Enumerate constants
; Arguments :
; \1 starting constant value
; \2 incrementation value
; \3 constant value limit
MACRO? const_def
DEF const_format = $FF
const_def_common \#
@ -7,11 +11,13 @@ ENDM
MACRO? bit_const_def
DEF const_format = $7
REDEF const_format_string EQUS "bit"
const_def_common \#
ENDM
MACRO? nybble_const_def
DEF const_format = $F
REDEF const_format_string EQUS "nybble"
const_def_common \#
ENDM
@ -20,81 +26,47 @@ MACRO? word_const_def
const_def_common \#
ENDM
; Disable constant limit verification.
MACRO? unlimited_const_def
ASSERT _NARG <= 2, "Third argument found, unlimited_const_def disable constant value limitations."
ASSERT WARN, _NARG <= 2, "Third argument found, unlimited_const_def disable constant value limitations."
DEF const_format = $FFFFFFFF
const_def_common \#
ENDM
MACRO? listable_const_def ; Some functions like IsInArray use value $FF as a list terminator.
IF _NARG == 1
const_def \1, 1, $FE
ELIF _NARG == 2
const_def \1, \2, $FE
ELSE
ASSERT _NARG <= 2, "Third argument found, listable_const_def already define constant value limit as $FE."
const_def 0, 1, $FE
ENDC
; Some functions like IsInArray use value $FF as a list terminator. Predefine constant limit as $FE
MACRO? listable_const_def
ASSERT WARN, _NARG <= 2, "Third argument found, listable_const_def already define constant value limit as $FE."
max_const_def $FE, \#
ENDM
MACRO? const_def_common
IF _NARG >= 1
DEF const_value = \1
ELSE
DEF const_value = 0
ENDC
; max_* variations of the macros define the constant limit with the first argument
MACRO? max_const_def
DEF const_format = $FF
max_const_def_common \#
ENDM
IF _NARG >= 2
DEF const_inc = \2
ELSE
DEF const_inc = 1
ENDC
IF const_inc > 0
REDEF const_size_compare EQUS "bigger"
DEF const_inc_sign = 1
ELSE ; const_inc < 0
REDEF const_size_compare EQUS "smaller"
DEF const_inc_sign = -1
ENDC
IF const_value >= 0 && const_inc > 0
DEF const_limit_offset = 0
ELIF const_value < 0 && const_inc < 0
DEF const_limit_offset = -1
ELSE
DEF const_limit_offset = const_value
ENDC
MACRO? max_bit_const_def
DEF const_format = $7
REDEF const_format_string EQUS "bit"
max_const_def_common \#
ENDM
; Checking if the starting constant value is coherant with the value format chosen.
IF (const_format == $7 || const_format == $F) && (const_value > const_format || const_value < 0)
IF const_format == $7
fail "Starting bit_const_def value {d:const_value} outside of range [0 , 7]."
ELSE ; const_format == $F
fail "Starting nybble_const_def value {const_value} outside of range [$0 , $F]."
ENDC
ELIF const_format == $FF && (const_value < -$100 || const_value > $FF)
fail "Starting const_def value {const_value} outside of range [-$100, $FF], use word_const_def instead."
ENDC
MACRO? max_nybble_const_def
DEF const_format = $F
REDEF const_format_string EQUS "nybble"
max_const_def_common \#
ENDM
IF const_format != $FFFFFFFF
IF _NARG >= 3
DEF const_limit = \3
ELIF const_format == $F || const_format == 7
IF const_inc < 0
DEF const_limit = 0
ELSE
DEF const_limit = const_format
ENDC
ELSE
DEF const_limit = const_limit_offset + const_inc_sign * const_format
ENDC
ENDC
MACRO? max_word_const_def
DEF const_format = $FFFF
max_const_def_common \#
ENDM
MACRO? const
IF (const_format != $FFFFFFFF) && ((const_inc > 0 && const_value > const_limit) || (const_inc < 0 && const_value < const_limit))
fail "Constant value cannot be {const_size_compare} than {const_limit}. Tried to define constant \1 for value {const_value}."
fail "Constant value cannot be {const_size_compare} than {const_limit}. Attempted to define constant \1 for value {const_value}."
ELSE
DEF \1 EQU const_value & const_format
DEF \1 EQU const_value
DEF const_value += const_inc
ENDC
ENDM
@ -119,7 +91,7 @@ ENDM
MACRO? const_next
if (const_inc > 0 && \1 < const_value) || (const_inc < 0 && \1 > const_value)
def failed_const_value = \1
DEF failed_const_value = \1
fail "const_next cannot go backwards from {const_value} to {failed_const_value}"
else
DEF const_value = \1
@ -138,3 +110,103 @@ MACRO? rb_skip
rsset _RS + 1
ENDC
ENDM
; Macros past this comment arent meant to be used by themselves
MACRO? max_const_def_common
IF _NARG >= 3
const_def_common \2, \3, \1
ELIF _NARG >= 2
const_def_common \2, 1, \1
ELIF _NARG >= 1
const_def_common 0, 1, \1
ELSE
const_def_common 0, 1
ENDC
ENDM
MACRO? const_def_common
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
; pass all constant limit related operations if unlimited_const_def
IF const_format != $FFFFFFFF
IF const_inc > 0
REDEF const_size_compare EQUS "bigger"
ELSE ; const_inc < 0
REDEF const_size_compare EQUS "smaller"
ENDC
const_def_common_{const_format} \#
; check the coherance of the starting value and constant limit.
IF (const_format == $7 || const_format == $F) && (const_limit < 0 || const_limit > const_format)
fail "Constant limit {const_limit} for {const_format_string}_const_def outside of range [$0 , {const_format}]"
ELIF (const_format == $7 || const_format == $F) && (const_value < 0 || const_value > const_format)
fail "Starting constant value {const_value} for {const_format_string}_const_def outside of range [$0 , {const_format}]."
ELIF (const_inc > 0 && const_value > const_limit) || (const_inc < 0 && const_value < const_limit)
fail "Starting constant value {const_value} {const_size_compare} than constant limit value {const_limit}."
ELIF ((const_limit > 0 && const_value < 0) && (const_value & const_format) < const_limit)
DEF failed_const_value = const_value & const_format
fail "Starting constant value and constant limit allow an overlap in constant value range [{failed_const_value} , {const_limit}]."
ELIF ((const_limit < 0 && const_value > 0) && const_value > (const_limit & const_format))
DEF failed_const_value = const_limit & const_format
fail "Starting constant value and constant limit allow an overlap in constant value range [{failed_const_value} , {const_value}]."
ELIF ((const_value & const_format) != const_value && (const_value & const_format) == const_limit) || \
((const_limit & const_format) != const_limit && const_value == (const_limit & const_format))
DEF failed_const_value = const_value & const_format
fail "Starting constant value and constant limit allow an overlap on constant value {failed_const_value}."
ENDC
ENDC
ENDM
MACRO? const_def_common_$FFFF
const_def_common_$FF \#
ENDM
MACRO? const_def_common_$FF
IF const_value >= 0 && const_inc > 0
DEF const_limit_offset = 0
ELIF const_value < 0 && const_inc < 0
DEF const_limit_offset = -1
ELSE
DEF const_limit_offset = const_value
ENDC
; change default $FF const_format to $FFFF if starting constant value is outside of [-$100 ; $FF] range
IF const_format == $FF && (const_value < -$100 || const_value > $FF)
DEF const_format = $FFFF
ENDC
IF _NARG >= 3
DEF const_limit = \3
; change default $FF const_format to $FFFF if constant limit is outside of [-$100 ; $FF] range
IF const_format == $FF && (const_limit < -$100 || const_limit > $FF)
DEF const_format = $FFFF
ENDC
ELIF const_inc < 0
DEF const_limit = const_limit_offset - const_format
ELSE
DEF const_limit = const_limit_offset + const_format
ENDC
ENDM
MACRO? const_def_common_$F
const_def_common_$7 \#
ENDM
MACRO? const_def_common_$7
IF _NARG >= 3
DEF const_limit = \3
; set constant limit to 0 for negative increment and to const_format for positive
ELIF const_inc < 0
DEF const_limit = 0
ELSE
DEF const_limit = const_format
ENDC
ENDM