Added immediate opcodes

This commit is contained in:
Devine Lu Linvega 2024-06-09 16:29:26 -08:00
parent fa52bd7eba
commit 134c4990b0
2 changed files with 131 additions and 8 deletions

View File

@ -13,7 +13,7 @@ lint:
bal:
@ ${BAL} src/${ID}.tal
run: all
@ ${EMU} ${ROM} etc/example.tal
@ ${EMU} ${ROM} ${ROM}
clean:
@ rm -f ${ROM} ${ROM}.sym
install: all

View File

@ -1,5 +1,5 @@
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|a0 @File &vector $2 &success $1 &success-lb $1 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|000
@src $40
@ -28,12 +28,128 @@
BRK
@<dis> ( -- )
;src <pstr> #0a18 DEO
( | load )
;src .File/name DEO2
#0001 .File/length DEO2
&>stream ( -- )
;&b .File/read DEO2
[ LIT2 00 -File/success-lb ] DEI EQU ?{
[ LIT &b $1 ] [ LIT2 &ptr =rom ] INC2k ,&ptr STR2
STA
!&>stream }
( | print )
,&ptr LDR2 ;rom
&>l ( -- )
<print-line>
INC2 GTH2k ?&>l
POP2 POP2 JMP2r
@<print-line> ( addr* -- addr* )
DUP2 ;rom SUB2 <print-address>
<print-opcode>
#0a18 DEO
JMP2r
@<print-address> ( addr* -- )
<phex>
[ LIT2 ": 18 ] DEO
#03 !<print-pad>
@<print-1-byte> ( addr* -- addr* )
LDAk <phex>/b
#09 !<print-pad>
@<print-2-byte> ( addr* -- addr* )
LDAk <print-byte>
INC2k LDA <print-byte>
#05 !<print-pad>
@<print-3-byte> ( addr* -- addr* )
LDAk <print-byte>
INC2k LDA <print-byte>
INC2k INC2 LDA <print-byte>
#02 !<print-pad>
@<print-byte> ( byte -- )
<phex>/b
#2018 DEO
JMP2r
@<print-opcode> ( addr* -- addr* )
( | print hex )
LDAk ?{ <print-1-byte>
;opcodes/brk !<pstr> }
LDAk #20 NEQ ?{
<print-3-byte>
;opcodes/jci <pstr>
#2018 DEO
INC2 LDA2k <print-rel>
INC2 JMP2r }
LDAk #40 NEQ ?{
<print-3-byte>
;opcodes/jsi <pstr>
#2018 DEO
INC2 LDA2k <print-rel>
INC2 JMP2r }
LDAk #60 NEQ ?{
<print-3-byte>
;opcodes/jmi <pstr>
#2018 DEO
INC2 LDA2k <print-rel>
INC2 JMP2r }
LDAk DUP #80 NEQ SWP #c0 NEQ AND ?{
<print-2-byte>
;opcodes <pstr>
#2018 DEO
INC2 LDAk !<phex>/b }
LDAk DUP #a0 NEQ SWP #e0 NEQ AND ?{
<print-3-byte>
;opcodes <pstr>
#2018 DEO
INC2 LDA2k <phex>
INC2 JMP2r }
<print-1-byte>
LDAk #1f AND #00 SWP #20 SFT2 ;opcodes ADD2 <pstr>
( >> )
@<print-mode> ( addr* -- )
LDAk #20 AND #00 EQU ?{
[ LIT2 "2 18 ] DEO }
LDAk #80 AND #00 EQU ?{
[ LIT2 "k 18 ] DEO }
LDAk #40 AND #00 EQU ?{
[ LIT2 "r 18 ] DEO }
JMP2r
@<print-rel> ( value* -- )
OVR #80 AND ?<pdec>
[ LIT2 "+ 18 ] DEO
!<pdec>
@<print-pad> ( count -- )
#00
&>l ( -- )
#2018 DEO
INC GTHk ?&>l
POP2 JMP2r
(
@|stdlib )
@<pdec> ( short* -- )
( | sign )
DUP2 #8000 AND2 #0000 EQU2 ?{
[ LIT2 "- 18 ] DEO
#8000 SWP2 SUB2 #7fff AND2 }
[ LIT2 00 _&z ] STR
#2710 /parse #03e8 /parse #0064 /parse #000a /parse NIP #30 ADD #18 DEO
JMP2r
&parse ( -- )
DIV2k DUPk [ LIT &z $1 ] EQU ?{
DUP #30 ADD #18 DEO
[ LIT2 ff _&z ] STR }
POP MUL2 SUB2 JMP2r
@<phex> ( short* -: )
SWP /b
&b ( byte -: )
@ -48,11 +164,18 @@
POP2 JMP2r
@opcodes [
"LIT "INC "POP "NIP "SWP "ROT "DUP "OVR
"EQU "NEQ "GTH "LTH "JMP "JCN "JSR "STH
"LDZ "STZ "LDR "STR "LDA "STA "DEI "DEO
"ADD "SUB "MUL "DIV "AND "ORA "EOR "SFT
&brk "BRK ]
"LIT 00 "INC 00 "POP 00 "NIP 00
"SWP 00 "ROT 00 "DUP 00 "OVR 00
"EQU 00 "NEQ 00 "GTH 00 "LTH 00
"JMP 00 "JCN 00 "JSR 00 "STH 00
"LDZ 00 "STZ 00 "LDR 00 "STR 00
"LDA 00 "STA 00 "DEI 00 "DEO 00
"ADD 00 "SUB 00 "MUL 00 "DIV 00
"AND 00 "ORA 00 "EOR 00 "SFT 00
&brk "BRK 00 &jci "JCI 00 &jsi "JSI
00 &jmi "JMI 00 ]
@dict &usage "usage: 20 "uxndis.rom 20 "input.rom 0a $1
@rom