(ulz) Housekeeping

This commit is contained in:
Devine Lu Linvega 2024-06-05 10:32:20 -08:00
parent ec6fbe4263
commit 6177f80024
4 changed files with 101 additions and 108 deletions

View File

@ -10,8 +10,8 @@ if [[ "$*" == *"--lint"* ]]
then then
clang-format -i ulzdec.c clang-format -i ulzdec.c
clang-format -i ulzenc.c clang-format -i ulzenc.c
$LIN decoder.tal $LIN ulzdec.tal
$LIN encoder.tal $LIN ulzenc.tal
fi fi
# Building # Building

View File

@ -2,19 +2,17 @@
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1 |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 $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|000
|0000
@src $30 @src $30
@dst $30 @dst $30
@ptr $1 @ptr $1
|0100 |100
@on-reset ( -> ) @on-reset ( -> )
;meta #06 DEO2 ;meta #06 DEO2
.Console/type DEI #03 AND ?{ .Console/type DEI #03 AND ?{ ;dict/usage <perr>/
;dict/usage <perr>/
#010f DEO } #010f DEO }
;&await .Console/vector DEO2 ;&await .Console/vector DEO2
BRK BRK
@ -33,7 +31,7 @@
( name ) "Ulzdec 0a ( name ) "Ulzdec 0a
( desc ) "ULZ 20 "Decoder 0a ( desc ) "ULZ 20 "Decoder 0a
( auth ) "By 20 "Devine 20 "Lu 20 "Linvega 0a ( auth ) "By 20 "Devine 20 "Lu 20 "Linvega 0a
( date ) "19 20 "Nov 20 "2023 $1 ( date ) "5 20 "Jun 20 "2024 $1
( exts ) 00 ( exts ) 00
@on-ready ( -> ) @on-ready ( -> )
@ -58,12 +56,12 @@
@<decode_ulz> ( str* -- ) @<decode_ulz> ( str* -- )
;mem .ptr STZ2 ;mem .ptr STZ2
.File/name DEO2 .File/name DEO2
&stream ( -- ) &>stream ( -- )
#0001 .File/length DEO2 #0001 .File/length DEO2
;&b DUP2 .File/read DEO2 ;&b DUP2 .File/read DEO2
.File/success DEI2 ORA ?{ POP2 JMP2r } .File/success DEI2 ORA ?{ POP2 JMP2r }
[ LIT &b $1 ] <decode_ulz_byte> [ LIT &b $1 ] <decode_ulz_byte>
!&stream !&>stream
@<decode_ulz_byte> ( byte -- ) @<decode_ulz_byte> ( byte -- )
DUP #80 AND ?op-cpy DUP #80 AND ?op-cpy
@ -90,12 +88,12 @@
@|stdlib ) @|stdlib )
@skey ( key buf -- proc ) @skey ( key buf -- proc )
OVR #21 LTH ?&eval OVR #21 LTH ?{
#00 SWP sput #00 JMP2r #00 SWP sput #00 JMP2r }
&eval POP2 #01 JMP2r POP2 #01 JMP2r
@scap ( str* -- end* ) @scap ( str* -- end* )
&w INC2 & LDAk ?&w INC2 & LDAk ?scap
JMP2r JMP2r
@sput ( chr str* -- ) @sput ( chr str* -- )
@ -109,26 +107,25 @@
[ LIT &b $1 ] JMP2r [ LIT &b $1 ] JMP2r
@<pstr> ( str* -- ) @<pstr> ( str* -- )
&w LDAk #18 DEO LDAk #18 DEO
INC2 & LDAk ?&w INC2 & LDAk ?<pstr>
POP2 JMP2r POP2 JMP2r
@<perr> ( str* -- ) @<perr> ( str* -- )
&w LDAk #19 DEO LDAk #19 DEO
INC2 & LDAk ?&w INC2 & LDAk ?<perr>
POP2 JMP2r POP2 JMP2r
@<pdec> ( short* -- ) @<pdec> ( short* -- )
#2710 [ LIT2r 00fb ] #2710 [ LIT2r 00fb ]
&w ( -- ) &>w ( -- )
DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?{ DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?{
DUP [ LIT "0 ] ADD #19 DEO DUP [ LIT "0 ] ADD #19 DEO
INCr } INCr }
POP2 #000a DIV2 SWPr INCr STHkr ?&w POP2 #000a DIV2 SWPr INCr STHkr ?&>w
POP2r POP2 POP2 JMP2r POP2r POP2 POP2 JMP2r
( @
( | mem )
@| mem )
@dict &usage "usage: 20 "ulzdec.rom 20 "a.bin 20 "b.ulz 0a $1 @dict &usage "usage: 20 "ulzdec.rom 20 "a.bin 20 "b.ulz 0a $1
&decompressed "Decompressed 20 $1 &decompressed "Decompressed 20 $1
@ -137,4 +134,3 @@
@mem @mem

View File

