From 7da7908989686daa2ac9fd2f3f79cad2f03c0828 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 24 Feb 2023 12:07:02 +0100 Subject: WIP ppu interface --- stm32/main.c | 37 +++++++++++++++++++++++++++++++++++++ stm32/ppu/consts.h | 26 ++++++++++++++++++++++++++ stm32/ppu/internals.h | 22 ++++++++++++++++++++++ stm32/ppu/ppu.h | 11 +++++++++++ stm32/ppu/types.h | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 stm32/ppu/consts.h create mode 100644 stm32/ppu/internals.h create mode 100644 stm32/ppu/ppu.h create mode 100644 stm32/ppu/types.h diff --git a/stm32/main.c b/stm32/main.c index 4722fe0..910d2dd 100644 --- a/stm32/main.c +++ b/stm32/main.c @@ -1,3 +1,40 @@ +#include +#include +#include + +#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)); + + 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; + + return s; +} + int main() { + 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_s_ppu_loc_sprite* sprite = hh_debug_circle_sprite(); + hh_ppu_update_sprite(0, *sprite); + free(sprite); + while (1); } + +void hh_ppu_vblank_interrupt() { + static unsigned long frame = 0; + frame++; + + +} diff --git a/stm32/ppu/consts.h b/stm32/ppu/consts.h new file mode 100644 index 0000000..ee94a69 --- /dev/null +++ b/stm32/ppu/consts.h @@ -0,0 +1,26 @@ +#pragma once + +#define HH_PPU_PALETTE_COUNT 8 +#define HH_PPU_PALETTE_COLOR_COUNT 8 +#define HH_PPU_RAM_BUS_ADDR_WIDTH 16 +#define HH_PPU_RAM_BUS_DATA_WIDTH 16 +#define HH_PPU_FG_SPRITE_COUNT 128 +#define HH_PPU_SPRITE_WIDTH 16 +#define HH_PPU_SPRITE_HEIGHT 16 +#define HH_PPU_SCREEN_WIDTH 320 +#define HH_PPU_SCREEN_HEIGHT 240 +#define HH_PPU_BG_CANVAS_TILES_H 40 +#define HH_PPU_BG_CANVAS_TILES_V 30 + +#include "types.h" + +#define HH_PPU_VRAM_TMM_OFFSET ((hh_ppu_addr_t) 0x0000) +#define HH_PPU_VRAM_TMM_SIZE ((hh_ppu_addr_t) 0xd000) +#define HH_PPU_VRAM_BAM_OFFSET ((hh_ppu_addr_t) 0xd000) +#define HH_PPU_VRAM_BAM_SIZE ((hh_ppu_addr_t) 0x04b0) +#define HH_PPU_VRAM_FAM_OFFSET ((hh_ppu_addr_t) 0xd800) +#define HH_PPU_VRAM_FAM_SIZE ((hh_ppu_addr_t) 0x0100) +#define HH_PPU_VRAM_PAL_OFFSET ((hh_ppu_addr_t) 0xdc00) +#define HH_PPU_VRAM_PAL_SIZE ((hh_ppu_addr_t) 0x0040) +#define HH_PPU_VRAM_AUX_OFFSET ((hh_ppu_addr_t) 0xde00) +#define HH_PPU_VRAM_AUX_SIZE ((hh_ppu_addr_t) 0x0002) diff --git a/stm32/ppu/internals.h b/stm32/ppu/internals.h new file mode 100644 index 0000000..ddb2196 --- /dev/null +++ b/stm32/ppu/internals.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +#include "types.h" + +typedef struct { + hh_ppu_addr_t offset; + hh_ppu_addr_t size; + hh_ppu_data_t* data; +} hh_s_ppu_vram_data; + +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); + +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); + diff --git a/stm32/ppu/ppu.h b/stm32/ppu/ppu.h new file mode 100644 index 0000000..ac01ef7 --- /dev/null +++ b/stm32/ppu/ppu.h @@ -0,0 +1,11 @@ +#pragma once + +#include "types.h" + +void hh_ppu_vblank_interrupt(); +void hh_ppu_init(); + +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); +void hh_ppu_update_sprite(unsigned tilemap_index, hh_s_ppu_loc_sprite sprite); +void hh_ppu_update_aux(hh_s_ppu_loc_aux aux); diff --git a/stm32/ppu/types.h b/stm32/ppu/types.h new file mode 100644 index 0000000..d7605a5 --- /dev/null +++ b/stm32/ppu/types.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +#include "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 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; + bool vertical_flip; + uint8_t palette_index; + uint8_t tilemap_index; +} hh_s_ppu_loc_bam_entry; + +typedef struct { + bool horizontal_flip; + bool vertical_flip; + uint16_t position_x; + uint16_t position_y; + uint8_t palette_index; + uint8_t tilemap_index; +} hh_s_ppu_loc_fam_entry; + +typedef struct { + bool sysreset; + bool fg_fetch; + uint16_t bg_shift_x; + uint16_t bg_shift_y; +} hh_s_ppu_loc_aux; + +typedef uint16_t hh_ppu_native_color_t; -- cgit v1.2.3