Browse code

Improved polycat example

neauoire authored on 24/02/2021 01:57:57
Showing 4 changed files
... ...
@@ -101,7 +101,6 @@ A device that works like a NES controller, each button is a bit from a single by
101 101
 - Line routine
102 102
 - Getting rid of IOR/IOW would be nice..
103 103
 - Example of button pointing to a subroutine
104
-- Labels should not have the trailing space
105 104
 
106 105
 ### Misc TODOs
107 106
 
... ...
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
20 20
 # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
21 21
 
22 22
 # run
23
-./bin/assembler examples/window.usm bin/boot.rom
23
+./bin/assembler examples/devmouse.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
... ...
@@ -3,17 +3,24 @@
3 3
 :dev/r fff8 ( std read port )
4 4
 :dev/w fff9 ( std write port )
5 5
 
6
-;mousex 2 ;mousey 2 
7
-;lastx 2  ;lasty 2 
8
-;catx 2 ;caty 2
6
+&Point2d { x 2 y 2 }
7
+
8
+;mouse Point2d
9
+;cat Point2d
10
+
9 11
 ;state 1 ;timer 1
10 12
 
11 13
 |0100 @RESET 
12 14
 	
15
+	#01 =dev/r ( set dev/read mouse )
16
+
17
+	( position cat )
18
+	#00 IOR2 #0002 DIV2 =cat.x 
19
+	#02 IOR2 #0038 SUB2 =cat.y
20
+
13 21
 	#05 =dev/r ( set dev/read mouse )
14 22
 	#02 =dev/w ( set dev/write to sprite ) 
15
-	( position cat )
16
-	#0050 =catx #0058 =caty
23
+	
17 24
 	( draw polycat )
18 25
 	,draw-polycat JSR
19 26
 
... ...
@@ -22,9 +29,9 @@ BRK
22 29
 |c000 @FRAME
23 30
 
24 31
 	( clear last cursor )
25
-	#10 ,clear_icn ~lastx ~lasty ,draw-sprite JSR
32
+	#10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR
26 33
 	( record mouse positions )
27
-	#00 IOR2 =mousex #02 IOR2 =mousey
34
+	#00 IOR2 =mouse.x #02 IOR2 =mouse.y
28 35
 	( record mouse state )
29 36
 	#04 IOR #11 ADD =state
30 37
 	( detect click )
... ...
@@ -32,11 +39,10 @@ BRK
32 39
 		#50 =timer
33 40
 	@no-click
34 41
 	( draw mouse )
35
-	~state ,cursor_icn ~mousex ~mousey ,draw-sprite JSR
42
+	~state ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
36 43
 	( animate )
37 44
 	,animate-polycat JSR
38 45
 	( update last pos )
39
-	~mousex =lastx ~mousey =lasty 
40 46
 	~timer #01 ADD =timer
41 47
 
42 48
 BRK
... ...
@@ -44,14 +50,14 @@ BRK
44 50
 @draw-polycat
45 51
 
46 52
 	( ears )
47
-	,polycat ~catx ~caty ,draw-sprite-chr JSR
48
-	,polycat #0010 ADD2 ~catx #0008 ADD2 ~caty ,draw-sprite-chr JSR
53
+	,polycat ~cat.x ~cat.y ,draw-sprite-chr JSR
54
+	,polycat #0010 ADD2 ~cat.x #0008 ADD2 ~cat.y ,draw-sprite-chr JSR
49 55
 	( eye )
50
-	,polycat #0020 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
51
-	,polycat #0030 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
56
+	,polycat #0020 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
57
+	,polycat #0030 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
52 58
 	( body )
53
-	,polycat #00a0 ADD2 ~catx ~caty #0010 ADD2 ,draw-sprite-chr JSR
54
-	,polycat #00b0 ADD2 ~catx #0008 ADD2 ~caty #0010 ADD2 ,draw-sprite-chr JSR
59
+	,polycat #00a0 ADD2 ~cat.x ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
60
+	,polycat #00b0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
55 61
 
