Ported the hello-world example

This commit is contained in:
neauoire 2021-04-20 11:32:26 -07:00
parent 68a253e67e
commit a293c1daa8
4 changed files with 25 additions and 30 deletions

View File

@ -22,35 +22,34 @@ To build the Uxn emulator, you must have [SDL2](https://wiki.libsdl.org/).
Read more in the [Uxambly Guide](https://wiki.xxiivv.com/site/uxambly.html).
```
( Dev/Console )
%RTN { JMP2r }
( devices )
|0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 }
|0110 @Console [ &pad $8 &char $1 ]
( program )
|0200
,text1 ,print-label JSR2
,text2 ,print-label JSR2
#ab =Console.byte
#cdef =Console.short
;hello-word ;print JSR2
BRK
@print-label ( text )
@print ( addr -- )
$loop
( send ) DUP2 PEK2 =Console.char
&loop
( send ) DUP2 PEK2 .Console/char IOW
( incr ) #0001 ADD2
( loop ) DUP2 PEK2 #00 NEQ ^$loop JNZ
( loop ) DUP2 PEK2 #00 NEQ ,&loop JNZ
POP2
RTN
RTN
@hello-word [ 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 ]
@text1 [ Welcome 20 to 20 UxnVM 0a00 ]
@text2 [ Hello 20 World 0a00 ]
```
## TODOs

View File

@ -32,7 +32,7 @@ else
fi
echo "Assembling.."
./bin/assembler projects/examples/dev.controller.buttons.usm bin/boot.rom
./bin/assembler projects/examples/dev.console.usm bin/boot.rom
echo "Running.."
if [ "${2}" = '--cli' ];

View File

@ -4,28 +4,24 @@
( devices )
|0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 string 2 }
|0110 @Console [ &pad $8 &char $1 ]
( program )
|0200
,text1 ,print-label JSR2
,text2 ,print-label JSR2
#ab =Console.byte
#cdef =Console.short
;hello-word ;print JSR2
BRK
@print-label ( text )
@print ( addr -- )
$loop
( send ) DUP2 PEK2 =Console.char
&loop
( send ) DUP2 PEK2 .Console/char IOW
( incr ) #0001 ADD2
( loop ) DUP2 PEK2 #00 NEQ ^$loop JNZ
( loop ) DUP2 PEK2 #00 NEQ ,&loop JNZ
POP2
RTN
RTN
@text1 [ Welcome 20 to 20 UxnVM 0a00 ]
@text2 [ Hello 20 World 0a00 ]
@hello-word [ 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 ]

View File

@ -49,8 +49,8 @@ char ops[][4] = {
int scin(char *s, char c) { int i = 0; while(s[i]) if(s[i++] == c) return i - 1; return -1; } /* string char index */
int scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i] && i < len) if(!a[i++]) return 1; return 0; } /* string compare */
int slen(char *s) { int i = 0; while(s[i] && s[++i]) ; return i; } /* string length */
int sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) return 0; return 1; } /* string is hexadecimal */
int shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'A' && c <= 'F') n = n * 16 + 10 + (c - 'A'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */
int sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return 1; } /* string is hexadecimal */
int shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */
char *scpy(char *src, char *dst, int len) { int i = 0; while((dst[i] = src[i]) && i < len - 2) i++; dst[i + 1] = '\0'; return dst; } /* string copy */
#pragma mark - Helpers
@ -338,7 +338,7 @@ void
cleanup(char *filename)
{
int i;
printf("Assembled %s(%0.2fkb), %d labels, %d macros.\n\n", filename, (p.ptr - TRIM) / 1000.0, p.llen, p.mlen);
printf("Assembled %s(%d bytes), %d labels, %d macros.\n\n", filename, (p.ptr - TRIM), p.llen, p.mlen);
for(i = 0; i < p.llen; ++i)
if(!p.labels[i].refs)
printf("--- Unused label: %s\n", p.labels[i].name);