-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtt.asm
370 lines (311 loc) · 8.75 KB
/
tt.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
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
.MODEL SMALL
.DATA
msg db "Elnaggar"
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
;file3 db "t1.txt", o
;handle dw ?
mystack db ?
col db ?
column db 0
row db 6
select_buffer db 100 dup(0) ; a variable to store the data selected
select_buffer_end db 0
select_buffer_length equ 100 ; the buffer length
scan_code db 0
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 100 dup(0)
file_buffer_length equ 100
.STACK
dw 128 dup(0)
.code
uprow proc far
dec row
mov ah,02h
mov dh,row
mov dl,column
mov bh,0
int 10h
ret
uprow endp
downrow proc far
inc row
mov ah,02h
mov dh,row
mov dl,column
mov bh,0
int 10h
ret
downrow endp
rightcolumn proc far
inc column
mov ah,02h
mov dh,row
mov dl,column
mov bh,0
int 10h
ret
rightcolumn endp
leftcolumn proc far
dec column
mov ah,02h
mov dh,row
mov dl,column
mov bh,0
int 10h
ret
leftcolumn endp
arrowcheck proc far
; check if the button is arrow up
cmp ah, 48h
jne arrowDownCheck
arrowUP:
call uprow
mov ax, 1 ; ax = 1 if an arrow key was actually pressed
jmp exitarrowcheck
arrowDownCheck:
cmp ah,50h
jne arrowRightCheck
arrowDown:
call downrow
mov ax, 1 ; ax = 1 if an arrow key was actually pressed
jmp exitarrowcheck
arrowRightCheck:
cmp ah,4Dh
jne arrowLeftCheck
arrowRight:
call rightcolumn
mov ax, 1 ; ax = 1 if an arrow key was actually pressed
jmp exitarrowcheck
arrowLeftCheck:
cmp ah, 4Bh
jne exitarrowcheck
arrowLeft:
call leftcolumn
mov ax, 1 ; ax = 1 if an arrow key was actually pressed
jmp exitarrowcheck
exitarrowcheck:
ret
arrowcheck endp
select proc far
mov si, offset select_buffer ; initialize the si to point at the first byte of the byffer
mov cx, select_buffer_length ; set the maximum amount of characters to be selcted
select_loop:
mov ah, 10h
int 16h
call arrowcheck
cmp ax, 1 ; see if an arrow is pressed
;jne exit_select
read_char:
mov ah,10h
int 16h ; read a charcter at cursor position
cmp al, 13 ; check if enter is pressed
je exit_select
mov [si], al ; store the charcter in the buffer
inc si ; move the pointer to the next byte of the buffer
loop select_loop
exit_select:
ret
select endp
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
wait_for_key: ;Mouse initialization
mov ax,0
int 33h
;int 33h
;It gets mouse status and position of it's buttons
;left button -> bx = 1
;right button -> bx = 2
;both buttons -> bx = 3
mov ax,3
int 33h
cmp bx,1
je mymouse_bridge2
; check for keystroke in keyboard buffer
mov ah, 1
int 16h
jz wait_for_key
cmp al, 'i'
je input_loop ; IF input is I accept user input
jmp wait_for_key ; wait for another key
input_loop:
mov ah,10h
int 16h
;taking a character from std in
; Check if arrow key is pressed
;cmp al, 97 ; check for ctrl+n
;jne check_for_arrow
mov [si], al
inc si
;call select
;mov al, offset select_buffer
;mov ah,0ah
;mov cx,1
;mov bh,0
;int 10h
;jmp input_loop
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
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
;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 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_bridge
save:
;;;;;
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
;code end
exit:
mov ah, 3ch
mov cx, 0
mov dx, offset filename
mov ah, 3ch
int 21h
mov handle, ax
;write into file the input char
mov ah,40h
mov bx, handle
mov cx, file_buffer_length
mov dx, offset file_buffer
int 21h
;close file
mov ah,3eh
mov bx,handle
int 21h
mov ah, 1
int 21h; wait for a key input
mov ah,4ch
int 21h
main endp
end main