From: Lukas Krickl Date: Thu, 3 Oct 2024 17:10:32 +0000 (+0200) Subject: Added basic meta-tile room drawing X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=bcae39b850c8a425b4cce6ad42fe194c291a14b1;p=gbrg%2F.git Added basic meta-tile room drawing --- diff --git a/src/hw.inc b/src/hw.inc index 7d2c69e..0cc40ff 100644 --- a/src/hw.inc +++ b/src/hw.inc @@ -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 diff --git a/src/map.s b/src/map.s index 6ffb6e3..d66eead 100644 --- 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 @@ -13,24 +14,113 @@ ; 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 diff --git a/src/wram.s b/src/wram.s index 0e69333..0cc107a 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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 diff --git a/tiles/tileset1.inc b/tiles/tileset1.inc index 405104d..552865d 100644 --- a/tiles/tileset1.inc +++ b/tiles/tileset1.inc @@ -608,8 +608,8 @@ .chr 00000000 .chr 00000000 .chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 00000010 +.chr 00000001 ; tile 68 .chr 00000000 .chr 00000000 @@ -617,8 +617,8 @@ .chr 00000000 .chr 00000000 .chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 01000000 +.chr 10000000 ; tile 69 .chr 00000000 .chr 00000000 @@ -746,8 +746,8 @@ .chr 00000010 .chr 11111100 ; tile 83 -.chr 00000000 -.chr 00000000 +.chr 00000001 +.chr 00000010 .chr 00000000 .chr 00000000 .chr 00000000 @@ -755,8 +755,8 @@ .chr 00000000 .chr 00000000 ; tile 84 -.chr 00000000 -.chr 00000000 +.chr 10000000 +.chr 01000000 .chr 00000000 .chr 00000000 .chr 00000000