; icebrawl library
; ****************************************************************************************************
; * put(x1,y1,transparency,address image)
; ****************************************************************************************************
FUNCTION	PUT	X1,Y1,TRANS,IMAGE
REM	; put(x1,y1,transparency,+image)
REM	; 128x192
DEF	X1	BYTE
DEF	Y1	BYTE
DEF	TRANS	BYTE
DEF	IMAGE	WORD
; put on the screen
RAMROM	EQU	$3FF0
SETX	FCB	0
XST	FCB	0
X1	FCB	0
Y1	FCB	0
X2	FCB	0
Y2	FCB	0
XCNT	FCB	0
TRANS	FCB	0
PAGE	FCB	0	;what screen
IMAGE	FCB	0,0	;start draw addr
COL	FCB	0
DOTST	FCB	0	;odd even
DOTMSK1	FCB	15,240,240,15
DOTCOL	FCB	0,17,34,51,68,85,102,119,136,153,170,187,204,221,238,255	;full colors both dots
SCRNTBL	FDB	3584,9728
PUT	LDA	X1	;check if pixel is on screen
	LBMI	OUT	;nope exit 128-
	STA	XST
	LDA	Y1
	CMPA	#191
	LBHI	OUT
;	LDA	#1
;	STA	RAMROM	;need to swap ramram
;	STA	$FFDF
	LDX	#49152	;new screens for hockey
	LDB	#64
	LDA	Y1
	MUL
	LEAX	D,X
; no x save
PUT1	LDY	#DOTMSK1
	LDU	IMAGE
	LDD	0,U
	STD	X2
	ADDB	Y1
	STB	Y2	;sizes saved
	LEAU	2,U
; lets process dots
LOOP0	LDA	X2
	STA	XCNT	;x counter
LOOP	LDA	,U+	;got first pixel
	BNE	NOTRANS
	LDB	TRANS
	BNE	DONE2
NOTRANS	STA	COL	;color to set
	CLR	DOTST
	LDB	X1
	BITB	#1
	BEQ	ODD1
	INC	DOTST
ODD1	LSRB
	STB	SETX
	LDA	B,X
	LDB	DOTST
	ANDA	B,Y	;initial mask
	LDB	SETX
	STA	B,X
; masked
	LDA	COL
	ADDA	#4
	LDA	A,Y	;loaded color
	LDB	DOTST
	ADDB	#2
	ANDA	B,Y	;mask
;	anda	col
	LDB	SETX
	ADDA	B,X
	STA	B,X
DONE2	INC	X1
	LDA	XCNT
	BEQ	NEXTY
	DEC	XCNT
	BRA	LOOP
NEXTY	INC	Y1
	LEAX	64,X
	LDA	XST
	STA	X1
	LDA	Y1
	CMPA	Y2
	BLS	LOOP0
OUT	RTS
;	CLR	RAMROM
;	STA	$FFDE	;out
;	RTS
ENDFUNCTION
;
; ****************************************************************************************************
; * get(x1,y1,x2,y2,address image)
; ****************************************************************************************************
FUNCTION	GET	X1,Y1,X2,Y2,IMAGE
REM	; get(x1,y1,x2,y2,+image)
REM	; 128x192
DEF	X1	BYTE
DEF	Y1	BYTE
DEF	X2	BYTE
DEF	Y2	BYTE
DEF	IMAGE	WORD
; put on the screen
RAMROM	EQU	$3FF0
SETX	FCB	0
XST	FCB	0
X1	FCB	0
Y1	FCB	0
X2	FCB	0
Y2	FCB	0
XP1	FCB	0
YP1	FCB	0
CNTX	FCB	0
PAGE	FCB	0	;what screen
IMAGE	FCB	0,0	;start draw addr
TEST3	FCB	0
COCO3	FCB	0
COL	FCB	0
DOTST	FCB	0	;odd even
DOTMSK1	FCB	15,240,240,15
DOTCOL	FCB	0,17,34,51,68,85,102,119,136,153,170,187,204,221,238,255	;full colors both dots
SCRNTBL	FDB	3584,9728
GET	LDU	IMAGE
	LDD	X2
	SUBA	X1
	STA	0,U
	STA	X2
	SUBB	Y1
	STB	1,U
	LEAU	2,U
;	LDA	#1
;	STA	RAMROM	;need to swap ramram
;	STA	$FFDF
; lets process dots
LOOP0	CLR	CNTX	;x counter
LOOP	LDA	X1
	ADDA	CNTX
	STA	XP1	;plus x
	LDA	Y1
	STA	YP1
	JSR	POINT	;draw dot
	STB	,U+
	INC	CNTX
	LDA	CNTX
	CMPA	X2
	BLS	LOOP	;may need adj
	INC	Y1
	LDA	Y1
	CMPA	Y2
	BHI	DONEA
	BRA	LOOP0
DONEA	RTS
; CLR	RAMROM
;	STA	$FFDE	;out
;	RTS
POINT	LDX	#49152	;coco 3 uses 9728 for both pages
; x index is at start of screen
	LDA	YP1
	LDB	#64
	MUL
	LEAX	D,X	; advance y pos
	CLR	DOTST
	LDB	XP1
	BITB	#1
	BNE	ODD1
	INC	DOTST
ODD1	LSRB
	ABX
	LDB	,X
	LDA	DOTST
	BEQ	ODDS
; evens
	LSRB
	LSRB
	LSRB
	LSRB
	RTS
ODDS	ANDB	#15
	RTS
ENDFUNCTION
