commit 2b1d44e862939e77deaba954f92c70817ea3cd9a
parent 1e0d5bbf50ab4ab3f8f323c1139fec0e5ed06057
Author: neauoire <aliceffekt@gmail.com>
Date: Fri, 5 Feb 2021 14:01:34 -0800
First hello world
Diffstat:
4 files changed, 40 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md
@@ -28,22 +28,30 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
- `"hello`, push literal bytes for word "hello"
```
-;value ( alloc a zero-page variable )
+( hello world )
-@0010 ( start at page 1 )
+;iterator
+:dev1r FFF0
+:dev1w FFF1
-,03 ,02 ADD ,05 EQU
-,there ROT JMC
+|0100 @RESET
-:here
- ( when not equal )
- ,ee
- BRK
+"hello
+
+@loop
+ ,dev1w STR
+ ,iterator LDR
+ ,01 ADD
+ ,iterator STR
+ ,iterator LDR
+ ,05 NEQ ,loop ROT JSC
+
+BRK ( RESET )
+
+|c000 @FRAME BRK
+|d000 @ERROR BRK
+|FFFA .RESET .FRAME .ERROR
-:there
- ( when is equal )
- ,ff
- BRK
```
## Mission
diff --git a/examples/core.usm b/examples/core.usm
@@ -1,18 +1,20 @@
-( blank project )
+( hello world )
-;variable1
+;iterator
:dev1r FFF0
:dev1w FFF1
|0100 @RESET
-"hello
+"hello
-,dev1w STR
-,dev1w STR
-,dev1w STR
-,dev1w STR
-,dev1w STR
+@loop
+ ,dev1w STR
+ ,iterator LDR
+ ,01 ADD
+ ,iterator STR
+ ,iterator LDR
+ ,05 NEQ ,loop ROT JSC
BRK ( RESET )
diff --git a/uxn.c b/uxn.c
@@ -85,15 +85,21 @@ echom(Memory *m, Uint8 len, char *name)
/* clang-format off */
+Uint16 bytes2short(Uint8 a, Uint8 b) { return (a << 8) + b; }
Uint8 rampeek8(Uint16 s) { return cpu.ram.dat[s] & 0xff; }
+Uint8 mempeek8(Uint16 s) { return cpu.rom.dat[s]; }
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]; }
Uint16 wspop16(void) { return wspop8() + (wspop8() << 8); }
Uint8 wspeek8(void) { return cpu.wst.dat[cpu.wst.ptr - 1]; }
+Uint16 rspop16(void) { return cpu.rst.dat[--cpu.rst.ptr] + (cpu.rst.dat[--cpu.rst.ptr] << 8); }
void op_brk() { setflag(FLAG_HALT, 1); }
-void op_rts() { cpu.rom.ptr = cpu.rst.dat[--cpu.rst.ptr]; }
+void op_rts() {
+ cpu.rom.ptr = rspop16();
+ printf("RTS: %04x\n", cpu.rom.ptr);
+}
void op_lit() { cpu.literal += cpu.rom.dat[cpu.rom.ptr++]; }
void op_drp() { wspop8(); }
void op_dup() { wspush8(wspeek8()); }
@@ -101,7 +107,7 @@ void op_swp() { Uint8 b = wspop8(), a = wspop8(); wspush8(b); wspush8(a); }
void op_ovr() { wspush8(cpu.wst.dat[cpu.wst.ptr - 2]); }
void op_rot() { Uint8 c = wspop8(),b = wspop8(),a = wspop8(); wspush8(b); wspush8(c); wspush8(a); }
void op_jmu() { cpu.rom.ptr = wspop8(); }
-void op_jsu() { cpu.rst.dat[cpu.rst.ptr++] = cpu.rom.ptr; cpu.rom.ptr = wspop8(); }
+void op_jsu() { cpu.rst.dat[cpu.rst.ptr++] = (cpu.rom.ptr >> 8) & 0xff; cpu.rst.dat[cpu.rst.ptr++] = cpu.rom.ptr; cpu.rom.ptr = wspop16(); }
void op_jmc() { if(wspop8()) op_jmu(); }
void op_jsc() { if(wspop8()) op_jsu(); }
void op_equ() { wspush8(wspop8() == wspop8()); }
@@ -163,6 +169,7 @@ device1(Uint8 *read, Uint8 *write)
{
printf("%c", *write);
*write = 0;
+ (void)read;
return 0;
}
diff --git a/uxnasm.c b/uxnasm.c
@@ -239,7 +239,7 @@ pass1(FILE *f)
else if(w[0] == '.')
addr += 2;
else if(w[0] == '"')
- addr += slen(w + 1);
+ addr += slen(w + 1) + 2;
else if(w[0] == ',')
addr += 4;
else if(ismarker(w))