-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathChat.asm
More file actions
460 lines (402 loc) · 6.24 KB
/
Copy pathChat.asm
File metadata and controls
460 lines (402 loc) · 6.24 KB
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
Public ChatScreen
EXTRN SendByte:FAR
EXTRN Ana_El_Tl3t:Byte
EXTRN SMsg:Byte
EXTRN RMsg:Byte
.286
.model small
.stack 64
.data
IY DB 0D
IX DB 0D
OX DB 40D
OY DB 0D
VLine db '#'
Player_Exited_Msg db 'The other person left the chat :(', '$'
.code
ChatScreen proc far
mov ax,@data
mov ds,ax
call inializeScreen
;CALL intializePort
;CODE
CHECKKEYPRESSED:
;CHECK IF THERE IS A KEY PRESSESD SEND TO THE OTHER USER
MOV AH,01h
INT 16H
JZ CHECKKEYSENT ;KEY recieved
oout:
MOV AH,00
INT 16H
CMP AL,1BH
JE EXIT
cmp al,' ' ;if space or enter it is ok
je vvv
cmp al,8
je vvv
cmp al,0dh
je vvv
cmp al, 'z' ;out of range for letters
ja oout
cmp al, 21h
jb oout
; cmp al, 'Z'
; jb oout
; cmp al, 'a'
; jb oout
vvv:
call WRITEINPUT
CALL SENDKEY
CHECKKEYSENT:
;CHECK STATE IF THERE IS DATA RECIVED
;IF THERE IS NO DATA RECIVED
MOV DX,3FDH
IN AL,DX
AND AL,1
JZ CHECKKEYPRESSED
;IF THERE IS DATA RECIVED
;RECIVE DATA AND CALL WRITE IN OUTPUT PROC
MOV DX,03F8H
IN AL,DX
cmp al, 200
je OtherPlayerExited
CALL WRITEOUTPUT
JMP CHECKKEYPRESSED
;END CODE
OtherPlayerExited:
lea bp, Player_Exited_Msg
mov al, 1
mov bh, 0
mov bl, 4
mov cx, 33
mov dl, 24
mov dh, 12
push ds
pop es
mov ah, 13h
int 10h
AwaitESC:
mov ah,1
int 16h
jz AwaitESC
mov ah,0
int 16h
cmp ah,1
jne AwaitESC
mov SMsg, 201
lea di, SMsg
call SendByte
ret
EXIT:
mov al, 200
call SENDKEY
call SCROLLInputScreen
call SCROLLOutputScreen
mov Ana_El_Tl3t, 1
ret
ChatScreen ENDP
intializePort proc
mov dx,3fbh ;line control register
mov al,10000000b ;set divisor latch access bit
out dx,al ;out it
mov dx,3f8h
mov al,0ch
out dx,al
mov dx,3f9h
mov al,00h
out dx,al
mov dx,3fbh
mov al,00011011b
out dx,al
ret
intializePort endp
WRITEINPUT PROC
cmp IY,24d
jb kammelI
cmp IX,37
jb kammelI
call SCROLLInputScreen
mov IY,24d
mov IX,0
kammelI:
cmp al,8
jne notback
mov ah,2
mov dl,8
int 21h
mov dl,' '
int 21h
mov dl,8
int 21h
cmp ix,0
je ohno3
dec iX
mov AH,2
mov DL,iX
MOV DH,iY
int 10h
ret
ohno3:
mov ix,38
cmp iy,0
jne ohno4
mov ix,0
mov AH,2
mov DL,iX
MOV DH,iY
int 10h
ret
ohno4:
dec iy
mov AH,2
mov DL,iX
MOV DH,iY
int 10h
ret
notback:
cmp al,13d ;to check if the value entered is an enter key
jne cont1
cmp Iy,24d
jb cont1
cmp ix,38d ;to check the borders before writing the char
jb cc
CALL newILine
mov AH,2
mov DL,IX
MOV DH,IY
int 10h
call SCROLLInputScreen
RET
cc:
call SCROLLInputScreen
call newILine
mov IY,24d
mov AH,2
mov DL,IX
MOV DH,IY
int 10h
ret
cont1:
CMP AL,13d
JE IENTER
CMP ix,38
jb p1
mov IX,0
inc IY
p1:
mov AH,2
mov DL,IX
MOV DH,IY
int 10h
mov ah,2
mov dl,al
int 21h
; MOV AH,09H
; MOV BH, 0 ; Set page number
; MOV BL, 0fh ; Color (blue)
; MOV CX, 1 ; Character count
; INT 10h
INC IX
RET
IENTER:
CALL newILine
mov AH,2
mov DL,IX
MOV DH,IY
int 10h
RET
WRITEINPUT ENDP
WRITEOUTPUT PROC
cmp OY,24d
jb kammelO
cmp Ox,78
jb KammelO
call SCROLLOutputScreen
mov OY,24d
mov Ox,40
kammelO:
cmp al,8
jne notback2
cmp ox,40
je fo
mov ah,2
mov dl,8
int 21h
mov dl,' '
int 21h
mov dl,8
int 21h
fo:
cmp ox,40
jbe ohno1
dec OX
mov AH,2
mov DL,oX
MOV DH,oY
int 10h
ret
ohno1:
mov ox,78
cmp oy,0
jne ohno2
mov ox,40
mov AH,2
mov DL,oX
MOV DH,oY
int 10h
ret
ohno2:
dec oy
mov AH,2
mov DL,oX
MOV DH,oY
int 10h
ret
notback2:
cmp al,13d
jne cont2
cmp oy,24d
jb cont2
cmp ox,78d
jb cc1
call SCROLLOutputScreen ;before scrolling the screen ->check the y if equal 24 and x if equal 79 the last place of the crusor ,if true scroll
RET
cc1:
call SCROLLOutputScreen
call newOLine
mov oY,24d
mov AH,2
mov DL,oX
MOV DH,oY
int 10h
ret
cont2:
CMP AL,13d
JE OENTER
CMP ox,78
jb p2
mov oX,40
inc oY
p2:
mov AH,2
mov DL,oX
MOV DH,oy
int 10h
mov ah,2
mov dl,al
int 21h
; MOV AH,09H
; MOV BH, 0 ; Set page number
; MOV BL, 0fh ; Color (red)
; MOV CX, 1 ; Character count
; INT 10h
INC oX
RET
OENTER:
CALL newOLine
mov AH,2
mov DL,OX
MOV DH,OY
int 10h
RET
WRITEOUTPUT ENDP
SENDKEY PROC
MOV DX,3F8H
OUT DX,AL
RET
SENDKEY ENDP
inializeScreen proc
mov ah,0
mov al,3h ;to open text mode
int 10h
mov ah,2
mov dl,39
mov dh,0
mov cx,25 ;the length of the screen
lp:
mov ah,2 ;to move the cursor the the values of(dl,dh)
int 10h
mov dl,186 ;to print H to separate the screen at the middle
int 21h
mov dl,39
inc dh
LOOP lp
mov al,0h ; function 6
mov ah,6h
mov bh, 8Fh ; normal video attribute
mov ch,0 ; upper left Y
mov cl,40 ; upper left X
mov dh,24 ; lower right Y
mov dl,79 ; lower right X
int 10h
mov al,0h ; function 6
mov ah,6h
mov bh,8Fh ; normal video attribute
mov ch,0 ; upper left Y
mov cl,0 ; upper left X
mov dh,24 ; lower right Y
mov dl,38 ; lower right X
int 10h
mov IY , 0D
mov IX , 0D
mov OX , 40D
mov OY , 0D
mov ah,2
mov bh,0
mov dl,0
mov dh,0
int 10h
mov ax,1003h
mov bx,0
int 10h
ret
inializeScreen endp
SCROLLInputScreen proc
pusha
mov al,1h ; function 6
mov ah,6h
mov bh,8Fh ; normal video attribute
mov ch,0 ; upper left Y
mov cl,0 ; upper left X
mov dh,24 ; lower right Y
mov dl,38 ; lower right X
int 10h
mov ah,3
mov bh,0
int 10h
;mov ah,2
;mov dl,' '
;int 21h
popa
ret
SCROLLInputScreen endp
SCROLLOutputScreen proc
pusha
mov al,1h ; function 6
mov ah,6h
mov bh,8Fh ; normal video attribute
mov ch,0 ; upper left Y
mov cl,40 ; upper left X
mov dh,24 ; lower right Y
mov dl,79 ; lower right X
int 10h
mov ah,3
mov bh,0
int 10h
;mov ah,2
;;mov dl,' '
;int 21h
popa
ret
SCROLLOutputScreen endp
newILine proc
mov IX,0
inc IY
ret
newILine endp
newOLine proc
mov OX,40
inc OY
ret
newOLine endp
end