diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-04-06 16:49:36 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-04-06 16:49:36 +0200 |
commit | 892424ba4d0c979e4351f7a866b6fe777783e4d2 (patch) | |
tree | d6688765834be74370038d8662703bd83b1acd40 /src/ppusim | |
parent | 4881723cf765fbd7bad2a1f08baf5897a7425401 (diff) |
dma send done and working
Diffstat (limited to 'src/ppusim')
-rw-r--r-- | src/ppusim/mem.c | 56 | ||||
-rw-r--r-- | src/ppusim/sim.c | 2 | ||||
-rw-r--r-- | src/ppusim/work.c | 6 |
3 files changed, 62 insertions, 2 deletions
diff --git a/src/ppusim/mem.c b/src/ppusim/mem.c index f536727..20464cb 100644 --- a/src/ppusim/mem.c +++ b/src/ppusim/mem.c @@ -6,12 +6,66 @@ hh_ppu_data_t *g_hh_ppusim_vram = NULL; +#define HH_DBG_PPUSIM_PRINT_MEM + +static void hh_ppu_dbg_memprint(hh_ppu_addr_t addr, hh_ppu_data_t data) { + int area_i = ((addr >= HH_PPU_VRAM_TMM_OFFSET) && (addr < (HH_PPU_VRAM_TMM_OFFSET + HH_PPU_VRAM_TMM_SIZE))) ? 0 : + ((addr >= HH_PPU_VRAM_BAM_OFFSET) && (addr < (HH_PPU_VRAM_BAM_OFFSET + HH_PPU_VRAM_BAM_SIZE))) ? 1 : + ((addr >= HH_PPU_VRAM_FAM_OFFSET) && (addr < (HH_PPU_VRAM_FAM_OFFSET + HH_PPU_VRAM_FAM_SIZE))) ? 2 : + ((addr >= HH_PPU_VRAM_PAL_OFFSET) && (addr < (HH_PPU_VRAM_PAL_OFFSET + HH_PPU_VRAM_PAL_SIZE))) ? 3 : + ((addr >= HH_PPU_VRAM_AUX_OFFSET) && (addr < (HH_PPU_VRAM_AUX_OFFSET + HH_PPU_VRAM_AUX_SIZE))) ? 4 : -1; + char* area_str = (area_i == 0) ? "TMM" : + (area_i == 1) ? "BAM" : + (area_i == 2) ? "FAM" : + (area_i == 3) ? "PAL" : + (area_i == 4) ? "AUX" : "???"; + printf("[%s] %04x: %04x", area_str, addr, data); + + switch (area_i) { + case 0: { + unsigned short i = addr - HH_PPU_VRAM_TMM_OFFSET; + printf(" (tile[%04i] data)", i / 52); + break; + } + case 1: { + unsigned short i = addr - HH_PPU_VRAM_BAM_OFFSET; + printf(" (bam tile [%02i, %02i] attributes)", i % 40, i / 40); + break; + } + case 2: { + unsigned short i = addr - HH_PPU_VRAM_FAM_OFFSET; + printf(" (fam[%03i] attributes)", i/2); + break; + } + case 3: { + unsigned short i = addr - HH_PPU_VRAM_PAL_OFFSET; + printf(" (pal[%02i] = #%x%x%x%x%x%x)", i, (data >> 0) & 0xf, (data >> 0) & 0xf, + (data >> 4) & 0xf, (data >> 4) & 0xf, + (data >> 8) & 0xf, (data >> 8) & 0xf); + break; + } + case 4: { + + if (addr == 0xde01 && ((data & (1 << 2)) > 0)) printf(" (+sysreset)"); + break; + } + + default: { break; } + } + + if (addr == 0xffff && data == 0xffff) printf(" (flush)"); + + printf("\n"); +} + void hh_ppu_vram_dwrite(uint8_t* data, size_t size) { for (size_t i = 0; i < size; i += 4) { if (i+4 > size) break; hh_ppu_addr_t ppu_addr = (data[i+0] << 8) | (data[i+1] << 0); hh_ppu_data_t ppu_data = (data[i+2] << 8) | (data[i+3] << 0); - // printf("%04x: %04x\n", ppu_addr, ppu_data); +#ifdef HH_DBG_PPUSIM_PRINT_MEM + hh_ppu_dbg_memprint(ppu_addr, ppu_data); +#endif if (!hh_ppu_vram_valid_address(ppu_addr)) continue; g_hh_ppusim_vram[ppu_addr] = ppu_data; } diff --git a/src/ppusim/sim.c b/src/ppusim/sim.c index be5fbeb..14d79a7 100644 --- a/src/ppusim/sim.c +++ b/src/ppusim/sim.c @@ -24,7 +24,7 @@ void hh_ppu_init() { g_hh_ppusim_threads = malloc(sizeof(pthread_t) * g_hh_ppusim_core_count); g_hh_ppusim_vram = malloc(sizeof(hh_ppu_data_t) * 0xffff); - memset(g_hh_ppusim_vram, 0x0000, 0xffff); + memset(g_hh_ppusim_vram, 0x0000, 0xffff * sizeof(hh_ppu_data_t)); } void hh_ppu_load_tilemap() { diff --git a/src/ppusim/work.c b/src/ppusim/work.c index 96d15aa..977b2c4 100644 --- a/src/ppusim/work.c +++ b/src/ppusim/work.c @@ -6,6 +6,8 @@ #include "ppusim/pixel.h" #include "ppusim/sim.h" #include "ppusim/work.h" +#include "ppusim/mem.h" +#include "ppu/internals.h" pthread_t *g_hh_ppusim_threads; unsigned g_hh_ppusim_core_count; @@ -23,6 +25,10 @@ void *hh_ppusim_draw_thread(void *arg) { } void hh_ppusim_draw_frame(SDL_Renderer *renderer) { + hh_ppu_data_t *aux = &g_hh_ppusim_vram[HH_PPU_VRAM_AUX_OFFSET]; + bool reset = HH_RESIZE(aux[1], 2, 2); + if (reset) memset(g_hh_ppusim_vram, 0x0000, 0xffff * sizeof(hh_ppu_data_t)); + for (unsigned core = 0; core < g_hh_ppusim_core_count; core++) pthread_create(&g_hh_ppusim_threads[core], NULL, hh_ppusim_draw_thread, (void *)(unsigned long)core); for (unsigned core = 0; core < g_hh_ppusim_core_count; core++) pthread_join(g_hh_ppusim_threads[core], NULL); |