-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgui.asm
More file actions
1630 lines (1511 loc) · 39.1 KB
/
Copy pathgui.asm
File metadata and controls
1630 lines (1511 loc) · 39.1 KB
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
TITLE ggWP
;========= COLOR ENUM =========
PL_BLACK equ 00h
PL_BLUE equ 01h
PL_GREEN equ 02h
PL_CYAN equ 03h
PL_RED equ 04h
PL_MAGENTA equ 05h
PL_BROWN equ 06h
PL_LGRAY equ 07h
PL_DGRAY equ 08h
PL_LBLUE equ 09h
PL_LGREEN equ 0Ah
PL_LCYAN equ 0Bh
PL_LRED equ 0Ch
PL_LMAGENTA equ 0Dh
PL_YELLOW equ 0Eh
PL_WHITE equ 0Fh
;========= COLOR ENUM =========
;========= SCANCODE ENUM =========
KEY_LEFT equ 4B00h
KEY_RIGHT equ 4D00h
KEY_DOWN equ 5000h
KEY_UP equ 4800h
KEY_ESC equ 011Bh
KEY_ENTER equ 1C0DH
KEY_F1 equ 3B00h
KEY_F2 equ 3C00h
KEY_F3 equ 3D00h
KEY_F4 equ 3E00h
KEY_F5 equ 3F00h
KEY_F6 equ 4000h
KEY_F7 equ 4100h
KEY_F8 equ 4200h
KEY_F9 equ 4300h
KEY_F10 equ 4400h
KEY_BACKSPACE equ 0E08h
KEY_DEL equ 5300h
;========= SCANCODE ENUM =========
;========= OTHER PARAM =========
MAX_LEN_FILENAME equ 8d ;Working up to 8 ?
MAX_LEN_SEARCH_STR equ 16d
SELECTION_COLOR equ PL_RED
;Cursor parameters
BG_COLOR equ PL_BLUE
CURSOR_COLOR equ PL_LGRAY
CURSOR_BG_COLOR equ PL_BLUE
CURSOR_TYPE equ 219d
;UI parameters
UIBUTTONOFFSET equ 103d ;Offset to first Buttons
UIBUTTONSPACING equ 65d ;Spacing between Buttons
UIBUTTONHEIGHT equ 30d ;Button height
UIBUTTONWIDTH equ 32d ;Button width
UIBUTTONNUMBER equ 5d ; Number of buttons
UIBUTTONXPOS equ 24d ; Button X position
UIROWCOLSTRPOS equ 64d; Row and column count , position in y
;========= OTHER PARAM =========
;========= MACRO DEFINITIONS =========
LOG_HANDLE_N_ERROR MACRO FileHandleReg, FileErrorCodeReg
local proc_success
jnc proc_success
mov FileErrorCodeReg,ax
;mov FileHandleReg,0000h
POPALL
RET
proc_success:
mov FileHandleReg,ax
mov FileErrorCodeReg,0000h
POPALL
RET
ENDM
PASS_RECT_PARAM MACRO Xpos, Ypos, Xlen, Ylen, Color
;Pass parameters to register for rectangle function
mov RectXpos,Xpos
mov RectYpos,Ypos
mov RectXdim,Xlen
mov RectYdim,Ylen
mov RectColor,Color
ENDM
PASS_SEL_PARAM MACRO Xpos, Ypos, Xlen, Ylen, Color
;Pass parameters to register for selection function
mov BoxXpos,Xpos
mov BoxYpos,Ypos
mov BoxXdim,Xlen
mov BoxYdim,Ylen
mov BoxSelColor,Color
ENDM
MOVRB MACRO reg1, reg2
;Mov byte reg2 to reg1
push bx
xor bx,bx
mov bl,reg2
mov reg1,bl
pop bx
ENDM
MOVRW MACRO reg1, reg2
;Mov word reg2 to reg1
push bx
mov bx,reg2
mov reg1,bx
pop bx
ENDM
MULW MACRO reg1, reg2
;MUL word reg2 to reg1 and store to reg1
PUSHALL
xor dx,dx
mov bx,reg2
mov ax,reg1
mul bx
mov reg1,ax
POPALL
ENDM
PUSHALL MACRO
push ax
push cx
push dx
push bx
ENDM
POPALL MACRO
pop bx
pop dx
pop cx
pop ax
ENDM
CMPSC MACRO var1, var2
push bx
mov bx,var2
cmp var1,bl
pop bx
ENDM
PUT_PIXEL MACRO x_cor, y_cor, color
PUSHALL
xor bx,bx
mov ah,0Ch
mov al,color
mov cx,x_cor
mov dx,y_cor
int 10h
POPALL
ENDM
SET_CURSOR MACRO row, col
;Set cursor to row,col
PUSHALL
mov ax,0200h
xor bx,bx
mov dh,row
mov dl,col
int 10h
POPALL
ENDM
PUT_CURSOR MACRO rowPos, colPos ,crsColor, crsBG_COLOR
PUSHALL
;set cursor
mov ax,0200h
xor bx,bx
mov dh,rowPos
mov dl,colPos
int 10h
;Put undersoce and restore cursor position
mov ah,0Eh
mov al,CURSOR_TYPE ;underscore cursor
xor bh,bh
mov bl,crsColor ;Text Color
xor bl,crsBG_COLOR ;Button BG
or bl,0F0h
int 10h
;restore cursor
mov ax,0200h
xor bx,bx
mov dh,rowPos
mov dl,colPos
int 10h
POPALL
ENDM
PRINT_BHEX_NUM MACRO PackedHex, strColor, strBG_COLOR
;Print byte hex num
xor ah,ah
mov al,PackedHex
xor bx,bx
mov bl,10d
div bl
add al,30h
push ax
mov ah,0Eh
xor bh,bh
mov bl,strColor ;Text Color
xor bl,strBG_COLOR ;Button BG
or bl,0F0h
int 10h
pop ax
mov al,ah
add al,30h
mov ah,0Eh
xor bh,bh
mov bl,strColor ;Text Color
xor bl,strBG_COLOR ;Button BG
or bl,0F0h
int 10h
ENDM
DEL_CHAR MACRO Row, Col, stringName, charColor, BG_COLOR
PUSHALL
MOVRB FEcursorRow,Row
MOVRB FEcursorCol,Col
call CalcCursorPos
lea bx,stringName
add bx,FEcursorPos
xor ax,ax
mov al,[bx]
push ax
;Reset position
mov ax,0200h
xor bx,bx
mov dh,Row
mov dl,Col
int 10h
;Put char into position
pop ax
mov ah,0Eh
xor bh,bh
mov bl,charColor ;Text Color
xor bl,BG_COLOR ;Button BG
or bl,0F0h
int 10h
lea bx,stringName
add bx,FEcursorPos
mov BYTE PTR [bx],20h
POPALL
ENDM
WRITE_CHAR MACRO char, rowPos, colPos ,strColor, strBG_COLOR, crsColor, crsBG_COLOR
push bx
push dx
;Delete cursor at pos
push ax
;Reset position
mov ax,0200h
xor bx,bx
mov dh,rowPos
mov dl,colPos
int 10h
mov ah,0Eh
mov al,CURSOR_TYPE ;put underscore
xor bh,bh
mov bl,crsColor ;Text Color
xor bl,strBG_COLOR ;Button BG
or bl,0F0h
int 10h
;Reset position
mov ax,0200h
xor bx,bx
mov dh,rowPos
mov dl,colPos
int 10h
;Put char into position
pop ax
mov al,char ;put char
mov ah,0Eh
xor bh,bh
mov bl,strColor ;Text Color
xor bl,strBG_COLOR ;Button BG
or bl,0F0h
int 10h
pop dx
pop bx
ENDM
WRITE_STRING MACRO strName, strColor, strBG_COLOR
local string_loop
lea bx,strName
mov al,[bx]
string_loop:
push bx
mov ah,0Eh
xor bh,bh
mov bl,strColor ;Text Color
xor bl,strBG_COLOR ;Button BG
or bl,0F0h
int 10h
pop bx
inc bx
mov al,[bx]
cmp al,'$'
jnz string_loop
ENDM
WRITE_STRING_BYTE MACRO strName, strColor, strBG_COLOR ,byteNum
local string_loop
lea bx,strName
mov al,[bx]
mov cx,byteNum
string_loop:
push bx
mov ah,0Eh
xor bh,bh
mov bl,strColor ;Text Color
xor bl,strBG_COLOR ;Button BG
or bl,0F0h
int 10h
pop bx
inc bx
mov al,[bx]
inc FEcursorCol
call WrapColRowCount
call CalcCursorPos
SET_CURSOR FEcursorRow, FEcursorCol
loop string_loop
ENDM
;========= MACRO DEFINITIONS =========
.MODEL large,stdcall
.STACK 100h ;256 BYTE STACK
.DATA
;======== STRINGS ========
strLoad db "Load File",'$'
strNew db "New File",'$'
strSave db "Save File",'$'
strResume db "Resume",'$'
strExit db "Exit",'$'
strToolbar db "F1 ","#Menu ","*F2 ","#Load ","*F3 ","#New ","*F4 ","#Save ","*F5 ","#Find ","*F6 ","#Find-Replace "
db 0Ah, 0Dh, " ","*F7 ","#Capitalize Sentence ","*F8 ","#Capitalize Words ","*ESC ","#Exit ",'$'
; '#' write in PL_BLACK color
; '*' write in PL_RED color
strName db "File Name : ",'$'
strRow db "Row = ",'$'
strCol db "Column = ",'$'
strTxt db ".txt",'$'
strSearch db "Search for : ",'$'
strReplace db "Replace with: ",'$'
strHeader db "gg Word Processor",'$'
strFooterVersion db "Ver 1.0",'$'
strNotFoundError db "Not Found !!$"
;======== STRINGS ========
MenuOption dw LoadFile, NewFile, SaveFile, Resume, Exit
StatCallFromMenu db 0d ;Called from menu 1 , not 0
;Set palette variables
PLnewcolor db 00h
PLlastcolor db 00h
PLaddrReg db 00h
PLdataReg db 00h
;DrawRect function variables
RectXpos dw 0000h ;0-80
RectYpos dw 0000h ;0-480
RectXdim dw 0000h ;0-80
RectYdim dw 0000h ;0-480
RectColor db 00h
;DrawSelectionBox function variables
BoxXpos dw 0000h ;0-80
BoxYpos dw 0000h ;0-480
BoxXdim dw 0000h ;0-80
BoxYdim dw 0000h ;0-480
BoxSelColor db 00h ;Selection box color
;DrawSelection function variables
UIactiveSel dw 103d ;Position of active selection px
UIopt dw 0000h ;Number of active selection 0-1-2-3-4
;Draw toolbar varibles
DTstrColor db 00h
DTstatActive db 00h ;Status for toolbar, 0:Deactive , 1:Active
;Namebar variables
NBstatActive db 00h ;Status for namebar, 0:Deactive , 1:Active
NBfileName db MAX_LEN_FILENAME DUP (20h),'$'
;Write Methods
FEcursorPos dw 00h
FEcursorRow db 00h
FEcursorCol db 00h
WIFcursorStatActive db 00h ;Status for cursor str 0:Deactive , 1:Active
;File Methods
FileBuffer db 2500d DUP (20h),'$'
TempBuffer db 3500d DUP (20h),'$'
FileErrorCode dw 0000h
FileHandle dw 0000h
FileBytesRead dw 0000h
FileBytesWrite dw 0000h
FilePointer dw 0000h
LoadedFilePath db "./" ,MAX_LEN_FILENAME DUP (20h),".txt",0
NewFilePath db "./" ,MAX_LEN_FILENAME DUP (20h),".txt",0
;New feature variables
FNRsearchStr db MAX_LEN_SEARCH_STR DUP (20h),'$'
FNRreplaceStr db MAX_LEN_SEARCH_STR DUP (20h),'$'
FNRfoundindex dw 80d ; Found : index of found pattern
FNRstrPointer dw 0000d
FileBuffer_index dw ? ;INDEX FOR "FileBuffer".
TempBuffer_index dw ? ;INDEX FOR "RESULT".
.CODE
.STARTUP
;DS -> Data segment
mov ax,@data
mov ds,ax
;ES -> Video memory
mov ax,0A000h
mov es,ax
init:
call InitScreen
main:
call CheckKey
call DrawSelection
jmp main
.EXIT
mov ax,0002h ;Set text mode
int 10h
mov ax,4c00h
int 21h
; ===================== PROCEDURES =====================
InitScreen PROC
;Initialize display
mov ax,0012h
int 10h
;Draw Menu
call DrawMenu
ret
InitScreen ENDP
CheckKey PROC
;Check keyboard and update ui
mov ax,0000h
int 16h
cmp ax,KEY_UP
jz ck_dec
cmp ax,KEY_DOWN
jz ck_inc
cmp ax,KEY_ENTER
jz ck_enter
cmp ax,KEY_ESC
jz ck_exit
ck_end:
ret
ck_inc:
mov ax,UIBUTTONNUMBER
add UIopt,1d
cmp UIopt,ax
jb ck_end
sub UIopt,ax
jmp ck_end
ck_dec:
mov ax,UIBUTTONNUMBER
sub UIopt,1d
cmp UIopt,0d
jns ck_end
add UIopt,ax
jmp ck_end
ck_enter:
mov StatCallFromMenu,1d
mov bx,UIopt
shl bx,1
jmp MenuOption[bx]
jmp ck_end
ck_exit:
mov ax,0002h ;Set text mode
int 10h
mov ax, 4c00h
int 21h
CheckKey ENDP
NotFoundError PROC
SET_CURSOR 0d, 35d
WRITE_STRING strNotFoundError, PL_RED, PL_LGRAY
mov ax,0000h
int 16h
cmp ax,KEY_ESC
jz Exit
PASS_RECT_PARAM 35d,0d,12d,20d,PL_LGRAY
call DrawRect
ret
NotFoundError ENDP
WrapColRowCount PROC
;Checks boundaries of row and column positions
PUSHALL
cmp FEcursorCol,01d
jb wcrc_col_below
cmp FEcursorCol,78d
ja wcrc_col_above
wcrc_col_end:
cmp FEcursorRow,2d
jb wcrc_row_below
cmp FEcursorRow,26d
ja wcrc_row_above
jmp wcrc_row_end
wcrc_row_below:
mov FEcursorRow,26d
jmp wcrc_row_end
wcrc_row_above:
mov FEcursorRow,2d
jmp wcrc_row_end
wcrc_col_below:
mov FEcursorCol,78d
dec FEcursorRow
jmp wcrc_col_end
wcrc_col_above:
mov FEcursorCol,01d
inc FEcursorRow
jmp wcrc_col_end
wcrc_row_end:
POPALL
ret
WrapColRowCount ENDP
CalcCursorPos PROC
;Calculates linear cursor position using row and column data
;pos = 78*(row-2)+column-1
PUSHALL
xor ax,ax
mov al,FEcursorRow
sub ax,2d
mov bl,78d
mul bl
xor bx,bx
mov bl,FEcursorCol
add ax,bx
dec ax
mov FEcursorPos,ax
POPALL
ret
CalcCursorPos ENDP
CalcCursorRowCol PROC
;Calculates row and column data using cursor position data
PUSHALL
xor ax,ax
xor dx,dx
mov ax,FEcursorPos
mov bl,78d
div bl
add al,2
add ah,1
mov FEcursorCol,ah
mov FEcursorRow,al
POPALL
ret
CalcCursorRowCol ENDP
FileEditor PROC
mov FEcursorRow,2d
mov FEcursorCol,2d
SET_CURSOR FEcursorRow, FEcursorCol
call CalcCursorPos
fe_loop:
call DrawCursorStr
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
mov ax,0000h
int 16h
;;Check valid input
cmp ax,KEY_F1
jz fe_Menu
cmp ax,KEY_F2
jz fe_LoadFile
cmp ax,KEY_F3
jz fe_NewFile
cmp ax,KEY_F4
jz fe_SaveFile
cmp ax,KEY_F5
jz fe_Find
cmp ax,KEY_F6
jz fe_Find_Replace
cmp ax,KEY_F7
jz fe_Cap_Sents
cmp ax,KEY_F8
jz fe_Cap_Words
cmp ax,KEY_ENTER
jz fe_Enter
cmp ax,KEY_UP
jz fe_Up
cmp ax,KEY_DOWN
jz fe_Down
cmp ax,KEY_LEFT
jz fe_Left
cmp ax,KEY_RIGHT
jz fe_Right
cmp ax,KEY_BACKSPACE
jz fe_BackSpace
cmp ax,KEY_DEL
jz fe_Delete
cmp ax,KEY_ESC
jz fe_Exit
;else print to screen
DEL_CHAR FEcursorRow, FEcursorCol, FileBuffer, PL_WHITE, BG_COLOR
WRITE_CHAR al, FEcursorRow, FEcursorCol, PL_WHITE, BG_COLOR, CURSOR_COLOR, CURSOR_BG_COLOR
lea bx,FileBuffer
add bx,FEcursorPos
mov BYTE PTR [bx],al
inc FEcursorCol
call WrapColRowCount
call CalcCursorPos
jmp fe_loop
ret
fe_Enter:
WRITE_CHAR 0Dh, FEcursorRow, FEcursorCol, PL_WHITE, BG_COLOR, CURSOR_COLOR, CURSOR_BG_COLOR
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
WRITE_CHAR 0Ah, FEcursorRow, FEcursorCol, PL_WHITE, BG_COLOR, CURSOR_COLOR, CURSOR_BG_COLOR
mov FEcursorCol,01d ; chars in 1 line
inc FEcursorRow
call WrapColRowCount
call CalcCursorPos
jmp fe_loop
fe_Menu:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
call Menu
ret
fe_LoadFile:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
mov StatCallFromMenu,0d
call LoadFile
ret
fe_NewFile:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
mov StatCallFromMenu,0d
call NewFile
ret
fe_SaveFile:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
mov StatCallFromMenu,0d
call SaveFile
ret
fe_Find:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
mov FNRstrPointer,Offset FNRsearchStr
call ResetSearchStr
call DrawSearchbar
mov FNRstrPointer,Offset FNRsearchStr
call TakeSearchStr
call SearchInBuffer
cmp FNRfoundindex,-1d
jz fe_searchnotfound
;search and mark
MOVRW FEcursorPos,FNRfoundindex
call CalcCursorRowCol
call WrapColRowCount
jmp fe_loop
ret
fe_searchnotfound:
call NotFoundError
mov FEcursorPos,00d
call CalcCursorRowCol
call WrapColRowCount
jmp fe_loop
ret
fe_Find_Replace:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
;reset search/replace str
mov FNRstrPointer,Offset FNRsearchStr
call ResetSearchStr
mov FNRstrPointer,Offset FNRreplaceStr
call ResetSearchStr
;take search str
call DrawSearchbar
mov FNRstrPointer,Offset FNRsearchStr
call TakeSearchStr
;take replace str
PASS_RECT_PARAM 50d,0d,30d,20d,PL_LGRAY
call DrawRect
SET_CURSOR 0d, 50d
WRITE_STRING strReplace, PL_BLACK, PL_LGRAY ;replace word
SET_CURSOR 0d, 63d
mov FNRstrPointer,Offset FNRreplaceStr
call TakeSearchStr
call FindReplaceInBuffer
call Resume
jmp fe_loop
ret
fe_Cap_Sents:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
call CapSentsInBuffer
call Resume
jmp fe_loop
ret
fe_Cap_Words:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
call CapWordsInBuffer
call Resume
jmp fe_loop
ret
fe_Up:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
dec FEcursorRow
call WrapColRowCount
call CalcCursorPos
jmp fe_loop
ret
fe_Down:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
inc FEcursorRow
call WrapColRowCount
call CalcCursorPos
jmp fe_loop
ret
fe_Left:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
dec FEcursorCol
call WrapColRowCount
call CalcCursorPos
jmp fe_loop
ret
fe_Right:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
inc FEcursorCol
call WrapColRowCount
call CalcCursorPos
jmp fe_loop
ret
fe_BackSpace:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
dec FEcursorCol
call WrapColRowCount
call CalcCursorPos
;delete char at pos
DEL_CHAR FEcursorRow, FEcursorCol, FileBuffer, PL_WHITE ,BG_COLOR
call WrapColRowCount
call CalcCursorPos
jmp fe_loop
ret
fe_Delete:
PUT_CURSOR FEcursorRow, FEcursorCol, CURSOR_COLOR, CURSOR_BG_COLOR
inc FEcursorCol
call WrapColRowCount
call CalcCursorPos
;delete char at pos
DEL_CHAR FEcursorRow, FEcursorCol, FileBuffer, PL_WHITE ,BG_COLOR
call WrapColRowCount
call CalcCursorPos
jmp fe_loop
ret
fe_Exit:
call Exit
jmp fe_loop
ret
FileEditor ENDP
TakeFileName PROC
call ResetFileName
mov FEcursorRow,0d
mov FEcursorCol,13d
SET_CURSOR 0d, 13d
lea bx,NBfileName
mov cx,bx
add cx,MAX_LEN_FILENAME ;End condition
inc cx
tfn_loop:
PUT_CURSOR FEcursorRow, FEcursorCol, PL_RED, PL_LGRAY
mov ax,0000h
int 16h
cmp bx,cx
jz tfn_end
cmp ax,KEY_ENTER ;Enter key
jz tfn_end
cmp ax,KEY_BACKSPACE
jz tfn_BackSpace
cmp ax,KEY_ESC
jz tfn_Exit
WRITE_CHAR al, FEcursorRow, FEcursorCol, PL_RED, PL_LGRAY, PL_RED, PL_LGRAY
inc FEcursorCol ;check and inc FEcursorRow also
mov [bx],al
inc bx
jmp tfn_loop
tfn_end:
WRITE_CHAR ' ', FEcursorRow, FEcursorCol, PL_RED, PL_LGRAY, PL_RED, PL_LGRAY ;delete underscore
SET_CURSOR FEcursorRow,FEcursorCol
WRITE_STRING strTxt, PL_RED, PL_LGRAY ;put .txt
mov NBstatActive,1d
ret
tfn_BackSpace:
lea dx,NBfileName
cmp bx,dx
jz tfn_donothing
;delete cursor at pos
PUT_CURSOR FEcursorRow, FEcursorCol, PL_RED, PL_LGRAY
dec FEcursorCol
SET_CURSOR FEcursorRow,FEcursorCol
;delete char at pos
dec bx
mov ah,[bx]
WRITE_CHAR ah, FEcursorRow, FEcursorCol, PL_RED, PL_LGRAY, PL_RED, PL_LGRAY
mov BYTE PTR [bx],' '
tfn_donothing:
PUT_CURSOR FEcursorRow, FEcursorCol, PL_RED, PL_LGRAY
jmp tfn_loop
ret
tfn_Exit:
call Exit
jmp tfn_loop
ret
TakeFileName ENDP
TakeSearchStr PROC
mov FEcursorRow,0d
mov FEcursorCol,63d
SET_CURSOR 0d, 63d
mov bx,FNRstrPointer
;lea bx,FNRsearchStr
mov cx,bx
add cx,MAX_LEN_SEARCH_STR ;End condition
tss_loop:
PUT_CURSOR FEcursorRow, FEcursorCol, PL_BLUE, PL_LGRAY
mov ax,0000h
int 16h
cmp ax,KEY_ENTER ;Enter key
jz tss_end
cmp ax,KEY_BACKSPACE
jz tss_BackSpace
cmp ax,KEY_ESC
jz tss_Exit
WRITE_CHAR al, FEcursorRow, FEcursorCol, PL_BLUE, PL_LGRAY, PL_BLUE, PL_LGRAY
inc FEcursorCol ;check and inc FEcursorRow also
mov BYTE PTR [bx],al
inc bx
cmp bx,cx
jnz tss_loop
tss_end:
WRITE_CHAR ' ', FEcursorRow, FEcursorCol, PL_BLUE, PL_LGRAY, PL_BLUE, PL_LGRAY ;delete underscore
ret
tss_BackSpace:
;lea dx,FNRsearchStr
mov dx,FNRstrPointer
cmp bx,dx
jz tss_donothing
;delete cursor at pos
PUT_CURSOR FEcursorRow, FEcursorCol, PL_BLUE, PL_LGRAY
dec FEcursorCol
SET_CURSOR FEcursorRow,FEcursorCol
;delete char at pos
dec bx
mov ah,[bx]
WRITE_CHAR ah, FEcursorRow, FEcursorCol, PL_BLUE, PL_LGRAY, PL_BLUE, PL_LGRAY
mov BYTE PTR [bx],' '
tss_donothing:
PUT_CURSOR FEcursorRow, FEcursorCol, PL_BLUE, PL_LGRAY
jmp tss_loop
ret
tss_Exit:
call Exit
jmp tss_loop
ret
TakeSearchStr ENDP
ResetBuffer PROC
push bx
push cx
mov cx,2500d
lea bx,FileBuffer
add cx,bx
rfir_loop:
mov BYTE PTR [bx],20h
inc bx
cmp bx,cx
jnz rfir_loop
pop cx
pop bx
ret
ResetBuffer ENDP
ResetFileName PROC
push bx
push cx
mov cx,MAX_LEN_FILENAME
lea bx,NBfileName
add cx,bx
rfn_loop:
mov BYTE PTR [bx],20h
inc bx
cmp bx,cx
jnz rfn_loop
pop cx
pop bx
ret
ResetFileName ENDP
ResetSearchStr PROC
push bx
push cx
mov cx,MAX_LEN_SEARCH_STR
mov bx,FNRstrPointer
add cx,bx
rss_loop:
mov BYTE PTR [bx],20h
inc bx
cmp bx,cx
jnz rss_loop
pop cx
pop bx
ret
ResetSearchStr ENDP
SearchInBuffer PROC
PUSHALL
xor cx,cx ;Search index for file
xor dx,dx ;index for FNRsearchStr
sib_loop:
lea bx,FNRsearchStr
add bx,dx
mov ah,[bx]
cmp ah,20h
jz sib_found
cmp ah,'$'
jz sib_found
lea bx,FileBuffer
add bx,cx
cmp BYTE PTR [bx],ah
jz sib_match
jmp sib_unmatch
sib_match:
cmp dx,0h
jnz sib_notfirstmatch
mov FNRfoundindex,cx
sib_notfirstmatch:
inc cx
cmp cx,2500d;search depth
ja sib_notfound
inc dx
jmp sib_loop
sib_unmatch:
inc cx
cmp cx,2500d;search depth
ja sib_notfound
xor dx,dx
jmp sib_loop
sib_notfound:
mov FNRfoundindex,-1d
sib_found:
POPALL
RET
SearchInBuffer ENDP
FindReplaceInBuffer PROC
PUSHALL
mov FileBuffer_index, offset FileBuffer
mov TempBuffer_index, offset TempBuffer
mov si, FileBuffer_index
lea di, FNRsearchStr
frib_search:
mov al, [di]
cmp al, 20h
je frib_match
mov bl,[si]
cmp bl,24h
je frib_finale
cmp [si], al
jne frib_mismatch
inc si
inc di
jmp frib_search
frib_match:
mov FileBuffer_index, si
dec FileBuffer_index
lea di, FNRreplaceStr
frib_replace:
mov al,[di]
cmp al,20h
je frib_next
mov si, TempBuffer_index
mov [si], al
inc TempBuffer_index
inc di
jmp frib_replace
frib_mismatch:
mov si, FileBuffer_index
mov di, TempBuffer_index
mov al, [si]
mov [di], al
inc TempBuffer_index
frib_next:
lea di, FNRsearchStr
inc FileBuffer_index
mov si,FileBuffer_index