-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final.asm
243 lines (202 loc) · 5.54 KB
/
Final.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
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
.MODEL SMALL
.DATA
msg db "EDITOR PROJECT"
msg1 db " File Help "
msg1end db 0
msg2 db "File ",0ah,0dh
db "Open CTRL+O",0ah,0dh
db "Save CTRL+S",0ah,0dh
db "Delete CTRL+D",0ah,0dh
db "Exit(ESC) CTRL+E",0ah,0dh
msg2end db 0
mystack db ?
col db ?
column db 0
row db 1
select_buffer db 1000 dup(0) ; a variable to store the data selected
select_buffer_end db 0
select_buffer_length equ 1000 ; the buffer length
scan_code db 0
temp_char db 0
mouse_temp_char db 0
filename db "Results.txt",0
handle dw ?
file_error db "Erorr: couldn't open the file."
file_error_end db "0$"
file_buffer db 1000 dup(0)
file_buffer_length equ 1000
.STACK
dw 128 dup(0)
.code
segment code
assume cs:code
include proc.inc
main proc far
mov ax, @data
mov ds, ax
mov es,ax
push si
push dx
push cx
push bx
push ax
mov si, offset file_buffer ; Initialize SI to point to the buffer
mov cx, file_buffer_length ; Set the maximum number of characters to read
;setting the screen to 80x25 text mode
mov ah,0h
mov al, 03h
int 10h
; set cursor shape
mov ah,2
mov ch, 0
mov cl, 7
int 10h
; set cursor position
mov dh, 0 ;row
mov dl,3 ; column
mov bh, 0 ; page
mov ah, 2
int 10h
;code start
;print the first line
mov al,1
mov bh, 0
mov bl, 01001111b
mov cx, offset msg1end - offset msg1
mov dl,0
mov dh, 0
push ds
pop es
mov bp, offset msg1
mov ah,13h
int 10h
;Mouse initialization
;int 33h
;It gets mouse status and position of it's buttons
;left button -> bx = 1
;right button -> bx = 2
;both buttons -> bx = 3
mouse_check proc
mov ax,3
int 33h
cmp bx,1
je mymouse_bridge2
ret
endp mouse_check
wait_for_key:
mov ax,0
int 33h
input_loop:
; initializing the mouse and checking if the left button is pressed
call mouse_check
; getting input from the keyboard
mov ah,10h
int 16h
cmp al, 13h
je check_for_save
check_for_arrow:
call arrowcheck ;check for arrow
cmp ax, 1
je input_loop
cmp al, 8 ;see if it is backspace
je backspace
jne newline
check_for_save:
call save_file_Proc;check for arrow
jmp input_loop
mymouse_bridge2:
jmp mymouse
wait_for_key_bridge:
jmp wait_for_key
input_loop_bridge:
jmp input_loop
backspace:
; set cursor position back
mov ah,02h
mov dh,row ; set the row
dec column ; decrement the column to backa column (move right)
mov dl,column ; set the column
mov bh,0
int 10h
;print space
mov al, ' '
mov ah,0ah
mov cx,1
mov bh,0
int 10h
cmp column, 0
jne input_loop
back_line:
; move the cursor position to the end of the row above
dec row ; decrement the row to move up
mov column, 80 ; the screen is 80x25 so the last screen colum is 80
mov ah,02h
mov dh,row
mov dl,column
mov bh,0
int 10h
jmp input_loop
; check if at start of row
newline:
; check if the enter the key press
cmp al,13
jne print
; set cursor position down a row
mov ah,02h
inc row
mov dh,row
mov column, 0
mov dl,column
mov bh,0
int 10h
jmp input_loop
mymouse_bridge:
jmp mymouse
input_loop_bridge2:
jmp input_loop_bridge
; print character
print:
mov [si], al
inc si
mov ah,0ah
mov cx,1
mov bh,0
int 10h
; set cursor position one column to the right every time
mov ah,02h
mov dh,row
inc column
mov dl,column
mov bh,0
int 10h
cmp column,80
jne checkESC
reset_column:
mov column,0
inc row
checkESC:
cmp al, 27 ;check if ESC is pressed
je exit
jmp input_loop_bridge2
mymouse:
mov al,1
mov bh, 0
mov bl, 01001111b
mov cx, offset msg2end - offset msg2
mov dl,0
mov dh, 0
push ds
pop es
mov bp, offset msg2
mov ah,13h
int 10h
jmp input_loop_bridge
;code end
exit:
call save_file_proc
mov ah, 1
int 21h; wait for a key input
mov ah,4ch
int 21h
main endp
end main