diff options
Diffstat (limited to 'src/ppu/internals.c')
-rw-r--r-- | src/ppu/internals.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/ppu/internals.c b/src/ppu/internals.c index a60cb68..2d90665 100644 --- a/src/ppu/internals.c +++ b/src/ppu/internals.c @@ -4,8 +4,9 @@ #include "ppu/internals.h" #include "ppu/types.h" -uint8_t g_hh_ppu_vram_buffer[HH_PPU_COMMAND_BUFFER_SIZE] = { 0 }; -size_t g_hh_ppu_vram_buffer_head = 0; +uint8_t g_hh_ppu_vram_buffer[HH_PPU_COMMAND_BUFFER_SIZE * 2] = { 0 }; +uint8_t* g_hh_ppu_vram_buffer_ptr = g_hh_ppu_vram_buffer; +size_t g_hh_ppu_vram_buffer_size = 0; bool hh_ppu_vram_valid_address(hh_ppu_addr_t addr) { #pragma GCC diagnostic push @@ -19,6 +20,13 @@ bool hh_ppu_vram_valid_address(hh_ppu_addr_t addr) { return false; } +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_vram_write(hh_s_ppu_vram_data data) { for (unsigned i = 0; i < data.size; i++) { hh_ppu_addr_t ppu_addr = data.offset + i; @@ -87,16 +95,20 @@ hh_s_ppu_vram_data hh_ppu_2nat_color(hh_ppu_rgb_color_t rgb) { } void hh_ppu_vram_buffer(uint8_t data[4]) { - size_t head = g_hh_ppu_vram_buffer_head; + size_t head = g_hh_ppu_vram_buffer_size; g_hh_ppu_vram_buffer[head+0] = data[0]; g_hh_ppu_vram_buffer[head+1] = data[1]; g_hh_ppu_vram_buffer[head+2] = data[2]; g_hh_ppu_vram_buffer[head+3] = data[3]; - g_hh_ppu_vram_buffer_head += 4; + g_hh_ppu_vram_buffer_size += 4; } void hh_ppu_vram_flush() { - hh_ppu_vram_dwrite(g_hh_ppu_vram_buffer, g_hh_ppu_vram_buffer_head); - g_hh_ppu_vram_buffer_head = 0; + static bool buffer_swap = false; + buffer_swap = !buffer_swap; + hh_ppu_vram_buffer((uint8_t[4]){ 0xff, 0xff, 0xff, 0xff }); + hh_ppu_vram_dwrite(g_hh_ppu_vram_buffer_ptr, g_hh_ppu_vram_buffer_size); + g_hh_ppu_vram_buffer_size = 0; + g_hh_ppu_vram_buffer_ptr = g_hh_ppu_vram_buffer + (buffer_swap * HH_PPU_COMMAND_BUFFER_SIZE); } |