ref: b6ac1018c29592d667a559016baa18301f21dad4
parent: 599a6aeaaf81e7174577c782f3b3ba113a4a4c39
author: YamaArashi <shadow962@live.com>
date: Thu Aug 13 22:46:12 EDT 2015
add border constant and clear up misnomer
--- 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
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -25,13 +25,14 @@
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
--- a/engine/trade.asm
+++ b/engine/trade.asm
@@ -552,14 +552,14 @@
; 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
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -555,10 +555,10 @@
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 @@
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 @@
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 @@
ret
LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
- ld c,$03
+ ld c,MAP_BORDER
.loop
push de
push hl
@@ -1016,7 +1016,7 @@
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 @@
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 @@
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 @@
; 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -22,7 +22,7 @@
call AutoBgMapTransfer
call VBlankCopyBgMap
- call RedrawExposedScreenEdge
+ call RedrawRowOrColumn
call VBlankCopy
call VBlankCopyDouble
call UpdateMovingBgTiles
--- a/home/vcopy.asm
+++ b/home/vcopy.asm
@@ -33,23 +33,26 @@
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 @@
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 @@
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 @@
; 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 @@
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
--- a/hram.asm
+++ b/hram.asm
@@ -242,12 +242,12 @@
; 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
--- a/macros.asm
+++ b/macros.asm
@@ -104,6 +104,14 @@
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)
--- a/main.asm
+++ b/main.asm
@@ -3184,7 +3184,7 @@
add hl, de
dec a
jr nz, .calcWRAMAddrLoop
- call CopyToScreenEdgeTiles
+ call CopyToRedrawRowOrColumnSrcTiles
pop hl
ld de, $20
ld a, [$ffbe]
@@ -3196,11 +3196,11 @@
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]
--- a/scripts/vermiliondock.asm
+++ b/scripts/vermiliondock.asm
@@ -181,12 +181,12 @@
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 @@
; 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
--- a/wram.asm
+++ b/wram.asm
@@ -287,8 +287,8 @@
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)