diff options
Diffstat (limited to 'src/ppusim')
-rw-r--r-- | src/ppusim/input.c | 2 | ||||
-rw-r--r-- | src/ppusim/sim.c | 30 | ||||
-rw-r--r-- | src/ppusim/sim.h | 3 |
3 files changed, 35 insertions, 0 deletions
diff --git a/src/ppusim/input.c b/src/ppusim/input.c index 08bc382..4bc7018 100644 --- a/src/ppusim/input.c +++ b/src/ppusim/input.c @@ -12,4 +12,6 @@ void hh_input_read() { g_hh_controller_p1.dpad_down = kb[SDL_SCANCODE_S]; g_hh_controller_p1.dpad_left = kb[SDL_SCANCODE_A]; g_hh_controller_p1.dpad_right = kb[SDL_SCANCODE_D]; + g_hh_controller_p1.button_primary = kb[SDL_SCANCODE_SPACE]; + g_hh_controller_p1.button_secondary = kb[SDL_SCANCODE_R]; } diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index 449b78d..8b67acc 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -1,9 +1,12 @@ #include <SDL2/SDL.h> #include <stdbool.h> #include <stdlib.h> +#include <stdio.h> #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" @@ -22,6 +25,33 @@ void hh_ppu_init() { g_hh_ppusim_vram = malloc(sizeof(hh_ppu_data_t) * 0xffff); memset(g_hh_ppusim_vram, 0x0000, 0xffff); + hh_ppu_load_tilemap(); +} + +void hh_ppu_load_tilemap() { + //TODO: remove magic file name here + char* filename = "static/tiles.bin"; + FILE* fp = fopen(filename,"rb"); + if (!fp){ + fprintf(stderr,"Error: Failed to load tiles."); + return;//error + } + int sprite_size = (HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT); + fseek(fp, 0, SEEK_END);//goto EOF + int _size = ftell(fp)/sprite_size; + fseek(fp, 0, 0);//goto start of file + + for (int i = 0; i < _size; i++) { + uint8_t data[sprite_size]; + + 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; + hh_ppu_vram_write(sprite); + free(sprite.data); + } + fclose(fp); } void hh_ppu_deinit() { diff --git a/src/ppusim/sim.h b/src/ppusim/sim.h index 73f4b23..4d1d718 100644 --- a/src/ppusim/sim.h +++ b/src/ppusim/sim.h @@ -4,3 +4,6 @@ #define HH_PPUSIM_UPSCALE_FACTOR 3 /** @brief max framerate for PPUSIM */ #define HH_PPUSIM_FRAMERATE 60 + +/** @brief pump tilemap from rom to ppu ram */ +void hh_ppu_load_tilemap(); //ppu sim? |