map: vram origin is now configurable
authorLukas Krickl <lukas@krickl.dev>
Wed, 26 Nov 2025 04:51:59 +0000 (05:51 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 26 Nov 2025 04:51:59 +0000 (05:51 +0100)
src/map.s
src/mem.s
src/wram.s

index a457a802367b6d595f925dd9fa56363bff6f1b07..ce2eb49cb141c137a88e7da75c434d43ebab210a 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -1,4 +1,14 @@
 #define SCRN0_END 0x9BF3
+       
+       ; inits map globals
+       ; such as map_vram_tl
+map_globals_init:
+       ld hl, SCRN0
+       ld a, h
+       ld [map_vram_tl], a
+       ld a, l
+       ld [map_vram_tl+1], a
+       ret
 
        ; loads a map 
        ; including the required tileset
@@ -230,8 +240,13 @@ map_draw_tile_prep:
        ; load tile into a
        ld a, [hl] ; a = tile
        push af ; save tile gfx
-
-       ld hl, SCRN0
+       
+       ; TODO: this needs to wrap around
+       ; if hl goes oob in y-loop
+       ld a, [map_vram_tl]
+       ld h, a
+       ld a, [map_vram_tl+1]
+       ld l, a
        ld de, ((MAP_W * 2) + 12) * 2 ; * 4 because tiles are 8x8 
        
        ; skip y loop if b is 0
index 60da28ec2ba4907626427a00c935986775e888a6..00662ef3b9a5f76aabbd448e6e74b15ba5516508 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -4,6 +4,8 @@ mem_init:
   ld hl, WRAM
   ld bc, WRAMLEN
   call memset
+
+       call map_globals_init
   
   ; set up shadow IE
   ld a, IVBLANK | ILCD
@@ -29,6 +31,7 @@ mem_init:
        ld hl, new_game 
        call game_set_state
 
+
   ret
 
 ; copies memory from one location to another 
index 4dcc26c8a809645f606d32aa96493e38b5c41e6d..026b41d57f6b12358a4dbb1293c97ea928c9c243 100644 (file)
@@ -84,6 +84,9 @@ tmp_x: .adv 1
        
        ; current map ptr
 map: .adv 2
+       ; ptr to top left corner of SCRN
+       ; where the map should be drawn
+map_vram_tl: .adv 2
        
        ; ptr to current tile to be updated
 tiles: .adv t_size * MAP_TILES