pret / pokecrystal

Disassembly of Pokémon Crystal
https://pret.github.io/pokecrystal/
2.06k stars 770 forks source link

Improvements thanks to upcoming rgbds versions #686

Open mid-kid opened 4 years ago

mid-kid commented 4 years ago

This issue thread will keep track of different optimizations and improvements we can make when newer versions of rgbds are released.

These will be in some RGBDS >0.7.0:

Features I think we should avoid (generally because they make it harder to process .asm files via regular expressions, as with optimize.py):

ISSOtm commented 4 years ago
* [ ]  `ds $0150 - $0104` can become `ds $0150 - @` in home/header.asm

Well, considering hacks could choose to put anything there but 0 should be the default value for the header (as RGBFIX just patches over instead of overwriting the whole region), that'd be one of the places where ds $150 - @, 0 would make sense.

ISSOtm commented 4 years ago

2-arg ds added in rednex/rgbds@4cc24f436947890f41a3e16392a3c7ec7e8949ba.

ISSOtm commented 4 years ago

https://github.com/rednex/rgbds/releases/tag/v0.4.0

Rangi42 commented 3 years ago

User-defined functions are under development, which will allow replacing the coord macros:

def coord(x, y) = coord(x, y, wTilemap)
def coord(x, y, origin) = y * SCREEN_WIDTH + x + origin

def bgcoord(x, y) = bgcoord(x, y, vBGMap0)
def bgcoord(x, y, origin) = y * BG_MAP_WIDTH + x + origin

Old:

    hlcoord 1, 2
    debgcoord 3, 4, wAttrmap
    dwcoord 5, 6
    ldcoord_a 7, 8
    lda_coord 9, 10

New:

    ld hl, coord(1, 2)
    ld de, bgcoord(3, 4, wAttrmap)
    dw coord(5, 6)
    ld [coord(7, 8)], a
    ld a, [coord(9, 10)]

If a ternary operator is added later, then maskbits n can become ld a, bitmask(n):

def bitmask(n) = n > 0 ? bitmask(n, 1) : 0
def bitmask(n, x) = n <= x+1 ? x : bitmask(n, x*2+1)
ISSOtm commented 3 years ago

Features I think we should avoid (generally because they make it harder to process .asm files via regular expressions, as with optimize.py):

* New `MACRO name` and `DEF name EQU value` syntax (the old syntaxes are more familiar and not deprecated)

Be careful, as the changelog states:

The old syntax will still be supported for a couple versions, but may eventually be phased out.

(Emphasis added.) The syntax change is to get rid of the newbie trap that is "column 1", and it hasn't been deprecated as a courtesy due to the wide usage; but you're still strongly advised to prepare for an eventual deprecation.

Rangi42 commented 3 years ago
def rgb555(r, g, b) = (r << 0) | (g << 5) | (b << 10)

RGB: MACRO
rept _NARG / 3
    assert_valid_rgb \1, \2, \3
    dw rgb555(\1, \2, \3)
    shift 3
endr
ENDM
Rangi42 commented 3 years ago
BASE_TMHM rb (NUM_TM_HM_TUTOR + 7) / 8
for n, (NUM_TM_HM_TUTOR + 7) / 8
    ds ((\1) + 7) / 8

def nb_flags(n) := (n + 7) / 8

BASE_TMHM rb nb_flags(NUM_TM_HM_TUTOR)
for n, nb_flags(NUM_TM_HM_TUTOR)
    ds nb_flags(\1)
rawr51919 commented 2 years ago

This issue I presume is meant to be a tracker for RGBDS updates and the syntax that goes along with them for pokecrystal adoption