-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.asm
9467 lines (8651 loc) · 204 KB
/
main.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
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.286
.model huge
.stack 64
.data
;dimensions of the screen
row dw 0
col dw 0
firstPointX db 3d
;position of my registers
myAXx db 3h
myAXy db 3h
myBXx db 3h
myBXy db 4h
myCXx db 3h
myCXy db 6h
myDXx db 3h
myDXy db 7h
mySIx db 0Bh
mySIy db 3h
myDIx db 0Bh
myDIy db 4h
mySPx db 0Bh
mySPy db 6h
myBPx db 0Bh
myBPy db 7h
;position of my memory
myMemx db 10h
;other's register positions
otherAXx db 18h
otherAXy db 3h
otherBXx db 18h
otherBXy db 4h
otherCXx db 18h
otherCXy db 6h
otherDXx db 18h
otherDXy db 7h
otherSIx db 20h
otherSIy db 3h
otherDIx db 20h
otherDIy db 4h
otherSPx db 20h
otherSPy db 6h
otherBPx db 20h
otherBPy db 7h
;position of other memory
otherMemx db 24h
; colors
WHITE EQU 0FH
RED EQU 0CH
YELLOW EQU 0EH
BLACK EQU 0H
GRAY EQU 7H
LBLUE EQU 9H
DBLUE EQU 1H
PURPLE EQU 0DH
LGREEN EQU 0AH
DGREEN EQU 2H
CYAN EQU 3H
;data for the char to draw (x,y,char,color)
charToDraw db ?
charToDrawColor db ?
charToDrawx db ?
charToDrawy db ?
myNameL LABEL BYTE
myNameSize db 15
myNameActualSize db ?
myName db 15 dup('$')
otherNameL LABEL BYTE
otherNameSize db 15
otherNameActualSize db ?
otherName db 15 dup('$')
; message to winner of the game
firstWin db ' is the winner with score ','$'
;flag to know that there is a winner (1 --> my) (2 --> other)
winnerFlag db 0
; ESC winner
ESCWinnerMSGTitle db "END GAME$"
ESCWinnerMSG db " got score $"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Main Screen;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
firstModifiedMSG db 'You Sent a game inivitation to ','$'
secondModifiedMSG db 'You Sent a chatting inivitation to ','$'
thirdModifiedMSG db ' sent you a game invitation to accept press F2 ','$'
fourthModifiedMSG db ' sent you a chatting invitation to accept press F1 ','$'
firstMSG db 'To Start Chatting Press F1','$'
secondMSG db 'To Start The Game Press F2','$'
thirdMSG db 'To End the program press ESC','$'
LINE db '--------------------------------------------------------------------------------','$'
carReturn db 10,13,'$'
selectedMode db ? ; 1 for chat ---- 2 for game
;flag to know if the current user is the one who started the chat or the game
;0 --> the other started
;1 --> i started
starterMainScreenFlag db ?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Get Forbidden char;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; level window data
getLevelMSG db "Please enter the level (1-2): $"
; forbiden character window data
getForbiddenMSGWindow db "Please enter forbidden character: $"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Level 2 Registers;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AXmsg db 'AX = $'
BXmsg db 'BX = $'
CXmsg db 'CX = $'
DXmsg db 'DX = $'
SImsg db 'SI = $'
DImsg db 'DI = $'
SPmsg db 'SP = $'
BPmsg db 'BP = $'
Donemsg db 'Registers Done!$'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Wanted Value Variables;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wantedValue dw 105Eh ; number not string to compare it with other
newWantedValueMessage db 'Wanted Value:$'
;if set to 1 this player used it before
flagChangeWantedValue db 0
newWantedValueL LABEL BYTE
newWantedValueSize db 5
newWantedValueActualSize db ?
newWantedValue db 6 dup('$')
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Chating Section;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
myMessageL LABEL BYTE
myMessageSize db 100
myMessageActualSize db ?
myMessage db 100 dup('$')
otherMessageL LABEL BYTE
otherMessageSize db 100
otherMessageActualSize db ?
otherMessage db 100 dup('$')
MessageL LABEL BYTE
MessageSize db 100
MessageActualSize db ?
Message db 100 dup('$')
;position for the messages
MessagePostionY db 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Command Variables;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 0 my turn execute on other registers
; 1 his turn execute on my registers
flagTurn db 0
choiceMessage db '0->yours 1->other$'
myCommandL LABEL BYTE
myCommandSize db 15
myCommandActualSize db ?
myCommand db 15 dup('$')
otherCommandL LABEL BYTE
otherCommandSize db 15
otherCommandActualSize db ?
otherCommand db 15 dup('$')
clearBGC db ' $'
clearBGCHAT db ' $'
Names dw 'xa','xb','xc','xd','is','id','pb','ps','la','ha','lb','hb','lc','hc','ld','hd'
offsets dw 16 dup(00)
flagdst db 0h ;flag for wrong destination
flag db 0h ;flag for wrong source
;type of source and destination and the final offset of them
typeOfDestination db 0fh
destination dw 0000h
typeOfSource db 0fh
source dw 0000h
;our memory variable
offsetMemory dw ?
;our carry
carry db 0
;the chosen level
level db 2
;after getting the command we need to separate it into 3 parts
ourOperation db 4 dup('$')
regName db 5 dup('$')
SrcStr db 5 dup('$')
;our forbidden char
forbiddenChar db ? ; my the other player enters it
myforbiddenChar db ? ; my the other player enters it
otherforbiddenChar db ? ; other i enter it
getForbiddenMsg db 'New Forbidden: $'
;forbidden flag to know that he entered forbidden char
forbiddenFlag db 0 ;equal 1 when the player use that char
;forbidden flag to know if the user used the power up
forbiddenPowerUpFlag db 0 ;equal 1 when the player use the power up
;the possible operations for the player to use
operations db 'mov','add','adc','sub','sbb','xor','and','nop','shr','shl','clc','ror','rol','rcr','rcl','inc','dec','/'
;codes for the operation
;1=mov, 2=add, 3=adc, 4=sub, 5=sbb, 6=xor, 7=and, 8=nop, 9=shr, 10=shl, 11=clc, 12=ror, 13=rol, 14=rcr, 15=rcl, 16=inc, 17=dec
CodeOfOperation db ?
;flags for invalid command
invalidOperationFlag db 0 ;equal 1 when the operation is wrong
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Get name & initial points;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
endl db 10,13 ,'$'
StringToPrint db 'Please enter your Name: ','$'
intialPointSize db 5
intialPointActualSize db ?
initalPointStr db 6 dup ('$')
STRIP db 'Please enter your Intial Point: ','$'
intialPointSizeother db 5
intialPointActualSizeother db ?
initalPointStrother db 6 dup ('$')
myPointsValue db 14h
otherPointsValue db 14h
myPointsX db ?
otherPointsX db ?
pointsY db 0dh
;global variable for printing line (x)
linex dw ?
liney dw ?
;the values of hitted balls with a given color
; 1 2 3 4 5
;Blue, green , Cyan, red , Magenta
coloredPoints db 0h , 0h , 0h , 0h , 0h
;flag to know which operation to perform
ReadyFlag db ?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;variables for postioning
printX db ?
printY db ?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Registers variables;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;my registers data needed
;dummy variable to help printing
RegStringToPrint db 4 dup(?)
MemStringToPring db 2 dup(?)
ASC_TBL DB '0','1','2','3','4','5','6','7','8','9'
DB 'A','B','C','D','E','F'
;flag to know where to run the command
; 0 --> execute on other Registers
; 1 --> execute on my Registers
whichRegisterToExecute db 0
flagSecondPowerUp db 0
; AX, BX, CX, DX, SI, DI, BP, SP
myRegisters dw 0000H, 0000h, 0000h, 0000h, 0000h, 0000h, 0000h, 0000h
; AX, BX, CX, DX, SI, DI, BP, SP
otherRegisters dw 0000h, 0000h, 0000h, 0000h, 0000h, 0000h, 0000h, 0000h
clearAllRegPowerUp db 0
clearAllRegMsg db 'Registers Cleared$'
myMemory db 16 dup(00h)
otherMemory db 16 dup(00h)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Gun Variables;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GUNLoopIterator dw 0
gunFlag db 0
; Variables for Gun
;iterators for draw gun
; gun starts at row 80d
rowGun dw 80d
colGun dw 20d
; gun start row and end row are constants
gunEndRowPosition EQU 90d
; gun start column is variable
; This variable changes the position of my gun
gunStartColumnPosition dw 0d
gunWidth EQU 20d
;Other Variables for Gun
;iterators for draw gun
; gun start column is variable
; This variable changes the position of Other gun
gunStartColumnPositionOther dw 163d
rowTarget dw 0d
colTarget dw 20d
; target start row and end row are constants
targetEndRowPosition EQU 7d
; target start column is variable
; This variable changes the position of my target
targetStartColumnPosition dw 115d
targetWidth EQU 10d
; gun start column is variable
; This variable changes the position of Other target
targetStartColumnPositionOther dw 277d
targetColor db 1 ; this is considered also as the score
rowBullet dw 80d ; iterator for row of bullet always starts at 80d
colBullet dw 20d ; iterator for columns of bullet
; target start row and end row are constants
bulletStartRowPosition dw 85d ; changes and it equals start row + bullet height
bulletStartRowPositionOther dw 85d ; changes and it equals start row + bullet height
bulletEndRowPosition dw 5d ; changes and it equals start row + bullet height
bulletEndRowPositionOther dw 5d ; changes and it equals start row + bullet height
; target start column is variable
; This variable changes the position of my target
bulletStartColumnPosition dw 10d ; equals to midpoint of gun
bulletEndColumnPosition dw 10d
bulletWidth EQU 5d
; gun start column is variable
; This variable changes the position of Other target
bulletStartColumnPositionOther dw 200d
bulletEndColumnPositionOther dw 200d
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;flag to know when to exit the game and chat
exitGame db 0
exitChat db 0
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
call Portinitialization
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Names and Points;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call GetNameAndIntialP
call SendingAndRecevingNames
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Main Screen;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MainScreenLoop:
mov ah,0h
mov al,3h
int 10h
call clearScreen
call mainScreen
mov al,selectedMode
mov dl,2
cmp al,dl
jz StartGame
mov dl,0
cmp al,dl
jz ProgramExit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Chat Section;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
StartChat:
call clearScreen
chatingMainLoop:
call recieveChatKey
call getChatKey
;check if the exit chat flag = 1
mov al,exitChat
mov dl,1
cmp al,dl
jz OutOfChat
jmp chatingMainLoop
OutOfChat:
call clearChat
jmp MainScreenLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Game;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
StartGame:
mov flagTurn,1h
;check if the current user is the one who start the game
mov al,starterMainScreenFlag
mov dl,1
cmp al,dl
jnz IamNotTheStarter
call levelWindow
mov flagTurn,0h
IamNotTheStarter:
;get the forbidden char
call myforbiddenWindow
call getMyIntialPoints
call SendingAndRecevingFCIP
mov al,starterMainScreenFlag
mov dl,1
cmp al,dl
jnz WillNotRecieveLvl
call sendLevel
jmp ContinueAfterLevel
WillNotRecieveLvl:
call recieveLevel
ContinueAfterLevel:
call calcInitialPoints
;set video mode (320x200)
mov ah,0h
mov al,13h
int 10h
call drawBackGround
;draw the register and its intial values
call drawRegNames
call drawMyRegisters
call drawOtherRegisters
;draw the memory and its intial values
call drawMemoryAdresses
call drawMemoryLines
call drawMyMemory
call drawOtherMemory
call printTwoNames
call printPoints
call printCommands
call printWantedValue
call printTwoMessage
call printTwoPoints
call level2Intial
call sendAndRecieveInitialReg
call printForbiddenChar
;for the main loop, note: outside the loop called one time
;get out of the loop when (myPointsValue or otherPointsValue) = 0
;get out of the loop when (any register value = wantedValue)
GameLoop:
call receiveKeyPressed
call getKeyPressed
;check if the exit game flag = 1
mov al,exitGame
mov dl,1
cmp al,dl
jz OutOfGame
;update the screen
call drawRegNames
call drawMyRegisters
call drawOtherRegisters
call drawMyMemory
call drawOtherMemory
call printTwoPoints
call printPoints
call checkWinner
;check the winner flag
mov al,winnerFlag
mov dl,1
cmp al,dl
jz HaveAWinner
mov dl,2
cmp al,dl
jz HaveAWinner
jmp GameLoop
OutOfGame:
call ESCWinnerScreen
mov exitGame,0
call clearTheGame
jmp MainScreenLoop
HaveAWinner:
call WinnerScreen
mov winnerFlag,0
mov exitGame,0
call clearTheGame
jmp MainScreenLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ProgramExit:
call clearScreen
hlt
main endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Communication;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Portinitialization proc
;Set Divisor Latch Access Bit
mov dx,3fbh ; Line Control Register
mov al,10000000b ;Set Divisor Latch Access Bit
out dx,al
;Set LSB byte of the Baud Rate Divisor Latch register.
mov dx,3f8h
mov al,0ch
out dx,al
;Set MSB byte of the Baud Rate Divisor Latch register.
mov dx,3f9h
mov al,00h
out dx,al
;Set port configuration
mov dx,3fbh
mov al,00011011b
out dx,al
ret
Portinitialization endp
SendingAndRecevingNames proc
;who finish first send the other (DD --> will start sending his name first)
;check if the other sent (DD)
;{ send (DF) which means that we are ready to receive and call receive function }
;else send him (DD)
;check if the other sent any thing
mov dx , 3FDH ; Line Status Register
in al , dx
AND al , 1
jz sendReady
mov dx , 03F8H
in al , dx
mov ReadyFlag,al
;send DF to start receiving the other name
mov dx , 3FDH ;Line Status Register
SDFAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SDFAGAIN
mov dx , 3F8H ;Transmit data register
mov al,0DFH
out dx,al
call receiveOtherName
;send DD to start sending your name
mov dx , 3FDH ;Line Status Register
SDDAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SDDAGAIN
mov dx , 3F8H ;Transmit data register
mov al,0DDH
out dx,al
mov dx , 3FDH ; Line Status Register
WAITDFCHK:
in al , dx
AND al , 1
JZ WAITDFCHK
mov dx , 03F8H
in al , dx
mov ReadyFlag,al
call sendMyName
jmp readyFlagEnd
sendReady:
;then send DD if no thing to receive
mov dx , 3FDH ;Line Status Register
SRFAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SRFAGAIN
mov dx , 3F8H ;Transmit data register
mov al,0DDH
out dx,al
mov dx , 3FDH ; Line Status Register
WAITDFCHK2:
in al , dx
AND al , 1
JZ WAITDFCHK2
mov dx , 03F8H
in al , dx
mov ReadyFlag,al
call sendMyName
mov dx , 3FDH ; Line Status Register
WAITDDCHK:
in al , dx
AND al , 1
JZ WAITDDCHK
mov dx , 03F8H
in al , dx
mov ReadyFlag,al
;send DF to start receiving the other name
mov dx , 3FDH ;Line Status Register
SDFAGAIN2:
In al,dx ;Read Line Status
AND al,00100000b
JZ SDFAGAIN2
mov dx , 3F8H ;Transmit data register
mov al,0DFH
out dx,al
call receiveOtherName
readyFlagEnd:
ret
SendingAndRecevingNames endp
sendMyName proc
;send the actualSize
mov dx , 3FDH ;Line Status Register
SACNAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SACNAGAIN
mov dx , 3F8H ;Transmit data register
mov al,myNameActualSize
out dx,al
;loop to send the entire name
mov ch,0
mov cl,myNameActualSize
lea si,myName
MyNameSendLoop:
mov dx,3FDH ;Line Status Register
SMNAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SMNAGAIN
mov dx , 3F8H ;Transmit data register
mov al,[si]
out dx,al
inc si
loop MyNameSendLoop
ret
sendMyName endp
receiveOtherName proc
;receive the actual size of the otherName
mov dx,3FDH ; Line Status Register
RONACCHK:
in al,dx
AND al,1
JZ RONACCHK
mov dx,03F8H
in al,dx
mov otherNameActualSize,al
mov ch,0
mov cl,otherNameActualSize
lea si,otherName
otherNameReceiveLoop:
mov dx,3FDH ; Line Status Register
RONCHK:
in al,dx
AND al,1
JZ RONCHK
mov dx,03F8H
in al,dx
mov [si],al
inc si
loop otherNameReceiveLoop
ret
receiveOtherName endp
SendingAndRecevingFCIP proc
;who finish first send the other (DD --> will start sending his name first)
;check if the other sent (DD)
;{ send (DF) which means that we are ready to receive and call receive function }
;else send him (DD)
;check if the other sent any thing
mov dx , 3FDH ; Line Status Register
in al , dx
AND al , 1
jz sendReadyFCIP
mov dx , 03F8H
in al , dx
mov ReadyFlag,al
;send DF to start receiving the forbidden char and intial points
mov dx , 3FDH ;Line Status Register
SFCIPAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SFCIPAGAIN
mov dx , 3F8H ;Transmit data register
mov al,0DFH
out dx,al
call receiveForbiddenChar
call receiveIntialPoints
;send DD to start sending your forbidden char and intial point
mov dx , 3FDH ;Line Status Register
SDDFCIPAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SDDFCIPAGAIN
mov dx , 3F8H ;Transmit data register
mov al,0DDH
out dx,al
mov dx , 3FDH ; Line Status Register
WAITDFFCIPCHK:
in al , dx
AND al , 1
JZ WAITDFFCIPCHK
mov dx , 03F8H
in al , dx
mov ReadyFlag,al
call sendForbiddenChar
call sendIntialPoints
jmp readyFlagEndFCIP
sendReadyFCIP:
;then send DD if no thing to receive
mov dx , 3FDH ;Line Status Register
SRFAGAINFCIP:
In al,dx ;Read Line Status
AND al,00100000b
JZ SRFAGAINFCIP
mov dx , 3F8H ;Transmit data register
mov al,0DDH
out dx,al
mov dx , 3FDH ; Line Status Register
WAITDFFCIPCHK2:
in al , dx
AND al , 1
JZ WAITDFFCIPCHK2
mov dx , 03F8H
in al , dx
mov ReadyFlag,al
call sendForbiddenChar
call sendIntialPoints
mov dx , 3FDH ; Line Status Register
WAITDDCHKFCIP:
in al , dx
AND al , 1
JZ WAITDDCHKFCIP
mov dx , 03F8H
in al , dx
mov ReadyFlag,al
;send DF to start receiving the other name
mov dx , 3FDH ;Line Status Register
SDFAGAINFCIP2:
In al,dx ;Read Line Status
AND al,00100000b
JZ SDFAGAINFCIP2
mov dx , 3F8H ;Transmit data register
mov al,0DFH
out dx,al
call receiveForbiddenChar
call receiveIntialPoints
readyFlagEndFCIP:
ret
SendingAndRecevingFCIP endp
sendForbiddenChar proc
;send my forbidden char
mov dx , 3FDH ;Line Status Register
SFCAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SFCAGAIN
mov dx , 3F8H ;Transmit data register
mov al,otherforbiddenChar
out dx,al
ret
sendForbiddenChar endp
sendWantedValue proc
mov cx,wantedValue
;send wanted value
mov dx , 3FDH ;Line Status Register
SWVAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SWVAGAIN
mov dx , 3F8H ;Transmit data register
mov al,cl
out dx,al
;send my forbidden char
mov dx , 3FDH ;Line Status Register
SFWVGAIN2:
In al,dx ;Read Line Status
AND al,00100000b
JZ SFWVGAIN2
mov dx , 3F8H ;Transmit data register
mov al,ch
out dx,al
ret
sendWantedValue endp
receiveWantedValue proc
;receive the wanted char
mov cx,0
mov dx,3FDH ; Line Status Register
RWVCHK:
in al,dx
AND al,1
JZ RWVCHK
mov dx,03F8H
in al,dx
mov cl,al
mov dx,3FDH ; Line Status Register
RWVCHK2:
in al,dx
AND al,1
JZ RWVCHK2
mov dx,03F8H
in al,dx
mov ch,al
mov wantedValue,cx
ret
receiveWantedValue endp
sendIntialPoints proc
;send my inital value
mov dx , 3FDH ;Line Status Register
SIPAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SIPAGAIN
mov dx , 3F8H ;Transmit data register
mov al,myPointsValue
out dx,al
ret
sendIntialPoints endp
receiveForbiddenChar proc
;receive the forbidden char
mov dx,3FDH ; Line Status Register
RFCCHK:
in al,dx
AND al,1
JZ RFCCHK
mov dx,03F8H
in al,dx
mov myforbiddenChar,al
ret
receiveForbiddenChar endp
receiveIntialPoints proc
;receive the intial point
mov dx,3FDH ; Line Status Register
RIPCHK:
in al,dx
AND al,1
JZ RIPCHK
mov dx,03F8H
in al,dx
mov otherPointsValue,al
ret
receiveIntialPoints endp
sendLevel proc
;send the level
mov dx , 3FDH ;Line Status Register
SLVLAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SLVLAGAIN
mov dx , 3F8H ;Transmit data register
mov al,level
out dx,al
ret
sendLevel endp
recieveLevel proc
;receive the level
mov dx,3FDH ; Line Status Register
RLVLCHK:
in al,dx
AND al,1
JZ RLVLCHK
mov dx,03F8H
in al,dx
mov level,al
ret
recieveLevel endp
sendMyCommand proc
;first send the actual size of the command
mov dx , 3FDH ; Line Status Register
SENDASCOMAGAIN:
In al , dx ;Read Line Status
AND al , 00100000b
JZ SENDASCOMAGAIN
mov dx , 3F8H ; Transmit data register
mov al,myCommandActualSize
out dx , al
;loop to send the entire name
mov ch,0
mov cl,myCommandActualSize
lea si,myCommand
MyCommandSendLoop:
mov dx,3FDH ;Line Status Register
SENDCOMAGAIN:
In al,dx ;Read Line Status
AND al,00100000b
JZ SENDCOMAGAIN
mov dx , 3F8H ;Transmit data register
mov al,[si]
out dx,al
inc si
loop MyCommandSendLoop
ret
sendMyCommand endp
receiveMyCommand proc
;receive the actual size of the command
mov dx,3FDH ; Line Status Register
REASCOMCCHK:
in al,dx
AND al,1
JZ REASCOMCCHK
mov dx,03F8H
in al,dx
mov otherCommandActualSize,al
mov ch,0
mov cl,otherCommandActualSize
lea si,otherCommand
otherCommandReceiveLoop:
mov dx,3FDH ; Line Status Register
ROCOMCHK:
in al,dx
AND al,1
JZ ROCOMCHK
mov dx,03F8H
in al,dx
mov [si],al
inc si
loop otherCommandReceiveLoop
ret
receiveMyCommand endp
sendOtherRegisters proc
;send Other Registers
mov ch,0
mov cl,16d
lea si,OtherRegisters
SendORegistersLoop:
mov dx , 3FDH ; Line Status Register
SENDOREGAGAIN:
In al , dx ;Read Line Status
AND al , 00100000b
JZ SENDOREGAGAIN
mov dx , 3F8H ; Transmit data register
mov al,[si]
out dx , al
inc si
loop SendORegistersLoop
ret
sendOtherRegisters endp
receiveOtherRegisters proc
mov ch,0
mov cl,16d
lea si,otherRegisters
otherRegReceiveLoop:
mov dx,3FDH ; Line Status Register
ROREGCHK:
in al,dx
AND al,1
JZ ROREGCHK
mov dx,03F8H
in al,dx
mov [si],al
inc si
loop otherRegReceiveLoop
ret
receiveOtherRegisters endp
sendOtherMemory proc
;send Other Memory
mov ch,0
mov cl,16d
lea si,otherMemory
SendOtherMemoryLoop:
mov dx , 3FDH ; Line Status Register
SENDOMEMAGAIN: