From b6ac1018c29592d667a559016baa18301f21dad4 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Fri, 14 Aug 2015 02:46:12 -0700 Subject: add border constant and clear up misnomer --- constants/connection_constants.asm | 4 ++ constants/misc_constants.asm | 9 +++-- engine/trade.asm | 10 ++--- home/overworld.asm | 76 +++++++++++++++++++------------------- home/vblank.asm | 2 +- home/vcopy.asm | 51 +++++++++++++------------ hram.asm | 8 ++-- macros.asm | 8 ++++ main.asm | 10 ++--- scripts/vermiliondock.asm | 8 ++-- wram.asm | 4 +- 11 files changed, 103 insertions(+), 87 deletions(-) diff --git a/constants/connection_constants.asm b/constants/connection_constants.asm index 916d6c4f..154c4163 100755 --- a/constants/connection_constants.asm +++ b/constants/connection_constants.asm @@ -1,3 +1,7 @@ +; width of east/west connections +; height of north/south connections +MAP_BORDER EQU 3 + ; connection directions EAST EQU 1 WEST EQU 2 diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index 9fa50e9c..43dc908e 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -25,13 +25,14 @@ D_LEFT EQU %00100000 D_UP EQU %01000000 D_DOWN EQU %10000000 -PIXELS_PER_TILE EQU 8 - SCREEN_WIDTH EQU 20 SCREEN_HEIGHT EQU 18 -SCREEN_WIDTH_PIXELS EQU SCREEN_WIDTH * PIXELS_PER_TILE -SCREEN_HEIGHT_PIXELS EQU SCREEN_HEIGHT * PIXELS_PER_TILE +SCREEN_WIDTH_PIXELS EQU SCREEN_WIDTH * 8 +SCREEN_HEIGHT_PIXELS EQU SCREEN_HEIGHT * 8 + +BG_MAP_WIDTH EQU 32 +BG_MAP_HEIGHT EQU 32 NPC_MOVEMENT_DOWN EQU $00 NPC_MOVEMENT_UP EQU $40 diff --git a/engine/trade.asm b/engine/trade.asm index 0e816e05..66afa47e 100755 --- a/engine/trade.asm +++ b/engine/trade.asm @@ -552,14 +552,14 @@ Trade_CopyCableTilesOffScreen: ; 414ae (10:54ae) ; continues when the screen is scrolled. push hl coord hl, 0, 4 - call CopyToScreenEdgeTiles + call CopyToRedrawRowOrColumnSrcTiles pop hl ld a, h - ld [H_SCREENEDGEREDRAWADDR + 1], a + ld [hRedrawRowOrColumnDest + 1], a ld a, l - ld [H_SCREENEDGEREDRAWADDR], a - ld a, REDRAWROW - ld [H_SCREENEDGEREDRAW], a + ld [hRedrawRowOrColumnDest], a + ld a, REDRAW_ROW + ld [hRedrawRowOrColumnMode], a ld c, 10 jp DelayFrames diff --git a/home/overworld.asm b/home/overworld.asm index 6b3a75c6..051d055e 100644 --- a/home/overworld.asm +++ b/home/overworld.asm @@ -555,10 +555,10 @@ CheckMapConnections:: ; 07ba (0:07ba) jr z,.savePointer1 .pointerAdjustmentLoop1 ld a,[wWestConnectedMapWidth] ; width of connected map - add a,$06 + add a,MAP_BORDER * 2 ld e,a - ld d,$00 - ld b,$00 + ld d,0 + ld b,0 add hl,de dec c jr nz,.pointerAdjustmentLoop1 @@ -591,10 +591,10 @@ CheckMapConnections:: ; 07ba (0:07ba) jr z,.savePointer2 .pointerAdjustmentLoop2 ld a,[wEastConnectedMapWidth] - add a,$06 + add a,MAP_BORDER * 2 ld e,a - ld d,$00 - ld b,$00 + ld d,0 + ld b,0 add hl,de dec c jr nz,.pointerAdjustmentLoop2 @@ -883,15 +883,15 @@ LoadTileBlockMap:: ; 09fc (0:09fc) ld hl,wOverworldMap ld a,[W_CURMAPWIDTH] ld [hMapWidth],a - add a,$06 ; border (east and west) + add a,MAP_BORDER * 2 ; east and west ld [hMapStride],a ; map width + border - ld b,$00 + ld b,0 ld c,a ; make space for north border (next 3 lines) add hl,bc add hl,bc add hl,bc - ld c,$03 + ld c,MAP_BORDER add hl,bc ; this puts us past the (west) border ld a,[W_MAPDATAPTR] ; tile map pointer ld e,a @@ -995,7 +995,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc) ret LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade) - ld c,$03 + ld c,MAP_BORDER .loop push de push hl @@ -1016,7 +1016,7 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade) inc h .noCarry1 ld a,[W_CURMAPWIDTH] - add a,$06 + add a,MAP_BORDER * 2 add e ld e,a jr nc,.noCarry2 @@ -1029,7 +1029,7 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade) LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02) push hl push de - ld c,$03 + ld c,MAP_BORDER .innerLoop ld a,[hli] ld [de],a @@ -1045,7 +1045,7 @@ LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02) inc h .noCarry1 ld a,[W_CURMAPWIDTH] - add a,$06 + add a,MAP_BORDER * 2 add e ld e,a jr nc,.noCarry2 @@ -1387,7 +1387,7 @@ LoadCurrentMapView:: ; 0caa (0:0caa) ; update tile block map pointer to next row's address pop de ld a,[W_CURMAPWIDTH] - add a,$06 + add a,MAP_BORDER * 2 add e ld e,a jr nc,.noCarry @@ -1418,7 +1418,7 @@ LoadCurrentMapView:: ; 0caa (0:0caa) ld bc,$0002 add hl,bc .copyToVisibleAreaBuffer - coord de, 0, 0 ; base address for the tiles that are directly transfered to VRAM during V-blank + coord de, 0, 0 ; base address for the tiles that are directly transferred to VRAM during V-blank ld b, SCREEN_HEIGHT .rowLoop2 ld c, SCREEN_WIDTH @@ -1662,7 +1662,7 @@ MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f) ret MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79) - add a,$06 + add a,MAP_BORDER * 2 ld b,a ld a,[de] add b @@ -1675,7 +1675,7 @@ MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79) ret MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85) - add a,$06 + add a,MAP_BORDER * 2 ld b,a ld a,[de] sub b @@ -1692,17 +1692,17 @@ MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85) ScheduleNorthRowRedraw:: ; 0e91 (0:0e91) coord hl, 0, 0 - call CopyToScreenEdgeTiles + call CopyToRedrawRowOrColumnSrcTiles ld a,[wMapViewVRAMPointer] - ld [H_SCREENEDGEREDRAWADDR],a + ld [hRedrawRowOrColumnDest],a ld a,[wMapViewVRAMPointer + 1] - ld [H_SCREENEDGEREDRAWADDR + 1],a - ld a,REDRAWROW - ld [H_SCREENEDGEREDRAW],a + ld [hRedrawRowOrColumnDest + 1],a + ld a,REDRAW_ROW + ld [hRedrawRowOrColumnMode],a ret -CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6) - ld de,wScreenEdgeTiles +CopyToRedrawRowOrColumnSrcTiles:: ; 0ea6 (0:0ea6) + ld de,wRedrawRowOrColumnSrcTiles ld c,2 * SCREEN_WIDTH .loop ld a,[hli] @@ -1714,7 +1714,7 @@ CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6) ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2) coord hl, 0, 16 - call CopyToScreenEdgeTiles + call CopyToRedrawRowOrColumnSrcTiles ld a,[wMapViewVRAMPointer] ld l,a ld a,[wMapViewVRAMPointer + 1] @@ -1724,11 +1724,11 @@ ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2) ld a,h and a,$03 or a,$98 - ld [H_SCREENEDGEREDRAWADDR + 1],a + ld [hRedrawRowOrColumnDest + 1],a ld a,l - ld [H_SCREENEDGEREDRAWADDR],a - ld a,REDRAWROW - ld [H_SCREENEDGEREDRAW],a + ld [hRedrawRowOrColumnDest],a + ld a,REDRAW_ROW + ld [hRedrawRowOrColumnMode],a ret ScheduleEastColumnRedraw:: ; 0ed3 (0:0ed3) @@ -1742,15 +1742,15 @@ ScheduleEastColumnRedraw:: ; 0ed3 (0:0ed3) add a,18 and a,$1f or b - ld [H_SCREENEDGEREDRAWADDR],a + ld [hRedrawRowOrColumnDest],a ld a,[wMapViewVRAMPointer + 1] - ld [H_SCREENEDGEREDRAWADDR + 1],a - ld a,REDRAWCOL - ld [H_SCREENEDGEREDRAW],a + ld [hRedrawRowOrColumnDest + 1],a + ld a,REDRAW_COL + ld [hRedrawRowOrColumnMode],a ret ScheduleColumnRedrawHelper:: ; 0ef2 (0:0ef2) - ld de,wScreenEdgeTiles + ld de,wRedrawRowOrColumnSrcTiles ld c,SCREEN_HEIGHT .loop ld a,[hli] @@ -1773,11 +1773,11 @@ ScheduleWestColumnRedraw:: ; 0f08 (0:0f08) coord hl, 0, 0 call ScheduleColumnRedrawHelper ld a,[wMapViewVRAMPointer] - ld [H_SCREENEDGEREDRAWADDR],a + ld [hRedrawRowOrColumnDest],a ld a,[wMapViewVRAMPointer + 1] - ld [H_SCREENEDGEREDRAWADDR + 1],a - ld a,REDRAWCOL - ld [H_SCREENEDGEREDRAW],a + ld [hRedrawRowOrColumnDest + 1],a + ld a,REDRAW_COL + ld [hRedrawRowOrColumnMode],a ret ; function to write the tiles that make up a tile block to memory diff --git a/home/vblank.asm b/home/vblank.asm index 8ffae9f1..f69d4a86 100644 --- a/home/vblank.asm +++ b/home/vblank.asm @@ -22,7 +22,7 @@ VBlank:: call AutoBgMapTransfer call VBlankCopyBgMap - call RedrawExposedScreenEdge + call RedrawRowOrColumn call VBlankCopy call VBlankCopyDouble call UpdateMovingBgTiles diff --git a/home/vcopy.asm b/home/vcopy.asm index 02caef29..69773cfe 100644 --- a/home/vcopy.asm +++ b/home/vcopy.asm @@ -33,23 +33,26 @@ ClearBgMap:: ; 1cf0 (0:1cf0) jr nz,.loop ret -; When the player takes a step, a row or column of 2x2 tile blocks at the edge -; of the screen toward which they moved is exposed and has to be redrawn. -; This function does the redrawing. -RedrawExposedScreenEdge:: ; 1d01 (0:1d01) - ld a,[H_SCREENEDGEREDRAW] +RedrawRowOrColumn:: ; 1d01 (0:1d01) +; This function redraws a BG row of height 2 or a BG column of width 2. +; One of its main uses is redrawing the row or column that will be exposed upon +; scrolling the BG when the player takes a step. Redrawing only the exposed +; row or column is more efficient than redrawing the entire screen. +; However, this function is also called repeatedly to redraw the whole screen +; when necessary. It is also used in trade animation and elevator code. + ld a,[hRedrawRowOrColumnMode] and a ret z ld b,a xor a - ld [H_SCREENEDGEREDRAW],a + ld [hRedrawRowOrColumnMode],a dec b jr nz,.redrawRow .redrawColumn - ld hl,wScreenEdgeTiles - ld a,[H_SCREENEDGEREDRAWADDR] + ld hl,wRedrawRowOrColumnSrcTiles + ld a,[hRedrawRowOrColumnDest] ld e,a - ld a,[H_SCREENEDGEREDRAWADDR + 1] + ld a,[hRedrawRowOrColumnDest + 1] ld d,a ld c,SCREEN_HEIGHT .loop1 @@ -58,7 +61,7 @@ RedrawExposedScreenEdge:: ; 1d01 (0:1d01) inc de ld a,[hli] ld [de],a - ld a,31 + ld a,BG_MAP_WIDTH - 1 add e ld e,a jr nc,.noCarry @@ -72,23 +75,24 @@ RedrawExposedScreenEdge:: ; 1d01 (0:1d01) dec c jr nz,.loop1 xor a - ld [H_SCREENEDGEREDRAW],a + ld [hRedrawRowOrColumnMode],a ret .redrawRow - ld hl,wScreenEdgeTiles - ld a,[H_SCREENEDGEREDRAWADDR] + ld hl,wRedrawRowOrColumnSrcTiles + ld a,[hRedrawRowOrColumnDest] ld e,a - ld a,[H_SCREENEDGEREDRAWADDR + 1] + ld a,[hRedrawRowOrColumnDest + 1] ld d,a push de - call .drawHalf ; draw upper half + call .DrawHalf ; draw upper half pop de - ld a,32 ; width of VRAM background map + ld a,BG_MAP_WIDTH ; width of VRAM background map add e ld e,a - ; draw lower half -.drawHalf - ld c,10 + ; fall through and draw lower half + +.DrawHalf + ld c,SCREEN_WIDTH / 2 .loop2 ld a,[hli] ld [de],a @@ -113,7 +117,7 @@ RedrawExposedScreenEdge:: ; 1d01 (0:1d01) ; background per V-blank. It cycles through which third it draws. ; This transfer is turned off when walking around the map, but is turned ; on when talking to sprites, battling, using menus, etc. This is because -; the above function, RedrawExposedScreenEdge, is used when walking to +; the above function, RedrawRowOrColumn, is used when walking to ; improve efficiency. AutoBgMapTransfer:: ; 1d57 (0:1d57) ld a,[H_AUTOBGTRANSFERENABLED] @@ -302,12 +306,11 @@ VBlankCopyDouble:: VBlankCopy:: -; Copy [H_VBCOPYSIZE] 2bpp tiles +; Copy [H_VBCOPYSIZE] 2bpp tiles (or 16 * [H_VBCOPYSIZE] tile map entries) ; from H_VBCOPYSRC to H_VBCOPYDEST. -; Source and destination addresses -; are updated, so transfer can -; continue in subsequent calls. +; Source and destination addresses are updated, +; so transfer can continue in subsequent calls. ld a, [H_VBCOPYSIZE] and a diff --git a/hram.asm b/hram.asm index c1fb4c4c..f5817fa4 100644 --- a/hram.asm +++ b/hram.asm @@ -242,12 +242,12 @@ H_VBCOPYDOUBLEDEST EQU $FFCE ; 00 = no redraw ; 01 = redraw column ; 02 = redraw row -H_SCREENEDGEREDRAW EQU $FFD0 +hRedrawRowOrColumnMode EQU $FFD0 -REDRAWCOL EQU 1 -REDRAWROW EQU 2 +REDRAW_COL EQU 1 +REDRAW_ROW EQU 2 -H_SCREENEDGEREDRAWADDR EQU $FFD1 +hRedrawRowOrColumnDest EQU $FFD1 hRandomAdd EQU $FFD3 hRandomSub EQU $FFD4 diff --git a/macros.asm b/macros.asm index 20a82007..9efb69e5 100644 --- a/macros.asm +++ b/macros.asm @@ -104,6 +104,14 @@ dwCoord: MACRO dw wTileMap + 20 * \2 + \1 ENDM +;\1 = r +;\2 = X +;\3 = Y +;\4 = map width +overworldMapCoord: MACRO + ld \1, wOverworldMap + ((\2) + 3) + (((\3) + 3) * ((\4) + (3 * 2))) + ENDM + ;\1 = Map Width ;\2 = Rows above (Y-blocks) ;\3 = X movement (X-blocks) diff --git a/main.asm b/main.asm index 6db76b46..c87cd1f0 100755 --- a/main.asm +++ b/main.asm @@ -3184,7 +3184,7 @@ RedrawMapView: ; eedc (3:6edc) add hl, de dec a jr nz, .calcWRAMAddrLoop - call CopyToScreenEdgeTiles + call CopyToRedrawRowOrColumnSrcTiles pop hl ld de, $20 ld a, [$ffbe] @@ -3196,11 +3196,11 @@ RedrawMapView: ; eedc (3:6edc) or $98 dec c jr nz, .calcVRAMAddrLoop - ld [H_SCREENEDGEREDRAWADDR + 1], a + ld [hRedrawRowOrColumnDest + 1], a ld a, l - ld [H_SCREENEDGEREDRAWADDR], a - ld a, REDRAWROW - ld [H_SCREENEDGEREDRAW], a + ld [hRedrawRowOrColumnDest], a + ld a, REDRAW_ROW + ld [hRedrawRowOrColumnMode], a call DelayFrame ld hl, $ffbe inc [hl] diff --git a/scripts/vermiliondock.asm b/scripts/vermiliondock.asm index d3c7e31a..78ada7cf 100755 --- a/scripts/vermiliondock.asm +++ b/scripts/vermiliondock.asm @@ -181,12 +181,12 @@ VermilionDock_1dc7c: ; 1dc7c (7:5c7c) VermilionDock_EraseSSAnne: ; 1dc94 (7:5c94) ; Fill the area the S.S. Anne occupies in BG map 0 with water tiles. ld hl, wVermilionDockTileMapBuffer - ld bc, (5 * 32) + SCREEN_WIDTH + ld bc, (5 * BG_MAP_WIDTH) + SCREEN_WIDTH ld a, $14 ; water tile call FillMemory - ld hl, vBGMap0 + 10 * 32 + ld hl, vBGMap0 + 10 * BG_MAP_WIDTH ld de, wVermilionDockTileMapBuffer - ld bc, (6 * 32) / 16 + ld bc, (6 * BG_MAP_WIDTH) / 16 call CopyVideoData ; Replace the blocks of the lower half of the ship with water blocks. This @@ -194,7 +194,7 @@ VermilionDock_EraseSSAnne: ; 1dc94 (7:5c94) ; the blocks is unnecessary because the blocks the ship occupies are south of ; the player and won't be redrawn when the player automatically walks north and ; exits the map. This code could be removed without affecting anything. - ld hl, wOverworldMap + (5 + 3) + (2 + 3) * (VERMILION_DOCK_WIDTH + 6) ; (5, 2) + overworldMapCoord hl, 5, 2, VERMILION_DOCK_WIDTH ld a, $d ; water block ld [hli], a ld [hli], a diff --git a/wram.asm b/wram.asm index 44ad46a5..7ab8f8c9 100755 --- a/wram.asm +++ b/wram.asm @@ -287,8 +287,8 @@ wTempPic:: wOverworldMap:: ; c6e8 ds 1300 -wScreenEdgeTiles:: ; cbfc -; the tiles of the row or column to be redrawn by RedrawExposedScreenEdge +wRedrawRowOrColumnSrcTiles:: ; cbfc +; the tiles of the row or column to be redrawn by RedrawRowOrColumn ds 20 * 2 ; coordinates of the position of the cursor for the top menu item (id 0) -- cgit v1.2.3