( uxncli tgachr.rom img.tga | output img20x10.chr ) |10 @Console/vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1 |a0 @File/vector $2 &success $1 &success-lb $1 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 |b0 @File2/vector $2 &success $1 &success-lb $1 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 |000 @src/buf $40 @dst/buf $40 @size $2 |100 @on-reset ( -> ) .Console/type DEI ?{ ;dict/usage str/ #010f DEO BRK } ;src/on-console .Console/vector DEO2 BRK @src/on-console ( -> ) [ LIT2 02 -Console/type ] DEI LTH ?{ / BRK } ;&buf tga/ #800f DEO BRK @src/ ( c -- ) .Console/read DEI [ LIT &ptr -&buf ] INCk ,&ptr STR STZ JMP2r @dst/ ( w h -- ) [ LIT2 fc _&ptr ] LDR ADD ,&ptr STR SWP / LIT "x / / ;dict/chr-ext ( >> ) @dst/ ( str* -- ) &>w LDAk DUP ?{ POP POP2 JMP2r } / INC2 !/>w @dst/ ( b -- ) DUP #04 SFT / ( >> ) @dst/ ( n -- ) #00 SWP #0f AND ;&lut ADD2 LDA ( >> ) @dst/ ( c -- ) [ LIT &ptr -&buf ] INCk ,&ptr STR STZ JMP2r &lut "0123456789abcdef ( @|Core ) @tga/get-length ( -- lengt* ) #00 ;&depth LDA #03 SFT JMP2r @tga/ ( path* -- ) DUP2 dst/ .File/name DEO2 #0012 .File/length DEO2 ;&head .File/read DEO2 ( | flip endianness ) ;&w LDA2k SWP SWP2 STA2 ;&h LDA2k SWP SWP2 STA2 /get-size dst/ ( | set buffer length ) ;dst/buf .File2/name DEO2 ;&w LDA2 #43 SFT2 .File2/length DEO2 ( | get parser ) ;&image-type LDA ( | handlers ) DUP #02 NEQ ?{ POP ;filter/raw-true /get-length !/ } DUP #03 NEQ ?{ POP ;filter/raw-bw /get-length !/ } ( error ) ;&error-txt !str/ &error-txt "Unsupported 20 "tga-type: 20 00 @tga/ ( filter* length* -- ) .File/length DEO2 ,&filter STR2 #0000 ,&x STR2 #0000 ,&y STR2 &>stream ;&pixel STH2k .File/read DEO2 [ LIT2 &x $2 ] [ LIT2 &y $1 &y-lb $1 ] STH2r [ LIT2 &filter $2 ] JSR2 ( chr ) pixel/ ( | on linebreak ) ,&x LDR2 INC2 DUP2 ,&x STR2 ;&w LDA2 NEQ2 ?{ #0000 ,&x STR2 [ LIT2 07 _&y-lb ] LDR INC AND DUP ,&y-lb STR ?{ ;&buffer .File2/write DEO2 .size LDZ2k .File2/length DEI2 ADD2 ROT STZ2 } } .File/success DEI2 ORA ?/>stream JMP2r &pixel $4 @pixel/assoc-color ( gray -- color ) DUP #ef GTH ?{ DUP #7f GTH ?{ #1f GTH ?{ #03 JMP2r } #01 JMP2r } POP #02 JMP2r } POP #00 JMP2r @pixel/ ( x* y* gray -- ) /assoc-color STH ( addr ) OVR2 #43 SFT2 ADD2 ;tga/buffer ADD2 ( mask ) SWP2 NIP #07 AND #80 SWP SFT DUP ,&mask STR #ff EOR ,&nm STR ( ch1 ) DUP2 STHkr #01 SFT / ( ch2 ) #0008 ADD2 STHr #01 AND ( >> ) @pixel/ ( addr* bit -- ) [ LIT &mask $1 ] MUL STH LDAk [ LIT &nm $1 ] AND STH ORAr STH2 STAr JMP2r @filter/raw-true ( pixel* -- color ) STH2 ( b ) #00 LDAkr STHr INC2r ( g ) #00 LDAkr STHr INC2r ( r ) #00 LDAr STHr ( res ) ADD2 ADD2 #0003 DIV2 NIP JMP2r @filter/raw-bw ( pixel* -- color ) LDA JMP2r @tga/get-size ( -- w h ) ( w ) ;&w LDA2 #03 SFT2 NIP ( h ) ;&h LDA2 #03 SFT2 NIP JMP2r ( @|Stdlib ) @str/ ( str* -- ) LDAk DUP ?{ POP POP2 JMP2r } #18 DEO INC2 !/ @dict/usage "usage: 20 "tgachr.rom 20 "input.tga 0a00 &chr-ext ".chr 00 ( @|Buffers ) @tga/head [4 &id-length $1 &color-map $1 &image-type $1 &map $5 &_x $2 &_y $2 &w $2 &h $2 &depth $1 &descriptor $1 ] @tga/buffer