#
# Commodore Plus/4 Botticelli multicolor exporter
# A Multipaint internal script
#
# Thanks to KiCHY
#
# Thanks to Imre S.
#

XREM "Botticelli multicolor header"

XBYTE 0,120

XREM "Luminance"

FOR Y=0 TO 24
	FOR X=0 TO 39
		P = Y*40
		P = P+X
		P = P+65536
		H = PEEK P
		P = P+1000
		L = PEEK P

		C = H
		R = C-1
		R = R/15
		IF H=0
			R=0
		ENDIF
		H = R

		C = L
		R = C-1
		R = R/15
		IF L=0
			R=0
		ENDIF		
		L = R

		M = H*16
		A = M+L

		XBYTE A
	NEXT X
NEXT Y

XREM "Padding"

FOR I=0 TO 17
	XBYTE 0
NEXT I

XREM "Signature - MULT"
	XBYTE 77
	XBYTE 85
	XBYTE 76
	XBYTE 84

XREM "Background 1"

	H = PEEK 2

	C = H
	R = C-1
	R = R/15
	R = R*15
	H = C-R

	L = PEEK 2

	C = L
	R = C-1
	R = R/15
	L = R

	A = H*16
	A = A+L
	XBYTE A

XREM "Background 2"

	H = PEEK 1

	C = H
	R = C-1
	R = R/15
	R = R*15
	H = C-R

	L = PEEK 1

	C = L
	R = C-1
	R = R/15
	L = R

	A = H*16
	A = A+L
	XBYTE A

XREM "Color"

FOR Y=0 TO 24
	FOR X=0 TO 39
		P = Y*40
		P = P+X
		P = P+65536
		L = PEEK P
		P = P+1000
		H = PEEK P

		C = H
		R = C-1
		R = R/15
		R = R*15
		IF H=0
			C=0
			R=0
		ENDIF
		H = C-R

		C = L
		R = C-1
		R = R/15
		R = R*15
		IF L=0
			C=0
			R=0
		ENDIF		
		L = C-R

		M = H*16
		A = M+L
		XBYTE A
	NEXT X
NEXT Y

XREM "Padding"

FOR I=0 TO 23
	XBYTE 0
NEXT I

XREM "Bitmap"

FOR Y=0 TO 24
	FOR X=0 TO 39
		FOR V=0 TO 7
			C=128
			L=0
			FOR B=0 TO 7
				P=V*320
				P=P+B
				M=X*8
				P=P+M
				M=Y*2560
				P=P+M
				P=P+1024
				O=PEEK P
				M=C*O
				L=L+M
				C=C/2
			NEXT B
			XBYTE L
		NEXT V
	NEXT X
NEXT Y


# Write to file (10050 bytes)

SAVE
