forked from Samiha-Sadek/Microprocessor-Simulation-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.asm
More file actions
9009 lines (7056 loc) · 177 KB
/
Main.asm
File metadata and controls
9009 lines (7056 loc) · 177 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
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
.386
include Erase.inc
include ShowR.inc
include WChar.inc
include WName.inc
include WScore.inc
include WMemory.inc
include Str_Hex.inc
include Hex_Str.inc
include BG.inc
include UCL.inc
include DMem.inc
include WReg.inc
include WByte.inc
include WWord.inc
include RByte.inc
include RWord.inc
include WMWord.inc
include RMWord.inc
include ShowCirc.inc
include ShwTrg.inc
include ShwRct.inc
include WBalls.inc
include Scr_Dec.inc
include Scr_Str.inc
include NoOp.inc
include OneOp.inc
include TwoOpF.inc
include TwoOpS.inc
include Regzer.inc
include Regloss.inc
include ChatInv.inc
include GameInv.inc
include ShowL.inc
.model Large
.stack
.data
xxxx db 0
db '0000'
operand2 db 15 DUP('$')
SRCend db '$' ;source terminator
lenSRC db ? ;source length
db '0000'
operand1 db 15 DUP('$')
DESTend db '$' ;destination terminator
lenDEST db ? ;destination length
AddressTypeSRC db 0 ; 1: immediate, 2: Register, 3: Direct, 4: Register Indirect
AddressTypeDEST db 0 ; 1: immediate, 2: Register, 3: Direct, 4: Register Indirect
MemoryTypeSRC db ? ; 1: 8-bits 2: 16-Bits
MemoryTypeDEST db ? ; 1: 8-bits 2: 16-Bits
AddressingMode db ? ; 1: immediate, 2: Register, 3: Direct, 4: Register Indirect
SourceOffset dw ?
DestinationOffset dw ?
ImmediateValue1 dw ?
ImmediateValue2 dw ?
ImmediateValueStr db '$$$$', '$'
Target db '105E' ,'$'
Level db 1
player db 1 ;1 for player 1 and 2 for player 2
DummyPlayerNum db 1
buffer db 16,?
command db 17 dup('$')
CommandList db 'ADD','ADC','SUB','SBB','DIV','MUL','MOV','NOP','INC','DEC','XOR','AND','SHR','SHL','CLC','ROR'
ORCommandstr db 'OR'
spaces db ' ', '$'
opcode db 5 dup('$')
spaces2 db ' ', '$'
dummyyyyy db 0
dummyyyyy2 db 0
dummy dw ?
CommandNo db 1
disp db 41h
disp1 db 0
disp2 db 1
;;;;; Player Names:
buffer2 db 16,?
Name1 db 16 dup('$')
buffer3 db 16,?
Name2 db 16 dup('$')
;;;;; Player Scores:
buffer4 db 4,?
Score1 db 4 dup('$')
buffer5 db 4,?
Score2 db 4 dup('$')
Score1InDec dw ?
Score2InDec dw ?
HexNumbers db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F', '$'
operandsize db 1
SourceMem db 0 ;1 = Source is memory, 0 = source is register
DestMem db 0 ;1 = Dest is memory, 0 = Dest is register
carry1 db 0
carry2 db 0
carry db 0 ;Intermediate carry for both MP
db '000'
VarHexstr1 db '$$$$','$'
db '000'
VarHexstr2 db '$$$$','$'
db '000'
VarHexstr3 db '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$','$'
VarHexNum dw ?
VarHexNum1 dw ?
VarHexNum2 dw ?
;;;;;;;;;;;;;;;;;;;;Promts
Promt1 db 'Enter Your Name: ', '$'
Promt2 db 'Enter Initial Points: ', '$'
Promt3 db 'Press F1 to start chatting ', '$'
Promt4 db 'Press F2 to start the game', '$'
Promt5 db 'Press ESC to Exit', '$'
Promt6 db 'Game Invitation', '$'
Promt7 db 'Chat Invitation', '$'
Promt8 db 'Level', '$'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
col db 0
column1 db 0
row1 db 13
row2 db 1
messageoffset dw ?
message1 db 42 dup('$')
dummystr db 42 dup('$')
displacment1 dw 0
displacment2 dw 0
pagenumber db 0
inputnumber db 0
Inputsize db 0
SentName db 16 dup('$')
ReceivedName db 16 dup('$')
Sending db 0
Receiving db 0
EscapePressed db 0
F1PressedSender db 0
F1PressedReceiver db 0
F2PressedSender db 0
F2PressedReceiver db 0
ChatModuleStart db 0
GameModuleStart db 0
ISentTheInvitation db 0
CurrentPlayer db ?
RegisterOffset dw ?
counter dw 0
RegisterDisp dw 0
SentPoints db 4 dup('$')
REceivedPoints db 4 dup('$')
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; For Testing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
msg db 'Incorrect','$' ;;Temporary
HexNum db 'ABCD','$' ;;Temporary
HexNum2 db '54','$' ;;Temporary
HexNum3 db '122','$' ;;Temporary
HexNum4 db '$$$','$' ;;Temporary
x dw 50
y dw 60
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
col1 db 16, 17
col2 db 36, 37
reg1 db 2,3,4,5
reg2 db 10,11,12,13
reg3 db 22,23,24,25
reg4 db 30,31,32,33
balls1 db 3,5,7,9,11
balls2 db 23,25,27,29,31
;;player1 balls
Ob1 db 0
WGb1 db 0
DGb1 db 0
Bb1 db 0
Gb1 db 0
;;player2 balls
Ob2 db 0
WGb2 db 0
DGb2 db 0
Bb2 db 0
Gb2 db 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Processor1 data
ax1 label byte
ah1 db 30h,30h
al1 db 30h,30h
bx1 label byte
bh1 db 30h,30h
bl1 db 30h,30h
cx1 label byte
ch1 db 30h,30h
cl1 db 30h,30h
dx1 label byte
dh1 db 30h,30h
dl1 db 30h,30h
si1 db 30h,30h,30h,30h
di1 db 30h,30h,30h,30h
sp1 db 30h,30h,30h,30h
bp1 db 30h,30h,30h,30h
mem1 db 32 DUP(30h), 0
;Processor2 data
ax2 label byte
ah2 db 30h,30h
al2 db 30h,30h
bx2 label byte
bh2 db 30h,30h
bl2 db 30h,30h
cx2 label byte
ch2 db 30h,30h
cl2 db 30h,30h
dx2 label byte
dh2 db 30h,30h
dl2 db 30h,30h
; si2 db 30h,30h,30h,30h
si2 db 30h,30h,30h,30h
di2 db 30h,30h,30h,30h
sp2 db 30h,30h,30h,30h
bp2 db 30h,30h,30h,30h
mem2 db 32 DUP(30h), 0
modee db 3 ; 1 for chatting, 2 for minigame , 3 for playing the game
;;;;;;;;;;;;vars to check if a powerup has been used before ;;;;;;;;;;;;;;;
player1PU1 db 0
player1PU2 db 0
player1PU3 db 0
player1PU4 db 0
player1PU15 db 0
player1PU5 db 0
player2PU1 db 0
player2PU2 db 0
player2PU3 db 0
player2PU4 db 0
player2PU15 db 0
player2PU5 db 0
ExecutePowerUp1 db 0 ;0 = Do not execute, 1 = Execute
ExecutePowerUp2 db 0 ;0 = Do not execute, 1 = Execute
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;minigame
p1position dw 80, 170
p2position dw 236, 170
bulltes1 dw 20 dup (0)
bulletsno1 dw 0
bulltes2 dw 20 dup (0)
bulletsno2 dw 0
shapeC dw 20,40
shexist dw 1
ShpClr dw 6 ;can be either 6,7,8,9,10
Trnsnmbr dw 0 ;Current nubmer of turns
TrnsBMG dw 2 ;turns before mingame ;ranges form 2 to 12 ;default is 1
valid2Chk db 1 ; 0 = Invalid, 1 = Valid. if it's invalid, skip the rest of the checks
bufferL db 3,?
LevelStr db 3 dup('$')
PromtL db 'Enter the Level of the Game: ', '$'
ppnn1 db 'Player1:','$'
ppnn2 db 'Player2:','$'
Promtvalax db 'Enter the Value of Ax: ', '$'
Promtvalbx db 'Enter the Value of Bx: ', '$'
Promtvalcx db 'Enter the Value of Cx: ', '$'
Promtvaldx db 'Enter the Value of Dx: ', '$'
Promtvalsi db 'Enter the Value of SI: ', '$'
Promtvaldi db 'Enter the Value of DI: ', '$'
Promtvalbp db 'Enter the Value of SP: ', '$'
Promtvalsp db 'Enter the Value of BP: ', '$'
PromtvalMP db 'Choose which microprocessor: ', '$'
bufferrregs db 6,?
rreggs db 6 dup('$')
buffermmp db 6,?
mmmp db 6 dup('$')
PromtF db 'Enter Forbidden key: ', '$'
bufferF1 db 16,?
ForbiddenChar1 db '$$' ; A variable to store the forbidden char
bufferF2 db 16,?
ForbiddenChar2 db '$$' ; A variable to store the forbidden char
PromtLs1 db 'Player 1 Lost ', '$'
PromtLs2 db 'Player 2 Lost', '$'
;THE VALUE WHICH MAKES THE PLAYER LOSE
Promttarg db 'Enter New target: ', '$'
buffertarg db 16,?
dummytargetlol db '105E' ,'$'
targetlol db '105E' ,'$'
; 8albn el target lazem yefdal 4 7roof, eb2a garab kda
valTarLol db 0 ; Used to make sure the target isn't already in a register
lose1 db 0
lose2 db 0
pplayer db 0 ;placeholder for player while choosing the microprocessor
hasrc db 0 ;0 for not rec, 1 for rec
chr db '$'
commandcol1 db 1
commandcol2 db 22
SentForbChar db 2 dup('$')
ReceivedForbChar db 2 dup('$')
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.code
RecClr proc far
pusha
Reccll: ;Recieve the clr
;Check that Data is Ready
mov dx , 3FDH ; Line Status Register
in al , dx
test al , 1
jz Reccll ;Not Ready
;If Ready read the VALUE in Receive data register
mov dx , 03F8H
in al , dx
cmp al, 6 ; it will be either 1 or 2
je ReccllEnd
cmp al,7
je ReccllEnd
cmp al, 8
je ReccllEnd
cmp al,9
je ReccllEnd
cmp al, 10
je ReccllEnd
jmp Reccll
ReccllEnd:
mov ah,0
mov word ptr ShpClr ,ax
popa
ret
RecClr ENDP
;sends whatever is in bl
;The proc waits for the other side to be free before sending
;we might need a version that doesn't keep checking
sendbayte proc far
pusha
mov dx , 3FDH ; Line Status Register
AGAINsnd: In al , dx ;Read Line Status
test al , 00100000b
JZ AGAINsnd ;Not empty
;If empty put the VALUE in Transmit data register
mov dx , 3F8H ; Transmit data register
;7ot el value beta3 el byte ely 3ayez teb3atha fil al
mov al,bl
out dx , al
popa
ret
sendbayte ENDP
;recieves in a variable called chr
; if not recieved, hasrc will be 0
recbayte proc far
pusha
mov dx , 3FDH ; Line Status Register
CHKrr: in al , dx
test al , 1
JZ skrec ;Not Ready
;If Ready read the VALUE in Receive data register
mov hasrc,1
mov dx , 03F8H
in al , dx
mov chr,al
jmp endrc
skrec:
mov hasrc,0
endrc:
popa
ret
recbayte ENDP
rndfreq proc
;randomize the freq of shooter
push ax
push cx
mov ah,00h
int 1Ah ; CX:DX now hold number of clock ticks since midnight
mov ax,dx
mov cx,11
mov dx,0
div cx ;dx contains the remainder
pop ax
pop cx
push bx
push di
lea bx, TrnsBMG
mov di,[bx] ;di has the value
add di, dx
mov [bx],di
pop bx
pop di
ret
rndfreq ENDP
axchk proc far
cmp ax,0
jl axisneg
jnl axispos
axisneg:
mov bx,-1
push dx
mul bx
pop dx
axispos:
ret
axchk ENDP
wtFrVR proc far
;wait for VR
pusha
mov dx, 3dah
;Wait for bit 3 to be zero (not in VR).
;We want to detect a 0->1 transition.
waitForEnd:
in al, dx
test al, 08h
jnz waitForEnd
;Wait for bit 3 to be one (in VR)
waitForNew:
in al, dx
test al, 08h
jz waitForNew
popa
ret
wtFrVR ENDP
rndclr proc far
;randomize the colour of the object
pusha
mov ah,00h
int 1Ah ; CX:DX now hold number of clock ticks since midnight
mov ax,dx
mov cx,5
mov dx,0
div cx ;dx contains the remainder
lea bx, ShpClr
mov di,[bx] ;di has the value
add di, dx
mov [bx],di
mov al, CurrentPlayer
cmp player, al
jne Receiveclr
sndclr:
mov bx, word ptr ShpClr
call sendbayte
jmp rcend
Receiveclr:
call RecClr ; will keep looping
rcend:
popa
ret
rndclr ENDP
FinBul1 proc far
;move bullets1
pusha
lea bx, bulltes1 ;for comparison
sub bx,2 ;just for checking
; mov cx ,ax
lea cx, bulltes1
add cx,40
; loop over all the bullets and move them too
sub cx,2 ;because we need the y of the bullet not the x of next bullet
finbults1:
mov di,cx
mov di, [di]
sub cx,2
mov si, cx
mov si, [si]
;moving the bullet
ShowRect si,di,2,2,0 ;show black square
mov si,0
push bx
mov bx,cx
add bx,2
mov [bx],si
sub bx,2
mov [bx],si
pop bx
sub cx,2
cmp cx,bx
jnz finbults1
mov bulletsno1,0
popa
ret
FinBul1 ENDP
FinBul2 proc far
;move bullets2
pusha
lea bx, bulltes2 ;for comparison
sub bx,2 ;just for checking
; mov cx ,ax
lea cx, bulltes2
add cx,40
; loop over all the bullets and move them too
sub cx,2 ;because we need the y of the bullet not the x of next bullet
finbults2:
mov di,cx
mov di, [di]
sub cx,2
mov si, cx
mov si, [si]
;moving the bullet
ShowRect si,di,2,2,0 ;show black square
mov si,0
push bx
mov bx,cx
add bx,2
mov [bx],si
sub bx,2
mov [bx],si
pop bx
sub cx,2
cmp cx,bx
jnz finbults2
mov bulletsno2,0
popa
ret
FinBul2 ENDP
chkCol1 proc far
;check colided
pusha
;di,si are the bullets coordinates
lea bx, shexist
mov ax, 0
mov bx,[bx]
cmp ax,bx
; jz far ptr skchk1
jnz sj1
jmp skchk1
sj1: ;skip jump1
mov ax,si
mov bx,di
lea di, shapeC
mov si, [di]
add di,2
mov di, [di]
;check on y
add di,5
cmp bx,di
; jg skchk1 ;jump greater
jbe sj2
jmp skchk1
sj2:
sub di,10
cmp bx, di
; jb skchk1 ;jump below
jge sj3
jmp skchk1
sj3:
add di,5 ;back to original value
;check on x
add si,5
cmp ax,si
; jg skchk1
jbe sj4
jmp skchk1
sj4:
sub si,10
cmp ax, si
; jb skchk1 ;jump below
jge sj5
jmp skchk1
sj5:
;;;;;;;;;;;;;;;;;;;;;;;;;Collided;;;;;;;
add si,5 ;back to original value
ShowCirc si,di,5,0 ;draw a black circle
;for now
add si,158
ShowCirc si,di,5,0 ;draw a black circle
;now we set the shape to not exist
call FinBul1
call FinBul2
lea di, shexist
mov si,0
mov [di],si
;send to the other side that the player1 collided
push bx
mov bl,10 ; 10 is for p1 winning the minigame
call sendbayte
pop bx
mov si, ShpClr
sub si,5
add Score1InDec,si
ScoreToString Score1, Score1InDec
add si,5
;update the number of balls
;6,7,8,9,10
cmp si,6
jz addOr1
cmp si,7
jz addWG1
cmp si,8
jz addDG1
cmp si,9
jz addB1
jmp addG1
addOr1:
add Ob1,1
jmp skAB
addWG1:
add WGb1,1
jmp skAB
addDG1:
add DGb1,1
jmp skAB
addB1:
add Bb1,1
jmp skAB
addG1:
add Gb1,1
skAB:
mov ShpClr,6
mov modee,3 ;back to playing the main game
mov TrnsBMG, 2 ;default number
mov Trnsnmbr,0
CALL rndfreq ;pick a random number of turns before starting the minigame
skchk1: ;skip check
popa
ret
chkCol1 ENDP
chkCol2 proc far
pusha
;di,si are the bullets coordinates
lea bx, shexist
mov ax, 0
mov bx,[bx]
cmp ax,bx
; jz skchk2
jnz skj6
jmp skchk2
skj6:
mov ax,si
mov bx,di
lea di, shapeC
mov si, [di]
add di,2
mov di, [di]
;check on y
add di,5
cmp bx,di
; jg skchk2
jbe skj7
jmp skchk2
skj7:
sub di,10
cmp bx, di
; jb skchk2 ;jump below
jge skj8
jmp skchk2
skj8:
add di,5 ;back to original value
;check on x
add si,5
add si, 158 ; for player 2 side
cmp ax,si
; jg skchk2
jbe skj9
jmp skchk2
skj9:
sub si,10
cmp ax, si
; jb skchk2 ;jump below
jge skjA
jmp skchk2
skjA:
;;;;;;;;;;;;;;;;;;;;;;;;;;;Collided
add si,5 ;back to original value
ShowCirc si,di,5,0 ;draw a black circle
;for now
sub si,158
ShowCirc si,di,5,0 ;draw a black circle
;we need to finish the bullets
call FinBul1
call FinBul2
;now we set the shape to not exist
lea di, shexist
mov si,0
mov [di],si
;send to the other side that the player2 collided
push bx
mov bl,11 ; 11 is for p2 winning the minigame
call sendbayte
pop bx
mov si, ShpClr
sub si,5
add Score2InDec,si
ScoreToString Score2, Score2InDec
add si,5
;update the number of balls
;6,7,8,9,10
cmp si,6
jz addOr2