#
# Commodore Plus/4 MultiBotticelli multicolor importer
# A Multipaint internal script
#
# Thanks to KiCHY
#

LOAD

# Error check

A = LENGTH

IF A<10050
	ALERT 1
	STOP
ENDIF
IF A>10064
	ALERT 1
	STOP
ENDIF

# header

READ A
READ A

# luminance

FOR Y=0 TO 24
	FOR X=0 TO 39
		READ A
		H=A&$F0
		L=A&$0F
		H=H/16
		H=H*15
		L=L*15
		J=65536+X+Y*40
		P=65536+X+Y*40+1000
		POKE P,L
		POKE J,H
	NEXT X
NEXT Y

# padding

FOR I=0 TO 21
	READ A
NEXT I

# background 1

READ A
H=A&$0F
L=A&$F0
L=L/16
POKE 2,H*15+L

# background 2

READ A
H=A&$0F
L=A&$F0
L=L/16
POKE 1,H*15+L


# add color

FOR Y=0 TO 24
	FOR X=0 TO 39
		READ A
		H=A&$F0
		L=A&$0F
		H=H/16
		J=65536+X+Y*40
		P=65536+X+Y*40+1000
		M=PEEK P
		M=M+H
		POKE P,M
		M=PEEK J
		M=M+L		
		POKE J,M
	NEXT X
NEXT Y

# padding

FOR I=0 TO 23
	READ A
NEXT I

# bitmap

P=1024

FOR Y=0 TO 24
	FOR X=0 TO 39
		FOR V=0 TO 7
			READ L
			C=128
			P=1024+X*8+Y*2560+V*320
			FOR B=0 TO 7
				A=L&C				
				IF A=0
					POKE P,0
				ENDIF
				IF A<>0
					POKE P,1
				ENDIF
				P=P+1
				C=C/2
			NEXT B
		NEXT V
	NEXT X
NEXT Y
