~rabbits/dexe

ref: 47f0c12ecf0317af19693135998463db5d780264 dexe/dexe.tal -rw-r--r-- 20.0 KiB
47f0c12eneauoire Added fast scrolling with arrow keys 4 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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
(
	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 }

%RTN  { JMP2r }
%8**  { #30 SFT2 } %8//  { #03 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 }
%DEBUG  { .Console/byte DEO #0a .Console/char DEO }
%DEBUG2 { .Console/short DEO2 #0a .Console/char DEO }
%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 &pad     $6 &char   $1 &byte  $1 &short $2 &string $2 ]
|20 @Screen     [ &vector $2 &width   $2 &height $2 &pad   $2 &x     $2 &y $2 &addr $2 &color $1 ]
|80 @Controller [ &vector $2 &button  $1 &key    $1 ]
|90 @Mouse      [ &vector $2 &x       $2 &y      $2 &state $1 &wheel $1 ]
|a0 @File       [ &vector $2 &success $2 &offset $2 &pad   $2 &name  $2 &length $2 &load $2 &save $2 ]

( variables )

|0000

@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

( 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

	;untitled-txt ;new-file JSR2

	;redraw JSR2

BRK

@on-frame ( -> )
	
	.state/trap LDZ #00 ! #01 JCN [ BRK ]

	( incr ) .state/timer LDZ #01 + DUP .state/timer STZ 

	#08 ! ,&no-toggle JCN
		.state/blink TOGGLE
		#23 .state/blink LDZ #09 * + ;draw-filepath JSR2
		#00 .state/timer STZ 
	&no-toggle
	
BRK

@on-mouse ( -> )
	
	;draw-cursor JSR2

	.Mouse/state DEI #00 ! .Mouse/y DEI2 .Screen/height DEI2 #0008 -- >> #0101 == 
		;on-touch-toolbar JCN2
	.Mouse/state DEI #00 ! .Mouse/x DEI2 .Screen/width DEI2 #0008 -- >> #0101 == 
		;on-touch-scrollbar JCN2

	( on mouse-down )
	.Mouse/state DEI #00 > .pointer/last LDZ 
	DUP2 #0100 !! ,&no-mouse-down JCN
		.Mouse/x DEI2 .Mouse/y DEI2 .selection/scroll LDZ2 #0008 ** ++ ;get-cell JSR2 .selection/from STZ2 &no-mouse-down
	POP2

	( on scroll up )
	.Mouse/wheel DEI #01 ! ,&no-scroll-up JCN
		( clamp ) .selection/from LDZ2 #0008 << ,&no-scroll-up JCN
		( move ) .selection/from LDZ2 #0008 -- DUP2 .selection/from STZ2 .selection/to STZ2
		;follow JSR2 ;redraw JSR2 BRK
	&no-scroll-up

	( on scroll down )
	.Mouse/wheel DEI #ff ! ,&no-scroll-down JCN
		( clamp ) .selection/from LDZ2 ;MEMORY-LEN LDA2 #0008 -- >> ,&no-scroll-down JCN
		( move ) .selection/from LDZ2 #0008 ++ DUP2 .selection/from STZ2 .selection/to STZ2
		;follow JSR2 ;redraw JSR2 BRK
	&no-scroll-down

	.Mouse/state DEI DUP .pointer/last STZ #01 JCN [ BRK ]

	.Mouse/x DEI2 .Mouse/y DEI2 .selection/scroll LDZ2 #0008 ** ++ ;get-cell JSR2 
	.selection/to STZ2

	;clamp-selection JSR2

	#00 .selection/nibble STZ

	;redraw JSR2

BRK

@on-touch-scrollbar ( -> )
	
	;MEMORY-LEN LDA2 8// .Screen/height DEI2 8// #0003 -- >> #01 JCN BRK

	.Mouse/y DEI2
	DUP2 8// TOB #00 ! ,&no-up JCN
		( clamp ) .selection/scroll LDZ2 #0000 == ,&no-scroll JCN
		.selection/scroll LDZ2 #0001 -- .selection/scroll STZ2
		;redraw JSR2 POP2 RELEASE-MOUSE BRK &no-up
	DUP2 8// TOB .Screen/height DEI2 8// TOB #03 - ! ,&no-down JCN
		( clamp ) ( TODO )
		.selection/scroll LDZ2 #0001 ++ .selection/scroll STZ2
		;redraw JSR2 POP2 RELEASE-MOUSE BRK &no-down
	DUP2 
		#aa DEBUG
		POP2
		(
		#0008 -- #0010 ** #0010 ** 
		;MEMORY-LEN LDA2 8// #0010 **
		// DEBUG2
		.Screen/height DEI2 8// #0003 -- DEBUG2
		)
	&no-scroll
	POP2

BRK

@on-touch-toolbar ( -> )
	
	.Mouse/x DEI2 8// .Screen/width DEI2 8// TOB SWP -
	DUP #01 ! ,&no-save JCN
		;save-file JSR2
		RELEASE-MOUSE ;redraw JSR2 &no-save
	DUP #03 ! ,&no-load JCN
		;load-file JSR2
		RELEASE-MOUSE ;redraw JSR2 &no-load
	DUP #04 ! ,&no-blank JCN
		;untitled-txt ;new-file JSR2
		RELEASE-MOUSE ;redraw JSR2 &no-blank
	DUP #25 < OVR #05 > #0101 !! ,&no-rename JCN
		.state/trap TOGGLE
		#00 .state/blink STZ 
		#23 ;draw-filepath JSR2
		RELEASE-MOUSE ;redraw JSR2 &no-rename
	POP

BRK

@on-button ( -> )
	
	.Controller/key DEI #00 ! .state/trap LDZ #0101 == ;on-button-trap JCN2

	.Controller/button DEI
	DUP #10 ! ,&no-up JCN
		( clamp ) .selection/from LDZ2 #0008 << ,&no-up JCN
		( move ) .selection/from LDZ2 #0008 -- DUP2 .selection/from STZ2 .selection/to STZ2 
		;follow JSR2
		#00 .selection/nibble STZ &no-up
	DUP #11 ! ,&no-up-jump JCN
		( clamp ) .selection/from LDZ2 #0020 << ,&no-up-jump JCN
		( move ) .selection/from LDZ2 #0020 -- DUP2 .selection/from STZ2 .selection/to STZ2 
		;follow JSR2
		#00 .selection/nibble STZ &no-up-jump
	DUP #20 ! ,&no-down JCN
		( move ) .selection/from LDZ2 #0008 ++ DUP2 .selection/from STZ2 .selection/to STZ2 
		;follow JSR2
		#00 .selection/nibble STZ &no-down
	DUP #21 ! ,&no-down-jump JCN
		( move ) .selection/from LDZ2 #0020 ++ DUP2 .selection/from STZ2 .selection/to STZ2 
		;follow JSR2
		#00 .selection/nibble STZ &no-down-jump
	DUP #40 ! ,&no-left JCN
		( clamp ) .selection/from LDZ2 #0007 AND2 #0000 == ,&no-left JCN
		( move ) .selection/from LDZ2 #0001 -- DUP2 .selection/from STZ2 .selection/to STZ2 
		#00 .selection/nibble STZ &no-left
	DUP #80 ! ,&no-right JCN
		( clamp ) .selection/from LDZ2 #0007 AND2 #0007 == ,&no-right JCN
		( move ) .selection/from LDZ2 #0001 ++ DUP2 .selection/from STZ2 .selection/to STZ2 
		#00 .selection/nibble STZ &no-right
	POP
	
	;clamp-selection JSR2

	.Controller/key DEI
	( insert )
	DUP #0d ! ,&no-enter JCN
		.selection/to LDZ2 .selection/from LDZ2 -- #0001 ++ STH2
		.selection/from LDZ2 ;MEMORY ++ STH2kr ;shift-memory-right JSR2
		;MEMORY-LEN LDA2 STH2r ++ ;MEMORY-LEN STA2 &no-enter
	( erase )
	DUP #08 ! ,&no-backspace JCN
		( no erase when size is tiny )
		;MEMORY-LEN LDA2 #0003 << ,&no-backspace JCN
		.selection/to LDZ2 .selection/from LDZ2 -- #0001 ++ STH2
		( no erase when size is small )
		STH2kr ;MEMORY-LEN LDA2 #0002 -- >> ,&no-backspace JCN
		.selection/from LDZ2 ;MEMORY ++ STH2kr ;shift-memory-left JSR2
		;MEMORY-LEN LDA2 STH2r -- ;MEMORY-LEN STA2 
		.selection/from LDZ2 .selection/to STZ2 &no-backspace
	( number keys )
	DUP #2f > OVR #3a < #0101 !! ,&no-number JCN
		DUP #30 - ;write JSR2 &no-number
	( lc letter )
	DUP #60 > OVR #67 < #0101 !! ,&no-lc-letter JCN
		DUP #60 - #09 + ;write JSR2 &no-lc-letter
	POP

	;redraw JSR2

BRK

@on-button-trap ( -> )

	( enter )
	.Controller/key DEI #0d ! ,&no-edit-enter JCN
		#00 .state/trap STZ
		#23 ;draw-filepath JSR2
		BRK &no-edit-enter
	( backspace )
	.Controller/key DEI #08 ! ,&no-edit-backspace JCN
		.path/length LDZ #00 = ,&edit-end JCN
		.path/length LDZ #01 - .path/length STZ
		#00 .path/name .path/length LDZ + STZ
		#23 ;draw-filepath JSR2
		BRK &no-edit-backspace
	( default )
	.path/length LDZ #1f = ,&edit-end JCN
		.Controller/key DEI .path/name .path/length LDZ + STZ
		.path/length LDZ #01 + .path/length STZ &edit-end
	#00 .path/name .path/length LDZ + STZ

BRK

@follow ( -- )
	
	( up )
	.selection/from LDZ2 #03 SFT2 STH2k
	.selection/scroll LDZ2
	>> ,&no-follow-up JCN
		STH2r .selection/scroll STZ2
		RTN &no-follow-up
	POP2r

	( down )
	.selection/to LDZ2 #03 SFT2 STH2k
	.selection/scroll LDZ2 .Screen/height DEI2 8// #0002 -- ++ 
	<< ,&no-follow-down JCN
		STH2r
		.Screen/height DEI2 8// #0003 --
		-- .selection/scroll STZ2
		RTN &no-follow-down
	POP2r

RTN

@write ( char -- )
	
	.selection/from LDZ2 ;MEMORY ++ STH2k LDA
	.selection/nibble LDZ ,&lo JCN
		#0f AND SWP #40 SFT +
		,&continue JMP
	&lo
		#f0 AND +
	&continue
	STH2r STA
	( toggle nibble )
	.selection/nibble TOGGLE

RTN

@redraw ( -- )
	
	( offset )
	;MEMORY .selection/scroll LDZ2 #0008 ** ++ STH2

	( draw lines )
	#0000 .Screen/y DEO2
	;font-hex .Screen/addr DEO2
	#0000 .Screen/height DEI2 #0010 --
	&loop
		#0000 .Screen/x DEO2
		OVR2 STH2kr ++ ,draw-line JSR
		SWP2 #0008 ++ SWP2
		OVR2 .Screen/y DEO2
		LTH2k ,&loop JCN
	POP2 POP2
	POP2r

	;draw-scrollbar JSR2
	;draw-toolbar JSR2

RTN

@draw-line ( addr* -- )
	
	STH2

	STH2kr ;draw-bytes JSR2
	STH2kr ;draw-ascii JSR2

	( icn )
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	STH2kr .Screen/addr DEO2
	#21 .Screen/color DEO

	( chr )
	.Screen/x DEI2 #0010 ++ .Screen/x DEO2
	STH2kr .Screen/addr DEO2
	#41 STH2kr #0008 // #0001 AND2 #0001 == - .Screen/color DEO

	POP2r

RTN

@draw-bytes ( addr* -- )
	
	STH2
	#00 #08
	&byte-loop
		OVR TOS STH2kr ++ STH2

		( is end of file )
		STH2kr ;MEMORY -- ;MEMORY-LEN LDA2 << ,&within-file JCN
			;font-hex .Screen/addr DEO2
			#23 .Screen/color DEO
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2
			#23 .Screen/color DEO
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2
			,&resume JMP
		&within-file
			STH2kr LDA #04 SFT ASCII-FONT .Screen/addr DEO2
			#21 [ STH2kr ;is-selected JSR2 #07 * ] + .Screen/color DEO
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2
			STH2kr LDA #0f AND ASCII-FONT .Screen/addr DEO2
			#21 [ STH2kr ;is-selected JSR2 #07 * ] + .Screen/color DEO
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2
		&resume
		POP2r

		( jump after a short )
		OVR #01 AND #00 = ,&no-leap JCN
			.Screen/x DEI2 #0008 ++ .Screen/x DEO2 &no-leap
		INCR
		LTHk ;&byte-loop JCN2
	POP2

	POP2r

RTN

@draw-ascii ( addr* -- )
	
	STH2
	#00 #08
	&ascii-loop
		OVR TOS STH2kr ++ STH2
		( is end of file )
		STH2kr LDA #00 = ,&blank JCN
		STH2kr ;MEMORY -- ;MEMORY-LEN LDA2 << ,&within-file JCN
		&blank
			;font #2e TOS 8** ++ .Screen/addr DEO2 
			#23 [ STH2kr ;is-selected JSR2 ] - .Screen/color DEO
			,&resume JMP
		&within-file
			STH2kr LDA TOS 8** ;font ++ .Screen/addr DEO2 
			#21 [ STH2kr ;is-selected JSR2 #0b * ] + .Screen/color DEO
		&resume
		POP2r
		.Screen/x DEI2 #0008 ++ .Screen/x DEO2
		INCR
		LTHk ,&ascii-loop JCN
	POP2
	POP2r

RTN

@draw-toolbar ( -- )

	( selection )
	.Screen/height DEI2 #0008 -- .Screen/y DEO2
	#0000 .Screen/x DEO2
	.selection/to LDZ2 #22 .selection/from LDZ2 .selection/to LDZ2 == - ;draw-short JSR2
	#0028 .Screen/x DEO2
	;MEMORY-LEN LDA2 #23 ;draw-short JSR2

	( path )
	#0050 .Screen/x DEO2
	#21 ;draw-filepath JSR2

	( draw filesize )
	.Screen/width DEI2 #0008 -- .Screen/x DEO2
	;save-icn .Screen/addr DEO2
	#21 .Screen/color DEO
	.Screen/x DEI2 #0010 -- .Screen/x DEO2
	;load-icn .Screen/addr DEO2
	#21 .Screen/color DEO
	.Screen/x DEI2 #0008 -- .Screen/x DEO2
	;make-icn .Screen/addr DEO2
	#21 .Screen/color DEO

RTN

@draw-short ( short* color -- )

	STH SWP 
	DUP #04 SFT ASCII-FONT .Screen/addr DEO2
	( draw ) STHkr .Screen/color DEO
	#0f AND ASCII-FONT .Screen/addr DEO2
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	( draw ) STHkr .Screen/color DEO
	DUP #04 SFT ASCII-FONT .Screen/addr DEO2
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	( draw ) STHkr .Screen/color DEO
	#0f AND ASCII-FONT .Screen/addr DEO2
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	( draw ) STHr .Screen/color DEO

RTN

@draw-cursor ( -- )

	( clear last cursor )
	.pointer/x LDZ2 .Screen/x DEO2
	.pointer/y LDZ2 .Screen/y DEO2
	#30 .Screen/color DEO

	( record mouse positions )
	.Mouse/x DEI2 .pointer/x STZ2
	.Mouse/y DEI2 .pointer/y STZ2

	( draw new cursor )
	.pointer/x LDZ2 .Screen/x DEO2
	.pointer/y LDZ2 .Screen/y DEO2
	;cursor-icn .Screen/addr DEO2
	#33 .Mouse/state DEI #00 ! - .Screen/color DEO

RTN

@draw-scrollbar ( -- )

	;scrollbar_icn ( keeping a copy on stack )

	.Screen/width DEI2 #0008 -- .Screen/x DEO2
	#0008 .Screen/y DEO2
	DUP2 .Screen/addr DEO2

	#0008 .Screen/height DEI2 #0018 --
	&loop
		( draw ) #23 .Screen/color DEO
		( incr ) SWP2 #0008 ++ DUP2 .Screen/y DEO2 SWP2
		OVR2 OVR2 LTH2 ,&loop JCN
	POP2 POP2

	;MEMORY-LEN LDA2 #03 SFT2 
	.Screen/height DEI2 8// #0002 -- 
	<< ,&skip-indicator JCN
		.selection/scroll LDZ2 #0008 ++ .Screen/y DEO2
		DUP2 #0008 ++ .Screen/addr DEO2
		( draw ) #21 .Screen/color DEO &skip-indicator

	#0000 .Screen/y DEO2
	DUP2 #0010 ++ .Screen/addr DEO2
	( draw ) #23 .Screen/color DEO

	.Screen/height DEI2 #0018 -- .Screen/y DEO2
	#0018 ++ .Screen/addr DEO2
	( draw ) #23 .Screen/color DEO

RTN

@draw-filepath ( color -- )
	
	STH
	#0050 .Screen/x DEO2
	.Screen/height DEI2 #0008 -- .Screen/y DEO2
	;path/name
	&loop
		LDAk TOS #0008 ** ;font ++ .Screen/addr DEO2 
		STHkr .Screen/color DEO
		.Screen/x DEI2 #0008 ++ .Screen/x DEO2
		#0001 ++
		LDAk ,&loop JCN
	POP2
	POPr
	( clear last ) 
	#20 .Screen/color DEO

RTN

@shift-memory-left ( addr* length* -- )
	
	STH2
	DUP2 ;MEMORY-LEN LDA2 ++
	&loop
		OVR2 DUP2 STH2kr ++ LDA ROT ROT STA
		INCR2
		NEQ2k ,&loop JCN
	POP2 POP2
	POP2r
	
RTN

@shift-memory-right ( addr* length* -- )
	
	STH2
	DUP2 ;MEMORY-LEN LDA2 ++ SWP2 #0001 --
	&loop
		OVR2 DUP2 LDA ROT ROT STH2kr ++ STA
		DECR2
		NEQ2k ,&loop JCN
	POP2 POP2
	POP2r
	
RTN

@clamp-selection ( -- )
	
	( no outside )
	;MEMORY-LEN LDA2 STH2
	.selection/from LDZ2 STH2kr << ,&skip-from JCN
		STH2kr #0001 -- .selection/from STZ2 &skip-from
	.selection/to LDZ2 STH2kr << ,&skip-to JCN
		STH2kr #0001 -- .selection/to STZ2 &skip-to
	POP2r
	( no backward )
	.selection/to LDZ2 .selection/from LDZ2 >> ,&no-negative JCN
		.selection/from LDZ2 .selection/to STZ2 &no-negative
	
RTN

@is-selected ( addr* -- flag )
	
	;MEMORY --
	DUP2 .selection/from LDZ2 !! ,&no-from JCN
		POP2 #01 RTN &no-from 
	DUP2 .selection/to LDZ2 !! ,&no-to JCN
		POP2 #01 RTN &no-to 
	STH2k
	.selection/from LDZ2 >> 
	STH2r .selection/to LDZ2 << 
	#0101 ==

RTN

@get-cell ( x* y* -- addr* )

	( row ) 8// #0008 ** SWP2
	( col ) DUP2 #00a0 << ,&byte JCN
		POP2 RTN &byte
	DUP2 #0028 // #0008 ** --
	#0008 // #0002 //
	++ 

RTN

@clear ( from* to* -- )
	
	;MEMORY DUP2 ;MEMORY-LEN LDA2 ++
	&loop
		OVR2 #00 ROT ROT STA
		INCR2
		LTH2k ,&loop JCN
	POP2 POP2

RTN

@new-file ( default* -- )
	
	#20 ;draw-filepath JSR2 

	;clear JSR2
	RESET-SELECTION

	STH2
	#00 #0c
	&loop
		OVR DUP TOS STH2kr ++ LDA SWP .path/name + STZ
		INCR
		LTHk ,&loop JCN
	.path/length STZ POP 
	POP2r

	#00 .path/name #0c + STZ
	#0002 ;MEMORY-LEN STA2

RTN

@load-file ( -- )

	( BANK LENGTH ;op-clear JSR2 )
	;path/name .File/name DEO2 
	#fff0 ;MEMORY -- .File/length DEO2 
	;MEMORY .File/load DEO2
	.File/success DEI2 ;MEMORY-LEN STA2

RTN

@save-file ( -- )

	;path/name .File/name DEO2 
	;MEMORY-LEN LDA2 .File/length DEO2 
	;MEMORY .File/save DEO2

RTN

@untitled-txt  "untitled.chr $1
@save-icn      1054 28c6 2854 1000 
@make-icn      fe82 8282 848a f400 
@load-icn      feaa d6aa d4aa f400 
@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 

@font ( specter8 font )
	0000 0000 0000 0000 0000 2400 7e3c 0000
	0000 2400 3c42 0000 0000 6c7c 7c38 1000
	0010 387c 7c38 1000 0038 387c 6c10 3800
	0010 387c 7c10 3800 0000 0018 1800 0000
	007e 4242 4242 7e00 0000 1824 2418 0000
	003c 665a 5a66 3c00 001e 063a 4a48 3000
	0038 446c 107c 1000 000e 0808 0838 3800
	003e 3e22 2266 6600 0000 1044 0044 1000
	0000 1018 1c18 1000 0000 0818 3818 0800
	0008 1c00 001c 0800 0028 2828 2800 2800
	003e 4a4a 3a0a 0a00 000c 3046 620c 3000
	0000 0000 0000 ffff 0010 3800 3810 0038
	0010 3854 1010 1000 0010 1010 5438 1000
	0000 0804 7e04 0800 0000 1020 7e20 1000
	0000 4040 7e00 0000 0000 0024 6624 0000
	0000 1038 7c00 0000 0000 007c 3810 0000
	0000 0000 0000 0000 0008 0808 0800 0800
	0014 1400 0000 0000 0024 7e24 247e 2400
	0008 1e28 1c0a 3c08 0000 2204 0810 2200
	0030 4832 4c44 3a00 0008 1000 0000 0000
	0004 0808 0808 0400 0020 1010 1010 2000
	0000 2214 0814 2200 0000 0808 3e08 0800
	0000 0000 0000 0810 0000 0000 3e00 0000
	0000 0000 0000 0800 0000 0204 0810 2000
	003c 464a 5262 3c00 0018 0808 0808 1c00
	003c 4202 3c40 7e00 003c 421c 0242 3c00
	000c 1424 447e 0400 007e 407c 0242 3c00
	003c 407c 4242 3c00 007e 0204 0810 1000
	003c 423c 4242 3c00 003c 4242 3e02 3c00
	0000 0010 0000 1000 0000 1000 0010 1020
	0000 0810 2010 0800 0000 003e 003e 0000
	0000 1008 0408 1000 003c 420c 1000 1000
	003c 4232 4a42 3c00 003c 4242 7e42 4200
	007c 427c 4242 7c00 003c 4240 4042 3c00
	007c 4242 4242 7c00 007e 4078 4040 7e00
	007e 4078 4040 4000 003c 4240 4642 3c00
	0042 427e 4242 4200 001c 0808 0808 1c00
	007e 0202 0242 3c00 0042 4478 4442 4200
	0040 4040 4040 7e00 0042 665a 4242 4200
	0042 6252 4a46 4200 003c 4242 4242 3c00
	007c 4242 7c40 4000 003c 4242 4244 3a00
	007c 4242 7c44 4200 003e 403c 0242 3c00
	007e 0808 0808 1000 0042 4242 4244 3a00
	0042 4242 4224 1800 0042 4242 5a66 4200
	0042 423c 4242 4200 0042 423e 0242 3c00
	007e 020c 3040 7e00 000c 0808 0808 0c00
	0040 2010 0804 0200 0030 1010 1010 3000
	0008 1400 0000 0000 0000 0000 0000 7e00
	0008 0400 0000 0000 0000 3c02 3e42 3a00
	0040 407c 4242 7c00 0000 3c42 4042 3c00
	0002 023e 4242 3e00 0000 3c42 7e40 3e00
	0000 3e40 7840 4000 0000 3c42 3e02 3c00
	0040 405c 6242 4200 0008 0018 0808 0400
	0008 0018 0808 4830 0040 4244 7844 4200
	0010 1010 1010 0c00 0000 6c52 5252 5200
	0000 5c62 4242 4200 0000 3c42 4242 3c00
	0000 7c42 427c 4040 0000 3e42 423e 0202
	0000 5c62 4040 4000 0000 3e40 3c02 7c00
	0008 7e08 0808 1000 0000 4242 4244 3a00
	0000 4242 4224 1800 0000 5252 5252 2e00
	0000 4224 1824 4200 0000 4242 3e02 7c00
	0000 7e02 3c40 7e00 000c 0810 1008 0c00
	0008 0808 0808 0800 0030 1008 0810 3000
	0000 0032 4c00 0000 3c42 99a1 a199 423c
	003c 4240 423c 1070 0044 0044 4444 3800
	0810 3844 7840 3c00 0814 3c02 3e42 3a00
	1400 3c02 3e42 3a00 0804 3c02 3e42 3a00
	0814 2c02 3e42 3a00 0000 1c20 201c 0818
	1028 3844 7840 3c00 2800 3844 7840 3c00
	2010 3c44 7840 3c00 0028 0030 1010 0c00
	1028 0030 1010 0c00 2010 0030 1010 0c00
	423c 4242 7e42 4200 0814 3c42 7e42 4200
	0810 7e40 7c40 7e00 0000 6c12 3c50 6e00
	003e 507c 5050 5e00 1028 0038 4444 3800
	2800 3844 4444 3800 2010 3844 4444 3800
	1028 0044 4444 3800 2010 4444 4444 3800
	4400 4444 443c 0438 423c 4242 4242 3c00
	4200 4242 4242 3c00 0010 3840 4038 1000
	001c 2278 2020 7e00 0044 287c 107c 1000
	007c 4252 7c50 4c00 000c 107c 1010 6000
	0810 3c02 3e42 3a00 0810 0030 1010 0c00
	0810 3844 4444 3800 0810 4444 4444 3800
	324c 005c 6242 4200 324c 0062 524a 4600
	3848 5828 0078 0000 3048 4830 0078 0000
	0008 0008 3042 3c00 0000 0000 7c40 4000
	0000 0000 7c04 0400 4448 502c 4204 0e00
	4448 5024 541e 0400 0010 0010 1010 1000
	0000 1224 4824 1200 0000 4824 1224 4800
	8844 2211 8844 2211 aa55 aa55 aa55 aa55
	4411 4411 4411 4411 1010 1010 1010 1010
	1010 1010 f010 1010 1010 10f0 10f0 1010
	2828 2828 e828 2828 0000 0000 f828 2828
	0000 00f0 10f0 1010 2828 28e8 08e8 2828
	2828 2828 2828 2828 0000 00f8 08e8 2828
	2828 28e8 08f8 0000 2828 2828 f800 0000
	1010 10f0 10f0 0000 0000 0000 f010 1010
	1010 1010 1f00 0000 1010 1010 ff00 0000
	0000 0000 ff10 1010 1010 1010 1f10 1010
	0000 0000 ff00 0000 1010 1010 ff10 1010
	1010 101f 101f 1010 2828 2828 2f28 2828
	2828 282f 203f 0000 0000 003f 202f 2828
	2828 28ef 00ff 0000 0000 00ff 00ef 2828
	2828 282f 202f 2828 0000 00ff 00ff 0000
	2828 28ef 00ef 2828 1010 10ff 00ff 0000
	2828 2828 ff00 0000 0000 00ff 00ff 1010
	0000 0000 ff28 2828 2828 2828 3f00 0000
	1010 101f 101f 0000 0000 001f 101f 1010
	0000 0000 3f28 2828 2828 2828 ef28 2828
	1010 10ff 00ff 1010 1010 1010 f000 0000
	0000 0000 1f10 1010 ffff ffff ffff ffff
	0000 0000 ffff ffff f0f0 f0f0 f0f0 f0f0
	0f0f 0f0f 0f0f 0f0f ffff ffff 0000 0000
	0000 324a 4444 3a00 0038 445c 4262 5c40
	007e 4240 4040 4000 0000 7c28 2828 2400
	007e 2210 1022 7e00 0000 3e44 4444 3800
	0000 4444 4444 7a40 0000 7c10 1010 0800
	0010 3854 5438 1000 003c 4242 7e42 3c00
	003c 4242 4224 6600 7820 1844 4444 3800
	0000 6c92 926c 0000 0000 1854 5438 1000
	003e 407e 4040 3e00 003c 4242 4242 4200
	0000 7e00 7e00 7e00 0008 083e 0800 3e00
	0010 0804 0810 3c00 0008 1020 1008 3c00
	0000 0814 1010 1010 1010 1010 5020 0000
	0000 0800 3e00 0800 0000 324c 0032 4c00
	0018 2424 1800 0000 0000 0018 1800 0000
	0000 0000 1000 0000 000e 0808 4828 1800
	0050 6848 4800 0000 0060 1020 7000 0000
	0000 3c3c 3c3c 0000 0000 3c3c 3c3c 0000

@MEMORY-LEN $2

@MEMORY