; function library SMDBASIC vr1.0a
; written by Sheldon MacDonald (c)2020
;
;this library is a list of basic functions i have built to make programming assembly easier
;
;
; **********************************************************************************************************************
; * circlesg4(sin_costable,x1,y1,dx,dy,angle,dist,color)
; * 
; **********************************************************************************************************************
FUNCTION	CIRCLESG4	X,PLOTX,PLOTY,RADX,RADY,ANGLE,DIST,SETCOL
REM	; circlesg4([sintbl pointer],x1,y1,diamx,diamy,angle,dist,col) max rad 34 dist=0-255 full circle angle 0-255 as percentage of 360
REM	; Does not push to stack uses X for sine table
DEF	X	STRING
DEF	ANGLE	BYTE
DEF	DIST	BYTE
DEF	PLOTX	BYTE
DEF	PLOTY	BYTE
DEF	RADX	BYTE
DEF	RADY	BYTE
DEF	SETCOL	BYTE
COLOR0	FCB	128
	FCB	128
	FCB	144
	FCB	160
	FCB	176
	FCB	192
	FCB	208
	FCB	224
	FCB	240
DIST	FCB	0
ANGLE	FCB	0
DISPLAY	FCB	4
XROW	FCB	0
YROW	FCB	0
BIT1	FCB	0
BIT2	FCB	0
BIT3	FCB	0
BIT4	FCB	0
SETCOL	FCB	4
DRAW	FCB	0
ORCHR	FCB	0
WCOL	FCB	0
COLTMP	FCB	0
ODD	FCB	0
RADX	FCB	20	;radius
RADY	FCB	10
PLOTX	FCB	32
PLOTY	FCB	32
MCOL	FCB	4	;color
CNT	FCB	0	;counter from 0-255 to make circle
CALCX	FCB	0
CALCY	FCB	0
SINTB1	FCB	0,0
COSTB1	FCB	0,0
STEPP	FCB	1
CIRCLESG4	LDD	,X
	TFR	D,X
	LDB	ANGLE	;rotation
	ABX
	STX	SINTB1
	LDB	#64
	ABX
	STX	COSTB1
	CLR	CNT	;counter set
LOOP	LDA	CNT
	LDX	SINTB1
	LDB	CNT
	ABX
	LDB	,X
	LDA	RADX
	MUL
	ASLB	;taken from simons code.... i dont understand it fyi
	ROLA	;same
	SUBA	RADX
	ADDA	PLOTX
	STA	CALCX
;cos
	LDB	CNT
	LDX	COSTB1
	ABX
	LDB	,X
	LDA	RADY
	MUL
	ASLB	;taken from simons code.... i dont understand it fyi
	ROLA	;same
	SUBA	RADY
	ADDA	PLOTY
	STA	CALCY
;ok lets try it out...??
;	LDD	CALCX	;temp code for test
	JSR	DOTS2
	LDA	CNT
	INCA
	STA	CNT
	CMPA	DIST
	BLO	LOOP
DONEE	RTS
;
;sg4 mode
DOTS2	LDD	CALCX	;save x,y
	CMPA	#63
	BLS	CHKY1
	RTS	;dot is off the screen
CHKY1	CMPB	#31
	BLS	DRAWD1
	RTS	;dots off the screen
DRAWD1	LDA	SETCOL
	BEQ	DRAWD2
	INC	DRAW
DRAWD2	CLRA
	CLRB
	STD	BIT1
	STD	BIT3
	STD	XROW
	LDX	#1024
	LDA	CALCY
	BITA	#1
	BEQ	SETRD	;odd or even y
	INC	YROW
SETRD	LSRA	;half value y
	LDB	#32
	MUL
	LEAX	D,X
	LDA	CALCX
	BITA	#1
	BEQ	SETCND	;odd or even x
	INC	XROW
SETCND	LSRA	;half value from 64 to 32
	LEAX	A,X
	LDA	,X	;ready to check
;set color correctly
	STA	ORCHR	;saved original chr code
	STA	WCOL	;lets destroy this copy
;see if color is wrong
;if so and not black then errase it all
	LDA	SETCOL
CONTD3	LDU	#COLOR0	;first color index
	LEAU	A,U
	LDA	,U	;color loaded in a
	LDB	WCOL	;load b with whats on screen currently
	ANDB	#240	;extract color from it
	STB	WCOL	;only has color now
	CMPA	WCOL	;compare the two colors
	BEQ	CONTD	;same color? ok we are good to go
