~rabbits/uxn

uxn/projects/examples/demos/bifurcan.tal -rw-r--r-- 3.6 KiB
e00e74b9Andrew Alderwick (uxnasm) Raise an error if the output rom would be empty. 6 days 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
( Bifurcan )

|00 @System     [ &vector $2 &pad      $6 &r      $2 &g     $2 &b      $2 ]
|20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y      $2 &addr $2 &pixel $1 &sprite $1 ]
|90 @Mouse      [ &vector $2 &x        $2 &y      $2 &state $1 &wheel  $1 ]
|c0 @DateTime   [ &year   $2 &month    $1 &day    $1 &hour  $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
|80 @Controller [ &vector $2 &button   $1 &key    $1 ] 

|0000

@last  $1
@style $1
@pointer [ &x $2 &y $2 ]
@center  [ &x $2 &y $2 ]

|0100 ( -> )

	( theme ) 
	#0f3a .System/r DEO2 
	#0fda .System/g DEO2 
	#0faa .System/b DEO2
	( vectors )
	;on-frame .Screen/vector DEO2
	;on-mouse .Mouse/vector DEO2
	;on-button .Controller/vector DEO2
	( find center )
	.Screen/width DEI2 #01 SFT2 .center/x STZ2
	.Screen/height DEI2 #01 SFT2 .center/y STZ2
	( background ) 
	;tiles ;cover-pattern JSR2
	;redraw JSR2

BRK

@on-frame ( -> )

	( only draw once per second )
	.DateTime/second DEI .last LDZ NEQ JMP [ BRK ]
	.DateTime/second DEI .last STZ
	;redraw JSR2

BRK

@on-mouse ( -> )

	;draw-cursor JSR2

	.Mouse/state DEI #00 NEQ JMP BRK
	,select JSR

BRK 

@on-button ( -> )
	
	.Controller/button DEI #00 NEQ JMP BRK
	,select JSR

BRK

@select ( -- )

	( incr ) .style LDZ INC #03 ;mod JSR2 .style STZ
	( bg ) ;tiles [ #00 .style LDZ #40 SFT ] ADD2 ;cover-pattern JSR2
	( fg ) ;redraw JSR2
	( release ) #0000 .Mouse/state DEO .Controller/button DEO

JMP2r

@redraw ( -- )
	
	( hrs )
	[ .center/x LDZ2 #0018 SUB2 ] 
	[ .center/y LDZ2 #0048 SUB2 ] 
	.DateTime/hour DEI #0a DIV ;draw-number JSR2
	[ .center/x LDZ2 #0008 ADD2 ] 
	[ .center/y LDZ2 #0048 SUB2 ] 
	.DateTime/hour DEI #0a ;mod JSR2 ;draw-number JSR2
	( min )
	[ .center/x LDZ2 #0018 SUB2 ] 
	[ .center/y LDZ2 #0018 SUB2 ] 
	.DateTime/minute DEI #0a DIV ;draw-number JSR2
	[ .center/x LDZ2 #0008 ADD2 ] 
	[ .center/y LDZ2 #0018 SUB2 ] 
	.DateTime/minute DEI #0a ;mod JSR2 ;draw-number JSR2
	( sec )
	[ .center/x LDZ2 #0018 SUB2 ] 
	[ .center/y LDZ2 #0018 ADD2 ]
	.DateTime/second DEI #0a DIV 
	;draw-number JSR2
	[ .center/x LDZ2 #0008 ADD2 ] 
	[ .center/y LDZ2 #0018 ADD2 ] 
	.DateTime/second DEI #0a ;mod JSR2 
	;draw-number JSR2

JMP2r

@draw-number ( x* y* n -- )
	
	,&digit STR ,&y STR2 ,&x STR2
	#0f00 
	&loop
		( save-x ) DUP #03 ;mod JSR2 #00 SWP #30 SFT2 [ LIT2 &x $2 ] ADD2 .Screen/x DEO2
		( save-y ) DUP #03 DIV #00 SWP #30 SFT2 [ LIT2 &y $2 ] ADD2 .Screen/y DEO2
		( get digit* ) DUP [ LIT &digit $1 ] DUP ADD #00 SWP ;digits ADD2 LDA2 
		( get bit ) ROT #0e SWP SUB SFT2 #0001 AND2 
		( set tile ) #30 SFT2 ;tiles ADD2 
		( set style ) .style LDZ #40 SFT #00 SWP ADD2
			.Screen/addr DEO2
		( draw ) #01 .Screen/sprite DEO
		INC GTHk ,&loop JCN
	POP2

JMP2r

@cover-pattern ( addr* -- )
	
	.Screen/addr DEO2
	.Screen/height DEI2 #03 SFT2 NIP ,&h STR
	.Screen/width DEI2 #03 SFT2 NIP ,&w STR
	[ LIT &h $1 ] #00
	&ver
		#00 OVR #30 SFT2 .Screen/y DEO2
		[ LIT &w $1 ] #00
		&hor
			#00 OVR #30 SFT2 .Screen/x DEO2
			#01 .Screen/sprite DEO
			INC GTHk ,&hor JCN
		POP2
		INC GTHk ,&ver JCN
	POP2

JMP2r

@draw-cursor ( -- )
	
	( clear last cursor )
	;cursor .Screen/addr DEO2 
	.pointer/x LDZ2 .Screen/x DEO2 
	.pointer/y LDZ2 .Screen/y DEO2 
	#40 .Screen/sprite DEO
	( record pointer positions )
	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 
	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2 
	( colorize on state )
	#41 [ .Mouse/state DEI #00 NEQ ] ADD .Screen/sprite DEO

JMP2r

@mod DUP2 DIV MUL SUB JMP2r

@cursor 
	80c0 e0f0 f8e0 1000

@digits
	7b6f 2492 73e7 73cf 
	5bc9 79cf 49ef 7249 
	7bef 7bc9

@tiles
	0102 0408 1020 4080
	8040 2010 0804 0201 
	0718 2040 4080 8080
	0101 0102 0204 18e0
	0808 0810 e304 0808
	0808 0804 e310 0808