-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextEditor.asm
129 lines (115 loc) · 3.23 KB
/
TextEditor.asm
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
[org 0x100]
start:
;CAPTURE KEY.
mov ah, 0
int 16h
;EVALUATE KEY.
cmp al, 27 ; ESC
je Exit
cmp ax, 0x4800 ; UP.
je moveUp
cmp ax, 0x4B00 ; LEFT.
je moveLeft
cmp ax, 0x4D00 ; RIGHT.
je moveRight
cmp ax, 0x5000 ; DOWN.
je moveDown
cmp al,0xD;Enter key
Je Enter
cmp ax, 0E08h ; BackSpace.
je back_Space
cmp al, 32;space
jae any_char
jmp start
;DISPLAY LETTER, DIGIT OR ANY OTHER ACCEPTABLE CHAR.
any_char:
mov ah, 9
mov bh, 0
mov bl,0xF0 ;white backdgound with black foreground color
mov cx, 1 ; how many times display char.
int 10h ; display char in al.
;UPDATE CHAR IN MATRIX.
mov si, curr_line ; si points to the beginning of the line.
add si, curr_char ; si points to the char in the line.
mov [ si ], al ; the char is in the matrix.
;!!! EXTREMELY IMPORTANT : PREVIOUS BLOCK DISPLAYS ONE
;CHAR, AND NEXT BLOCK MOVES CURSOR TO THE RIGHT. THAT'S
;THE NORMAL BEHAVIOR FOR ALL EDITORS. DO NOT MOVE THESE
;TWO BLOCKS, THEY MUST BE THIS WAY. IF IT'S NECESSARY
;TO MOVE THEM, ADD A JUMP FROM ONE BLOCK TO THE OTHER.
;RIGHT.
moveRight:
inc word[curr_char] ; update current char.
mov dl, [Row]
mov dh, [Column]
inc dl ; Row ++
mov [Row], dl
jmp prntCrs
;LEFT.
moveLeft:
dec word[curr_char] ; update current char.
mov dl, [Row]
mov dh, [Column]
dec dl ; Row --
mov [Row], dl
jmp prntCrs
;UP.
moveUp:
sub word[curr_line], 80 ; update current line.
mov dl, [Row]
mov dh, [Column]
dec dh ; column --
mov [Column], dh
jmp prntCrs ; print cursor
;DOWN.
moveDown:
add word[curr_line], 80 ; update current line.
mov dl, [Row]
mov dh, [Column]
inc dh ; column ++
mov [Column], dh
jmp prntCrs
Enter:
mov si, [curr_line]
add si, 79
mov word[si], 0dh
add word[curr_line],80
mov word[curr_char], 0
mov byte[Row], 0
mov dl, [Row]
mov dh, [Column]
inc dh
mov [Column], dh
add word[length], 80
jmp prntCrs
back_Space:
dec word[curr_char]
mov si, [curr_line] ; si points to the beginning of the line.
add si, [curr_char] ; si points to the char in the line.
mov word[ si ], ' ' ; the char is in the matrix.
dec word[length] ; count the number of chars
dec byte[Row]
mov dl, [Row]
;Move the cursor
mov ah, 2h
int 10h
;Update the Screen
mov al,' '
mov ah, 9
mov bh, 0
mov bl, 0000
mov cx, 1 ; how many times display char.
int 10h ; display char in al.
jmp prntCrs
prntCrs: ; print cursor
mov ah, 2h
int 10h
jmp start
Exit:
int 20h ;exit when esc key is pressed
Row db 1 ; dh = Row-> controls row
Column db 1 ; dl = Column -> controls column
matrix dw 160*25 ; 25 lines of 80 chars each.
curr_line dw '?'
curr_char dw '?'
length:dw 0