;ok we need to kill it
	LDA	,U
	STA	ORCHR	;destroy original color cause its diff
CONTD	LDB	#1	;this is needed to set bit flags
	LDA	ORCHR	;load the one we are using
	ANDA	#15	;extract dots
	BITA	#8
	BNE	SETDOT1
RETD1	BITA	#4
	BNE	SETDOT2
RETD2	BITA	#2
	BNE	SETDOT3
RETD3	BITA	#1
	BNE	SETDOT4
	BRA	SETDOTS
SETDOT1	STB	BIT1
	BRA	RETD1
SETDOT2	STB	BIT2
	BRA	RETD2
SETDOT3	STB	BIT3
	BRA	RETD3
SETDOT4	STB	BIT4
;now we are here
SETDOTS	LDU	#BIT1	;working color= wcol
	LDA	YROW	
	LDB	#2
	MUL
	ADDB	XROW
	LEAU	B,U
	LDB	DRAW
	STB	,U	;set draw on or off for that bit
;reconstruct it
	LDU	#COLOR0
	LDA	SETCOL
	LEAU	A,U
	LDA	,U	;ok got color
	LDB	BIT1	;load the bits in
	LSLB
	ADDB	BIT2
	LSLB
	ADDB	BIT3
	LSLB
	ADDB	BIT4
	STB	COLTMP
	ADDA	COLTMP
	STA	,X
	RTS
ENDFUNCTION
;
;
*
;
; *************************************************************************************************************************
; * setsg4(x,y,c)
; *************************************************************************************************************************
FUNCTION	SETSG4	X1,Y1,SETCOL
REM	; setsg4(x,y,color)  display=(2 or 4) x,y,color 0-8
REM	; Does not push to stack
DEF	X1	BYTE
DEF	Y1	BYTE
DEF	SETCOL	BYTE
COLOR0	FCB	128
	FCB	128
	FCB	144
	FCB	160
	FCB	176
	FCB	192
	FCB	208
	FCB	224
	FCB	240
XROW	FCB	0
YROW	FCB	0
X1	FCB	0
Y1	FCB	0
BIT1	FCB	0
BIT2	FCB	0
BIT3	FCB	0
BIT4	FCB	0
SETCOL	FCB	0
DRAW	FCB	0
ORCHR	FCB	0
WCOL	FCB	0
COLTMP	FCB	0
ODD	FCB	0
SETSG4	CLRA
	CLRB
	STD	XROW
	STD	BIT1
	STD	BIT3
	STD	DRAW
;sg4 mode
DOTS2	LDD	X1	;save x,y
	CMPA	#63
	BLS	CHKY1
	RTS	;dot is off the screen
CHKY1	CMPB	#31
	BLS	DRAWD1
	RTS	;dots off the screen
DRAWD1	LDA	SETCOL
	BEQ	DRAWD2
	INC	DRAW
DRAWD2	CLRA
	CLRB
	STD	BIT1
	STD	BIT3
	STD	XROW
	LDX	#1024
	LDA	Y1
	BITA	#1
	BEQ	SETRD	;odd or even y
	INC	YROW
SETRD	LSRA	;half value y
	LDB	#32
	MUL
	LEAX	D,X
	LDA	X1
	BITA	#1
	BEQ	SETCND	;odd or even x
	INC	XROW
SETCND	LSRA	;half value from 64 to 32
	LEAX	A,X
	LDA	,X	;ready to check
;set color correctly
	STA	ORCHR	;saved original chr code
	STA	WCOL	;lets destroy this copy
;see if color is wrong
;if so and not black then errase it all
	LDA	SETCOL
CONTD3	LDU	#COLOR0	;first color index
	LEAU	A,U
	LDA	,U	;color loaded in a
	LDB	WCOL	;load b with whats on screen currently
	ANDB	#240	;extract color from it
	STB	WCOL	;only has color now
	CMPA	WCOL	;compare the two colors
	BEQ	CONTD	;same color? ok we are good to go
;ok we need to kill it
	LDA	,U
	STA	ORCHR	;destroy original color cause its diff
CONTD	LDB	#1	;this is needed to set bit flags
	LDA	ORCHR	;load the one we are using
	ANDA	#15	;extract dots
	BITA	#8
	BNE	SETDOT1
RETD1	BITA	#4
	BNE	SETDOT2
RETD2	BITA	#2
	BNE	SETDOT3
RETD3	BITA	#1
	BNE	SETDOT4
	BRA	SETDOTS
