From b2b0cfa7c1e25cd96ecffaab18aaf799972000c1 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 17 Mar 2025 17:55:14 +0100 Subject: [PATCH] scroll: Added basic scrolling to map --- src/player.s | 31 +++++++++++++++++++++++ src/video.s | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/wram.s | 9 +++++++ 3 files changed, 110 insertions(+) diff --git a/src/player.s b/src/player.s index 8df7fed..f559bcf 100644 --- a/src/player.s +++ b/src/player.s @@ -28,16 +28,22 @@ player_update: @draw_cursor: ; draw cursor + ld a, [scroll_y] + ld b, a ; b = scroll_y + ld a, [scroll_x] + ld c, a ; c = scroll_x ; 8x8 small cursor ld hl, PLAYER_SPRITE1 ld a, [cursor_y] add a, OBJ_OFF_Y + sub a, b ld [hl+], a ld a, [cursor_x] add a, OBJ_OFF_X + sub a, c ld [hl+], a ld a, CURSOR_TILE @@ -59,6 +65,13 @@ handle_inputs: ld [cursor_move_timer], a ld a, CURSOR_MOVE_SPEED ld [cursor_move_y], a + + + ; adjust scroll + ld a, [scroll_move_y] + add a, 1 + ld [scroll_move_y], a + ret @notdown: @@ -71,6 +84,12 @@ handle_inputs: ld [cursor_move_timer], a ld a, CURSOR_MOVE_SPEED * NEGATE ld [cursor_move_y], a + + ; adjust scroll + ld a, [scroll_move_y] + sub a, 1 + ld [scroll_move_y], a + ret @notup: @@ -83,6 +102,12 @@ handle_inputs: ld [cursor_move_timer], a ld a, CURSOR_MOVE_SPEED * NEGATE ld [cursor_move_x], a + + ; adjust scroll + ld a, [scroll_move_x] + sub a, 1 + ld [scroll_move_x], a + ret @notleft: @@ -95,6 +120,12 @@ handle_inputs: ld [cursor_move_timer], a ld a, CURSOR_MOVE_SPEED ld [cursor_move_x], a + + ; adjust scroll + ld a, [scroll_move_x] + add a, 1 + ld [scroll_move_x], a + @notright: ret diff --git a/src/video.s b/src/video.s index 655a2b4..397ec51 100644 --- a/src/video.s +++ b/src/video.s @@ -9,10 +9,80 @@ vblank: call poll_inputs call ui_draw + call scroll_update + ld a, 1 ld [frame_ready], a ret + ; updates scroll based on scroll_move_y/x +scroll_update: + + ld a, [scroll_move_y] + cp a, 0x12 + jr nz, @no_scroll_down REL + + ; move-1 + sub a, 1 + ld [scroll_move_y], a + + ld b, TILE_SIZE + ld a, [scroll_y] + add a, b + ld [scroll_y], a + jr @done REL +@no_scroll_down: + + + cp a, 0xFF + jr nz, @no_scroll_up REL + + ; move+1 + add a, 1 + ld [scroll_move_y], a + + ld b, TILE_SIZE + ld a, [scroll_y] + sub a, b + ld [scroll_y], a + jr @done REL +@no_scroll_up: + + + ld a, [scroll_move_x] + cp a, 0x14 + jr nz, @no_scroll_right REL + + sub a, 1 + ld [scroll_move_x], a + + ld b, TILE_SIZE + ld a, [scroll_x] + add a, b + ld [scroll_x], a + jr @done REL +@no_scroll_right: + + cp a, 0xFF + jr nz, @no_scroll_left REL + + add a, 1 + ld [scroll_move_x], a + + ld b, TILE_SIZE + ld a, [scroll_x] + sub a, b + ld [scroll_x], a +@no_scroll_left: +@done: + ld a, [scroll_y] + ld [RSCY], a + + ld a, [scroll_x] + ld [RSCX], a + + ret + ; wait for next vblank vblank_wait: ld a, [RLY] diff --git a/src/wram.s b/src/wram.s index 4dc5326..8009c43 100644 --- a/src/wram.s +++ b/src/wram.s @@ -32,6 +32,15 @@ cursor_move_timer: .adv 1 cursor_move_y: .adv 1 cursor_move_x: .adv 1 + ; +/-1 for each time the cursor moves + ; allows us to move scroll when needed +scroll_move_y: .adv 1 +scroll_move_x: .adv 1 + + ; scroll location +scroll_y: .adv 1 +scroll_x: .adv 1 + money: .adv 3 debt: .adv 3 demand_house: .adv 1 -- 2.30.2