Working example for dev.control

This commit is contained in:
neauoire 2021-04-19 21:33:52 -07:00
parent 50b11f12ca
commit 716d048906
3 changed files with 73 additions and 110 deletions

View File

@ -18,26 +18,19 @@ contexts:
- match: '\|(\S+)\s?' - match: '\|(\S+)\s?'
scope: variable.control scope: variable.control
pop: true pop: true
# variables - match: '\$(\S+)\s?'
- match: '\;(\S+)\s?' scope: variable.control
scope: string.control
pop: true pop: true
# constants # constants
- match: '\:(\S+)\s?' - match: '\:(\S+)\s?'
scope: string.control scope: string.control
pop: true pop: true
# structs # structs
- match: '\&(\S+)\s?'
scope: string.control
pop: true
- match: '\$(\S+)\s?'
scope: string.control
pop: true
# Special # Special
- match: '\~(\S+)\s?' - match: '\&(\S+)\s?'
scope: entity.name.type scope: string.control
pop: true pop: true
- match: '\=(\S+)\s?' - match: '\=(\S+)\s?'
scope: entity.name.type scope: entity.name.type
@ -45,18 +38,25 @@ contexts:
# Pushing to stack # Pushing to stack
- match: '\,(\S+)\s?'
scope: keyword.control
pop: true
- match: '\.(\S+)\s?'
scope: keyword.control
pop: true
- match: '\^(\S+)\s?' - match: '\^(\S+)\s?'
scope: keyword.control scope: keyword.control
pop: true pop: true
- match: '\#(\S+)\s?' - match: '\#(\S+)\s?'
scope: keyword.control scope: keyword.control
pop: true 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 # Blocks

View File

