diff options
-rw-r--r-- | Allow-tiles-to-have-different-attributes-in-different-blocks-(including-X-and-Y-flip).md | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/Allow-tiles-to-have-different-attributes-in-different-blocks-(including-X-and-Y-flip).md b/Allow-tiles-to-have-different-attributes-in-different-blocks-(including-X-and-Y-flip).md index 6fee8d4..d52163c 100644 --- a/Allow-tiles-to-have-different-attributes-in-different-blocks-(including-X-and-Y-flip).md +++ b/Allow-tiles-to-have-different-attributes-in-different-blocks-(including-X-and-Y-flip).md @@ -319,18 +319,19 @@ Edit [wram.asm](../blob/master/wram.asm): ```diff wTileset:: - wTilesetBank:: db ; d1d9 - wTilesetAddress:: dw ; d1da - wTilesetBlocksBank:: db ; d1dc - wTilesetBlocksAddress:: dw ; d1dd - wTilesetCollisionBank:: db ; d1df - wTilesetCollisionAddress:: dw ; d1e0 + wTilesetBank:: db + wTilesetAddress:: dw + wTilesetBlocksBank:: db + wTilesetBlocksAddress:: dw + wTilesetCollisionBank:: db + wTilesetCollisionAddress:: dw +wTilesetAttributesBank:: db +wTilesetAttributesAddress:: dw - wTilesetAnim:: dw ; bank 3f ; d1e2 -- ds 2 ; unused ; d1e4 --wTilesetPalettes:: dw ; bank 3f ; d1e6 + wTilesetAnim:: dw ; bank 3f +- ds 2 ; unused +-wTilesetPalettes:: dw ; bank 3f wTilesetEnd:: + assert wTilesetEnd - wTileset == TILESET_LENGTH ``` And edit [constants/tileset_constants.asm](../blob/master/constants/tileset_constants.asm): @@ -348,7 +349,7 @@ Now each tileset will be associated with the correct attribute data. We just removed the `wTilesetPalettes` pointer and the \*_palette_map.asm data it pointed to, so it's time to see how they were being used and update that code to use the \*_attributes.bin files instead. -It turns out that `wTilesetPalettes` is only used in [engine/tilesets/map_palettes.asm](../blob/master/engine/tilesets/map_palettes.asm), which defines two routines: `SwapTextboxPalettes` and `ScrollBGMapPalettes`. `SwapTextboxPalettes` is only called by `FarCallSwapTextboxPalettes`, and `ScrollBGMapPalettes` is only called by `FarCallScrollBGMapPalettes`, both in [home/palettes.asm](../blob/master/home/palettes.asm). Furthermore, `FarCallSwapTextboxPalettes` and `FarCallScrollBGMapPalettes` are only called in [home/map.asm](../blob/master/home/map.asm). +It turns out that `wTilesetPalettes` is only used in [engine/tilesets/map_palettes.asm](../blob/master/engine/tilesets/map_palettes.asm), which defines two routines: `_SwapTextboxPalettes` and `_ScrollBGMapPalettes`. `_SwapTextboxPalettes` is only called by `SwapTextboxPalettes`, and `_ScrollBGMapPalettes` is only called by `ScrollBGMapPalettes`, both in [home/palettes.asm](../blob/master/home/palettes.asm). Furthermore, `SwapTextboxPalettes` and `ScrollBGMapPalettes` are only called in [home/map.asm](../blob/master/home/map.asm). First, delete [engine/tilesets/map_palettes.asm](../blob/master/engine/tilesets/map_palettes.asm). @@ -364,12 +365,12 @@ Edit [main.asm](../blob/master/main.asm): Edit [home/palettes.asm](../blob/master/home/palettes.asm): ```diff --FarCallSwapTextboxPalettes:: -- homecall SwapTextboxPalettes +-SwapTextboxPalettes:: +- homecall _SwapTextboxPalettes - ret - --FarCallScrollBGMapPalettes:: -- homecall ScrollBGMapPalettes +-ScrollBGMapPalettes:: +- homecall _ScrollBGMapPalettes - ret ``` @@ -381,14 +382,16 @@ Finally, we need to edit [home/map.asm](../blob/master/home/map.asm); but it's p Edit [wram.asm](../blob/master/wram.asm) again: ```diff - ; This union spans 480 bytes from c608 to c7e8. - UNION ; c608 + ; This union spans 480 bytes. + SECTION UNION "Miscellaneous", WRAM0 + -; surrounding tiles -; This buffer determines the size for the rest of the union; -; it uses exactly 480 bytes. -wSurroundingTiles:: ds SURROUNDING_WIDTH * SURROUNDING_HEIGHT - --NEXTU ; c608 +-SECTION UNION "Miscellaneous", WRAM0 + ; box save buffer ; SaveBoxAddress uses this buffer in three steps because it ; needs more space than the buffer can hold. @@ -407,11 +410,10 @@ Edit [wram.asm](../blob/master/wram.asm) again: +SECTION "Surrounding Data", WRAMX + +wSurroundingTiles:: ds SURROUNDING_WIDTH * SURROUNDING_HEIGHT -+ +wSurroundingAttributes:: ds SURROUNDING_WIDTH * SURROUNDING_HEIGHT + + - SECTION "GBC Video", WRAMX + SECTION "GBC Video", WRAMX, ALIGN[8] ... ``` @@ -438,7 +440,7 @@ Now we can edit [home/map.asm](../blob/master/home/map.asm). Let's go over it pi ```diff OverworldTextModeSwitch:: - call LoadMapPart -- call FarCallSwapTextboxPalettes +- call SwapTextboxPalettes - ret + ; fallthrough @@ -468,7 +470,7 @@ OverworldTextModeSwitch:: ret ``` -We deleted `FarCallSwapTextboxPalettes`, so now `OverworldTextModeSwitch` just calls `LoadMapPart`; but since the latter is right after the former, they can just be two labels for the same routine. +We deleted `SwapTextboxPalettes`, so now `OverworldTextModeSwitch` just calls `LoadMapPart`; but since the latter is right after the former, they can just be two labels for the same routine. Anyway, `LoadMapPart` calls `LoadMetatiles` to load certain data from the \*_metatiles.bin files, and we're going to define a `LoadMetatileAttributes` routine that does the same thing with the \*_attributes.bin files, so this is where it will be called. @@ -579,7 +581,7 @@ Anyway, `LoadMapPart` calls `LoadMetatiles` to load certain data from the \*_met add hl, de pop de ld a, [wMapWidth] - add 6 + add MAP_CONNECTION_PADDING_WIDTH * 2 add e ld e, a jr nc, .ok2 @@ -600,7 +602,7 @@ We also fixed [the bug that only allowed 128 blocks](../blob/master/docs/bugs_an ld de, wBGMapBuffer call BackupBGMapRow - ld c, 2 * SCREEN_WIDTH -- call FarCallScrollBGMapPalettes +- call ScrollBGMapPalettes + hlcoord 0, 0, wAttrmap + ld de, wBGMapPalBuffer + call BackupBGMapRow @@ -611,7 +613,7 @@ We also fixed [the bug that only allowed 128 blocks](../blob/master/docs/bugs_an ld de, wBGMapBuffer call BackupBGMapRow - ld c, 2 * SCREEN_WIDTH -- call FarCallScrollBGMapPalettes +- call ScrollBGMapPalettes + hlcoord 0, SCREEN_HEIGHT - 2, wAttrmap + ld de, wBGMapPalBuffer + call BackupBGMapRow @@ -622,7 +624,7 @@ We also fixed [the bug that only allowed 128 blocks](../blob/master/docs/bugs_an ld de, wBGMapBuffer call BackupBGMapColumn - ld c, 2 * SCREEN_HEIGHT -- call FarCallScrollBGMapPalettes +- call ScrollBGMapPalettes + hlcoord 0, 0, wAttrmap + ld de, wBGMapPalBuffer + call BackupBGMapColumn @@ -633,14 +635,14 @@ We also fixed [the bug that only allowed 128 blocks](../blob/master/docs/bugs_an ld de, wBGMapBuffer call BackupBGMapColumn - ld c, 2 * SCREEN_HEIGHT -- call FarCallScrollBGMapPalettes +- call ScrollBGMapPalettes + hlcoord SCREEN_WIDTH - 2, 0, wAttrmap + ld de, wBGMapPalBuffer + call BackupBGMapColumn ... ``` -`FarCallScrollBGMapPalettes` used to update `wBGMapPalBuffer` when the screen was scrolled. We deleted it, so now have to update it the same way as `wBGMapBuffer`. +`ScrollBGMapPalettes` used to update `wBGMapPalBuffer` when the screen was scrolled. We deleted it, so now have to update it the same way as `wBGMapBuffer`. (Note that before June 17, 2019, the names of `ScrollMapUp` and `ScrollMapDown` were mistakenly reversed, as were `ScrollMapLeft` and `ScrollMapRight`.) @@ -656,7 +658,7 @@ One more thing: edit [engine/overworld/load_map_part.asm](../blob/master/engine/ + call .copy + ld hl, wSurroundingAttributes + decoord 0, 0, wAttrmap -+.copy: ++.copy ld a, [wMetatileStandingY] and a jr z, .top_row |