0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-10 16:25:05 +00:00

Removed addr ptr moves to assmbler

This commit is contained in:
neauoire 2021-03-01 09:38:54 -08:00
parent e162b4f083
commit 0a4ae60762
6 changed files with 31 additions and 24 deletions

View file

@ -37,8 +37,6 @@ evaluxn(u, u->vframe); /* Each frame
- `=label`, helper to STR, equivalent to `,label STR`, or `label STR2`.
- `~label`, helper to LDR, equivalent to `,label LDR2`, or `,label LDR2`.
- `|0010`, move to position in the program.
- `<23`, move the program position `23` bytes backward.
- `>12`, move the program position `12` bytes forward.
- `( comment )`, toggle parsing on/off.
- `[ 0123 abcd ]`, write shorts to memory.
- `[ Hello World ]`, write text to memory.
@ -53,33 +51,35 @@ evaluxn(u, u->vframe); /* Each frame
```
( hello world )
&Console { pad 8 stdio 1 }
&Console { pad 8 char 1 byte 1 }
|0100 @RESET
,text1 ,print-label JSR ( print to console )
,text1 ,print-label JSR
,text2 ,print-label JSR
BRK
@print-label ( text )
@cliloop
DUP2 LDR =dev/console.stdio ( write pointer value to console )
DUP2 LDR =dev/console.char ( write pointer value to console )
#0001 ADD2 ( increment string pointer )
DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2 ( while *ptr!=0 goto loop )
POP2
RTS
@text1 [ Hello World ] <1 .00 ( add text to memory, return 1 byte, add null byte )
@text1 [ Hello World 0a00 ] ( store text with a linebreak and null byte )
@text2 [ Welcome to UxnVM 0a00 ]
|c000 @FRAME
|d000 @ERROR
|FF00 ;dev/console Console
|FFF0 .RESET .FRAME .ERROR
|FFF8 [ f3f0 f30b f30a ] ( palette )
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
```
## Emulator

View file

@ -280,7 +280,10 @@ pass1(FILE *f)
if(skipblock(w, &cbits, '[', ']')) {
if(w[0] == '[' || w[0] == ']')
continue;
addr += sihx(w) ? 2 : slen(w) + 1;
if(sihx(w))
addr += slen(w) == 4 ? 2 : 1;
else
addr += slen(w) + 1;
} else if(w[0] == '@') {
if(!makelabel(w + 1, addr, 0, NULL))
return error("Pass1 failed", w);
@ -302,8 +305,6 @@ pass1(FILE *f)
return error("Memory Overlap", w);
addr = shex(w + 1);
break;
case '<': addr -= shex(w + 1); break;
case '>': addr += shex(w + 1); break;
case '=': addr += 4; break; /* STR helper (lit addr-hb addr-lb str) */
case '~': addr += 4; break; /* LDR helper (lit addr-hb addr-lb ldr) */
case ',': addr += 3; break;
@ -335,11 +336,11 @@ pass2(FILE *f)
/* clang-format off */
if(skipblock(w, &cbits, '[', ']')) {
if(w[0] == '[' || w[0] == ']') { continue; }
if(slen(w) == 4 && sihx(w)) pushshort(shex(w), 0); else pushtext(w, 0);
if(slen(w) == 4 && sihx(w)) pushshort(shex(w), 0);
else if(slen(w) == 2 && sihx(w)) pushbyte(shex(w), 0);
else pushtext(w, 0);
}
else if(w[0] == '|') p.ptr = shex(w + 1);
else if(w[0] == '<') p.ptr -= shex(w + 1);
else if(w[0] == '>') p.ptr += shex(w + 1);
else if((op = findopcode(w)) || scmp(w, "BRK", 4)) pushbyte(op, 0);
else if(w[0] == ':') fscanf(f, "%s", w);
else if(w[0] == ';') fscanf(f, "%s", w);

View file

@ -332,7 +332,7 @@ console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
switch(b0) {
case 0x08: printf("%c", b1); break;
case 0x09: printf("%02x", b1); break;
case 0x0a: printf("%d", b1); break;
case 0x0b: printf("%04x", (m[ptr + 0x0a] << 8) + b1); break;
}
fflush(stdout);
(void)m;
@ -377,6 +377,8 @@ Uint8
system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
{
loadtheme(&m[0xfff8]);
(void)ptr;
(void)b0;
return b1;
}

View file

@ -1,10 +1,13 @@
( hello world )
&Console { pad 8 char 1 byte 1 }
&Console { pad 8 char 1 byte 1 short 2 }
|0100 @RESET
,text1 ,print-label JSR ( print to console )
,text1 ,print-label JSR
,text2 ,print-label JSR
#ab =dev/console.byte
#cdef =dev/console.short
BRK
@ -18,7 +21,8 @@ BRK
RTS
@text1 [ Hello World ] <1 .00 ( add text to memory, return 1 byte, add null byte )
@text1 [ Hello World 0a00 ] ( store text with a linebreak and null byte )
@text2 [ Welcome to UxnVM 0a00 ]
|c000 @FRAME
|d000 @ERROR

View file

@ -213,10 +213,10 @@ RTS
0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
]
@mouse0_text [ no click ] <1 .00
@mouse1_text [ mouse 1_ ] <1 .00
@mouse2_text [ mouse _2 ] <1 .00
@mouse12_text [ mouse 12 ] <1 .00
@mouse0_text [ no click 00 ]
@mouse1_text [ mouse 1_ 00 ]
@mouse2_text [ mouse _2 00 ]
@mouse12_text [ mouse 12 00 ]
|d000 @ERROR BRK

View file

@ -140,7 +140,7 @@ RTS
0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
]
@text [ Label Text ] <1 .00 ( add characters to memory )
@text [ Label Text 00 ] ( add characters to memory )
|c000 @FRAME BRK
|d000 @ERROR BRK