@ -1,119 +1,78 @@
( Dev/Controller ) ( Dev/Controller )
%++ { #0001 ADD2 } %++ { #0001 ADD2 } %-- { #0001 SUB2 }
%-- { #0001 SUB2 }
%2/ { #0002 DIV2 } %2/ { #0002 DIV2 }
( variables ) ( variables )
@slime [ @slime $1
&color 00
&end
]
( devices ) ( devices )
|0100 @System [ |0100 @System &vector $2 &pad $6 &r $2 &g $2 &b $2
&vector 0000 |0110 @Console &pad $8 &char $1 &byte $1 &short $2 &string $2
&pad 0000 |0120 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1
0000 |0140 @Controller &vector $2 &button $1 &key $1
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
]
|0200 |0200
( theme ) ( theme )
#0daf ,System/r STR2 #0daf ;System/r STR2
#02ff ,System/g STR2 #02ff ;System/g STR2
#035f ,System/b STR2 #035f ;System/b STR2
( vectors ) ( vectors )
,on-frame ,Screen/vector STR2 ;on-frame ;Screen/vector STR2
( set origin ) ( set origin )
,Screen/width LDR2 2/ ,Screen/x STR2 ;Screen/width LDR2 2/ ;Screen/x STR2
,Screen/height LDR2 2/ ,Screen/y STR2 ;Screen/height LDR2 2/ ;Screen/y STR2
,default_icn ,Screen/addr STR2 ;default_icn ;Screen/addr STR2
#31 ,Screen/color POK2 #31 ;Screen/color POK2
#2a ,slime/color POK2 #2a .slime POK
BRK BRK
@on-frame @on-frame
#2a ,slime/color POK2 #2a .slime POK
,default_icn ,Screen/addr STR2 ;default_icn ;Screen/addr STR2
( hold ctrl key to change slime color ) ( hold ctrl key to change slime color )
,Controller/button PEK2 #0f AND ;Controller/button PEK2 #0f AND
DUP #01 NEQ ^&no-ctrl JNZ #25 ,slime/color POK2 &no-ctrl DUP #01 NEQ ,&no-ctrl JNZ #25 .slime POK &no-ctrl
DUP #02 NEQ ^&no-alt JNZ #2f ,slime/color POK2 &no-alt DUP #02 NEQ ,&no-alt JNZ #2f .slime POK &no-alt
POP POP
( clear ) #30 ,Screen/color POK2 ( clear ) #30 ;Screen/color POK2
( detect movement ) ( detect movement )
,Controller/button PEK2 #f0 AND ;Controller/button PEK2 #f0 AND
DUP #04 SFT #01 AND #01 NEQ ^&no-up JNZ DUP #04 SFT #01 AND #01 NEQ ,&no-up JNZ
( move ) ( move )
,Screen/y LDR2 -- ,Screen/y STR2 ;Screen/y LDR2 -- ;Screen/y STR2
,up_icn ,Screen/addr STR2 &no-up ;up_icn ;Screen/addr STR2 &no-up
DUP #05 SFT #01 AND #01 NEQ ^&no-down JNZ DUP #05 SFT #01 AND #01 NEQ ,&no-down JNZ
( move ) ( move )
,Screen/y LDR2 ++ ,Screen/y STR2 ;Screen/y LDR2 ++ ;Screen/y STR2
,down_icn ,Screen/addr STR2 &no-down ;down_icn ;Screen/addr STR2 &no-down
DUP #06 SFT #01 AND #01 NEQ ^&no-left JNZ DUP #06 SFT #01 AND #01 NEQ ,&no-left JNZ
( move ) ( move )
,Screen/x LDR2 -- ,Screen/x STR2 ;Screen/x LDR2 -- ;Screen/x STR2
,left_icn ,Screen/addr STR2 &no-left ;left_icn ;Screen/addr STR2 &no-left
DUP #07 SFT #01 AND #01 NEQ ^&no-right JNZ DUP #07 SFT #01 AND #01 NEQ ,&no-right JNZ
( move ) ( move )
,Screen/x LDR2 ++ ,Screen/x STR2 ;Screen/x LDR2 ++ ;Screen/x STR2
,right_icn ,Screen/addr STR2 &no-right ;right_icn ;Screen/addr STR2 &no-right
POP POP
( draw face ) ( draw face )
#31 ,Screen/color POK2 #31 ;Screen/color POK2
( draw slime ) ( draw slime )
,slime_icn ,Screen/addr STR2 ;slime_icn ;Screen/addr STR2
,slime/color PEK2 ,Screen/color POK2 .slime PEK ;Screen/color POK2
BRK BRK

View File

@ -210,9 +210,9 @@ walktoken(char *w)
if(findopcode(w) || scmp(w, "BRK", 4)) if(findopcode(w) || scmp(w, "BRK", 4))
return 1; return 1;
switch(w[0]) { switch(w[0]) {
case ',': return 3; /* lit2 addr-hb addr-lb */ case '.': return 2; /* zero-page: LIT addr-lb */
case '.': return 2; /* addr-hb addr-lb */ case ';': return 3; /* absolute: LIT addr-hb addr-lb */
case '^': return 2; /* Relative jump: lit addr-offset */ case ',': return 2; /* Relative jump: lit addr-offset */
case '#': return (slen(w + 1) == 4 ? 3 : 2); case '#': return (slen(w + 1) == 4 ? 3 : 2);
} }
if((m = findmacro(w))) { if((m = findmacro(w))) {
@ -231,18 +231,16 @@ parsetoken(char *w)
Label *l; Label *l;
Macro *m; Macro *m;
if(w[0] == '^' && (l = findlabel(w + 1))) { if(w[0] == '.' && (l = findlabel(w + 1))) { /* zero-page */
int off = l->addr - p.ptr - 3; pushbyte(l->addr, 1);
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);
return ++l->refs; return ++l->refs;
} else if(w[0] == ',' && (l = findlabel(w + 1))) { } 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); pushshort(l->addr, 1);
return ++l->refs; return ++l->refs;
} else if((op = findopcode(w)) || scmp(w, "BRK", 4)) { } else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {
@ -302,7 +300,9 @@ pass1(FILE *f)
if(shex(w + 1) < addr) if(shex(w + 1) < addr)
return error("Memory Overwrite", w); return error("Memory Overwrite", w);
addr = shex(w + 1); addr = shex(w + 1);
} else } else if(w[0] == '$')
addr += shex(w + 1);
else
addr += walktoken(w); addr += walktoken(w);
} }
rewind(f); rewind(f);
@ -324,7 +324,11 @@ pass2(FILE *f)
p.ptr = shex(w + 1); p.ptr = shex(w + 1);
continue; continue;
} }
if(w[0] == '@') { else if(w[0] == '$') {
p.ptr += shex(w + 1);
continue;
}
else if(w[0] == '@') {
scpy(w + 1, scope, 64); scpy(w + 1, scope, 64);
continue; continue;
} }