diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-03-10 13:16:16 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-03-10 13:16:16 +0100 |
commit | c37397234534e9888dfeed9b1728c46646c33b58 (patch) | |
tree | c0e97dcccb1fce5bcd4550db243a67949a42ea1a /src/ppu | |
parent | bf8c5fdb43ae2446a502227a95f17167c3dcda33 (diff) |
`clang-format`
Diffstat (limited to 'src/ppu')
-rw-r--r-- | src/ppu/internals.c | 75 | ||||
-rw-r--r-- | src/ppu/ppu.c | 22 |
2 files changed, 32 insertions, 65 deletions
diff --git a/src/ppu/internals.c b/src/ppu/internals.c index 650ba3e..b8d3e27 100644 --- a/src/ppu/internals.c +++ b/src/ppu/internals.c @@ -1,8 +1,8 @@ #include <stdlib.h> -#include "ppu/types.h" -#include "ppu/internals.h" #include "ppu/consts.h" +#include "ppu/internals.h" +#include "ppu/types.h" bool hh_ppu_vram_valid_address(hh_ppu_addr_t addr) { #pragma GCC diagnostic push @@ -17,88 +17,59 @@ bool hh_ppu_vram_valid_address(hh_ppu_addr_t addr) { } 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]); + 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); + 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; + 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 - }; + 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); + 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, 7, 3) << 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 - }; + 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, 7, 3) << 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 - }; + 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(const 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); + hh_ppu_data_t *data = malloc(sizeof(hh_ppu_data_t) * HH_PPU_VRAM_TMM_SPRITE_SIZE); for (unsigned i = 0; i < HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT; i++) { - unsigned word = i / 5; + unsigned word = i / 5; unsigned pixel = i % 5; if (pixel == 0) data[word] = 0; 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 - }; + 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); + 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) << 8 | - HH_RESIZE(rgb[1], 3, 0) << 4 | - HH_RESIZE(rgb[2], 3, 0) << 0; + data[0] = HH_RESIZE(rgb[0], 3, 0) << 8 | HH_RESIZE(rgb[1], 3, 0) << 4 | HH_RESIZE(rgb[2], 3, 0) << 0; - hh_s_ppu_vram_data out = { - .data = data, - .size = HH_PPU_VRAM_PAL_ENTRY_SIZE - }; + hh_s_ppu_vram_data out = {.data = data, .size = HH_PPU_VRAM_PAL_ENTRY_SIZE}; return out; } diff --git a/src/ppu/ppu.c b/src/ppu/ppu.c index 5f33c55..df14b9f 100644 --- a/src/ppu/ppu.c +++ b/src/ppu/ppu.c @@ -1,52 +1,48 @@ #include <stdlib.h> -#include "ppu/ppu.h" -#include "ppu/internals.h" #include "ppu/consts.h" +#include "ppu/internals.h" +#include "ppu/ppu.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; + 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; + 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, const 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; + 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; + 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]); + 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]); + 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; + 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); } |