( ulz decoder ) |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 |0000 @src $30 @dst $30 @ptr $1 |0100 @on-reset ( -> ) ;meta #06 DEO2 .Console/type DEI #03 AND ?{ ;dict/usage / #010f DEO } ;&await .Console/vector DEO2 BRK &await ( -> ) .Console/read DEI .src skey ?ready-dst BRK @ready-dst ( -> ) ;&await .Console/vector DEO2 BRK &await ( -> ) .Console/read DEI .dst skey ?on-ready BRK @meta $1 ( name ) "Ulzdec 0a ( desc ) "ULZ 20 "Decoder 0a ( auth ) "By 20 "Devine 20 "Lu 20 "Linvega 0a ( date ) "19 20 "Nov 20 "2023 $1 ( exts ) 00 @on-ready ( -> ) ;src ( | export ) ;dst .File/name DEO2 .ptr LDZ2 ;mem SUB2 .File/length DEO2 ;mem .File/write DEO2 ( | summary ) ;dict/decompressed ;src ;dict/spacer ;dst [ LIT2 "( 18 ] DEO .ptr LDZ2 ;mem SUB2 ;dict/bytes [ LIT2 ") 18 ] DEO #0a18 DEO ( halt ) #800f DEO BRK @ ( str* -- ) ;mem .ptr STZ2 .File/name DEO2 &stream ( -- ) #0001 .File/length DEO2 ;&b DUP2 .File/read DEO2 .File/success DEI2 ORA ?{ POP2 JMP2r } [ LIT &b $1 ] !&stream @ ( byte -- ) DUP #80 AND ?op-cpy @op-lit ( byte -- ) #00 SWP INC2 DUP2 .File/length DEO2 .ptr LDZ2 DUP2 .File/read DEO2 ADD2 .ptr STZ2 JMP2r @op-cpy ( byte -- ) #7f AND DUP #40 AND ?{ #00 SWP !© } #3f AND getc © ( length* -- ) .ptr LDZ2 #00 getc INC2 SUB2 ,&offset STR2 #0004 ADD2 #0000 &l ( length* i* -- ) ( get ) DUP2 [ LIT2 &offset $2 ] ADD2 LDA ( put ) .ptr LDZ2 STAk INC2 .ptr STZ2 POP INC2 GTH2k ?&l POP2 POP2 JMP2r ( @|stdlib ) @skey ( key buf -- proc ) OVR #21 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r @scap ( str* -- end* ) &w INC2 & LDAk ?&w JMP2r @sput ( chr str* -- ) scap/ INC2k #00 ROT ROT STA STA JMP2r @getc ( -- b ) #0001 .File/length DEO2 ;&b .File/read DEO2 [ LIT &b $1 ] JMP2r @ ( str* -- ) &w LDAk #18 DEO INC2 & LDAk ?&w POP2 JMP2r @ ( str* -- ) &w LDAk #19 DEO INC2 & LDAk ?&w POP2 JMP2r @ ( short* -- ) #2710 [ LIT2r 00fb ] &w ( -- ) DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?{ DUP [ LIT "0 ] ADD #19 DEO INCr } POP2 #000a DIV2 SWPr INCr STHkr ?&w POP2r POP2 POP2 JMP2r ( @| mem ) @dict &usage "usage: 20 "ulzdec.rom 20 "a.bin 20 "b.ulz 0a $1 &decompressed "Decompressed 20 $1 &spacer 20 "-> 20 $1 &bytes 20 "bytes $1 @mem