aboutsummaryrefslogtreecommitdiffstats
path: root/src/uxn
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-18 18:18:18 +0200
committerBad Diode <bd@badd10de.dev>2021-05-18 18:18:18 +0200
commitec5b9644db2ff26cc6f0cc3d84854b714a25eff9 (patch)
treee6806bbe0bc84a20d11f620c0425ab58aba12b42 /src/uxn
parent0c7265cf0de9d4ec95d28c5e103c00a63f4a1697 (diff)
downloaduxngba-ec5b9644db2ff26cc6f0cc3d84854b714a25eff9.tar.gz
uxngba-ec5b9644db2ff26cc6f0cc3d84854b714a25eff9.zip
Draw directly to the FRAMEBUFFER
Diffstat (limited to 'src/uxn')
-rw-r--r--src/uxn/devices/ppu.c21
-rw-r--r--src/uxn/uxn.c46
2 files changed, 4 insertions, 63 deletions
diff --git a/src/uxn/devices/ppu.c b/src/uxn/devices/ppu.c
index b977f97..06d84bf 100644
--- a/src/uxn/devices/ppu.c
+++ b/src/uxn/devices/ppu.c
@@ -121,26 +121,7 @@ void
121drawpixel(Ppu *p, Uint16 x, Uint16 y, Uint8 color) 121drawpixel(Ppu *p, Uint16 x, Uint16 y, Uint8 color)
122{ 122{
123 if(x >= p->pad && x <= p->width - p->pad - 1 && y >= p->pad && y <= p->height - p->pad - 1) 123 if(x >= p->pad && x <= p->width - p->pad - 1 && y >= p->pad && y <= p->height - p->pad - 1)
124 p->output[y * p->width + x] = p->colors[color]; 124 FRAMEBUFFER[y][x] = p->colors[color];
125}
126
127void
128drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr)
129{
130 Uint8 i, x, y, b;
131 for(i = 0; i < 0x20; ++i) { /* memory */
132 x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i];
133 puticn(p, p->bg, x, y, font[(b >> 4) & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
134 puticn(p, p->bg, x + 8, y, font[b & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
135 }
136 for(x = 0; x < 0x20; ++x) {
137 drawpixel(p, x, p->height / 2, 2);
138 drawpixel(p, p->width - x, p->height / 2, 2);
139 drawpixel(p, p->width / 2, p->height - x, 2);
140 drawpixel(p, p->width / 2, x, 2);
141 drawpixel(p, p->width / 2 - 16 + x, p->height / 2, 2);
142 drawpixel(p, p->width / 2, p->height / 2 - 16 + x, 2);
143 }
144} 125}
145 126
146void 127void
diff --git a/src/uxn/uxn.c b/src/uxn/uxn.c
index 796a980..08b3b9b 100644
--- a/src/uxn/uxn.c
+++ b/src/uxn/uxn.c
@@ -116,14 +116,6 @@ void (*ops[])(Uxn *u) = {
116 116
117#pragma mark - Core 117#pragma mark - Core
118 118
119int
120haltuxn(Uxn *u, char *name, int id)
121{
122 txt_printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->ram.ptr);
123 u->ram.ptr = 0;
124 return 0;
125}
126
127void 119void
128opcuxn(Uxn *u, Uint8 instr) 120opcuxn(Uxn *u, Uint8 instr)
129{ 121{
@@ -140,46 +132,14 @@ opcuxn(Uxn *u, Uint8 instr)
140} 132}
141 133
142int 134int
143stepuxn(Uxn *u, Uint8 instr)
144{
145 opcuxn(u, instr);
146 if(u->wst.error)
147 return haltuxn(u, u->wst.error == 1 ? "Working-stack underflow" : "Working-stack overflow", instr);
148 if(u->rst.error)
149 return haltuxn(u, u->rst.error == 1 ? "Return-stack underflow" : "Return-stack overflow", instr);
150 return 1;
151}
152
153int
154evaluxn(Uxn *u, Uint16 vec) 135evaluxn(Uxn *u, Uint16 vec)
155{ 136{
156 u->ram.ptr = vec; 137 u->ram.ptr = vec;
157 u->wst.error = 0; 138 u->wst.error = 0;
158 u->rst.error = 0; 139 u->rst.error = 0;
159 while(u->ram.ptr) 140 while(u->ram.ptr) {
160 if(!stepuxn(u, u->ram.dat[u->ram.ptr++])) 141 opcuxn(u, u->ram.dat[u->ram.ptr++]);
161 return 0; 142 }
162 return 1;
163}
164
165int
166bootuxn(Uxn *u)
167{
168 size_t i;
169 char *cptr = (char *)u;
170 for(i = 0; i < sizeof(*u); i++)
171 cptr[i] = 0;
172 return 1;
173}
174
175int
176loaduxn(Uxn *u, char *filepath)
177{
178 FILE *f;
179 if(!(f = fopen(filepath, "rb")))
180 return haltuxn(u, "Missing input rom.", 0);
181 fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f);
182 txt_printf("Uxn loaded[%s].\n", filepath);
183 return 1; 143 return 1;
184} 144}
185 145