;(g*9)+(r*3)+B
;down red
SetPalette:
		ret

GetPalette:		;-GRB

		ld c,a
		ld b,&7f
		push bc
			ld a,l
			and %11110000
			call ZXcolconv
			ld b,a	 				;R
		
			ld a,l
			and %00001111  			;B

			call ZXcolconvR
			ld l,a

			ld a,h					;G
			and %00001111
			call ZXcolconvR
			ld h,a
			xor a

			add h					;Add Green x9
			add h
			add h
			add h
			add h
			add h
			add h
			add h
			add h
			
			add b					;Add Red x3
			add b
			add b

			add l					;Add Blue x1
		
			ld b,0
			ld c,a

			ld hl,ZXPalette_Map
			add hl,bc
			ld a,(hl)

		pop bc

		out (c),c               
		out (c),a

	ret
ZXcolconvR:			;We need to shift the Red color bits
	rrca
	rrca
	rrca
	rrca
ZXcolconv:				;We need to limit our returned value to 0,1 or 2
	cp &50
	jr c,ZXcolconv0	
	cp &A0
	jr c,ZXcolconv1
	ld a,2
	ret
ZXcolconv0:	
	xor a
	ret
ZXcolconv1:	
	ld a,1
	ret
ZXPalette_Map:
	
	db 0,	1,	65
	db 2,	3,	3
	db 66,	67,	67
		
	db 4,	4,	5
	db 6,	7,	5
	db 66,	66,	67
		
	db 68,	68,	69
	db 68,	68,	69
	db 70,	70,	71

	