Browse code

Optimized some example files

neauoire authored on 14/03/2021 22:17:00
Showing 3 changed files
... ...
@@ -75,6 +75,7 @@ RTN
75 75
 - Don't brk when return stack is not zeroed
76 76
 - LDRS should load from the zeropage?
77 77
 - Keep ref counts in macros
78
+- A fast way(2 bytes) to read from the zero page #aa LDR.
78 79
 
79 80
 ### Macros
80 81
 
... ...
@@ -2,7 +2,6 @@
2 2
 
3 3
 ;center { x 2 y 2 }
4 4
 ;timer { byte 1 }
5
-;i { byte 1 }
6 5
 
7 6
 |0100 @RESET 
8 7
 
... ...
@@ -12,26 +11,31 @@
12 11
 
13 12
 	( draw hor line )
14 13
 	#0000 =Screen.x ~center.y =Screen.y
15
-	$draw-hor
14
+	#0000 ~Screen.width ( from/to )
15
+	$draw-hor NOP
16 16
 		( draw ) #01 =Screen.color
17
-		( incr ) ~Screen.x #0002 ADD2 =Screen.x
18
-		,$draw-hor ~Screen.x ~Screen.width LTH2 JMP2? POP2
17
+		( incr ) SWP2 #0002 ADD2 DUP2 =Screen.x SWP2
18
+		OVR2 OVR2 LTH2 ^$draw-hor SWP JMPS? POP
19
+	POP2 POP2
19 20
 
20 21
 	( draw ver line )
21 22
 	~center.x =Screen.x #0000 =Screen.y
22
-	$draw-ver
23
+	#0000 ~Screen.height ( from/to )
24
+	$draw-ver NOP
23 25
 		( draw ) #02 =Screen.color
24
-		( incr ) ~Screen.y #0002 ADD2 =Screen.y
25
-		,$draw-ver ~Screen.y ~Screen.height LTH2 JMP2? POP2
26
+		( incr ) SWP2 #0002 ADD2 DUP2 =Screen.y SWP2
27
+		OVR2 OVR2 LTH2 ^$draw-ver SWP JMPS? POP
28
+	POP2 POP2
26 29
 
27 30
 	( draw blending modes )
28
-	#00 =i
29 31
 	#0020 =Sprite.x #0020 =Sprite.y ,icon =Sprite.addr
30
-	$draw-blends
31
-		( draw ) #00 ~i ADD =Sprite.color
32
-		( incr ) ~Sprite.x #0008 ADD2 =Sprite.x
33
-		( incr ) ~i #01 ADD =i
34
-		,$draw-blends ~i #10 LTH JMP2? POP2
32
+	#00 #10
33
+	$draw-blends NOP
34
+		( move ) OVR #00 SWP #0008 MUL2 #0020 ADD2 =Sprite.x
35
+		( draw ) OVR =Sprite.color
36
+		( incr ) SWP #01 ADD SWP 
37
+		DUP2 LTH ^$draw-blends SWP JMPS? POP
38
+	POP POP
35 39
 
36 40
 BRK
37 41
 
... ...
@@ -4,38 +4,60 @@
4 4
 
5 5
 |0100 @RESET 
6 6
 	
7
-	,type1 JSR2
8
-	,type2 JSR2
9
-	,type3 JSR2
7
+	,slow-muljmp JSR2
8
+	,slow-jmppop JSR2
9
+	,slow-jmppop-rel JSR2
10
+	,fast-byte JSR2
11
+	,fast-short JSR2
10 12
 
11 13
 BRK 
12 14
 
13
-@type1 ( type: padded muljmp )
15
+|0200 @slow-muljmp ( type: padded muljmp )
14 16
 
15 17
 	$loop NOP
16 18
 		~a #01 ADD =a
17 19
 		~a #d0 LTH ^$loop MUL JMPS
18 20
 	~a =Console.byte
19 21
 
20
-RTS
22
+RTN
21 23
 
22
-@type2 ( type: jmppop )
24
+|0300 @slow-jmppop ( type: jmppop )
23 25
 	
24 26
 	$loop
25 27
 		~b #01 ADD =b
26 28
 		,$loop ~b #d0 LTH JMP2? POP2
27 29
 	~b =Console.byte 
28 30
 
29
-RTS
31
+RTN
30 32
 
31
-@type3 ( type: padded jmppop )
33
+|0400 @slow-jmppop-rel ( type: padded jmppop )
32 34
 
33 35
 	$loop NOP
34 36
 		~c #01 ADD =c
35 37
 		~c #d0 LTH ^$loop SWP JMPS? POP
36 38
 	~c =Console.byte 
37 39
 
38
-RTS
40
+RTN
41
+
42
+|0500 @fast-byte ( fast byte )
43
+	
44
+	#00 #d0
45
+	$loop NOP
46
+		( incr ) SWP #01 ADD SWP 
47
+		DUP2 LTH ^$loop SWP JMPS? POP
48
+	POP =Console.byte
49
+
50
+RTN
51
+
52
+|0600 @fast-short ( fast short )
53
+	
54
+	#0000 #0d00
55
+	$loop NOP
56
+		( incr ) SWP2 #0001 ADD2 SWP2
57
+		OVR2 OVR2 LTH2 ^$loop SWP JMPS? POP
58
+	POP2 =Console.short
59
+
60
+RTN
39 61
 
40 62
 |c000 @FRAME
41 63
 |d000 @ERROR