seems to be working
This commit is contained in:
parent
0e85bd16c0
commit
dd368c12ec
|
@ -1,8 +1,6 @@
|
|||
( icn_to_bmp.tal )
|
||||
( )
|
||||
( converts ICN to BMP )
|
||||
( limited to 255x255 tiles, i.e. 2040x2040 pixels )
|
||||
( for now uses black and white for colors 0 and 1. )
|
||||
( converts ICN files to BMP files. )
|
||||
( )
|
||||
( USAGE: icn_to_bmp.rom $tile-w $tile-h $in-file $out-file )
|
||||
( )
|
||||
|
@ -17,13 +15,14 @@
|
|||
@tile-w $2
|
||||
@adj-tile-w $2
|
||||
@tile-h $2
|
||||
@icn-size $2
|
||||
@in-file $2
|
||||
@out-file $2
|
||||
@row-size-bytes $2
|
||||
@adj-row-size-bytes $2
|
||||
|
||||
|0100
|
||||
;after-args #0000 ( stdin: nop ) arg/init BRK
|
||||
;after-args #0000 arg/init BRK
|
||||
|
||||
( load argument parsing )
|
||||
~arg.tal
|
||||
|
@ -43,16 +42,20 @@
|
|||
&bytes-to 20 "bytes 20 "to 20 00
|
||||
&invalid-width "Invalid 20 "tile 20 "width 00
|
||||
&invalid-height "Invalid 20 "tile 20 "height 00
|
||||
&read-error "Failed 20 "to 20 "read 20 "enough 20 "data 00
|
||||
&invalid-size "Invalid 20 "size: 20 "ICN 20 "too 20 "large
|
||||
&write-error "Failed 20 "to 20 "write 20 "data 00
|
||||
&wrong-number-of-args "Wrong 20 "number 20 "of 20 "args; 20 "expected 20 "four 00
|
||||
|
||||
@usage ( reason* -> )
|
||||
;usage/error emit emit ;usage/message emit !exit
|
||||
&error "ERROR 20 00
|
||||
&error "ERROR: 20 00
|
||||
&message
|
||||
0a 0a "USAGE: 20 "icn_to_bmp.rom 20 "width 20 "height 20 "icn 20 "bmp 0a
|
||||
20 20 "width 20 "and 20 "height 20 "are 20 "given 20 "in 20 "tiles 20 "(each 20 "tile 20 "is 20 "8x8 20 "pixels) 0a
|
||||
20 20 "icn/bmp 20 "should 20 "be 20 "paths 20 "(that 20 "are 20 "readable/writable) 0a 0a 00
|
||||
0a 0a "USAGE: 20 "icn_to_bmp.rom 20 "WIDTH 20 "HEIGHT 20 "ICN 20 "BMP 0a
|
||||
20 20 "WIDTH 20 "and 20 "HEIGHT 20 "are 20 "given 20 "in 20 "tiles 20 "(each 20 "tile 20 "is 20 "8x8 20 "pixels) 0a
|
||||
20 20 "maximum 20 "WIDTH/HEIGHT 20 "is 20 "255 20 "tiles 0a
|
||||
20 20 "ICN/BMP 20 "should 20 "be 20 "paths 20 "(that 20 "are 20 "readable/writable) 0a
|
||||
20 20 "maximum 20 "ICN 20 "size 20 "is 20 "49152 20 "bytes 0a
|
||||
0a 00
|
||||
|
||||
@str-to-int ( s* -> n* )
|
||||
LIT2r 0000
|
||||
|
@ -74,17 +77,18 @@
|
|||
POPr JMP2r
|
||||
|
||||
@after-args ( -> )
|
||||
;arg/count LDA #04 NEQ ?&bad
|
||||
;arg/count LDA #04 EQU ?{ ;msg/wrong-number-of-args !usage }
|
||||
#00 arg/read str-to-int .tile-w STZ2
|
||||
#01 arg/read str-to-int .tile-h STZ2
|
||||
#02 arg/read .in-file STZ2
|
||||
#03 arg/read .out-file STZ2
|
||||
.tile-w LDZ2 .tile-h LDZ2 MUL2 #30 SFT2 .icn-size STZ2
|
||||
.tile-w LDZ2 #30 SFT2 .row-size-bytes STZ2
|
||||
.tile-w LDZ2 #0008 MUL2 #001f ADD2 #0020 DIV2 #0004 MUL2 .adj-tile-w STZ2
|
||||
.adj-tile-w LDZ2 #30 SFT2 .adj-row-size-bytes STZ2
|
||||
&bad
|
||||
validate
|
||||
write-header
|
||||
read-icn
|
||||
write-body
|
||||
;msg/wrote emit
|
||||
;bmp-header/total-size LDA2 SWP emit-dec2
|
||||
|
@ -92,17 +96,14 @@
|
|||
#0a .Console/w DEO
|
||||
!exit
|
||||
|
||||
@start-read ( -> ok^ )
|
||||
@read-icn ( -> ok^ )
|
||||
.in-file LDZ2 .File1/name DEO2
|
||||
JMP2r
|
||||
|
||||
@read-tile-row ( -> ok^ )
|
||||
.row-size-bytes LDZ2 STH2k .File1/len DEO2
|
||||
;icn-buf .File1/r DEO2
|
||||
.icn-size LDZ2 STH2k .File1/len DEO
|
||||
;icn-dat .File1/r DEO2
|
||||
.File1/ok DEI2 STH2r EQU2 JMP2r
|
||||
|
||||
@convert-tile-row ( -> )
|
||||
;icn-buf .row-size-bytes LDZ2 ( src* size* )
|
||||
@convert-tile-row ( src* -> )
|
||||
.row-size-bytes LDZ2 ( src* size* )
|
||||
OVR2 ADD2 SWP2 LIT2r =bmp-buf ( limit* src* [dst*] )
|
||||
&loop ( limit* src* [dst*] )
|
||||
DUP2 STH2kr convert-row ( limit* src* [dst*] )
|
||||
|
@ -111,12 +112,11 @@
|
|||
POP2 POP2 POP2r JMP2r ( )
|
||||
|
||||
@convert-row ( src* dst* -> )
|
||||
LITr -adj-tile-w LDZ2r STH2 #fff8 ( src* -8* [w* dst*] )
|
||||
&loop ( src* i* [w* dst*] )
|
||||
SWP2 LDAk STH2kr #010e DEO STA ( i* src* [w* dst*] ; dst<-src )
|
||||
OVR2r ADD2r ( i* src* [w* dst+w*] )
|
||||
INC2 SWP2 INC2 ( src+1* i+1* [w* dst+w*] )
|
||||
ORAk ?&loop ( src+1* i+1* [w* dst+w*] )
|
||||
LITr -adj-tile-w LDZ2r STH2 ( src* [w* dst*] )
|
||||
#0001 SUB2 DUP2 #0008 ADD2 ( lim* src+7* [w* dst*] )
|
||||
&loop ( lim* pos* [w* dst*] )
|
||||
LDAk STH2kr STA OVR2r ADD2r ( src* pos* [w* dst+w*] ; dst<-pos )
|
||||
#0001 SUB2 LTH2k ?&loop ( src* pos-1* [w* dst+w*] )
|
||||
POP2 POP2 POP2r POP2r JMP2r ( )
|
||||
|
||||
@write-tile-row ( -> ok^ )
|
||||
|
@ -127,14 +127,26 @@
|
|||
@validate ( -> )
|
||||
.tile-w LDZ2 #0001 SUB2 #00ff LTH2 ?&tile-w-ok ;msg/invalid-width !usage &tile-w-ok
|
||||
.tile-h LDZ2 #0001 SUB2 #00ff LTH2 ?&tile-h-ok ;msg/invalid-height !usage &tile-h-ok
|
||||
.icn-size LDZ2 #c001 LTH2 ?&size-ok ;msg/invalid-size !usage &size-ok
|
||||
JMP2r
|
||||
|
||||
( colors are provided in RGB order, written to BMP header in reverse )
|
||||
@write-color ( r^ g^ b^ addr* -> )
|
||||
STH2k STA INC2r ( ; addr+0<-b )
|
||||
STH2kr STA INC2r ( ; addr+1<-g )
|
||||
STH2r STA JMP2r ( ; addr+2<-r )
|
||||
|
||||
@write-header ( -> )
|
||||
.adj-tile-w LDZ2 .tile-h LDZ2 MUL2 ( aw*h )
|
||||
#30 SFT2 #0020 ADD2 ( 32+aw*h*8 )
|
||||
SWP ;bmp-header/total-size STA2
|
||||
.tile-h LDZ2 #30 SFT2 SWP ;bmp-header/pixel-h STA2 ( )
|
||||
.tile-w LDZ2 #30 SFT2 SWP ;bmp-header/pixel-w STA2 ( )
|
||||
|
||||
( these colors are specified in RGB order )
|
||||
#ff #ff #ff ;bmp-header/color0 write-color
|
||||
#00 #00 #00 ;bmp-header/color1 write-color
|
||||
|
||||
.out-file LDZ2 .File2/name DEO2
|
||||
#0020 .File2/len DEO2
|
||||
;bmp-header .File2/w DEO2
|
||||
|
@ -142,28 +154,30 @@
|
|||
&ok JMP2r
|
||||
|
||||
@write-body ( -> )
|
||||
start-read #0000 .tile-h LDZ2 SUB2
|
||||
;icn-dat ( dat* )
|
||||
.icn-size LDZ2 OVR2 ADD2 ( dat* dat+size* )
|
||||
.row-size-bytes LDZ2 STH2k SUB2 ( dat* dat+size-row* [row*] )
|
||||
&loop
|
||||
read-tile-row ?&ok1 ;msg/read-error !usage &ok1
|
||||
convert-tile-row
|
||||
DUP2 convert-tile-row
|
||||
write-tile-row ?&ok2 ;msg/write-error !usage &ok2
|
||||
INC2 ORAk ?&loop
|
||||
JMP2r
|
||||
STH2kr SUB2 GTH2k ?&done !&loop
|
||||
&done POP2r POP2 POP2 JMP2r
|
||||
|
||||
( fields marked "MOD" will be updated; others will stay the same )
|
||||
@bmp-header
|
||||
"BM ( 0: identify bitmap )
|
||||
&total-size 00 00 00 00 ( 2: total file size in bytes, includes header, TODO )
|
||||
&total-size 00 00 00 00 ( 2: total file size in bytes, includes header, MOD )
|
||||
00 00 ( 6: reserved, zero )
|
||||
00 00 ( 8: reserved, zero )
|
||||
20 00 00 00 ( 10: pixel data offset, 32 bytes )
|
||||
0c 00 00 00 ( 14: header size, 12 bytes )
|
||||
&pixel-w 00 00 ( 18: width in pixels, TODO )
|
||||
&pixel-h 00 00 ( 20: height in pixels, TODO )
|
||||
&pixel-w 00 00 ( 18: width in pixels, MOD )
|
||||
&pixel-h 00 00 ( 20: height in pixels, MOD )
|
||||
01 00 ( 22: color planes, 1 )
|
||||
01 00 ( 24: bits per pixel, 1 )
|
||||
&color0 ff ff ff ( 26: color 0, rgb, TODO )
|
||||
&color1 00 00 00 ( 29: color 1, rgb, TODO )
|
||||
( 32: start of data, TODO )
|
||||
&color0 ff ff ff ( 26: color 0, blue/green/red MOD )
|
||||
&color1 00 00 00 ( 29: color 1, blue/green/red MOD )
|
||||
( 32: start of pixel data MOD )
|
||||
|
||||
@bmp-buf $7f8
|
||||
@icn-buf $7f8
|
||||
@icn-dat $c000 ( 48k )
|
||||
|
|
Loading…
Reference in New Issue