Browse code

Starting redesign for devices

neauoire authored on 26/02/2021 18:16:35
Showing 5 changed files
... ...
@@ -98,11 +98,26 @@ A device that works like a NES controller, each button is a bit from a single by
98 98
 
99 99
 ## TODOs
100 100
 
101
-- Line routine
102
-- Getting rid of IOR/IOW would be nice..
103
-- Example of button pointing to a subroutine
101
+### OS Boot Disk
104 102
 
105
-### Misc TODOs
103
+- Load external disk in disk2
104
+- Build hex editor
105
+- Build sprite editor
106
+
107
+### Examples
108
+
109
+- Basics:
110
+	- Simple drag/drop redraw
111
+	- Window basics with open/close drag/drop redraw
112
+	- Example of button pointing to a subroutine
113
+- GUI:
114
+	- Line routine
115
+
116
+### Devices redesign
117
+
118
+- Possibly remove
119
+
120
+### Assembler
106 121
 
107 122
 - Includes
108 123
 - Defines
... ...
@@ -241,7 +241,8 @@ int
241 241
 makevariable(char *id, Uint16 *addr, FILE *f)
242 242
 {
243 243
 	char wv[64];
244
-	Uint8 origin, len;
244
+	Uint16 origin;
245
+	Uint8 len;
245 246
 	Macro *m = NULL;
246 247
 	fscanf(f, "%s", wv);
247 248
 	origin = *addr;
248 249
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+( blank )
2
+
3
+:dev/r fff8 ( std read port )
4
+:dev/w fff9 ( std write port )
5
+
6
+&Device { r 8 w 8 }
7
+
8
+|0100 @RESET 
9
+
10
+	#aa =device1.r 
11
+	~device1.r NOP
12
+
13
+BRK
14
+
15
+|c000 @FRAME BRK 
16
+|d000 @ERROR BRK 
17
+
18
+|FF00 
19
+;device1 Device 
20
+;device2 Device
21
+
22
+|FFF0 [ f2ac 35bb 2b53 ] ( palette )
23
+|FFFA .RESET .FRAME .ERROR
... ...
@@ -18,10 +18,13 @@ WITH REGARD TO THIS SOFTWARE.
18 18
 /* clang-format off */
19 19
 void   setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); }
20 20
 int    getflag(Uint8 *a, char flag) { return *a & flag; }
21
-void   mempoke8(Memory *m, Uint16 a, Uint8 b) { m->dat[a] = b; }
22
-Uint8  mempeek8(Memory *m, Uint16 a) { return m->dat[a]; }
23
-void   mempoke16(Memory *m, Uint16 a, Uint16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); }
24
-Uint16 mempeek16(Memory *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); }
21
+Uint8  devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < u->devices ? u->dev[id].poke(b0, b1) : b1; }
22
+Uint8  devpeek8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < u->devices ? u->dev[id].peek(b0, b1) : b1; }
23
+void   mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = a >= 0xff00 ? devpoke8(u, (a & 0xff) >> 4, a & 0xf, b) : b; }
24
+Uint8  mempeek8(Uxn *u, Uint16 a) { return a >= 0xff00 ? devpeek8(u, (a & 0xff) >> 4, a & 0xf, u->ram.dat[a]) : u->ram.dat[a]; }
25
+void   mempoke16(Uxn *u, Uint16 a, Uint16 b) { mempoke8(u, a, b >> 8); mempoke8(u, a + 1, b); }
26
+Uint16 mempeek16(Uxn *u, Uint16 a) { return (mempeek8(u, a) << 8) + mempeek8(u, a + 1); }
27
+
25 28
 void   push8(Stack *s, Uint8 a) { s->dat[s->ptr++] = a; }
26 29
 Uint8  pop8(Stack *s) { return s->dat[--s->ptr]; }
27 30
 Uint8  peek8(Stack *s, Uint8 a) { return s->dat[s->ptr - a - 1]; }
... ...
@@ -32,10 +35,10 @@ Uint16 peek16(Stack *s, Uint8 a) { return peek8(s, a * 2) + (peek8(s, a * 2 + 1)
32 35
 void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); }
33 36
 void op_lit(Uxn *u) { u->literal += 1; }
34 37
 void op_nop(Uxn *u) { printf("0x%02x \n", pop8(&u->wst)); fflush(stdout); }
35
-void op_ior(Uxn *u) { Device *dev = &u->dev[mempeek8(&u->ram, u->devr)]; if(dev) push8(&u->wst, dev->read(dev, &u->ram, pop8(&u->wst))); }
36
-void op_iow(Uxn *u) { Uint8 a = pop8(&u->wst); Device *dev = &u->dev[mempeek8(&u->ram, u->devw)]; if(dev) dev->write(dev, &u->ram, a); }
37
-void op_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(&u->ram, a)); }
38
-void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(&u->ram, a, b); }
38
+void op_ior(Uxn *u) { Device *dev = &u->dev[mempeek8(u, u->devr)]; if(dev) push8(&u->wst, dev->read(dev, &u->ram, pop8(&u->wst))); }
39
+void op_iow(Uxn *u) { Uint8 a = pop8(&u->wst); Device *dev = &u->dev[mempeek8(u, u->devw)]; if(dev) dev->write(dev, &u->ram, a); }
40
+void op_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(u, a)); }
41
+void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(u, a, b); }
39 42
 /* Logic */
