#
# Atari ST Degas .PI1 (lowres 320x200 bitmap) importer
# A Multipaint internal script
#
# R0 G0 B0 xx R1 R4 R3 R2  G1 G4 G3 G2 B1 B4 B3 B2
#  *  *  *     *            *           *        
# What about Atari STE/Falcon?     
#
# fail if less than 32000 or more than 32768

LOAD

# Error checking

A = LENGTH

IF A<32000
	ALERT 1
	STOP
ENDIF
IF A>32768
	ALERT 1
	STOP
ENDIF

# header

READ A
READ A

# palette

FOR I=0 TO 15
	READW V
	R=V&$0F00
	G=V&$00F0
	B=V&$000F
	R=R/256
	G=G/16
	MAKECOLOR I,7,7,7,R,G,B
NEXT I

# bitmap

H=199
W=319/16

FOR Y=0 TO H
	FOR X=0 TO W
		READW a
		READW b
		READW c
		READW d
		T=$8000
		FOR B=0 TO 15
			P=0
			M=T&a
			IF M<>0
				P=P+1
			ENDIF
			M=T&b
			IF M<>0
				P=P+2
			ENDIF
			M=T&c
			IF M<>0
				P=P+4
			ENDIF
			M=T&d
			IF M<>0
				P=P+8
			ENDIF
			PUTPOINT X*16+B,Y,P
			T=T/2
		NEXT B	
	NEXT X
NEXT Y

REFRESH
