-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer1.asm
3217 lines (2483 loc) · 68.6 KB
/
Player1.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
displayRegister MACRO corX,corY,string,sizeOfString
local again
;This macro is to display the names of registers
;; corX--> cordinate of x of the starting point of typing
;; corY-->coordinate of y of the starting point of typing
;; string--> the string I want to type it
;;color-->to select the color of the printed word or byte
XOR AX,AX ;clear ax
XOR BX,BX ;clear bx
XOR CX,CX ;clear cx
XOR DX,DX ;clear dx
xor si,si
xor di,di
MOV SI, OFFSET string
MOV DH,corY
MOV DL,corX
MOV CX,sizeOfString
;-----------------------DisplayContents------------------
again:
MOV AH,2 ;; INT 10/AH=2 FOR SETTIING THE CURSOR
INT 10H
push dx
MOV AL,[SI] ;;the ascii of the letter for al bec. the letter to print is stored in AL
MOV BL,0EH ;; BL FOR THE COLOR
MOV BH,0 ;; BH FOR THE PAGE NUMBER
MOV AH,0EH ;; INT 10/AH=0EH FOR WRITING IN VGA MODE
INT 10H
pop dx
INC DL ;;increment the cordinates of x for the cursor
INC SI ;;go to the next letter
LOOP again
; mov cx,00
; mov dx,0F015H
; mov ah,86h
; Int 15h
ENDM
DisplayWord MACRO corX,corY,string,numberByte,COLOR,ASCII_TABLE
local back
;This is a macro to be used in displaying word in VGA mode
;; corX--> cordinate of x of the starting point of typing
;; corY-->coordinate of y of the starting point of typing
;; string--> the string I want to type it
;;numberByte--> the size of the string
;;COLOR-->to select the color of the printed word or byte
;;ASCII_TABLE for XLAT instruction
XOR AX,AX ;clear ax
XOR BX,BX ;clear bx
XOR CX,CX ;clear cx
XOR DX,DX ;clear dx
xor si,si
xor di,di
MOV SI,OFFSET STRING
MOV CL,4
MOV DH,corY
MOV DL,corX
MOV CL,4
MOV DI, numberByte
MOV AH,2 ;; INT 10/AH=2 FOR SETTIING THE CURSOR
INT 10H
xor ax,ax
INC SI ;; this is to start by the first of
MOV AL,[SI]
BACK:
;the next section for trying to isolate the nibble to print it only
;sub ax,ax
MOV AL,[SI]
ROl Ax,CL
ROR AL,CL
PUSH AX
MOV AL,AH
MOV BX,OFFSET ASCII_TABLE
XLAT
;NOW LET'S SET THE CURSOR
; MOV AH,2 ;; INT 10/AH=2 FOR SETTIING THE CURSOR
; INT 10H
;THIS FOR TYPING THE nibble
MOV BL,COLOR ;; BL FOR THE COLOR
MOV BH,0 ;; BH FOR THE PAGE NUMBER
MOV AH,0EH ;; INT 10/AH=0EH FOR WRITING IN VGA MODE
INT 10H
;INCREMENT THE VALUES FOR THE NEXT ITERATIONS
INC DL
MOV AH,2 ;; INT 10/AH=2 FOR SETTIING THE CURSOR
INT 10H
;NOW WE WILL PRINT THE SECOND NIBBLE
POP AX
MOV BX,OFFSET ASCII_TABLE
XLAT
MOV BL,COLOR ;; BL FOR THE COLOR
MOV BH,0 ;; BH FOR THE PAGE NUMBER
MOV AH,0EH ;; INT 10/AH=0EH FOR WRITING IN VGA MODE
INT 10H
;THE NEXT PART IS TO ORGANISE THE LOOP
INC DL
DEC DI
DEC SI
xor ax,ax
CMP DI,0
JNE BACK
ENDM
getString MACRO corX,corY,string
XOR AX,AX ;clear ax
XOR BX,BX ;clear bx
XOR CX,CX ;clear cx
XOR DX,DX ;clear dx
xor si,si
xor di,di
mov dh,corY
mov dl,corX
mov ah,2
int 10h
mov dx, offset string
mov ah,0Ah
int 21h
ENDM
LoadString MACRO OriginalString,CopiedString,SizeOfOriginal,SizeOfCopied
MOV SI,OFFSET OriginalString
MOV DI,OFFSET CopiedString
MOV CX,SizeOfOriginal
REPE MOVSB
;Push BX
MOV BX,SizeOfOriginal
MOV SizeOfCopied,BX
ENDM
COMPARE MACRO instruction,avaliable_instruction,sizeOfInstruction,opcode
Local FOUND,UNFOUND,DONE1
MOV SI,OFFSET avaliable_instruction
MOV DI,OFFSET instruction
MOV CX,sizeOfInstruction
REPE CMPSB
CMP CX,0
JE FOUND
JNE UNFOUND
FOUND: MOV AX,opcode
MOV instructionOpcode,AX
MOV instructionFound,1
JMP DONE1
UNFOUND:MOV instructionFound,0
DONE1:
ENDM
displayName MACRO corX,corY,string
XOR AX,AX ;clear ax
XOR BX,BX ;clear bx
XOR CX,CX ;clear cx
XOR DX,DX ;clear dx
xor si,si
xor di,di
; MOV SI, OFFSET string
; ADD SI,2
MOV DH,corY
MOV DL,corX
MOV AH,2 ;; INT 10/AH=2 FOR SETTIING THE CURSOR
INT 10H
MOV DX, OFFSET string
MOV AH,9
INT 21H
XOR AX,AX ;clear ax
XOR BX,BX ;clear bx
XOR CX,CX ;clear cx
XOR DX,DX ;clear dx
xor si,si
xor di,di
ENDM
HexToAsc MACRO number,string ;2 characters only
Push ax
Push di
XOR AX, AX
XOR DI,DI
mov al,number
MOV DL, 0AH
DIV DL
MOV DI, offset string
ADD DI, 1
MOV [DI], AH
ADD [DI], 30H
MOV AH, 0
DIV DL
DEC DI
MOV [DI], AH
ADD [DI], 30H
Pop di
Pop ax
ENDM
AscToHex MACRO string, result
Push ax
Push si
XOR AX, AX
XOR SI, SI
mov si,offset string
add si,2
sub [si],30h
inc si
sub [si],30h
mov SI,offset string
ADD SI, 2
mov AL, [SI]
MOV DL, 10
MUL DL
INC SI
ADD AL, [SI]
mov result,AL
Pop si
Pop ax
ENDM
.model large
.386
.stack 64
;ORG 1000
.data
;ORG 1000
please db 'Please enter your name:',10,13,'$'
initial db 'Initial Points:',10,13,'$'
key db 'Press ENTER key to continue$'
hasWon db 0h
StartChatting db 'To Start Chatting Press F1','$'
StartGame db 'To Start The Game Press F2','$'
EndGame db 'To End The Game Press ESC','$'
Assump db 'All instructions should be written in UPPERCASE letters',10,13,' ',10,13,'No spaces between operands',10,13,' ',10,13,'Each mistake will cost you -1 points','$'
forbiddenCharLabel db 'Please Enter the forbidden Character(In Caps):',10,13,'$'
LevelSelect db 'Press 1 to select level 1',10,13,' ',10,13,'Press 2 to select level 2','$'
namePlayer1 db 15,?, 15 dup('$')
scoreLabelPlayer1 db 5,?,5 dup('$')
namePlayer2 db 15,?, 15 dup('$')
scoreLabelPlayer2 db 5,?,5 dup('$')
forbiddenTempChar1 db 2,?, 2 dup('$')
forbiddenTempChar2 db 2,?, 2 dup('$')
forbiddenChar1 db 0H
forbiddenChar2 db 0H
noOfForbiddenPlayer1 db 0h
scoreLabel db 'Score:','$'
;org 20
scorePlayer1 db 0h
scorePlayer2 db 0h
;;namePlayer1 db 'Omar','$'
;sizeNamePlayer1 db ?
;;namePlayer2 db 'Atef','$'
;sizeNamePlayer2 db ?
;cfPlayer2 db 00h
userString db 12,?,12 dup('$')
cfLabel db 'CF','$'
axLabel db 'AX'
bxLabel db 'BX'
cxLabel db 'CX'
dxLabel db 'DX'
siLabel db 'SI'
diLabel db 'DI'
spLabel db 'SP'
bpLabel db 'BP'
all_Registers_stringPlayer1 DB "AXBXCXDXSIDISPBPALAHBLBHCLCHDLDH" ;this is a string that contain all the registers, this string is helpful in detecting the exsistance of registers
player1Registers label byte
;Send elements starting from here
axPlayer1 dw 0
bxPlayer1 dw 07h
cxPlayer1 dw 09h
dxPlayer1 dw 30h
siPlayer1 dw 0
diPlayer1 dw 0
spPlayer1 dw 0Fh
bpPlayer1 dw 0
;player1Registers + 15
memoryPlayer1 db 16 dup(0)
originatevar db 0
cfPlayer1 DB 0
axPlayer2 DW 0008h
bxPlayer2 DW 0009h
cxPlayer2 DW 000Ah
dxPlayer2 DW 000Bh
siPlayer2 DW 000Ch
diPlayer2 DW 000Dh
spPlayer2 DW 000Eh
bpPlayer2 DW 000Fh
;player2Registers + 15
memoryPlayer2 db 16 dup(0)
cfPlayer2 DB 0
playerTurn db 1h
hasWon DB 0
;End Send 33*2 bytes -> put 66 (42h) in cx and loop
axPlayerN DW 0000h
determineRegisters db 2h
CarryFlagN dw 0000h
scorePlayerN dw 0h
forbiddenCharFound db 0h
;ORG 20
operand2Immediate dw ?
operand1Immediate dw ?
isOperand2Immediate dw ?
isOperand1Immediate dw ?
offsetOperand1 dw ?
offsetOperand2 dw ?
offsetOperandN dw ?
operation DB 20,?,20 dup('$')
instruction DB 5 DUP('$')
operands DB 20 dup('$')
operand1 DB 5 DUP('$')
operand2 DB 5 DUP('$')
operandN DB 5 DUP('$')
ptrOperandN DB 5 DUP('$')
emptyString DB 5 DUP('$')
sizeOfOperand1 DW ?
sizeOfOperand2 DW ?
sizeOfOperandN DW ?
sizeOfInstruction DW ?
Operand db '[CX]'
hexOperand1 dw 0
hexOperand2 dw 0
hexOperandN dw 0
hasError db 0h
hasBrack db 0h
isNum db 0h
isChar db 0h
operandsCount db ?
validAddressing db 0h
validMem db 0h
isOperand1Register DB ?
isOperand2Register DB ?
isOperand1HasOffset DB ?
isOperand2HasOffset DB 0
isOperandNHasOffset DB 0
isOperand18Bits DB ?
isOperand28Bits DB ?
isOperandN8Bits DB ?
Counter dw 0h
isFirstCharLetterOperand1 DB 0
isFirstCharLetterOperand2 DB 0
isFirstCharNumberOperand1 DB 0
isFirstCharNumberOperand2 DB 0
isFirstCharLetterOperandN DB 0
isFirstCharNumberOperandN DB 0
;Size db 4h
AsciiToHexTable db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,41h,42h,43h,44h,45h,46h
instructionFound db 0h ;This is a boolean variable
instructionOpcode dw ?
movInst db 'MOV'
addInst db 'ADD'
adcInst db 'ADC'
subInst db 'SUB'
sbbInst db 'SBB'
mulInst db 'MUL'
;imulInst db 'IMUL'
xorInst db 'XOR'
andInst db 'AND'
orInst db 'OR'
notInst db 'NOT'
clcInst db 'CLC'
pushInst db 'PUSH'
popInst db 'POP'
incInst db 'INC'
decInst db 'DEC'
nopInst db 'NOP'
divInst db 'DIV'
shlInst db 'SHL'
shrInst db 'SHR'
negInst db 'NEG'
;------------------------------------------------------------------
;------------------------------------------------------------------
;------------------------------------------------------------------
gameLevel DB 0
noOfClearedRegisters DB 0
newForbidden db 2,?, 2 dup('$')
forbiddenCharN db 2,?, 2 dup('$')
winningValue dw 10Eh
Palette LABEL WORD
dw 0000h;0 -GRB ChatLine
dw 00A1h;1 -GRB Strokes
dw 0FFFh;2 -GRB
dw 0FFAh;3 -GRB Background
dw 0FFFh;4 -GRB
dw 0FFFh;5 -GRB
dw 0FFFh;6 -GRB
dw 0FFFh;7 -GRB
dw 0FFFh;8 -GRB
dw 0FFFh;9 -GRB
dw 0FFFh;10 -GRB
dw 0FFFh;11 -GRB
dw 0FFFh;12 -GRB
dw 0FFFh;13 -GRB
dw 0FFFh;14 -GRB
dw 0FFFh;15 -GRB
dw 0FFFh;16 -GRB
dw 0FFFh;17 -GRB
dw 0FFFh;18 -GRB
dw 0FFFh;19 -GRB
ImageWidth EQU 320
ImageHeight EQU 200
ASC_TABL DB '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
BOL_TABL DB '0','1'
Filename DB 'guifinal.bin', 0
Filehandle DW ?
ImageData DB ImageWidth*ImageHeight dup(0)
.code
;MAIN PROC FAR
; call the menus
; call the gui
; MAIN ENDP
main proc far
mov ax,@data
mov ds,ax
mov es,ax
XOR AX,AX ;clear ax
XOR BX,BX ;clear bx
XOR CX,CX ;clear cx
XOR DX,DX ;clear dx
xor si,si
xor di,di
mov ax,0013h
int 10h ;clear screen 10h/ah=0
MOV AX,0003H
int 10h
mov ah,9
mov dx,offset please
int 21h
mov ah,0ah
mov dx, offset namePlayer1
int 21h
mov ah,2
mov dx,0300h ;Moving the cursor
int 10h
XOR AX,AX ;clear ax
XOR BX,BX ;clear bx
XOR CX,CX ;clear cx
XOR DX,DX ;clear dx
xor si,si
xor di,di
mov ah,9
mov dx, offset initial
int 21h
XOR AX,AX ;clear ax
XOR BX,BX ;clear bx
XOR CX,CX ;clear cx
XOR DX,DX ;clear dx
xor si,si
xor di,di
mov ah,0ah
mov dx, offset scoreLabelPlayer1
int 21h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah,2
mov dx,0600h ;Moving the cursor
int 10h
mov ah,9
mov dx, offset forbiddenCharLabel
int 21h
mov ah,0ah
mov dx, offset forbiddenTempChar1
int 21h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah,2
mov dx,0B10h ;Moving the cursor
int 10h
mov ah,9
mov dx, offset key
int 21h
is1Enter:
mov ah,0
int 16h
cmp ah,1ch ;Enter key scan code
Jnz is1Enter
jz itisEnter
itisEnter:
call far ptr P2_main_screen
call far ptr GameFlow
main endp
Check_forbidden proc
xor ax,ax
xor bx,bx
xor cx,cx
xor dx,dx
mov di,offset operation[2]
mov al,forbiddenCharN
mov cl,operation[1]
REPNE SCASB
CMP CX,0
JNE forbiddenFOUND
MOV forbiddenCharFound,0
JMP RETURN
forbiddenFOUND: MOV forbiddenCharFound,1
RETURN:
RET
Check_forbidden endp
;------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------
IsWon PROC
mov ax,winningValue
mov di,axPlayer1
mov cx,08h
repne SCASW
CMP CX,0
JNE Player1Won
mov di,axPlayer2
mov cx,08h
repne SCASW
CMP CX,0
JNE Player2Won
cmp scorePlayer1,0H
je Player2Won
cmp scorePlayer2,0h
je Player1Won
jmp NotWon
Player1Won:
mov al,1
mov hasWon, al
ret
Player2Won:
mov al,1
mov hasWon, al
ret
NotWon:
mov al,0
mov hasWon,al
ret
IsWon ENDP
;------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------
;------------------------------------MAIN PROCEDURE----------------------------------------
;------------------------------------------------------------------------------------------
CountOperands proc
mov si, offset operand1
cmp byte ptr[si],'$'
jne IncCount
CheckSecond:
mov si, offset operand2
cmp byte ptr[si],'$'
je exit
inc operandsCount
jmp exit
IncCount:
inc operandsCount
jmp CheckSecond
exit:
ret
CountOperands endp
AssignPlayerN proc
mov cl,determineRegisters
cmp cl,1h
je EnablePlayer1Reg
mov bx, offset axPlayer2
mov axPlayerN, bx
mov bx,offset cfPlayer2
mov CarryFlagN, bx
ret
EnablePlayer1Reg:
mov bx, offset axPlayer1
mov axPlayerN, bx
mov bx,offset cfPlayer1
mov CarryFlagN, bx
ret
AssignPlayerN endp
;Integrated Function
OperandsProc proc far
call far ptr Seperate
call far ptr AssignPlayerN
call far ptr AssignInstructionOpcode
call CountOperands
mov cl,operandsCount
cmp cl,0h
je NoOperands
call far ptr GetOperandType
NoOperands:
ret
OperandsProc endp
ExecuteOperation proc
call far ptr OperandsProc
call far ptr ExecuteInstruction
ret
ExecuteOperation endp
GameFlow proc far
;Call the main screen
; depending on the options of the main screen, we decide if we want to get into the game mode
; the flowing code is just for the flow of the game mode
;the flow of the game itself depends on the main screen
; we can call this procedure by game mode procedure
;Also note that this procedure will almost be the same in player2 with the exception of small change in input values for macros and others
;call far ptr ClearAllRegisters
CMP playerTurn,1
jz its_player_1
jnz ReceiveChanges
its_player_1:
call far ptr ResetVars
;LoadString forbiddenTempChar1,forbiddenCharN,4,4
MOV SI,OFFSET forbiddenTempChar1
MOV DI,OFFSET forbiddencharN
MOV CX,4
REPE MOVSB
EnterAnotherKey:
mov ah,01h
int 16h
mov ah,0h
int 16h
CMP AL,31H
je PowerUpMyself
CMP AL,32H
je PowerUpBoth
CMP AL,33H
je ChangeForbiddenChar
CMP AL,34H
je ClearAll
CMP AL,35H
je CheckCheckLevel2PowerUp
jnz ContinueCheckingKeys
CheckCheckLevel2PowerUp:
CMP gameLevel,2
je ChangeWinValuePowerUp
CMP AL,37H
je PowerUpOnOtherRegisters
jne EnterAnotherKey
ContinueCheckingKeys:
CMP AL,36H
je No_power_up
jne EnterAnotherKey
PowerUpMyself:
getString 1,19,operation
CALL Check_forbidden
CMP forbiddenCharFound,1
JE ErrorFound
mov determineRegisters,1
CALL ExecuteOperation
CMP hasError,1
JE ErrorFound
sub ScorePlayer1,5
jmp endTurn1
PowerUpBoth:
getString 1,19,operation
CALL Check_forbidden
CMP forbiddenCharFound,1
JE ErrorFound
mov determineRegisters,1
CALL ExecuteOperation
CMP hasError,1
JE ErrorFound
sub ScorePlayer1,3
jmp endTurn1
CALL Check_forbidden
CMP forbiddenCharFound,1
JE ErrorFound
mov determineRegisters,2
CALL ExecuteOperation
CMP hasError,1
JE ErrorFound
jmp endTurn1
ChangeForbiddenChar:
INC noOfForbiddenPlayer1
CMP noOfForbiddenPlayer1,1
JLE ExecuteNoForbiddenPlayer1
JG DontExecuteForbidden
ExecuteNoForbiddenPlayer1:
getString 1,19,newForbidden
;LoadString newForbidden,forbiddenTempChar1,2,2
MOV SI,OFFSET newForbidden
MOV DI,OFFSET forbiddenTempChar1
MOV CX,2
REPE MOVSB
Sub ScorePlayer1,8
JMP No_power_up
DontExecuteForbidden:
JMP No_power_up
ClearAll:
INC noOfClearedRegisters
CMP noOfClearedRegisters,1
JG DontExecuteClearRegisters
mov determineRegisters,1
Call far ptr ClearAllRegisters
mov determineRegisters,2
call far ptr ClearAllRegisters
sub scorePlayer1,30
;Update Gui
jmp No_power_up
DontExecuteClearRegisters:
JMP EnterAnotherKey
ChangeWinValuePowerUp:
;level 2
;change ascii to hex
PowerUpOnOtherRegisters: ; level 2
mov ah,01h
int 16h
mov ah,0h
int 16h
CMP AL,1
je PowerUpMyself
Cmp AL,2
je No_power_up
jne PowerUpOnOtherRegisters
;This is the normal case for the player where his commands are executed on his rival's registers
No_power_up:
getString 0,19,operation
CALL Check_forbidden
CMP forbiddenCharFound,1
JE ErrorFound
mov determineRegisters,2
CALL ExecuteOperation
CMP hasError,1
JE ErrorFound
jmp endTurn1
ErrorFound:
SUB ScorePlayer1,10
mov hasError,0
endTurn1:
call IsWon
mov al,hasWon
CMP al,1
JE Won
mov playerTurn,2
CALL far ptr ResetVars
;Update Gui
;CALL far ptr SendGuiElements
ReceiveChanges:
; CALL far ptr RecieveGuiElements
;Update Gui
call far ptr UpdateGui
Won: ; Give winning screen then Return to main screen
ret
GameFlow endp
;------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------
SendGuiElements proc far
;Set Divisor Latch Access Bit
mov dx,3fbh ; Line Control Register
mov al,10000000b ;Set Divisor Latch Access Bit
out dx,al ;Out it
;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
;0:Access to Receiver buffer, Transmitter buffer
;0:Set Break disabled
;011:Even Parity
;0:One Stop Bit
;11:8bits
out dx,al
;Sending a value
mov cx,42h
mov si, offset axPlayer1
;Check that Transmitter Holding Register is Empty
SendLoop:
mov dx , 3FDH ; Line Status Register
AGAIN: In al , dx ;Read Line Status
and al , 00100000b
JZ AGAIN ;Not empty
;If empty put the VALUE in Transmit data register
mov dx , 3F8H ; Transmit data register
mov al,[si]
inc si
out dx , al
Loop SendLoop
; Put the byte you want to send in location 3f8h
ret
SendGuiElements endp
;------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------
RecieveGuiElements proc far
;Set Divisor Latch Access Bit
mov dx,3fbh ; Line Control Register
mov al,10000000b ;Set Divisor Latch Access Bit
out dx,al ;Out it
;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
;0:Access to Receiver buffer, Transmitter buffer
;0:Set Break disabled
;011:Even Parity
;0:One Stop Bit
;11:8bits
out dx,al
mov cx,46h