SETDOT1	STB	BIT1
	BRA	RETD1
SETDOT2	STB	BIT2
	BRA	RETD2
SETDOT3	STB	BIT3
	BRA	RETD3
SETDOT4	STB	BIT4
;now we are here
SETDOTS	LDU	#BIT1	;working color= wcol
	LDA	YROW	
	LDB	#2
	MUL
	ADDB	XROW
	LEAU	B,U
	LDB	DRAW
	STB	,U	;set draw on or off for that bit
;reconstruct it
	LDU	#COLOR0
	LDA	SETCOL
	LEAU	A,U
	LDA	,U	;ok got color
	LDB	BIT1	;load the bits in
	LSLB
	ADDB	BIT2
	LSLB
	ADDB	BIT3
	LSLB
	ADDB	BIT4
	STB	COLTMP
	ADDA	COLTMP
	STA	,X
	RTS
ENDFUNCTION
;
;
; ***************************************************************************************************************
; *   line2sg4(vect1,vect2,color)   sg mode
; ***************************************************************************************************************
FUNCTION	LINE2SG4	X,Y,SETCOL
REM	; line2sg4(vecx,vecy,col)  x and y need to be indexed. vector should be x,y data color 0-8
REM	; Does not push to stack
DEF	X	STRING
DEF	Y	STRING
DEF	SETCOL	BYTE
SETCOL	FCB	0
TMP	FCB	0
X1	FCB	0
Y1	FCB	0
X2	FCB	0
Y2	FCB	0
XD	FCB	0
YD	FCB	0
XC	FCB	0
YC	FCB	0
WN	FCB	0
CNT	FCB	0
COLOR0	FCB	128	;green but we can take original screen value
COLOR1	FCB	128	;green
COLOR2	FCB	144	;yellow
COLOR3	FCB	160	;blue
COLOR4	FCB	176	;red
COLOR5	FCB	192	;white
COLOR6	FCB	208	;cyan
COLOR7	FCB	224	;magenta
COLOR8	FCB	240	;orange
SETX	FCB	0
SETY	FCB	0
WCOL	FCB	0	;working with
XROW	FCB	0
YROW	FCB	0
ORCHR	FCB	0
DRAW	FCB	0
ODD	FCB	0	;is it setting or erasing
BIT1	FCB	0
BIT2	FCB	0
BIT3	FCB	0
BIT4	FCB	0
COLTMP	FCB	0
LINE2SG4	LDD	,X	;deals with registers for load
	STD	X1
	LDD	,Y
	STD	X2
	CLR	DRAW
	LDA	SETCOL
	CMPA	#0
	BEQ	CONTD2	;this is a dot off command
	INC	DRAW	
CONTD2	LDA	X1	;ok no swapping just get distances
	CMPA	X2
	BLS	LINS1	;if x1 is lower
	SUBA	X2	;its greater so sub x2
	STA	XD	;save x distance
	BRA	LINS2
LINS1	LDA	X2
	SUBA	X1
	STA	XD
;
LINS2	LDA	Y1	;ok now lets look at y
	CMPA	Y2
	BLS	LINS3	;y1 is lower?
	SUBA	Y2
	STA	YD	;save y distance
	BRA	LINS4
LINS3	LDA	Y2
	SUBA	Y1
	STA	YD
;
;which is greater?
LINS4	LDA	YD
	CMPA	XD
	BLO	LINS5	;y is lower then goto lins5
	STA	WN	;x is lower so save y as whole fraction
	BRA	LINS6	;done
LINS5	LDA	XD	;nope y is lower so save x as whole fraction
	STA	WN	;stored it
; ok now the main loop
LINS6	CLRA
	STA	XC	;x counter
	STA	YC	;y counter
	LDA	WN
	STA	CNT	;set counter
	INC	CNT
;ok check what display
;
;main loop for sg 4
LINE1	LDD	X1	;main loop
	STD	SETX
	JSR	DOT2	;jump to draw dot
	LDA	XC
	ADDA	XD	;add distance to xc counter
	CMPA	WN	;has it gone over or same as our whole fraction?
	BHS	ADV1	;it has on x.... lets advance it
	STA	XC	;nope keep counting 
	BRA	CHK1	;lets check y now
;
ADV1	SUBA	WN	;advance the x counter....subtract the whole fraction
	STA	XC	;store remainder to play with next loop
	LDA	X1
	CMPA	X2
	BHI	ADVX1
	INC	X1	;increase y plot or dec?
	BRA	CHK1
