~rabbits/catclock

8c08aa8a35da0a46156823cc2dac5f85060abd86 — Devine Lu Linvega 1 year, 2 months ago 174fc6f
Faster line drawing
1 files changed, 32 insertions(+), 24 deletions(-)

M src/catclock.tal
M src/catclock.tal => src/catclock.tal +32 -24
@@ 11,7 11,7 @@
@center
	&x $2 &y $2
@line
	&x $2 &y $2 &dx $2 &dy $2 &e1 $2
	&x2 $2 &y2 $2
@needles
	&hx $2 &hy $2
	&mx $2 &my $2


@@ 72,7 72,7 @@ BRK
	( name ) "Catclock 0a
	( details ) "Tic 20 "Tac 20 "Cat 20 "Clock 0a
	( author ) "By 20 "Hundred 20 "Rabbits 0a
	( date ) "Jan 20 "8, 20 "2023 00
	( date ) "Mar 20 "8, 20 "2023 00
	02
		( icon ) 83 =appicon
		( mask ) 41 1705


@@ 122,7 122,6 @@ JMP2r
	STHr #07 GTH ?&tail-reverse

	( tail )

	#0c MUL #00 SWP #30 SFT2 ;spritesheet/tail ADD2 .Screen/addr DEO2
	#0c00
	&loop-tail


@@ 141,7 140,7 @@ JMP2r
	#0c00
	&loop-tail-reverse
		#00 OVRk
			( x ) #03 AND [ #04 SWP SUB ] #30 SFT2 .center/x LDZ2 ADD2 #0018 SUB2 .Screen/x DEO2
			( x ) #03 AND #04 SWP SUB #30 SFT2 .center/x LDZ2 ADD2 #0018 SUB2 .Screen/x DEO2
			( y ) #32 SFT2 .center/y LDZ2 ADD2 #0015 ADD2 .Screen/y DEO2
		[ LIT2 14 -Screen/sprite ] DEO
		INC GTHk ?&loop-tail-reverse


@@ 160,9 159,9 @@ JMP2r
		OVR2 OVR2 .needles/mx LDZ2 .needles/my LDZ2 #00 draw-line
		OVR2 OVR2 .needles/hx LDZ2 .needles/hy LDZ2 #00 draw-line
	( middle )
	#0001 SUB2 .Screen/y DEO2
	#0001 SUB2 .Screen/x DEO2
	;middle-icn .Screen/addr DEO2
		#0001 SUB2 .Screen/y DEO2
		#0001 SUB2 .Screen/x DEO2
	[ LIT2 0a -Screen/sprite ] DEO

JMP2r


@@ 172,35 171,44 @@ JMP2r
	[ LIT2 76 -Screen/auto ] DEO
	.center/x LDZ2 #0020 SUB2 .Screen/x DEO2
	.Screen/addr DEO2
	#00
	#00 SWP SUB
	&ver
		[ LIT2 04 -Screen/sprite ] DEO
		INC GTHk ?&ver
	POP2
		INC DUP ?&ver
	POP

JMP2r

@draw-line ( x1* y1* x2* y2* color -- )

	( load ) ,&color STR ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2
	,&x LDR2 .line/x LDZ2 SUB2 abs2 .line/dx STZ2
	#0000 ,&y LDR2 .line/y LDZ2 SUB2 abs2 SUB2 .line/dy STZ2
	#ffff #00 .line/x LDZ2 ,&x LDR2 lts2 DUP2 ADD2 ADD2 ,&sx STR2
	#ffff #00 .line/y LDZ2 ,&y LDR2 lts2 DUP2 ADD2 ADD2 ,&sy STR2
	.line/dx LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
	( load )
	,&color STR
	,&y STR2
	,&x STR2
	.line/y2 STZ2
	.line/x2 STZ2

	,&x LDR2 .line/x2 LDZ2 SUB2 abs2 ,&dx STR2
	#0000 ,&y LDR2 .line/y2 LDZ2 SUB2 abs2 SUB2 ,&dy STR2

	#ffff #00 .line/x2 LDZ2 ,&x LDR2 lts2 DUP2 ADD2 ADD2 ,&sx STR2
	#ffff #00 .line/y2 LDZ2 ,&y LDR2 lts2 DUP2 ADD2 ADD2 ,&sy STR2

	[ LIT2 &dx $2 ] [ LIT2 &dy $2 ] ADD2 ,&e1 STR2

	&loop
		.line/x LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
		.line/y LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
		.line/x2 LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
		.line/y2 LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
			[ LIT2 &color $1 -Screen/pixel ] DEO
			AND ?&end
		.line/e1 LDZ2 DUP2 ADD2 DUP2
		.line/dy LDZ2 lts2 ?&skipy
			.line/e1 LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
			.line/x LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x STZ2
		[ LIT2 &e1 $2 ] DUP2 ADD2 DUP2
		,&dy LDR2 lts2 ?&skipy
			,&e1 LDR2 ,&dy LDR2 ADD2 ,&e1 STR2
			.line/x2 LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x2 STZ2
		&skipy
		.line/dx LDZ2 gts2 ?&skipx
			.line/e1 LDZ2 .line/dx LDZ2 ADD2 .line/e1 STZ2
			.line/y LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y STZ2
		,&dx LDR2 gts2 ?&skipx
			,&e1 LDR2 ,&dx LDR2 ADD2 ,&e1 STR2
			.line/y2 LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y2 STZ2
		&skipx
		!&loop
	&end