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