Browse code

Added polycat

neauoire authored on 20/02/2021 22:07:20
Showing 6 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/devctrl.usm bin/boot.rom
23
+./bin/assembler examples/devmouse.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
... ...
@@ -99,8 +99,8 @@ paintchr(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite)
99 99
 	Uint16 v, h;
100 100
 	for(v = 0; v < 8; v++)
101 101
 		for(h = 0; h < 8; h++) {
102
-			Uint8 ch1 = ((sprite[v] >> h) & 0x1);
103
-			Uint8 ch2 = (((sprite[v + 8] >> h) & 0x1) << 1);
102
+			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
103
+			Uint8 ch2 = (((sprite[v + 8] >> (7 - h)) & 0x1) << 1);
104 104
 			paintpixel(dst, x + h, y + v, ch1 + ch2);
105 105
 		}
106 106
 }
... ...
@@ -266,8 +266,14 @@ domouse(SDL_Event *event)
266 266
 	devmouse->mem[4] = event->button.button == SDL_BUTTON_LEFT;
267 267
 	devmouse->mem[5] = 0x00;
268 268
 	switch(event->type) {
269
-	case SDL_MOUSEBUTTONUP: devmouse->mem[5] = 0x10; break;
270
-	case SDL_MOUSEBUTTONDOWN: devmouse->mem[5] = 0x01; break;
269
+	case SDL_MOUSEBUTTONUP:
270
+		devmouse->mem[4] = 0;
271
+		devmouse->mem[5] = 0x10;
272
+		break;
273
+	case SDL_MOUSEBUTTONDOWN:
274
+		devmouse->mem[4] = event->button.button == SDL_BUTTON_LEFT;
275
+		devmouse->mem[5] = 0x01;
276
+		break;
271 277
 	}
272 278
 }
273 279
 
