commit d5fed95
neauoire
·
2023-06-07 15:42:22 +0000 UTC
parent 1892352
Returned PADDING
3 files changed,
+242,
-6
M
build.sh
+3,
-2
1@@ -45,7 +45,8 @@ fi
2
3 # bin/uxnasm etc/polycat.tal bin/polycat.rom
4 # bin/uxn11 bin/polycat.rom
5+# bin/uxnasm etc/friend.tal bin/friend.rom
6
7-bin/uxnasm etc/friend.tal bin/friend.rom
8-bin/uxn11 bin/friend.rom
9+bin/uxnasm etc/mouse.tal bin/mouse.rom
10+bin/uxn11 bin/mouse.rom
11
+227,
-0
1@@ -0,0 +1,227 @@
2+( Mouse:
3+ Paint with 3 colors with each mouse button. )
4+
5+|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
6+|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
7+|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &modx $2 &mody $2
8+
9+|0000
10+
11+ @line &x2 $2 &y2 $2
12+ @length $2
13+ @frame $2
14+ @pen &x $2 &y $2 &x2 $2 &y2 $2
15+ @pointer &x $2 &y $2 &lastx $2 &lasty $2 &state $1
16+
17+|0100 ( -> )
18+
19+ ( theme )
20+ #4cfd .System/r DEO2
21+ #4cf3 .System/g DEO2
22+ #dcf2 .System/b DEO2
23+
24+ ( vectors )
25+ ;on-mouse .Mouse/vector DEO2
26+ ;on-frame .Screen/vector DEO2
27+
28+ draw-mouse
29+
30+BRK
31+
32+(
33+@|vectors )
34+
35+@on-frame ( -> )
36+
37+ .Mouse/state DEI ?&skip
38+ ;run DUP2 JSR2 JSR2
39+ &skip
40+
41+BRK
42+
43+@on-mouse ( -> )
44+
45+ ( clear last cursor )
46+ .pointer/x LDZ2 .Screen/x DEO2
47+ .pointer/y LDZ2 .Screen/y DEO2
48+ [ LIT2 40 -Screen/sprite ] DEO
49+ draw-mouse
50+ ( draw new cursor )
51+ ;pointer-icn .Screen/addr DEO2
52+ #00 .Screen/auto DEO
53+ .Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
54+ .Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
55+ #45 .Mouse/state DEI #00 NEQ #05 MUL ADD .Screen/sprite DEO
56+ ( on down )
57+ .Mouse/state DEI #00 NEQ .pointer/state LDZ #00 EQU AND ?on-mouse-down
58+ ( on drag )
59+ .Mouse/state DEI ?on-mouse-drag
60+ .Mouse/state DEI .pointer/state STZ
61+
62+BRK
63+
64+@on-mouse-down ( -> )
65+
66+ #0000 DUP2 .length STZ2 .frame STZ2
67+ clear-screen
68+ ( record start position )
69+ .Mouse/x DEI2 DUP2 .pointer/x STZ2 .pointer/lastx STZ2
70+ .Mouse/y DEI2 DUP2 .pointer/y STZ2 .pointer/lasty STZ2
71+ .Mouse/state DEI .pointer/state STZ
72+
73+BRK
74+
75+@on-mouse-drag ( -> )
76+
77+ ( record )
78+ ;stroke .length LDZ2 #20 SFT2 ADD2 STH2
79+ .pointer/x LDZ2 .pointer/lastx LDZ2 SUB2 STH2kr STA2
80+ .pointer/y LDZ2 .pointer/lasty LDZ2 SUB2 STH2r INC2 INC2 STA2
81+ ( move ptr )
82+ .length LDZ2 INC2 .length STZ2
83+ ( draw line )
84+ .pointer/lastx LDZ2
85+ .pointer/lasty LDZ2
86+ .pointer/x LDZ2
87+ .pointer/y LDZ2
88+ #01 draw-line
89+ ( record last position )
90+ .Mouse/x DEI2
91+ DUP2 .pointer/lastx STZ2
92+ DUP2 .pen/x STZ2
93+ .pen/x2 STZ2
94+ .Mouse/y DEI2
95+ DUP2 .pointer/lasty STZ2
96+ DUP2 .pen/y STZ2
97+ .pen/y2 STZ2
98+ .Mouse/state DEI
99+ DUP #01 NEQ INC ;run/color STA
100+ .pointer/state STZ
101+
102+BRK
103+
104+(
105+@|main )
106+
107+@run ( -- )
108+
109+ ( read )
110+ ;stroke .frame LDZ2 #20 SFT2 ADD2 STH2
111+ .pen/x LDZ2 STH2kr LDA2 ADD2 .pen/x STZ2
112+ .pen/y LDZ2 STH2r INC2 INC2 LDA2 ADD2 .pen/y STZ2
113+ ( line )
114+ .pen/x LDZ2 .pen/y LDZ2
115+ .pen/x2 LDZ2 .pen/y2 LDZ2
116+ .frame LDZ2 #01 SFT2 NIP #01 AND [ LIT &color $1 ] ADD INC draw-line
117+ ( history )
118+ .pen/x LDZ2 .pen/x2 STZ2
119+ .pen/y LDZ2 .pen/y2 STZ2
120+ ( incr frame )
121+ .frame LDZ2 INC2 .length LDZ2 INC2 ( mod2 ) DIV2k MUL2 SUB2 .frame STZ2
122+
123+JMP2r
124+
125+@draw-mouse ( -- )
126+
127+ ( clear )
128+ #0010
129+ DUP2 .Screen/x DEO2
130+ .Screen/y DEO2
131+ #16 .Screen/auto DEO
132+ #40 .Screen/sprite DEOk DEO
133+ ( buttons )
134+ #0300
135+ &l
136+ #01 OVR #40 SFT SFT .Mouse/state DEI AND #00 EQU ?&no-draw
137+ #0010 .Screen/y DEO2
138+ #00 OVR #40 SFT2 ;button-icn ADD2 .Screen/addr DEO2
139+ #45 .Screen/sprite DEO
140+ &no-draw
141+ INC GTHk ?&l
142+ POP2
143+ ( outline )
144+ #0010 .Screen/y DEO2
145+ ;mouse-icn .Screen/addr DEO2
146+ #16 .Screen/auto DEO
147+ #4a .Screen/sprite DEOk DEO
148+
149+JMP2r
150+
151+@draw-line ( x1* y1* x2* y2* color -- )
152+
153+ ( load )
154+ ,&color STR
155+ ,&y STR2
156+ ,&x STR2
157+ .line/y2 STZ2
158+ .line/x2 STZ2
159+
160+ ,&x LDR2 .line/x2 LDZ2 SUB2 abs2 ,&dx STR2
161+ #0000 ,&y LDR2 .line/y2 LDZ2 SUB2 abs2 SUB2 ,&dy STR2
162+
163+ #ffff #00 .line/x2 LDZ2 ,&x LDR2 lts2 DUP2 ADD2 ADD2 ,&sx STR2
164+ #ffff #00 .line/y2 LDZ2 ,&y LDR2 lts2 DUP2 ADD2 ADD2 ,&sy STR2
165+
166+ [ LIT2 &dx $2 ] [ LIT2 &dy $2 ] ADD2 ,&e1 STR2
167+
168+ &loop
169+ .line/x2 LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
170+ .line/y2 LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
171+ [ LIT2 &color $1 -Screen/pixel ] DEO
172+ AND ?&end
173+ [ LIT2 &e1 $2 ] DUP2 ADD2 DUP2
174+ ,&dy LDR2 lts2 ?&skipy
175+ ,&e1 LDR2 ,&dy LDR2 ADD2 ,&e1 STR2
176+ .line/x2 LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x2 STZ2
177+ &skipy
178+ ,&dx LDR2 gts2 ?&skipx
179+ ,&e1 LDR2 ,&dx LDR2 ADD2 ,&e1 STR2
180+ .line/y2 LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y2 STZ2
181+ &skipx
182+ !&loop
183+ &end
184+
185+JMP2r
186+
187+@abs2 DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 JMP2r
188+@lts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 GTH2 JMP2r
189+@gts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 LTH2 JMP2r
190+
191+@clear-screen ( -- )
192+
193+ #00 .Screen/auto DEO
194+
195+ .Screen/height DEI2 #03 SFT2 NIP #00
196+ &y
197+ #00 OVR #30 SFT2 .Screen/y DEO2
198+ .Screen/width DEI2 #03 SFT2 NIP #00
199+ &x
200+ #00 OVR #30 SFT2 .Screen/x DEO2
201+ [ LIT2 00 -Screen/sprite ] DEO
202+ INC GTHk ?&x
203+ POP2
204+ INC GTHk ?&y
205+ POP2
206+
207+JMP2r
208+
209+@pointer-icn [
210+ 80c0 e0f0 f8e0 1000 ]
211+@mouse-icn [
212+ 000d 1212 1212 121d
213+ 00b0 4848 4848 48b8
214+ 1010 1010 1008 0700
215+ 0808 0808 0810 e000 ]
216+@button-icn [
217+ 000c 1e1e 1e1e 1e0c
218+ 0000 0000 0000 0000
219+ 0001 0303 0303 0301
220+ 0080 c0c0 c0c0 c080
221+ 0000 0000 0000 0000
222+ 0030 7878 7878 7830 ]
223+
224+(
225+@|memory )
226+
227+@stroke
228+
+12,
-4
1@@ -35,12 +35,18 @@ char *rom_path;
2
3 #define WIDTH (64 * 8)
4 #define HEIGHT (40 * 8)
5-#define PAD 0
6+#define PAD 2
7 #define CONINBUFSIZE 256
8
9 Uint16 deo_mask[] = {0xff28, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
10 Uint16 dei_mask[] = {0x0000, 0x0000, 0x003c, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
11
12+static int
13+clamp(int val, int min, int max)
14+{
15+ return (val >= min) ? (val <= max) ? val : max : min;
16+}
17+
18 Uint8
19 uxn_dei(Uxn *u, Uint8 addr)
20 {
21@@ -118,7 +124,7 @@ emu_event(Uxn *u)
22 XNextEvent(display, &ev);
23 switch(ev.type) {
24 case Expose:
25- XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, 0, 0, uxn_screen.width, uxn_screen.height);
26+ XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, uxn_screen.width, uxn_screen.height);
27 break;
28 case ClientMessage: {
29 XDestroyImage(ximage);
30@@ -159,7 +165,9 @@ emu_event(Uxn *u)
31 } break;
32 case MotionNotify: {
33 XMotionEvent *e = (XMotionEvent *)&ev;
34- mouse_pos(u, &u->dev[0x90], (e->x - PAD) / SCALE, (e->y - PAD) / SCALE);
35+ int x = clamp((e->x - PAD) / SCALE, 0, uxn_screen.width - 1);
36+ int y = clamp((e->y - PAD) / SCALE, 0, uxn_screen.height - 1);
37+ mouse_pos(u, &u->dev[0x90], x, y);
38 } break;
39 }
40 }
41@@ -233,7 +241,7 @@ main(int argc, char **argv)
42 if(uxn_screen.x2) {
43 int x1 = uxn_screen.x1, y1 = uxn_screen.y1, x2 = uxn_screen.x2, y2 = uxn_screen.y2;
44 screen_redraw();
45- XPutImage(display, window, DefaultGC(display, 0), ximage, x1, y1, x1, y1, x2 - x1, y2 - y1);
46+ XPutImage(display, window, DefaultGC(display, 0), ximage, x1, y1, x1 + PAD, y1 + PAD, x2 - x1, y2 - y1);
47 }
48 }
49 XDestroyImage(ximage);