Browse Source

Stub out scrolling implementation

master
Forest Belton 2 years ago
parent
commit
0e5cd549d3
2 changed files with 62 additions and 5 deletions
  1. +37
    -0
      src/main.s
  2. +25
    -5
      src/map.s

+ 37
- 0
src/main.s View File

@ -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

+ 25
- 5
src/map.s View File

@ -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)

Loading…
Cancel
Save