From 8670e4bb2bdaf46399830d9c4d413705ae01dc40 Mon Sep 17 00:00:00 2001 From: UnavailableDev Date: Fri, 10 Mar 2023 16:32:50 +0100 Subject: ppusim read sprites from file and put into vram --- src/ppusim/sim.c | 25 +++++++++++++++++++++++- test/bin/test_file_read.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 test/bin/test_file_read.c diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index 7d56d2d..1fceb82 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -1,9 +1,12 @@ #include #include #include +#include #include "main.h" #include "ppu/ppu.h" +#include "ppu/consts.h" +#include "ppu/internals.h" #include "ppusim/mem.h" #include "ppusim/sim.h" #include "ppusim/work.h" @@ -26,7 +29,27 @@ void hh_ppu_init() { } void hh_ppu_load_tilemap() { - + char* filename = "tiles.bin"; + FILE* fp = fopen(filename,"rb"); + if (!fp){ + return;//error + } + + fseek(fp, 0, SEEK_END);//goto EOF + int _size = ftell(fp)/HH_PPU_VRAM_TMM_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]; + + fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); + + hh_s_ppu_vram_data sprite = hh_ppu_2nat_sprite(data); + sprite.offset = i*HH_PPU_VRAM_TMM_SPRITE_SIZE; + hh_ppu_vram_write(sprite); + free(sprite.data); + } + fclose(fp); } void hh_ppu_deinit() { diff --git a/test/bin/test_file_read.c b/test/bin/test_file_read.c new file mode 100644 index 0000000..6357feb --- /dev/null +++ b/test/bin/test_file_read.c @@ -0,0 +1,48 @@ + +#include +#include +#include + + +#define HH_PPU_VRAM_TMM_SPRITE_SIZE 52 + + +void printData(uint8_t* in) { + for (int i = 0; i < HH_PPU_VRAM_TMM_SPRITE_SIZE; i++) + { + printf("%02x ",in[i]); + } + printf("\n"); +} + +void hh_ppu_load_tilemap() { + + //TODO: lees bestand in mem + char* filename = "tiles.bin"; + FILE* fp = fopen(filename,"rb"); + if (!fp){ + return;//error + } + + fseek(fp, 0, SEEK_END); + int _size = ftell(fp)/HH_PPU_VRAM_TMM_SPRITE_SIZE; + fseek(fp, 0, 0); + // printf("%i",_size); + for (int i = 0; i < _size; i++) { + uint8_t data[HH_PPU_VRAM_TMM_SPRITE_SIZE]; + // for (int i = 0; i < 255; i++) { + // buffer[i] = 0; //TODO: vullen + fread(data,HH_PPU_VRAM_TMM_SPRITE_SIZE,1,fp); + // } + + printData(data); + } + fclose(fp); + +} + + +int main(){ +hh_ppu_load_tilemap(); + return 0; +} -- cgit v1.2.3