commit fed31a8a16a7d6eb5d46fc49fee385f3854e572a
parent c13de491114767263e5e014a508bbdc4c87817b8
Author: neauoire <aliceffekt@gmail.com>
Date: Sun, 7 Feb 2021 12:13:38 -0800
Added zero-page shorthand
Diffstat:
7 files changed, 61 insertions(+), 50 deletions(-)
diff --git a/README.md b/README.md
@@ -26,6 +26,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"
+- `#04`, a zero-page address, equivalent to `,0004`
### Operator modes
@@ -65,23 +66,20 @@ BRK ( RESET )
### Assembler
-- Complete implementing short mode
+- Create a benchmark file
- Implement shorthand operators
-- Catch overflow/underflow
-- Jumps should be relative
-- Load program in RAM
- Signed operations
+- zero-page address?
### CPU
-- Pointers/Literals
+- Signed operations
+- Catch overflow/underflow
- A Three-Way Decision Routine(http://www.6502.org/tutorials/compare_instructions.html)
-- Print word to stdout
- Draw pixel to screen
- Detect mouse click
- SDL Layer Emulator
- Build PPU
-- Add flags..
### Devices
diff --git a/build.sh b/build.sh
@@ -14,5 +14,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c -o uxn
# run
-./uxnasm examples/core.usm boot.rom
+./uxnasm examples/benchmark.usm boot.rom
./uxn boot.rom
diff --git a/examples/benchmark.usm b/examples/benchmark.usm
@@ -0,0 +1,31 @@
+( benchmark )
+
+;iterator
+:dev1r FFF0
+:dev1w FFF1
+
+|0100 @RESET
+
+( arithmetic )
+,12 ,34 ADD ,46 EQU #00 STR
+,12 ,06 SUB ,0c EQU #01 STR
+,12 ,06 MUL ,6c EQU #02 STR
+,12 ,06 DIV ,03 EQU #03 STR
+,12 ,12 EQU #04 STR
+,12 ,13 NEQ #05 STR
+,12 ,11 GTH #06 STR
+,12 ,13 LTH #07 STR
+
+( arithmetic 16-bit )
+,1234 ,2345 ADD^ ,3579 EQU^ #08 STR
+,1234 ,0123 SUB^ ,1111 EQU^ #09 STR
+,1234 ,0102 MUL^ ,5868 EQU^ #0a STR
+,5678 ,0100 DIV^ ,0056 EQU^ #0b STR
+,1234 ,1234 EQU^ #0c STR
+,1234 ,0123 NEQ^ #0d STR
+,1234 ,1233 GTH^ #0e STR
+,1234 ,1235 LTH^ #0f STR
+
+|c000 @FRAME BRK
+|d000 @ERROR BRK
+|FFFA .RESET .FRAME .ERROR
diff --git a/examples/core.usm b/examples/core.usm
@@ -6,27 +6,6 @@
|0100 @RESET
-@word1 "hello_word ( len: 0x0b )
-
-@loop
- ,dev1w STR ( write to stdout )
- ,incr JSU ( increment itr )
- ,word1 ,strlen JSU ( get strlen )
- NEQ ,loop ROT JSC ( loop != strlen )
-
-BRK
-
-@strlen
- ,0001 ADD^ LDR
- RTU
-
-@incr
- ,iterator LDR
- ,01 ADD
- ,iterator STR
- ,iterator LDR
- RTU
-
|c000 @FRAME BRK
|d000 @ERROR BRK
|FFFA .RESET .FRAME .ERROR
diff --git a/examples/hello.usm b/examples/hello.usm
@@ -17,7 +17,7 @@
BRK
@strlen
- ,0001 ADD^ PEK
+ ,0001 ADD^ LDR
RTU
@incr
diff --git a/uxn.c b/uxn.c
@@ -65,7 +65,7 @@ void
echos(Stack8 *s, Uint8 len, char *name)
{
int i;
- printf("%s\n", name);
+ printf("\n%s\n", name);
for(i = 0; i < len; ++i) {
if(i % 16 == 0)
printf("\n");
@@ -78,7 +78,7 @@ void
echom(Memory *m, Uint8 len, char *name)
{
int i;
- printf("%s\n", name);
+ printf("\n%s\n", name);
for(i = 0; i < len; ++i) {
if(i % 16 == 0)
printf("\n");
@@ -127,14 +127,14 @@ void op_and() { Uint8 a = wspop8(), b = wspop8(); wspush8(a & b); }
void op_ora() { Uint8 a = wspop8(), b = wspop8(); wspush8(a | b); }
void op_rol() { Uint8 a = wspop8(), b = wspop8(); wspush8(a << b); }
/* Arithmetic */
-void op_add() { Uint8 a = wspop8(), b = wspop8(); wspush8(a + b); }
-void op_sub() { Uint8 a = wspop8(), b = wspop8(); wspush8(a - b); }
-void op_mul() { Uint8 a = wspop8(), b = wspop8(); wspush8(a * b); }
-void op_div() { Uint8 a = wspop8(), b = wspop8(); wspush8(a / b); }
-void op_equ() { Uint8 a = wspop8(), b = wspop8(); wspush8(a == b); }
-void op_neq() { Uint8 a = wspop8(), b = wspop8(); wspush8(a != b); }
-void op_gth() { Uint8 a = wspop8(), b = wspop8(); wspush8(a < b); }
-void op_lth() { Uint8 a = wspop8(), b = wspop8(); wspush8(a > b); }
+void op_add() { Uint8 a = wspop8(), b = wspop8(); wspush8(b + a); }
+void op_sub() { Uint8 a = wspop8(), b = wspop8(); wspush8(b - a); }
+void op_mul() { Uint8 a = wspop8(), b = wspop8(); wspush8(b * a); }
+void op_div() { Uint8 a = wspop8(), b = wspop8(); wspush8(b / a); }
+void op_equ() { Uint8 a = wspop8(), b = wspop8(); wspush8(b == a); }
+void op_neq() { Uint8 a = wspop8(), b = wspop8(); wspush8(b != a); }
+void op_gth() { Uint8 a = wspop8(), b = wspop8(); wspush8(b > a); }
+void op_lth() { Uint8 a = wspop8(), b = wspop8(); wspush8(b < a); }
/* Stack(16-bits) */
void op_pop16() { wspop16(); }
void op_dup16() { wspush16(wspeek16(2)); }
@@ -145,14 +145,14 @@ void op_and16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a & b); }
void op_ora16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a | b); }
void op_rol16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a << b); }
/* Arithmetic(16-bits) */
-void op_add16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a + b); }
-void op_sub16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a - b); }
-void op_mul16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a * b); }
-void op_div16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a / b); }
-void op_equ16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a == b); }
-void op_neq16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a != b); }
-void op_gth16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a < b); }
-void op_lth16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a > b); }
+void op_add16() { Uint16 a = wspop16(), b = wspop16(); wspush16(b + a); }
+void op_sub16() { Uint16 a = wspop16(), b = wspop16(); wspush16(b - a); }
+void op_mul16() { Uint16 a = wspop16(), b = wspop16(); wspush16(b * a); }
+void op_div16() { Uint16 a = wspop16(), b = wspop16(); wspush16(b / a); }
+void op_equ16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b == a); }
+void op_neq16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b != a); }
+void op_gth16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b > a); }
+void op_lth16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b < a); }
void (*ops[])() = {
op_brk, op_lit, op_nop, op_nop, op_nop, op_nop, op_ldr, op_str,
@@ -163,7 +163,7 @@ void (*ops[])() = {
op_add16, op_sub16, op_mul16, op_div16, op_equ16, op_neq16, op_gth16, op_lth16
};
-Uint8 opr[][2] = { /* todo: 16 bits mode */
+Uint8 opr[][2] = {
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
diff --git a/uxnasm.c b/uxnasm.c
@@ -168,6 +168,7 @@ pass1(FILE *f)
case '@':
case ';': break;
case '.': addr += 2; break;
+ case '#': addr += 4; break;
case '"': addr += slen(w + 1) + 2; break;
case ',': addr += 2 + (sihx(w + 1) && slen(w + 1) == 2 ? 1 : 2); break;
default: return error("Unknown label", w);
@@ -195,7 +196,9 @@ pass2(FILE *f)
fscanf(f, "%s", w);
else if(w[0] == '"')
pushtext(w + 1);
- else if((l = findlabel(w + 1)))
+ else if(w[0] == '#') {
+ pushshort(shex(w + 1) & 0xff, 1);
+ } else if((l = findlabel(w + 1)))
pushshort(l->addr, w[0] == ',');
else if((op = findoperator(w)) || scmp(w, "BRK"))
pushbyte(op, 0);