From 716d04890662d0de34f6ffe0c9f06f98f11d581e Mon Sep 17 00:00:00 2001 From: neauoire Date: Mon, 19 Apr 2021 21:33:52 -0700 Subject: [PATCH] Working example for dev.control --- etc/usm.sublime-syntax | 34 +++--- projects/examples/dev.controller.buttons.usm | 115 ++++++------------- src/assembler.c | 34 +++--- 3 files changed, 73 insertions(+), 110 deletions(-) diff --git a/etc/usm.sublime-syntax b/etc/usm.sublime-syntax index 740cc04..b84e2ea 100644 --- a/etc/usm.sublime-syntax +++ b/etc/usm.sublime-syntax @@ -18,26 +18,19 @@ contexts: - match: '\|(\S+)\s?' scope: variable.control pop: true - # variables - - match: '\;(\S+)\s?' - scope: string.control + - match: '\$(\S+)\s?' + scope: variable.control pop: true # constants - match: '\:(\S+)\s?' scope: string.control pop: true # structs - - match: '\&(\S+)\s?' - scope: string.control - pop: true - - match: '\$(\S+)\s?' - scope: string.control - pop: true # Special - - match: '\~(\S+)\s?' - scope: entity.name.type + - match: '\&(\S+)\s?' + scope: string.control pop: true - match: '\=(\S+)\s?' scope: entity.name.type @@ -45,18 +38,25 @@ contexts: # Pushing to stack - - match: '\,(\S+)\s?' - scope: keyword.control - pop: true - - match: '\.(\S+)\s?' - scope: keyword.control - pop: true - match: '\^(\S+)\s?' scope: keyword.control pop: true - match: '\#(\S+)\s?' scope: keyword.control pop: true + + + # Addressing + - match: '\.(\S+)\s?' # zero-page + scope: variable.control + pop: true + - match: '\,(\S+)\s?' # relative + scope: entity.name.type + pop: true + - match: '\;(\S+)\s?' # absolute + scope: keyword.control + pop: true + # Blocks diff --git a/projects/examples/dev.controller.buttons.usm b/projects/examples/dev.controller.buttons.usm index 84e7ebd..4c3df01 100644 --- a/projects/examples/dev.controller.buttons.usm +++ b/projects/examples/dev.controller.buttons.usm @@ -1,119 +1,78 @@ ( Dev/Controller ) -%++ { #0001 ADD2 } -%-- { #0001 SUB2 } +%++ { #0001 ADD2 } %-- { #0001 SUB2 } %2/ { #0002 DIV2 } ( variables ) -@slime [ - &color 00 - &end -] +@slime $1 ( devices ) -|0100 @System [ - &vector 0000 - &pad 0000 - 0000 - 0000 - &r 0daf - &g 02ff - &b 035f - &end -] - -|0110 @Console [ - &pad 0000 - 0000 - 0000 - 0000 - &char 00 - &byte 00 - &short 0000 - &string 0000 - &end -] - -|0120 @Screen [ - &vector 0000 - &width 0000 - &height 0000 - &pad 0000 - &x 0000 - &y 0000 - &addr 0000 - &color 00 - &end -] - -|0140 @Controller [ - &vector 0000 - &button 00 - &key 00 - &end -] +|0100 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 +|0110 @Console &pad $8 &char $1 &byte $1 &short $2 &string $2 +|0120 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 +|0140 @Controller &vector $2 &button $1 &key $1 |0200 ( theme ) - #0daf ,System/r STR2 - #02ff ,System/g STR2 - #035f ,System/b STR2 + #0daf ;System/r STR2 + #02ff ;System/g STR2 + #035f ;System/b STR2 ( vectors ) - ,on-frame ,Screen/vector STR2 + ;on-frame ;Screen/vector STR2 ( set origin ) - ,Screen/width LDR2 2/ ,Screen/x STR2 - ,Screen/height LDR2 2/ ,Screen/y STR2 - ,default_icn ,Screen/addr STR2 - #31 ,Screen/color POK2 - #2a ,slime/color POK2 + ;Screen/width LDR2 2/ ;Screen/x STR2 + ;Screen/height LDR2 2/ ;Screen/y STR2 + ;default_icn ;Screen/addr STR2 + #31 ;Screen/color POK2 + #2a .slime POK BRK @on-frame - #2a ,slime/color POK2 - ,default_icn ,Screen/addr STR2 + #2a .slime POK + ;default_icn ;Screen/addr STR2 ( hold ctrl key to change slime color ) - ,Controller/button PEK2 #0f AND - DUP #01 NEQ ^&no-ctrl JNZ #25 ,slime/color POK2 &no-ctrl - DUP #02 NEQ ^&no-alt JNZ #2f ,slime/color POK2 &no-alt + ;Controller/button PEK2 #0f AND + DUP #01 NEQ ,&no-ctrl JNZ #25 .slime POK &no-ctrl + DUP #02 NEQ ,&no-alt JNZ #2f .slime POK &no-alt POP - ( clear ) #30 ,Screen/color POK2 + ( clear ) #30 ;Screen/color POK2 ( detect movement ) - ,Controller/button PEK2 #f0 AND - DUP #04 SFT #01 AND #01 NEQ ^&no-up JNZ + ;Controller/button PEK2 #f0 AND + DUP #04 SFT #01 AND #01 NEQ ,&no-up JNZ ( move ) - ,Screen/y LDR2 -- ,Screen/y STR2 - ,up_icn ,Screen/addr STR2 &no-up - DUP #05 SFT #01 AND #01 NEQ ^&no-down JNZ + ;Screen/y LDR2 -- ;Screen/y STR2 + ;up_icn ;Screen/addr STR2 &no-up + DUP #05 SFT #01 AND #01 NEQ ,&no-down JNZ ( move ) - ,Screen/y LDR2 ++ ,Screen/y STR2 - ,down_icn ,Screen/addr STR2 &no-down - DUP #06 SFT #01 AND #01 NEQ ^&no-left JNZ + ;Screen/y LDR2 ++ ;Screen/y STR2 + ;down_icn ;Screen/addr STR2 &no-down + DUP #06 SFT #01 AND #01 NEQ ,&no-left JNZ ( move ) - ,Screen/x LDR2 -- ,Screen/x STR2 - ,left_icn ,Screen/addr STR2 &no-left - DUP #07 SFT #01 AND #01 NEQ ^&no-right JNZ + ;Screen/x LDR2 -- ;Screen/x STR2 + ;left_icn ;Screen/addr STR2 &no-left + DUP #07 SFT #01 AND #01 NEQ ,&no-right JNZ ( move ) - ,Screen/x LDR2 ++ ,Screen/x STR2 - ,right_icn ,Screen/addr STR2 &no-right + ;Screen/x LDR2 ++ ;Screen/x STR2 + ;right_icn ;Screen/addr STR2 &no-right POP ( draw face ) - #31 ,Screen/color POK2 + #31 ;Screen/color POK2 ( draw slime ) - ,slime_icn ,Screen/addr STR2 - ,slime/color PEK2 ,Screen/color POK2 + ;slime_icn ;Screen/addr STR2 + .slime PEK ;Screen/color POK2 BRK diff --git a/src/assembler.c b/src/assembler.c index 1004c61..8bc0657 100644 --- a/src/assembler.c +++ b/src/assembler.c @@ -210,9 +210,9 @@ walktoken(char *w) if(findopcode(w) || scmp(w, "BRK", 4)) return 1; switch(w[0]) { - case ',': return 3; /* lit2 addr-hb addr-lb */ - case '.': return 2; /* addr-hb addr-lb */ - case '^': return 2; /* Relative jump: lit addr-offset */ + case '.': return 2; /* zero-page: LIT addr-lb */ + case ';': return 3; /* absolute: LIT addr-hb addr-lb */ + case ',': return 2; /* Relative jump: lit addr-offset */ case '#': return (slen(w + 1) == 4 ? 3 : 2); } if((m = findmacro(w))) { @@ -231,18 +231,16 @@ parsetoken(char *w) Label *l; Macro *m; - if(w[0] == '^' && (l = findlabel(w + 1))) { - int off = l->addr - p.ptr - 3; - if(off < -126 || off > 126) { - printf("Address %s is too far(%d).\n", w, off); - return 0; - } - pushbyte((Sint8)(l->addr - p.ptr - 3), 1); - return ++l->refs; - } else if(w[0] == '.' && (l = findlabel(w + 1))) { - pushshort(l->addr, 0); + if(w[0] == '.' && (l = findlabel(w + 1))) { /* zero-page */ + pushbyte(l->addr, 1); return ++l->refs; } else if(w[0] == ',' && (l = findlabel(w + 1))) { + int off = l->addr - p.ptr - 3; + if(off < -126 || off > 126) + return error("Address is too far", w); + pushbyte((Sint8)off, 1); + return ++l->refs; + } else if(w[0] == ';' && (l = findlabel(w + 1))) { /* absolute */ pushshort(l->addr, 1); return ++l->refs; } else if((op = findopcode(w)) || scmp(w, "BRK", 4)) { @@ -302,7 +300,9 @@ pass1(FILE *f) if(shex(w + 1) < addr) return error("Memory Overwrite", w); addr = shex(w + 1); - } else + } else if(w[0] == '$') + addr += shex(w + 1); + else addr += walktoken(w); } rewind(f); @@ -324,7 +324,11 @@ pass2(FILE *f) p.ptr = shex(w + 1); continue; } - if(w[0] == '@') { + else if(w[0] == '$') { + p.ptr += shex(w + 1); + continue; + } + else if(w[0] == '@') { scpy(w + 1, scope, 64); continue; }