~rabbits/dexe

ref: 8cbb2684e4178edb1427689f7d7960d9425a7243 dexe/src/main.tal -rw-r--r-- 7.3 KiB
8cbb2684neauoire Starting controls 2 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
(
	app/dexe : hex editor
	
	arrows     - move selection
	enter      - insert byte
	backspace  - delete byte
	left-click - select bytes

	TODO:
		copy/paste
		scrollbar
)

%+  { ADD } %-   { SUB }  %*  { MUL } %/   { DIV }
%<  { LTH } %>   { GTH }  %=  { EQU } %!   { NEQ }
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }

%DEBUG  { ;print-hex/byte JSR2 #0a .Console/write DEO }
%DEBUG2 { ;print-hex/short JSR2 #0a .Console/write DEO }

%RTN  { JMP2r }
%SWP2? { #01 JCN SWP }
%BRK? { #01 JCN BRK }

%2*   { #10 SFT }
%8*   { #30 SFT }
%20*  { #50 SFT } 
%40*  { #60 SFT }
%2**  { #10 SFT2 } %2// { #01 SFT2 }
%4**  { #20 SFT2 } %4// { #02 SFT2 }
%8**  { #30 SFT2 } %8// { #03 SFT2 }
%10** { #40 SFT2 } %10// { #04 SFT2 }

%TOS  { #00 SWP } %TOB { SWP POP }
%INCR { SWP #01 + SWP }
%TOGGLE { DUP LDZ #00 = SWP STZ }
%INCR2 { SWP2 #0001 ++ SWP2 }
%DECR2 { SWP2 #0001 -- SWP2 }

%ASCII-FONT { TOS #0008 ** ;font-hex ++ }
%RELEASE-MOUSE { #00 .Mouse/state DEO }
%RESET-SELECTION { #0000 DUP2 .selection/from STZ2 .selection/to STZ2 }

( devices )

|00 @System     &vector $2 &pad     $6 &r      $2 &g     $2 &b     $2
|10 @Console    &vector $2 &read    $1 &pad    $5 &write $1 
|20 @Screen     &vector $2 &width   $2 &height $2 &auto  $1 &pad   $1 &x     $2 &y $2 &addr $2 &pixel $1 &sprite $1
|80 @Controller &vector $2 &button  $1 &key    $1
|90 @Mouse      &vector $2 &x       $2 &y      $2 &state $1 &chord $1 &wheel $1
|a0 @File       &vector $2 &success $2 &offset $2 &pad   $2 &name  $2 &length $2 &load $2 &save $2

( variables )

|0000

@scroll $2
@cursor 
	&x $2 &y $2 
@state
	&timer $1
	&trap $1
	&blink $1
@pointer
	&x $2 
	&y $2
	&last $1
@selection
	&from $2
	&to $2
	&scroll $2
	&nibble $1
@path 
	&length $1
	&name $20
@frame
	&x $2 &y $2 &x2 $2 &y2 $2 
@byte-frame
	&x $2 &y $2 &x2 $2 &y2 $2 
@char-frame
	&x $2 &y $2 &x2 $2 &y2 $2 
@tile-frame
	&x $2 &y $2 &x2 $2 &y2 $2 

( program )

|0100
	
	( theme )
	#0f77 .System/r DEO2 
	#0fc7 .System/g DEO2 
	#0f97 .System/b DEO2

	( vectors ) 
	;on-button .Controller/vector DEO2
	;on-mouse .Mouse/vector DEO2
	;on-frame    .Screen/vector DEO2

	( set size )

	( frame )
	.Screen/width DEI2 2// #0080 -- DUP2 .frame/x STZ2
		#0100 ++ .frame/x2 STZ2
	.Screen/height DEI2 2// #0080 -- DUP2 .frame/y STZ2
		#0100 ++ .frame/y2 STZ2

	.frame/x LDZ2 
		DUP2 .byte-frame/x STZ2
		#00c0 ++ .byte-frame/x2 STZ2
	.frame/y LDZ2 
		DUP2 .byte-frame/y STZ2
		#0100 ++ .byte-frame/y2 STZ2

	.byte-frame/x2 LDZ2 
		DUP2 .char-frame/x STZ2
		#0040 ++ .char-frame/x2 STZ2
	.byte-frame/y LDZ2 
		DUP2 .char-frame/y STZ2
		#0100 ++ .char-frame/y2 STZ2

	.char-frame/x2 LDZ2 #0008 ++
		DUP2 .tile-frame/x STZ2
		#0008 ++ .tile-frame/x2 STZ2
	.byte-frame/y LDZ2 
		DUP2 .tile-frame/y STZ2
		#0100 ++ .tile-frame/y2 STZ2

	( load bytes )
	;untitled-txt .File/name DEO2
	#1000         .File/length DEO2
	;MEMORY       .File/load DEO2

	#0000 .scroll STZ2
	;redraw JSR2

BRK

@on-frame ( -> )
	
BRK

@on-button ( -> )

BRK

@on-mouse ( -> )

	( clear last cursor )
	.cursor/x LDZ2 .Screen/x DEO2
	.cursor/y LDZ2 .Screen/y DEO2
	#40 .Screen/sprite DEO

	( draw new cursor )
	.Mouse/x DEI2 DUP2 .cursor/x STZ2 .Screen/x DEO2
	.Mouse/y DEI2 DUP2 .cursor/y STZ2 .Screen/y DEO2
	;cursor-icn .Screen/addr DEO2
	.Mouse/state DEI #00 ! #41 + .Screen/sprite DEO

	.Mouse/state DEI BRK?

	.Mouse/x DEI2 .Mouse/y DEI2 
	( begin with canvas )
	OVR2 OVR2 .byte-frame ;within-rect JSR2
		;on-touch-byte JCN2
	OVR2 OVR2 .char-frame ;within-rect JSR2
		;on-touch-char JCN2
	OVR2 OVR2 .tile-frame ;within-rect JSR2
		;on-touch-tile JCN2
	POP2 POP2
	
BRK

@on-touch-byte ( x* y* -> )

	.byte-frame/y LDZ2 -- 10// NIP STH

	.byte-frame/x LDZ2 -- 8// NIP #03 DIV STHr

	DEBUG2


BRK

@on-touch-char ( x* y* -> )

BRK

@on-touch-tile ( x* y* -> )

BRK


@redraw ( -- )

	#0010 #0000 
	&loop
		( addr ) DUP2 8** ;MEMORY ++ STH2
		( y ) DUP2 10** .frame/y LDZ2 ++
		STH2r ;draw-row JSR2
		INC2 GTH2k ,&loop JCN
	POP2 POP2

RTN

@draw-row ( y* id* -- )

	;&row STA2
	;&y STA2

	#08 #00
	&bytes-loop
		( color ) #01 STH
		( byte ) DUP TOS ;&row LDA2 ++ LDA STH
		( y ) ;&y LDA2 STH2
		( x-block ) DUP #03 MUL TOS 8** .frame/x LDZ2 ++
		STH2r STHr STHr ;draw-byte JSR2
		INC GTHk ,&bytes-loop JCN
	POP2

	#08 #00
	&chars-loop
		( color ) #01 STH
		( byte ) DUP TOS ;&row LDA2 ++ LDA STH
		( y ) ;&y LDA2 STH2
		( x-block ) DUP TOS 8** .frame/x LDZ2 ++ #00c0 ++
		STH2r STHr STHr ;draw-char JSR2
		INC GTHk ,&chars-loop JCN
	POP2

	.Screen/y DEI2 #0010 -- .Screen/y DEO2
	#0108 .frame/x LDZ2 ++ .Screen/x DEO2
	;&row LDA2 .Screen/addr DEO2
	#01 .Screen/sprite DEO

RTN
	&y $2 &row $2

@draw-byte ( x* y* byte color -- )

	#06 .Screen/auto DEO
	STH STH
	.Screen/y DEO2
	.Screen/x DEO2
	STHr
	DUP
		( hn )
		#04 SFT ,&parse JSR #18 - TOS 10** ;font-hex ++ .Screen/addr DEO2
		STHkr .Screen/sprite DEO
		STHkr .Screen/sprite DEO
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	.Screen/y DEI2 #0010 -- .Screen/y DEO2
		( ln )
		#0f AND ,&parse JSR #18 - TOS 10** ;font-hex ++ .Screen/addr DEO2
		STHkr .Screen/sprite DEO
		STHr .Screen/sprite DEO
	#00 .Screen/auto DEO
	RTN
	&parse ( value -- char )
		DUP #09 > ,&above JCN 
			#30 + RTN 
		&above 
			#09 - #60 + RTN

RTN

@draw-char ( x* y* char color -- )

	#06 .Screen/auto DEO

	STH STH
	.Screen/y DEO2
	.Screen/x DEO2
	STHr #7f AND
	#20 - TOS 10** ;font ++ .Screen/addr DEO2
	STHkr .Screen/sprite DEO
	STHr .Screen/sprite DEO

	#00 .Screen/auto DEO

RTN

@line-rect ( rect color -- )

	STH STH
	( y2 ) STHkr #06 + LDZ2
	( y1 ) STHkr #02 + LDZ2 #0001 -- ( flip sign ) GTH2k SWP2?
	&ver
		( save ) DUP2 .Screen/y DEO2
		( x1 ) STHkr LDZ2 #0001 -- .Screen/x DEO2 
		OVRr STHr .Screen/pixel DEO
		( x2 ) STHkr #04 + LDZ2 .Screen/x DEO2 
		OVRr STHr .Screen/pixel DEO
		( incr )
		INC2 GTH2k ,&ver JCN
	POP2
	( x2 ) STHkr #04 + LDZ2
	( x1 ) STHkr LDZ2 #0001 -- ( flip sign ) GTH2k SWP2?
	&hor
		( save ) DUP2 .Screen/x DEO2
		( y1 ) STHkr #02 + LDZ2 #0001 -- .Screen/y DEO2 
		OVRr STHr .Screen/pixel DEO
		( y2 ) STHkr #06 + LDZ2 .Screen/y DEO2 
		OVRr STHr .Screen/pixel DEO
		( incr )
		INC2 GTH2k ,&hor JCN
	POP2
	POPr 
	.Screen/x DEO2
	.Screen/y DEO2 
	STHr .Screen/pixel DEO

RTN

@within-rect ( x* y* rect -- flag )
	
	STH
	( y < rect.y1 ) DUP2 STHkr #02 ADD LDZ2 << ,&skip JCN
	( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 >> ,&skip JCN
	SWP2
	( x < rect.x1 ) DUP2 STHkr LDZ2 << ,&skip JCN
	( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 >> ,&skip JCN
	POP2 POP2 POPr
	#01 
RTN
	&skip
	POP2 POP2 POPr
	#00

RTN

@print-hex ( value* -- )
	
	&short ( value* -- )
		SWP ,&echo JSR 
	&byte ( value -- )
		,&echo JSR
	RTN

	&echo ( value -- )
	STHk #04 SFT ,&parse JSR .Console/write DEO
	STHr #0f AND ,&parse JSR .Console/write DEO
	RTN
	&parse ( value -- char )
		DUP #09 GTH ,&above JCN #30 + RTN &above #09 - #60 + RTN

RTN

@byte-spacing
	0002 0507 0a0c 0f11
	1416 191b 1e20 2325

@untitled-txt  "example.chr $1
@cursor-icn    80c0 e0f0 f8e0 1000

@scrollbar_icn
	aa55 aa55 aa55 aa55 ( bg )
	ffff ffff ffff ffff ( fg )
	0010 387c fe10 1010 ( up )
	0010 1010 fe7c 3810 ( down )

@font-hex
	007c 8282 8282 827c 0030 1010 1010 1010
	007c 8202 7c80 80fe 007c 8202 1c02 827c
	000c 1424 4484 fe04 00fe 8080 7c02 827c
	007c 8280 fc82 827c 007c 8202 1e02 0202
	007c 8282 7c82 827c 007c 8282 7e02 827c
	007c 8202 7e82 827e 00fc 8282 fc82 82fc
	007c 8280 8080 827c 00fc 8282 8282 82fc
	007c 8280 f080 827c 007c 8280 f080 8080 

include src/font.tal

@MEMORY-LEN $2

@MEMORY