40 43
 void op_jmp(Uxn *u) { u->ram.ptr = pop16(&u->wst); }
41 44
 void op_jsr(Uxn *u) { push16(&u->rst, u->ram.ptr); u->ram.ptr = pop16(&u->wst); }
... ...
@@ -64,10 +67,10 @@ void op_lth(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst,
64 67
 /* --- */
65 68
 void op_lit16(Uxn *u) { u->literal += 2; }
66 69
 void op_nop16(Uxn *u) { printf("%04x\n", pop16(&u->wst)); }
67
-void op_ior16(Uxn *u) { Uint8 a = pop8(&u->wst); Device *dev = &u->dev[mempeek8(&u->ram, u->devr)]; if(dev) push16(&u->wst, (dev->read(dev, &u->ram, a) << 8) + dev->read(dev, &u->ram, a + 1)); }
68
-void op_iow16(Uxn *u) { Uint8 a = pop8(&u->wst); Uint8 b = pop8(&u->wst); Device *dev = &u->dev[mempeek8(&u->ram, u->devw)]; if(dev) { dev->write(dev, &u->ram, b); dev->write(dev, &u->ram, a); } }
69
-void op_ldr16(Uxn *u) { Uint16 a = pop16(&u->wst); push16(&u->wst, mempeek16(&u->ram, a)); }
70
-void op_str16(Uxn *u) { Uint16 a = pop16(&u->wst); Uint16 b = pop16(&u->wst); mempoke16(&u->ram, a, b); }
70
+void op_ior16(Uxn *u) { Uint8 a = pop8(&u->wst); Device *dev = &u->dev[mempeek8(u, u->devr)]; if(dev) push16(&u->wst, (dev->read(dev, &u->ram, a) << 8) + dev->read(dev, &u->ram, a + 1)); }
71
+void op_iow16(Uxn *u) { Uint8 a = pop8(&u->wst); Uint8 b = pop8(&u->wst); Device *dev = &u->dev[mempeek8(u, u->devw)]; if(dev) { dev->write(dev, &u->ram, b); dev->write(dev, &u->ram, a); } }
72
+void op_ldr16(Uxn *u) { Uint16 a = pop16(&u->wst); push16(&u->wst, mempeek16(u, a)); }
73
+void op_str16(Uxn *u) { Uint16 a = pop16(&u->wst); Uint16 b = pop16(&u->wst); mempoke16(u, a, b); }
71 74
 void op_and16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b & a); }
72 75
 void op_ora16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b | a); }
73 76
 void op_rol16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b << a); }
... ...
@@ -197,9 +200,9 @@ loaduxn(Uxn *u, char *filepath)
197 200
 	fread(u->ram.dat, sizeof(u->ram.dat), 1, f);
198 201
 	u->devr = 0xfff8;
199 202
 	u->devw = 0xfff9;
200
-	u->vreset = mempeek16(&u->ram, 0xfffa);
201
-	u->vframe = mempeek16(&u->ram, 0xfffc);
202
-	u->verror = mempeek16(&u->ram, 0xfffe);
203
+	u->vreset = mempeek16(u, 0xfffa);
204
+	u->vframe = mempeek16(u, 0xfffc);
205
+	u->verror = mempeek16(u, 0xfffe);
203 206
 	printf("Uxn loaded[%s] vrst:%04x vfrm:%04x verr:%04x.\n",
204 207
 		filepath,
205 208
 		u->vreset,
... ...
@@ -208,12 +211,28 @@ loaduxn(Uxn *u, char *filepath)
208 211
 	return 1;
209 212
 }
210 213
 
214
+Uint8
215
+peek1(Uint8 b, Uint8 m)
216
+{
217
+	printf("PEEK! %02x\n", b);
218
+	return m;
219
+}
220
+
221
+Uint8
222
+poke1(Uint8 b, Uint8 m)
223
+{
224
+	printf("POKE! %02x\n", b);
225
+	return m;
226
+}
227
+
211 228
 Device *
212 229
 portuxn(Uxn *u, char *name, Uint8 (*rfn)(Device *, Memory *, Uint8), Uint8 (*wfn)(Device *, Memory *, Uint8))
213 230
 {
214 231
 	Device *d = &u->dev[u->devices++];
215 232
 	d->read = rfn;
216 233
 	d->write = wfn;
234
+	d->peek = peek1;
235
+	d->poke = poke1;
217 236
 	d->ptr = 0;
218 237
 	printf("Device #%d: %s \n", u->devices - 1, name);
219 238
 	return d;
... ...
@@ -35,6 +35,8 @@ typedef struct Device {
35 35
 	Uint8 ptr, mem[8];
36 36
 	Uint8 (*read)(struct Device *, Memory *, Uint8);
37 37
 	Uint8 (*write)(struct Device *, Memory *, Uint8);
38
+	Uint8 (*peek)(Uint8, Uint8);
39
+	Uint8 (*poke)(Uint8, Uint8);
38 40
 } Device;
39 41
 
40 42
 typedef struct {