Added basic meta-tile room drawing
authorLukas Krickl <lukas@krickl.dev>
Thu, 3 Oct 2024 17:10:32 +0000 (19:10 +0200)
committerLukas Krickl <lukas@krickl.dev>
Thu, 3 Oct 2024 17:10:32 +0000 (19:10 +0200)
src/hw.inc
src/map.s
src/wram.s
tiles/tileset1.inc

index 7d2c69e05a90cf6bc3881ca1f4cb6ee1e59213f5..0cc40ff244314db32026afcea6cdddda17718fb6 100644 (file)
@@ -68,6 +68,8 @@
 .def int VRAM = 0x8000
 .def int VRAM9000 = VRAM+0x1000
 
+.def int VIEW_W = 20
+.def int VIEW_H = 20
 .def int SCRN_W = 32
 .def int SCRN_H = 32
 
index 6ffb6e31396cbf0dd94b4577bef5f4747f1a1668..d66eead272b9205546740a1ffa85e4cb185fd799 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -3,6 +3,7 @@
   ; this simply defines the first tile 
   ; in the set 
 #define TFLOOR1 0x41
+#define TFLOOR2 0x43
 
   ; maps are collections of rooms
 
   ; rooms may have 4 regular exits and 1 secret exit
 
 
+  ; draws one row for a room
+  ; inputs:
+  ;   de: room ptr 
+  ;   hl: screen ptr 
+  ; modifies: 
+  ;   de: next row
+  ;   hl: next screen address
+room_row_draw:
+  ld b, ROOM_W
+
+  ; we'll need 
+  ; de for the second loop again 
+  push de
+  ; darwa first set of tiles 
+@loop_first:
+  ; read tile from de
+  ld a, [de]
+  ; write to scrn
+  ld [hl+], a
+
+  ; move to next tile index
+  add a, 1
+  ; write it to scrn 
+  ld [hl+], a
+  
+  ; de++
+  inc de
+  ; loop counter --
+  dec b
+
+  ld a, b
+  cp a, 0
+  jp nz, @loop_first
+
+  ; get the previous de value 
+  pop de
+  
+
+  ; move screen to next row
+  ld bc, SCRN_W - VIEW_W
+  add hl, bc
+  
+  ld b, ROOM_W
+  
+  ; almost the same loop again
+  ; for the second row
+  ; of the meta tile 
+@loop_second:
+  ; read tile 
+  ld a, [de]
+  ; move to next "row" of tiels 
+  add a, 16
+  ; write to scrn
+  ld [hl+], a
+
+  ; move to next tile index
+  add a, 1
+  ; write it to scrn 
+  ld [hl+], a
+
+  ; de++
+  inc de
+  ; b++
+  dec b
+
+  ld a, b
+  cp a, 0
+  jp nz, @loop_second
+
+
+  ; do not draw outside of the room viewport
+  ; -> advance scrn by 12 to move to next row
+  ld bc, SCRN_W - VIEW_W
+  add hl, bc
+
+  ret
 
   ; draws the entire room to the tilemap
   ; disable rendering before drawing a room!
   ; inputs:
-  ;   curr_toom: pointer to current room
+  ;   curr_room: pointer to current room
 room_draw:
   ; load current room ptr
   ld a, [curr_room+1]
   ld d, a
   ld a, [curr_room]
   ld e, a
-  ld hl, SCRN0
 
-@copy_meta_tile:
-  ld a, [de]
-  ld [hl+], a
-  inc de
+  ; hl is the screen address 
+  ld hl, SCRN0
+  
+  ld b, ROOM_H
+@loop:
+  ; draw next tile 
+  push bc ; save bc for loop counter
+  call room_row_draw
   
+  ; we need bc to be the 
+  ; loop counter again
+  pop bc 
+  dec b 
+
+  ld a, b
+  cp a, 0
+  jp nz, @loop
+   
+
 
   ret
 
@@ -38,12 +128,11 @@ room_draw:
   ; this can be copied and modified 
   ; by the map gen
 base_room:
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
-.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1  
+.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR2  
+.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR2  
+.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR2  
+.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR2  
+.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR2  
+.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR2  
+.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR2  
+.db TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1,  TFLOOR1, TFLOOR1, TFLOOR2  
index 0e69333e8c772c1f55b0a55b4af1d1dc8e09b70b..0cc107af882be6238326e25f9e680f18c6b4ee39 100644 (file)
@@ -44,8 +44,8 @@ player: .adv player_size
 .de map_size, 0
 
   ; rooms are 9x9 meta tiles 
-#define ROOM_W 9
-#define ROOM_H 9
+#define ROOM_W 10
+#define ROOM_H 8
 
 ; struct room
 .se 0
index 405104dbe47f0973addc9d068becc495d5624152..552865d6e5b62c791bb134e0c7db33486605277a 100644 (file)
 .chr 00000000
 .chr 00000000
 .chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 00000010
+.chr 00000001
 ; tile 68
 .chr 00000000
 .chr 00000000
 .chr 00000000
 .chr 00000000
 .chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 01000000
+.chr 10000000
 ; tile 69
 .chr 00000000
 .chr 00000000
 .chr 00000010
 .chr 11111100
 ; tile 83
-.chr 00000000
-.chr 00000000
+.chr 00000001
+.chr 00000010
 .chr 00000000
 .chr 00000000
 .chr 00000000
 .chr 00000000
 .chr 00000000
 ; tile 84
-.chr 00000000
-.chr 00000000
+.chr 10000000
+.chr 01000000
 .chr 00000000
 .chr 00000000
 .chr 00000000