aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-03-04 17:28:46 +0100
committerBad Diode <bd@badd10de.dev>2022-03-04 17:28:46 +0100
commit43eaa37472551bf1f7d2d245d92a939bc428f016 (patch)
treec61c99ef25e488bd17368056edcf266fa8b44621
parent232f303cf139ec7aa0b3af1c89003c3f01a9f25b (diff)
downloaduxnfb-43eaa37472551bf1f7d2d245d92a939bc428f016.tar.gz
uxnfb-43eaa37472551bf1f7d2d245d92a939bc428f016.zip
Update ppu to use current version of screen talk
-rw-r--r--Makefile2
-rw-r--r--src/main.c66
-rw-r--r--src/ppu.c28
-rw-r--r--src/ppu.h6
-rw-r--r--src/uxn.h1
5 files changed, 71 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index cfdf43f..203e1d3 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ BASE_UXN := src/uxn/src
2SRC_DIR ?= src 2SRC_DIR ?= src
3BUILD_DIR ?= build 3BUILD_DIR ?= build
4SRC_MAIN ?= $(SRC_DIR)/main.c 4SRC_MAIN ?= $(SRC_DIR)/main.c
5EXE_NAME ?= fbtest 5EXE_NAME ?= uxnfb
6BIN := $(BUILD_DIR)/$(EXE_NAME) 6BIN := $(BUILD_DIR)/$(EXE_NAME)
7UXN_HEAD := $(BASE_UXN)/uxn.h 7UXN_HEAD := $(BASE_UXN)/uxn.h
8 8
diff --git a/src/main.c b/src/main.c
index 73a74e1..7d77051 100644
--- a/src/main.c
+++ b/src/main.c
@@ -89,22 +89,56 @@ system_talk(Device *d, u8 b0, u8 w) {
89 89
90void 90void
91screen_talk(Device *d, u8 b0, u8 w) { 91screen_talk(Device *d, u8 b0, u8 w) {
92 if(w && b0 == 0xe) { 92 if (w) {
93 Uint16 x = mempeek16(d->dat, 0x8); 93 switch (b0) {
94 Uint16 y = mempeek16(d->dat, 0xa); 94 case 0x1: {
95 Uint8 layer = d->dat[0xe] >> 4 & 0x1; 95 d->vector = mempeek16(d->dat, 0x0);
96 ppu_pixel(layer, x, y, d->dat[0xe] & 0x3); 96 } break;
97 reqdraw = 1; 97 case 0xe: {
98 } else if(w && b0 == 0xf) { 98 u16 x = mempeek16(d->dat, 0x8);
99 Uint16 x = mempeek16(d->dat, 0x8); 99 u16 y = mempeek16(d->dat, 0xa);
100 Uint16 y = mempeek16(d->dat, 0xa); 100 u8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
101 Uint8 layer = d->dat[0xf] >> 0x6 & 0x1; 101 u8 *layer = d->dat[0xe] >> 4 & 0x1 ? pixels_fg : pixels_bg;
102 Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; 102 u8 mode = d->dat[0xe] >> 5;
103 if(d->dat[0xf] >> 0x7 & 0x1) 103 u8 color = d->dat[0xf] & 0xf;
104 ppu_2bpp(layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); 104 if(!mode) {
105 else 105 ppu_pixel(layer, x, y, d->dat[0xe] & 0x3);
106 ppu_1bpp(layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); 106 } else if(mode-- & 0x1) {
107 reqdraw = 1; 107 u8 flipx = mode & 0x2;
108 u8 flipy = mode & 0x4;
109 ppu_1bpp(layer, x, y, addr, color, flipx, flipy);
110 } else {
111 u8 flipx = mode & 0x2;
112 u8 flipy = mode & 0x4;
113 ppu_2bpp(layer, x, y, addr, color, flipx, flipy);
114 }
115 if(d->dat[0x6] & 0x01) { mempoke16(d->dat, 0x8, x + 1); }
116 if(d->dat[0x6] & 0x02) { mempoke16(d->dat, 0xa, y + 1); }
117 } break;
118 case 0xf: {
119 u16 x = mempeek16(d->dat, 0x8);
120 u16 y = mempeek16(d->dat, 0xa);
121 u8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
122 u8 *layer = d->dat[0xf] >> 6 & 0x1 ? pixels_fg : pixels_bg;
123 u8 color = d->dat[0xf] & 0xf;
124 u8 flipx = (d->dat[0xf] >> 0x4) & 0x1;
125 u8 flipy = (d->dat[0xf] >> 0x5) & 0x1;
126 if(d->dat[0xf] >> 0x7 & 0x1) {
127 ppu_2bpp(layer, x, y, addr, color, flipx, flipy);
128 if(d->dat[0x6] & 0x04) {
129 mempoke16(d->dat, 0xc, mempeek16(d->dat, 0xc) + 16);
130 }
131 } else {
132 ppu_1bpp(layer, x, y, addr, color, flipx, flipy);
133 if(d->dat[0x6] & 0x04) {
134 mempoke16(d->dat, 0xc, mempeek16(d->dat, 0xc) + 8);
135 }
136 }
137 if(d->dat[0x6] & 0x01) { mempoke16(d->dat, 0x8, x + 8); }
138 if(d->dat[0x6] & 0x02) { mempoke16(d->dat, 0xa, y + 8); }
139 } break;
140 default: break;
141 }
108 } 142 }
109} 143}
110 144
diff --git a/src/ppu.c b/src/ppu.c
index 19e530b..a8d7dc6 100644
--- a/src/ppu.c
+++ b/src/ppu.c
@@ -21,7 +21,8 @@ static size_t screen_height = 0;
21static u32 *framebuffer = 0; 21static u32 *framebuffer = 0;
22 22
23static u32 palette[16]; 23static u32 palette[16];
24static u8 *pixels_buf; 24static u8 *pixels_fg;
25static u8 *pixels_bg;
25static u8 *dirty_lines; 26static u8 *dirty_lines;
26static u8 reqdraw = 0; 27static u8 reqdraw = 0;
27// TODO: Probably should consider this 28// TODO: Probably should consider this
@@ -35,17 +36,18 @@ static u8 blending[5][16] = {
35 {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; 36 {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}};
36 37
37void 38void
38ppu_pixel(u8 layer, u16 x, u16 y, u8 color) { 39ppu_pixel(u8 *layer, u16 x, u16 y, u8 color) {
39 size_t idx = y * screen_width + x; 40 if(x < screen_width && y < screen_height) {
40 u8 *pixel = &pixels_buf[idx], shift = layer * 2; 41 Uint32 i = x + y *screen_width;
41 if(x < screen_width && y < screen_height) { 42 if(color != layer[i]) {
42 *pixel = (*pixel & ~(0x3 << shift)) | (color << shift); 43 layer[i] = color;
43 } 44 }
45 }
44 dirty_lines[y] |= 1; 46 dirty_lines[y] |= 1;
45} 47}
46 48
47void 49void
48ppu_1bpp(u8 layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) { 50ppu_1bpp(u8 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) {
49 u16 v, h; 51 u16 v, h;
50 for(v = 0; v < 8; v++) 52 for(v = 0; v < 8; v++)
51 for(h = 0; h < 8; h++) { 53 for(h = 0; h < 8; h++) {
@@ -59,7 +61,7 @@ ppu_1bpp(u8 layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) {
59} 61}
60 62
61void 63void
62ppu_2bpp(u8 layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) { 64ppu_2bpp(u8 *layer, u16 x, u16 y, u8 *sprite, u8 color, u8 flipx, u8 flipy) {
63 u16 v, h; 65 u16 v, h;
64 for(v = 0; v < 8; v++) 66 for(v = 0; v < 8; v++)
65 for(h = 0; h < 8; h++) { 67 for(h = 0; h < 8; h++) {
@@ -106,7 +108,8 @@ ppu_init(void) {
106 } 108 }
107 109
108 // Allocate intermediate buffers. 110 // Allocate intermediate buffers.
109 pixels_buf = malloc(screen_width * screen_height); 111 pixels_fg = malloc(screen_width * screen_height);
112 pixels_bg = malloc(screen_width * screen_height);
110 dirty_lines = malloc(screen_height); 113 dirty_lines = malloc(screen_height);
111 114
112 // Initialize default palette. 115 // Initialize default palette.
@@ -116,7 +119,8 @@ ppu_init(void) {
116 palette[3] = 0xff7777; 119 palette[3] = 0xff7777;
117 120
118 // Clear pixel buffer memory. 121 // Clear pixel buffer memory.
119 memset(pixels_buf, 0, screen_width * screen_height); 122 memset(pixels_fg, 0, screen_width * screen_height);
123 memset(pixels_bg, 0, screen_width * screen_height);
120 memset(dirty_lines, 1, screen_height); 124 memset(dirty_lines, 1, screen_height);
121 125
122 // Make sure we perform an initial screen drawing. 126 // Make sure we perform an initial screen drawing.
@@ -135,7 +139,7 @@ blit_framebuffer(void) {
135 if (dirty_lines[j] != 0) { 139 if (dirty_lines[j] != 0) {
136 for (size_t i = 0; i < screen_width; i++) { 140 for (size_t i = 0; i < screen_width; i++) {
137 size_t idx = i + j * screen_width; 141 size_t idx = i + j * screen_width;
138 framebuffer[idx] = palette[pixels_buf[idx] % 16]; 142 framebuffer[idx] = palette[pixels_fg[idx] << 2 | pixels_bg[idx]];
139 } 143 }
140 } 144 }
141 dirty_lines[j] = 0; 145 dirty_lines[j] = 0;
diff --git a/src/ppu.h b/src/ppu.h
index 852c207..1c427c3 100644
--- a/src/ppu.h
+++ b/src/ppu.h
@@ -15,6 +15,6 @@ typedef unsigned short Uint16;
15typedef unsigned int Uint32; 15typedef unsigned int Uint32;
16 16
17int ppu_init(void); 17int ppu_init(void);
18void ppu_pixel(Uint8 layer, Uint16 x, Uint16 y, Uint8 color); 18void ppu_pixel(Uint8 *layer, Uint16 x, Uint16 y, Uint8 color);
19void ppu_1bpp(Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); 19void ppu_1bpp(Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
20void ppu_2bpp(Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); 20void ppu_2bpp(Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
diff --git a/src/uxn.h b/src/uxn.h
index e904e24..94dda0b 100644
--- a/src/uxn.h
+++ b/src/uxn.h
@@ -29,6 +29,7 @@ typedef struct {
29typedef struct Device { 29typedef struct Device {
30 struct Uxn *u; 30 struct Uxn *u;
31 Uint8 addr, dat[16], *mem; 31 Uint8 addr, dat[16], *mem;
32 u16 vector;
32 void (*talk)(struct Device *d, Uint8, Uint8); 33 void (*talk)(struct Device *d, Uint8, Uint8);
33} Device; 34} Device;
34 35