commit 0c587b9e0e0291deac20e4ff6676b2ce24ea0f39
parent c4f74830273aacb20d4a8e1dff26185a03c10827
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun, 27 Mar 2022 09:43:24 -0700
(mouse.tal) Optimized
Diffstat:
2 files changed, 52 insertions(+), 99 deletions(-)
diff --git a/projects/examples/devices/mouse.tal b/projects/examples/devices/mouse.tal
@@ -1,56 +1,51 @@
-( dev/mouse )
+( Mouse )
 
-%RTN   { JMP2r }
-%ABS2  { DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 }
-%LTS2  { #8000 ADD2 SWP2 #8000 ADD2 GTH2 }
-%GTS2  { #8000 ADD2 SWP2 #8000 ADD2 LTH2 }
-%2** { #10 SFT2 }
-
-( devices )
-
-|00 @System     &vector $2 &wst      $1 &rst    $1 &pad    $4 &r      $2 &g      $2 &b      $2 &debug  $1 &halt $1
-|20 @Screen     &vector $2 &width    $2 &height $2 &pad    $2 &x      $2 &y      $2 &addr   $2 &pixel  $1 &sprite $1
-|90 @Mouse      &vector $2 &x        $2 &y      $2 &state  $1 &pad    $3 &modx   $2 &mody   $2
+|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
+|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
+|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &modx $2 &mody $2
 
 |0000
 
-@color $1
-@line    
-	&x0 $2 &y0 $2 &x     $2 &y     $2 &sx    $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2
-@pointer 
-	&x  $2 &y  $2 &lastx $2 &lasty $2 &state $1
-
-( program )
+@line
+	&x $2 &y $2 &dx $2 &dy $2 &e1 $2
+@pointer
+	&x $2 &y $2 &lastx $2 &lasty $2 &state $1
 
 |0100 ( -> )
 
-	( theme ) 
-	#f030 .System/r DEO2 
-	#f04f .System/g DEO2 
-	#f050 .System/b DEO2
+	( theme )
+	#a0f0 .System/r DEO2
+	#40ff .System/g DEO2
+	#60ff .System/b DEO2
 
-	( vectors ) 
+	( vectors )
 	;on-mouse .Mouse/vector DEO2
 
 BRK
 
 @on-mouse ( -> )
 
-	;draw-cursor JSR2
-
+	;pointer-icn .Screen/addr DEO2
+	( clear last cursor )
+	.pointer/x LDZ2 .Screen/x DEO2
+	.pointer/y LDZ2 .Screen/y DEO2
+	#40 .Screen/sprite DEO
+	( draw new cursor )
+	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
+	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
+	#43 .Mouse/state DEI #00 NEQ DUP ADD SUB .Screen/sprite DEO
 	( on down )
 	.Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU #0101 EQU2 ,on-mouse-down JCN
-
 	( on drag )
 	.Mouse/state DEI ,on-mouse-drag JCN
 	.Mouse/state DEI .pointer/state STZ
 
-BRK 
+BRK
 
 @on-mouse-down ( -> )
 
 	( record start position )
-	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .pointer/lastx STZ2 
+	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .pointer/lastx STZ2
 	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .pointer/lasty STZ2
 	.Mouse/state DEI .pointer/state STZ
 
@@ -59,62 +54,50 @@ BRK
 @on-mouse-drag ( -> )
 	
 	( draw line )
-	.pointer/lastx LDZ2 
-	.pointer/lasty LDZ2 
-	.pointer/x LDZ2 
-	.pointer/y LDZ2 
-	#01 [ .Mouse/state DEI #10 EQU DUP ADD ADD ] 
+	.pointer/lastx LDZ2
+	.pointer/lasty LDZ2
+	.pointer/x LDZ2
+	.pointer/y LDZ2
+	.Mouse/state DEI INC
 	;draw-line JSR2
 
 	( record last position )
-	.Mouse/x DEI2 .pointer/lastx STZ2 
+	.Mouse/x DEI2 .pointer/lastx STZ2
 	.Mouse/y DEI2 .pointer/lasty STZ2
 	.Mouse/state DEI .pointer/state STZ
 
 BRK
 
-@draw-cursor ( -- )
-	
-	;pointer-icn .Screen/addr DEO2
-
-	( clear last cursor )
-	.pointer/x LDZ2 .Screen/x DEO2
-	.pointer/y LDZ2 .Screen/y DEO2
-	#40 .Screen/sprite DEO
+@draw-line ( x1* y1* x2* y2* color -- )
 
-	( draw new cursor )
-	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 
-	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
-	#43 .Mouse/state DEI #00 NEQ DUP ADD SUB .Screen/sprite DEO
-
-RTN
-
-@draw-line ( x1 y1 x2 y2 color -- )
-	
-	( load ) .color STZ .line/y0 STZ2 .line/x0 STZ2 .line/y STZ2 .line/x STZ2
-	.line/x0 LDZ2 .line/x LDZ2 SUB2 ABS2 .line/dx STZ2
-	.line/y0 LDZ2 .line/y LDZ2 SUB2 ABS2 #0000 SWP2 SUB2 .line/dy STZ2
-	#ffff #00 .line/x LDZ2 .line/x0 LDZ2 LTS2 2** ADD2 .line/sx STZ2
-	#ffff #00 .line/y LDZ2 .line/y0 LDZ2 LTS2 2** ADD2 .line/sy STZ2
+	( load ) STH ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2
+	,&x LDR2 .line/x LDZ2 SUB2 ;abs2 JSR2 .line/dx STZ2
+	#0000 ,&y LDR2 .line/y LDZ2 SUB2 ;abs2 JSR2 SUB2 .line/dy STZ2
+	#ffff #00 .line/x LDZ2 ,&x LDR2 ;lts2 JSR2 #10 SFT2 ADD2 ,&sx STR2
+	#ffff #00 .line/y LDZ2 ,&y LDR2 ;lts2 JSR2 #10 SFT2 ADD2 ,&sy STR2
 	.line/dx LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
 	&loop
-		.line/x LDZ2 .Screen/x DEO2 
-		.line/y LDZ2 .Screen/y DEO2 
-		.color LDZ .Screen/pixel DEO
-		[ .line/x LDZ2 .line/x0 LDZ2 EQU2 ] 
-		[ .line/y LDZ2 .line/y0 LDZ2 EQU2 ] #0101 EQU2 ,&end JCN
-		.line/e1 LDZ2 2** .line/e2 STZ2
-		.line/e2 LDZ2 .line/dy LDZ2 LTS2 ,&skipy JCN
+		.line/x LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
+		.line/y LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
+			STHkr .Screen/pixel DEO
+			AND ,&end JCN
+		.line/e1 LDZ2 #10 SFT2 DUP2
+		.line/dy LDZ2 ;lts2 JSR2 ,&skipy JCN
 			.line/e1 LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
-			.line/x LDZ2 .line/sx LDZ2 ADD2 .line/x STZ2
+			.line/x LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x STZ2
 		&skipy
-		.line/e2 LDZ2 .line/dx LDZ2 GTS2 ,&skipx JCN
+		.line/dx LDZ2 ;gts2 JSR2 ,&skipx JCN
 			.line/e1 LDZ2 .line/dx LDZ2 ADD2 .line/e1 STZ2
-			.line/y LDZ2 .line/sy LDZ2 ADD2 .line/y STZ2
+			.line/y LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y STZ2
 		&skipx
-		;&loop JMP2
+		,&loop JMP
 	&end
+	POPr
+
+JMP2r
 
-RTN
+@abs2 DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 JMP2r
+@lts2 #8000 ADD2 SWP2 #8000 ADD2 GTH2 JMP2r
+@gts2 #8000 ADD2 SWP2 #8000 ADD2 LTH2 JMP2r
 
 @pointer-icn 80c0 e0f0 f8e0 1000
diff --git a/projects/examples/devices/screen.auto.tal b/projects/examples/devices/screen.auto.tal
@@ -1,30 +0,0 @@
-( devices )
-
-|00 @System     &vector $2 &wst      $1 &rst    $1 &swsz   $1 &swap   $1 &pad     $2 &r       $2 &g      $2 &b     $2 &debug  $1 &halt $1
-|20 @Screen     &vector $2 &width    $2 &height $2 &auto   $1 &pad    $1 &x       $2 &y       $2 &addr   $2 &pixel $1 &sprite $1
-
-( variables )
-
-|0000
-
-( program )
-
-|0100 ( -> )
-	( theme ) 
-	#0fe5 .System/r DEO2 
-	#0fc5 .System/g DEO2 
-	#0f25 .System/b DEO2
-
-	#35 .Screen/auto DEO
-
-	;font #0210 ADD2 .Screen/addr DEO2
-	#0d00 &loop
-		#04 .Screen/sprite DEO
-		INC
-		GTHk ,&loop JCN
-
-BRK
-
-~projects/assets/msx01x02.tal
-
-