-
Notifications
You must be signed in to change notification settings - Fork 5
/
SCREEN.inc
2005 lines (1818 loc) · 79.8 KB
/
SCREEN.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
; CONVENTIONS - FUNCTION NAME PREFIXES:
;
; 'screen': function can safely be called from non-'screen' functions in any
; part of the program, because it sets ES to VRAM + restores on
; exit, and ensure correct color attributes
; 'draw': may be called safely ONLY from a 'screen' function
; 'update': for dynamic UI elements; should be safely callable from 'screen'
; functions or from anywhere else, as they depend on state and have
; to be changed dynamically
;-----------------------------------------------------------------------------
screen_init_text_IO: ; Save some space because this is used a lot
;-----------------------------------------------------------------------------
mov es, [seg_screen] ; VGA text mode RAM
mov bx, [state.pal_attrmap] ; lookups into attr_map
ret
;-----------------------------------------------------------------------------
screen_gen_editor: ; Draw everything! (Call whenever changing palettes)
;-----------------------------------------------------------------------------
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
call screen_status_bar ; Status bar (line 0)
xchg ax, cx ; CL=0 here => AL = NULL char
mov ah, [att.normal_right+bx] ; Fill common background
mov cx, 80*99
rep stosw
mov ah, [att.normal_left+bx] ; Left panels:
mov dh, 2
mov dl, 21 ; ... for 25-line screen
mov di, VRAM_ED25+(3*ROW)
@@: mov cl, 43
rep stosw
add di, (80-43)*2
dec dl
jnz @b
mov dl, 44 ; ... for 50-line screen
mov di, VRAM_ED50+(5*ROW)
dec dh
jnz @b
; Draw dynamic UI elements
call update_tabs
call ed_set_box.init ; Draws initial box stuff
call update_lbox_grid
; Draw dual-screen elements (stateful labels done in ed_get_key)
mov cl, loc_formatted_count ; String count (keep it correct!)
mov si, loc_formatted ; Point to first one
@@: push cx
mov ax, draw_formatted_asc0 ; How/what are we drawing?
clc
call locate_n_draw_x2 ; Do it
pop cx
loop @b
mov cl, ellipsis_count ; Do the same for ellipses
mov si, loc_ellipsis ; Point to first one
@@: push cx
mov ax, draw_ellipsis ; How/what are we drawing?
clc
call locate_n_draw_x2 ; Do it
pop cx
loop @b
mov si, loc_attstr_esc ; And why not Esc too
mov ax, draw_attr_asc0 ; How/what are we drawing?
clc
call locate_n_draw_x2 ; Do it
mov si, loc_attstr_esc2
mov ax, draw_attr_asc0
clc
call locate_n_draw_x2 ; and again for 2nd one
call update_box_legend ; Box-specific caption+line+labels
; Done: return to sender
pop es ; Restore previous I/O target
ret
;-----------------------------------------------------------------------------
screen_gen_files: ; Create file dialog; title varies depending on action
;-----------------------------------------------------------------------------
mov ax, [fdlg.actkey] ; presentation varies by action key
cmp ax, 1205h ; EXPORT?
jne @f ; - nah: continue
mov si, .fmt ; - yeah: look up which extension
mov bx, [fdlg.export_fmt] ; to put in the title
shl bx, 1
mov si, [si+bx]
mov di, txt.fdt_ext ; + do it
times 2 movsw
@@: mov di, file_keys ; see ed_get_key
mov cx, NUM_FKEYS ; "
repne scasw ; find keycode in the list
add di, .titles-2-file_keys ; find pointer to corresponding title
mov si, [di] ; get the text
mov di, si
xor al, al
mov cl, 0FFh ; a big enough max length
repne scasb ; now find the terminating zero
sub di, si ; ...this is our length
and di, 0FFFEh ; ...make sure it's even, so we can
mov bp, di ; ...use BP for centering later
push es ;1; ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
mov di, VRAM_FILES ; fill area with solid background
mov cx, 24*ROW/2
mov ah, [att.normal_right+bx] ; <TEMP?>
mov al, 20h
rep stosw
mov di, VRAM_FILES+ROW+2 ; now set location for THE BOX
mov ah, [att.dlg_title+bx] ; attribute for first row only
push ax ;2;
mov dx, 22 ; row counter
@@: mov cx, (ROW/2)-2 ; box width
rep stosw
add di, 2*2
mov ah, [att.dlg_bg+bx] ; attribute for all other rows
dec dx
jnz @b
pop ax ;1; ; restore title attribute
mov di, VRAM_FILES+ROW+80 ; acquire target
sub di, bp ; center the text...
call draw_asc0 ; ...and write it out
pop es ;0; ; restore previous I/O target
ret
.titles:
dw txt.fdt_s, txt.fdt_s, txt.fdt_l, txt.fdt_l, txt.fdt_i, txt.fdt_e
; F2/save ^S/save F3/load ^L/load ^I/import ^E/export
.fmt:
dw txt.ext_com, txt.ext_bmp, txt.ext_xbin
; 'COM' 'BMP' 'XB'
;-----------------------------------------------------------------------------
screen_gen_preview: ; Create preview page; varies depending on font height
;
; In: SI -> current font structure
; Out: BP = font height
;-----------------------------------------------------------------------------
mov bp, word[si] ; BP: current user font height
.known_h: ; (call here if already set)
push bp ; + save it for returning
; Prepare current character number (for tiling)
mov al, [state.currchar] ; tile current character
mov di, pvw.final2 + 1 ; target for decimal codepoint
mov dh, OP_STOSB ; no attributes
call str_dec_byte ; write it
; Draw to desired page
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
mov bx, draw_attr_asc0.x ; our favorite routine to call here
mov al, 20h ; fire blanks
mov ah, [preview_attr.regular] ; snatch wanted attribute
mov di, VRAM_PVW_AREA ; stomp over the entire virtual page
mov cx, 100*ROW/2
rep stosw
; "Pack my liquor box with five dozen jugs"
push ax
mov ah, [preview_attr.inverse] ; swap FG/BG for this one
mov di, VRAM_PVW_TEXT
mov si, pvw.pangram
call bx ;draw_attr_asc0.x
pop ax
mov di, ROW
cmp bp, 21 ; skip separating row if height>21
ja @f
shl di, 1
@@: add di, VRAM_PVW_TEXT
; Draw all 256 characters
xor al, al ; start at 0
.r: mov cl, 32 ; chars per row (CH = 0 here)
.c: stosw ; DO IT
inc al ; value++
jz @f ; exit if all 256 done (wrapped to 0)
loop .c
add di, ROW-32*2
jmp short .r
; Draw three-four stuff
@@: sub di, ROW*7-2 ; si = pvw.threefour
push di ;1; ; for upper-block fixups
mov cl, 8
@@: lodsb
times 3 stosw
lodsb
times 4 stosw
add di, ROW-7*2
loop @b
mov dx, -(32+1)*2+15*2
cmp bp, 23 ; skip separating row if height>23
ja @f
mov dx, 7*2+80+15*2
@@: add di, dx
push di ;2; ; for upper-half integral fixups
; Draw boxes and math stuff
mov cl, 3 ; SI = pvw.boxes
@@: call bx ;draw_attr_asc0.x
add di, ROW-(24*2)
loop @b
sub di, ROW*2+14*2
call bx ;draw_attr_asc0.x
mov dx, ROW*2-13*2
cmp bp, 22 ; skip separating row if height>22
ja @f
add dx, ROW
@@: add di, dx
; Draw last 3 rows
mov dx, 3 ; SI = pvw.final1
.l: call bx ;draw_attr_asc0.x
inc di
inc di
mov al, [state.currchar] ; tile current character
mov cl, 13
call draw_char_CX_times
add di, 3*2 + 1
call bx ;draw_attr_asc0.x ; print reminder of line
cmp dl, 3 ; top row only:
je .m ; skip
mov cl, 9 ; else:
sub cl, dl ; draw (9-DL) 'alignment test'
@@: mov al, 219 ; characters
stosw
lodsb
stosw
loop @b
.m: add di, ROW-40*2 ; next row
dec dx
jnz .l
; Do single-char fixups
pop di ;1;
sub di, 14*2
mov al, 244 ; upper-half integral
stosw
add di, ROW*2-2
inc ax ; lower-half integral
stosw
pop di ;0;
add di, ROW*2+4*2
mov cl, 2
mov al, 223 ; upper block char
@@: stosw ; do fixup
inc di
inc di
stosw
add di, ROW-3*2
loop @b
; All done
pop es ; restore previous I/O target
pop bp ; return height
ret
;-----------------------------------------------------------------------------
screen_status_bar: ; Cursor OFF, draws status bar @ addr. 0 for split-screen
;-----------------------------------------------------------------------------
call vga_set_cursor.off
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
xor di, di
mov cx, 80
mov ah, [att.version+bx] ; nice attribute for messages
mov al, 20h
rep stosw
mov di, 2
mov si, attstr_status_bar
call draw_attr_asc0
mov al, 0B3h ; '³' vertical line
stosb
mov di, (68-VER_STRLEN)*2 ; spaces before version string
stosb
inc di
mov cl, 3
@@: call draw_attr_asc0
loop @b
pop es ; restore previous I/O target
ret
;-----------------------------------------------------------------------------
screen_status_msg: ; Prints message to status bar
;
; In: SI -> pointer to ASCIIZ string
; Destroys: CX, AX, BX
;-----------------------------------------------------------------------------
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
mov di, 30
call draw_asc0
mov cx, 62*2 ; fill the rest with NULLs
sub cx, di ; (Do 79-(DI/2) times)
shr cl, 1
xor ax, ax
mov ah, [att.version+bx]
rep stosw
pop es ; restore previous I/O target
ret
;-----------------------------------------------------------------------------
screen_status_prompt: ; Displays a configurable prompt in the status bar
;
; In: AH = display parameters:
; bit 0: STYLE; 0 = normal prompt; 1 = warning prompt
; bit 1: CURSOR; 0 = off; 1 = on
; bit 2: RETURN; 0 = immediate, 1 = wait for a key first
; bit 3: WIPE; 0 = keep contents & print @ DI; 1 = clear bar
; SI-> ASCIIZ string to display
; DI-> screen VRAM target (if AH bit 3 is set)
; Out: AX = key code (if requested w/AH bit 2)
; Destroys: CX, AX, DX, BX
;-----------------------------------------------------------------------------
push ax
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
xchg ax, dx ; DH <- AH (display parameters)
test dh, 1
mov ah, [att.prompt+bx] ; parameter bit 0 set?
jz @f ; - nope, do not panic
mov ah, [att.prompt_warn+bx] ; - yep, use warning attr.
@@: test dh, 8 ; parameter bit 3 set?
jz @f ; - no, just go print
xor al, al ; - yep, wipe the bar first
xor di, di
mov cx, 80
rep stosw
mov di, 2
@@: mov dl, [att.prompt_hilite+bx] ; yet another BORING drawing routine
mov dh, [att.prompt_select+bx] ; for ASCIIZ strings with custom
.go_markup: ; markup... only used for propmpts
lodsb ; so let's inline this nonsense
cmp al, 0
je .msg_done ; 0? - Get out
cmp al, 1
jne @f ; 1? - Swap normal <-> highlight
xchg ah, dl
jmp short .go_markup
@@: cmp al, 2
jne @f ; 2? - Swap normal <-> select
xchg ah, dh
jmp short .go_markup
@@: stosw ; none of the above? WRITE THE SUCKER
cmp di, 158
ja .msg_done ; about to exceed row length? ABORT
jmp short .go_markup
.msg_done:
call vga_set_cursor.off
pop es ; restore previous I/O target
pop ax
test ah, 2 ; parameter bit 1 set?
jz @f ; - no; begone, ye blinkin' block
call vga_place_cursor ; - yes; enable the cursor at DI
@@: test ah, 4
jz @f ; parameter bit 2 set?
xor ax, ax
int 16h ; - wait for a keystroke
@@: ret
;-----------------------------------------------------------------------------
screen_status_menu: ; Displays menu of selectable options in the status bar
;
; In: DI -> screen VRAM target
; SI -> menu: DW num_options; then:
; times num_options DB 'text' (EXACTLY 4 CHARS)
; times num_options DW return_val
; Out: CF = clear? option was selected; set? user pressed ESC
; DX = number of selected option if CF clear
; Destroys: EVERYTHING
;-----------------------------------------------------------------------------
push es ;1; ; save previous I/O target
call vga_set_cursor.off ; shoo the cursor away
lodsw ; number of options
xchg ax, cx
mov bp, cx ; + back it up
push di ;2; ; screen VRAM target
mov di, scratch ; construct menu in scratch
mov al, ' '
@@: stosb ; space
times 2 movsw ; copy 4 chars of text
times 2 stosb ; space*2
loop @b
xor al, al ; terminating zero
stosb
xchg cx, dx ; DX = CX=0= selected option number
pop di ;1; ; screen VRAM target
.menu_loop:
call screen_init_text_IO ; ES -> VGA text, BX = attr_map
mov si, scratch ; menu please
push di ;2;
mov ah, [att.prompt_hilite+bx]
call draw_attr_asc0.x
pop di ;1; ; screen VRAM target
push di ;2;
mov al, 14
mul dl
add di, ax ; VRAM target += (14*option#)
mov al, 11h
stosb
mov al, [att.prompt_select+bx]
mov cx, 6
call draw_char_CX_times ; actually attr, but DI is odd
dec di
dec di
mov al, 10h
stosb
.get_key:
xor ax, ax ; now let's go get some input
int 16h
cmp ax, 011Bh ; Esc?
jne @f
stc ; - chicken out w/CF set
jmp short .done_here
@@: cmp ax, 1C0Dh ; Enter?
jne @f
clc ; - return w/CF clear, DX=selection
jmp short .done_here
@@: push cs ;3; ; neither Esc nor Enter?
pop es ;2;
mov di, .keys ; - see if we increase/decrease the
mov cl, MENUKEYS ; option number: consult keylist
repne scasw
jne .get_key ; key not in list? try again
pop di ;1; ; screen VRAM target... AGAIN
cmp cx, MENUFWD
jb @f
inc dx ; num_option++
cmp dx, bp ; >= allowed number?
jne .menu_loop ; - no, ok
xor dx, dx ; - yes, wrap to 0
jmp short .menu_loop
@@: dec dx ; num_option--
jns .menu_loop ; - if >=0, ok
add dx, bp ; - if negative, wrap to max
jmp short .menu_loop
.done_here:
pop di ;1; ; keep the stack tidy
pop es ;0; ; restore previous I/O target
pushf ; preserve CF
push dx ; preserve DX (cursor OUTs mangle it)
call screen_status_bar ; clear that crap
pop dx
popf
ret
.keys:
dw 0F09h ; Tab
dw 3920h ; Space
dw 4800h ; Up arrow
dw 4838h ; Up arrow*
dw 4D00h ; Right arrow
dw 4D36h ; Right arrow
MENUFWD = 4 ; CX>=this if key means forward
dw 4B00h ; Left arrow
dw 4B34h ; Left arrow*
dw 5000h ; Down arrow
dw 5032h ; Down arrow*
MENUKEYS = ($-.keys)/2
;-----------------------------------------------------------------------------
update_filedlg: ; Update file dialog state and contents
;-----------------------------------------------------------------------------
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
; Status bar first
mov ah, [att.prog_name+bx] ; prepare attribute #1
mov dh, [att.version+bx] ; ...and #2
xor di, di
mov si, txt.fdbar
mov cx, 10 ; CAREFUL
@@: call draw_attr_asc0.x ; draw key legend
xchg ax, dx ; switch attributes
loop @b
test byte[fdlg.focus], 1 ; where's our focus?
pushf ;1; (save the answer)
jnz @f ; - dir list: keep legend as-is
mov di, 2 ; - text input: relocate
xchg ax, dx ; ...switch attributes again
call draw_attr_asc0.x ; ...clobber left half w/prompt
mov cl, 15 ; ...and add some blank space for
rep stosw ; good measure
; Now see about those attributes
@@: lea bp, [bx+FD_ATTDIFF] ; BP = transform 'ON' attrs to 'OFF'
popf ;0; ; where were we again?
pushf ;1; ; (nope, not done with this yet)
jz @f ; - text input: start w/'ON'
xchg bx, bp ; - dir list: start w/'OFF'
; Take care of input label+field
@@: mov si, txt.fd_label
mov di, VRAM_FILES+ROW*3+6
mov ah, [att.dlg_ON_label+bx] ; set a proper attribute
call draw_attr_asc0.x ; print that label
mov ah, [att.dlg_ON_text+bx] ; now for the input field contents
call update_filedlg_inp.a ; - SHOW 'EM
; Show the selected directory
xchg bx, bp ; swap 'ON' and 'OFF' attrs
mov ah, [att.dlg_ON_label+bx]
mov al, 196 ; 'Ä' horizontal line
mov si, fdlg.truepath
mov di, VRAM_FILES+ROW*5+6
push di ;2;
mov cx, 74
rep stosw ; fill out a nice separating border
pop di ;1;
call draw_attr_asc0.x ; show current path
stosw ; ...and another blank
; Draw file list area
mov di, VRAM_FILES+ROW*6+6
mov bp, di ; store this destination
mov ah, [att.dlg_ON_vline+bx]
mov dx, 16 ; rows
.r: mov cl, 5 ; column
jmp short @f ; no separator before first column
.c: mov al, 179 ; '³' vertical line
stosw
@@: push cx
mov cl, 14
mov al, ' '
rep stosw
pop cx
loop .c
add di, 6*2 ; assume position for next row
dec dx
jnz .r
cmp word[fdlg.count], dx ; still haven't got any files? (DX=0)
jne @f
mov si, txt.reading ; - then say we're busy reading
mov di, bp
call draw_attr_asc0.x
jmp short .done
; Got files? List 'em now
@@: mov cx, 80 ; each page has 5*16=80 files
mov si, [fdlg.pagebase] ; fseg.fname_ptrs = 0, so...
mov ah, [att.dlg_ON_text+bx]
mov dx, [fdlg.count] ; DX counts down from total
mov bp, [fdlg.fnum_rel] ; BP = # of selected file on page;
shl bp, 1 ; make it OFFSET (for position)
push si ;1;
push ds ;2;
mov ds, [seg_fseg] ; .++++++ DS <- FILES SEG +++++++,
push bx ;3; ; | save attr map |
sub dx, si ; | fseg.fname_ptrs = 0, so... |
shl si, 1 ;fseg.fname_ptrs=0 ; | SI-> file #1 |
mov bx, fseg.pos ; | BX -> VRAM position table |
add bp, bx ; | BP -> pos. for current file |
.print: ; | |
mov di, [bx] ; | get first one |
call draw_fname ; | |
inc bx ; | next VRAM position |
inc bx ; | |
dec dx ; | counter-- |
loopnz .print ; | exceeded file count? ABORT |
mov di, [bx] ; | pos++ (for 'too many' case) |
pop bx ;2; ; | retore attr map |
push di ;3; ; | |
mov al, [cs:att.dlg_ON_hilite+bx] ; | highlight selected file |
mov di, [ds:bp] ; | |
dec di ; | |
mov cl, 14 ; | |
call draw_char_CX_times ; | (this zeroes out CX) |
pop di ;2; ; | |
pop ds ;1; ; `+++++++ DS <- BASE SEG +++++++'
; Print a notice if list is incomplete (dir contains to many files)
pop dx ;0; ; DX = pagebase
cmp [fdlg.too_long], cl ; is the flag zero? (CL=0)
je .done ; - yep: all files were listed
cmp dx, (MAX_FILES/80)*80 ; - are we on the last page?
jne .done ; - no: go on
mov si, txt.too_many ; - yes: show the warning
call draw_attr_asc0.x
add di, ROW-(9*2)
call draw_attr_asc0.x
.done:
popf ;0; ; check our focus once more
jz @f ; - text input: keep cursor on
call vga_set_cursor.off ; - dir list: dismissed
@@: pop es ; restore previous I/O target
ret
;-----------------------------------------------------------------------------
update_file_hilite: ; Update highlight in dir list (ON/OFF)
;
; In: CF = 0 to set highlight OFF, 1 to set it ON
; AX = number of file on current page (0..80)
;-----------------------------------------------------------------------------
push bx
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
push ds
push di
push cx
push ax
jnc @f
add bx, NUM_ATTRMAPS ; CF set? use highlight attr.
@@: mov ds, [seg_fseg]
mov di, fseg.pos ; position table
add di, ax
add di, ax
mov di, [di] ; locate target character cell
mov al, [cs:att.dlg_ON_text+bx]
dec di ; go to previous cell's attr. byte
mov cl, 14 ; CH = 0 if we're here
call draw_char_CX_times ;
pop ax
pop cx
pop di
pop ds
pop es
pop bx
ret
;-----------------------------------------------------------------------------
update_filedlg_inp: ; Update file dialog input field
;
; IN: [fdlg.input] = ASCIIZ string
;-----------------------------------------------------------------------------
mov ah, -1
.a: ; call here if attribute is known
push di ; PRESERVE INPUT LOCATION
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
cmp ah, -1
jne @f ; not coming from update_filedlg?
mov ah, [att.dlg_ON_text+bx] ; then always use "ON" attribute
@@: mov si, fdlg.input
mov di, I_VRAM
call draw_attr_asc0.x
push ax ;!; ; save crap attr + NULL char
call vga_place_cursor ; show cursor after end of string
pop ax ;!;
mov cx, I_VRAM+ILEN*2
sub cx, di
shr cx, 1
rep stosw ; fill w/blanks to end of input!
pop es ; restore previous I/O target
pop di ; RESTORE INPUT LOCATION
ret
;-----------------------------------------------------------------------------
update_preview_inp: ; Update preview screen w/custom text string
;
; IN: [pvw_txtlen] = length of input string
; [pvw.pangram] = ASCIIZ string
; BP =< 32 if input was ended (enter/esc)
;-----------------------------------------------------------------------------
push di ; PRESERVE INPUT LOCATION
push es ; I/O target = screen: ES -> VGA text
mov es, [seg_screen] ; mode RAM (don't touch BX here!)
mov al, [preview_attr.inverse]
mov ah, al
cmp bp, 32
jna @f
mov al, 70h
cmp al, ah
jne @f
mov al, 60h
@@: mov ah, al
mov di, VRAM_PVW_TEXT
push di
mov si, pvw.pangram
call draw_attr_asc0.x
pop di
mov ax, [pvw_txtlen]
cmp al, 40
jb @f
dec ax
@@: shl ax, 1
add di, ax
call vga_place_cursor ; show cursor after end of string
pop es ; restore previous I/O target
pop di ; RESTORE INPUT LOCATION
ret
;-----------------------------------------------------------------------------
update_box_legend: ; Redraws caption, line, and box-specific labels
;-----------------------------------------------------------------------------
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
mov si, loc_cap_line ; Draw caption line on right side
mov ax, draw_caption_line ; How/what are we drawing?
clc
call locate_n_draw_x2 ; Do it (both screens)
mov si, loc_attstr_editbox_cap ; Now do the actual caption, and the
mov dx, loc_f_editbox ; box-specific labels
test byte[state.currbox], 1
jz @f
mov si, loc_attstr_fontbox_cap
mov dx, loc_f_fontbox
@@:
mov ax, draw_attr_asc0 ; First the caption
clc
call locate_n_draw_x2 ; Do it (both screens)
mov si, dx ; box-specific label
mov ax, draw_formatted_asc0 ; (Space/Enter legend)
clc
call locate_n_draw_x2 ; Do it (both screens)
pop es ; Restore previous I/O target
ret
;-----------------------------------------------------------------------------
update_stateful: ; Updates all 'stateful' action labels on screen
;-----------------------------------------------------------------------------
push es ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
mov bp, .do_it
; DRAG, GUIDE: enabled only in editbox
mov si, loc_f_stateful.drag
test byte[state.currbox], 1 ; ZF set = enabled (only for editbox)
call bp ; SI -> drag
call bp ; SI -> guide
; DESELECT: enabled if selection exists for current box
; CUT, COPY: font box = always enabled; editbox = as above
pushf ;1;
pushf ;2;
mov di, state.chrmark_mask ; word to check for editbox
jz @f ; ZF set? = editbox (from prev check)
mov di, state.fntmark ; word to check for fontbox
@@: xor ax, ax
cmp word[di], ax ; got a relevant marking?
je @f ; - no? skip
dec ax
@@: inc ax ; - yes? ZF should be set now
push ax ;3;
call bp ; UNMARK
pop ax ;2; ; 0 or 1
popf ;1; ; for cut/copy:
jz @f ; - editbox? - reuse condition
xor ax, ax ; - fontobx? - always allow
@@: dec ax
mov [state.can_copy], ax ; bit 0 = 1 if enabled
inc ax
call bp ; CUT
call bp ; COPY
; PASTE: enabled if clip type and dimensions match relevant box
mov al, 1
popf ;0; ; ZF set? = editbox
jz .e
cmp word[state.clip_len], 0 ; FONTBOX: length must be > 0
jne .g
inc ax ; fail? ensure ZF won't be set
@@: jmp short .g ; all ok? ensure it WILL be
.e: dec ax
cmp word[state.clip_dim], 0 ; EDITBOX: dimensions must be > 0
jne .g ; ok? keep AL=0 so ZF will be set
dec ax ; fail? -1 - ensure it won't be
.g: sub al, byte[state.clip_type] ; good _type: 1=fontbox, 0=editbox
call bp
mov al, 1
jz @f ; (flags preserved!)
dec ax
@@: mov byte[state.can_paste], al
; REVERT: enabled if active font isn't '<NoName>' & has unsaved changes
mov di, [state.currfont_ptr] ; Point at current font
mov al, byte[di+font.unsaved] ; AL = 1 if unsaved
mov ah, byte[di+font.fname]
cmp ah, '<'
je @f
cbw ; AH = 0 if **NOT** '<NoName>'
@@: dec ax ; ZF set if both conditions true
call bp ; draw
mov al, 1
jz @f ; (flags preserved!)
dec ax
@@: mov byte[state.can_revert], al
; UNDO: enabled if current font has undo buffer
cmp byte[di+font.can_undo], 1
call bp
; 9-DOT CELL: enabled unless we're in DOSBox with a non-"vgaonly" config
test byte[state.is_bad_vga], 1
call bp
; LGE: enabled if we're in 9-dot mode only
test byte[state.clkmode80], 1
call bp
; DUP LINE, INS LINE: enabled if current font is <32 lines tall
test byte[di], 100000b ; DI -> current font (.height)
call bp ; dup line
call bp ; ins line
; DEL LINE: enabled if current font is >1 line tall
mov al, 33
sub al, [di]
test al, 100000b
call bp
; SWAP CHARS: enabled if current char != hover char
mov al, byte[state.currchar]
mov ah, byte[state.hoverchar]
cmp al, ah
mov al, ah
jne @f ; invert sense of zero flag (UGLY)
inc al
@@: xor al, ah
call bp
call update_8_9_dot_hilite ; update these too
pop es ; Restore previous I/O target
ret
.do_it:
push di ; preserve font ptr if applicable
push bp ; function ptr, too
pushf ; and flags for repeated ops
mov ax, draw_formatted_asc0
jz @f ; ZF set? - draw label as ENABLED
mov ax, draw_formatted_asc0.off ; ZF clear? - draw label as DISABLED
@@: clc
call locate_n_draw_x2 ; Do it
popf
pop bp
pop di
ret
;-----------------------------------------------------------------------------
update_lbox_char: ; Updates actual character + marking in edit box
;-----------------------------------------------------------------------------
push es ;-1 ; I/O target = screen: ES -> VGA text
call screen_init_text_IO ; mode RAM, BX = attr_map index
push es ;-2
push ds ;-3
pop es ;-2 ; Draw to scartch RAM first, to
mov di, scratch ; speedup later VRAM update
push di ;-3
mov ax, [state.currchar] ; High byte = 0
mov cl, 5
shl ax, cl ; char*32 (offset in font.data)
xchg bx, ax ; `-> BX
mov ax, [state.currfont_ptr]
mov si, ax
mov cx, word[si] ; CX = height (hi byte 0)
push cx ;-4
add ax, font.data ; Point to current font data
add bx, ax ;+^ lea? ; BX-> line 0 of current character
mov si, editbox_ON_att ; SI-> editbox attributes
test byte[state.currbox], 1 ; Is editbox active?
jz @f ; - yep, keep active attrs
mov si, editbox_OFF_att ; - nope, use inactive ones
@@: mov bp, state.chrmark_rows ; BP-> row 0 of editbox mark
mov ah, 10000000b ; AH = current col/px (rotating mask)
mov al, byte[state.clkmode80] ; AL = Bit0 = 0? 9-dot; = 1? 8-dot
.row:
push cx ;-5
mov dh, byte[bx] ; DH = char row bitmask (0=BG, 1=FG)
mov dl, byte[bp]
and dl, byte[state.chrmark_mask] ; DL = ANDed mark bit mask
mov cl, 8 ; (0=off, 1=on)
.pel:
push si ;-6 ; "px0" at start
test dh, ah ; BG or FG?
jz @f ; - BG; "px0"
inc si ; - FG; "px1"
@@: test dl, ah ; Marked or not?
jz @f ; - N; keep
inc si ; - Y: advance two more to
inc si ; "px?_mark"
@@: movsb ; Copy to scratch
ror ah, 1 ; Next column to check
test si, 1 ; * if was BG, bit0 *SET* (movsb^)
pop si ;-5
loop .pel ; Next pixel
push si ;-6 ; Done with 8 columns; have 9th?
jnz @f ; * Was last SI odd? (=BG ^)
inc si ; - no: pixel was FG, add one
@@: add si, edbox_attrs.px0_col9 ; Get col9 attr, whether BG/FG
test al, 1 ; Need to draw the 9th?
jnz @f ; - nope, skip it
movsb ; - yep, do it
@@: pop si ;-5
inc bx ; Next line of current char
inc bp ; Next row of editbox mark
pop cx ;-4
loop .row
test al, 1 ; Do the following only if in
jnz .ok ; 9-dot mode?
add si, edbox_attrs.px0_col9 ; Get col9 attr - now BG only!
pop cx ;-3 ; Restore font height
pop di ;-2 ; DI-> Scratch
push di ;-3
push cx ;-4
test byte[state.attr_modectl], 4 ; if B2=0 (LGE off), force BG
jz @f ; column 9
mov ah, [state.currchar] ; UGLY HACK IS UGLY
and ah, 0E0h ; Are you a line-graphics char
cmp ah, 0C0h ; w/a right extension?
je .ok ; - yes? okay then
@@: add di, 8 ; - no? NO 9TH COLUMN FOR YOU!
movsb
dec si
loop @b
.ok:
; Finished drawing in scratch RAM - copy to the screen:
pop cx ;-3 ; Restore font height
pop si ;-2 ; SI-> Scratch
pop es ;-1 ; Now write to VGA
mov dh, al ; DH = Bit0 = 0? 9-dot; = 1? 8-dot
mov di, VRAM_ED25+5*ROW+3*2 ; ED25 " "
mov al, byte[state.screen]
inc ax
test al, 2
jz @f
mov di, VRAM_ED50+10*ROW+6*2 ; ED50 screen: target offset
mov al, -1
@@: cbw
xchg ax, bx ; BX = 1 for ED25, -1 for ED50
macro _w_px { lodsb ; Get attribute
inc di ; Advance to attribute byte
stosb ; Copy attr
add di, bx ; ED50? - effectively "dec di"
stosb } ; ED25? - paint next char
.w_row:
push di
rept 8 {_w_px} ; Unrolled the inner loop...
test dh, 1 ; 9-dot (paint an extra cell)?
jnz .w_next
_w_px