~rabbits/uxn

uxn/examples/devmouse.usm -rw-r--r-- 3.7 KiB
54da651cneauoire Added hover example 5 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
( mouse )

:dev/r fff8 ( std read port )
:dev/w fff9 ( std write port )

&Point2d { x 2 y 2 }

;mouse Point2d
;cat Point2d

;state 1 ;timer 1

|0100 @RESET 
	
	#01 =dev/r ( set dev/read screen )

	( position cat )
	#00 IOR2 #0002 DIV2 =cat.x 
	#02 IOR2 #0038 SUB2 =cat.y

	#05 =dev/r ( set dev/read mouse )
	#02 =dev/w ( set dev/write to sprite ) 
	
	( draw polycat )
	,draw-polycat JSR

BRK

|c000 @FRAME

	( clear last cursor )
	#10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR
	( record mouse positions )
	#00 IOR2 =mouse.x #02 IOR2 =mouse.y
	( record mouse state )
	#04 IOR #11 ADD =state
	( detect click )
	#04 IOR #01 NEQ ,no-click ROT JMP? POP2
		#50 =timer
	@no-click
	( draw mouse )
	~state ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
	( animate )
	,animate-polycat JSR
	( update last pos )
	~timer #01 ADD =timer

BRK

@draw-polycat

	( ears )
	,polycat ~cat.x ~cat.y ,draw-sprite-chr JSR
	,polycat #0010 ADD2 ~cat.x #0008 ADD2 ~cat.y ,draw-sprite-chr JSR
	( eye )
	,polycat #0020 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
	,polycat #0030 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
	( body )
	,polycat #00a0 ADD2 ~cat.x ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
	,polycat #00b0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR

RTS

@animate-polycat

	( tail )
	~timer #50 NEQ ,animate-polycat-tail-next0 ROT JMP? POP2
		,polycat #00c0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
	@animate-polycat-tail-next0
	~timer #58 NEQ ,animate-polycat-tail-next1 ROT JMP? POP2
		,polycat #00d0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
	@animate-polycat-tail-next1
	~timer #60 NEQ ,animate-polycat-tail-next2 ROT JMP? POP2
		,polycat #00b0 ADD2 ~cat.x #0008 ADD2 ~cat.y #0010 ADD2 ,draw-sprite-chr JSR
	@animate-polycat-tail-next2
	( look-at )
	~mouse.x ~cat.x #0008 ADD2 GTH2 ,animate-polycat-right ROT JMP? POP2
	@animate-polycat-left
		~mouse.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-left-down ROT JMP? POP2
		@animate-polycat-left-up 
			,polycat #0040 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
			,polycat #0050 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
		RTS
		@animate-polycat-left-down 
			,polycat #0020 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
			,polycat #0030 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
		RTS
	@animate-polycat-right
		~mouse.y ~cat.y #0008 ADD2 GTH2 ,animate-polycat-right-down ROT JMP? POP2
		@animate-polycat-right-up 
			,polycat #0060 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
			,polycat #0070 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
		RTS
		@animate-polycat-right-down 
			,polycat #0080 ADD2 ~cat.x ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
			,polycat #0090 ADD2 ~cat.x #0008 ADD2 ~cat.y #0008 ADD2 ,draw-sprite-chr JSR
		RTS

RTS

@draw-sprite
	IOW2 ( y byte )
	IOW2 ( x byte )
	IOW2 ( sprite address )
	IOW ( layer-color )
	RTS

@draw-sprite-chr
	IOW2 ( y byte )
	IOW2 ( x byte )
	IOW2 ( sprite address )
	#20 IOW ( layer-color )
	RTS

@clear_icn   [ 0000 0000 0000 0000 ]
@cursor_icn  [ 80c0 e0f0 f8e0 1000 ]

@polycat [
	081c 3e3e 7f7f ffff 081c 3e3e 7f7f fffc
	081c 3c3e 7e7e ffff 081c 3c3e 7e7e ff1f
	ffff ffff ff7f 3f0f f0e7 cfef f77c 3f0f
	ffff ffff fffe fcf0 0783 c1c3 871e fcf0
	ffff ffff ff7f 3f0f f7ef cfe7 f07c 3f0f
	ffff ffff fffe fcf0 87c3 c183 071e fcf0
	ffff ffff ff7f 3f0f f0e1 c1e0 f07c 3f0f
	ffff ffff fffe fcf0 f7fb f9f3 071e fcf0
	ffff ffff ff7f 3f0f f0e0 c1e1 f07c 3f0f
	ffff ffff fffe fcf0 07f3 f9fb f71e fcf0
	0307 0707 0302 0200 0307 0707 0300 0000
	c0f0 f0e0 e080 8000 c0f2 f9f9 fef8 b000
	c0f0 f0e0 e080 8000 c0f2 faf9 fef8 b000
	c0f0 f0e0 e080 8000 c0f1 faf9 fef8 b000
]

|d000 @ERROR BRK 
|FFF0 [ 0f85 0fd5 0fb5 ] ( palette )
|FFFA .RESET .FRAME .ERROR