@ -1,9 +1,8 @@
( ulz decoder ) ( uxncli ulzenc.rom example.txt a.ulz )
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1 |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 $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|000
|0000
@pad $2 @pad $2
@src $30 @src $30
@ -15,12 +14,11 @@
@dict-data $2 @dict-data $2
@dict-len $2 @dict-len $2
|0100 |100
@ready-src ( -> ) @ready-src ( -> )
;meta #06 DEO2 ;meta #06 DEO2
.Console/type DEI #03 AND ?{ .Console/type DEI #03 AND ?{ ;dict/usage <perr>/
;dict/usage <perr>/
#010f DEO } #010f DEO }
;&await .Console/vector DEO2 ;&await .Console/vector DEO2
BRK BRK
@ -39,7 +37,7 @@
( name ) "Ulzenc 0a ( name ) "Ulzenc 0a
( desc ) "ULZ 20 "Encoder 0a ( desc ) "ULZ 20 "Encoder 0a
( auth ) "By 20 "Devine 20 "Lu 20 "Linvega 0a ( auth ) "By 20 "Devine 20 "Lu 20 "Linvega 0a
( date ) "19 20 "Nov 20 "2023 $1 ( date ) "5 20 "Jun 20 "2024 $1
( exts ) 00 ( exts ) 00
@on-ready ( -> ) @on-ready ( -> )
@ -100,12 +98,12 @@
.dict-data LDZ2 .dict-best STZ2 .dict-data LDZ2 .dict-best STZ2
POP2 !&done-search } POP2 !&done-search }
( | in[i] != dict[i % dict_len] break; ) ( | in[i] != dict[i % dict_len] break; )
( a ) ADD2k LDA STH ( a ) ADD2k LDA STH
( b ) DUP2 .dict-len LDZ2 DIV2k MUL2 SUB2 .dict-data LDZ2 ADD2 ( b ) DUP2 .dict-len LDZ2 DIV2k MUL2 SUB2 .dict-data LDZ2 ADD2
( res ) LDA STHr NEQ ?&end-for2 ( res ) LDA STHr NEQ ?&end-for2
INC2 ORAk ?&for2 INC2 ORAk ?&for2
&end-for2 ( | i > match_len ) &end-for2 ( i > match_len )
DUP2 .match-len LDZ2 LTH2 ?{ DUP2 .match-len LDZ2 LTH2 ?{
DUP2 .match-len STZ2 DUP2 .match-len STZ2
.dict-data LDZ2 .dict-best STZ2 } .dict-data LDZ2 .dict-best STZ2 }
@ -126,8 +124,8 @@
.match-len LDZ2 #0004 SUB2 .match-len LDZ2 #0004 SUB2
( | CPY2 ) ( | CPY2 )
DUP2 #003f GTH2 ?&cpy2 DUP2 #003f GTH2 ?&cpy2
( | *output_ptr++ = match_ctl | 0x80; ) ( *output_ptr++ = match_ctl
NIP #80 ORA <append-byte> | 0x80; ) NIP #80 ORA <append-byte>
!&cpy-resume !&cpy-resume
&cpy2 ( match-ctl* -- ) &cpy2 ( match-ctl* -- )
SWP #c0 ORA <append-short> SWP #c0 ORA <append-short>
@ -142,8 +140,8 @@
@op-lit ( in* -- ) @op-lit ( in* -- )
.combine LDZ2 ORA ?&combine .combine LDZ2 ORA ?&combine
( | start a new literal ) ( start a new literal )
( | Store this address, and later use it to increment the literal size. ) ( Store this address, and later use it to increment the literal size. )
( | combine = output_ptr++; ) ( | combine = output_ptr++; )
.output-ptr LDZ2 INC2k .output-ptr STZ2 .output-ptr LDZ2 INC2k .output-ptr STZ2
.combine STZ2 .combine STZ2
@ -163,12 +161,12 @@
@|stdlib ) @|stdlib )
@skey ( key buf -- proc ) @skey ( key buf -- proc )
OVR #21 LTH ?&eval OVR #21 LTH ?{
#00 SWP sput #00 JMP2r #00 SWP sput #00 JMP2r }
&eval POP2 #01 JMP2r POP2 #01 JMP2r
@scap ( str* -- end* ) @scap ( str* -- end* )
&w INC2 & LDAk ?&w INC2 & LDAk ?scap
JMP2r JMP2r
@sput ( chr str* -- ) @sput ( chr str* -- )
@ -177,22 +175,22 @@
JMP2r JMP2r
@<pstr> ( str* -- ) @<pstr> ( str* -- )
&w LDAk #18 DEO LDAk #18 DEO
INC2 & LDAk ?&w INC2 & LDAk ?<pstr>
POP2 JMP2r POP2 JMP2r
@<perr> ( str* -- ) @<perr> ( str* -- )
&w LDAk #19 DEO LDAk #19 DEO
INC2 & LDAk ?&w INC2 & LDAk ?<perr>
POP2 JMP2r POP2 JMP2r
@<pdec> ( short* -- ) @<pdec> ( short* -- )
#2710 [ LIT2r 00fb ] #2710 [ LIT2r 00fb ]
&w ( -- ) &>w ( -- )
DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?{ DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?{
DUP [ LIT "0 ] ADD #19 DEO DUP [ LIT "0 ] ADD #19 DEO
INCr } INCr }
POP2 #000a DIV2 SWPr INCr STHkr ?&w POP2 #000a DIV2 SWPr INCr STHkr ?&>w
POP2r POP2 POP2 JMP2r POP2r POP2 POP2 JMP2r
( (
@ -207,4 +205,3 @@
@compressed @compressed