Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer direct expressions to EQUS #1164

Open
Rangi42 opened this issue Jan 7, 2025 · 0 comments
Open

Prefer direct expressions to EQUS #1164

Rangi42 opened this issue Jan 7, 2025 · 0 comments

Comments

@Rangi42
Copy link
Member

Rangi42 commented Jan 7, 2025

Here's an example. engine/events/mom_phone.asm defines DEF NUM_MOM_ITEMS_1 EQUS "((MomItems_1.End - MomItems_1) / 8)" and DEF NUM_MOM_ITEMS_2 EQUS "((MomItems_2.End - MomItems_2) / 8)". NUM_MOM_ITEMS_1 is only used once, in ld a, NUM_MOM_ITEMS_1. NUM_MOM_ITEMS_2 is used in two cp NUM_MOM_ITEMS_2. Neither of those EQUS definitions should exist -- just do ld a, (MomItems_1.End - MomItems_1) / 8 and cp (MomItems_2.End - MomItems_2) / 8.

This goes for EQUS more generally. The way the auto-expand is a misfeature of the assembly language, and we should avoid it when alternatives are possible. For example, DEF text EQUS "db TX_START," should really be MACRO text db TX_START, \# ENDM -- although it's two lines longer, it's more flexible (you could add checks inside for mistakes like text after line) and more future-proof (rgbasm eventually wants to remove EQUS expansion).

(The big exception is things like DEF tiles EQUS "* LEN_2BPP_TILE" so you can do ld bc, (7 * 7) tiles. Eventually rgbasm will have user-defined functions and we can replace it with DEF tiles(n) := n * LEN_2BPP_TILE to do ld bc, tiles(7 * 7)... but until then, the EQUS is okay.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant