-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.asm
More file actions
7617 lines (6574 loc) · 167 KB
/
Copy pathMain.asm
File metadata and controls
7617 lines (6574 loc) · 167 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
;-----------بِسْمِ اللَّـهِ الرَّحْمَـٰنِ الرَّحِيمِ------------;
;-----------------MACROS-----------------
;-------------------Serial Port Macros-------------------
;----Initializes serial port with a certian configuration---
SerialPort MACRO
;Set divisor latch access bit
MOV DX, ADDRESS+3 ;Line control register
MOV AL, 10000000b
OUT DX, AL
;Set the least significant byte of the Baud rate divisor latch register
MOV DX, ADDRESS
MOV AL, 0CH
OUT DX, AL
;Set the most significant byte of the Baud rate divisor latch register
MOV DX, ADDRESS+1
MOV AL, 0
OUT DX, AL
;Set serial port configurations
MOV DX, ADDRESS+3 ;Line Control Register
MOV AL, 00011011B
;0: Access to receiver and transmitter buffers
;0: Set break disabled
;011: Even parity
;0: One stop bit
;11: 8-bit word length
OUT DX, AL
ENDM SerialPort
;-------Send character serial port-------
SendCharSerial MACRO char
LOCAL Send
Send:
MOV DX, ADDRESS+5 ;Line Status Register
IN AL, DX
AND AL, 00100000B ;Check transmitter holding register status: 1 ready, 0 otherwise
JZ Send ;Transmitter is not ready
MOV DX, ADDRESS
MOV AL, char
OUT DX, AL
ENDM SendCharSerial
;------Receive a character from the serial port into AL----
ReceiveCharSerial MACRO
LOCAL ending
MOV AL, 0
MOV DX, ADDRESS+5 ;Line Status Register
IN AL, DX
AND AL, 00000001B ;Check for data ready
JZ ending ;No character received
MOV DX, ADDRESS ;Receive data register
IN AL, DX
ending:
ENDM ReceiveCharSerial
;--------Print Character in Serial-------
PrintCharSerial MACRO char
MOV AH, 02H
MOV DL, char
INT 21H
ENDM PrintCharSerial
;--------Empty buffer in Serial----------
EmptyBuffer MACRO
LOCAL Back, Return
Back:
GetKeyNoWaitSerial
JZ Return
GetKeyWaitSerial
JMP Back
Return:
ENDM EmptyBuffer
;--------Get key wait for serial---------
GetKeyWaitSerial MACRO
MOV AH, 00H
INT 16H
endm GetKeyWaitSerial
;-------Get key no wait for serial-------
GetKeyNoWaitSerial MACRO
MOV AH, 01H
INT 16H
endm GetKeyNoWaitSerial
;--------Flush keys pressed serial-------
FlushPressedSerial MACRO
LOCAL NoKeyPressed
GetKeyNoWaitSerial
jz NoKeyPressed
GetKeyWaitSerial
NoKeyPressed:
ENDM FlushPressedSerial
;--------InLineChat------------
InLineChat macro
Local CursorLoop1,SendingChat1,Khalas1,ReceivingChat1
pusha
mov User1InCursorX, 8
mov User2InCursorX, 8
mov User1InCursorY,23
mov User2InCursorY,24
mov end_chat,0
CursorLoop1:
SetCursor User1InCursorX,User1InCursorY,0
SendingChat1:
FlushPressedSerial
JZ ReceivingChat1
mov SentCharChat, AL
SendCharSerial SentCharChat
CheckInputCharSerialInLine SentCharChat, User1InCursorX, User1InCursorY, 23
cmp OK,1
je ReceivingChat1
cmp end_chat, 1
je Khalas1
ReceivingChat1:
ReceiveCharSerial
jz CursorLoop1
mov ReceivedCharChat, AL
CheckInputCharSerialInLine ReceivedCharChat, User2InCursorX, User2InCursorY, 24
cmp end_chat, 1
jne CursorLoop1
Khalas1:
mov end_chat,0
popa
endm InLineChat
;--------Checking Input Character--------
; StartY for sending is WindowStart
; StartY for receiving is ChatHeight
CheckInputCharSerial MACRO char, x, y, StartY
LOCAL Checking_Enter, Check_Scroll, Checking_BS, Checking_Printable, Modifying_Cursor, ending_check_char
CMP char, ESCAsciiCode
JNE Checking_Enter
MOV end_chat, 1
jmp ending_check_char
Checking_Enter:
cmp char, 0DH ;enter ascii
jne Checking_BS
mov x, WindowStart+4
inc y
jmp Check_Scroll
Checking_BS:
cmp char, 8 ;backspace ascii
jne Checking_Printable
cmp x, WindowStart
jbe Checking_Printable
mov char, ' '
dec x
SetCursor x,y,0
PrintCharSerial char
jmp ReceivingChat
Checking_Printable: ;printing character if printable
cmp char, ' '
jb ReceivingChat
cmp char, '~'
ja ReceivingChat
SetCursor x,y,0
PrintCharSerial char
Modifying_Cursor:
inc x
cmp x, ChatLength - 1
jb ending_check_char
mov x, WindowStart
inc y
Check_Scroll:
cmp y, ChatHeight+StartY-1
jbe ending_check_char
dec y
Scroll WindowStart,StartY+2,WindowEndX,y,00h,1
ending_check_char:
endm CheckInputCharSerial
;--------Checking Input Character--------
; StartY for sending is WindowStart
; StartY for receiving is ChatHeight
CheckInputCharSerialInLine MACRO char, x, y, StartY
LOCAL Checking_Enter, Check_Scroll, Checking_BS, Checking_Printable, Modifying_Cursor, ending_check_char,Set_OK_In_Line
mov OK,0
CMP char, ESCAsciiCode
JNE Checking_Enter
MOV end_chat, 1
jmp ending_check_char
Checking_Enter:
cmp char, 0DH ;enter ascii
jne Checking_BS
mov x, 8
jmp Check_Scroll
Checking_BS:
cmp char, 8 ;backspace ascii
jne Checking_Printable
cmp x, 8
jbe Checking_Printable
mov char, ' '
dec x
SetCursor x,y,0
PrintCharSerial char
jmp Set_OK_In_Line
Checking_Printable: ;printing character if printable
cmp char, ' '
jb Set_OK_In_Line
cmp char, '~'
ja Set_OK_In_Line
SetCursor x,y,0
PrintCharSerial char
Modifying_Cursor:
inc x
cmp x, 39
jb ending_check_char
mov x, 8
; inc y
Check_Scroll:
ClearScreenGraphics 8,StartY,WindowEndX,y,black
Set_OK_In_Line:
mov OK,1
ending_check_char:
endm CheckInputCharSerialInLine
;--------Checking Input for Main Screen from My Side--------
MainCheckInputSerialFromMe MACRO char
LOCAL Checking_Game_Me, start_chatting_me, Checking_Exit, start_game_me, undefined_main, ending_check_main_me
;Check if chatting
CMP char, F1Scancode
JNE Checking_Game_Me
mov ChatInvitationSent,1
cmp ChatInvitationRec,1
je start_chatting_me
jmp ending_check_main_me
start_chatting_me:
call ChatWindow
jmp ending_check_main_me
;Check if start game pressed
Checking_Game_Me:
cmp char, F2Scancode ;enter ascii
jne Checking_Exit
mov GameInvitationSent,1
cmp GameInvitationRec,1
je start_game_me
jmp ending_check_main_me
start_game_me:
mov IamSlave, 1
changeGraphicsmode
call GameScreen
jmp ending_check_main_me
Checking_Exit:
cmp char, 1
jnz undefined_main
jmp ending_check_main_me
undefined_main:
SetCursor 0, 21, 0
PrintMessage undefinedMsg
ending_check_main_me:
endm MainCheckInputSerialFromMe
;--------Checking Input for Main Screen from My Side--------
MainCheckInputSerialFromYou MACRO char
LOCAL Checking_Game_You, start_chatting_you, Checking_Exit_2, start_game_you, undefined_main2, ending_check_main_you, GoGame
;Check if chatting
CMP char, F1Scancode
JNE Checking_Game_You
mov ChatInvitationRec,1
cmp ChatInvitationSent,1
je start_chatting_you
jmp ending_check_main_you
start_chatting_you:
call ChatWindow
jmp ending_check_main_you
;Check if start game pressed
Checking_Game_You:
cmp char, F2Scancode ;enter ascii
jne Checking_Exit_2
mov GameInvitationRec,1
cmp GameInvitationSent,1
je start_game_you
jmp ending_check_main_you
start_game_you:
mov IamSlave, 0
call LevelScreen
cmp LevelVariable+2,'1'
je GoGame
;call InputRegistersScreen
GoGame:
changeGraphicsmode
call GameScreen
jmp ending_check_main_you
Checking_Exit_2:
cmp char, 1
jnz undefined_main2
jmp ending_check_main_you
undefined_main2:
SetCursor 0, 21, 0
PrintMessage undefinedMsg
ending_check_main_you:
endm MainCheckInputSerialFromYou
;------Set Level According to Player-------
GetLevel macro
LOCAL ReceiveLevel, ending_get_level
cmp IamSlave,0
jne ReceiveLevel
SendCharSerial LevelVariable+2
jmp ending_get_level
ReceiveLevel:
FlushPressedSerial
ReceiveCharSerial
JZ ReceiveLevel
mov LevelVariable+2,AL
cmp LevelVariable+2 , '2'
jne ending_get_level
;call InputRegistersScreen
ending_get_level:
endm GetLevel
;-------Debug------
Debug macro charDebug
SetCursor 10,10,0
PrintCharGraphics charDebug, White,1
endm Debug
;-------Copy the string with unknown size-------
CopyStringDollar macro string1,string2
local myLoop, ending_compare_string
pusha
mov si, 0
mov di, 0
myLoop:
mov al, string1[si]
cmp string1[si],'$'
je ending_compare_string
mov string2[di], al
inc si
inc di
dec cx
cmp cx, 0
jnz myLoop
ending_compare_string:
popa
endm EmptyTheString
;-------Copy the string with size 4-------
CopyString macro string1,string2
local myLoop
pusha
mov si, 2
mov di, 0
mov cl,4
mov ch,0
myLoop:
mov al, string1[si]
mov string2[di], al
inc si
inc di
dec cx
cmp cx, 0
jnz myLoop
popa
endm EmptyTheString
;-------Empty the string-------
EmptyTheString macro string2,size
local myLoop
pusha
mov si, offset string2
mov cl,size
mov ch,0
myLoop:
mov [si], '$'
inc si
dec cx
cmp cx, 0
jnz myLoop
popa
endm EmptyTheString
;------PUT ZERO IN ALL REGISTERS--------------
;------FOR START GAME AND POWER UP------------
;------0 for all registers and data segment---
;------1 for user 1 registers-----------------
;------2 for user 2 registers-----------------
ZeroALL macro user
LOCAL user_2_zeroing,user_1_zeroing,ending_zeroall
pusha
mov al,user
cmp al,2
je user_2_zeroing
cmp al,1
je user_1_zeroing
MoveString2Bytes ZerosMSG,DS00_Value1
MoveString2Bytes ZerosMSG,DS00_Value2
MoveString2Bytes ZerosMSG,DS01_Value1
MoveString2Bytes ZerosMSG,DS01_Value2
MoveString2Bytes ZerosMSG,DS02_Value1
MoveString2Bytes ZerosMSG,DS02_Value2
MoveString2Bytes ZerosMSG,DS03_Value1
MoveString2Bytes ZerosMSG,DS03_Value2
MoveString2Bytes ZerosMSG,DS04_Value1
MoveString2Bytes ZerosMSG,DS04_Value2
user_1_zeroing:
MoveString4Bytes ZerosMSG,AX_Reg_Value1
UpdateSmallReg AX_Reg_Value1,AH_Reg_Value1,AL_Reg_Value1
MoveString4Bytes ZerosMSG,BX_Reg_Value1
UpdateSmallReg BX_Reg_Value1,BH_Reg_Value1,BL_Reg_Value1
MoveString4Bytes ZerosMSG,CX_Reg_Value1
UpdateSmallReg CX_Reg_Value1,CH_Reg_Value1,CL_Reg_Value1
MoveString4Bytes ZerosMSG,DX_Reg_Value1
UpdateSmallReg DX_Reg_Value1,DH_Reg_Value1,DL_Reg_Value1
MoveString4Bytes ZerosMSG,SI_Reg_Value1
MoveString4Bytes ZerosMSG,DI_Reg_Value1
MoveString4Bytes ZerosMSG,BP_Reg_Value1
MoveString4Bytes ZerosMSG,SP_Reg_Value1
cmp al, 1
je ending_zeroall
user_2_zeroing:
MoveString4Bytes ZerosMSG,AX_Reg_Value2
UpdateSmallReg AX_Reg_Value2,AH_Reg_Value2,AL_Reg_Value2
MoveString4Bytes ZerosMSG,BX_Reg_Value2
UpdateSmallReg BX_Reg_Value2,BH_Reg_Value2,BL_Reg_Value2
MoveString4Bytes ZerosMSG,CX_Reg_Value2
UpdateSmallReg CX_Reg_Value2,CH_Reg_Value2,CL_Reg_Value2
MoveString4Bytes ZerosMSG,DX_Reg_Value2
UpdateSmallReg DX_Reg_Value2,DH_Reg_Value2,DL_Reg_Value2
MoveString4Bytes ZerosMSG,SI_Reg_Value2
MoveString4Bytes ZerosMSG,DI_Reg_Value2
MoveString4Bytes ZerosMSG,BP_Reg_Value2
MoveString4Bytes ZerosMSG,SP_Reg_Value2
ending_zeroall:
popa
endm ZeroALL
;--Check Data Bus Stuck From PowerUp 4--
;---------Called each time--------------
CheckDataBus Macro CurrOperandCheckStuck
LOCAL stuck_at_zero,check_type_zero,stuck_zero_big,stuck_at_one,check_type_one,stuck_one_big,ending_checkdatabus
pusha
cmp Power4Chosen,1
jne ending_checkdatabus
cmp StuckValue,'0'
jne stuck_at_one
stuck_at_zero:
cmp DataLineValue,8
jae check_type_zero
mov bx,0
mov dx,1
mov cl,DataLineValue
mov ch,0
shl dx,cl
or bx,dx
not bx
and CurrOperandCheckStuck,bx
jmp ending_checkdatabus
check_type_zero:
cmp Operand2Type,2
je stuck_zero_big
cmp Operand2Type,5
je stuck_zero_big
jmp ending_checkdatabus
stuck_zero_big:
mov bx,0
mov dx,1
mov cl,DataLineValue
mov ch,0
shl dx,cl
or bx,dx
not bx
and CurrOperandCheckStuck,bx
jmp ending_checkdatabus
stuck_at_one:
cmp DataLineValue,8
jae check_type_one
mov bx,0
mov dx,1
mov cl,DataLineValue
mov ch,0
shl dx,cl
or bx,dx
or CurrOperandCheckStuck,bx
jmp ending_checkdatabus
check_type_one:
cmp Operand2Type,2
je stuck_one_big
cmp Operand2Type,5
je stuck_one_big
jmp ending_checkdatabus
stuck_one_big:
mov bx,0
mov dx,1
mov cl,DataLineValue
mov ch,0
shl dx,cl
or bx,dx
not bx
or bx,cx
or CurrOperandCheckStuck,bx
jmp ending_checkdatabus
ending_checkdatabus:
mov Power4Chosen,0
popa
endm CheckDataBus
;-------Changing to graphics mode-------
changeGraphicsmode Macro
mov ah,0
mov al,13h
int 10h
endm changeGraphicsmode
;-------Changing to text mode-------
changeTextmode Macro
mov ah,0
mov al,3
int 10h
endm changeTextmode
;-------Clear Screen-------
ClearScreen MACRO x1,y1,x2,y2,Color
mov ax,0600h
mov bh,07
mov cl,x1
mov ch,y1
mov dl,x2
mov dh,y2
int 10h
endm ClearScreen
;-------Clear Screen Graphics-------
ClearScreenGraphics MACRO x1,y1,x2,y2,Color
mov ax,0600h
mov bh,color
mov cl,x1
mov ch,y1
mov dl,x2
mov dh,y2
int 10h
endm ClearScreenGraphics
;-------Set cursor-------
SetCursor MACRO x,y,PageNO
pusha
mov ah,2
mov dl,x
mov dh,y
mov bh,PageNO
int 10h
popa
endm SetCursor
;-------Print Character-------
PrintChar MACRO Type,Color,Len,PageNO
mov ah,9
mov bh,PageNO
mov al,Type
mov cx,Len
mov bl,Color
int 10h
endm PrintChar
;-------Print Character in graphics mode-------
PrintCharGraphics MACRO char,color,times
mov al,char
mov ah,09h
mov bh,0
mov bl,color
mov cx,times
int 10h
ENDM PrintCharGraphics
;-------Draw MACRO-------
DrawLine MACRO x,y,HorLen,VerLen,Color,PageNO,Type
SetCursor x,y,PageNO
PrintChar Type,Color,HorLen,PageNO
endm DrawLine
;-------Print a message on the screen-------
PrintMessage MACRO MyMessage
pusha
mov AH,9h
mov bl,Purple
lea DX,MyMessage
int 21h
popa
ENDM PrintMessage
;-------Status Chat-------
StatusChat MACRO msg1
DrawLine WindowStart,WindowEndY-2,WindowEndX,0,03h,0,'-'
SetCursor WindowStart,WindowEndY-1,0
PrintMessage msg1
endm StatusChat
;-------Show Mouse-------
ShowMouse MACRO
mov ax,1
int 33h
endm ShowMouse
;-------Get Cursor position-------
GetCursorPos MACRO x,y,stat
mov si,200
mov ax,3
mPos:int 33h
cmp bx,0
jnz TheEnd
dec si
jnz mPos
jmp TheEnd2
TheEnd:
mov x,cx
mov y,dx
mov stat,bx
TheEnd2:
mov stat,0
endm GetCursorPos
;-------Get key no wait-------
GetKeyNoWait MACRO SC
mov al,0
mov ah,1
int 16h
cmp al,0
jz EndKeyNoWait
mov SC,ah
mov ah,7
int 21h
EndKeyNoWait:
endm GetKeyNoWait
;-------Get key wait-------
GetKeyWait MACRO sc,char
mov ah,0
int 16h
mov sc,ah
mov char,al
endm GetKeyWait
;-------Compare Strings-------
CompareStrings MACRO cmd1,cmd2,size,ok
LOCAL endinggg,true
pusha
mov ok,0
mov cx,size
lea si,cmd1
lea di,cmd2
REPE CMPSB
cmp cx,0
je true
mov ok,0
jmp endinggg
true:
mov ok,1
endinggg:
popa
endm CompareStrings
;-------Check Empty String-------
isEmptyString MACRO msg,ok
LOCAL is_empty,is_empty_end
mov ok,0
cmp msg[0],'$'
je is_empty
mov ok,0
jmp is_empty_end
is_empty:
mov ok,1
is_empty_end:
endm isEmptyString
;-------Check String Size-------
GetStringSize MACRO msg,size
LOCAL find_string_size
pusha
mov si,0
find_string_size:
inc si
cmp msg[si-1],'$'
jne find_string_size
dec si
mov size,si
popa
endm GetStringSize
;-------MOVE STRING 2 BYTES-------
MoveString2Bytes Macro source,dest
pusha
mov al, source[0]
mov dest[0], al
mov al, source[1]
mov dest[1], al
popa
endm MoveString2Bytes
;-------MOVE STRING 4 BYTES-------
MoveString4Bytes Macro source,dest
pusha
mov al, source[0]
mov dest[0], al
mov al, source[1]
mov dest[1], al
mov al, source[2]
mov dest[2], al
mov al, source[3]
mov dest[3], al
popa
endm MoveString4Bytes
;-------Update small registers-------
; When a 16-bit register is updated, it updates
; the value of its two equivalent 8-bit ones
UpdateSmallReg Macro regX, regH, regL
pusha
mov al, regX[0]
mov regH[0], al
mov al, regX[1]
mov regH[1], al
mov al, regX[2]
mov regL[0], al
mov al, regX[3]
mov regL[1], al
popa
endm UpdateSmallReg
;-------Update big registers-------
; When an lower 8-bit register is updated, it updates
; the value of its corresponding 16-bit one (Al -> AX)
UpdateBigRegL Macro regX, regL
pusha
mov al, regL[0]
mov regX[2], al
mov al, regL[1]
mov regX[3], al
popa
endm UpdateBigRegL
;-------Update big registers-------
; When an upper 8-bit register is updated, it updates
; the value of its corresponding 16-bit one (AH -> AX)
UpdateBigRegH Macro regX, regH
pusha
mov al, regH[0]
mov regX[0], al
mov al, regH[1]
mov regX[1], al
popa
endm UpdateBigRegH
;-------Check if Operand is Immediate-------
CheckImmediate MACRO Operand,OK
LOCAL check_all_dig,check_letter,end,cont
pusha
mov OK,0
GetStringSize Operand,OperandLength
mov si,0
cmp OperandLength,4
ja end ; no immediate has more than 4 bytes
check_all_dig:
cmp Operand[si],'0'
jb end
cmp Operand[si],'9'
ja check_letter
jmp cont
check_letter:
cmp Operand[si],'a'
jb end
cmp Operand[si],'f'
ja end
cont:
inc si
cmp si,OperandLength
jb check_all_dig
mov OK,1
end:
popa
endm CheckImmediate
;-------Convert from Ascii (decimal) to number-------
AsciiToNumberDecimal MACRO current,answer
LOCAL looping,rest,setSize
pusha
GetStringSize current,StringSize
mov si,StringSize
mov bx,0
mov cx,1
looping:
mov ah,0
mov al,current[si-1]
sub al,30h
rest:
mul cx
add bx,ax
mov dx,10
mov ax,cx
mul dx
mov cx,ax
dec si
cmp si,0
ja looping
mov answer,bx
popa
endm AsciiToNumberDecimal
;-------Convert from Ascii (hexa) to number-------
; If u know the size send it in "val"
; if not send 0 in val & it automatically calculates size
AsciiToNumber MACRO current,val,answer
LOCAL looping,rest,setSize
pusha
mov ax,val
cmp ax,2
je setSize
GetStringSize current,StringSize
mov si,StringSize
mov bx,0
mov cx,1
jmp looping
setSize:
mov bx,0
mov cx,1
mov si, 2
looping:
mov ah,0
mov al,current[si-1]
sub al,30h
cmp current[si-1],'A'
jb rest
sub al,7h
cmp current[si-1],'a'
jb rest
sub al,20h
rest:
mul cx
add bx,ax
mov dx,16
mov ax,cx
mul dx
mov cx,ax
dec si
cmp si,0
ja looping
mov answer,bx
popa
endm AsciiToNumber
;-------Convert from 4-byte Number to Ascii-------
NumbertoAscii4byte MACRO current,answer
LOCAL looping,rest,rest2
pusha
mov si,0
mov bx,0
mov cx,1000h
looping:
mov ax,current
mov dx,0
div cx
mov current,dx
mov ah,0
cmp ax,0Ah
jb rest2
add ax,37h
jmp rest
rest2:
add ax,30h
rest:
shr cx,4
mov answer[si],al
inc si
cmp si,4
jb looping
popa
endm NumbertoAscii4byte
;-------Convert from 2-byte Number to Ascii--------
NumbertoAscii2byte MACRO current,answer
LOCAL looping,rest,rest2
pusha
mov si,0
mov bx,0
mov cl,10h
looping:
mov al,byte ptr current