Removing rawchr run

This commit is contained in:
Devine Lu Linvega 2022-08-14 12:06:23 -07:00
parent ef30fb8f8e
commit f348d24606
11 changed files with 50 additions and 75 deletions

View File

@ -13,13 +13,13 @@
;memory
;program
&while
LDAk LIT '> NEQ ,&movr JCN [ SWP2 INC2 SWP2 ] &movr
LDAk LIT '< NEQ ,&movl JCN [ SWP2 #0001 SUB2 SWP2 ] &movl
LDAk LIT '+ NEQ ,&incr JCN [ OVR2 STH2k LDA INC STH2r STA ] &incr
LDAk LIT '- NEQ ,&decr JCN [ OVR2 STH2k LDA #01 SUB STH2r STA ] &decr
LDAk LIT '. NEQ ,&emit JCN [ OVR2 LDA #18 DEO ] &emit
LDAk LIT '[ NEQ ,&next JCN [ ,goto-next JSR ] &next
LDAk LIT '] NEQ ,&prev JCN [ ,goto-back JSR ] &prev
LDAk LIT "> NEQ ,&movr JCN [ SWP2 INC2 SWP2 ] &movr
LDAk LIT "< NEQ ,&movl JCN [ SWP2 #0001 SUB2 SWP2 ] &movl
LDAk LIT "+ NEQ ,&incr JCN [ OVR2 STH2k LDA INC STH2r STA ] &incr
LDAk LIT "- NEQ ,&decr JCN [ OVR2 STH2k LDA #01 SUB STH2r STA ] &decr
LDAk LIT ". NEQ ,&emit JCN [ OVR2 LDA #18 DEO ] &emit
LDAk LIT "[ NEQ ,&next JCN [ ,goto-next JSR ] &next
LDAk LIT "] NEQ ,&prev JCN [ ,goto-back JSR ] &prev
INC2 LDAk ,&while JCN
POP2
( halt ) #010f DEO
@ -32,8 +32,8 @@ BRK
( depth ) LITr 00
INC2
&loop
LDAk LIT '[ NEQ JMP INCr
LDAk LIT '] NEQ ,&no-end JCN
LDAk LIT "[ NEQ JMP INCr
LDAk LIT "] NEQ ,&no-end JCN
STHkr #00 EQU ,&end JCN
LITr 01 SUBr
&no-end
@ -49,8 +49,8 @@ JMP2r
( depth ) LITr 00
#0001 SUB2
&loop
LDAk LIT '] NEQ JMP INCr
LDAk LIT '[ NEQ ,&no-end JCN
LDAk LIT "] NEQ JMP INCr
LDAk LIT "[ NEQ ,&no-end JCN
STHkr #00 EQU ,&end JCN
LITr 01 SUBr
&no-end
@ -67,4 +67,4 @@ JMP2r
"..+++.>>.<-.<.+++.------.-------
"-.>>+.>++. $1
@memory
@memory

View File

@ -25,8 +25,8 @@ JMP2r
@input-main ( -> )
.Console/read DEI
LIT '0 EQUk NIP ,&no JCN
LIT '1 EQUk NIP ,&yes JCN
LIT "0 EQUk NIP ,&no JCN
LIT "1 EQUk NIP ,&yes JCN
( ignore other inputs )
POP
@ -56,7 +56,7 @@ JMP2r
@pstr ( str* -- )
&while
LDAk DUP LIT '_ EQU #3f MUL SUB .Console/write DEO
LDAk DUP LIT "_ EQU #3f MUL SUB .Console/write DEO
INC2 LDAk ,&while JCN
POP2

View File

