Browse code

Rewrote the snake example

neauoire authored on 15/03/2021 00:32:40
Showing 2 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/left.usm bin/boot.rom
23
+./bin/assembler projects/examples/dev.controller.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
... ...
@@ -1,62 +1,57 @@
1 1
 ( Controller )
2 2
 
3
+%INCR2 { #0001 ADD2 }
4
+%DECR2 { #0001 SUB2 }
5
+%HALF2 { #0002 DIV2 }
6
+
3 7
 ;slime { color 1 }
4 8
 
5 9
 |0100 @RESET 
6 10
 	
7 11
 	( set origin )
8
-	~Screen.width #0002 DIV2 =Sprite.x 
9
-	~Screen.height #0002 DIV2 =Sprite.y
12
+	~Screen.width HALF2 =Sprite.x 
13
+	~Screen.height HALF2 =Sprite.y
10 14
 	,default_icn =Sprite.addr
11 15
 	#11 =Sprite.color
12 16
 	#0a =slime
13 17
 
14 18
 BRK
15 19
 
16
-|c000 @FRAME 
20
+@FRAME 
17 21
 	
22
+	~Controller.buttons #f0 AND #00 EQU BRK?
23
+
18 24
 	#0a =slime
25
+
19 26
 	( hold ctrl key to change slime color )
20
-	,no-ctrl ~Controller.buttons #0f AND #01 NEQ JMP2? POP2
21
-		#05 =slime
22
-	@no-ctrl
23
-	( hold alt key to change slime color )
24
-	,no-alt ~Controller.buttons #0f AND #02 NEQ JMP2? POP2
25
-		#0f =slime
26
-	@no-alt
27
-	( detect movement )
28
-	,no-up ~Controller.buttons #f0 AND #10 NEQ JMP2? POP2
29
-		( clear ) #10 =Sprite.color
30
-		( move ) ~Sprite.y #0001 SUB2 =Sprite.y ,up_icn =Sprite.addr
31
-		( draw ) ,redraw JSR2 BRK
32
-	@no-up
33
-	,no-down ~Controller.buttons #f0 AND #20 NEQ JMP2? POP2
34
-		( clear ) #10 =Sprite.color
35
-		( move ) ~Sprite.y #0001 ADD2 =Sprite.y ,down_icn =Sprite.addr
36
-		( draw ) ,redraw JSR2 BRK
37
-	@no-down
38
-	,no-left ~Controller.buttons #f0 AND #40 NEQ JMP2? POP2
39
-		( clear ) #10 =Sprite.color
40
-		( move ) ~Sprite.x #0001 SUB2 =Sprite.x ,left_icn =Sprite.addr
41
-		( draw ) ,redraw JSR2 BRK
42
-	@no-left
43
-	,no-right ~Controller.buttons #f0 AND #80 NEQ JMP2? POP2
44
-		( clear ) #10 =Sprite.color
45
-		( move ) ~Sprite.x #0001 ADD2 =Sprite.x ,right_icn =Sprite.addr
46
-		( draw ) ,redraw JSR2 BRK
47
-	@no-right
48 27
 
49
-BRK
28
+	~Controller.buttons #0f AND
29
+		DUP #01 NEQ ,$no-ctrl ROT JMP2? POP2 #05 =slime $no-ctrl
30
+		DUP #02 NEQ ,$no-alt ROT JMP2? POP2 #0f =slime $no-alt
31
+	POP
32
+
33
+	( clear ) #10 =Sprite.color
34
+
35
+	( detect movement )
36
+	~Controller.buttons #f0 AND
37
+		DUP #04 ROR #01 AND #01 NEQ ,$no-up ROT JMP2? POP2 
38
+			( move ) ~Sprite.y DECR2 =Sprite.y ,up_icn =Sprite.addr $no-up
39
+		DUP #05 ROR #01 AND #01 NEQ ,$no-down ROT JMP2? POP2 
40
+			( move ) ~Sprite.y INCR2 =Sprite.y ,down_icn =Sprite.addr $no-down
41
+		DUP #06 ROR #01 AND #01 NEQ ,$no-left ROT JMP2? POP2 
42
+			( move ) ~Sprite.x DECR2 =Sprite.x ,left_icn =Sprite.addr $no-left
43
+		DUP #07 ROR #01 AND #01 NEQ ,$no-right ROT JMP2? POP2 
44
+			( move ) ~Sprite.x INCR2 =Sprite.x ,right_icn =Sprite.addr $no-right
45
+	POP
50 46
 
51
-@redraw
52
-	
53 47
 	( draw face )
54 48
 	#11 =Sprite.color
49
+
55 50
 	( draw slime )
56 51
 	,slime_icn =Sprite.addr
57 52
 	~slime =Sprite.color
58 53
 
59
-RTN
54
+BRK
60 55
 
61 56
 @default_icn [ 3c7e ffdb ffe7 7e3c ]
62 57
 @up_icn      [ 2466 e7db ffff 7e3c ]
... ...
@@ -67,6 +62,7 @@ RTN
67 62
 
68 63
 |d000 @ERROR BRK 
69 64
 
65
+|FF00 ;Console { pad 8 char 1 byte 1 short 2 }
70 66
 |FF10 ;Screen { width 2 height 2 pad 4 y 2 x 2 color 1 }
71 67
 |FF20 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
72 68
 |FF30 ;Controller { buttons 1 }