uxn-utils/cli/uxndis/src/uxndis.tal

225 lines
4.2 KiB
Tal
Raw Normal View History

2024-07-21 11:41:53 -04:00
( uxncli uxndis.rom input.rom )
2024-06-09 19:27:36 -04:00
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
2024-06-09 20:29:26 -04:00
|a0 @File &vector $2 &success $1 &success-lb $1 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
2024-07-21 11:41:53 -04:00
2024-06-09 19:27:36 -04:00
|000
@src $40
|100
@on-reset ( -> )
;meta #06 DEO2
;await-src .Console/vector DEO2
.Console/type DEI ?{ ;dict/usage <pstr>
#000f DEO }
BRK
@await-src ( -> )
2024-06-10 12:21:11 -04:00
[ LIT2 04 -Console/type ] DEI NEQ ?{
;src <load-rom>
[ LIT ". ] src/<append>
[ LIT "s ] src/<append>
[ LIT "y ] src/<append>
[ LIT "m ] src/<append>
;src <load-sym>
( | print result )
,<load-rom>/ptr LDR2 ;rom
&>l ( -- )
<print-line>
INC2 GTH2k ?&>l
POP2 POP2 #800f DEO
2024-06-09 19:27:36 -04:00
BRK }
2024-06-10 12:21:11 -04:00
.Console/read DEI src/<append>
2024-06-09 19:27:36 -04:00
BRK
2024-06-10 12:21:11 -04:00
@src/<append> ( char -- )
[ LIT &ptr -src ] INCk ,&ptr STR
STZ
JMP2r
@<load-rom> ( src* -- )
.File/name DEO2
2024-06-09 20:29:26 -04:00
#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
2024-07-21 11:41:53 -04:00
STA !&>stream }
2024-06-10 12:21:11 -04:00
JMP2r
@<load-sym> ( src* -- )
.File/name DEO2
#4000 .File/length DEO2
;sym .File/read DEO2
.File/success DEI2 #0000 EQU2 ;find-sym/null STA
2024-06-10 12:21:11 -04:00
JMP2r
2024-06-09 20:29:26 -04:00
@<print-line> ( addr* -- addr* )
2024-06-10 12:21:11 -04:00
( ) DUP2 ;rom SUB2
( ) DUP2 #0100 ADD2 find-sym DUP2 #ffff EQU2 ?{
2024-06-11 11:47:17 -04:00
#0a18 DEO
2024-06-10 12:21:11 -04:00
[ LIT2 "@ 18 ] DEO
DUP2 <pstr>
#0a18 DEO }
POP2
( ) <print-address>
2024-06-09 20:29:26 -04:00
<print-opcode>
#0a18 DEO
JMP2r
@<print-address> ( addr* -- )
2024-07-21 11:41:53 -04:00
#0100 ADD2 <phex>
2024-06-09 20:29:26 -04:00
[ 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* )
LDAk ?{ <print-1-byte>
;opcodes/brk !<pstr> }
2024-06-10 11:12:20 -04:00
LDAk #9f AND ?{
2024-06-09 20:29:26 -04:00
<print-3-byte>
2024-06-10 11:12:20 -04:00
LDAk #03 SFT #00 SWP ;opcodes/brk ADD2 <pstr>
2024-06-09 20:29:26 -04:00
#2018 DEO
DUP2 INC2k LDA2 <print-rel>
INC2 INC2 JMP2r }
2024-06-09 20:29:26 -04:00
LDAk DUP #80 NEQ SWP #c0 NEQ AND ?{
<print-2-byte>
;opcodes <pstr>
2024-06-11 11:47:17 -04:00
LDAk #80 EOR <print-mode>
2024-06-09 20:29:26 -04:00
#2018 DEO
INC2 LDAk !<phex>/b }
LDAk DUP #a0 NEQ SWP #e0 NEQ AND ?{
<print-3-byte>
;opcodes <pstr>
2024-06-11 11:47:17 -04:00
LDAk #80 EOR <print-mode>
2024-06-09 20:29:26 -04:00
#2018 DEO
2024-06-11 11:47:17 -04:00
INC2 LDA2k find-sym DUP2 #ffff EQU2 ?{ <pstr>
INC2 JMP2r }
POP2 LDA2k <phex>
2024-06-09 20:29:26 -04:00
INC2 JMP2r }
<print-1-byte>
LDAk #1f AND #00 SWP #20 SFT2 ;opcodes ADD2 <pstr>
2024-06-11 11:47:17 -04:00
LDAk
2024-06-09 20:29:26 -04:00
( >> )
2024-06-11 11:47:17 -04:00
@<print-mode> ( byte -- )
DUP #20 AND #00 EQU ?{
2024-06-10 12:58:05 -04:00
[ LIT2 "2 18 ] DEO }
2024-06-11 11:47:17 -04:00
DUP #80 AND #00 EQU ?{
[ LIT2 "k 18 ] DEO }
#40 AND #00 EQU ?{
2024-06-09 20:29:26 -04:00
[ LIT2 "r 18 ] DEO }
2024-06-09 19:27:36 -04:00
JMP2r
@<print-rel> ( addr* value* -- )
( | find sym )
SWP2 ;rom SUB2 #0103 ADD2 OVR2 ADD2 find-sym
2024-06-11 11:47:17 -04:00
( ) INC2k ORA ?{
POP2 OVR #80 AND ?<pdec>
2024-07-21 11:41:53 -04:00
[ LIT2 "+ 18 ] DEO !<pdec> }
NIP2 !<pstr>
2024-06-09 20:29:26 -04:00
@<print-pad> ( count -- )
#00
&>l ( -- )
#2018 DEO
INC GTHk ?&>l
POP2 JMP2r
2024-06-10 12:21:11 -04:00
@find-sym ( addr* -- sym* )
,&t STR2
[ LIT &null 01 ] ?&skip
2024-06-10 12:21:11 -04:00
;sym
&>w ( -- )
LDA2k [ LIT2 &t $2 ] NEQ2 ?{ INC2 INC2 JMP2r }
INC2 INC2 scap/ INC2 INC2k INC2 LDA ?&>w
POP2 &skip #ffff JMP2r
2024-06-10 12:21:11 -04:00
2024-06-09 19:27:36 -04:00
(
@|stdlib )
2024-06-09 20:29:26 -04:00
@<pdec> ( short* -- )
( | sign )
2024-06-09 20:48:39 -04:00
OVR #80 AND #00 EQU ?{
2024-06-09 20:29:26 -04:00
[ LIT2 "- 18 ] DEO
#8000 SWP2 SUB2 #7fff AND2 }
[ LIT2 00 _&z ] STR
2024-06-09 20:48:39 -04:00
#2710 /p #03e8 /p #0064 /p #000a /p NIP !<pnum>
2024-07-21 11:41:53 -04:00
2024-06-09 20:48:39 -04:00
&p ( -- )
2024-06-09 20:29:26 -04:00
DIV2k DUPk [ LIT &z $1 ] EQU ?{
2024-06-09 20:48:39 -04:00
DUP <pnum>
2024-06-09 20:29:26 -04:00
[ LIT2 ff _&z ] STR }
POP MUL2 SUB2 JMP2r
2024-06-09 19:27:36 -04:00
@<phex> ( short* -: )
SWP /b
&b ( byte -: )
DUP #04 SFT /c
&c ( byte -: )
2024-06-09 20:48:39 -04:00
#0f AND DUP #09 GTH #27 MUL ADD
( >> )
@<pnum> ( num -- )
[ LIT "0 ] ADD #18 DEO
2024-06-09 19:27:36 -04:00
JMP2r
@<pstr> ( str* -- )
LDAk #18 DEO
INC2 LDAk ?<pstr>
POP2 JMP2r
2024-06-10 12:21:11 -04:00
@scap ( str* -: end* )
INC2 & LDAk ?scap
JMP2r
2024-06-10 11:12:20 -04:00
(
@|assets )
@meta $1
( name ) "Uxndis 0a
( desc ) "Uxntal 20 "Disassembler 0a
( auth ) "By 20 "Devine 20 "Lu 20 "Linvega 0a
2024-07-21 11:41:53 -04:00
( date ) "21 20 "Jul 20 "2024 $2
2024-06-10 11:12:20 -04:00
2024-06-09 19:27:36 -04:00
@opcodes [
2024-06-09 20:29:26 -04:00
"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
2024-06-10 11:12:20 -04:00
&brk "BRK 00 &jci "JCI 00 &jmi "JMI
00 &jsi "JSI 00 ]
2024-06-09 19:27:36 -04:00
2024-07-21 11:41:53 -04:00
@dict
&usage "usage: 20 "uxndis.rom 20 "input.rom 0a $1
2024-06-09 19:27:36 -04:00
2024-06-10 12:21:11 -04:00
@rom $8000
@sym
2024-06-09 20:29:26 -04:00