#
# Vic-20 importer, raw *.VIC data
# A Multipaint internal script
#
# Uses Aleksi Eeben's source & format
#

#

# We in hires (22) or multicolor (222) VIC20 mode?

M = PEEK 3

# Offset

Q = 2

IF M=222
	Q = 1
ENDIF

# input file

LOAD

# Error checking

A = LENGTH

IF A<3995
	ALERT 1
	STOP
ENDIF

IF A>3995
	ALERT 1
	STOP
ENDIF

# .VIC format

# Bitmap

P=1024

FOR Y=0 TO 10
	FOR X=0 TO 21
		FOR V=0 TO 15
			READ L
			C=128
			IF M=222
				P=1024+X*8+Y*2816+V*176
			ENDIF
			IF M=22
				P=1024+X*16+Y*5632+V*352
			ENDIF
			FOR B=0 TO 7
				A=L&C				
				IF A=0
					POKE P,0
				ENDIF
				IF A<>0
					POKE P,1
				ENDIF

				P=P+Q

				C=C/2
			NEXT B
		NEXT V
	NEXT X
NEXT Y

# Aux in high nybble

READ C

A = C/16

POKE 2,A


# Back and Border in nybbles

READ C

A = C&7

B = C/16
B = B&15

POKE 0,A
POKE 1,B


# Colors as nybbles

S = 65536
FOR P=0 TO 120
	
	READ C


	B = C/16
	B = B&7
	POKE S,B

	S = S + 1
	
	A = C&7
	POKE S,A

	S = S + 1

NEXT P

# finalize

REFRESH
