Browse Source

Begin trying to fix map

master
Forest Belton 2 years ago
parent
commit
a3b48045c1
2 changed files with 79 additions and 10 deletions
  1. +14
    -0
      inc/util.inc
  2. +65
    -10
      src/map.s

+ 14
- 0
inc/util.inc View File

@ -49,3 +49,17 @@ MACRO LD16
ld HIGH(\1), HIGH(\2)
ld LOW(\1), LOW(\2)
ENDM
; \1 8-bit register
; \2 Number of shifts (1-7)
MACRO srln
ASSERT \2 >= 1 && \2 <= 7
REPT \2
srl \1
ENDR
ENDM
MACRO SLA16
sla LOW(\1)
rl HIGH(\1)
ENDM

+ 65
- 10
src/map.s View File

@ -91,6 +91,40 @@ Map_Load::
ret
; Loads the map X-coordinate into B
MACRO LOAD_MAPX
; if SCX <= 0x7f
ld a, [rSCX]
cp $80
jr nc, .wrap\@
; B = CAMERA_X - SCX/8
ld a, [rSCX]
ld b, a
ld a, [CURRENT_CAMERA_X]
srln b, 3
sub b
ld b, a
jr .done\@
; else SCX > 0x7f
.wrap\@:
; B = CAMERA_X - PAGE_X/8
ld a, [PAGEX]
ld b, a
ld a, [CURRENT_CAMERA_X]
srln b, 3
sub b
ld b, a
; HL += PAGE_X/8
ld a, [PAGEX]
srln a, 3
ADD16 hl
.done\@:
ENDM
; Update map state based on SCX/SCY
Map_Scroll::
; If SCY = PAGEY, write map row
@ -154,15 +188,7 @@ Map_Scroll::
ld e, a
call compute_vram_ptr
; B = CAMERA_X - SCX/8
ld a, [rSCX]
ld b, a
ld a, [CURRENT_CAMERA_X]
srl b
srl b
srl b
sub b
ld b, a
LOAD_MAPX
; C = CAMERA_Y + 18 + 1
ld a, [CURRENT_CAMERA_Y]
@ -271,7 +297,27 @@ Map_Update::
ld hl, PENDING_ROW_DATA
ld d, SCRN_VX_B
MEMCPY bc, hl, d
.copy_row:
ld a, [hl+]
ld [bc], a
inc bc
; if BC % 32 == 0 (we just crossed a row boundary)
ld a, c
and %11111
jr nz, .copy_row1
; BC -= 32 (reset back to beginning of row)
ld a, c
sub 32
ld c, a
ld a, b
sbc 0
ld b, a
.copy_row1:
dec d
jr nz, .copy_row
.update_col:
; Skip column update if PENDING_COL_PTR is 0
@ -361,6 +407,14 @@ enqueue_row_write:
ld c, SCRN_VX_B
ld de, PENDING_ROW_DATA
; If X > 0, increment map pointer by X
bit 7, b
jr nz, .pad_left
ld a, b
ADD16 hl
jr .copy_middle
; Note: Can skip checking BYTES_LEFT > 0 in this loop. If there were
; SCRN_VX_B zeros to write, then Y would be 1 greater and we would have
; jumped into .zero_row before reaching this code
@ -446,6 +500,7 @@ write_map_row:
ld a, [PENDING_ROW_PTR + 1]
ld b, a
; TODO: Fix
ld hl, PENDING_ROW_DATA
ld d, SCRN_VX_B
MEMCPY bc, hl, d

Loading…
Cancel
Save