SPINDEMO			PSHS	A,B,X,Y,U

					LBSR	INSTALL_LINEDDA_IN_SUBCPU
					LBSR	INSTALL_CLEAR_BITPLANE_IN_SUBCPU
					LBSR	CLEAR_SCREEN

					LDX		#0
					LBSR	SUBCPU_SET_VRAM_OFFSET

					LBSR	HIDE_BY_PALETTE
					LBSR	SPINDEMO_DRAW_CUBE
					LBSR	RESET_PALETTE
					LDA		#14
					BSR		SPINDEMO_SPINONLY

					LBSR	HIDE_BY_PALETTE
					LBSR	SPINDEMO_DRAW_GEAR
					LBSR	RESET_PALETTE
					LDA		#14
					BSR		SPINDEMO_SPINONLY

					LBSR	HIDE_BY_PALETTE
					LBSR	SPINDEMO_DRAW_BLOWUP
					LBSR	RESET_PALETTE
					LDA		#14
					BSR		SPINDEMO_SPINONLY

					;LDA		#24
					;BSR		SPINDEMO_SPIN_PLUS_SWING


					PULS 	A,B,X,Y,U,PC



SPINDEMO_SPINONLY
					LDX		#0
					LBSR	SUBCPU_SET_VRAM_OFFSET
					LBSR	SPINDEMO_WAIT

					LDX		#$60
					LBSR	SUBCPU_SET_VRAM_OFFSET
					LBSR	SPINDEMO_WAIT

					LDX		#$20
					LBSR	SUBCPU_SET_VRAM_OFFSET
					LBSR	SPINDEMO_WAIT

					LDX		#$80
					LBSR	SUBCPU_SET_VRAM_OFFSET
					LBSR	SPINDEMO_WAIT

					LDX		#$40
					LBSR	SUBCPU_SET_VRAM_OFFSET
					LBSR	SPINDEMO_WAIT

					LDB		$FD04
					BITB	#2
					BEQ		SPINDEMO_SPINONLY_EXIT

					DECA
					BNE		SPINDEMO_SPINONLY

SPINDEMO_SPINONLY_EXIT
					RTS



SPINDEMO_SPIN_PLUS_SWING

SPINDEMO_SPIN_PLUS_SWING_LOOP
					LDB		$FD04
					BITB	#2
					BEQ		SPINDEMO_SPIN_PLUS_SWING_EXIT

					PSHS	A

					LDX		#0
					BSR		SPINDEMO_SWING_CALCOFFSET
					LEAX	D,X
					BSR		SPINDEMO_SWING_INCREMENT
					LBSR	SUBCPU_SET_VRAM_OFFSET
					BSR		SPINDEMO_WAIT

					LDX		#$60
					BSR		SPINDEMO_SWING_CALCOFFSET
					LEAX	D,X
					BSR		SPINDEMO_SWING_INCREMENT
					LBSR	SUBCPU_SET_VRAM_OFFSET
					BSR		SPINDEMO_WAIT

					LDX		#$20
					BSR		SPINDEMO_SWING_CALCOFFSET
					LEAX	D,X
					BSR		SPINDEMO_SWING_INCREMENT
					LBSR	SUBCPU_SET_VRAM_OFFSET
					BSR		SPINDEMO_WAIT

					LDX		#$80
					BSR		SPINDEMO_SWING_CALCOFFSET
					LEAX	D,X
					BSR		SPINDEMO_SWING_INCREMENT
					LBSR	SUBCPU_SET_VRAM_OFFSET
					BSR		SPINDEMO_WAIT

					LDX		#$40
					BSR		SPINDEMO_SWING_CALCOFFSET
					LEAX	D,X
					BSR		SPINDEMO_SWING_INCREMENT
					LBSR	SUBCPU_SET_VRAM_OFFSET
					BSR		SPINDEMO_WAIT

					PULS	A
					DECA
					BNE		SPINDEMO_SPIN_PLUS_SWING_LOOP

SPINDEMO_SPIN_PLUS_SWING_EXIT
					RTS

