aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUnavailableDev <ggwildplay@gmail.com>2023-03-12 11:37:58 +0100
committerUnavailableDev <ggwildplay@gmail.com>2023-03-12 11:37:58 +0100
commita386709d12167ab8f85336a1764040c3f573e9eb (patch)
tree14da1e60ed7b21a74d3058928ac925f2d619e65d /src
parent311850396060dbd2b6d716d69bd98af44ee69164 (diff)
integrated palettes and fixed reading tiles
Diffstat (limited to 'src')
-rw-r--r--src/engine/engine.c1
-rw-r--r--src/engine/sprite_controller.c10
-rw-r--r--src/engine/sprite_controller.h96
-rw-r--r--src/makefile3
-rw-r--r--src/ppusim/sim.c12
5 files changed, 115 insertions, 7 deletions
diff --git a/src/engine/engine.c b/src/engine/engine.c
index f3410a4..799ee7c 100644
--- a/src/engine/engine.c
+++ b/src/engine/engine.c
@@ -1,3 +1,4 @@
#include "engine/draw_screen.h"
#include "engine/level.h"
#include "engine/maths.h"
+#include "engine/sprite_controller.h"
diff --git a/src/engine/sprite_controller.c b/src/engine/sprite_controller.c
index e69de29..c224ff7 100644
--- a/src/engine/sprite_controller.c
+++ b/src/engine/sprite_controller.c
@@ -0,0 +1,10 @@
+#include <stdint.h>
+
+#include "engine/sprite_controller.h"
+// #include "engine/maths.h"
+#include "ppu/types.h"
+#include "ppu/consts.h"
+
+uint8_t hh_get_palette(uint16_t tile_idx) {
+ return hh_g_sprite_palette[tile_idx];
+}
diff --git a/src/engine/sprite_controller.h b/src/engine/sprite_controller.h
index a433bd6..47ab0af 100644
--- a/src/engine/sprite_controller.h
+++ b/src/engine/sprite_controller.h
@@ -1,8 +1,104 @@
#pragma once
+#include <stdint.h>
+
+#include "ppu/types.h"
+
// handles sprites
// Bg sprites
// Fg or entity sprites
+//TODO: pack data inside of sprite_palette LUT
+//HH_PPU_PALETTE_COUNT
+#define HH_SPRITE_COUNT 32
+#define HH_PAL_IDX_SKY 0
+#define HH_PAL_IDX_BRICK 1
+uint8_t hh_g_sprite_palette[HH_SPRITE_COUNT] = {
+ 0,1,1,1,1,1,1,1,1,1, //1+9
+ 1,1,1,1,1,1,1,1,1,1, //6+4
+ 1,1,1,1,1,1,1,1,1, //9
+ 7,7,7,2,7,7,1,2,7
+ //other palettes here:
+};
+
+
+hh_ppu_loc_palette_table_t hh_g_palette = {
+ {//palette info here
+ {0x1,0x2,0x3},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0}},
+ {//Bricks
+ {0x1,0x2,0x3},//01
+ {0xd,0x8,0xa},//24
+ {0x0,0x0,0x1},//25
+ {0x1,0x1,0x1},//26
+ {0x1,0x1,0x2},//27
+ {0x2,0x2,0x3},//28
+ {0x3,0x4,0x5},//29
+ {0x5,0x1,0x7}},
+ {//slime
+ {0x1,0x2,0x3},
+ {0x1,0x3,0x2},
+ {0x4,0x8,0x3},
+ {0x7,0xa,0x4},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0}},
+ {
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0}},
+ {
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0}},
+ {
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0}},
+ {
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0}},
+ {
+ {0xf,0xf,0xf},
+ {0xf,0xf,0xf},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0},
+ {0x0,0x0,0x0}}
+};
+
+/** @brief return palette index that belongs to tilemap index */
+uint8_t hh_get_palette(uint16_t tile_idx);
+bool hh_colidable(uint16_t tile_idx);
diff --git a/src/makefile b/src/makefile
index 96751fb..02fcb12 100644
--- a/src/makefile
+++ b/src/makefile
@@ -31,7 +31,8 @@ LOCAL_SRCS += main.c \
ppu/internals.c \
ppu/ppu.c \
demo.c \
- engine/engine.c
+ engine/engine.c \
+ engine/sprite_controller.c
CFLAGS += $(SHARED_FLAGS)
LFLAGS += $(SHARED_FLAGS)
diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c
index a759039..1e7e609 100644
--- a/src/ppusim/sim.c
+++ b/src/ppusim/sim.c
@@ -29,21 +29,21 @@ void hh_ppu_init() {
}
void hh_ppu_load_tilemap() {
- char* filename = "tiles.bin";
+ char* filename = "../test/bin/tiles.bin";
FILE* fp = fopen(filename,"rb");
if (!fp){
- printf("File error!");
+ fprintf(stderr,"File error!");
return;//error
}
-
+ int sprite_size = (HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT);
fseek(fp, 0, SEEK_END);//goto EOF
- int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE;
+ int _size = ftell(fp)/sprite_size;
fseek(fp, 0, 0);//goto start of file
for (int i = 0; i < _size; i++) {
- uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE];
+ uint8_t data[sprite_size];
- fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp);
+ fread(data,sizeof(uint8_t),sprite_size,fp);
hh_s_ppu_vram_data sprite = hh_ppu_2nat_sprite(data);
sprite.offset = i*HH_PPU_VRAM_TMM_SPRITE_SIZE;