Browse code

Added circle to shapes

neauoire authored on 22/03/2021 16:42:48
Showing 5 changed files
... ...
@@ -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 projects/software/noodle.usm bin/boot.rom
23
+./bin/assembler projects/examples/gui.ripples.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
... ...
@@ -52,16 +52,16 @@ BRK
52 52
 	
53 53
 	( update colors every 40 frames )
54 54
 	~timer #40 NEQ ,skip1 ROT JMP2?
55
-		#0fac #fffa STR2 #f0bb #fffc STR2 #f053 #fff8 STR2
55
+		#0fac #01fa STR2 #f0bb #01fc STR2 #f053 #01f8 STR2
56 56
 	@skip1
57 57
 	~timer #80 NEQ ,skip2 ROT JMP2?
58
-		#00fc #fffc STR2 #f0bb #fff8 STR2 #f053 #fffa STR2
58
+		#00fc #01fc STR2 #f0bb #01f8 STR2 #f053 #01fa STR2
59 59
 	@skip2
60 60
 	~timer #c0 NEQ ,skip3 ROT JMP2?
61
-		#000f #fff8 STR2 #0f0f #fffa STR2 #ff00 #fffc STR2
61
+		#000f #01f8 STR2 #0f0f #01fa STR2 #0100 #01fc STR2
62 62
 	@skip3
63 63
 	~timer #00 NEQ ,skip4 ROT JMP2?
64
-		#f0ac #fff8 STR2 #f0bb #fffa STR2 #f053 #fffc STR2
64
+		#f0ac #01f8 STR2 #f0bb #01fa STR2 #f053 #01fc STR2
65 65
 	@skip4
66 66
 	~timer #01 ADD =timer
67 67
 
