rgbds icon indicating copy to clipboard operation
rgbds copied to clipboard

[Feature request] Enums

Open Rangi42 opened this issue 4 years ago • 4 comments

Macro Assembler AS has enums, similar to the ones implemented by pret's const macros. They define a series of numeric constants with a configurable starting value and increment value.

; rgbasm
foo equ 1
bar equ 3
baz equ 5
; AS
enumconf 2
enum foo = 1
enum bar
enum baz
; pret
const_def 1, 2
const foo
const bar
const baz

Rangi42 avatar Feb 01 '21 19:02 Rangi42

Why not _RS?

rsreset
foo rb
bar rb
baz rb

ISSOtm avatar Feb 10 '21 09:02 ISSOtm

RS is meant for defining relative offset constants, e.g. for structs. Apart from the name "rb" being less appropriate for defining general-purpose constants, it's also that RS has features irrelevant to enums, and vice-versa.

If you're defining a series of enum constants using rb, then the feature allows you to use rb 2, rw, rs 12, which don't make sense in that context. Plus, RS constants have no ability to change the increment value, which can be useful for enums. Compare:

enumconf 1, 2
enum foo
enum bar
enum baz

with:

rsset 1
foo rb 2
bar rb 2
baz rb 2

Or:

enumconf $FF, -1
enum ENTER_MAP_MUSIC
enum RESTART_MAP_MUSIC
enum SPECIAL_MUSIC

with:

rsset $FF - 3 + 1
SPECIAL_MUSIC rb
RESTART_MAP_MUSIC rb
ENTER_MAP_MUSIC rb

pret has its const macros for this purpose, which do not use rsset internally; we're planning to use rsset for its stated purpose of defining struct offsets (currently we have no consistent approach for those), but not for constants in general. Aevilia-GB also has enum macros. LADX so far defines all its constants as explicit EQU values even when they're in a series, but it's still in progress, maybe they'll simplify it.

Rangi42 avatar Feb 10 '21 16:02 Rangi42

Aevilia uses macros because I mimicked pokered, but my more recent (not yet published) works use _RS.

ISSOtm avatar Feb 11 '21 23:02 ISSOtm

Fair enough, but I would be surprised to see something like:

rsset 1
BULBASAUR rb
IVYSAUR   rb
VENUSAUR  rb
...

Rangi42 avatar Feb 12 '21 01:02 Rangi42