Browse code

Fixed issue with mouse button not being released

neauoire authored on 10/04/2021 18:24:38
Showing 3 changed files
... ...
@@ -32,7 +32,7 @@ else
32 32
 fi
33 33
 
34 34
 echo "Assembling.."
35
-./bin/assembler projects/software/nasu.usm bin/boot.rom
35
+./bin/assembler projects/examples/dev.mouse.usm bin/boot.rom
36 36
 
37 37
 echo "Running.."
38 38
 if [ "${2}" = '--cli' ]; 
... ...
@@ -1,10 +1,15 @@
1 1
 ( Dev/Mouse )
2 2
 
3 3
 %RTN { JMP2r }
4
+%8+  { #0008 ADD2 }
4 5
 %++  { #0001 ADD2 }
5 6
 %--  { #0001 SUB2 }
6 7
 
8
+;touch1 { xc 2 yc 2 r 2 }
9
+;touch2 { xc 2 yc 2 r 2 }
10
+
7 11
 ;color { byte 1 }
12
+;addr { short 2 }
8 13
 ;pointer { x 2 y 2 }
9 14
 ;circle { xc 2 yc 2 x 2 y 2 r 2 d 2 }
10 15
 
... ...
@@ -23,9 +28,18 @@
23 28
 BRK
24 29
 
25 30
 @on-screen
26
-	
27
-	( clear ) ~circle.xc ~circle.yc ~circle.r #00 ,draw-circle JSR2
28
-	( draw ) ~circle.xc ~circle.yc ~circle.r #0001 ADD2 #03 ,draw-circle JSR2
31
+
32
+	( clear ) ~touch1.xc ~touch1.yc ~touch1.r #00 ,draw-circle JSR2
33
+	( clear ) ~touch2.xc ~touch2.yc ~touch2.r #00 ,draw-circle JSR2
34
+
35
+	~touch1.r ++ =touch1.r
36
+	~touch2.r ++ =touch2.r
37
+
38
+	( draw ) ~touch1.xc ~touch1.yc ~touch1.r #03 ,draw-circle JSR2
39
+	( draw ) ~touch2.xc ~touch2.yc ~touch2.r #02 ,draw-circle JSR2
40
+
41
+	~touch1.xc ~touch1.yc #23 ,touch1.r #0001 ADD2 ,draw-byte JSR2
42
+	~touch2.xc ~touch2.yc #28 ,touch2.r #0001 ADD2 ,draw-byte JSR2
29 43
 
30 44
 BRK
31 45
 
... ...
@@ -33,14 +47,16 @@ BRK
33 47
  	
34 48
 	,draw-cursor JSR2
35 49
 
36
-	( clear ) ~circle.xc ~circle.yc ~circle.r #00 ,draw-circle JSR2
37
-
38
-	~Mouse.state #00 EQU ^$no-touch JNZ
39
-		~Mouse.x DUP2 =circle.xc
40
-		~Mouse.y DUP2 =circle.yc
41
-		#0000 =circle.r
50
+	~Mouse.state #01 NEQ ,$no-touch1 JNZ2
51
+		( clear )   ~touch1.xc ~touch1.yc ~touch1.r #00 ,draw-circle JSR2
52
+		( update )  ~Mouse.x =touch1.xc ~Mouse.y =touch1.yc #0000 =touch1.r
42 53
 		( release ) #00 =Mouse.state
43
-	$no-touch
54
+	$no-touch1
55
+	~Mouse.state #10 NEQ ,$no-touch2 JNZ2
56
+		( clear )   ~touch2.xc ~touch2.yc ~touch2.r #00 ,draw-circle JSR2
57
+		( update )  ~Mouse.x =touch2.xc ~Mouse.y =touch2.yc #0000 =touch2.r
58
+		( release ) #00 =Mouse.state
59
+	$no-touch2
44 60
 
45 61
 BRK 
46 62
 
... ...
@@ -93,5 +109,30 @@ RTN
93 109
 
94 110
 RTN
95 111
 
112
+@draw-byte ( x y color addr -- )
113
+
114
+	=addr STH
115
+	=Screen.y
116
+	=Screen.x
117
+	,font_hex #00 ~addr PEK2 #04 SFT #0008 MUL2 ADD2 =Screen.addr
118
+	STHr DUP STH =Screen.color
119
+	,font_hex #00 ~addr PEK2 #0f AND #0008 MUL2 ADD2 =Screen.addr
120
+	~Screen.x 8+ =Screen.x
121
+	STHr =Screen.color
122
+
123
+RTN
124
+
96 125
 @clear_icn   [ 0000 0000 0000 0000 ]
97
-@cursor_icn  [ 80c0 e0f0 f8e0 1000 ]
98 126
\ No newline at end of file
127
+@cursor_icn  [ 80c0 e0f0 f8e0 1000 ]
128
+
129
+@font_hex
130
+[
131
+	003c 464a 5262 3c00 0018 0808 0808 1c00
132
+	003c 4202 3c40 7e00 003c 421c 0242 3c00
133
+	000c 1424 447e 0400 007e 407c 0242 3c00
134
+	003c 407c 4242 3c00 007e 0204 0810 1000
135
+	003c 423c 4242 3c00 003c 4242 3e02 3c00
136
+	003c 4242 7e42 4200 007c 427c 4242 7c00 
137
+	003c 4240 4042 3c00 007c 4242 4242 7c00 
138
+	007e 4078 4040 7e00 007e 4078 4040 4000
139
+]
99 140
\ No newline at end of file
... ...
@@ -128,23 +128,25 @@ void
128 128
 domouse(Uxn *u, SDL_Event *event)
129 129
 {
130 130
 	Uint8 flag = 0x00;
131
-	Uint16 addr = devmouse->addr + 2;
132 131
 	Uint16 x = clamp(event->motion.x / zoom - ppu.pad, 0, ppu.hor * 8 - 1);
133 132
 	Uint16 y = clamp(event->motion.y / zoom - ppu.pad, 0, ppu.ver * 8 - 1);
134
-	mempoke16(u, addr + 0, x);
135
-	mempoke16(u, addr + 2, y);
136
-	u->ram.dat[addr + 5] = 0x00;
137
-	flag = event->button.button == SDL_BUTTON_LEFT ? 0x01 : 0x10;
133
+	mempoke16(u, devmouse->addr + 2, x);
134
+	mempoke16(u, devmouse->addr + 4, y);
135
+	u->ram.dat[devmouse->addr + 7] = 0x00;
136
+	switch(event->button.button) {
137
+	case SDL_BUTTON_LEFT: flag = 0x01; break;
138
+	case SDL_BUTTON_RIGHT: flag = 0x10; break;
139
+	}
138 140
 	switch(event->type) {
139 141
 	case SDL_MOUSEBUTTONDOWN:
140
-		u->ram.dat[addr + 4] |= flag;
141
-		if(flag == 0x10 && (u->ram.dat[addr + 4] & 0x01))
142
-			u->ram.dat[addr + 5] = 0x01;
143
-		if(flag == 0x01 && (u->ram.dat[addr + 4] & 0x10))
144
-			u->ram.dat[addr + 5] = 0x10;
142
+		u->ram.dat[devmouse->addr + 6] |= flag;
143
+		if(flag == 0x10 && (u->ram.dat[devmouse->addr + 6] & 0x01))
144
+			u->ram.dat[devmouse->addr + 7] = 0x01;
145
+		if(flag == 0x01 && (u->ram.dat[devmouse->addr + 6] & 0x10))
146
+			u->ram.dat[devmouse->addr + 7] = 0x10;
145 147
 		break;
146 148
 	case SDL_MOUSEBUTTONUP:
147
-		u->ram.dat[addr + 4] &= (~flag);
149
+		u->ram.dat[devmouse->addr + 6] &= (~flag);
148 150
 		break;
149 151
 	}
150 152
 }