SPINDEMO_SWING_CALCOFFSET
					LDD		#32
					STD		COS_MULTIPLIER,PCR
					LDA		SPINDEMO_SPIN_PLUS_SWING_ANGLE,PCR
					STA		COS_ANGLE,PCR
					LBSR	CALC_COS
					LDD		COS_MULTIPLIER,PCR
					NEGB
					ADDB	#32
					LDA		#$A0
					MUL
					RTS

SPINDEMO_SWING_INCREMENT
					LDA		SPINDEMO_SPIN_PLUS_SWING_ANGLE,PCR
					ADDA	#14
					STA		SPINDEMO_SPIN_PLUS_SWING_ANGLE,PCR
					RTS

SPINDEMO_SPIN_PLUS_SWING_ANGLE	FDB	0


SPINDEMO_WAIT		LDX		#$4000
SPINDEMO_WAIT_LOOP	LEAX	-1,X
					BNE		SPINDEMO_WAIT_LOOP
					RTS



SPINDEMO_DRAW_CUBE
					LDX		#64
					STX		TO_SCREEN_PERS_CX,PCR
					LDX		#100
					STX		TO_SCREEN_PERS_CY,PCR
					LDA		#6
					STA		TO_SCREEN_PERS_XSHIFT,PCR
					LDA		#5
					STA		TO_SCREEN_PERS_YSHIFT,PCR


					LDX		#0
					STX		TO_SCREEN_WX0,PCR
					STX		TO_SCREEN_WY0
					LDX		#639
					STX		TO_SCREEN_WX1,PCR
					LDX		#199
					STX		TO_SCREEN_WY1,PCR

					LDX		#10
					STX		TO_SCREEN_NEARZ,PCR


					LDX		#0
					STX		TRANS3D_OBJX,PCR
					STX		TRANS3D_OBJY,PCR
					STX		TRANS3D_OBJZ,PCR
					STX		TRANS3D_VIEWX,PCR
					STX		TRANS3D_VIEWY,PCR
					STX		TRANS3D_VIEWZ,PCR

					CLR		TO_SCREEN_TRANS3D_OBJH,PCR
					CLR		TO_SCREEN_TRANS3D_OBJP,PCR
					CLR		TO_SCREEN_TRANS3D_OBJB,PCR

					LDX		#0
					STX		TO_SCREEN_TRANS3D_VIEWX,PCR
					STX		TO_SCREEN_TRANS3D_VIEWY,PCR
					CLR		TO_SCREEN_TRANS3D_VIEWH,PCR
					CLR		TO_SCREEN_TRANS3D_VIEWP,PCR
					CLR		TO_SCREEN_TRANS3D_VIEWB,PCR
					LDX		#300
					STX		TO_SCREEN_TRANS3D_VIEWZ,PCR

					LDX		#$8000
					STX		CUBE_DEMO_VRAMADDR,PCR
					LBSR	RENDER_CUBE



					LDA		#13
					STA		TO_SCREEN_TRANS3D_OBJH,PCR
					LDX		#192
					STX		TO_SCREEN_PERS_CX,PCR

					LBSR	RENDER_CUBE


					LDA		#25
					STA		TO_SCREEN_TRANS3D_OBJH,PCR
					LDX		#320
					STX		TO_SCREEN_PERS_CX,PCR

					LBSR	RENDER_CUBE


					LDA		#38
					STA		TO_SCREEN_TRANS3D_OBJH,PCR
					LDX		#448
					STX		TO_SCREEN_PERS_CX,PCR

					LBSR	RENDER_CUBE


					LDA		#51
					STA		TO_SCREEN_TRANS3D_OBJH,PCR
					LDX		#576
					STX		TO_SCREEN_PERS_CX,PCR

					LBSR	RENDER_CUBE



					RTS


