commit 1e0d5bbf50ab4ab3f8f323c1139fec0e5ed06057
parent e2b6b6907dc4bbe16bc3f5e7880b0fa0e6a3a747
Author: neauoire <aliceffekt@gmail.com>
Date: Fri, 5 Feb 2021 11:57:37 -0800
Added experimental dev1
Diffstat:
6 files changed, 57 insertions(+), 34 deletions(-)
diff --git a/README.md b/README.md
@@ -25,6 +25,7 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
- `( comment )`, toggle parsing on/off
- `|0010`, move to position in the program
+- `"hello`, push literal bytes for word "hello"
```
;value ( alloc a zero-page variable )
diff --git a/etc/usm.sublime-syntax b/etc/usm.sublime-syntax
@@ -29,7 +29,7 @@ contexts:
- match: '\;(\S+)\s?'
scope: string.control
pop: true
- - match: '\_(\S+)\s?'
+ - match: '\@(\S+)\s?'
scope: string.control
pop: true
- match: '\,(\S+)\s?'
@@ -38,6 +38,9 @@ contexts:
- match: '\.(\S+)\s?'
scope: keyword.control
pop: true
+ - match: '\"(\S+)\s?'
+ scope: keyword.control
+ pop: true
comments:
- match: '\('
diff --git a/examples/blank.usm b/examples/blank.usm
@@ -1,24 +1,27 @@
( blank project )
;variable1
-;variable2
-_constant1 abcd
+:constant1 9abc
|0100 ( -------------------------------- )
-:RESET BRK
+@RESET
-|c000 ( -------------------------------- )
+,abcd
+
+BRK ( RESET-END )
-:FRAME ( FRAME-START )
+|c000 ( -------------------------------- )
+@FRAME ( FRAME-START )
+,abcd
BRK ( FRAME-END )
|d000 ( -------------------------------- )
-:ERROR BRK
+@ERROR BRK
|FFFA ( -------------------------------- )
diff --git a/examples/core.usm b/examples/core.usm
@@ -1,30 +1,21 @@
( blank project )
;variable1
-:constant1 9abc
+:dev1r FFF0
+:dev1w FFF1
-|0100 ( -------------------------------- )
+|0100 @RESET
-@RESET
+"hello
-,abcd
+,dev1w STR
+,dev1w STR
+,dev1w STR
+,dev1w STR
+,dev1w STR
-BRK ( RESET-END )
+BRK ( RESET )
-|c000 ( -------------------------------- )
-
-@FRAME ( FRAME-START )
-
-,abcd
-
-BRK ( FRAME-END )
-
-|d000 ( -------------------------------- )
-
-@ERROR BRK
-
-|FFFA ( -------------------------------- )
-
-.RESET
-.FRAME
-.ERROR
+|c000 @FRAME BRK
+|d000 @ERROR BRK
+|FFFA .RESET .FRAME .ERROR
diff --git a/uxn.c b/uxn.c
@@ -85,7 +85,7 @@ echom(Memory *m, Uint8 len, char *name)
/* clang-format off */
-Uint8 mempeek8(Uint16 s) { return cpu.rom.dat[s] & 0xff; }
+Uint8 rampeek8(Uint16 s) { return cpu.ram.dat[s] & 0xff; }
Uint16 mempeek16(Uint16 s) { return (cpu.rom.dat[s] << 8) + (cpu.rom.dat[s+1] & 0xff); }
void wspush8(Uint8 b) { cpu.wst.dat[cpu.wst.ptr++] = b; }
Uint8 wspop8(void) { return cpu.wst.dat[--cpu.wst.ptr]; }
@@ -159,6 +159,14 @@ error(char *name)
}
int
+device1(Uint8 *read, Uint8 *write)
+{
+ printf("%c", *write);
+ *write = 0;
+ return 0;
+}
+
+int
eval(void)
{
Uint8 instr = cpu.rom.dat[cpu.rom.ptr++];
@@ -192,12 +200,15 @@ start(FILE *f)
cpu.vframe = mempeek16(0xfffc);
cpu.verror = mempeek16(0xfffe);
/* eval reset */
- printf("Phase: reset\n");
+ printf("\nPhase: reset\n");
cpu.rom.ptr = cpu.vreset;
- while(!(cpu.status & FLAG_HALT) && eval())
- ;
+ while(!(cpu.status & FLAG_HALT) && eval()) {
+ /* experimental */
+ if(cpu.ram.dat[0xfff1])
+ device1(&cpu.ram.dat[0xfff0], &cpu.ram.dat[0xfff1]);
+ }
/*eval frame */
- printf("Phase: frame\n");
+ printf("\nPhase: frame\n");
setflag(FLAG_HALT, 0);
cpu.rom.ptr = cpu.vframe;
while(!(cpu.status & FLAG_HALT) && eval())
diff --git a/uxnasm.c b/uxnasm.c
@@ -148,6 +148,16 @@ pushshort(Uint16 s, int lit)
pushbyte(s & 0xff, 0);
}
+void
+pushword(char *w)
+{
+ int i = slen(w);
+ pushbyte(0x02, 0);
+ pushbyte(slen(w), 0);
+ while(i > 0)
+ pushbyte(w[--i], 0);
+}
+
Label *
findlabel(char *s)
{
@@ -228,6 +238,8 @@ pass1(FILE *f)
addr += 0;
else if(w[0] == '.')
addr += 2;
+ else if(w[0] == '"')
+ addr += slen(w + 1);
else if(w[0] == ',')
addr += 4;
else if(ismarker(w))
@@ -255,6 +267,8 @@ pass2(FILE *f)
p.ptr = shex(w + 1);
else if(w[0] == ':')
fscanf(f, "%s", w);
+ else if(w[0] == '"')
+ pushword(w + 1);
else if((op = findop(w)) || scmp(w, "BRK"))
pushbyte(op, 0);
else if((l = findlabel(w + 1)))