~rabbits/orca-toy

ref: 7ade8024516a1f776c18b943c73126b3d021612f orca-toy/src/manifest.tal -rw-r--r-- 7.0 KiB
7ade8024Devine Lu Linvega Removed extra macros 3 months 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
( manifest )

@trap-menu ( -> )

	;on-mouse-menu .Mouse/vector DEO2
	;on-control-menu .Controller/vector DEO2

	#40 ;draw-cursor JSR2

BRK

@on-mouse-menu ( -> )

	#40 ;draw-cursor JSR2
	( record mouse positions )
	.Mouse/x DEI2 DUP2 .cursor/x STZ2 .Screen/x DEO2
	.Mouse/y DEI2 DUP2 .cursor/y STZ2 .Screen/y DEO2
	( draw new cursor )
	;hand-icn .Screen/addr DEO2
	#42 .Mouse/state DEI #00 NEQ ADD .Screen/sprite DEO
	( when touch cat )
	.Mouse/state DEI #00 EQU ,&no-touch-cat JCN
	.Mouse/y DEI2 #0014 GTH2 ,&no-touch-cat JCN
		.Mouse/x DEI2 ;get-xcat JSR2 ;menu-select JSR2
		( release ) #00 .Mouse/state DEO
		BRK
		&no-touch-cat
	( when sub active )
	;draw-menu/sel LDA #ff EQU ,&no-sub JCN
		( when sel changed )
		.Mouse/y DEI2 #0004 SUB2 #04 SFT2 NIP #01 SUB
		DUP ;draw-sub/sel LDA EQU ,&no-change JCN
			DUP ;draw-sub/sel STA
			;draw-menu/sel LDA #ff ;draw-sub JSR2
			&no-change
		POP
		( when touch sub )
		.Mouse/state DEI #00 EQU ,&no-touch-sub JCN
			;draw-sub/sel LDA ;menu-select-sub JSR2
			( release ) #00 .Mouse/state DEO
			&no-touch-sub
		BRK
		&no-sub
	( don't leave if menu is active )
	;draw-menu/sel LDA #ff NEQ ,&no-leave JCN
	.Mouse/y DEI2 #0014 LTH2 ,&no-leave JCN
		,menu-close JSR
		&no-leave

BRK

@menu-close ( -- )

	;untrap JSR2
	;draw-menu/sel LDA
	DUP #ff EQU ,&no-clear JCN
		DUP #00 ;draw-sub JSR2
		#ff ;draw-menu/sel STA
		;redraw-all JSR2
		;draw-menu JSR2
	&no-clear
	POP

JMP2r

@menu-select ( cat -- )

	( exists )
	DUP ;get-cat JSR2 ORA ,&exists JCN
		POP JMP2r
		&exists
	( clear )
	;draw-menu/sel LDA
	( unchanged ) EQUk ,menu-deselect JCN
	( unselected ) DUP #ff EQU ,&no-clear JCN
		DUP #00 ;draw-sub JSR2
		&no-clear
	POP
	( draw )
	;redraw-all JSR2
	#ff ;draw-sub/sel STA
	DUP ;draw-menu/sel STA
	#ff ;draw-sub JSR2
	;draw-menu ( .. )

JMP2

@menu-deselect ( cat cat -- )

	POP2 ;menu-close ( .. )

JMP2

@menu-select-sub ( sub -- )

	;get-sub JSR2
	;menu-close JSR2
	ORAk ROT ROT JCN2

JMP2r

@on-control-menu ( -> )

	( TODO )

BRK

@get-cat ( cat -- cat* )

	STH
	#00 ,&id STR
	;draw-menu/manifest LDA2
	&cat
		[ LIT &id 00 ] STHkr EQU ,&end JCN
		;skip-sub JSR2
		,&id LDR INC ,&id STR
		LDAk ,&cat JCN
	POP2
	#0000
	&end
	POPr

JMP2r

@get-sub ( sub -- sub* )

	STH
	;draw-menu/sel LDA ;get-cat JSR2
	LDAk STH INC2 ;skip-str JSR2
	STHr #00
	&subcat
		DUP STHkr EQU ,&end JCN
		SWP2 #0004 ADD2 ;skip-str JSR2 SWP2
		INC GTHk ,&subcat JCN
	POP2 POP2
	( TODO: merge tails )
	POPr
	#0000
	JMP2r
	&end
	POP2
	INC2 INC2 LDA2
	POPr

JMP2r

@get-catx ( cat -- x* )

	LIT2r 0000
	,&target STR
	#00 ,&id STR
	;draw-menu/manifest LDA2
	&cat
		[ LIT &id 00 ] [ LIT &target $1 ] EQU ,&end JCN
		INC2k ;get-strw JSR2 #0008 ADD2 STH2 ADD2r
		;skip-sub JSR2
		,&id LDR INC ,&id STR
		LDAk ,&cat JCN
	POP2
	&end
	STH2r
	#0010 ADD2

JMP2r

@get-xcat ( x* -- <cat> )

	#0010 SUB2
	LIT2r 0000
	,&target STR2
	#00 ,&id STR
	;draw-menu/manifest LDA2
	&cat
		INC2k ;get-strw JSR2 #0008 ADD2 STH2r ADD2
		DUP2 [ LIT2 &target $2 ] LTH2 ,&continue JCN
			POP2 POP2 [ LIT &id 00 ] JMP2r
			&continue
			STH2
		;skip-sub JSR2
		,&id LDR INC ,&id STR
		LDAk ,&cat JCN
	POP2
	POP2r
	#ff

JMP2r

@find-modkey ( mod key -- fn* )

	ORAk ,&no-null JCN JMP2r &no-null
	( not null )
	,&mk STR2
	;draw-menu/manifest LDA2
	&cat
		LDAk STH INC2 ,skip-str JSR
		STHr #00
		&subcat
			OVR2 LDA2 [ LIT2 &mk $2 ] NEQ2 ,&continue JCN
				POP2 INC2 INC2 LDA2 JMP2r
				&continue
			SWP2 #0004 ADD2 ,skip-str JSR SWP2
			INC GTHk ,&subcat JCN
		POP2
		LDAk ,&cat JCN
	POP2
	#0000

JMP2r

@skip-sub ( sub* -- sub* )

	LDAk STH INC2 ;skip-str JSR2
	STHr #00
	&subcat
		SWP2 #0004 ADD2 ,skip-str JSR SWP2
		INC GTHk ,&subcat JCN
	POP2

JMP2r

@skip-str ( str* -- str* )

	&skip INC2 LDAk ,&skip JCN INC2

JMP2r

@draw-menu ( mask -- )

	#0010 .Screen/x DEO2
	#0004 .Screen/y DEO2
	#00 ,&id STR
	[ LIT2 &manifest :manifest ]
	&cat
		#0401 [ LIT &sel ff ] [ LIT &id $1 ] EQU [ JMP SWP POP ] ;draw-chr/color STA
		INC2k ;draw-str JSR2 POP2 #20 ;draw-chr JSR2
		;skip-sub JSR2
		,&id LDR INC ,&id STR
		LDAk ,&cat JCN
	POP2

JMP2r

@draw-sub ( cat mask -- )

	,&mask STR POP
	;draw-menu/sel LDA ;get-cat JSR2
	ORAk #00 EQU ,&skip JCN
	;draw-menu/sel LDA ;get-catx JSR2 ,&anchor STR2
	LDAk STH INC2 ;skip-str JSR2
	STHr #00
	&subcat
		STHk #0804 STHr [ LIT &sel ff ] EQU [ JMP SWP POP ] [ LIT &mask $1 ] AND ;draw-chr/color STA
		[ LIT2 &anchor $2 ] .Screen/x DEO2
		#00 OVR INC #40 SFT2 #0004 ADD2 .Screen/y DEO2
		SWP2 ;draw-label JSR2 SWP2
		INC GTHk ,&subcat JCN
	POP2 POP2
	&skip
	POP2

JMP2r

@draw-label ( label* -- next-label* )

	.Screen/x DEI2
	.Screen/y DEI2
		.Screen/auto DEI
			#f2 .Screen/auto DEO
			;blank-icn .Screen/addr DEO2
			;draw-chr/color LDA .Screen/sprite DEOk DEO
		.Screen/auto DEO
	.Screen/y DEO2
	( mod )
	STH2k #0078 ADD2 .Screen/x DEO2
	LDA2k ;get-modkey-str JSR2 ;draw-str-right JSR2 POP2
	STH2r .Screen/x DEO2
	#0004 ADD2 ;draw-str ( .. )

JMP2

@get-modkey-str ( mod key -- str* )

	;&buf #0008 ;mclr JSR2
	( mod )
	SWP STH
	#0800
	&loop
		STHkr OVR SFT #01 AND #00 EQU ,&no-button JCN
			#00 OVR ;&buttons ADD2 LDA ;&buf ;sput JSR2
			&no-button
		INC GTHk ,&loop JCN
	POP2
	( mix )
	DUP #00 NEQ STHr #00 NEQ #0101 NEQ2 ,&no-mod JCN
		LIT '+ ;&buf ;sput JSR2
		&no-mod
	( key )
	DUP #08 NEQ ,&no-bsp JCN ;&bsp ,&cat JMP &no-bsp
	DUP #09 NEQ ,&no-tab JCN ;&tab ,&cat JMP &no-tab
	DUP #0d NEQ ,&no-ent JCN ;&ent ,&cat JMP &no-ent
	DUP #20 NEQ ,&no-spc JCN ;&spc ,&cat JMP &no-spc
	DUP #1b NEQ ,&no-esc JCN ;&esc ,&cat JMP &no-esc
	DUP #7f NEQ ,&no-del JCN ;&del ,&cat JMP &no-del
	DUP ;&buf ;sput JSR2
	&end
	POP
	;&buf

JMP2r
	&buf $8
	&buttons "ABsSUDLR $1
	&cat ;&buf ;scat JSR2 ,&end JMP
	&bsp "bsp $1 &tab "tab $1 &ent "ent $1 &spc "spc $1 &esc "esc $1 &del "del $1

@update-cursor ( color addr* -- )

	#00 .Screen/auto DEO
	#40 ,draw-cursor JSR
	.Mouse/x DEI2 DUP2 .cursor/x STZ2 .Screen/x DEO2
	.Mouse/y DEI2 DUP2 .cursor/y STZ2 .Screen/y DEO2
	.Screen/addr DEO2
	.Screen/sprite DEO

JMP2r

@draw-cursor ( color -- )

	.cursor/x LDZ2 .Screen/x DEO2
	.cursor/y LDZ2 .Screen/y DEO2
	.Screen/sprite DEO

JMP2r

( theme )

@load-theme ( -- )

	;&path .File/name DEO2
	#0002 .File/length DEO2
	;&r .File/read DEO2
	;&g .File/read DEO2
	;&b .File/read DEO2
	.File/success DEI2 ORA #01 JCN JMP2r
	LIT2 &r $2 .System/r DEO2
	LIT2 &g $2 .System/g DEO2
	LIT2 &b $2 .System/b DEO2

JMP2r
	&path ".theme $1

(
@|stdlib )

@scap ( str* -- end* ) LDAk #00 NEQ JMP JMP2r &w INC2 LDAk ,&w JCN JMP2r
@spop ( str* -- ) LDAk ,&n JCN POP2 JMP2r &n ,scap JSR #0001 SUB2 #00 ROT ROT STA JMP2r
@sput ( chr str* -- ) ,scap JSR INC2k #00 ROT ROT STA STA JMP2r
@slen ( str* -- len* ) DUP2 ,scap JSR SWP2 SUB2 JMP2r
@scat ( src* dst* -- ) ,scap JSR
@scpy ( src* dst* -- ) STH2 &w LDAk STH2kr STA INC2r INC2 LDAk ,&w JCN POP2 #00 STH2r STA JMP2r
@mclr ( src* len* -- ) OVR2 ADD2 SWP2 &l STH2k #00 STH2r STA INC2 GTH2k ,&l JCN POP2 POP2 JMP2r

@print ( short* -- )

	SWP ,&byte JSR
	&byte ( byte -- ) DUP #04 SFT ,&char JSR
	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO

JMP2r

@exit ( -- )

	#010f DEO

JMP2r

( assets )

@hand-icn
	2020 20b8 7c7c 3838
@blank-icn
	0000 0000 0000 0000