@ -96,7 +96,7 @@ JMP2r
;program/accumulator
&w
[ LIT2 &a $2 ] OVR2 ;sseg JSR2 #01 NEQ ,&no-found JCN
,&b LDR2 LDA LIT '~ EQU ,&output JCN
,&b LDR2 LDA LIT "~ EQU ,&output JCN
( shift ) DUP2 [ ,&b LDR2 ;slen JSR2 ,&a LDR2 ;slen JSR2 SUB2 ] ;ssft JSR2
( write ) [ LIT2 &b $2 ] SWP2 OVR2 ;slen JSR2 ;mcpy JSR2
POP2 #01 JMP2r
@ -109,7 +109,7 @@ JMP2r
&output
,&a LDR2 ;slen JSR2 #0000 SWP2 SUB2 ;ssft JSR2
POP2 ,&b LDR2 INC2
LDAk LIT '` NEQ ,&no-lb JCN
LDAk LIT "` NEQ ,&no-lb JCN
#0a18 DEO #01 JMP2r
&no-lb
,print-str JSR #01

View File

@ -75,7 +75,7 @@ BRK
LIT 22 #02 ;draw-char JSR2
;buffer #03 ;draw-str JSR2
LIT 22 #02 ;draw-char JSR2
LIT '. #02 ;draw-char JSR2
LIT ". #02 ;draw-char JSR2
JMP2r
@ -85,7 +85,7 @@ JMP2r
#0010 .Screen/x DEO2
.Screen/height DEI2 #0020 SUB2 .Screen/y DEO2
( marker ) LIT '> #03 ;draw-char JSR2
( marker ) LIT "> #03 ;draw-char JSR2
;buffer STHr ;draw-str JSR2

View File

@ -137,8 +137,8 @@
DUP2 ,asma-print-labels JSR
( here )
DUP2 #0004 ADD2
LDAk LIT 'A LTH ,&loop JCN
LDAk LIT 'Z GTH ,&loop JCN
LDAk LIT "A LTH ,&loop JCN
LDAk LIT "Z GTH ,&loop JCN
POP2
,&skip-device-label JMP
&loop
@ -169,8 +169,8 @@
,asma-print-string JMP
@asma-print-short ( short* -- )
LIT '0 .Console/error DEO
LIT 'x .Console/error DEO
LIT "0 .Console/error DEO
LIT "x .Console/error DEO
OVR #04 SFT ,&hex JSR
SWP #0f AND ,&hex JSR
DUP #04 SFT ,&hex JSR
@ -496,15 +496,15 @@
JMP2r
&not-end
DUP LIT '2 NEQ ,&not-two JCN
DUP LIT "2 NEQ ,&not-two JCN
POP LIT &short-flag $1 ORA ,&loop JMP
&not-two
DUP LIT 'r NEQ ,&not-return JCN
DUP LIT "r NEQ ,&not-return JCN
POP LIT &return-flag $1 ORA ,&loop JMP
&not-return
LIT 'k NEQ ,&not-keep JCN
LIT "k NEQ ,&not-keep JCN
&set-keep LIT &keep-flag $1 ORA ,&loop JMP
&not-keep ( 00 byte / end* )

View File

