aboutsummaryrefslogtreecommitdiff
path: root/src/map.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-13 23:29:50 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-13 23:29:50 +0100
commit04af7fbd7891b4be883be8231d8fc0ae11a763e7 (patch)
treedadb4bd75c59335ba68ec157bea8d3460351fa8b /src/map.c
parentd6cff5d9a6056a4cd727f3e9dd6301a78169d246 (diff)
downloadgold-mine-run-04af7fbd7891b4be883be8231d8fc0ae11a763e7.tar.gz
gold-mine-run-04af7fbd7891b4be883be8231d8fc0ae11a763e7.zip
Map renderer
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/map.c b/src/map.c
new file mode 100644
index 0000000..55fc470
--- /dev/null
+++ b/src/map.c
@@ -0,0 +1,33 @@
+#include <stdint.h>
+
+#include "vga.h"
+#include "data.h"
+
+#include "map.h"
+
+static const uint8_t *cmap;
+
+void map_init(const uint8_t map[])
+{
+ cmap = map;
+}
+
+void map_render()
+{
+ const uint8_t *tiles = binary_tiles_start;
+ Rect src = { 0, 0, 160, 48 };
+ Rect dst = { 0, 0, 8, 8 };
+
+ for (uint8_t y = 0; y < MAP_H; y++)
+ for (uint8_t x = 0; x < MAP_W; x++)
+ {
+ dst.x = x * MAP_TILE_W;
+ dst.y = y * MAP_TILE_H + MAP_OFFS_Y;
+
+ uint8_t t = cmap[x + y * MAP_W];
+ src.x = (t % MAP_TILESET_COLS) * MAP_TILE_W;
+ src.y = (t / MAP_TILESET_COLS) * MAP_TILE_H;
+
+ blitrc(binary_tiles_start, &src, &dst);
+ }
+}