-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchat.asm
356 lines (288 loc) · 5.4 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
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
EXTRN Name1:byte
EXTRN Name2:byte
EXTRN SEND:FAR
EXTRN sendData:byte
public chat
.model HUGE
.data
str db 190 dup('$')
ind db 0
line db 80 dup('-'),'$'
spa db 160 dup(' '),'$'
you db 'you:','$'
bool db 1
char db 0d,'$'
x db 0
y db 0
myx db 0
myy db 19
mes db 0dh,'$'
.code
setCursor proc
mov dh , y ;
mov dl ,x ;
mov ah,2
mov bh,0
int 10h
ret
setCursor endp
setMyCursor proc
mov dh , myy ;
mov dl ,myx ;
mov ah,2
mov bh,0
int 10h
ret
setMyCursor endp
scroll proc
; scroll by 3 lines
mov ah,6 ; function 6
mov al,3 ; scroll by 1 line
mov bh,7 ; normal video attribute
mov ch,0 ; upper left Y
mov cl,0 ; upper left X
mov dh,16 ; lower right Y
mov dl,79 ; lower right X
int 10h
ret
scroll endp
delete PROC
cmp ind,0
je ign
dec myx
call setMyCursor
mov spa[1],'$'
mov ah,9
mov dx ,offset spa
int 21h
mov spa[1],' '
call setMyCursor
mov bl ,ind
mov bh , 0
mov str[bx],'$'
dec ind
ign:
ret
delete ENDP
send_str PROC
mov SI , offset str
send_strl:
LODSB ;
mov bl,al
mov dx ,3FDH
check_thr:
in al ,dx
AND al ,00100000b
jz check_thr
mov dx ,3F8H
mov al,bl
out dx ,al
cmp bl,'$'
je end_send_str
jmp send_strl
end_send_str:
ret
send_str ENDP
printmsg proc
mov x , 0
cmp y,14
jl here
call scroll
;update the cursor
mov y , 14
mov x ,0
here:
call setCursor
mov ah,9
mov dx ,offset Name1
int 21h
inc y
mov x,0
call setCursor
mov ah,9
mov dx ,offset str
int 21h
call send_str
;delete the mesage part
mov myx ,0
mov myy ,19
call setMyCursor
mov ah,9
mov dx ,offset spa
int 21h
mov myx ,0
mov myy ,19
; str =($)
mov bx, 0
mov cx , 180
lo:
mov str[bx],'$'
inc bx
dec cx
loop lo
mov ind , 0
inc y
inc y
ret
printmsg endp
printpl2name proc
;start position of recieved mesage is (x=13)
mov x ,40d
cmp y,16d
jl here3
call scroll
mov y ,14d
mov x,40d
here3:
;set the cursor postion
call setCursor
;print P2name
mov ah,9
mov dx ,offset Name2
int 21h
;set the cursor to the new line
inc y
mov x,40
call setCursor
mov bool , 0
ret
printpl2name endp
chat proc far
; mov ax,@data
; mov ds,ax
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; clear the screen
mov ax ,0003h ; clear the scren
int 10h ; clear the scren
; change to txt mode
mov al,3
mov ah ,0
int 10
;print initale lines
mov x,0
mov y,21
call setCursor
mov ah,9
mov dx , offset line
int 21h
mov x,0
mov y,17
call setCursor
mov ah,9
mov dx , offset line
int 21h
mov y,18 ;
mov x ,0 ;
call setCursor
;cout<< "P1name:"
mov ah,9
mov dx ,offset Name1
int 21h
mov x, 0
mov y, 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;infinte loop of the chat
infint:
;check for preesed key to input the message
mov ah,1
int 16h
jz jmpchecker2
; check for esc
mov ah,0
int 16h
cmp ah,1h
je jmpchecker3
;set the cursor to cin >> the mes
call setMyCursor
;get key preesed
cmp al , 8d
jne con6
; add delete proc
call delete
jmp no_prnt
con6:
mov bl,ind
mov bh , 0
mov str[bx],al
inc ind
mov char , al
mov ah,9
mov dx ,offset char
int 21h
inc myx
jmp cont3
jmpchecker:
jmp infint
cont3:
jmp cont4
jmpchecker2:
jmp rec
cont4:
jmp cont5
jmpchecker3:
jmp escape
cont5:
mov al ,char
cmp al,0dh
jne con7
call printmsg
con7:
no_prnt:
; inc the y pos after the mes is insertes and printed
rec:
;Check that Data Ready
mov dx , 3FDH ; Line Status Register
in al , dx
AND al , 1
JZ jmpchecker
; print the player name for the first time
and bool,1
jz no_pr
call printpl2name
no_pr:
;If Ready read the VALUE in Receive data register
mov dx , 03F8H
in al , dx
mov char , al
cmp al,1
jz exit
call setCursor
cmp char,0dh
je no_print
mov ah ,9
mov dx,offset char
int 21h
inc x
no_print:
cmp x,80
jl cont1
mov x,40d
inc y
cont1:
cmp y,17d
jl here1
; scroll by 3 lines
call scroll
;update the cursor
mov y ,14d
mov x ,40d
call setCursor
here1:
cmp char,'$'
je end_rec
jmp rec
end_rec:
; inc the y pos after the mes is insertes and printed
inc y
inc y
mov x , 0
mov bool,1
jmp infint
escape:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov sendData,1
call SEND
exit:
RET
chat endp
end