aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentd6cff5d9a6056a4cd727f3e9dd6301a78169d246 (diff)
downloadgold-mine-run-04af7fbd7891b4be883be8231d8fc0ae11a763e7.tar.gz
gold-mine-run-04af7fbd7891b4be883be8231d8fc0ae11a763e7.zip
Map renderer
Diffstat (limited to 'src')
-rw-r--r--src/Makefile8
-rw-r--r--src/data.h2
-rw-r--r--src/main.c4
-rw-r--r--src/map.c33
-rw-r--r--src/map.h17
5 files changed, 62 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile
index 4852b93..50b1179 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -6,8 +6,11 @@ LDFLAGS := -s
IMGS := $(wildcard ../data/*.png)
IMG_OBJS := $(IMGS:../data/%.png=%.o)
+MAPS := ../data/stage.json
+MAP_OBJS := $(MAPS:../data/%.json=%.o)
+
SRCS := $(wildcard *.c)
-OBJS := $(SRCS:.c=.o) $(IMG_OBJS) palette.o
+OBJS := $(SRCS:.c=.o) $(IMG_OBJS) palette.o $(MAP_OBJS)
all: $(BIN)
@@ -23,6 +26,9 @@ palette.o: ../data/sprites.png
$(IMG_OBJS): %.o: ../data/%.png
../tools/pngpix.py $< $@
+$(MAP_OBJS): %.o: ../data/%.json
+ ../tools/map.py $< $@
+
clean:
rm -f $(BIN) *.o Makefile.deps
diff --git a/src/data.h b/src/data.h
index d7f2f4c..8d4b2e3 100644
--- a/src/data.h
+++ b/src/data.h
@@ -7,4 +7,6 @@ extern const uint8_t binary_sprites_start[];
extern const uint8_t binary_tiles_start[];
extern const uint8_t binary_font_start[];
+extern const uint8_t binary_stage_start[];
+
#endif /* _DATA_H */
diff --git a/src/main.c b/src/main.c
index be248d3..9985159 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,6 +7,7 @@
#include "keyb.h"
#include "vga.h"
#include "text.h"
+#include "map.h"
#include "data.h"
/* disable paging because our int handlers are written in C */
@@ -36,7 +37,8 @@ int main(int argc, char *argv[])
blit_erase(0);
wait_vsync();
- put_text(10, 10, "TESTING! 1234567890* ()^_");
+ map_init(binary_stage_start);
+ map_render();
blit_update();
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);
+ }
+}
diff --git a/src/map.h b/src/map.h
new file mode 100644
index 0000000..7c08fe5
--- /dev/null
+++ b/src/map.h
@@ -0,0 +1,17 @@
+#ifndef _MAP_H
+#define _MAP_H
+
+#define MAP_TILE_W 8
+#define MAP_TILE_H 8
+
+#define MAP_W 40
+#define MAP_H 23
+
+#define MAP_OFFS_Y 16
+
+#define MAP_TILESET_COLS 20
+
+void map_init(const uint8_t map[]);
+void map_render();
+
+#endif /* _MAP_H */