-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchat.asm
315 lines (253 loc) · 4.95 KB
/
chat.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
PUBLIC Chat
.MODEL SMALL
.386
.STACK 100h
.DATA
closeProgram DB 0
myCursorX DB 0
myCursorY DB 0
otherCursorX DB 0
otherCursorY DB 13
.CODE
CLEAR_SCREEN PROC
MOV AH, 00H
MOV AL, 03H
INT 10H
RET
CLEAR_SCREEN ENDP
DRAW_SEPARATOR PROC
; Set the cursor position to row 12
MOV AH, 02H
MOV BH, 0
MOV DH, 12
MOV DL, 0
INT 10H
; Draw the horizontal line using the character '-'
MOV AH, 09H
MOV AL, '-'
MOV BL, 7
MOV CX, 80
INT 10H
RET
DRAW_SEPARATOR ENDP
MOVE_MY_CURSOR PROC
PUSH AX
PUSH BX
PUSH DX
MOV AH, 02H
MOV BH, 0
MOV DH, myCursorY
MOV DL, myCursorX
INT 10H
POP DX
POP BX
POP AX
RET
MOVE_MY_CURSOR ENDP
MOVE_OTHER_CURSOR PROC
PUSH AX
PUSH BX
PUSH DX
MOV AH, 02H
MOV BH, 0
MOV DH, otherCursorY
MOV DL, otherCursorX
INT 10H
POP DX
POP BX
POP AX
RET
MOVE_OTHER_CURSOR ENDP
SCROLL_WINDOW PROC
PUSH AX
PUSH BX
MOV AH, 06H
MOV AL, 01H
MOV BH, 07H
INT 10H
POP BX
POP AX
RET
SCROLL_WINDOW ENDP
RECEIVE_KEY PROC
; Check if data Ready from UART
MOV DX, 03FDH
IN AL, DX
AND AL, 1
JZ END_RECEIVE_KEY
; Read the value
MOV DX, 03F8H
IN AL, DX
; Check if esc is pressed
CMP AL, 27
JZ R_CLOSE_PROGRAM
; Move the cursor to the other side
CALL MOVE_OTHER_CURSOR
; Check if char is a new line
CMP AL, 0Dh
JNZ R_DISPLAY_VALUE
MOV otherCursorX, 0
INC otherCursorY
JMP R_CHECK_CURSOR_POS
R_DISPLAY_VALUE:
; check for backspace
CMP AL, 8
JNE R_SKIP_BACKSPACE
CMP otherCursorX, 0
JE R_CHECK_CURSOR_POS
R_HANDLE_BACKSPACE:
mov ah,0eh
int 10h
mov al,' '
int 10h
mov al,8
int 10h
DEC otherCursorX
JMP R_CHECK_CURSOR_POS
R_SKIP_BACKSPACE:
; Display the value
MOV DL, AL
MOV BH, 0
MOV CX, 1
MOV AH, 09h
MOV BL, 0Dh
INT 10h
R_INCREMENT_CURSOR:
; Increment the cursor position and check if it is the end of row
INC otherCursorX
CMP otherCursorX, 80
JNE R_CHECK_CURSOR_POS
MOV otherCursorX, 0
INC otherCursorY
R_CHECK_CURSOR_POS:
; Check if the cursor is at the end of the screen and set a flag
CMP otherCursorX, 0
JNE END_RECEIVE_KEY
CMP otherCursorY, 25
JNE END_RECEIVE_KEY
; Scroll the window
R_SCROLL_WINDOW:
MOV CH, 13
MOV CL, 0
MOV DH, 24
MOV DL, 79
MOV BL,03h
CALL SCROLL_WINDOW
MOV otherCursorX, 0
MOV otherCursorY, 24
JMP END_RECEIVE_KEY
R_CLOSE_PROGRAM:
MOV closeProgram, 1
END_RECEIVE_KEY:
RET
RECEIVE_KEY ENDP
TRANS_KEY PROC
; Check if key is pressed
MOV AH, 0Bh
INT 21h
CMP AL, 0h
JZ EXIT_TRANS_KEY
; Check that Transmitter Holding Register is Empty
WAIT_FOR_EMPTY:
MOV DX, 3FDH
IN AL, DX
AND AL, 00100000b
JZ WAIT_FOR_EMPTY
; Read the value
MOV AH, 00H
INT 16h
; Transmit the value
MOV DX, 3F8H
OUT DX , AL
; Check if esc is pressed
CMP AL, 27
JZ T_CLOSE_PROGRAM
; Move the cursor to the other side
CALL MOVE_MY_CURSOR
; Display the value
; Check if char is a new line
CMP AL, 0Dh
JNZ T_DISPLAY_VALUE
MOV myCursorX, 0
INC myCursorY
JMP T_CHECK_CURSOR_POS
T_DISPLAY_VALUE:
; check for backspace
CMP AL, 8
JNE T_SKIP_BACKSPACE
CMP myCursorX, 0
JE T_CHECK_CURSOR_POS
T_HANDLE_BACKSPACE:
mov ah,0eh
int 10h
mov al,' '
int 10h
mov al,8
int 10h
DEC myCursorX
JMP T_CHECK_CURSOR_POS
T_SKIP_BACKSPACE:
; Display the value
MOV DL, AL
MOV BH, 0
MOV CX, 1
MOV AH, 09h
MOV BL, 0Bh
INT 10h
T_INCREMENT_CURSOR:
; Increment the cursor position and check if it is the end of row
INC myCursorX
CMP myCursorX, 80
JNE T_CHECK_CURSOR_POS
MOV myCursorX, 0
INC myCursorY
T_CHECK_CURSOR_POS:
; Check if the cursor is at the end of the screen
CMP myCursorX, 0
JNE EXIT_TRANS_KEY
CMP myCursorY, 12
JNE EXIT_TRANS_KEY
; Scroll the window
T_SCROLL_WINDOW:
MOV CH, 0
MOV CL, 0
MOV DH, 11
MOV DL, 79
CALL SCROLL_WINDOW
MOV myCursorX, 0
DEC myCursorY
; Set the cursor position
CALL MOVE_MY_CURSOR
JMP EXIT_TRANS_KEY
T_CLOSE_PROGRAM:
MOV closeProgram, 1
EXIT_TRANS_KEY:
RET
TRANS_KEY ENDP
Chat PROC FAR
MOV closeProgram, 0
MOV myCursorX, 0
MOV myCursorY, 0
MOV otherCursorX, 0
MOV otherCursorY, 13
; Clear the screen
CALL CLEAR_SCREEN
; Divide the screen into two parts
CALL DRAW_SEPARATOR
MAIN_LOOP:
CALL MOVE_MY_CURSOR
; Check if there is a character in the UART
CALL RECEIVE_KEY
; Check if esc is pressed
CMP closeProgram, 1
JZ EXIT_PROGRAM
; Check if key is pressed and send it to the UART
CALL TRANS_KEY
; Check if esc is pressed
CMP closeProgram, 1
JZ EXIT_PROGRAM
JMP MAIN_LOOP
EXIT_PROGRAM:
ret
Chat ENDP
END