#
# Amstrad CPC mode 0 (lowres 160x200 bitmap) exporter
# A Multipaint internal script
#
# Based on CPC formats in Pixel Polizei by MarQ
#

XREM "CPC machine code header"

XBYTE $3E,$00,$CD,$0E,$BC,$CD,$19,$BD,$3A,$55,$A0,$47,$4F,$CD,$38,$BC
XBYTE $21,$56,$A0,$CD,$31,$60,$CD,$19,$BD,$21,$45,$60,$11,$00,$C0,$01
XBYTE $00,$40,$ED,$B0,$CD,$19,$BD,$21,$45,$A0,$CD,$31,$60,$CD,$18,$BB
XBYTE $C9,$06,$10,$3E,$00,$4E,$23,$E5,$C5,$F5,$41,$CD,$32,$BC,$F1,$C1
XBYTE $E1,$3C,$10,$F1,$C9

XREM "Bitmap"

U=32768
J=0

FOR W=0 TO 7
	FOR Y=0 TO 24
		FOR X=0 TO 79
			P = 1024
			V = Y*8
			V = V*320
			P = P+V
			V = W*320
			P = P+V
			V = X*4
			P = P+V

			A = 0
			B = 0
			C = 0
			D = 0
			E = 0
			F = 0
			G = 0
			H = 0

			Z = PEEK P

			M = Z&1
			IF M<>0
				H=1
			ENDIF

			M = Z&2
			IF M<>0
				D=1
			ENDIF

			M = Z&4
			IF M<>0
				F=1
			ENDIF

			M = Z&8
			IF M<>0
				B=1
			ENDIF
	
			P = P+2

			Z = PEEK P

			M = Z&1
			IF M<>0
				G=1
			ENDIF

			M = Z&2
			IF M<>0
				C=1
			ENDIF

			M = Z&4
			IF M<>0
				E=1
			ENDIF

			M = Z&8
			IF M<>0
				A=1
			ENDIF		

			O = A
			O = O+B*2
			O = O+C*4
			O = O+D*8
			O = O+E*16
			O = O+F*32
			O = O+G*64
			O = O+H*128

			XBYTE O

		NEXT X
	NEXT Y

	# padding

	FOR I=0 TO 47
		XBYTE 0
	NEXT I

NEXT W

XREM "Palette Order"

A=256
FOR I=0 TO 15
	R = PEEK A
	A = A+1
	G = PEEK A
	A = A+1
	B = PEEK A
	A = A+1

	H = SCALERGB G,3
	L = SCALERGB R,3
	M = SCALERGB B,3

	O = M
	O = O+L*3
	O = O+H*9

	XBYTE O
NEXT I

XREM "Border"

	A = PEEK 0
	A = A*3
	A = A+256

	R = PEEK A
	A = A+1
	G = PEEK A
	A = A+1
	B = PEEK A

	H = SCALERGB G,3
	L = SCALERGB R,3
	M = SCALERGB B,3

	O = M
	O = O+L*3
	O = O+H*9

	XBYTE O

FOR I=0 TO 15
	XBYTE 0
NEXT I

# Write to file

L = 16486

SAVE
