aboutsummaryrefslogtreecommitdiff
path: root/src/ppu
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-02-24 22:24:50 +0100
committerlonkaars <loek@pipeframe.xyz>2023-02-24 22:24:50 +0100
commit1a2bd8b70c12d497acb2eba548d161b2bfc4f9b6 (patch)
tree593cddcc473aad7a5e55f870893d813f17651a85 /src/ppu
parent97dd5f6bd354c8e931778c79c7a421d5bdaafee5 (diff)
background sprites working in ppusim
Diffstat (limited to 'src/ppu')
-rw-r--r--src/ppu/internals.c17
-rw-r--r--src/ppu/internals.h5
2 files changed, 10 insertions, 12 deletions
diff --git a/src/ppu/internals.c b/src/ppu/internals.c
index 5b47b75..7826ece 100644
--- a/src/ppu/internals.c
+++ b/src/ppu/internals.c
@@ -3,11 +3,6 @@
#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
@@ -72,13 +67,11 @@ hh_s_ppu_vram_data hh_ppu_2nat_aux(hh_s_ppu_loc_aux aux) {
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;
- }
+ for (unsigned i = 0; i < HH_PPU_SPRITE_WIDTH * HH_PPU_SPRITE_HEIGHT; i++) {
+ 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 = {
diff --git a/src/ppu/internals.h b/src/ppu/internals.h
index 7b60255..6e9dda7 100644
--- a/src/ppu/internals.h
+++ b/src/ppu/internals.h
@@ -4,6 +4,11 @@
#include "ppu/types.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)) >> lower)
+
typedef struct {
hh_ppu_addr_t offset;
hh_ppu_addr_t size;