pret / pokered

Disassembly of Pokémon Red/Blue
3.95k stars 966 forks source link

Add constants for wMapConnections bits and group map header wram labels #413

Closed LinusU closed 10 months ago

LinusU commented 1 year ago

@Rangi42 fixed ✅

Rangi42 commented 1 year ago

Good start! How about using this PR to expand wram_constants.asm to define more of the bit flags? IMO it's easier to deal with than lots of small PRs.

LinusU commented 1 year ago

Good start!

Thanks!

How about using this PR to expand wram_constants.asm to define more of the bit flags? IMO it's easier to deal with than lots of small PRs.

Unfortunately, this is not something I have time with now. I submitted the changes I had now since I'm working on another project that lead me to investigate how wMapConnections worked, and made the change locally.

vulcandth commented 1 year ago

Do we know where these wMapConnections bits are being set? Curious if there are other places where we can use these new constants.

Edit: if we are not sure I can spend some time on it.

LinusU commented 1 year ago

if we are not sure I can spend some time on it.

Please, feel free to! 🙏

vulcandth commented 1 year ago

Do we know where these wMapConnections bits are being set? Curious if there are other places where we can use these new constants.

Edit: if we are not sure I can spend some time on it.

wMapConnections bits are being loaded directly from the data/maps/headers/<MAPNAME>.asm files. Specifically the map_header macros.

See the following change suggestions:

https://github.com/pret/pokered/blob/d3128b9a7ffab9d4d9b615acf9527ee2f1744749/ram/wram.asm#L1797-L1811

Everything from wCurMapTileset to wMapConnections should be grouped together and some of the constants should be renamed... Something like:

wCurMapHeader::
wCurMapTileset:: db
wCurMapHeight:: db 
wCurMapWidth:: db
wCurMapDataPtr:: dw
wCurMapTextPtr:: dw
wCurMapScriptPtr:: dw
wCurMapConnections:: db
wCurMapHeaderEnd::

 wNorthConnectionHeader:: map_connection_struct wNorth 
 wSouthConnectionHeader:: map_connection_struct wSouth 
 wWestConnectionHeader::  map_connection_struct wWest 
 wEastConnectionHeader::  map_connection_struct wEast 

https://github.com/pret/pokered/blob/d3128b9a7ffab9d4d9b615acf9527ee2f1744749/home/overworld.asm#L2035-L2040

The above should then be changed to:

     ld a, [hli] 
     ld h, [hl] 
     ld l, a ; hl = base of map header 
     ld de, wCurMapHeader
     ld c, wCurMapHeaderEnd - wCurMapHeader
Rangi42 commented 12 months ago

So these are actually the same values as the EAST/WEST/SOUTH/NORTH constants, but bits instead of shifted values. pokecrystal declares them together in map_data_constants.asm; I think pokered should do the same.

; connection directions
        const_def
        const EAST_F
        const WEST_F
        const SOUTH_F
        const NORTH_F

; wMapConnections
        const_def
        shift_const EAST
        shift_const WEST
        shift_const SOUTH
        shift_const NORTH

This would also be the start of porting pokecrystal's *_F convention for bitflag constants.