@ -69,15 +69,15 @@ BRK
[ #1b ] NEQk NIP ,&no-esc JCN ;do-pop JSR2 POP BRK &no-esc
[ #08 ] NEQk NIP ,&no-backspace JCN ;do-erase JSR2 POP BRK &no-backspace
( arithmetic )
[ LIT '+ ] NEQk NIP ,&no-add JCN ;do-add JSR2 POP BRK &no-add
[ LIT '- ] NEQk NIP ,&no-sub JCN ;do-sub JSR2 POP BRK &no-sub
[ LIT '* ] NEQk NIP ,&no-mul JCN ;do-mul JSR2 POP BRK &no-mul
[ LIT '/ ] NEQk NIP ,&no-div JCN ;do-div JSR2 POP BRK &no-div
[ LIT "+ ] NEQk NIP ,&no-add JCN ;do-add JSR2 POP BRK &no-add
[ LIT "- ] NEQk NIP ,&no-sub JCN ;do-sub JSR2 POP BRK &no-sub
[ LIT "* ] NEQk NIP ,&no-mul JCN ;do-mul JSR2 POP BRK &no-mul
[ LIT "/ ] NEQk NIP ,&no-div JCN ;do-div JSR2 POP BRK &no-div
( bitwise )
[ LIT '& ] NEQk NIP ,&no-and JCN ;do-and JSR2 POP BRK &no-and
[ LIT '| ] NEQk NIP ,&no-ora JCN ;do-ora JSR2 POP BRK &no-ora
[ LIT '^ ] NEQk NIP ,&no-eor JCN ;do-eor JSR2 POP BRK &no-eor
[ LIT '~ ] NEQk NIP ,&no-not JCN ;do-not JSR2 POP BRK &no-not
[ LIT "& ] NEQk NIP ,&no-and JCN ;do-and JSR2 POP BRK &no-and
[ LIT "| ] NEQk NIP ,&no-ora JCN ;do-ora JSR2 POP BRK &no-ora
[ LIT "^ ] NEQk NIP ,&no-eor JCN ;do-eor JSR2 POP BRK &no-eor
[ LIT "~ ] NEQk NIP ,&no-not JCN ;do-not JSR2 POP BRK &no-not
( value )
;key-value JSR2 ;push-input JSR2

View File

@ -47,7 +47,7 @@
#006c ADD2 .time/y STZ2
;draw-watchface JSR2
( time buffer )
LIT ':
LIT ":
DUP .buf/s1 STZ
.buf/s2 STZ
@ -121,8 +121,8 @@ JMP2r
DUP ;is-lc JSR2 ,&lc JCN
DUP ;is-uc JSR2 ,&uc JCN
DUP ;is-num JSR2 ,&num JCN
DUP LIT '/ EQU ,&slash JCN
DUP LIT ': EQU ,&colon JCN
DUP LIT "/ EQU ,&slash JCN
DUP LIT ": EQU ,&colon JCN
POP ;font/blank
&end
.Screen/addr DEO2

View File

@ -191,7 +191,7 @@ JMP2r
#0010 .Screen/x DEO2
#0080 .Screen/y DEO2
.browser/sel LDZ #02 ;draw-byte JSR2
LIT '/ #02 ;draw-char JSR2
LIT "/ #02 ;draw-char JSR2
.browser/lines LDZ #01 SUB #02 ;draw-byte JSR2
#00 .Screen/auto DEO

View File

@ -88,14 +88,14 @@ BRK
#40 .Screen/sprite DEO
.Controller/key DEI
[ LIT 'a ] NEQk NIP ,&no-c JCN #30 .octave LDZ #0c MUL ADD ;play JSR2 &no-c
[ LIT 's ] NEQk NIP ,&no-d JCN #32 .octave LDZ #0c MUL ADD ;play JSR2 &no-d
[ LIT 'd ] NEQk NIP ,&no-e JCN #34 .octave LDZ #0c MUL ADD ;play JSR2 &no-e
[ LIT 'f ] NEQk NIP ,&no-f JCN #35 .octave LDZ #0c MUL ADD ;play JSR2 &no-f
[ LIT 'g ] NEQk NIP ,&no-g JCN #37 .octave LDZ #0c MUL ADD ;play JSR2 &no-g
[ LIT 'h ] NEQk NIP ,&no-a JCN #39 .octave LDZ #0c MUL ADD ;play JSR2 &no-a
[ LIT 'j ] NEQk NIP ,&no-b JCN #3b .octave LDZ #0c MUL ADD ;play JSR2 &no-b
[ LIT 'k ] NEQk NIP ,&no-c2 JCN #3c .octave LDZ #0c MUL ADD ;play JSR2 &no-c2
[ LIT "a ] NEQk NIP ,&no-c JCN #30 .octave LDZ #0c MUL ADD ;play JSR2 &no-c
[ LIT "s ] NEQk NIP ,&no-d JCN #32 .octave LDZ #0c MUL ADD ;play JSR2 &no-d
[ LIT "d ] NEQk NIP ,&no-e JCN #34 .octave LDZ #0c MUL ADD ;play JSR2 &no-e
[ LIT "f ] NEQk NIP ,&no-f JCN #35 .octave LDZ #0c MUL ADD ;play JSR2 &no-f
[ LIT "g ] NEQk NIP ,&no-g JCN #37 .octave LDZ #0c MUL ADD ;play JSR2 &no-g
[ LIT "h ] NEQk NIP ,&no-a JCN #39 .octave LDZ #0c MUL ADD ;play JSR2 &no-a
[ LIT "j ] NEQk NIP ,&no-b JCN #3b .octave LDZ #0c MUL ADD ;play JSR2 &no-b
[ LIT "k ] NEQk NIP ,&no-c2 JCN #3c .octave LDZ #0c MUL ADD ;play JSR2 &no-c2
[ #1b ] NEQk NIP ,&no-esc JCN #010f DEO &no-esc
POP

View File

@ -415,8 +415,8 @@
OPCODE
( DEI/DEO )
LIT '1 EMIT
LIT '1 EMIT
LIT "1 EMIT
LIT "1 EMIT
TYPE
( Branching )

View File

@ -44,8 +44,6 @@ typedef struct {
} Program;
Program p;
static int litlast = 0;
static int jsrlast = 0;
/* clang-format off */
@ -207,8 +205,6 @@ writebyte(Uint8 b)
return error("Memory overwrite", "");
p.data[p.ptr++] = b;
p.length = p.ptr;
litlast = 0;
jsrlast = 0;
return 1;
}
@ -216,14 +212,7 @@ static int
writeopcode(char *w)
{
Uint8 res;
if(jsrlast && scmp(w, "JMP2r", 5)) { /* tail-call optimization */
p.data[p.ptr - 1] = findopcode("JMP2");
jsrlast = 0;
return 1;
}
res = writebyte(findopcode(w));
if(scmp(w, "JSR2", 4))
jsrlast = 1;
return res;
}
@ -238,15 +227,8 @@ writeshort(Uint16 s, int lit)
static int
writelitbyte(Uint8 b)
{
if(litlast) { /* literals optimization */
Uint8 hb = p.data[p.ptr - 1];
p.ptr -= 2;
p.length = p.ptr;
return writeshort((hb << 8) + b, 1);
}
if(!writebyte(findopcode("LIT"))) return 0;
if(!writebyte(b)) return 0;
litlast = 1;
return 1;
}
@ -297,24 +279,20 @@ parse(char *w, FILE *f)
if(!sihx(w + 1))
return error("Invalid padding", w);
p.ptr = shex(w + 1);
litlast = jsrlast = 0;
break;
case '$': /* pad-relative */
if(!sihx(w + 1))
return error("Invalid padding", w);
p.ptr += shex(w + 1);
litlast = jsrlast = 0;
break;
case '@': /* label */
if(!makelabel(w + 1))
return error("Invalid label", w);
scpy(w + 1, p.scope, 0x40);
litlast = jsrlast = 0;
break;
case '&': /* sublabel */
if(!makelabel(sublabel(subw, p.scope, w + 1)))
return error("Invalid sublabel", w);
litlast = jsrlast = 0;
break;
case '#': /* literals hex */
if(!sihx(w + 1) || (slen(w) != 3 && slen(w) != 5))
@ -326,11 +304,11 @@ parse(char *w, FILE *f)
}
break;
case '.': /* literal byte zero-page */
makereference(p.scope, w, p.ptr - litlast);
makereference(p.scope, w, p.ptr);
if(!writelitbyte(0xff)) return 0;
break;
case ',': /* literal byte relative */
makereference(p.scope, w, p.ptr - litlast);
makereference(p.scope, w, p.ptr);
if(!writelitbyte(0xff)) return 0;
break;
case ';': /* literal short absolute */
@ -341,9 +319,6 @@ parse(char *w, FILE *f)
makereference(p.scope, w, p.ptr);
if(!writeshort(0xffff, 0)) return 0;
break;
case '\'': /* raw char */
if(!writebyte((Uint8)w[1])) return 0;
break;
case '"': /* raw string */
i = 0;
while((c = w[++i]))