#
# ZX Next NXI exporter 256/320
# A Multipaint internal script
#

XREM "9-bit palette"

# RRRGGGBB .......B

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

	R=R/36
	G=G/36
	B=B/36

	L=R*32
	S=G*4
	L=L|S

	S=B&6
	S=S/2
	L=L|S

	H=B&1

	XBYTE L
	XBYTE H

NEXT I

XREM "bitmap"

# detect 32 or 40 size

H=PEEK 5

IF H=32
    FOR Y=0 TO 191
	    FOR X=0 TO 255
		    P=GETPOINT X,Y
		    XBYTE P
	    NEXT X
    NEXT Y
ENDIF
IF H=40
	FOR X=0 TO 319
        FOR Y=0 TO 255
		    P=GETPOINT X,Y
		    XBYTE P
        NEXT Y
	NEXT X
ENDIF


# Write to file (bytes)

SAVE
