diff options
Diffstat (limited to 'src/ppusim')
-rw-r--r-- | src/ppusim/pixel.c | 22 | ||||
-rw-r--r-- | src/ppusim/pixel.h | 6 | ||||
-rw-r--r-- | src/ppusim/sim.c | 22 |
3 files changed, 33 insertions, 17 deletions
diff --git a/src/ppusim/pixel.c b/src/ppusim/pixel.c new file mode 100644 index 0000000..3a09ccd --- /dev/null +++ b/src/ppusim/pixel.c @@ -0,0 +1,22 @@ +#include <SDL2/SDL.h> + +#include "ppusim/sim.h" + +static void hh_ppusim_draw(SDL_Renderer* r, unsigned px, unsigned py, unsigned cr, unsigned cg, unsigned cb) { + SDL_SetRenderDrawColor(r, cr, cg, cb, 255); + SDL_RenderFillRect(r, &(SDL_Rect) { + .x = px * HH_PPUSIM_UPSCALE_FACTOR, + .y = py * HH_PPUSIM_UPSCALE_FACTOR, + .w = HH_PPUSIM_UPSCALE_FACTOR, + .h = HH_PPUSIM_UPSCALE_FACTOR + }); +} + +void hh_ppusim_pixel(SDL_Renderer* r, unsigned x, unsigned y) { + // loop through foreground sprites to get highest priority cidx + // get background cidx + // check if palette color cidx of foreground is 0 + // lookup color from PAL + // hh_ppusim_draw +} + diff --git a/src/ppusim/pixel.h b/src/ppusim/pixel.h new file mode 100644 index 0000000..8044560 --- /dev/null +++ b/src/ppusim/pixel.h @@ -0,0 +1,6 @@ +#pragma once + +#include <SDL2/SDL.h> + +void hh_ppusim_pixel(SDL_Renderer*, unsigned x, unsigned y); + diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index a3314e4..8f01359 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -7,26 +7,18 @@ #include "ppu/ppu.h" #include "ppusim/mem.h" #include "ppusim/sim.h" +#include "ppusim/pixel.h" SDL_Window *g_hh_window = NULL; SDL_Renderer *g_hh_renderer = NULL; -static void pixel(SDL_Renderer* r, unsigned px, unsigned py, unsigned cr, unsigned cg, unsigned cb) { - SDL_SetRenderDrawColor(r, cr, cg, cb, 255); - SDL_RenderFillRect(r, &(SDL_Rect) { - .x = px * HH_PPUSIM_UPSCALE_FACTOR, - .y = py * HH_PPUSIM_UPSCALE_FACTOR, - .w = HH_PPUSIM_UPSCALE_FACTOR, - .h = HH_PPUSIM_UPSCALE_FACTOR - }); -} - void hh_ppu_init() { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); 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); + memset(g_hh_ppusim_vram, 0x0000, 0xffff); } void hh_ppu_deinit() { @@ -38,22 +30,18 @@ void hh_ppu_deinit() { } void hh_loop() { - static unsigned long frame = 0; SDL_Event e; 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++) { - for (unsigned j = 0; j < HH_PPU_SCREEN_HEIGHT; j++) { - pixel(g_hh_renderer, i, j, (unsigned)(sqrt(i * 20) + frame) % 255, (i * j + frame) % 255, (j * 20) % 255); - } - } + for (unsigned x = 0; x < HH_PPU_SCREEN_WIDTH; x++) + for (unsigned y = 0; y < HH_PPU_SCREEN_HEIGHT; y++) + hh_ppusim_pixel(g_hh_renderer, x, y); SDL_SetRenderDrawColor(g_hh_renderer, 0, 0, 0, 255); SDL_RenderPresent(g_hh_renderer); |