diff options
Diffstat (limited to 'src/ppusim')
-rw-r--r-- | src/ppusim/mem.c | 13 | ||||
-rw-r--r-- | src/ppusim/mem.h | 4 | ||||
-rw-r--r-- | src/ppusim/sim.c | 26 |
3 files changed, 35 insertions, 8 deletions
diff --git a/src/ppusim/mem.c b/src/ppusim/mem.c new file mode 100644 index 0000000..72e01c5 --- /dev/null +++ b/src/ppusim/mem.c @@ -0,0 +1,13 @@ +#include <stdlib.h> +#include <stdio.h> + +#include "ppusim/mem.h" +#include "ppu/internals.h" + +hh_ppu_data_t *g_hh_ppusim_vram = NULL; + +void hh_ppu_vram_dwrite(hh_ppu_addr_t addr, hh_ppu_data_t data) { + if (!hh_ppu_vram_valid_address(addr)) return; + printf("ppu[0x%04x] = %04x\n", addr, data); + g_hh_ppusim_vram[addr] = data; +} diff --git a/src/ppusim/mem.h b/src/ppusim/mem.h new file mode 100644 index 0000000..72f40be --- /dev/null +++ b/src/ppusim/mem.h @@ -0,0 +1,4 @@ +#include "ppu/types.h" + +extern hh_ppu_data_t *g_hh_ppusim_vram; + diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index 560646d..a3314e4 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -3,7 +3,9 @@ #include <math.h> #include <SDL2/SDL.h> +#include "main.h" #include "ppu/ppu.h" +#include "ppusim/mem.h" #include "ppusim/sim.h" SDL_Window *g_hh_window = NULL; @@ -24,13 +26,27 @@ void hh_ppu_init() { g_hh_window = SDL_CreateWindow("ppusim", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, HH_PPU_SCREEN_WIDTH * HH_PPUSIM_UPSCALE_FACTOR, HH_PPU_SCREEN_HEIGHT * HH_PPUSIM_UPSCALE_FACTOR, SDL_WINDOW_SHOWN); g_hh_renderer = SDL_CreateRenderer(g_hh_window, -1, SDL_RENDERER_ACCELERATED); + g_hh_ppusim_vram = malloc(sizeof(hh_ppu_data_t) * 0xffff); +} + +void hh_ppu_deinit() { + free(g_hh_ppusim_vram); + + SDL_DestroyRenderer(g_hh_renderer); + SDL_DestroyWindow(g_hh_window); + SDL_Quit(); +} + +void hh_loop() { + static unsigned long frame = 0; SDL_Event e; - unsigned long frame = 0; - while (true) { + while (g_hh_run) { uint32_t start = SDL_GetTicks(); frame++; while (SDL_PollEvent(&e)) if (e.type == SDL_QUIT) exit(0); + hh_ppu_vblank_interrupt(); + SDL_RenderClear(g_hh_renderer); for (unsigned i = 0; i < HH_PPU_SCREEN_WIDTH; i++) { @@ -47,9 +63,3 @@ void hh_ppu_init() { if (wait_for > 0) SDL_Delay(wait_for); } } - -void hh_ppu_deinit() { - SDL_DestroyRenderer(g_hh_renderer); - SDL_DestroyWindow(g_hh_window); - SDL_Quit(); -} |