diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-02-24 15:24:55 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-02-24 15:24:55 +0100 |
commit | 5f5c6a410cafaa917ca3ff0a2a95bb1f2db4b980 (patch) | |
tree | ad1ff6847694c27da5e0a81324eeb505dfea3a6f /src | |
parent | 672982618cb3ea63f0305785d7c499c83ece145b (diff) |
ppusim refactor
Diffstat (limited to 'src')
-rw-r--r-- | src/ds.mk | 2 | ||||
-rw-r--r-- | src/main.c | 6 | ||||
-rw-r--r-- | src/makefile | 1 | ||||
-rw-r--r-- | src/ppu/ppu.h | 1 | ||||
-rw-r--r-- | src/ppusim/sim.c | 45 | ||||
-rw-r--r-- | src/ppusim/sim.h | 4 | ||||
-rw-r--r-- | src/stm32.mk | 1 |
7 files changed, 36 insertions, 24 deletions
@@ -3,5 +3,5 @@ LD := gcc LFLAGS += -lSDL2 -DESKTOP_SRCS += ppusim/main.c +DESKTOP_SRCS += ppusim/sim.c @@ -15,7 +15,7 @@ hh_s_ppu_loc_sprite* hh_debug_circle_sprite() { } int main() { - // hh_ppu_init(); + hh_ppu_init(); // hh_ppu_update_aux((hh_s_ppu_loc_aux) { // .bg_shift_x = 0, @@ -29,11 +29,11 @@ int main() { free(sprite); while (1); + + hh_ppu_deinit(); } void hh_ppu_vblank_interrupt() { static unsigned long frame = 0; frame++; - - } diff --git a/src/makefile b/src/makefile index f433385..671ab6c 100644 --- a/src/makefile +++ b/src/makefile @@ -19,6 +19,7 @@ HOST=$(strip $(shell uname -o)) SHARED_FLAGS += -g SHARED_FLAGS += -Wall SHARED_FLAGS += -Wextra +SHARED_FLAGS += -I. # SHARED_FLAGS += -O1 LFLAGS += -lm # LFLAGS += -lc diff --git a/src/ppu/ppu.h b/src/ppu/ppu.h index ac01ef7..7aeb7c1 100644 --- a/src/ppu/ppu.h +++ b/src/ppu/ppu.h @@ -4,6 +4,7 @@ void hh_ppu_vblank_interrupt(); void hh_ppu_init(); +void hh_ppu_deinit(); void hh_ppu_update_foreground(unsigned index, hh_s_ppu_loc_fam_entry e); void hh_ppu_update_background(unsigned index, hh_s_ppu_loc_bam_entry e); diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index beddc3f..560646d 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -3,20 +3,26 @@ #include <math.h> #include <SDL2/SDL.h> -#define UPSCALE_FACTOR 3 -#define WIN_HEIGHT 240 -#define WIN_WIDTH 320 -#define FPS 60 +#include "ppu/ppu.h" +#include "ppusim/sim.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 * UPSCALE_FACTOR, .y = py * UPSCALE_FACTOR, .w = UPSCALE_FACTOR, .h = UPSCALE_FACTOR}); + 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 + }); } -int main() { +void hh_ppu_init() { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); - SDL_Window *window = SDL_CreateWindow("sdl2 test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIN_WIDTH * UPSCALE_FACTOR, WIN_HEIGHT * UPSCALE_FACTOR, SDL_WINDOW_SHOWN); - SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + 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); SDL_Event e; unsigned long frame = 0; @@ -25,24 +31,25 @@ int main() { frame++; while (SDL_PollEvent(&e)) if (e.type == SDL_QUIT) exit(0); - SDL_RenderClear(renderer); + SDL_RenderClear(g_hh_renderer); - for (unsigned i = 0; i < WIN_WIDTH; i++) { - for (unsigned j = 0; j < WIN_HEIGHT; j++) { - pixel(renderer, i, j, (unsigned)(sqrt(i * 20) + frame) % 255, (i * j + frame) % 255, (j * 20) % 255); + 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); } } - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); - SDL_RenderPresent(renderer); + SDL_SetRenderDrawColor(g_hh_renderer, 0, 0, 0, 255); + SDL_RenderPresent(g_hh_renderer); uint32_t end = SDL_GetTicks(); - int wait_for = 1000 / FPS - (end - start); + int wait_for = 1000 / HH_PPUSIM_FRAMERATE - (end - start); if (wait_for > 0) SDL_Delay(wait_for); } +} - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); +void hh_ppu_deinit() { + SDL_DestroyRenderer(g_hh_renderer); + SDL_DestroyWindow(g_hh_window); SDL_Quit(); - return 0; } diff --git a/src/ppusim/sim.h b/src/ppusim/sim.h new file mode 100644 index 0000000..e161746 --- /dev/null +++ b/src/ppusim/sim.h @@ -0,0 +1,4 @@ +#pragma once + +#define HH_PPUSIM_UPSCALE_FACTOR 3 +#define HH_PPUSIM_FRAMERATE 60 diff --git a/src/stm32.mk b/src/stm32.mk index a3b8338..12acf0e 100644 --- a/src/stm32.mk +++ b/src/stm32.mk @@ -13,7 +13,6 @@ SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/CMSIS/STM32F0xx/inc SHARED_FLAGS += -I./lib/STM32-base/startup SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/include SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/portable/GCC/ARM_CM0/ -SHARED_FLAGS += -I. SHARED_FLAGS += -I./stm32 ifeq ($(HOST),GNU/Linux) SHARED_FLAGS += -I/usr/arm-none-eabi/include/ |