gbdev / rgbds

Rednex Game Boy Development System - An assembly toolchain for the Nintendo Game Boy and Game Boy Color
https://rgbds.gbdev.io
MIT License
1.33k stars 171 forks source link

[Feature request] 24-bit (3-byte) data support #1511

Closed Rangi42 closed 1 week ago

Rangi42 commented 1 week ago

RGBDS has db/rb for 8-bit bytes, dw/rw for 16-bit words, and dl/rl for 32-bit "long words". This leaves a gap for 24-bit values, which have various use cases both during assembly and runtime (bank+address, RGB888 color, any time you need "millions" of values but still with a fourth byte to spare).

Prior terminology is uncommon, since historically 24-bit machines just called these "words" (the eZ80 even referred to "16-bit words" and "24-bit words" on the same platform!), and then we settled on powers of 2 for everything. Some examples do exist:

Overall, I'd prefer adding dt/rt keywords for "tribyte" data.

ISSOtm commented 1 week ago

Thank you for your research, thorough as always :)

I don't feel convinced by this feature, because the primary use case, “far pointers”, are heterogeneous and I believe that (bank, ptr) is roughly as common as (ptr, bank). And also because I have thus far never witnessed a use of dl, not even emulated by dws due to a lack of awareness.

The other use cases, I feel are niche enough to be emulated using dbs for RGB888 (db $12,$34,$56, $78,$9A,$BC is fine..? And that's assuming you want the components stored in RGB order, too; dt would give you BGR.) or warrant writing a macro.

Rangi42 commented 1 week ago

Yeah, that's fair. Pokemon uses a few 3-byte values (e.g. for money and experience) but some of those would need a macro anyway for being big-endian or BCD, so plain dt wouldn't get much use. (Probably more than dl, but still not a lot.)