-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhome.asm
341 lines (271 loc) · 10.1 KB
/
home.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
INCLUDE macros.inc
EXTRN pressedButton:BYTE
EXTRN PlayedOnce:BYTE
EXTRN Name1:byte
EXTRN Name2:byte
EXTRN sendData:byte
EXTRN receivedData:byte
public HOME,SEND,printStatus,clear_status,RECEIVE
.MODEL SMALL
.DATA
enter_username db 0
emptystring db 20 dup(' '),'$'
userName db 15,?,15 dup('$')
invalidusername db 'Invalid User Name','$'
message1 db 'Please Enter Your Name:','$'
message1Size equ $-message1
; Name1 db 15,?,15 dup('$')
message3 db 'Press Enter Key to continue','$'
message4 db 'To Start Chatting press F2','$'
message5 db 'To start the game press F1','$'
message6 db 'To end the program press ESC','$'
NoOneInRoom db 'There is no Player in the room','$'
clearStatusMSG db 80 dup(' '),'$'
seperatingLine db 80 dup('-'),'$'
playerExits equ 9
.code
printStatus proc FAR
push dx
mov ah,2
mov dl,0
mov dh,22
int 10h
mov ah,9
pop dx
int 21h
ret
printStatus endp
clear_status proc FAR
lea dx,clearStatusMSG
call printStatus
ret
clear_status endp
SEND PROC FAR
mov dx , 3FDH
AG: in al, dx ;Read Line Status
AND al , 00100000b
JZ AG
mov dx , 3F8H ; Transmit data register
mov al,sendData
out dx , al
RET
SEND ENDP
RECEIVE PROC FAR
;Check that Data Ready
waitRec:
mov dx , 3FDH ; Line Status Register
in al , dx
AND al , 1
JZ waitRec
;If Ready read the VALUE in Receive data register
mov dx , 03F8H
in al , dx
mov receivedData , al
RET
RECEIVE ENDP
sendName proc FAR
lea dx,NoOneInRoom
call printStatus
mov bx,0
send_char: mov al,byte ptr Name1[bx]
cmp al,'$'
jne continue_send
mov sendData, al
call SEND
RET
continue_send:
mov sendData ,al
call SEND
waiting_success:
CALL checkExit
mov dx , 3FDH ; Line Status Register
in al , dx ;chk if i recived something
AND al , 1
cmp al, 1
jne waiting_success ;if not continue looping
mov dx , 03F8H ;else get character in al|value
in al , dx
inc bx ;update character
jmp send_char
ret
sendName endp
checkExit proc
mov ah, 1 ; if click on something
int 16h
jz skipexit ;if nothing
mov ah, 0
int 16h
cmp ah, 1h ;chk if key pressed = esc
jne skipexit
mov sendData, playerExits
call SEND
mov ax, 0003h ; clear screen
int 10H
MOV AH, 4CH ;quit
INT 21H
skipexit:
RET
checkExit endp
receiveName proc FAR
mov bx,0
wait_receive:
mov dx , 3FDH ; Line Status Register
in al , dx
AND al , 1
cmp al,1
jne wait_receive
mov dx , 03F8H ;else get character in al|value
in al , dx
mov Name2[bx], al
inc bx
cmp al, '$'
jne continue_receive
RET
continue_receive:
mov sendData, 1 ;send acceptance
CALL SEND
jmp wait_receive
RET
receiveName endp
send_receiveName proc FAR
CALL clear_status
mov dx , 3FDH ; Line Status Register
in al , dx
AND al , 1
cmp al,1
jne no_receive
call receiveName
call sendName
ret
no_receive:
call sendName
call receiveName
ret
send_receiveName endp
HOME PROC FAR
mov AX,@DATA
mov DS,AX
; Move cursor to row 9, column 12
mov ax,0003h
int 10h
cmp enter_username,1
je Restart
mov ah,2
mov dl,12
mov dh,9
int 10h
; Displat message3
mov ah, 9
mov dx, offset message3
int 21h
enteruseragain:
; Move cursor to row 10, column 12
mov ah,2
mov dl,12
mov dh,11
int 10h
; Display message1
mov ah, 9
mov dx, offset message1
int 21h
; Get user name input
mov ah,0AH
mov dx,offset userName
int 21h
; check first byte
cmp userName+2,65
JL showinvalid ; less than 65 invalid
cmp userName+2,90
JLE continue ; greater than 65 and less than or equal 90 continue
; greater than 90
cmp userName+2,122
JG showinvalid
cmp userName+2,97 ; less than or equal 122 and greater than or equal 97
JGE continue
showinvalid:
; Move cursor to row 10, column 12
mov ah,2
mov dl,12+message1Size-1
mov dh,11
int 10h
; remove old name
mov ah, 9
mov dx, offset emptystring
int 21h
; move cursor
mov ah,2
mov dl,12
mov dh,6
int 10h
; display invalid message
mov ah, 9
mov dx, offset invalidusername
int 21h
jmp enteruseragain
continue:
mov enter_username,1
mov ax,@data
mov es,ax
lea si,userName+2
lea di,Name1
mov cl,userName[1]
mov ch,0
rep movsb
Restart:
mov ax,0003h
int 10h
mov ah,2
mov dl,12
mov dh,10
int 10h
mov ah,9
mov dx,offset message4
int 21h
mov ah,2
mov dl,12
mov dh,11
int 10h
mov ah,9
mov dx,offset message5
int 21h
mov ah,2
mov dl,12
mov dh,12
int 10h
mov ah,9
mov dx,offset message6
int 21h
mov ah,2
mov dl,0
mov dh,21
int 10h
mov ah,9
mov dx,offset seperatingLine
int 21h
cmp PlayedOnce,1
jz no_connection
call send_receiveName
call clear_status
no_connection:
ret
notValid:
mov ah,0
int 16h
cmp ah, 3Bh
je retButton
cmp ah, 3Ch
je retButton
cmp ah, 1h
je quit
jmp notValid
retButton:
mov pressedButton,ah
ret
quit:
mov ax,0003h
int 10h
MOV AH, 4CH ; service 4CH - exit with a return code
MOV AL, 01 ; your return code
INT 21H
HOME ENDP
END