ADVX1	DEC	X1
CHK1	LDA	YC	;now the y axis.... loader up
	ADDA	YD	;add its distance
	CMPA	WN	;has it gone over or the same as our whole fraction
	BHS	ADVY1	;it has on y.... lets advance it
	STA	YC	;nope... keep counting
	BRA	CHKX1	;done
;advance it
ADVY1	SUBA	WN	;subtract the whole number from y counter
	STA	YC	;store the remainder for next loop
	LDA	Y1
	CMPA	Y2
	BHI	ADY1
	INC	Y1	;increase y plot or dec?
	BRA	CHKX1
ADY1	DEC	Y1
;done?
CHKX1	DEC	CNT	;check the counter
	BNE	LINE1	;nope keep plotting the line
	RTS	;we are done
;
DOT2	CLRA
	CLRB
	STD	BIT1
	STD	BIT3
	STD	XROW
	LDX	#1024
	LDA	SETY
	BITA	#1
	BEQ	SETRD	;odd or even y
	INC	YROW
SETRD	LSRA	;half value y
	LDB	#32
	MUL
	LEAX	D,X
	LDA	SETX
	BITA	#1
	BEQ	SETCND	;odd or even x
	INC	XROW
SETCND	LSRA	;half value from 64 to 32
	LEAX	A,X
	LDA	,X	;ready to check
;set color correctly
	STA	ORCHR	;saved original chr code
	STA	WCOL	;lets destroy this copy
;see if color is wrong
;if so and not black then errase it all
	LDA	SETCOL
CONTD3	LDU	#COLOR0	;first color index
	LEAU	A,U
	LDA	,U	;color loaded in a
	LDB	WCOL	;load b with whats on screen currently
	ANDB	#240	;extract color from it
	STB	WCOL	;only has color now
	CMPA	WCOL	;compare the two colors
	BEQ	CONTD	;same color? ok we are good to go
;ok we need to kill it
	LDA	,U
	STA	ORCHR	;destroy original color cause its diff
CONTD	LDB	#1	;this is needed to set bit flags
	LDA	ORCHR	;load the one we are using
	ANDA	#15	;extract dots
	BITA	#8
	BNE	SETDOT1
RETD1	BITA	#4
	BNE	SETDOT2
RETD2	BITA	#2
	BNE	SETDOT3
RETD3	BITA	#1
	BNE	SETDOT4
	BRA	SETDOTS
SETDOT1	STB	BIT1
	BRA	RETD1
SETDOT2	STB	BIT2
	BRA	RETD2
SETDOT3	STB	BIT3
	BRA	RETD3
SETDOT4	STB	BIT4
;now we are here
SETDOTS	LDU	#BIT1	;working color= wcol
	LDA	YROW	
	LDB	#2
	MUL
	ADDB	XROW
	LEAU	B,U
	LDB	DRAW
	STB	,U	;set draw on or off for that bit
;reconstruct it
	LDU	#COLOR0
	LDA	SETCOL
	LEAU	A,U
	LDA	,U	;ok got color
	LDB	BIT1	;load the bits in
	LSLB
	ADDB	BIT2
	LSLB
	ADDB	BIT3
	LSLB
	ADDB	BIT4
	STB	COLTMP
	ADDA	COLTMP
	STA	,X
	RTS
ENDFUNCTION
;
;
; ***************************************************************************************************************
; *   linesg4(x1,y1,x2,y2,color)   sg mode
; ***************************************************************************************************************
FUNCTION	LINESG4	X1,Y1,X2,Y2,SETCOL
REM	; linesg4(x1,y1,x2,y2,col)  x1,x2 range 0-63 y1,y2 range 0-31 color 0-8.  please note that if you go out of range it may crash.
REM	; Does not push to stack.  (Semi Graphics 4 Mode)
DEF	X1	BYTE
DEF	Y1	BYTE
DEF	X2	BYTE
DEF	Y2	BYTE
DEF	SETCOL	BYTE
SETCOL	FCB	0
TMP	FCB	0
X1	FCB	0
Y1	FCB	0
X2	FCB	0
Y2	FCB	0
XD	FCB	0
YD	FCB	0
XC	FCB	0
YC	FCB	0
WN	FCB	0
CNT	FCB	0
COLOR0	FCB	128	;green but we can take original screen value
COLOR1	FCB	128	;green
COLOR2	FCB	144	;yellow
COLOR3	FCB	160	;blue
COLOR4	FCB	176	;red
COLOR5	FCB	192	;white
COLOR6	FCB	208	;cyan
COLOR7	FCB	224	;magenta
COLOR8	FCB	240	;orange
SETX	FCB	0
SETY	FCB	0
WCOL	FCB	0	;working with
XROW	FCB	0
YROW	FCB	0
ORCHR	FCB	0
DRAW	FCB	0
ODD	FCB	0	;is it setting or erasing
BIT1	FCB	0
BIT2	FCB	0
BIT3	FCB	0
BIT4	FCB	0
COLTMP	FCB	0
LINESG4	CLR	DRAW
	LDA	SETCOL
	CMPA	#0
	BEQ	CONTD2	;this is a dot off command
	INC	DRAW	