SPINDEMO_DRAW_GEAR
					LDX		#64
					STX		RENDER_GEAR_CX,PCR
					LDX		#40
					STX		RENDER_GEAR_CY,PCR
					LDX		#40
					STX		RENDER_GEAR_MINRAD,PCR
					LDX		#44
					STX		RENDER_GEAR_MAXRAD,PCR
					LDD		#$0A06
					STD		RENDER_GEAR_LOWSTEP,PCR
					CLR		RENDER_GEAR_ANGLE0,PCR
					LDX		#20
					STX		RENDER_GEAR_INSIDECIRCLE_RAD,PCR

					LBSR	RENDER_GEAR


					LDA		#13
					STA		RENDER_GEAR_ANGLE0,PCR
					LDX		#192
					STX		RENDER_GEAR_CX,PCR

					LBSR	RENDER_GEAR


					LDA		#25
					STA		RENDER_GEAR_ANGLE0,PCR
					LDX		#320
					STX		RENDER_GEAR_CX,PCR

					LBSR	RENDER_GEAR


					LDA		#38
					STA		RENDER_GEAR_ANGLE0,PCR
					LDX		#448
					STX		RENDER_GEAR_CX,PCR

					LBSR	RENDER_GEAR


					LDA		#51
					STA		RENDER_GEAR_ANGLE0,PCR
					LDX		#576
					STX		RENDER_GEAR_CX,PCR

					LBSR	RENDER_GEAR


					RTS




SPINDEMO_DRAW_BLOWUP
;DRAW_CIRCLE_SUBCPU_CX	FDB		0
;DRAW_CIRCLE_SUBCPU_CY	FDB		0
;DRAW_CIRCLE_SUBCPU_R	FDB		0
;DRAW_CIRCLE_BUFFADDR	FDB		LINEDDA_IN_SUBCPU_BUFFER
;DRAW_CIRCLE_COLOR		FCB		0	; For DRAW_CIRCLE_COLOR_SUBCPU

					LDX		#64
					STX		DRAW_CIRCLE_SUBCPU_CX,PCR
					LDX		#160
					STX		DRAW_CIRCLE_SUBCPU_CY,PCR
					LDA		#1
					STA		DRAW_CIRCLE_COLOR,PCR

					LDX		#10
					STX		DRAW_CIRCLE_SUBCPU_R,PCR
					LBSR	DRAW_CIRCLE_COLOR_SUBCPU

					LDX		#192
					STX		DRAW_CIRCLE_SUBCPU_CX,PCR
					LDX		#20
					STX		DRAW_CIRCLE_SUBCPU_R,PCR
					INC		DRAW_CIRCLE_COLOR,PCR
					LBSR	DRAW_CIRCLE_COLOR_SUBCPU

					LDX		#320
					STX		DRAW_CIRCLE_SUBCPU_CX,PCR
					LDX		#30
					STX		DRAW_CIRCLE_SUBCPU_R,PCR
					INC		DRAW_CIRCLE_COLOR,PCR
					LBSR	DRAW_CIRCLE_COLOR_SUBCPU

					LDX		#448
					STX		DRAW_CIRCLE_SUBCPU_CX,PCR
					LDX		#40
					STX		DRAW_CIRCLE_SUBCPU_R,PCR
					INC		DRAW_CIRCLE_COLOR,PCR
					LBSR	DRAW_CIRCLE_COLOR_SUBCPU

					LDX		#576
					STX		DRAW_CIRCLE_SUBCPU_CX,PCR
					LDX		#50
					STX		DRAW_CIRCLE_SUBCPU_R,PCR
					INC		DRAW_CIRCLE_COLOR,PCR
					LBSR	DRAW_CIRCLE_COLOR_SUBCPU

					RTS



SPINDEMO_DRAW_RIPPLE
					LDX		#64
					STX		RIPPLE_CX,PCR
					LDX		#160
					STX		RIPPLE_CY,PCR
					CLR		RIPPLE_C0,PCR
					LDA		#5
					STA		RIPPLE_COUNT,PCR
					LDX		#$0A0A
					STX		RIPPLE_R0,PCR

					LBSR	RENDER_RIPPLE



					INC		RIPPLE_C0,PCR
					LDX		#192
					STX		RIPPLE_CX,PCR

					LBSR	RENDER_RIPPLE


					INC		RIPPLE_C0,PCR
					LDX		#320
					STX		RIPPLE_CX,PCR

					LBSR	RENDER_RIPPLE


					INC		RIPPLE_C0,PCR
					LDX		#448
					STX		RIPPLE_CX,PCR

					LBSR	RENDER_RIPPLE


					INC		RIPPLE_C0,PCR
					LDX		#576
					STX		RIPPLE_CX,PCR

					LBSR	RENDER_RIPPLE


					RTS


