From 1e0d5bbf50ab4ab3f8f323c1139fec0e5ed06057 Mon Sep 17 00:00:00 2001 From: neauoire Date: Fri, 5 Feb 2021 11:57:37 -0800 Subject: [PATCH] Added experimental dev1 --- README.md | 1 + etc/usm.sublime-syntax | 5 ++++- examples/blank.usm | 15 +++++++++------ examples/core.usm | 35 +++++++++++++---------------------- uxn.c | 21 ++++++++++++++++----- uxnasm.c | 14 ++++++++++++++ 6 files changed, 57 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 3f1daaf..efe73fb 100644 --- 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 index 1964e47..6f484a9 100644 --- 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 index e465d85..19da348 100644 --- a/examples/blank.usm +++ b/examples/blank.usm @@ -1,24 +1,27 @@ ( blank project ) ;variable1 -;variable2 -_constant1 abcd +:constant1 9abc |0100 ( -------------------------------- ) -:RESET BRK +@RESET + +,abcd + +BRK ( RESET-END ) |c000 ( -------------------------------- ) -:FRAME ( FRAME-START ) - +@FRAME ( FRAME-START ) +,abcd BRK ( FRAME-END ) |d000 ( -------------------------------- ) -:ERROR BRK +@ERROR BRK |FFFA ( -------------------------------- ) diff --git a/examples/core.usm b/examples/core.usm index 19da348..0f829a5 100644 --- 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 index 2754d04..c1b8831 100644 --- 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]; } @@ -158,6 +158,14 @@ error(char *name) return 0; } +int +device1(Uint8 *read, Uint8 *write) +{ + printf("%c", *write); + *write = 0; + return 0; +} + int eval(void) { @@ -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 index 506b11e..2b0f5a4 100644 --- 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)))