CONTD2	CMPA	#8
	BLO	CONTD7
	LDA	#8
	STA	SETCOL
CONTD7	LDA	X1	;ok no swapping just get distances
	CMPA	X2
	BLS	LINS1	;if x1 is lower
	SUBA	X2	;its greater so sub x2
	STA	XD	;save x distance
	BRA	LINS2
LINS1	LDA	X2
	SUBA	X1
	STA	XD
;
LINS2	LDA	Y1	;ok now lets look at y
	CMPA	Y2
	BLS	LINS3	;y1 is lower?
	SUBA	Y2
	STA	YD	;save y distance
	BRA	LINS4
LINS3	LDA	Y2
	SUBA	Y1
	STA	YD
;
;which is greater?
LINS4	LDA	YD
	CMPA	XD
	BLO	LINS5	;y is lower then goto lins5
	STA	WN	;x is lower so save y as whole fraction
	BRA	LINS6	;done
LINS5	LDA	XD	;nope y is lower so save x as whole fraction
	STA	WN	;stored it
; ok now the main loop
LINS6	CLRA
	STA	XC	;x counter
	STA	YC	;y counter
	LDA	WN
	STA	CNT	;set counter
	INC	CNT
;ok check what display
;main loop for sg 2
LINE1	JSR	DOT2
;	LDD	X1	;main loop
;	STD	SETX
;	JSR	DOT2	;jump to draw dot
	LDA	XC
	ADDA	XD	;add distance to xc counter
	CMPA	WN	;has it gone over or same as our whole fraction?
	BHS	ADV1	;it has on x.... lets advance it
	STA	XC	;nope keep counting 
	BRA	CHK1	;lets check y now
;
ADV1	SUBA	WN	;advance the x counter....subtract the whole fraction
	STA	XC	;store remainder to play with next loop
	LDA	X1
	CMPA	X2
	BHI	ADVX1
	INC	X1	;increase y plot or dec?
	BRA	CHK1
ADVX1	DEC	X1
CHK1	LDA	YC	;now the y axis.... loader up
	ADDA	YD	;add its distance
	CMPA	WN	;has it gone over or the same as our whole fraction
	BHS	ADVY1	;it has on y.... lets advance it
	STA	YC	;nope... keep counting
	BRA	CHKX1	;done
;advance it
ADVY1	SUBA	WN	;subtract the whole number from y counter
	STA	YC	;store the remainder for next loop
	LDA	Y1
	CMPA	Y2
	BHI	ADY1
	INC	Y1	;increase y plot or dec?
	BRA	CHKX1
ADY1	DEC	Y1
;done?
CHKX1	DEC	CNT	;check the counter
	BNE	LINE1	;nope keep plotting the line
	RTS	;we are done
; no safety checks
DOT2	CLRA
	CLRB
	STD	BIT1
	STD	BIT3
	STD	XROW
CHDTL1	LDX	#1024
	LDA	Y1
	BITA	#1
	BEQ	SETRD	;odd or even y
	INC	YROW
SETRD	LSRA	;half value y
	LDB	#32
	MUL
	LEAX	D,X
	LDA	X1
	BITA	#1
	BEQ	SETCND	;odd or even x
	INC	XROW
SETCND	LSRA	;half value from 64 to 32
	LEAX	A,X
	LDA	,X	;ready to check
;set color correctly
	STA	ORCHR	;saved original chr code
	STA	WCOL	;lets destroy this copy
;see if color is wrong
;if so and not black then errase it all
	LDA	SETCOL
CONTD3	LDU	#COLOR0	;first color index
	LEAU	A,U
	LDA	,U	;color loaded in a
	LDB	WCOL	;load b with whats on screen currently
	ANDB	#240	;extract color from it
	STB	WCOL	;only has color now
	CMPA	WCOL	;compare the two colors
	BEQ	CONTD	;same color? ok we are good to go
