aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ds.mk3
-rw-r--r--src/main.c66
-rw-r--r--src/main.h15
-rw-r--r--src/makefile4
-rw-r--r--src/ppu/consts.h33
-rw-r--r--src/ppu/internals.c103
-rw-r--r--src/ppu/internals.h19
-rw-r--r--src/ppu/ppu.c52
-rw-r--r--src/ppu/ppu.h14
-rw-r--r--src/ppu/types.h14
-rw-r--r--src/ppusim/mem.c13
-rw-r--r--src/ppusim/mem.h4
-rw-r--r--src/ppusim/sim.c26
-rw-r--r--src/stm32.mk3
-rw-r--r--src/stm32/main.c5
15 files changed, 325 insertions, 49 deletions
diff --git a/src/ds.mk b/src/ds.mk
index 2929344..65b7a51 100644
--- a/src/ds.mk
+++ b/src/ds.mk
@@ -3,5 +3,6 @@ LD := gcc
LFLAGS += -lSDL2
-DESKTOP_SRCS += ppusim/sim.c
+DESKTOP_SRCS += ppusim/sim.c \
+ ppusim/mem.c
diff --git a/src/main.c b/src/main.c
index 43f9482..365671a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,39 +1,63 @@
#include <stdlib.h>
#include <math.h>
+#ifdef HH_TARGET_DESKTOP
+#include <stdio.h>
+#endif
+#include "main.h"
#include "ppu/ppu.h"
#include "ppu/consts.h"
-hh_s_ppu_loc_sprite* hh_debug_circle_sprite() {
- hh_s_ppu_loc_sprite* s = malloc(sizeof(hh_s_ppu_loc_sprite));
+bool g_hh_run = true;
- for (int x = 0; x < HH_PPU_SPRITE_WIDTH; x++)
- for (int y = 0; y < HH_PPU_SPRITE_HEIGHT; y++)
- *s[y * HH_PPU_SPRITE_WIDTH + x] = (pow(x - 8, 2) + pow(y - 8, 2) < 67) ? 1 : 0;
+int main() {
+ hh_setup();
+ hh_loop();
+ hh_exit();
+ return 0;
+}
+
+void hh_ppu_vblank_interrupt() {
+ static unsigned long frame = 0;
+ frame++;
- return s;
+#ifdef HH_TARGET_DESKTOP
+ printf("frame %lu\n", frame);
+#endif
}
-int main() {
+void hh_setup() {
hh_ppu_init();
- // hh_ppu_update_aux((hh_s_ppu_loc_aux) {
- // .bg_shift_x = 0,
- // .bg_shift_y = 0,
- // .fg_fetch = 0,
- // .sysreset = 0,
- // });
+ hh_ppu_update_aux((hh_s_ppu_loc_aux) {
+ .bg_shift_x = 24,
+ .bg_shift_y = 0,
+ .fg_fetch = 1,
+ .sysreset = 1,
+ });
- hh_s_ppu_loc_sprite* sprite = hh_debug_circle_sprite();
- // hh_ppu_update_sprite(0, *sprite);
- free(sprite);
+ hh_s_ppu_loc_sprite sprite = {0};
- while (1);
+ for (int x = 0; x < HH_PPU_SPRITE_WIDTH; x++)
+ for (int y = 0; y < HH_PPU_SPRITE_HEIGHT; y++)
+ sprite[y * HH_PPU_SPRITE_WIDTH + x] = (pow(x - 8, 2) + pow(y - 8, 2) < 67) ? 1 : 0;
- hh_ppu_deinit();
+ hh_ppu_update_sprite(0, sprite);
+
+ hh_ppu_update_foreground(0, (hh_s_ppu_loc_fam_entry) {
+ .horizontal_flip = false,
+ .vertical_flip = false,
+ .palette_index = 1,
+ .tilemap_index = 0,
+ .position_x = 30,
+ .position_y = 40
+ });
+
+ hh_ppu_update_color(1, 1, (hh_ppu_rgb_color_t) {15, 0, 15});
}
-void hh_ppu_vblank_interrupt() {
- static unsigned long frame = 0;
- frame++;
+void hh_exit() {
+ g_hh_run = false;
+
+ hh_ppu_deinit();
}
diff --git a/src/main.h b/src/main.h
new file mode 100644
index 0000000..8e94f18
--- /dev/null
+++ b/src/main.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <stdbool.h>
+
+extern bool g_hh_run;
+
+/** @brief exec entrypoint */
+int main();
+
+/** @brief setup i/o interfaces */
+void hh_setup();
+/** @brief main loop (sim only) */
+void hh_loop();
+/** @brief stop main loop and cleanup/deinitialize */
+void hh_exit();
diff --git a/src/makefile b/src/makefile
index 671ab6c..41311eb 100644
--- a/src/makefile
+++ b/src/makefile
@@ -26,7 +26,9 @@ LFLAGS += -lm
CFLAGS += $(if $(STM), -DHH_TARGET_STM32, )
CFLAGS += $(if $(DESKTOP), -DHH_TARGET_DESKTOP, )
-LOCAL_SRCS += main.c
+LOCAL_SRCS += main.c \
+ ppu/internals.c \
+ ppu/ppu.c
CFLAGS += $(SHARED_FLAGS)
LFLAGS += $(SHARED_FLAGS)
diff --git a/src/ppu/consts.h b/src/ppu/consts.h
index ee94a69..0e8fba4 100644
--- a/src/ppu/consts.h
+++ b/src/ppu/consts.h
@@ -1,26 +1,57 @@
#pragma once
+/** @brief amount of total palettes in PPU */
#define HH_PPU_PALETTE_COUNT 8
+/** @brief amount of colors in palette */
#define HH_PPU_PALETTE_COLOR_COUNT 8
+/** @brief address line width in bits */
#define HH_PPU_RAM_BUS_ADDR_WIDTH 16
+/** @brief data line width in bits */
#define HH_PPU_RAM_BUS_DATA_WIDTH 16
+/** @brief max amount of foreground sprites allowed */
#define HH_PPU_FG_SPRITE_COUNT 128
+/** @brief sprite width in pixel */
#define HH_PPU_SPRITE_WIDTH 16
+/** @brief sprite height in pixels */
#define HH_PPU_SPRITE_HEIGHT 16
+/** @brief screen width in pixels */
#define HH_PPU_SCREEN_WIDTH 320
+/** @brief screen height in pixels */
#define HH_PPU_SCREEN_HEIGHT 240
+/** @brief amount of horizontal backgorund tiles on background canvas */
#define HH_PPU_BG_CANVAS_TILES_H 40
+/** @brief amount of vertical backgorund tiles on background canvas */
#define HH_PPU_BG_CANVAS_TILES_V 30
-#include "types.h"
+#include "ppu/types.h"
+/** @brief tilemap memory address offset */
#define HH_PPU_VRAM_TMM_OFFSET ((hh_ppu_addr_t) 0x0000)
+/** @brief tilemap memory size in words */
#define HH_PPU_VRAM_TMM_SIZE ((hh_ppu_addr_t) 0xd000)
+/** @brief sprite size in words */
+#define HH_PPU_VRAM_TMM_SPRITE_SIZE 52
+/** @brief pixels per word for sprite */
+#define HH_PPU_VRAM_TMM_SPRITE_PPW 5
+/** @brief background attribute memory address offset */
#define HH_PPU_VRAM_BAM_OFFSET ((hh_ppu_addr_t) 0xd000)
+/** @brief background attribute memory size in words */
#define HH_PPU_VRAM_BAM_SIZE ((hh_ppu_addr_t) 0x04b0)
+/** @brief background attribute memory entry size in words */
+#define HH_PPU_VRAM_BAM_ENTRY_SIZE 1
+/** @brief foreground attribute memory address offset */
#define HH_PPU_VRAM_FAM_OFFSET ((hh_ppu_addr_t) 0xd800)
+/** @brief foreground attribute memory size in words */
#define HH_PPU_VRAM_FAM_SIZE ((hh_ppu_addr_t) 0x0100)
+/** @brief foreground attribute memory entry size in words */
+#define HH_PPU_VRAM_FAM_ENTRY_SIZE 2
+/** @brief palette memory address offset */
#define HH_PPU_VRAM_PAL_OFFSET ((hh_ppu_addr_t) 0xdc00)
+/** @brief palette memory size in words */
#define HH_PPU_VRAM_PAL_SIZE ((hh_ppu_addr_t) 0x0040)
+/** @brief palette entry size in words */
+#define HH_PPU_VRAM_PAL_ENTRY_SIZE 1
+/** @brief auxiliary memory address offset */
#define HH_PPU_VRAM_AUX_OFFSET ((hh_ppu_addr_t) 0xde00)
+/** @brief auxiliary memory size in words */
#define HH_PPU_VRAM_AUX_SIZE ((hh_ppu_addr_t) 0x0002)
diff --git a/src/ppu/internals.c b/src/ppu/internals.c
new file mode 100644
index 0000000..5b47b75
--- /dev/null
+++ b/src/ppu/internals.c
@@ -0,0 +1,103 @@
+#include <stdlib.h>
+
+#include "ppu/types.h"
+#include "ppu/internals.h"
+
+/** @brief generate bitmask with `n` bits set to one from LSB */
+#define HH_MASK(n) ((1 << (n))-1)
+/** @brief resize `in` to `upper downto lower` like in vhdl */
+#define HH_RESIZE(in, upper, lower) ((((hh_ppu_data_t)(in)) & HH_MASK(upper+1-lower)) >> lower)
+
+bool hh_ppu_vram_valid_address(hh_ppu_addr_t addr) {
+ (void) addr; // compiler bruh
+ return true; // TODO
+}
+
+void hh_ppu_vram_write(hh_s_ppu_vram_data data) {
+ for (unsigned i = 0; i < data.size; i++)
+ hh_ppu_vram_dwrite(data.offset + i, data.data[i]);
+}
+
+hh_s_ppu_vram_data hh_ppu_2nat_bam(hh_s_ppu_loc_bam_entry e) {
+ hh_ppu_data_t* data = malloc(sizeof(hh_ppu_data_t) * HH_PPU_VRAM_BAM_ENTRY_SIZE);
+
+ data[0] = HH_RESIZE(e.tilemap_index, 9, 0) << 0 |
+ HH_RESIZE(e.palette_index, 2, 0) << 10 |
+ e.vertical_flip << 13 |
+ e.horizontal_flip << 14;
+
+ hh_s_ppu_vram_data out = {
+ .data = data,
+ .size = HH_PPU_VRAM_FAM_ENTRY_SIZE
+ };
+ return out;
+}
+
+hh_s_ppu_vram_data hh_ppu_2nat_fam(hh_s_ppu_loc_fam_entry e) {
+ hh_ppu_data_t* data = malloc(sizeof(hh_ppu_data_t) * HH_PPU_VRAM_FAM_ENTRY_SIZE);
+
+ e.position_x += 16;
+ e.position_y += 16;
+ data[0] = HH_RESIZE(e.tilemap_index, 9, 0) << 0 |
+ HH_RESIZE(e.palette_index, 2, 0) << 10 |
+ HH_RESIZE(e.position_y, 2, 0) << 13;
+ data[1] = HH_RESIZE(e.position_y, 4, 0) << 0 |
+ HH_RESIZE(e.position_x, 8, 0) << 5 |
+ e.vertical_flip << 14 |
+ e.horizontal_flip << 15;
+
+ hh_s_ppu_vram_data out = {
+ .data = data,
+ .size = HH_PPU_VRAM_FAM_ENTRY_SIZE
+ };
+ return out;
+}
+
+hh_s_ppu_vram_data hh_ppu_2nat_aux(hh_s_ppu_loc_aux aux) {
+ hh_ppu_data_t* data = malloc(sizeof(hh_ppu_data_t) * HH_PPU_VRAM_AUX_SIZE);
+
+ data[0] = HH_RESIZE(aux.bg_shift_y, 7, 0) << 0 |
+ HH_RESIZE(aux.bg_shift_x, 7, 0) << 8;
+ data[1] = HH_RESIZE(aux.bg_shift_x, 8, 8) << 0 |
+ aux.fg_fetch << 1 |
+ aux.sysreset << 2;
+
+ hh_s_ppu_vram_data out = {
+ .data = data,
+ .size = HH_PPU_VRAM_AUX_SIZE
+ };
+ return out;
+}
+
+hh_s_ppu_vram_data hh_ppu_2nat_sprite(hh_ppu_loc_sprite_data_t sprite_data) {
+ hh_ppu_data_t* data = malloc(sizeof(hh_ppu_data_t) * HH_PPU_VRAM_TMM_SPRITE_SIZE);
+
+ for (unsigned x = 0; x < HH_PPU_SPRITE_WIDTH; x++) {
+ for (unsigned y = 0; y < HH_PPU_SPRITE_HEIGHT; y++) {
+ unsigned i = y * HH_PPU_SPRITE_WIDTH + x;
+ unsigned word = i / 5;
+ unsigned pixel = i % 5;
+ data[word] |= HH_RESIZE(sprite_data[i], 2, 0) << pixel * 3;
+ }
+ }
+
+ hh_s_ppu_vram_data out = {
+ .data = data,
+ .size = HH_PPU_VRAM_TMM_SPRITE_SIZE
+ };
+ return out;
+}
+
+hh_s_ppu_vram_data hh_ppu_2nat_color(hh_ppu_rgb_color_t rgb) {
+ hh_ppu_data_t* data = malloc(sizeof(hh_ppu_data_t) * HH_PPU_VRAM_PAL_ENTRY_SIZE);
+
+ data[0] = HH_RESIZE(rgb[0], 3, 0) << 0 |
+ HH_RESIZE(rgb[1], 3, 0) << 4 |
+ HH_RESIZE(rgb[2], 3, 0) << 8;
+
+ hh_s_ppu_vram_data out = {
+ .data = data,
+ .size = HH_PPU_VRAM_PAL_ENTRY_SIZE
+ };
+ return out;
+}
diff --git a/src/ppu/internals.h b/src/ppu/internals.h
index ddb2196..7b60255 100644
--- a/src/ppu/internals.h
+++ b/src/ppu/internals.h
@@ -2,7 +2,7 @@
#include <stdbool.h>
-#include "types.h"
+#include "ppu/types.h"
typedef struct {
hh_ppu_addr_t offset;
@@ -10,13 +10,16 @@ typedef struct {
hh_ppu_data_t* data;
} hh_s_ppu_vram_data;
+/** @brief check if `addr` is a valid PPU address */
bool hh_ppu_vram_valid_address(hh_ppu_addr_t addr);
-void hh_ppu_vram_write(hh_ppu_addr_t addr, hh_ppu_data_t data);
-void hh_ppu_vram_memcpy(void* a, hh_s_ppu_vram_data b);
+/** @brief direct write vram word (platform-specific implementation) */
+void hh_ppu_vram_dwrite(hh_ppu_addr_t addr, hh_ppu_data_t data);
+/** @brief write data block into vram */
+void hh_ppu_vram_write(hh_s_ppu_vram_data data);
-hh_s_ppu_vram_data* hh_ppu_2nat_bam(hh_s_ppu_loc_bam_entry);
-hh_s_ppu_vram_data* hh_ppu_2nat_fam(hh_s_ppu_loc_fam_entry);
-hh_s_ppu_vram_data* hh_ppu_2nat_aux(hh_s_ppu_loc_aux);
-hh_s_ppu_vram_data* hh_ppu_2nat_sprite(hh_ppu_loc_sprite_data_t);
-hh_s_ppu_vram_data* hh_ppu_2nat_pal(hh_ppu_loc_palette_data_t);
+hh_s_ppu_vram_data hh_ppu_2nat_bam(hh_s_ppu_loc_bam_entry);
+hh_s_ppu_vram_data hh_ppu_2nat_fam(hh_s_ppu_loc_fam_entry);
+hh_s_ppu_vram_data hh_ppu_2nat_aux(hh_s_ppu_loc_aux);
+hh_s_ppu_vram_data hh_ppu_2nat_sprite(hh_ppu_loc_sprite_data_t);
+hh_s_ppu_vram_data hh_ppu_2nat_color(hh_ppu_rgb_color_t);
diff --git a/src/ppu/ppu.c b/src/ppu/ppu.c
new file mode 100644
index 0000000..e2fccb9
--- /dev/null
+++ b/src/ppu/ppu.c
@@ -0,0 +1,52 @@
+#include <stdlib.h>
+
+#include "ppu/ppu.h"
+#include "ppu/internals.h"
+#include "ppu/consts.h"
+
+void hh_ppu_update_foreground(unsigned index, hh_s_ppu_loc_fam_entry e) {
+ hh_s_ppu_vram_data s = hh_ppu_2nat_fam(e);
+ s.offset = HH_PPU_VRAM_FAM_OFFSET + HH_PPU_VRAM_FAM_ENTRY_SIZE * index;
+ hh_ppu_vram_write(s);
+ free(s.data);
+}
+
+void hh_ppu_update_background(unsigned index, hh_s_ppu_loc_bam_entry e) {
+ hh_s_ppu_vram_data s = hh_ppu_2nat_bam(e);
+ s.offset = HH_PPU_VRAM_BAM_OFFSET + HH_PPU_VRAM_BAM_ENTRY_SIZE * index;
+ hh_ppu_vram_write(s);
+ free(s.data);
+}
+
+void hh_ppu_update_sprite(unsigned tilemap_index, hh_s_ppu_loc_sprite sprite) {
+ hh_s_ppu_vram_data s = hh_ppu_2nat_sprite(sprite);
+ s.offset = HH_PPU_VRAM_TMM_OFFSET + HH_PPU_VRAM_TMM_SPRITE_SIZE * tilemap_index;
+ hh_ppu_vram_write(s);
+ free(s.data);
+}
+
+void hh_ppu_update_aux(hh_s_ppu_loc_aux aux) {
+ hh_s_ppu_vram_data a = hh_ppu_2nat_aux(aux);
+ a.offset = HH_PPU_VRAM_AUX_OFFSET;
+ hh_ppu_vram_write(a);
+ free(a.data);
+}
+
+void hh_ppu_update_palette_table(hh_ppu_loc_palette_table_t table) {
+ for(unsigned i = 0; i < HH_PPU_PALETTE_COUNT; i++)
+ hh_ppu_update_palette(i, table[i]);
+}
+
+void hh_ppu_update_palette(unsigned palette_index, hh_ppu_loc_palette_data_t palette) {
+ for(unsigned i = 0; i < HH_PPU_PALETTE_COLOR_COUNT; i++)
+ hh_ppu_update_color(palette_index, i, palette[i]);
+}
+
+void hh_ppu_update_color(unsigned palette_index, unsigned color_index, hh_ppu_rgb_color_t color) {
+ hh_s_ppu_vram_data c = hh_ppu_2nat_color(color);
+ c.offset = HH_PPU_VRAM_PAL_OFFSET +
+ palette_index * HH_PPU_VRAM_PAL_ENTRY_SIZE * HH_PPU_PALETTE_COLOR_COUNT +
+ color_index * HH_PPU_VRAM_PAL_ENTRY_SIZE;
+ hh_ppu_vram_write(c);
+ free(c.data);
+}
diff --git a/src/ppu/ppu.h b/src/ppu/ppu.h
index 7aeb7c1..90f964e 100644
--- a/src/ppu/ppu.h
+++ b/src/ppu/ppu.h
@@ -1,12 +1,22 @@
#pragma once
-#include "types.h"
+#include "ppu/types.h"
void hh_ppu_vblank_interrupt();
void hh_ppu_init();
void hh_ppu_deinit();
+/* @brief update single foreground sprite */
void hh_ppu_update_foreground(unsigned index, hh_s_ppu_loc_fam_entry e);
+/* @brief update single background sprite */
void hh_ppu_update_background(unsigned index, hh_s_ppu_loc_bam_entry e);
-void hh_ppu_update_sprite(unsigned tilemap_index, hh_s_ppu_loc_sprite sprite);
+/* @brief update aux register */
void hh_ppu_update_aux(hh_s_ppu_loc_aux aux);
+/* @brief update single sprite */
+void hh_ppu_update_sprite(unsigned tilemap_index, hh_s_ppu_loc_sprite sprite);
+/* @brief update entire palette table */
+void hh_ppu_update_palette_table(hh_ppu_loc_palette_table_t table);
+/* @brief update single palette */
+void hh_ppu_update_palette(unsigned palette_index, hh_ppu_loc_palette_data_t palette);
+/* @brief update single color in palette */
+void hh_ppu_update_color(unsigned palette_index, unsigned color_index, hh_ppu_rgb_color_t color);
diff --git a/src/ppu/types.h b/src/ppu/types.h
index d7605a5..08bef13 100644
--- a/src/ppu/types.h
+++ b/src/ppu/types.h
@@ -3,16 +3,18 @@
#include <stdint.h>
#include <stdbool.h>
-#include "consts.h"
+#include "ppu/consts.h"
typedef uint16_t hh_ppu_addr_t;
typedef uint16_t hh_ppu_data_t;
-typedef uint8_t hh_ppu_loc_sprite_data_t[HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT];
-typedef uint8_t hh_ppu_loc_palette_data_t[HH_PPU_PALETTE_COLOR_COUNT];
+typedef uint8_t hh_ppu_rgb_color_t[3];
+
+typedef hh_ppu_rgb_color_t hh_ppu_loc_palette_data_t[HH_PPU_PALETTE_COLOR_COUNT];
+typedef hh_ppu_loc_palette_data_t hh_ppu_loc_palette_table_t[HH_PPU_PALETTE_COUNT];
+typedef uint8_t hh_ppu_loc_sprite_data_t[HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT];
typedef hh_ppu_loc_sprite_data_t hh_s_ppu_loc_sprite;
-typedef hh_ppu_loc_palette_data_t hh_s_ppu_loc_palette;
typedef struct {
bool horizontal_flip;
@@ -24,8 +26,8 @@ typedef struct {
typedef struct {
bool horizontal_flip;
bool vertical_flip;
- uint16_t position_x;
- uint16_t position_y;
+ int32_t position_x;
+ int32_t position_y;
uint8_t palette_index;
uint8_t tilemap_index;
} hh_s_ppu_loc_fam_entry;
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();
-}
diff --git a/src/stm32.mk b/src/stm32.mk
index 12acf0e..e41bcf9 100644
--- a/src/stm32.mk
+++ b/src/stm32.mk
@@ -56,5 +56,6 @@ STM_SRCS += lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_rcc.c \
lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_tim_ex.c \
lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_uart.c \
lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_uart_ex.c
-STM_SRCS += stm32/idle_task_static_memory.c
+STM_SRCS += stm32/idle_task_static_memory.c \
+ stm32/main.c
diff --git a/src/stm32/main.c b/src/stm32/main.c
new file mode 100644
index 0000000..735b378
--- /dev/null
+++ b/src/stm32/main.c
@@ -0,0 +1,5 @@
+#include "main.h"
+
+void hh_loop() {
+ while(g_hh_run);
+}