forked from redcode/SpecEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx86gen.asm
1094 lines (874 loc) · 69.9 KB
/
x86gen.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
.data?
align 16
PageTableList ListHeader <>
PageTableNode struct
Node ListNode <>
PageTableNode ends
AllocPageTable PROTO :DWORD
FreePageTable PROTO :DWORD
.code
x86_dereferencemem macro
.if argbracketed
; mov bx,ax
invoke x86_WriteByte, 066h
invoke x86_WriteWord, 0d88bh
.if argisword
; call [GetMemWord]
x86_memcpy addr call_MemGetWord, CALL_MEMGETWORD_SIZEOF
.else
; call [GetMemByte]
x86_memcpy addr call_MemGetByte, CALL_MEMGETBYTE_SIZEOF
.endif
.endif
endm
x86_getregister macro @reg:req
local @asize
@asize = @GETARGSIZE (@reg)
if @asize eq 1
; movzx eax, byte ptr @reg
invoke x86_WriteByte, 0fh
invoke x86_WriteWord, 05b6h
invoke x86_WriteDWord, addr @reg
elseif @asize eq 2
; movzx eax, word ptr @reg
invoke x86_WriteByte, 0fh
invoke x86_WriteWord, 05b7h
invoke x86_WriteDWord, addr @reg
else
.err <Invalid sized argument for x86_getregister>
endif
x86_dereferencemem
endm
align 16
farcall macro @target:req
call [_jp_&@target&]
endm
call_MemGetByte: farcall MemGetByte
and ax, 255
CALL_MEMGETBYTE_SIZEOF equ $ - call_MemGetByte
call_MemGetWord: farcall MemGetWord
CALL_MEMGETWORD_SIZEOF equ $ - call_MemGetWord
call_GetBankAtAddr: push eax
farcall GetBankAtAddr
CALL_GETBANKATADDR_SIZEOF equ $ - call_GetBankAtAddr
call_GetBankConfig: farcall GetBankConfig
CALL_GETBANKCONFIG_SIZEOF equ $ - call_GetBankConfig
.const
align 16
_jp_MemGetByte dd MemGetByte
_jp_MemGetWord dd MemGetWord
_jp_GetBankAtAddr dd GetBankAtAddr
_jp_GetBankConfig dd GetBankConfig
_jp_GetByte dd GetByte
_jp_Op7E dd Op7E
_jp_Op12 dd Op12
_jp_Op23 dd Op23
_jp_Op13 dd Op13
.code
; *****************************************************************
; turn on indirect addressing here
USEESI 1
; *****************************************************************
; memory-related
x86get_memreadaddr: .if Reg_MemoryReadEvent == MEMACCESSNONE
jmp [Reg_x86_jmpexitaddr]
.endif
movzx eax, Reg_MemoryReadAddress
X86GET_MEMREADADDR_SIZEOF = $ - x86get_memreadaddr
x86get_memreadval: .if Reg_MemoryReadEvent == MEMACCESSNONE
jmp [Reg_x86_jmpexitaddr]
.endif
movzx eax, Reg_MemoryReadValueLo
X86GET_MEMREADVAL_SIZEOF = $ - x86get_memreadval
x86get_memwriteaddr: .if Reg_MemoryWriteEvent == MEMACCESSNONE
jmp [Reg_x86_jmpexitaddr]
.endif
movzx eax, Reg_MemoryWriteAddress
X86GET_MEMWRITEADDR_SIZEOF = $ - x86get_memwriteaddr
x86get_memwriteval: .if Reg_MemoryWriteEvent == MEMACCESSNONE
jmp [Reg_x86_jmpexitaddr]
.endif
movzx eax, Reg_MemoryWriteValueLo
X86GET_MEMWRITEVAL_SIZEOF = $ - x86get_memwriteval
; =====================================================================
; this does the "=" test for MRA
; ==============================
x86test_memreadaddr: cmp ax, cx
x86test_mra_jmp1: je @F ; correct jcc gets switched
cmp Reg_WordLengthAccess, TRUE
retcc ne
xor edx, edx
test eax, BRKFLAGF_MRA
setnz dl
add ax, dx
test ecx, BRKFLAGF_MRA
setnz dl
add cx, dx
cmp ax, cx
x86test_mra_jmp2: je @F ; correct jcc gets switched
ret
@@:
X86TEST_MEMREADADDR_SIZEOF = $ - x86test_memreadaddr
x86test_mra_offset_jmp1 = x86test_mra_jmp1 - x86test_memreadaddr
x86test_mra_offset_jmp2 = x86test_mra_jmp2 - x86test_memreadaddr
; =====================================================================
; this does the "=" test for MWA
; ==============================
x86test_memwriteaddr: cmp ax, cx
x86test_mwa_jmp1: je @F ; correct jcc gets switched
cmp Reg_WordLengthAccess, TRUE
retcc ne
xor edx, edx
test eax, BRKFLAGF_MWA
setnz dl
add ax, dx
test ecx, BRKFLAGF_MWA
setnz dl
add cx, dx
cmp ax, cx
x86test_mwa_jmp2: je @F ; correct jcc gets switched
ret
@@:
X86TEST_MEMWRITEADDR_SIZEOF = $ - x86test_memwriteaddr
x86test_mwa_offset_jmp1 = x86test_mwa_jmp1 - x86test_memwriteaddr
x86test_mwa_offset_jmp2 = x86test_mwa_jmp2 - x86test_memwriteaddr
; =====================================================================
; port-related
x86get_portreadaddr: .if PortAccessType != PORT_READ
jmp [Reg_x86_jmpexitaddr]
.endif
movzx eax, PortReadAddress
X86GET_PORTREADADDR_SIZEOF = $ - x86get_portreadaddr
x86get_portreadval: .if PortAccessType != PORT_READ
jmp [Reg_x86_jmpexitaddr]
.endif
movzx eax, PortReadByte
X86GET_PORTREADVAL_SIZEOF = $ - x86get_portreadval
x86get_portwriteaddr: .if PortAccessType != PORT_WRITE
jmp [Reg_x86_jmpexitaddr]
.endif
movzx eax, PortWriteAddress
X86GET_PORTWRITEADDR_SIZEOF = $ - x86get_portwriteaddr
x86get_portwriteval: .if PortAccessType != PORT_WRITE
jmp [Reg_x86_jmpexitaddr]
.endif
movzx eax, PortWriteByte
X86GET_PORTWRITEVAL_SIZEOF = $ - x86get_portwriteval
x86get_tstatecount: mov eax, totaltstates
.if eax > 65535
mov eax, 65535
.endif
X86GET_TSTATECOUNT_SIZEOF = $ - x86get_tstatecount
; *****************************************************************
; turn off indirect addressing here
USEESI 0
; *****************************************************************
AllocPageTable proc uses esi,
pagesize: DWORD
mov eax, pagesize
add eax, sizeof PageTableNode
.if $fnc (VirtualAlloc, NULL, eax, MEM_RESERVE or MEM_COMMIT, PAGE_EXECUTE_READWRITE) != NULL
mov esi, eax
AddTail offset PageTableList, esi
mov eax, esi
add eax, PageTableNode
.endif
ret
AllocPageTable endp
FreePageTable proc uses esi,
lpPageTable: DWORD
mov esi, lpPageTable
sub esi, sizeof PageTableNode
; as the node lives at the start of the memory block,
; we have to remove the node from the list before freeing
invoke RemoveNode, esi
invoke VirtualFree, esi, 0, MEM_RELEASE
ret
FreePageTable endp
FreePageTableList proc uses esi edi
lea esi, PageTableList
.while TRUE
.break .if $fnc (IsListEmpty, esi)
mov edi, [esi].ListHeader.lh_Head
add edi, sizeof PageTableNode
invoke FreePageTable, edi
.endw
ret
FreePageTableList endp
.data?
align 4
pBreakpointCodePage dd ?
.code
x86_Breakpoint proc uses esi edi ebx
.if $fnc (AllocPageTable, 4096) != NULL
mov pBreakpointCodePage, eax
.else
mov pBreakpointCodePage, 0
.endif
ret
x86_Breakpoint endp
RESETENUM
ENUM BRKARGTYPE_NONE
ENUM BRKARGTYPE_ERROR
ENUM BRKARGTYPE_NUMERIC
ENUM BRKARGTYPE_STRING
ENUM BRKARGTYPE_OPERATOR
.data?
align 4
pCodePageWriteAddr dd ?
.code
x86_SetOrigin proc lpOrgAddress: DWORD
mov eax, lpOrgAddress
mov pCodePageWriteAddr, eax
ret
x86_SetOrigin endp
x86_memcpy macro pbytes:req, count:req
mov eax, count
invoke x86_MemCpy, pbytes, eax ; invoke bug? count needs passing in a register here else it takes the wrong value
endm
x86_MemCpy proc uses esi,
pBytes: DWORD,
cnt: DWORD
mov esi, pBytes
.while cnt > 0
dec cnt
lodsb
invoke x86_WriteByte, al
.endw
ret
x86_MemCpy endp
x86_WriteByte proc uses ecx,
data: BYTE
mov ecx, pCodePageWriteAddr
inc pCodePageWriteAddr
mov al, data
mov [ecx], al
ret
x86_WriteByte endp
x86_WriteWord proc uses ecx,
data: WORD
mov ecx, pCodePageWriteAddr
add pCodePageWriteAddr, 2
mov ax, data
mov [ecx], ax
ret
x86_WriteWord endp
x86_WriteDWord proc uses ecx,
data: DWORD
mov ecx, pCodePageWriteAddr
add pCodePageWriteAddr, 4
mov eax, data
mov [ecx], eax
ret
x86_WriteDWord endp
FETCHCHAR macro
call FetchBreakChar
endm
FetchBreakChar: lodsb
cmp al, " "
je FetchBreakChar
cmp al, 9
je FetchBreakChar
ret
DecodeBreakArg: FETCHCHAR
ifc al eq 0 then return BRKARGTYPE_NONE
switch al
case "0".."9"
; decimal numeric
dec esi ; back to first digit for decimal numeric
xor ecx, ecx
xor ebx, ebx ; valid characters count
.while TRUE
lodsb
switch al
case "0".."9"
inc ebx
and eax, 255
sub eax, "0"
lea ecx, [ecx*4+ecx]
add ecx, ecx
add ecx, eax
.else
dec esi
ifc ebx eq 0 then return BRKARGTYPE_ERROR
mov [edi], ecx
return BRKARGTYPE_NUMERIC
endsw
.endw
case "#", "$"
; hexadecimal numeric
xor ecx, ecx
xor ebx, ebx ; valid characters count
.while TRUE
lodsb
TOUPPER
switch al
case "0".."9", "A".."F"
inc ebx
and eax, 255
sub eax, "0"
ifc eax gt 9 then sub eax, 7
shl ecx, 4
add ecx, eax
.else
dec esi
ifc ebx eq 0 then return BRKARGTYPE_ERROR
mov [edi], ecx
return BRKARGTYPE_NUMERIC
endsw
.endw
case "%"
; binary numeric
xor ecx, ecx
xor ebx, ebx ; valid characters count
.while TRUE
lodsb
switch al
case "0".."1"
inc ebx
and eax, 255
sub eax, "0"
shl ecx, 1
add ecx, eax
.else
dec esi
ifc ebx eq 0 then return BRKARGTYPE_ERROR
mov [edi], ecx
return BRKARGTYPE_NUMERIC
endsw
.endw
case "A".."Z", "a".."z" ; strings can only begin with a letter
; string
dec esi ; back to first character of string
xor ebx, ebx ; valid characters count (string length here)
.while TRUE
lodsb
TOUPPER
switch al
case "A".."Z", "0".."9", "'", "_" ; need "'" char for specifying alt register names
mov [edi+ebx], al
inc ebx
.else
mov byte ptr [edi+ebx], 0
dec esi
ifc ebx eq 0 then return BRKARGTYPE_ERROR
return BRKARGTYPE_STRING
endsw
.endw
case "=", 21h, 3ch, 3eh ; "=", "!", "<", ">"
; relational (type: string)
dec esi ; back to first character of string
xor ebx, ebx ; valid characters count (string length here)
.while TRUE
lodsb
switch al
case "=", 21h, 3ch, 3eh ; "=", "!", "<", ">"
mov [edi+ebx], al
inc ebx
.else
mov byte ptr [edi+ebx], 0
dec esi
ifc ebx eq 0 then return BRKARGTYPE_ERROR
return BRKARGTYPE_OPERATOR
endsw
.endw
endsw
return BRKARGTYPE_ERROR
; Bit flags in the register arguments themselves (upper 16 bits only)
BITDEF BRKFLAG, MRA, 31 ; marks this argument register as a memory read address argument
BITDEF BRKFLAG, MWA, 30 ; marks this argument register as a memory write address argument
CompileBreakpointCode proc uses esi edi ebx,
lpbreakstr: PTR
local expectbracket, argbracketed: BOOL
local argisword: BOOL
local x86pass: DWORD
local breakargtype: DWORD
local argfunction: DWORD
local operatortype: DWORD
local temp1: DWORD
local x86jcc: BYTE
local bitwisechar: BYTE
local breakpointstring [1024]: BYTE
local thisbreakarg [1024]: BYTE
local thisbitwisearg [1024]: BYTE
ADDMESSAGEPTR_DBG lpbreakstr
invoke x86_SetOrigin, pBreakpointCodePage
invoke x86_WriteWord, 0e783h ; and edi, nn
invoke x86_WriteByte, 0 ; nn = 0 (edi == False)
push pCodePageWriteAddr
invoke x86_WriteByte, 0c3h ; retn
pop pCodePageWriteAddr
.if len (lpbreakstr) >= sizeof breakpointstring - 4
ADDMESSAGE_DBG "Breakpoint string too long"
return FALSE
.endif
; take a copy of the break arg string
mov esi, lpbreakstr
lea edi, breakpointstring
@@: lodsb
stosb
or al, al
jnz @B
; add more null terminators to save on persistent checking
mov dword ptr [edi], 0
mov dword ptr [edi+4], 0
lea esi, breakpointstring
mov x86pass, 0
; clear the operator type; this is re-cleared after each cmp iteration in the main loop
mov operatortype, 0
.while TRUE
mov eax, x86pass
inc eax
and eax, 3
cmp eax, 1
adc eax, 0
mov x86pass, eax ; 1-3
mov expectbracket, FALSE
mov argbracketed, FALSE
mov argisword, FALSE
RESETENUM
ENUM ARGFNC_NONE
ENUM ARGFNC_ONLYHIGH, ARGFNC_ONLYLOW
mov argfunction, ARGFNC_NONE
@@: FETCHCHAR
switch al
case 0
.break
case "("
inc esi
mov expectbracket, TRUE
endsw
; INT3
; add ax, 32768
; or ax, 32710
; movzx eax, z80registers.hl.w
dec esi
lea edi, thisbreakarg
call DecodeBreakArg
mov breakargtype, eax ; store argument type return code
; except for BRKARGTYPE_OPERATOR operators (=, !=, <, etc), check if argument is followed by ".h" or ".l"
; being careful how we handle the current character pointer (esi)
.if breakargtype != BRKARGTYPE_OPERATOR
mov temp1, esi
FETCHCHAR
.if al == "."
FETCHCHAR
TOUPPER
.if al == "H"
mov argfunction, ARGFNC_ONLYHIGH
mov temp1, esi
.elseif al == "L"
mov argfunction, ARGFNC_ONLYLOW
mov temp1, esi
.endif
.endif
mov esi, temp1
.endif
; check for closing bracket if opening bracket was present
; being sure to check for ".w" word sized argument specifier within the brackets first
.if expectbracket
FETCHCHAR
.if al == "."
FETCHCHAR
TOUPPER
.if al == "W"
mov argisword, TRUE
FETCHCHAR ; to check for closing bracket
.else
return FALSE
.endif
.endif
.if al != ")"
return FALSE
.endif
mov expectbracket, FALSE
mov argbracketed, TRUE
.endif
; ===========================================================================
; move on to evaluating the argument based on return code from DecodeBreakArg
; ===========================================================================
; note: when loading all types of initial arguments into eax, be sure to extend to eax, clearing all bits.
; BRKFLAG flag bits may be set in upper 16 bits for certain types of arguments
switch breakargtype
case BRKARGTYPE_NONE
ADDMESSAGE_DBG "BRKARGTYPE_NONE"
case BRKARGTYPE_ERROR
return FALSE
case BRKARGTYPE_NUMERIC
; ADDMESSAGEDEC_DBG "Cond Numeric: ", dword ptr [edi]
switch x86pass
case 1, 3
; arg to eax
; mov eax, nnnn
invoke x86_WriteByte, 0b8h
mov eax, [edi]
ifc eax gt 65535 then return FALSE
invoke x86_WriteDWord, eax
x86_dereferencemem
.else
return FALSE
endsw
case BRKARGTYPE_STRING
switch x86pass
case 1, 3
switch$ edi
case$ "AF"
x86_getregister z80registers.af
case$ "A"
x86_getregister z80registers.af.hi
case$ "F"
x86_getregister z80registers.af.lo
case$ "AF'"
x86_getregister z80registers.af_
case$ "A'"
x86_getregister z80registers.af_.hi
case$ "F'"
x86_getregister z80registers.af_.lo
case$ "BC"
x86_getregister z80registers.bc
case$ "B"
x86_getregister z80registers.bc.hi
case$ "C"
x86_getregister z80registers.bc.lo
case$ "BC'"
x86_getregister z80registers.bc_
case$ "B'"
x86_getregister z80registers.bc_.hi
case$ "C'"
x86_getregister z80registers.bc_.lo
case$ "DE"
x86_getregister z80registers.de
case$ "D"
x86_getregister z80registers.de.hi
case$ "E"
x86_getregister z80registers.de.lo
case$ "DE'"
x86_getregister z80registers.de_
case$ "D'"
x86_getregister z80registers.de_.hi
case$ "E'"
x86_getregister z80registers.de_.lo
case$ "HL"
x86_getregister z80registers.hl
case$ "H"
x86_getregister z80registers.hl.hi
case$ "L"
x86_getregister z80registers.hl.lo
case$ "HL'"
x86_getregister z80registers.hl_
case$ "H'"
x86_getregister z80registers.hl_.hi
case$ "L'"
x86_getregister z80registers.hl_.lo
case$ "IX"
x86_getregister z80registers.ix
case$ "IXH"
x86_getregister z80registers.ix.hi
case$ "IXL"
x86_getregister z80registers.ix.lo
case$ "IY"
x86_getregister z80registers.iy
case$ "IYH"
x86_getregister z80registers.iy.hi
case$ "IYL"
x86_getregister z80registers.iy.lo
case$ "MPTR"
x86_getregister z80registers.memptr
case$ "IR"
; xor eax, eax
invoke x86_WriteWord, 0c033h
; mov ah, byte ptr z80registers.i
invoke x86_WriteWord, 258ah
invoke x86_WriteDWord, addr z80registers.i
; mov al, byte ptr z80registers.r
invoke x86_WriteByte, 0a0h
invoke x86_WriteDWord, addr z80registers.r
; and al, 7fh
invoke x86_WriteWord, 7f24h
; or al, byte ptr z80registers.r_msb
invoke x86_WriteWord, 050ah
invoke x86_WriteDWord, addr z80registers.r_msb
x86_dereferencemem
case$ "I"
x86_getregister z80registers.i
case$ "R"
; movzx eax, z80registers.r
invoke x86_WriteByte, 0fh
invoke x86_WriteWord, 05b6h
invoke x86_WriteDWord, addr z80registers.r
; and al, 7fh
invoke x86_WriteWord, 7f24h
; or al, byte ptr z80registers.r_msb
invoke x86_WriteWord, 050ah
invoke x86_WriteDWord, addr z80registers.r_msb
x86_dereferencemem
case$ "IM"
x86_getregister z80registers.intmode
case$ "IFF1"
x86_getregister z80registers.iff1
case$ "IFF2"
x86_getregister z80registers.iff2
case$ "SP"
x86_getregister z80registers._sp
case$ "PC"
x86_getregister z80registers.pc
case$ "MRA"
or operatortype, BRKFLAGF_MRA
x86_memcpy addr x86get_memreadaddr, X86GET_MEMREADADDR_SIZEOF
; mark this argument as the one with the MRA value (would be in eax or ecx when testing)
; or eax, BRKFLAGF_MRA
invoke x86_WriteByte, 0dh
invoke x86_WriteDWord, BRKFLAGF_MRA
case$ "MRV"
x86_memcpy addr x86get_memreadval, X86GET_MEMREADVAL_SIZEOF
case$ "MWA"
or operatortype, BRKFLAGF_MWA
x86_memcpy addr x86get_memwriteaddr, X86GET_MEMWRITEADDR_SIZEOF
; mark this argument as the one with the MWA value (would be in eax or ecx when testing)
; or eax, BRKFLAGF_MWA
invoke x86_WriteByte, 0dh
invoke x86_WriteDWord, BRKFLAGF_MWA
case$ "MWV"
x86_memcpy addr x86get_memwriteval, X86GET_MEMWRITEVAL_SIZEOF
case$ "PRA"
x86_memcpy addr x86get_portreadaddr, X86GET_PORTREADADDR_SIZEOF
case$ "IN"
x86_memcpy addr x86get_portreadaddr, X86GET_PORTREADADDR_SIZEOF
case$ "PRV"
x86_memcpy addr x86get_portreadval, X86GET_PORTREADVAL_SIZEOF
case$ "PWA"
x86_memcpy addr x86get_portwriteaddr, X86GET_PORTWRITEADDR_SIZEOF
case$ "OUT"
x86_memcpy addr x86get_portwriteaddr, X86GET_PORTWRITEADDR_SIZEOF
case$ "PWV"
x86_memcpy addr x86get_portwriteval, X86GET_PORTWRITEVAL_SIZEOF
case$ "P0"
; xor eax, eax
invoke x86_WriteWord, 0c033h
x86_memcpy addr call_GetBankAtAddr, CALL_GETBANKATADDR_SIZEOF
case$ "P1"
; mov eax, nnnn
invoke x86_WriteByte, 0b8h
invoke x86_WriteDWord, 16384
x86_memcpy addr call_GetBankAtAddr, CALL_GETBANKATADDR_SIZEOF
case$ "P2"
; mov eax, nnnn
invoke x86_WriteByte, 0b8h
invoke x86_WriteDWord, 32768
x86_memcpy addr call_GetBankAtAddr, CALL_GETBANKATADDR_SIZEOF
case$ "P3"
; mov eax, nnnn
invoke x86_WriteByte, 0b8h
invoke x86_WriteDWord, 49152
x86_memcpy addr call_GetBankAtAddr, CALL_GETBANKATADDR_SIZEOF
case$ "TS"
x86_memcpy addr x86get_tstatecount, X86GET_TSTATECOUNT_SIZEOF
case$ "PAGING"
x86_memcpy addr call_GetBankConfig, CALL_GETBANKCONFIG_SIZEOF
case$ "SNOW"
; movzx eax, SPGfx.SnowEffect
invoke x86_WriteByte, 0fh
invoke x86_WriteWord, 05b6h
invoke x86_WriteDWord, addr SPGfx.SnowEffect
case$ "SCREEN"
; movzx eax, SPGfx.CurrScreen
invoke x86_WriteByte, 0fh
invoke x86_WriteWord, 05b6h
invoke x86_WriteDWord, addr SPGfx.CurrScreen
case$ "BORDER"
; movzx eax, Last_FE_Write
invoke x86_WriteByte, 0fh
invoke x86_WriteWord, 05b6h
invoke x86_WriteDWord, addr Last_FE_Write
; and al, 7
invoke x86_WriteWord, 0724h
_x86flag macro fMask:req
invoke x86_WriteWord, 0c033h ; xor eax, eax
invoke x86_WriteWord, 05f6h ; test byte ptr z80registers.af.lo, fMask
invoke x86_WriteDWord, addr z80registers.af.lo
invoke x86_WriteByte, fMask
invoke x86_WriteWord, 950fh ; setnz al
invoke x86_WriteByte, 0c0h
endm
case$ "FS"
_x86flag FLAG_S
case$ "FZ"
_x86flag FLAG_Z
case$ "F5"
_x86flag FLAG_5
case$ "FH"
_x86flag FLAG_H
case$ "F3"
_x86flag FLAG_3
case$ "FV"
_x86flag FLAG_V
case$ "FP"
_x86flag FLAG_P
case$ "FN"
_x86flag FLAG_N
case$ "FC"
_x86flag FLAG_C
else$
return FALSE
endsw$
endsw
case BRKARGTYPE_OPERATOR
switch x86pass
case 2
; INT3
switch word ptr [edi]
; set the jcc opcode each relational operator
case "="
mov x86jcc, 74h ; je @F ; =
_jcc_ = 21h or ("=" shl 8) ; !=
case _jcc_
mov x86jcc, 75h ; jne @F
_jcc_ = 3ch or (3eh shl 8) ; <>
case _jcc_
mov x86jcc, 75h ; jne @F
_jcc_ = 3ch ; <
case _jcc_
mov x86jcc, 72h ; jb @F
_jcc_ = 3ch or ("=" shl 8) ; <=
case _jcc_
mov x86jcc, 76h ; jbe @F
_jcc_ = 3eh ; >
case _jcc_
mov x86jcc, 77h ; ja @F
_jcc_ = 3eh or ("=" shl 8) ; >=
case _jcc_
mov x86jcc, 73h ; jae @F
.else
return FALSE
endsw
endsw
endsw
; modify the eax argument if indicated for high byte or low byte only comparisons
; these argfunction values were excluded above for BRKARGTYPE_OPERATOR
switch argfunction
case ARGFNC_ONLYHIGH
invoke x86_WriteDWord, 08e8c166h ; shr ax, 8
case ARGFNC_ONLYLOW
invoke x86_WriteDWord, 00ff2566h ; and ax, ffh
endsw
; except for BRKARGTYPE_OPERATOR operators (=, !=, <, etc), check if argument is followed by bitwise operators for the current argument
; being careful how we handle the current character pointer (esi)
.if breakargtype != BRKARGTYPE_OPERATOR
mov temp1, esi
@@: FETCHCHAR
.if (al == "&") || (al == "|") || (al == "^") || (al == "+") || (al == "-")
mov bitwisechar, al
lea edi, thisbitwisearg ;thisbreakarg
call DecodeBreakArg
switch eax
case BRKARGTYPE_NUMERIC
mov temp1, esi ; update current character pointer
mov eax, [edi]
.if bitwisechar == "&"
; and ax, nn
invoke x86_WriteWord, 2566h
mov eax, [edi]
ifc eax gt 65535 then return FALSE
invoke x86_WriteWord, ax
jmp @B
.elseif bitwisechar == "|"
; or ax, nn
invoke x86_WriteWord, 0d66h
mov eax, [edi]
ifc eax gt 65535 then return FALSE
invoke x86_WriteWord, ax
jmp @B
.elseif bitwisechar == "^"
; or ax, nn
invoke x86_WriteWord, 3566h
mov eax, [edi]
ifc eax gt 65535 then return FALSE
invoke x86_WriteWord, ax
jmp @B
.elseif bitwisechar == "+"
; add ax, nn
invoke x86_WriteWord, 0566h
mov eax, [edi]
ifc eax gt 65535 then return FALSE
invoke x86_WriteWord, ax
jmp @B
.elseif bitwisechar == "-"
; sub ax, nn
invoke x86_WriteWord, 2d66h
mov eax, [edi]
ifc eax gt 65535 then return FALSE
invoke x86_WriteWord, ax
jmp @B
.else