-
Notifications
You must be signed in to change notification settings - Fork 5
/
EDITOR.inc
1794 lines (1680 loc) · 76.7 KB
/
EDITOR.inc
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; All functions called here should assume ES = DS = CS on entry
;-----------------------------------------------------------------------------
ed_get_key: ; Get a keystroke, set some hepful regs + figure out what to do
;-----------------------------------------------------------------------------
HND_OFFSET equ (key_handlers-key_codes)
NUM_KEYS equ (HND_OFFSET)/2
NUM_FKEYS equ (key_handlers-file_keys)/2
call update_stateful ; redraw all stateful option labels
push cs
pop es ; I/O target = base segment vars
mov ah, [state.int16h_func] ; use 10h if supported, otherwise 0
int 16h ; get key: AH=scancode, AL=ASCII
call str_upper_al ; lowercase to uppercase
mov cl, ah
and cl, 0E0h ; zero AL (ascii) for all 4#h/5#h
cmp cl, 40h ; scancodes, for simpler handling
jne @f
xor al, al
@@: cmp ah, 73h ; do the same for ctrl+arrow combos
jb @f
xor al, al
@@: push ax
call screen_status_bar ; clean it up on every keypress
pop ax
xchg ax, bx ; BX = keycode
mov ah, 2
int 16h ; get shift flags (AL)
mov ah, byte[state.currbox]
push ax ;!;
test al, byte[state.drag_flag] ; RShift / Ctrl pressed?
jz .setdrag ; - not dragging anything
call font_get_char_row ; - dragging, BUT WHAT? (destroys
test al, [state.cursor_mask] ; AX, hence the push/pop)
mov bp, di ;>>> BP-> char row (if we care)
mov ah, 1
mov al, byte[state.drag_flag]
jnz .setdrag
dec ah
.setdrag: ; DRAGGING?: AL bit0=1, AH=draggee;
mov word[state.drag], ax ; otherwise: AL bit0=0, AH=don't care
pop ax ;!;
xchg ax, bx ;>>> AX=key, BL=shift flags, BH=currbox
mov di, key_codes
mov cx, NUM_KEYS
repne scasw ; found keycode in the list?
jne ed_get_key ; - nah, try again
mov dx, word[di+HND_OFFSET-2] ; - yeah, get handler address
mov si, [state.currfont_ptr] ;>>> SI-> font structure
test bh, 1 ;>>> ZF-> box ID check
mov [fdlg.actkey], ax ;>>> store key for file dialog too
call dx ; do it
jmp short ed_get_key ; NEXT!
align 2
key_codes:
dw 0F09h ; Tab
dw 011Bh ; Esc
dw 0231h ; 1
dw 0332h ; 2
dw 4800h ; Up arrow
dw 4B00h ; Left arrow
dw 4D00h ; Right arrow
dw 5000h ; Down arrow
dw 8D00h ; Ctrl+Up arrow (*)
dw 7300h ; Ctrl+Left arrow (*)
dw 7400h ; Ctrl+Right arrow (*)
dw 9100h ; Ctrl+Down arrow (*)
dw 3920h ; Space
dw 1C0Dh ; Enter
dw 0D2Bh ; +
dw 4E00h ; + (modified)
dw 0C2Dh ; -
dw 4A00h ; - (modified)
dw 1245h ; E
dw 2146h ; F
dw 2247h ; G
dw 1749h ; I
dw 1F53h ; S
dw 1157h ; W
dw 2D58h ; X
dw 1559h ; Y
dw 1E01h ; Ctrl+A
dw 2E03h ; Ctrl+C
dw 2004h ; Ctrl+D
dw 2207h ; Ctrl+G
dw 1312h ; Ctrl+R
dw 2F16h ; Ctrl+V
dw 2D18h ; Ctrl+X
dw 2C1Ah ; Ctrl+Z
dw 3E00h ; F4
dw 3F00h ; F5
dw 4000h ; F6
dw 4100h ; F7
dw 4200h ; F8
dw 4300h ; F9
dw 4400h ; F10
dw 2B7Ch ; |
dw 0C5Fh ; _
dw 8000h ; (Ctrl+)Alt+9
dw 5B00h ; Shift+F8
file_keys:
dw 3C00h ; F2
dw 1F13h ; Ctrl+S
dw 3D00h ; F3
dw 260Ch ; Ctrl+L
dw 1709h ; Ctrl+I
dw 1205h ; Ctrl+E
key_handlers:
dw ed_set_box ; Tab
dw ed_key_esc ; Esc
dw ed_set_font ; 1
dw ed_set_font ; 2
dw ed_key_up ; Up arrow
dw ed_key_left ; Left arrow
dw ed_key_right ; Right arrow
dw ed_key_down ; Down arrow
dw ed_key_up ; Ctrl+Up arrow (*)
dw ed_key_left ; Ctrl+Left arrow (*)
dw ed_key_right ; Ctrl+Right arrow (*)
dw ed_key_down ; Ctrl+Down arrow (*)
dw ed_key_action ; Space
dw ed_key_action ; Enter
dw ed_next_char ; +
dw ed_next_char ; + (modified)
dw ed_prev_char ; -
dw ed_prev_char ; - (modified)
dw ed_block.erase ; E
dw ed_block.fill ; F
dw ed_goto_char ; G
dw ed_block.invert ; I
dw ed_slide ; S
dw ed_swap ; W
dw ed_block.flip_x ; X
dw ed_block.flip_y ; Y
dw ed_mark_all ; Ctrl+A
dw ed_copy ; Ctrl+C
dw ed_unmark ; Ctrl+D
dw ed_get_rom ; Ctrl+G
dw ed_revert ; Ctrl+R
dw ed_paste ; Ctrl+V
dw ed_copy ; Ctrl+X
dw ed_undo ; Ctrl+Z
dw ed_height ; F4
dw ed_one_line ; F5
dw ed_one_line ; F6
dw ed_one_line ; F7
dw ed_dot_mode ; F8
dw ed_palette ; F9
dw ed_preview ; F10
dw ed_guide.v ; |
dw ed_guide.h ; _
dw ed_cheat_code ; (Ctrl+)Alt+9
dw ed_lge ; Shift+F8
;file_keys:
dw file_dialog.with_fname ; F2
dw file_dialog.with_fname ; Ctrl+S
dw file_dialog ; F3
dw file_dialog ; Ctrl+L
dw file_dialog ; Ctrl+I
dw ed_export ; Ctrl+E
;++++++++++++++++++++++++++++++++++++++++++++
;########## HELPER FUNCTIONS ##########
;++++++++++++++++++++++++++++++++++++++++++++
;-----------------------------------------------------------------------------
ed_do_lbox: ; Update editbox (char+cursor + outside - NO NEED TO DO GRID)
;-----------------------------------------------------------------------------
call update_lbox_char ; Active screen only (+ cursor)
call update_lbox_out ; Active screen only (+ title)
ret
;-----------------------------------------------------------------------------
ed_do_rbox: ; Update fontbox (inside + outside - call .i for innards only)
;-----------------------------------------------------------------------------
call update_rbox_out ; Updates both screens
.i: call update_rbox_in ; Active screen only
ret
;-----------------------------------------------------------------------------
ed_get_fntmark: ; Check if fontbox mark exists; if not, make one at cursor
;-----------------------------------------------------------------------------
mov di, state.fntmark
test byte[di], 1 ; Fontbox mark exists?
jnz @f ; - Yes, keep it
push di
push ax
mov al, byte[di]
inc ax ; - No: set fntmark to 1
stosb
pop ax ; [state.hoverchar]
stosb ; + fntamrk_start = "
stosb ; + fntmark_end = "
pop di
@@: inc di ; DI -> fntmark_start
ret
;-----------------------------------------------------------------------------
ed_get_chrmark: ; Check if editbox mark exists; if not, make one at cursor
;-----------------------------------------------------------------------------
mov dl, [state.cursor_mask]
mov di, state.chrmark_mask
cmp byte[di], 0 ; Do we have an existing mark?
jne @f ; - Yes: keep it
mov byte[di], dl ; - No: set chrmark=cursor mask
push ax
push bx
mov al, [state.cursor_pos+1] ; current row
cbw
mov bx, ax
mov byte[state.chrmark_rows+bx],-1 ; gotta have it filled in :/
std ; -about-face-
dec di
stosb ; _rng_v FROM = current row
stosb ; _rng_v TO = current row
mov al, [state.cursor_pos] ; current column
stosb ; _rng_h FROM = current col
stosb ; _rng_h TO = current col
cld ; -flip dir again-
pop bx
pop ax
@@: mov di, state.chrmark_rng_h
ret
;-----------------------------------------------------------------------------
ed_chrmark_update_v: ; Update editbox mark after vertical move
;
; In: AX = new cursor row post-move
; DI-> low byte of _rng_h (TO)
; DH = JA if moved down, JAE if moved up
; BX = 0 if moved down, 1 if moved up
;-----------------------------------------------------------------------------
mov byte[.op], dh ; Modify conditional jump
jmp short @f ; prevent prefetch issues
@@: inc di
inc di ; DI-> _rng_v, "TO" row
cmp al, byte[di+bx] ; New row vs "FROM"(up) / "TO"(down)
.op: ; ( ">" if down, ">=" if up)
jae @f ; - Yep, set "to" row...
inc di ; - Nope, set "from" row...
@@: stosb ; ...to cursor row
xor ax, ax ; Now fill up chrmark_rows according
mov di, state.chrmark_rows ; to vertical range
mov bx, [state.chrmark_rng_v] ; BH = "from" row, BL = "to" row
inc bl ; ^ flipping point
mov cl, 32 ; Max height
.do_row: ; AL = row mask = 0; AH = row counter
cmp ah, bh ; Reached flip point?
jne @f ; - No, keep current mask
xchg bh, bl ; - Yes, flip from/to check
not al ; and flip that mask too
@@: stosb ; Set row to mask
inc ah ; Counter++
loop .do_row ; Next row
ret
;-----------------------------------------------------------------------------
ed_chrmark_update_h: ; Update editbox mark after horizontal move
;
; In: AX = new cursor column post-move
; DI-> low byte of _rng_h (TO)
; DH = JA if moved right, JAE if moved left
; BX = 0 if moved right, 1 if moved left
;-----------------------------------------------------------------------------
mov byte[.op], dh ; Modify conditional jump
jmp short @f ; prevent prefetch issues
@@: cmp al, byte[di+bx] ; New col vs "FROM"(<-) / "TO"(->)
.op: ; ( ">" if right, ">=" if left)
jae @f ; - Yep, set "to" column...
inc di ; - Nope, set "from" column...
@@: stosb ; ...to cursor column
xor ax, ax ; Start w/empty mask + counter
mov dx, 8000h ; DL = no bits on, DH = MSB on
mov bx, [state.chrmark_rng_h] ; BH = "from" col, BL = "to" col
inc bl ; ^flipping point
mov cl, 8
.do_col: ; AL = column bit; AH = counter
cmp ah, bh ; Reached flip point?
jne @f ; - No, keep current bit value
xchg bh, bl ; - Yes, flip from/to check
xchg dh, dl ; and flip that mask too
@@: or al, dl ; Set column bit
ror dx, 1 ; Rotate
inc ah ; Counter++
loop .do_col ; Next column
mov di, state.chrmark_mask
stosb ; Writing the result MIGHT HELP
ret
;-----------------------------------------------------------------------------
ed_check_drag: ; Check after cursor has moved - if dragged, apply pixel
;-----------------------------------------------------------------------------
mov si, state.dragged_last
mov ax, [state.drag] ; OK, cursor moved; check drag status
test al, byte[state.drag_flag] ; did we drag anything?
jnz @f
mov byte[si], 0 ; - no: make note for next time
jmp ed_do_lbox ; and just update cursor in lbox
@@: test byte[si], 1 ; - yes: is this a new drag op?
jnz @f ; * no: don't touch undo buffer
inc byte[si] ; * yes: adjust for next check
call font_update_undo_buf ; and update undo state
@@: mov al, [state.cursor_mask] ; get bit corresponding to cursor
test ah, 1 ; check draggee
jz @f ; pixel ON?
or byte[bp], al ; - yes, add it (BP -> target)
jmp short .end ; ...aaand done
@@: not al ; - no, pixel OFF
and byte[bp], al ; ...subtract it
.end: ; FALL THROUGH
;-----------------------------------------------------------------------------
ed_apply_change: ; Note that font/current char have changed + update screen
;-----------------------------------------------------------------------------
mov bx, [state.currchar] ; if called here, only current char
.1: mov cx, 1 ; has changed
@@: mov si, [state.currfont_ptr]
lea di, [bx+si+font.changes] ; update changes array
mov al, 1
rep stosb
mov [si+font.unsaved], al ; set unsaved flag
call update_unsaved ; show it on screen, too
call update_lbox_char ; update character in editbox
stc ; on-screen vertical centering ON
call vga_upload_font ; upload the font
jmp ed_do_rbox.i ; let's display the changes as well
.many:
mov ax, [state.fntmark_start] ; if called here, all marked chars
xchg ah, al ; have changed
xor bx, bx
mov bl, ah ; BX: from
xor ah, ah ; AX: to
sub ax, bx
inc ax
.pasted_many: ; called here? AX=#chars, BX=currchar
xchg ax, cx ; CX: number of chars to do
jmp short @b ; so go do it
.hover:
mov bx, [state.hoverchar]
jmp short .1
;-----------------------------------------------------------------------------
ed_warn_unsaved: ; Create 'lose changes' prompt in scratch + show it
;
; In: CF = method: 0 = current font, 1 = both fonts (before exit)
; Out: CF = answer: 0 = NO, 1 = YES
;-----------------------------------------------------------------------------
mov di, scratch
push di
pushf
mov si, txt.lose
call str_copy_asc0
mov al, '1'
test byte[state.currfont], 1
jz @f
inc ax
@@: dec di
stosb
mov si, txt.yes_no
popf
jnc @f
sub di, 6
mov si, txt.both_fonts
@@: call str_copy_asc0
pop si ; SI -> scratch (message)
mov ah, 1111b ; +wipe +getkey +cursor +warning
call screen_status_prompt
and al, 11011111b ; got ASCII in AL; lower -> upper
cmp al, 'Y'
clc
jne @f
stc
@@: pushf
call screen_status_bar
popf
ret
;++++++++++++++++++++++++++++++++++++++++++++++
;########## KEYPRESS FUNCTIONS ##########
;++++++++++++++++++++++++++++++++++++++++++++++
;-----------------------------------------------------------------------------
ed_set_box: ; Change focus between edit/font box (optional) and redraw them
;-----------------------------------------------------------------------------
not byte[state.currbox] ; swap the little suckers
jmp short .noinit
.init: ; call here on init (no switching)
mov ax, [state.currchar]
mov [state.hoverchar], ax ; a little conceit
.noinit: ; call here to keep curr/hover chars
call ed_do_rbox
call ed_do_lbox
call update_box_legend ; box-specific caption+line+labels
ret
;-----------------------------------------------------------------------------
ed_set_font: ; Sets active font to either 1 or 2, depending on keystroke
;-----------------------------------------------------------------------------
sub ah, 2 ; 0 = font 1, 1 = font 2
mov al, byte[state.currfont]
and al, 1
cmp ah, al ; selected font == current one?
jne @f
ret ; - yep, nothing to see here
@@: not byte[state.currfont] ; - nope, flip it...
cmp al, 0 ; but to what?
;aaa ; <- was this, but PCem barfed
mov ax, font1
jnz @f
mov ax, font2
@@: mov [state.currfont_ptr], ax ; ...and fall through:
;-----------------------------------------------------------------------------
ed_switch_to_font: ; Does some heavy lifting, call after active font was set
;-----------------------------------------------------------------------------
mov si, [state.currfont_ptr]
cmp byte[si], 16 ; height of current font
mov di, state.screen
mov al, SCR_ED25 ; - short enough? do the 25-row thing
jbe @f
mov al, SCR_ED50 ; - too tall? go 50
@@: stosb
call ed_set_box.noinit ; just draw whatever is needed
call update_lbox_grid
call update_tabs
call vga_switch_screen ; everything ready? pull the switch
stc
call vga_upload_font ; centered (needed for +/-LGE)
ret
;-----------------------------------------------------------------------------
ed_key_up: ; Handle up arrow key (for both edit & font boxes)
;-----------------------------------------------------------------------------
jz .editbox
.fontbox:
mov al, [state.hoverchar]
test bl, 2 ; Left shift pressed?
pushf ;!; ; (save answer)
jz @f ; - No, go on
call ed_get_fntmark ; - Yes, make sure we have a mark
@@: sub al, 10h
mov [state.hoverchar], al
popf ;!; ; Left shift pressed?
jz .fin ; - No, skip mark stuff
cmp al, byte[di] ; - Yes, test 'cursor' vs. mark start
jb @f ; below? - set start
inc di ; above? - set end
@@: stosb ; ...to 'cursor'
.fin:
jmp ed_do_rbox
.editbox:
mov al, [state.cursor_pos+1] ; Get *current* row
cbw ; AX = "
test bl, 2 ; Left shift pressed?
pushf ;!; ; (save answer)
jz @f ; - No, go on
call ed_get_chrmark ; - Yes, make sure we have a mark
@@: dec bp ; MOVE: ptr to new row (for drag)
dec al ; New row = current row - 1
jns @f ; SF set? - we've wrapped around
lodsb ; AL <= byte[si] = font height
add bp, ax ; Wrap pointer to bottom
dec ax ; Wrap to bottom: new row = height-1
@@: mov [state.cursor_pos+1], al
popf ;!; ; Left shift pressed?
jz @f ; - No, skip mark stuff
mov bx, 1 ; - Yes: set up for mark update
mov dh, OP_JAE ; * indicate we've moved UP
call ed_chrmark_update_v ; * update mark (vertical)
@@: jmp ed_check_drag ; Now do the drag check
;-----------------------------------------------------------------------------
ed_key_down: ; Handle down arrow key (for both edit & font boxes)
;-----------------------------------------------------------------------------
jz .editbox
.fontbox:
mov al, [state.hoverchar]
test bl, 2 ; Left shift pressed?
pushf ;!; ; (save answer)
jz @f ; - No, go on
call ed_get_fntmark ; - Yes, make sure we have a mark
@@: add al, 10h
mov [state.hoverchar], al
popf ;!; ; Left shift pressed?
jz .fin ; - No, skip mark stuff
cmp al, byte[di+1] ; - Yes, test 'cursor' vs. mark end
jbe @f ; below? - set start
inc di ; above? - set end
@@: stosb ; ...to 'cursor'
.fin:
jmp ed_do_rbox
.editbox:
mov al, [state.cursor_pos+1] ; Get *current* row
test bl, 2 ; Left shift pressed?
pushf ;!; ; (save answer)
jz @f ; - No, go on
call ed_get_chrmark ; - Yes, make sure we have a mark
@@: inc bp ; Ptr to new row (for dragging)
inc ax
cmp al, byte[si] ; Compare to char height
jb @f
xor al, al ; >=height? - we've wrapped around
sub bp, [si] ; Wrap pointer to top, too
@@: mov [state.cursor_pos+1], al
popf ;!; ; Left shift pressed?
jz @f ; - No, skip mark stuff
mov bx, 0 ; - Yes: set up for mark update
mov dh, OP_JA ; * indicate we've moved DOWN
call ed_chrmark_update_v ; * update mark (vertical)
@@: jmp ed_check_drag ; Now do the drag check
;-----------------------------------------------------------------------------
ed_key_left: ; Handle left arrow key (for both edit & font boxes)
;-----------------------------------------------------------------------------
jz .editbox
.fontbox:
mov al, [state.hoverchar]
test bl, 2 ; Left shift pressed?
pushf ;!; ; (save answer)
jz @f ; - No, go on
call ed_get_fntmark ; - Yes, make sure we have a mark
@@: test al, 0Fh
jnz @f
add al, 10h ; Position x0? wrap around to xF
@@: dec ax ; Otherwise move left
mov [state.hoverchar], al
popf ;!; ; Left shift pressed?
jz .fin ; - No, skip mark stuff
cmp al, byte[di] ; - Yes, test 'cursor' vs. mark start
jb @f ; below? - set start
inc di ; above? - set end
@@: stosb ; ...to 'cursor'
.fin:
jmp ed_do_rbox
.editbox:
mov al, [state.cursor_pos] ; Get *current* column
test bl, 2 ; Left shift pressed?
pushf ;!; ; (save answer)
jz @f ; - No, go on
call ed_get_chrmark ; - Yes, make sure we have a mark
@@: dec ax ; New column = current-1
rol byte[state.cursor_mask], 1
jnc @f
mov al, 7 ; CF set? - we've wrapped around
@@: mov [state.cursor_pos], al
popf ;!; ; Left shift pressed?
jz @f ; - No, skip mark stuff
mov bx, 1 ; - Yes: set up for mark update
mov dh, OP_JAE ; * indicate we've moved LEFT
call ed_chrmark_update_h ; * update mark (horizontal)
@@: jmp ed_check_drag ; Now do the drag check
;-----------------------------------------------------------------------------
ed_key_right: ; Handle right arrow key (for both edit & font boxes)
;-----------------------------------------------------------------------------
jz .editbox
.fontbox:
mov al, [state.hoverchar]
test bl, 2 ; Left shift pressed?
pushf ;!; ; (save answer)
jz @f ; - No, go on
call ed_get_fntmark ; - Yes, make sure we have a mark
@@: inc ax ; Move right
test al, 0Fh
jnz @f
sub al, 10h ; Position x0? wrap around
@@: mov [state.hoverchar], al
popf ;!; ; Left shift pressed?
jz .fin ; - No, skip mark stuff
cmp al, byte[di+1] ; - Yes, test 'cursor' vs. mark end
jbe @f ; below? - set start
inc di ; above? - set end
@@: stosb ; ...to 'cursor'
.fin:
jmp ed_do_rbox
.editbox:
mov al, [state.cursor_pos] ; Get *current* column
test bl, 2 ; Left shift pressed?
pushf ;!; ; (save answer)
jz @f ; - No, go on
call ed_get_chrmark ; - Yes, make sure we have a mark
@@: inc ax ; New column = current+1
ror byte[state.cursor_mask], 1
jnc @f
xor al, al ; CF set? - we've wrapped around
@@: mov [state.cursor_pos], al
popf ;!; ; Left shift pressed?
jz @f ; - No, skip mark stuff
mov bx, 0 ; - Yes: set up for mark update
mov dh, OP_JA ; * indicate we've moved RIGHT
call ed_chrmark_update_h ; * update mark (horizontal)
@@: jmp ed_check_drag ; Now do the drag check
;-----------------------------------------------------------------------------
ed_guide: ; Set horizontal/vertical guide on/off at current cursor position
;-----------------------------------------------------------------------------
.v:
jnz @f ; proceed only in editbox
mov al, [state.cursor_mask]
xor byte[state.guide_cols], al
jmp short .do_it
.h:
jnz @f ; proceed only in editbox
mov al, [state.cursor_pos+1] ; row only
cbw
xchg ax, bx
not byte[state.guide_rows+bx]
.do_it:
call update_lbox_grid
@@: ret
;-----------------------------------------------------------------------------
ed_one_line: ; Delete, insert, or duplicate line at cursor position
; across the entire font
;
; In: AX = 3F00h (delete), 4000h (insert), 4100h (duplicate)
;-----------------------------------------------------------------------------
xchg al, ah
xchg ax, bp ; BP = keycode
push si
push si
lodsb ; AL = font height
lea si, [bp+.actions] ; check restriction
cmp al, [si] ; height OK for requested action?
jne @f ; - yes, proceed
add sp, 4 ; - no, laters (tidy stack first)
ret
@@: call font_update_undo_buf
pop di ; DI -> current font's height
mov byte[di+font.unsaved], 1 ; note that we're making changes
mov ah, [si+3] ; get desired height modification
add al, ah ; apply it
stosb ; make it so
mov al, ah
cbw ; AX = -1 (del) or 1 (ins/dup)
inc ax
jz @f
dec ax ; AX = 0 (del) or 1 (ins/dup)
@@: mov bl, [state.cursor_pos+1]
xor bh, bh ; BX = cursor row
xor dl, dl ; DL = counter
mov dh, [si+6] ; DH = value to AND target line with
lea si, [font.data-1+bx+di] ; SI -> desired line in char #0
.loop_it:
push si
push si
mov cl, 32 ; (CH = 0 from undo update)
sub cx, bx
mov di, scratch
push di
rep movsb ; copy next 32b to scratch
pop si ; SI -> scratch
pop di ; DI -> desired char line
and [di], dh ; clear it (if INSerting a blank)
add di, ax ; DI += 0 (del) or 1 (ins/dup)
inc si
sub si, ax ; SI += 1 (del) or 0 (ins/dup)
mov cl, 32
sub cx, bx
sub cx, ax
rep movsb ; get lines back to where we want 'em
pop si
add si, 32 ; next char
inc dl ; counter++
jnz .loop_it ; iterated through all 256 chars?
mov di, scratch ; compose status message:
push di
shl bp, 1
mov si, [.texts+bp] ; - say what we've done
call str_copy_asc0
dec di
mov si, txt.finishline ; - finish that sentence
mov byte [si+20], 'f'
call str_copy_asc0
pop si
call screen_status_msg
pop di
call font_post_proc.after_height ; done: do the dance
ret
.actions = $-3Fh
; Del, Ins, Dup ; DATA TABLE FOR ACTIONS
db 1, 32, 32 ; <- verboten font heights
db -1, 1, 1 ; <- height adjustment to make
db -1, 0, -1 ; <- to AND w/line at cursor position
.texts = $-(3Fh*2)
dw txt.del_line
dw txt.ins_line
dw txt.dup_line
;-----------------------------------------------------------------------------
ed_height: ; Prompt for a new font height and set it
;-----------------------------------------------------------------------------
push si ;1;
push si ;2;
mov si, txt.set_height
mov ah, 1000b ; +wipe -getkey -cursor -warning
call screen_status_prompt
pop si ;1;
mov bl, byte[si] ; BL = new height
.get_it:
mov di, scratch
push di ;2;
mov al, bl
mov dh, OP_STOSB
call str_dec_byte ; write height as 3-digit decimal
mov al, 2 ; CLOSING markup: 'select' attr OFF!
push ax ;3;
stosb
mov si, txt.lines
call str_copy_asc0
xor al, al
stosb ; add terminating zero
pop ax ;2; ; leading "0" can go play in traffic
pop di ;1; ; so we can replace it with:
stosb ; OPENING markup: 'select' attr ON!
mov si, scratch
mov di, 48
push bx ;2;
mov ah, 0100b ; -wipe +getkey -cursor -warning
call screen_status_prompt ; out: AX = keycode
pop bx ;1;
cmp al, 1Bh ; ESC?
jne @f
pop si ;0;
jmp short .get_out
@@: cmp ah, 48h ; Increase? (up arrow)
jne @f
cmp bl, 32
jae .get_it
inc bx
jmp short .get_it
@@: cmp ah, 50h ; Decrease? (down arrow)
jne @f
cmp bl, 1
jna .get_it
dec bx
jmp short .get_it
@@: cmp al, 0Dh ; Enter?
jne .get_it
.got_it:
pop si ;0; ; SI -> current font height
cmp bl, byte[si] ; new height = current height?
je .get_out ; nothing to see - move along
push si ;1;
call font_update_undo_buf
pop di ;0;
mov byte[di], bl
mov byte[di+font.unsaved], 1
call font_post_proc.after_height ; SANITIZE & DISPLAY
call screen_status_bar
mov si, txt.done_h
mov byte [si], 'F'
call screen_status_msg
ret
.get_out:
call screen_status_bar
ret
;-----------------------------------------------------------------------------
ed_preview: ; Generate preview screen, show it, return
;----------------------------------------------------------------------------
mov di, state.preview ; retrieve column mode:
push di ;!;
mov ax, [di] ; get low byte (memorized value)
mov ah, al ; to high byte (current value)
mov [di], ax ; store setting
.draw:
call screen_gen_preview ; redraw page (bonus: BP = height!)
call vga_init_preview ; go through some boring VGA setup
.get_key:
mov ah, 1100b ; +wipe +getkey -cursor -warning
mov si, txt.pvw_bar ; status bar w/keystroke grab: do we
call screen_status_prompt ; want to redecorate, or get out?
cmp ah, 48h ; UP ARROW:
jne @f
mov ax, 1001h ; ... foreground++
jmp short .got_it
@@: cmp ah, 50h ; DOWN ARROW:
jne @f
mov ax, 7887h ; ... foreground--
jmp short .got_it
@@: cmp ah, 4Dh ; RIGHT ARROW:
jne @f
mov ax, 0110h ; ... background++
jmp short .got_it
@@: cmp ah, 4Bh ; LEFT ARROW:
jne @f
mov ax, 8778h ; ... background--
jmp short .got_it
@@: cmp ah, 44h ; F10:
jne @f
neg byte[state.preview+1] ; ... flip 40/80 column value
call vga_init_preview ; ... make it happen
jmp short .get_key
@@: cmp ah, 14h ; T:
jne .get_out
call .get_text ; ... ask for custom text
jmp short .get_key
.got_it:
mov di, preview_attr
add word[di], ax ; store our fancy new color scheme
and word[di], 7777h ; but keep it in a sane range
call screen_gen_preview.known_h ; now, apply it
jmp short .get_key
.get_out:
call vga_end_preview ; restore VGA to an agreeable state
call font_post_proc.after_undo ; back to editor + re-pad fonts
call screen_status_bar ; decontaminate status row
pop di ;!; ; point at state.preview... again
mov ax, [di] ; going out of preview:
mov al, ah ; shift hi byte (curr. value) to low
xor ah, ah ; byte (memorize) + clear hi byte
mov [di], ax ; store setting
ret ; that's all folks
.get_text: ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
push bp ; PRESERVE FONT HEIGHT
mov ah, 1000b ; +wipe -getkey -cursor -warning
mov si, txt.pvw_input ; status bar -
call screen_status_prompt ; show some friendly instructions
mov si, pvw.pangram
push si
memcp si, scratch+8, 20 ; make a backup
mov bx, pvw_txtlen
mov ax, [bx]
mov [di], ax ; memorize old length too
pop di ; overwrite this
mov bp, di
add di, [bx]
.k: call update_preview_inp ; show what we've got first
xor ax, ax ; grab a key
int 16h
cmp ax, 4B00h ; left arrow?
je .erase
cmp ah, 0Eh ; backspace?
je .erase
cmp ah, 01h ; esc?
je .cancel
cmp ah, 1Ch ; enter? = DONE
je .end_input
cmp al, 0 ; ignore non-ASCII keystrokes
je .k
cmp di, pvw.pangram+40 ; first: are we at end of string?
je @f ; - yes: point to previous
inc byte[bx] ; - no: character count ++
inc di ; + don't retreat
@@: dec di
stosb
jmp short .k ; - now show and get another
.erase:
cmp di, bp ; are we at the beginning?
je .k ; ...do nothing
dec di
mov byte[di], ' ' ; overwrite previous char w/space
dec byte[bx] ; ...character count --
jmp short .k
.cancel:
memcp scratch+8, bp, 20 ; ESC pressed? - restore old string
mov ax, [si] ; ...and the length too
mov [bx], ax
.end_input:
pop bp
call update_preview_inp
ret
;----------------------------------------------------------------------------
ed_swap: ; Swap selected character w/fontbox cursor (hover) character
;----------------------------------------------------------------------------
mov al, [state.currchar]
mov ah, [state.hoverchar]
cmp al, ah
jne @f ; same char? do nothing
ret
@@: call font_update_undo_buf
push ax ;1; ; save character codes
mov bp, .copy
call font_point_to_char ; SI-> font;
mov bx, di ; BX-> currchar
mov dx, si ; DX-> font
mov si, di
mov di, scratch
push di ;2; ; current char @ scratch
call bp
mov si, dx
call font_point_to_char.hover ; SI-> font; DI-> hoverchar
push di ;3; ; hover char @ font
mov si, di
mov di, bx
call bp ; current char <= hoverchar
pop di ;2;
pop si ;1;
call bp ; hover char <= copy of current char
mov di, txt.swapped + 6 ; compose message
mov dh, OP_STOSB
pop ax ;0; ; AL = character code #1
mov bh, ah ; BH = character code #2
call str_dec_byte
inc di
mov al, bh
call str_dec_byte
mov si, txt.swapped ; report
call screen_status_msg
call ed_apply_change ; ONE
jmp ed_apply_change.hover ; TWO
.copy:
memcp si, di, 16 ; single char
ret
;-----------------------------------------------------------------------------
ed_goto_char: ; Prompt for a character, select it, redraw boxes
;-----------------------------------------------------------------------------
mov si, txt.what_char
mov ah, 1110b ; +wipe +getkey +cursor -warning
call screen_status_prompt ; out: AX = keycode
cmp ah, 01h ; was it ESC?
je @f ; ...back away slowly
mov byte[state.currchar], al
@@: call screen_status_bar
jmp short @f
;-----------------------------------------------------------------------------
ed_next_char: ; Increment current char and redraw both edit/font boxes
;-----------------------------------------------------------------------------
inc byte[state.currchar]
jmp short @f
;-----------------------------------------------------------------------------
ed_prev_char: ; Decrement current char and redraw both edit/font boxes
;-----------------------------------------------------------------------------
dec byte[state.currchar]
@@: jmp ed_set_box.init
;-----------------------------------------------------------------------------
ed_mark_all: ; Select entire editbox, or entire font
;-----------------------------------------------------------------------------
jz .editbox
.fontbox:
mov di, state.fntmark
stosb ; AL=01 (ASCII code for Ctrl+A)
dec ax ; state.fntmark_start = 0
stosb
dec ax ; state.fntmark_end = 255
stosb
call update_rbox_in
ret
.editbox:
mov di, state.chrmark_rng_h
mov ax, 7 ; H. range: 0..7
stosw
lodsw ; AX = word[si] = height (hi byte 0)
mov cx, ax ; CX = height
dec ax
stosw ; V. range: 0..height-1
mov al, 0FFh
inc cx ; count=CX+1 (_mask + CX*height rows)
rep stosb
call update_lbox_char
ret
;-----------------------------------------------------------------------------
ed_unmark: ; DEselect entire editbox, or entire font
;-----------------------------------------------------------------------------
jz .editbox
.fontbox:
mov di, state.fntmark
xor al, al
stosb ; fntmark
stosb ; fntmark_start
stosb ; fntmark_end
jmp ed_do_rbox.i ; repaint innards only