274 280
new file mode 100644
... ...
@@ -0,0 +1,132 @@
1
+( mouse )
2
+
3
+:dev/r fff8 ( std read port )
4
+:dev/w fff9 ( std write port )
5
+
6
+;mousex 2 ;mousey 2 
7
+;lastx 2  ;lasty 2 
8
+;catx 2 ;caty 2
9
+;state 1 ;timer 1
10
+
11
+|0100 @RESET 
12
+	
13
+	#05 =dev/r ( set dev/read mouse )
14
+	#02 =dev/w ( set dev/write to sprite ) 
15
+	( position cat )
16
+	#0050 =catx #0058 =caty
17
+	( draw polycat )
18
+	,draw-polycat JSR
19
+
20
+BRK
21
+
22
+|c000 @FRAME
23
+
24
+	( clear last cursor )
25
+	#10 ,clear_icn ~lastx ~lasty ,draw-sprite JSR
26
+	( record mouse positions )
27
+	#00 IOR2 =mousex #02 IOR2 =mousey
28
+	( record mouse state )
29
+	#04 IOR #11 ADD =state
30
+
31
+	#04 IOR #01 NEQ ,no-click ROT JMP? POP2
32
+		#50 =timer
33
+	@no-click
34
+
35
+	( draw mouse )
36
+	~state ,cursor_icn ~mousex ~mousey ,draw-sprite JSR
37
+	( animate )
38
+	,animate-polycat JSR
39
+	( update last pos )
40
+	~mousex =lastx ~mousey =lasty 
41
+	~timer #01 ADD =timer
42
+
43
+BRK
44
+
45
+@draw-polycat
46
+
47
+	( ears )
48
+	,polycat ~catx ~caty ,draw-sprite-chr JSR
49
+	,polycat #0010 ADD2 ~catx #0008 ADD2 ~caty ,draw-sprite-chr JSR
50
+	( eye )
51
+	,polycat #0020 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
52
+	,polycat #0030 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
53
+	( body )
54
+	,polycat #00a0 ADD2 ~catx ~caty #0010 ADD2 ,draw-sprite-chr JSR
55
+	,polycat #00b0 ADD2 ~catx #0008 ADD2 ~caty #0010 ADD2 ,draw-sprite-chr JSR
56
+
57
+RTS
58
+
59
+@animate-polycat
60
+
61
+	( tail )
62
+	~timer #50 NEQ ,animate-polycat-tail-next0 ROT JMP? POP2
63
+		,polycat #00c0 ADD2 ~catx #0008 ADD2 ~caty #0010 ADD2 ,draw-sprite-chr JSR
64
+	@animate-polycat-tail-next0
65
+	~timer #58 NEQ ,animate-polycat-tail-next1 ROT JMP? POP2
66
+		,polycat #00d0 ADD2 ~catx #0008 ADD2 ~caty #0010 ADD2 ,draw-sprite-chr JSR
67
+	@animate-polycat-tail-next1
68
+	~timer #60 NEQ ,animate-polycat-tail-next2 ROT JMP? POP2
69
+		,polycat #00b0 ADD2 ~catx #0008 ADD2 ~caty #0010 ADD2 ,draw-sprite-chr JSR
70
+	@animate-polycat-tail-next2
71
+	( look-at )
72
+	~mousex ~catx #0008 ADD2 GTH2 ,animate-polycat-right ROT JMP? POP2
73
+	@animate-polycat-left
74
+		~mousey ~caty #0008 ADD2 GTH2 ,animate-polycat-left-down ROT JMP? POP2
75
+		@animate-polycat-left-up 
76
+			,polycat #0040 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
77
+			,polycat #0050 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
78
+		RTS
79
+		@animate-polycat-left-down 
80
+			,polycat #0020 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
81
+			,polycat #0030 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
82
+		RTS
83
+	@animate-polycat-right
84
+		~mousey ~caty #0008 ADD2 GTH2 ,animate-polycat-right-down ROT JMP? POP2
85
+		@animate-polycat-right-up 
86
+			,polycat #0060 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
87
+			,polycat #0070 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
88
+		RTS
89
+		@animate-polycat-right-down 
90
+			,polycat #0080 ADD2 ~catx ~caty #0008 ADD2 ,draw-sprite-chr JSR
91
+			,polycat #0090 ADD2 ~catx #0008 ADD2 ~caty #0008 ADD2 ,draw-sprite-chr JSR
92
+		RTS
93
+
94
+RTS
95
+
96
+@draw-sprite
97
+	IOW2 ( y byte )
98
+	IOW2 ( x byte )
99
+	IOW2 ( sprite address )
100
+	IOW ( layer-color )
101
+	RTS
102
+
103
+@draw-sprite-chr
104
+	IOW2 ( y byte )
105
+	IOW2 ( x byte )
106
+	IOW2 ( sprite address )
107
+	#08 IOW ( layer-color )
108
+	RTS
109
+
110
+@clear_icn   [ 0000 0000 0000 0000 ]
111
+@cursor_icn  [ 80c0 e0f0 f8e0 1000 ]
112
+
113
+@polycat [
114
+	0081c 3e3e 7f7f ffff 081c 3e3e 7f7f fffc
115
+	081c 3c3e 7e7e ffff 081c 3c3e 7e7e ff1f
116
+	ffff ffff ff7f 3f0f f0e7 cfef f77c 3f0f
117
+	ffff ffff fffe fcf0 0783 c1c3 871e fcf0
118
+	ffff ffff ff7f 3f0f f7ef cfe7 f07c 3f0f
119
+	ffff ffff fffe fcf0 87c3 c183 071e fcf0
120
+	ffff ffff ff7f 3f0f f0e1 c1e0 f07c 3f0f
121
+	ffff ffff fffe fcf0 f7fb f9f3 071e fcf0
122
+	ffff ffff ff7f 3f0f f0e0 c1e1 f07c 3f0f
123
+	ffff ffff fffe fcf0 07f3 f9fb f71e fcf0
124
+	0307 0707 0302 0200 0307 0707 0300 0000
125
+	c0f0 f0e0 e080 8000 c0f2 f9f9 fef8 b000
126
+	c0f0 f0e0 e080 8000 c0f2 faf9 fef8 b000
127
+	c0f0 f0e0 e080 8000 c0f1 faf9 fef8 b000
128
+]
129
+
130
+|d000 @ERROR BRK 
131
+|FFF0 [ 0f85 0fd5 0fb5 ] ( palette )
132
+|FFFA .RESET .FRAME .ERROR
0 133
similarity index 100%
1 134
rename from examples/drag.usm
2 135
rename to examples/devmousedrag.usm
3 136
deleted file mode 100644
... ...
@@ -1,41 +0,0 @@
1
-( mouse )
2
-
3
-:dev/r fff8 ( std read port )
4
-:dev/w fff9 ( std write port )
5
-
6
-|0100 @RESET 
7
-	
8
-	#05 =dev/r ( set dev/read mouse#02 )
9
-	#01 =dev/w ( set dev/write screen#01 )
10
-
11
-BRK
12
-
13
-|c000 @FRAME
14
-
15
-	( get mouse button, or break )
16
-	#04 IOR
17
-	#01 NEQ
18
-	BRK?
19
-		
20
-	( paint a white pixel )
21
-	#01 #01 
22
-	,getmouse JSR
23
-	,putpixel JSR
24
-
25
-BRK
26
-
27
-@getmouse
28
-	#00 IOR2 ( get mouse x )
29
-	#02 IOR2 ( get mouse y )
30
-	RTS
31
-
32
-@putpixel 
33
-	IOW2 ( y short )
34
-	IOW2 ( x short )
35
-	IOW ( color byte )
36
-	IOW ( redraw byte )
37
-	RTS
38
-
39
-|d000 @ERROR BRK 
40
-|FFF0 [ f2ac 35bb 2b53 ] ( palette )
41
-|FFFA .RESET .FRAME .ERROR
42 0
deleted file mode 100644
... ...
@@ -1,59 +0,0 @@
1
-( sprite )
2
-
3
-:dev/r fff8 ( std read port )
4
-:dev/w fff9 ( std write port )
5
-
6
-;mousex 2 ;mousey 2 ;lastx 2 ;lasty 2 ;color 1
7
-
8
-|0100 @RESET 
9
-
10
-	#05 =dev/r ( set dev/read mouse )
11
-	#02 =dev/w ( set dev/write to sprite ) 
12
-
13
-	#00 ,rounds_chr #0004 #0004 ,drawsprite JSR
14
-
15
-BRK
16
-
17
-|c000 @FRAME
18
-	
19
-	#02 =dev/w ( set dev/write to sprite ) 
20
-
21
-	( clear last cursor )
22
-	#10 ,clear_icn ~lastx ~lasty ,drawsprite JSR
23
-
24
-	( record mouse values )
25
-	#00 IOR2 =mousex #02 IOR2 =mousey
26
-	#04 IOR #11 ADD =color
27
-
28
-	~color ,cursor_icn ~mousex ~mousey ,drawsprite JSR
29
-
30
-	( check paint )
31
-	#04 IOR #00 EQU ,skip ROT JMP? POP2
32
-	#05 ,brush_large ~mousex #0004 SUB2 ~mousey #0004 SUB2 ,drawsprite JSR
33
-	@skip
34
-
35
-	~mousex =lastx ~mousey =lasty
36
-
37
-BRK
38
-
39
-@drawsprite
40
-	IOW2 ( y byte )
41
-	IOW2 ( x byte )
42
-	IOW2 ( sprite address )
43
-	IOW ( layer-color )
44
-	RTS
45
-
46
-|0200 @SPRITESHEET
47
-
48
-@rounds_chr [ 3844 92aa 9244 3800 0038 7c7c 7c38 0000 ]
49
-@cursor_icn [ 80c0 e0f0 f8e0 1000 ]
50
-@clear_icn [ 0000 0000 0000 0000 ]
51
-@brush_large [ 387c fefe fe7c 3800 ]
52
-@brush_small [ 0038 7c7c 7c38 0000 ]
53
-
54
-BRK
55
-
56
-|d000 @ERROR BRK 
57
-
58
-|FFF0 [ f2ac 35bb 2b53 ] ( palette )
59
-|FFFA .RESET .FRAME .ERROR