68 68
deleted file mode 100644
... ...
@@ -1,145 +0,0 @@
1
-( draw bezier )
2
-
3
-%RTN { JMP2r }
4
-%2/ { #0002 DIV2 }
5
-%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? } 
6
-%STEP8 { #0033 SFT2 }
7
-%STEP4 { #0022 SFT2 }
8
-
9
-;pt1 { x 2 y 2 }
10
-;pt2 { x 2 y 2 }
11
-;pt3 { x 2 y 2 }
12
-;pta { x 2 y 2 }
13
-;ptb { x 2 y 2 }
14
-;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
15
-;color { byte 1 }
16
-;pointer { x 2 y 2 }
17
-;i { byte 1 }
18
-;j { byte 1 }
19
-
20
-( devices )
21
-
22
-|0100 ;Console { pad 8 char 1 byte 1 short 2 }
23
-|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
24
-|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
25
-|0150 ;Mouse  { x 2 y 2 state 1 chord 1 }
26
-|01F0 .RESET .FRAME .ERROR ( vectors )
27
-|01F8 [ 13fd 1ef3 1bf2 ] ( palette )
28
-
29
-|0200 @RESET
30
-
31
-	#0020 #0020 =pt1.y =pt1.x
32
-	#0040 #0080 =pt2.y =pt2.x
33
-	#00f0 #00a0 =pt3.y =pt3.x
34
-
35
-	,redraw JSR2
36
-
37
-BRK
38
-
39
-@FRAME 
40
-
41
-	,draw-cursor JSR2
42
-
43
-	,$no-touch ~Mouse.state #00 EQU JMP2?
44
-
45
-		~Mouse.x STEP4 =pt2.x
46
-		~Mouse.y STEP4 =pt2.y
47
-		,redraw JSR2
48
-
49
-	$no-touch
50
-
51
-BRK 
52
-
53
-@redraw
54
-	
55
-	#0000 =Sprite.y 
56
-	$ver
57
-		#0000 =Sprite.x 
58
-		$hor
59
-			( draw ) #00 =Sprite.color
60
-			( incr ) ~Sprite.x #0008 ADD2 =Sprite.x
61
-			( incr ) #0000 =Sprite.addr
62
-		,$hor ~Sprite.x ~Screen.width LTH2 JMP2?
63
-		( incr ) ~Sprite.y #0008 ADD2 =Sprite.y
64
-	,$ver ~Sprite.y ~Screen.height LTH2 JMP2?
65
-
66
-	~pt1.x ~pt1.y ~pt2.x ~pt2.y #03 ,draw-line JSR2
67
-	~pt2.x ~pt2.y ~pt3.x ~pt3.y #03 ,draw-line JSR2
68
-
69
-	~pt1.x ~pt1.y #0a ,draw-point JSR2
70
-	~pt2.x ~pt2.y #0a ,draw-point JSR2
71
-	~pt3.x ~pt3.y #0a ,draw-point JSR2
72
-
73
-	#00 =i
74
-
75
-	$loop
76
-		~pt1.x ~pt2.x ~pt1.x SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =pta.x
77
-		~pt1.y ~pt2.y ~pt1.y SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =pta.y
78
-		~pt2.x ~pt3.x ~pt2.x SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =ptb.x
79
-		~pt2.y ~pt3.y ~pt2.y SUB2 #0008 DIV2 #00 ~i MUL2 ADD2 =ptb.y
80
-		~pta.x ~pta.y ~ptb.x ~ptb.y #0a ,draw-line JSR2
81
-		( incr ) ~i #01 ADD =i
82
-		,$loop ~i #08 LTH JMP2?
83
-
84
-RTN
85
-
86
-@draw-point ( x y color )
87
-
88
-	=color
89
-	#0003 SUB2 =Sprite.y
90
-	#0003 SUB2 =Sprite.x
91
-	,handle =Sprite.addr
92
-	~color =Sprite.color
93
-
94
-RTN
95
-
96
-@draw-line ( x1 y1 x2 y2 color )
97
-	
98
-	( load ) =color =line.y0 =line.x0 =line.y =line.x
99
-	~line.x0 ~line.x SUB2 ABS2 =line.dx
100
-	~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy
101
-	#ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx 
102
-	#ffff #00 ~line.y ~line.y0 LTS2 #0002 MUL2 ADD2 =line.sy 
103
-	~line.dx ~line.dy ADD2 =line.e1
104
-	$loop
105
-		~line.x =Screen.x ~line.y =Screen.y ~color =Screen.color
106
-		,$end ~line.x ~line.x0 EQU2 ~line.y ~line.y0 EQU2 #0101 EQU2 JMP2?
107
-		~line.e1 #0002 MUL2 =line.e2
108
-		,$skipy ~line.e2 ~line.dy LTS2 JMP2?
109
-			~line.e1 ~line.dy ADD2 =line.e1
110
-			~line.x ~line.sx ADD2 =line.x
111
-		$skipy
112
-		,$skipx ~line.e2 ~line.dx GTS2 JMP2?
113
-			~line.e1 ~line.dx ADD2 =line.e1
114
-			~line.y ~line.sy ADD2 =line.y
115
-		$skipx
116
-		,$loop JMP2
117
-
118
-	$end
119
-
120
-RTN
121
-
122
-@draw-cursor
123
-
124
-	( clear last cursor )
125
-	,clear_icn =Sprite.addr 
126
-	~pointer.x =Sprite.x 
127
-	~pointer.y =Sprite.y 
128
-	#10 =Sprite.color
129
-
130
-	( record pointer positions )
131
-	~Mouse.x =pointer.x ~Mouse.y =pointer.y
132
-
133
-	( draw new cursor )
134
-	,cursor_icn =Sprite.addr 
135
-	~pointer.x =Sprite.x 
136
-	~pointer.y =Sprite.y 
137
-	#11 =Sprite.color
138
-
139
-RTN
140
-
141
-@handle [ 0010 2844 2810 0000 ]
142
-@clear_icn   [ 0000 0000 0000 0000 ]
143
-@cursor_icn  [ 80c0 e0f0 f8e0 1000 ]
144
-
145
-@ERROR BRK 
146 0
new file mode 100644
... ...
@@ -0,0 +1,93 @@
1
+( draw routines )
2
+
3
+%RTN { JMP2r }
4
+%++  { #0001 ADD2 }
5
+%--  { #0001 SUB2 }
6
+%8+  { #0008 ADD2 }
7
+%ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? } 
8
+
9
+;color { byte 1 }
10
+;pointer { x 2 y 2 }
11
+;circle { xc 2 yc 2 x 2 y 2 r 2 d 2 }
12
+
13
+|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
14
+|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
15
+|0150 ;Mouse  { x 2 y 2 state 1 chord 1 }
16
+|01F0 .RESET .FRAME .ERROR ( vectors )
17
+|01F8 [ 13fd 1ef3 1bf2 ] ( palette )
18
+
19
+|0200 @RESET
20
+	
21
+BRK
22
+
23
+@FRAME
24
+ 	
25
+ 	( clear )
26
+	~circle.xc ~circle.yc ~circle.r #00 ,draw-circle JSR2
27
+
28
+	,draw-cursor JSR2
29
+
30
+	,$no-touch ~Mouse.state #00 EQU JMP2?
31
+		~Mouse.x =circle.xc
32
+		~Mouse.y =circle.yc
33
+		#0000 =circle.r
34
+	$no-touch
35
+
36
+ 	( draw )
37
+	~circle.xc ~circle.yc ~circle.r #0001 ADD2 #03 ,draw-circle JSR2
38
+
39
+BRK 
40
+
41
+@draw-cursor
42
+
43
+	( clear last cursor )
44
+	,clear_icn =Sprite.addr 
45
+	~pointer.x =Sprite.x 
46
+	~pointer.y =Sprite.y 
47
+	#10 =Sprite.color
48
+
49
+	( record pointer positions )
50
+	~Mouse.x =pointer.x ~Mouse.y =pointer.y
51
+
52
+	( draw new cursor )
53
+	,cursor_icn =Sprite.addr 
54
+	~pointer.x =Sprite.x 
55
+	~pointer.y =Sprite.y 
56
+	#11 =Sprite.color
57
+
58
+RTN
59
+
60
+@draw-circle ( xc yc r color )
61
+
62
+	( load ) =color =circle.r =circle.yc =circle.xc
63
+	#0000 =circle.x ~circle.r =circle.y
64
+	~circle.r #0002 MUL2 #0003 SUB2 =circle.d
65
+	( draw ) ,$seg JSR2
66
+	$loop
67
+		( incr ) ~circle.x ++ =circle.x
68
+		,$else ~circle.d #0000 #0001 ADD2 LTS2 JMP2?
69
+			( decr ) ~circle.y -- =circle.y
70
+			~circle.x ~circle.y SUB2 #0004 MUL2 ~circle.d ADD2 #000a ADD2 =circle.d
71
+			,$end JMP2
72
+		$else
73
+			~circle.x #0004 MUL2 ~circle.d ADD2 #0006 ADD2 =circle.d
74
+		$end
75
+		( draw ) ,$seg JSR2
76
+		,$loop ~circle.y ~circle.x #0001 SUB2 GTS2 JMP2?
77
+	RTN
78
+	$seg
79
+		~circle.xc ~circle.x ADD2 =Screen.x ~circle.yc ~circle.y ADD2 =Screen.y ~color =Screen.color
80
+		~circle.xc ~circle.x SUB2 =Screen.x ~circle.yc ~circle.y ADD2 =Screen.y ~color =Screen.color
81
+		~circle.xc ~circle.x ADD2 =Screen.x ~circle.yc ~circle.y SUB2 =Screen.y ~color =Screen.color
82
+		~circle.xc ~circle.x SUB2 =Screen.x ~circle.yc ~circle.y SUB2 =Screen.y ~color =Screen.color
83
+		~circle.xc ~circle.y ADD2 =Screen.x ~circle.yc ~circle.x ADD2 =Screen.y ~color =Screen.color
84
+		~circle.xc ~circle.y SUB2 =Screen.x ~circle.yc ~circle.x ADD2 =Screen.y ~color =Screen.color
85
+		~circle.xc ~circle.y ADD2 =Screen.x ~circle.yc ~circle.x SUB2 =Screen.y ~color =Screen.color
86
+		~circle.xc ~circle.y SUB2 =Screen.x ~circle.yc ~circle.x SUB2 =Screen.y ~color =Screen.color
87
+
88
+RTN
89
+
90
+@ERROR BRK 
91
+
92
+@clear_icn   [ 0000 0000 0000 0000 ]
93
+@cursor_icn  [ 80c0 e0f0 f8e0 1000 ]
0 94
\ No newline at end of file
... ...
@@ -2,6 +2,7 @@
2 2
 
3 3
 %RTN { JMP2r }
4 4
 %++  { #0001 ADD2 }
5
+%--  { #0001 SUB2 }
5 6
 %8+  { #0008 ADD2 }
6 7
 %ABS2 { DUP2 #000f SFT2 #ffff SWP2 SWP POP MUL2? } 
7 8
 
... ...
@@ -11,6 +12,8 @@
11 12
 ;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
12 13
 ;color { byte 1 }
13 14
 
15
+;circle { xc 2 yc 2 x 2 y 2 r 2 d 2 }
16
+
14 17
 |0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
15 18
 |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
16 19
 |01F0 .RESET .FRAME .ERROR ( vectors )
... ...
@@ -39,6 +42,10 @@
39 42
 	#0020 #0080 #0070 #0030 #02 ,draw-line JSR2
40 43
 	#00a0 #0020 #0050 #00b0 #03 ,draw-line JSR2
41 44
 	#00b0 #0090 #0030 #0010 #01 ,draw-line JSR2
45
+
46
+	#0040 #0040 #0030 #01 ,draw-circle JSR2
47
+	#0070 #0030 #0040 #02 ,draw-circle JSR2
48
+	#0050 #0080 #0050 #03 ,draw-circle JSR2
42 49
 	
43 50
 BRK
44 51
 
... ...
@@ -126,6 +133,36 @@ RTN
126 133
 
127 134
 RTN
128 135
 
136
+@draw-circle ( xc yc r color )
137
+
138
+	( load ) =color =circle.r =circle.yc =circle.xc
139
+	#0000 =circle.x ~circle.r =circle.y
140
+	~circle.r #0002 MUL2 #0003 SUB2 =circle.d
141
+	( draw ) ,$seg JSR2
142
+	$loop
143
+		( incr ) ~circle.x ++ =circle.x
144
+		,$else ~circle.d #0000 #0001 ADD2 LTS2 JMP2?
145
+			( decr ) ~circle.y -- =circle.y
146
+			~circle.x ~circle.y SUB2 #0004 MUL2 ~circle.d ADD2 #000a ADD2 =circle.d
147
+			,$end JMP2
148
+		$else
149
+			~circle.x #0004 MUL2 ~circle.d ADD2 #0006 ADD2 =circle.d
150
+		$end
151
+		( draw ) ,$seg JSR2
152
+		,$loop ~circle.y ~circle.x #0001 SUB2 GTS2 JMP2?
153
+	RTN
154
+	$seg
155
+		~circle.xc ~circle.x ADD2 =Screen.x ~circle.yc ~circle.y ADD2 =Screen.y ~color =Screen.color
156
+		~circle.xc ~circle.x SUB2 =Screen.x ~circle.yc ~circle.y ADD2 =Screen.y ~color =Screen.color
157
+		~circle.xc ~circle.x ADD2 =Screen.x ~circle.yc ~circle.y SUB2 =Screen.y ~color =Screen.color
158
+		~circle.xc ~circle.x SUB2 =Screen.x ~circle.yc ~circle.y SUB2 =Screen.y ~color =Screen.color
159
+		~circle.xc ~circle.y ADD2 =Screen.x ~circle.yc ~circle.x ADD2 =Screen.y ~color =Screen.color
160
+		~circle.xc ~circle.y SUB2 =Screen.x ~circle.yc ~circle.x ADD2 =Screen.y ~color =Screen.color
161
+		~circle.xc ~circle.y ADD2 =Screen.x ~circle.yc ~circle.x SUB2 =Screen.y ~color =Screen.color
162
+		~circle.xc ~circle.y SUB2 =Screen.x ~circle.yc ~circle.x SUB2 =Screen.y ~color =Screen.color
163
+
164
+RTN
165
+
129 166
 @pict_small [
130 167
 
131 168
 	ff80 8080 8080 8088 ffff fffc f8f9 f1f4