Browse code

Fixed issue with dev/ctrl

neauoire authored on 28/02/2021 17:40:19
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 examples/dev.mouse.usm bin/boot.rom
23
+./bin/assembler examples/dev.ctrl.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
... ...
@@ -304,18 +304,16 @@ doctrl(Uxn *u, SDL_Event *event, int z)
304 304
 	Uint16 addr = devctrl->addr;
305 305
 	if(z && event->key.keysym.sym == SDLK_h && SDL_GetModState() & KMOD_LCTRL)
306 306
 		GUIDES = !GUIDES;
307
-	if(SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL)
308
-		flag = 0x01;
309
-	if(SDL_GetModState() & KMOD_LALT || SDL_GetModState() & KMOD_RALT)
310
-		flag = 0x02;
311 307
 	switch(event->key.keysym.sym) {
308
+	case SDLK_LCTRL: flag = 0x01; break;
309
+	case SDLK_LALT: flag = 0x02; break;
312 310
 	case SDLK_BACKSPACE:
313 311
 		flag = 0x04;
314
-		if(z) u->ram.dat[0xff40] = 0x08;
312
+		if(z) u->ram.dat[devkey->addr] = 0x08;
315 313
 		break;
316 314
 	case SDLK_RETURN:
317 315
 		flag = 0x08;
318
-		if(z) u->ram.dat[0xff40] = 0x0d;
316
+		if(z) u->ram.dat[devkey->addr] = 0x0d;
319 317
 		break;
320 318
 	case SDLK_UP: flag = 0x10; break;
321 319
 	case SDLK_DOWN: flag = 0x20; break;
... ...
@@ -9,47 +9,39 @@ file_extensions:
9 9
 scope: source.usm
10 10
 
11 11
 contexts:
12
-  prototype:
13
-    - include: comments
14
-
15 12
   main:
16
-    - include: keywords
17
-    - include: numbers
18
-    - include: strings
19
-
20
-  numbers:
21
-    - match: '\|(\S+)\s?'
22
-      scope: punctuation.definition
23
-      pop: true
24
-    - match: '\_(\S+)\s?'
25
-      scope: punctuation.definition
26
-      pop: true
27
-    - match: '\+(\S+)\s?'
28
-      scope: keyword.control
29
-      pop: true
30
-    - match: '\-(\S+)\s?'
31
-      scope: keyword.control
32
-      pop: true
33
-    - match: '\~(\S+)\s?'
34
-      scope: keyword.control
35
-      pop: true
36
-    - match: '\=(\S+)\s?'
37
-      scope: keyword.control
38
-      pop: true
39
-
40
-  strings:
41
-    - match: '\:(\S+)\s?'
13
+    # pointer
14
+    - match: '\@(\S+)\s?'
42 15
       scope: string.control
43 16
       pop: true
17
+    # jump
18
+    - match: '\|(\S+)\s?'
19
+      scope: variable.control
20
+      pop: true
21
+    # variables
44 22
     - match: '\;(\S+)\s?'
45 23
       scope: string.control
46 24
       pop: true
47
-    - match: '\@(\S+)\s?'
25
+    # constants
26
+    - match: '\:(\S+)\s?'
48 27
       scope: string.control
49 28
       pop: true
29
+    # structs
50 30
     - match: '\&(\S+)\s?'
51 31
       scope: string.control
52 32
       pop: true
33
+
34
+    # Special
35
+
36
+    - match: '\~(\S+)\s?'
37
+      scope: entity.name.type
38
+      pop: true
39
+    - match: '\=(\S+)\s?'
40
+      scope: entity.name.type
41
+      pop: true
42
+
43
+    # Pushing to stack
44
+
53 45
     - match: '\,(\S+)\s?'
54 46
       scope: keyword.control
55 47
       pop: true
... ...
@@ -58,21 +50,31 @@ contexts:
58 50
       pop: true
59 51
     - match: '\.(\S+)\s?'
60 52
       scope: keyword.control
53
+    - match: '\+(\S+)\s?'
54
+      scope: string.control
61 55
       pop: true
62
-    - match: '\"(\S+)\s?'
63
-      scope: keyword.control
64
-      pop: true
65
-    - match: '\['
66
-      scope: punctuation.definition.keyword.usm
56
+    - match: '\-(\S+)\s?'
57
+      scope: string.control
58
+
59
+      # Blocks
60
+
61
+    - match: '\{'
62
+      scope: variable.control
67 63
       push:
68
-        - meta_scope: keyword.line.double-slash.usm
69
-        - match: '\]'
64
+        - meta_scope: variable.control
65
+        - match: '\}'
70 66
           pop: true
71 67
 
72
-  comments:
73 68
     - match: '\('
74
-      scope: punctuation.definition.comment.usm
69
+      scope: comment
75 70
       push:
76
-        - meta_scope: comment.line.double-slash.usm
71
+        - meta_scope: comment.line
77 72
         - match: '\)'
78 73
           pop: true
74
+
75
+    - match: '\['
76
+      scope: keyword
77
+      push:
78
+        - meta_scope: keyword.line
79
+        - match: '\]'
80
+          pop: true
... ...
@@ -4,58 +4,70 @@
4 4
 &Sprite     { pad 8 x 2 y 2 addr 2 color 1 }
5 5
 &Controller { buttons 1 }
6 6
 
7
-&Point2d { x 2 y 2 }
8
-
9
-;pos Point2d 
10
-;sprite 2
7
+;slime-color 1
11 8
 
12 9
 |0100 @RESET 
13 10
 
14 11
 	( set origin )
15
-	~dev/screen.width #0002 DIV2 =pos.x 
16
-	~dev/screen.height #0002 DIV2 =pos.y
17
-
18
-	#12 ,up_icn ~pos.y ~pos.x ,draw-sprite JSR
12
+	~dev/screen.width #0002 DIV2 =dev/sprite.x 
13
+	~dev/screen.height #0002 DIV2 =dev/sprite.y
14
+	,default_icn =dev/sprite.addr
15
+	#11 =dev/sprite.color
16
+	#0a =slime-color
19 17
 
20 18
 BRK
21 19
 
22 20
 |c000 @FRAME 
21
+	
22
+	#0a =slime-color
23
+	( hold ctrl key to change slime color )
24
+	,no-ctrl ~dev/ctrl.buttons #0f AND #01 NEQ JMP? POP2
25
+		#05 =slime-color
26
+	@no-ctrl
27
+	( hold alt key to change slime color )
28
+	,no-alt ~dev/ctrl.buttons #0f AND #02 NEQ JMP? POP2
29
+		#0f =slime-color
30
+	@no-alt
31
+	( detect movement )
32
+	,no-up ~dev/ctrl.buttons #f0 AND #10 NEQ JMP? POP2
33
+		( clear ) #10 =dev/sprite.color
34
+		( move ) ~dev/sprite.y #0001 SUB2 =dev/sprite.y ,up_icn =dev/sprite.addr
35
+		( draw ) ,redraw JSR BRK
36
+	@no-up
37
+	,no-down ~dev/ctrl.buttons #f0 AND #20 NEQ JMP? POP2
38
+		( clear ) #10 =dev/sprite.color
39
+		( move ) ~dev/sprite.y #0001 ADD2 =dev/sprite.y ,down_icn =dev/sprite.addr
40
+		( draw ) ,redraw JSR BRK
41
+	@no-down
42
+	,no-left ~dev/ctrl.buttons #f0 AND #40 NEQ JMP? POP2
43
+		( clear ) #10 =dev/sprite.color
44
+		( move ) ~dev/sprite.x #0001 SUB2 =dev/sprite.x ,left_icn =dev/sprite.addr
45
+		( draw ) ,redraw JSR BRK
46
+	@no-left
47
+	,no-right ~dev/ctrl.buttons #f0 AND #80 NEQ JMP? POP2
48
+		( clear ) #10 =dev/sprite.color
49
+		( move ) ~dev/sprite.x #0001 ADD2 =dev/sprite.x ,right_icn =dev/sprite.addr
50
+		( draw ) ,redraw JSR BRK
51
+	@no-right
23 52
 
24
-	,default_icn =sprite
53
+BRK
25 54
 
26
-	~dev/ctrl.buttons #10 NEQ ,next1 ROT JMP? POP2
27
-		,up_icn =sprite
28
-		~pos.y #0001 SUB2 =pos.y
29
-	@next1
30
-	~dev/ctrl.buttons #20 NEQ ,next2 ROT JMP? POP2
31
-		,down_icn =sprite
32
-		~pos.y #0001 ADD2 =pos.y
33
-	@next2
34
-	~dev/ctrl.buttons #40 NEQ ,next3 ROT JMP? POP2
35
-		,left_icn =sprite
36
-		~pos.x #0001 SUB2 =pos.x
37
-	@next3
38
-	~dev/ctrl.buttons #80 NEQ ,end ROT JMP? POP2
39
-		,right_icn =sprite
40
-		~pos.x #0001 ADD2 =pos.x
41
-	@end
42
-	( redraw )
43
-	#13 ~sprite ~pos.y ~pos.x ,draw-sprite JSR
55
+@redraw
56
+	
57
+	( draw face )
58
+	#11 =dev/sprite.color
59
+	( draw slime )
60
+	,slime_icn =dev/sprite.addr
61
+	~slime-color =dev/sprite.color
44 62
 
45
-BRK
63
+RTS
46 64
 
47 65
 @default_icn [ 3c7e ffdb ffe7 7e3c ]
48 66
 @up_icn      [ 2466 e7db ffff 7e3c ]
49 67
 @down_icn    [ 3c7e ffff dbe7 6624 ]
50 68
 @left_icn    [ 3c7e ef1f 1fef 7e3c ]
51 69
 @right_icn   [ 3c7e f7f8 f8f7 7e3c ]
52
-
53
-@draw-sprite
54
-	=dev/sprite.x
55
-	=dev/sprite.y
56
-	=dev/sprite.addr
57
-	=dev/sprite.color
58
-	RTS
70
+@slime_icn   [ 0000 183c 3c18 0000 ]
59 71
 
60 72
 |d000 @ERROR BRK 
61 73
 
... ...
@@ -63,5 +75,5 @@ BRK
63 75
 |FF20 ;dev/sprite Sprite
64 76
 |FF30 ;dev/ctrl   Controller
65 77
 
66
-|FFF0 [ 02ac 05bb 0b53 ] ( palette )
78
+|FFF0 [ 0daf 02ff 035f ] ( palette )
67 79
 |FFFA .RESET .FRAME .ERROR
... ...
@@ -4,6 +4,7 @@
4 4
 :dev/w fff9 ( std write port )
5 5
 
6 6
 &Point2d { x 2 y 2 }
7
+
7 8
 ;mouse Point2d
8 9
 ;state 1 ;color 1 ;brush 2
9 10