From 0e5cd549d37691912cb54cc951ff4a71448c334c Mon Sep 17 00:00:00 2001 From: Forest Belton <65484+forestbelton@users.noreply.github.com> Date: Fri, 9 Jul 2021 18:40:44 -0400 Subject: [PATCH] Stub out scrolling implementation --- src/main.s | 37 +++++++++++++++++++++++++++++++++++++ src/map.s | 30 +++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/main.s b/src/main.s index ced46a9..87e09cd 100644 --- a/src/main.s +++ b/src/main.s @@ -1,4 +1,5 @@ INCLUDE "hardware.inc" +INCLUDE "input.inc" SECTION "Header", ROM0[$100] @@ -54,9 +55,45 @@ start: inc [hl] call Keys_Update + + ; TODO: remove once scrolling is implemented + ; scroll map with arrow keys + ld a, [keys] + and BTN_UP + jr z, .down + + ld hl, rSCY + dec [hl] + +.down: + ld a, [keys] + and BTN_DOWN + jr z, .right + + ld hl, rSCY + inc [hl] + +.right: + ld a, [keys] + and BTN_RIGHT + jr z, .left + + ld hl, rSCX + inc [hl] + +.left: + ld a, [keys] + and BTN_LEFT + jr z, .vbl + + ld hl, rSCX + dec [hl] + + call Map_Scroll ; call Player_Update ; wait for vblank +.vbl: halt ; ~160 cycles diff --git a/src/map.s b/src/map.s index 1e45abd..0ac780e 100644 --- a/src/map.s +++ b/src/map.s @@ -6,6 +6,9 @@ SECTION "Map Data", WRAM0 PAGEX:: DB PAGEY:: DB +LAST_SCX:: DB +LAST_SCY:: DB + CURRENT_DATA_START:: CURRENT_TILE_PTR:: DW CURRENT_TILE_SIZE:: DB @@ -30,10 +33,6 @@ DEF STACK_OFFSET_ROW EQU 3 DEF STACK_OFFSET_MAP EQU 1 DEF STACK_OFFSET_LEFT EQU 0 -; TODO: Don't hardcode -DEF CAMERAX EQU 0 -DEF CAMERAY EQU 14 - ; Increments a 16-bit value located on the stack ; \1 Stack offset MACRO INC_STACK16 @@ -62,11 +61,13 @@ Map_Load:: ; Initialize scroll state ld a, INIT_SCX ld [rSCX], a + ld [LAST_SCX], a ld a, INIT_SCY ld [rSCY], a + ld [LAST_SCY], a - xor a + ld a, 8 ld [PAGEX], a ld [PAGEY], a @@ -108,6 +109,25 @@ Map_Load:: ret +; Update map state based on SCX/SCY +Map_Scroll:: + ; Adjust CURRENT_CAMERA_X + ; Adjust CURRENT_CAMERA_Y + + ; If SCY = PAGEY, write map row + ; map coords = CURRENT_CAMERA_X, CURRENT_CAMERA_Y - 2 + ; HL = _SCRN0 + 32 * (page_y - 1) + + ; If SCY = SCRN_Y - PAGEY, write map row + ; map coords = CURRENT_CAMERA_X, CURRENT_CAMERA_Y + 21 + ; HL = _SCRN0 + 32 * ((32 - page_y) - 1) + ; TODO: Check math on these + + ; If SCX = PAGEX, write map col + ; If SCX = SCRN_X - PAGEX, write map col + + ret + ; Write a row of map data into map RAM ; @param b Map X coordinate (signed) ; @param c Map Y coordinate (signed)