56 62
 RTS
57 63
 
... ...
@@ -59,35 +65,35 @@ RTS
59 65
 
60 66
 	( tail )
61 67
 	~timer #50 NEQ ,animate-polycat-tail-next0 ROT JMP? POP2
62
-		,polycat #00c0 ADD2 ~catx #0008 ADD2 ~caty #0010 ADD2 ,draw-sprite-chr JSR
68
+		,polycat #00c0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
63 69
 	@animate-polycat-tail-next0
64 70
 	~timer #58 NEQ ,animate-polycat-tail-next1 ROT JMP? POP2
65
-		,polycat #00d0 ADD2 ~catx #0008 ADD2 ~caty #0010 ADD2 ,draw-sprite-chr JSR
71
+		,polycat #00d0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
66 72
 	@animate-polycat-tail-next1
67 73
 	~timer #60 NEQ ,animate-polycat-tail-next2 ROT JMP? POP2
68
-		,polycat #00b0 ADD2 ~catx #0008 ADD2 ~caty #0010 ADD2 ,draw-sprite-chr JSR
74
+		,polycat #00b0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
69 75
 	@animate-polycat-tail-next2
70 76
 	( look-at )
71
-	~mousex ~catx #0008 ADD2 GTH2 ,animate-polycat-right ROT JMP? POP2
77
+	~mouse.x ~cat.x #0008 ADD2 GTH2 ,animate-polycat-right ROT JMP? POP2
72 78
 	@animate-polycat-left
73
-		~mousey ~caty #0008 ADD2 GTH2 ,animate-polycat-left-down ROT JMP? POP2
79
+		~mouse.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-left-down ROT JMP? POP2
74 80
 		@animate-polycat-left-up 
75
-			,polycat #0040 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
76
-			,polycat #0050 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
81
+			,polycat #0040 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
82
+			,polycat #0050 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
77 83
 		RTS
78 84
 		@animate-polycat-left-down 
79
-			,polycat #0020 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
80
-			,polycat #0030 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
85
+			,polycat #0020 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
86
+			,polycat #0030 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
81 87
 		RTS
82 88
 	@animate-polycat-right
83
-		~mousey ~caty #0008 ADD2 GTH2 ,animate-polycat-right-down ROT JMP? POP2
89
+		~mouse.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-right-down ROT JMP? POP2
84 90
 		@animate-polycat-right-up 
85
-			,polycat #0060 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
86
-			,polycat #0070 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
91
+			,polycat #0060 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
92
+			,polycat #0070 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
87 93
 		RTS
88 94
 		@animate-polycat-right-down 
89
-			,polycat #0080 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
90
-			,polycat #0090 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
95
+			,polycat #0080 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
96
+			,polycat #0090 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
91 97
 		RTS
92 98
 
93 99
 RTS
... ...
@@ -30,7 +30,7 @@
30 30
 	,window_name1 #0020 #0020 #00d0 #0080 ,paint-window JSR
31 31
 	,window_name2 #0040 #0040 #00f0 #0070 ,paint-window JSR
32 32
 	,window_name3 #0060 #004c #00c0 #007a ,paint-window JSR
33
-	
33
+
34 34
 	#05 =dev/r ( set dev/read mouse )
35 35
 
36 36
 BRK
... ...
@@ -101,8 +101,8 @@ RTS
101 101
 	=icon.y =icon.x =icon.sprite =icon.text
102 102
 
103 103
 	#01 =dev/w ( write to screen )
104
-
105 104
 	#02 =dev/w ( write to sprite )
105
+	
106 106
 	#01 =color
107 107
 	~icon.text ~icon.x #0008 ADD2 ~icon.y #0020 ADD2 ,draw-label JSR
108 108
 	#07 ~icon.sprite ~icon.x #0018 ADD2 ~icon.y #0008 ADD2