;ok we need to kill it
	LDA	,U
	STA	ORCHR	;destroy original color cause its diff
CONTD	LDB	#1	;this is needed to set bit flags
	LDA	ORCHR	;load the one we are using
	ANDA	#15	;extract dots
	BITA	#8
	BNE	SETDOT1
RETD1	BITA	#4
	BNE	SETDOT2
RETD2	BITA	#2
	BNE	SETDOT3
RETD3	BITA	#1
	BNE	SETDOT4
	BRA	SETDOTS
SETDOT1	STB	BIT1
	BRA	RETD1
SETDOT2	STB	BIT2
	BRA	RETD2
SETDOT3	STB	BIT3
	BRA	RETD3
SETDOT4	STB	BIT4
;now we are here
SETDOTS	LDU	#BIT1	;working color= wcol
	LDA	YROW	
	LDB	#2
	MUL
	ADDB	XROW
	LEAU	B,U
	LDB	DRAW
	STB	,U	;set draw on or off for that bit
;reconstruct it
	LDU	#COLOR0
	LDA	SETCOL
	LEAU	A,U
	LDA	,U	;ok got color
	LDB	BIT1	;load the bits in
	LSLB
	ADDB	BIT2
	LSLB
	ADDB	BIT3
	LSLB
	ADDB	BIT4
	STB	COLTMP
	ADDA	COLTMP
	STA	,X
	RTS
ENDFUNCTION
;
;**************************************************************************************
;* clssg4(color) 0-8 SEMI GRAPHICS DEFAULT MODE
;**************************************************************************************
FUNCTION	CLSSG4	CC
REM	; CLSsg4(n)  This is a number from 0 to 8.
REM	; Does not push to stack and uses A,X,Y
DEF	CC	BYTE
CC	FCB	0	;cc store
C0	FCB	128	;black
	FCB	143	;green
	FCB	159	;yellow
	FCB	175	;blue
	FCB	191	;red
	FCB	207	;white
	FCB	223	;cyan
	FCB	239	;megenta
	FCB	255	;orange
CLSSG4	LDX	#1024
	LDA	CC
	CMPA	#8
	BLS	LOP2
	LDA	#8
	STA	CC
LOP2	LDA	CC
	LDY	#C0
	LDA	CC
	LEAY	A,Y
	LDA	,Y	;color loaded
	LDB	,Y
LP2	STD	,X++
	CMPX	#1536
	BLO	LP2
	RTS
ENDFUNCTION
;
;
;**************************************************************************************
;* printsg4(caps on,pos,string) 
;**************************************************************************************
FUNCTION	PRINTSG4	CAP,CC,X
REM	;PRINTsg4(c,pos,string)c=0 or 1 for starting in caps mode. pos=0-511 for screen position.
REM	;Does not push to stack and uses A,B,X,Y. uses display mode 2
DEF	CAP	BYTE	;start in caps mode or not?
DEF	CC	WORD	;its 2 bytes print position
DEF	X	STRING	;populate x register with string at x
CAP	FCB	0	;caps flag
CC	FCB	0,0	;dword
MULTI	FCB	0
ROWY	FCB	0
PRINTSG4	LDD	CC	;check if out of bounds
	CMPD	#511
	BLS	LP0
	LDD	#511
	STD	CC
LP0	LDD	#1024	; x=has string  y is screen
	ADDD	CC
	TFR	D,Y	;y is set
	LDB	CAP	;load b with caps flag
LP1	LDA	,X+
;process this ascii code
	CMPA	#97
	BLO	LP2
	CLRB
	STB	CAP
;assume lowercase
	SUBA	#96
LP2	CMPA	#65
	BLO	LP3
	CMPA	#90
	BHI	LP3
	LDB	#1
	STB	CAP
LP3	CMPA	#32
	BNE	LP4
	CMPB	#1	;is cap on
	BNE	LP4
	ADDA	#64	;fix green space
;lets look at numbers
LP4	CMPA	#33
	BLO	LP5
	CMPA	#63
	BHI	LP5
;its a number
	CMPB	#1
	BNE	LP5
;change number to cap
	ADDA	#64
LP5	STA	,Y+
	CMPY	#1536
	BHS	LP6
	LDA	,X
	CMPA	#0
	BNE	LP1
LP6	RTS	;return
ENDFUNCTION
;
;
