-
Notifications
You must be signed in to change notification settings - Fork 27
/
c68k-patch.diff
2372 lines (2132 loc) · 65.7 KB
/
c68k-patch.diff
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
diff --git a/makefile.libretro b/makefile.libretro
index 1b33212..56f0576 100644
--- a/makefile.libretro
+++ b/makefile.libretro
@@ -157,6 +157,7 @@ BURN_BLACKLIST := $(FBA_BURNER_DIR)/un7z.cpp \
$(FBA_CPU_DIR)/konami/konamtbl.c \
$(FBA_CPU_DIR)/konami/konamops.c \
$(FBA_CPU_DIR)/m68k/m68k_in.c \
+ $(FBA_CPU_DIR)/m68k/m68kfpu.c \
$(FBA_CPU_DIR)/m6800/6800ops.c \
$(FBA_CPU_DIR)/m6800/6800tbl.c \
$(FBA_CPU_DIR)/m6805/6805ops.c \
@@ -175,8 +176,6 @@ BURN_BLACKLIST := $(FBA_BURNER_DIR)/un7z.cpp \
$(FBA_BURNER_DIR)/cong.cpp \
$(FBA_BURNER_DIR)/image.cpp \
$(FBA_BURNER_DIR)/misc.cpp \
- $(FBA_CPU_DIR)/c68k/c68k_ini.c \
- $(FBA_CPU_DIR)/c68k/c68k_op.c \
$(FBA_CPU_DIR)/h6280/tblh6280.c \
$(FBA_CPU_DIR)/m6502/t65sc02.c \
$(FBA_CPU_DIR)/m6502/t65c02.c \
@@ -188,22 +187,30 @@ BURN_BLACKLIST := $(FBA_BURNER_DIR)/un7z.cpp \
$(FBA_CPU_DIR)/nec/necinstr.c \
$(FBA_BURN_DIR)/drv/capcom/ctv_make.cpp
-EMU_C68K = 0
+EMU_M68K = 1
+EMU_C68K = 1
FBA_DEFINES :=
+M68K_DIR :=
ifeq ($(EMU_C68K), 1)
- FBA_DEFINES += -DEMU_C68K
+ FBA_DEFINES += -DBUILD_C68K
+ BURN_BLACKLIST += $(FBA_CPU_DIR)/c68k/c68k_ini.c \
+ $(FBA_CPU_DIR)/c68k/c68k_op.c
+ M68K_DIR += $(FBA_CPU_DIR)/c68k
+else
+ BURN_BLACKLIST += $(FBA_CPU_DIR)/c68k/c68k.c
+endif
+
+ifeq ($(EMU_M68K), 1)
+ FBA_DEFINES += -DBUILD_M68K
+ M68K_DIR += $(FBA_CPU_DIR)/m68k
+else
BURN_BLACKLIST += $(FBA_CPU_DIR)/m68k/m68kcpu.c \
$(FBA_CPU_DIR)/m68k/m68kopnz.c \
$(FBA_CPU_DIR)/m68k/m68kopac.c \
$(FBA_CPU_DIR)/m68k/m68kopdm.c \
$(FBA_CPU_DIR)/m68k/m68kopnz.c \
$(FBA_CPU_DIR)/m68k/m68kops.c
- M68K_DIR := $(FBA_CPU_DIR)/c68k
-else
- FBA_DEFINES += -DEMU_M68K
- BURN_BLACKLIST += $(FBA_CPU_DIR)/c68k/c68k.c
- M68K_DIR := $(FBA_CPU_DIR)/m68k
endif
#ifeq ($(LIBRETRO_OPTIMIZATIONS), 1)
diff --git a/src/burn/burn.h b/src/burn/burn.h
index f0d9359..38ce29f 100644
--- a/src/burn/burn.h
+++ b/src/burn/burn.h
@@ -535,6 +535,14 @@ void IpsApplyPatches(UINT8* base, char* rom_name);
#define FBF_SONICWI (1 << 7)
#define FBF_PWRINST (1 << 8)
+// ---------------------------------------------------------------------------
+// Common CPU definitions
+
+#define CPU_IRQSTATUS_NONE 0
+#define CPU_IRQSTATUS_ACK 1
+#define CPU_IRQSTATUS_AUTO 2
+#define CPU_IRQSTATUS_HOLD 4
+
#ifdef __cplusplus
} // End of extern "C"
#endif
diff --git a/src/burner/libretro/libretro.cpp b/src/burner/libretro/libretro.cpp
index 5a4d7d7..1c354a1 100644
--- a/src/burner/libretro/libretro.cpp
+++ b/src/burner/libretro/libretro.cpp
@@ -474,6 +474,14 @@ static void check_variables(void)
}
}
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern INT32 nSekCpuCore;
+#ifdef __cplusplus
+}
+#endif
+
void retro_run(void)
{
INT32 width, height;
@@ -482,6 +490,7 @@ void retro_run(void)
poll_input();
+ nSekCpuCore = 1;
nBurnLayer = 0xff;
pBurnSoundOut = g_audio_buf;
nBurnSoundRate = AUDIO_SAMPLERATE;
diff --git a/src/cpu/m68000_intf.c b/src/cpu/m68000_intf.c
index 1008f80..4deb0a3 100644
--- a/src/cpu/m68000_intf.c
+++ b/src/cpu/m68000_intf.c
@@ -3,6 +3,9 @@
#include "m68000_intf.h"
#include "m68000_debug.h"
+INT32 nSekCpuCore = SEK_CORE_C68K; // 0 - c68k, 1 - m68k, 2 - a68k
+INT32 DebugStep = 0; // 0 - off, 1 - on
+
#ifdef EMU_M68K
INT32 nSekM68KContextSize[SEK_MAX];
INT8* SekM68KContext[SEK_MAX];
@@ -23,13 +26,13 @@ INT32 nSekCPUType[SEK_MAX], nSekCycles[SEK_MAX], nSekIRQPending[SEK_MAX];
#if defined (FBA_DEBUG)
-void (*SekDbgBreakpointHandlerRead)(UINT32, INT32);
-void (*SekDbgBreakpointHandlerFetch)(UINT32, INT32);
-void (*SekDbgBreakpointHandlerWrite)(UINT32, INT32);
+void (*SekDbgBreakpointHandlerRead)(UINT32, INT32) = NULL;
+void (*SekDbgBreakpointHandlerFetch)(UINT32, INT32) = NULL;
+void (*SekDbgBreakpointHandlerWrite)(UINT32, INT32) = NULL;
-UINT32 (*SekDbgFetchByteDisassembler)(UINT32);
-UINT32 (*SekDbgFetchWordDisassembler)(UINT32);
-UINT32 (*SekDbgFetchLongDisassembler)(UINT32);
+UINT32 (*SekDbgFetchByteDisassembler)(UINT32) = NULL;
+UINT32 (*SekDbgFetchWordDisassembler)(UINT32) = NULL;
+UINT32 (*SekDbgFetchLongDisassembler)(UINT32) = NULL;
static struct { UINT32 address; INT32 id; } BreakpointDataRead[9] = { { 0, 0 }, };
static struct { UINT32 address; INT32 id; } BreakpointDataWrite[9] = { { 0, 0 }, };
@@ -141,15 +144,15 @@ inline static void SingleStep_PC()
// ----------------------------------------------------------------------------
// Default memory access handlers
-UINT8 __fastcall DefReadByte(UINT32 a) { return 0; }
-void __fastcall DefWriteByte(UINT32 a, UINT8 b) { }
+UINT8 DefReadByte(UINT32 a) { return 0; }
+void DefWriteByte(UINT32 a, UINT8 b) { }
#define DEFWORDHANDLERS(i) \
- UINT16 __fastcall DefReadWord##i(UINT32 a) { SEK_DEF_READ_WORD(i, a) } \
- void __fastcall DefWriteWord##i(UINT32 a, UINT16 d) { SEK_DEF_WRITE_WORD(i, a ,d) }
+ UINT16 DefReadWord##i(UINT32 a) { SEK_DEF_READ_WORD(i, a) } \
+ void DefWriteWord##i(UINT32 a, UINT16 d) { SEK_DEF_WRITE_WORD(i, a ,d) }
#define DEFLONGHANDLERS(i) \
- UINT32 __fastcall DefReadLong##i(UINT32 a) { SEK_DEF_READ_LONG(i, a) } \
- void __fastcall DefWriteLong##i(UINT32 a, UINT32 d) { SEK_DEF_WRITE_LONG(i, a , d) }
+ UINT32 DefReadLong##i(UINT32 a) { SEK_DEF_READ_LONG(i, a) } \
+ void DefWriteLong##i(UINT32 a, UINT32 d) { SEK_DEF_WRITE_LONG(i, a , d) }
DEFWORDHANDLERS(0)
DEFLONGHANDLERS(0)
@@ -216,10 +219,12 @@ inline static UINT8 ReadByte(UINT32 a)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("read8 0x%08X\n"), a);
-
pr = FIND_R(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+#ifdef FBA_DEBUG
+ CheckBreakpoint_R(a, ~0);
+#endif
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
+ {
a ^= 1;
return pr[a & SEK_PAGEM];
}
@@ -232,10 +237,9 @@ inline static UINT8 FetchByte(UINT32 a)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("fetch8 0x%08X\n"), a);
-
pr = FIND_F(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
+ {
a ^= 1;
return pr[a & SEK_PAGEM];
}
@@ -248,10 +252,9 @@ inline static void WriteByte(UINT32 a, UINT8 d)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("write8 0x%08X\n"), a);
-
pr = FIND_W(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
+ {
a ^= 1;
pr[a & SEK_PAGEM] = (UINT8)d;
return;
@@ -266,7 +269,8 @@ inline static void WriteByteROM(UINT32 a, UINT8 d)
a &= 0xFFFFFF;
pr = FIND_R(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
+ {
a ^= 1;
pr[a & SEK_PAGEM] = (UINT8)d;
return;
@@ -280,12 +284,9 @@ inline static UINT16 ReadWord(UINT32 a)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("read16 0x%08X\n"), a);
-
pr = FIND_R(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
return BURN_ENDIAN_SWAP_INT16(*((UINT16*)(pr + (a & SEK_PAGEM))));
- }
return pSekExt->ReadWord[(uintptr_t)pr](a);
}
@@ -295,12 +296,9 @@ inline static UINT16 FetchWord(UINT32 a)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("fetch16 0x%08X\n"), a);
-
pr = FIND_F(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
return BURN_ENDIAN_SWAP_INT16(*((UINT16*)(pr + (a & SEK_PAGEM))));
- }
return pSekExt->ReadWord[(uintptr_t)pr](a);
}
@@ -310,9 +308,10 @@ inline static void WriteWord(UINT32 a, UINT16 d)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("write16 0x%08X\n"), a);
-
pr = FIND_W(a);
+#ifdef FBA_DEBUG
+ CheckBreakpoint_W(a, ~1);
+#endif
if ((uintptr_t)pr >= SEK_MAXHANDLER) {
*((UINT16*)(pr + (a & SEK_PAGEM))) = (UINT16)BURN_ENDIAN_SWAP_INT16(d);
return;
@@ -340,10 +339,12 @@ inline static UINT32 ReadLong(UINT32 a)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("read32 0x%08X\n"), a);
-
pr = FIND_R(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+#ifdef FBA_DEBUG
+ CheckBreakpoint_R(a, ~1);
+#endif
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
+ {
UINT32 r = *((UINT32*)(pr + (a & SEK_PAGEM)));
r = (r >> 16) | (r << 16);
return BURN_ENDIAN_SWAP_INT32(r);
@@ -357,10 +358,9 @@ inline static UINT32 FetchLong(UINT32 a)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("fetch32 0x%08X\n"), a);
-
pr = FIND_F(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
+ {
UINT32 r = *((UINT32*)(pr + (a & SEK_PAGEM)));
r = (r >> 16) | (r << 16);
return BURN_ENDIAN_SWAP_INT32(r);
@@ -374,10 +374,12 @@ inline static void WriteLong(UINT32 a, UINT32 d)
a &= 0xFFFFFF;
-// bprintf(PRINT_NORMAL, _T("write32 0x%08X\n"), a);
-
pr = FIND_W(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+#ifdef FBA_DEBUG
+ CheckBreakpoint_W(a, ~1);
+#endif
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
+ {
d = (d >> 16) | (d << 16);
*((UINT32*)(pr + (a & SEK_PAGEM))) = BURN_ENDIAN_SWAP_INT32(d);
return;
@@ -392,7 +394,8 @@ inline static void WriteLongROM(UINT32 a, UINT32 d)
a &= 0xFFFFFF;
pr = FIND_R(a);
- if ((uintptr_t)pr >= SEK_MAXHANDLER) {
+ if ((uintptr_t)pr >= SEK_MAXHANDLER)
+ {
d = (d >> 16) | (d << 16);
*((UINT32*)(pr + (a & SEK_PAGEM))) = d;
return;
@@ -403,7 +406,7 @@ inline static void WriteLongROM(UINT32 a, UINT32 d)
#if defined (FBA_DEBUG)
// Breakpoint checking memory access functions
-UINT8 __fastcall ReadByteBP(UINT32 a)
+UINT8 ReadByteBP(UINT32 a)
{
UINT8* pr;
@@ -420,7 +423,7 @@ UINT8 __fastcall ReadByteBP(UINT32 a)
return pSekExt->ReadByte[(uintptr_t)pr](a);
}
-void __fastcall WriteByteBP(UINT32 a, UINT8 d)
+void WriteByteBP(UINT32 a, UINT8 d)
{
UINT8* pr;
@@ -438,7 +441,7 @@ void __fastcall WriteByteBP(UINT32 a, UINT8 d)
pSekExt->WriteByte[(uintptr_t)pr](a, d);
}
-UINT16 __fastcall ReadWordBP(UINT32 a)
+UINT16 ReadWordBP(UINT32 a)
{
UINT8* pr;
@@ -454,7 +457,7 @@ UINT16 __fastcall ReadWordBP(UINT32 a)
return pSekExt->ReadWord[(uintptr_t)pr](a);
}
-void __fastcall WriteWordBP(UINT32 a, UINT16 d)
+void WriteWordBP(UINT32 a, UINT16 d)
{
UINT8* pr;
@@ -471,7 +474,7 @@ void __fastcall WriteWordBP(UINT32 a, UINT16 d)
pSekExt->WriteWord[(uintptr_t)pr](a, d);
}
-UINT32 __fastcall ReadLongBP(UINT32 a)
+UINT32 ReadLongBP(UINT32 a)
{
UINT8* pr;
@@ -489,7 +492,7 @@ UINT32 __fastcall ReadLongBP(UINT32 a)
return pSekExt->ReadLong[(uintptr_t)pr](a);
}
-void __fastcall WriteLongBP(UINT32 a, UINT32 d)
+void WriteLongBP(UINT32 a, UINT32 d)
{
UINT8* pr;
@@ -517,19 +520,19 @@ struct A68KContext* SekRegs[SEK_MAX] = { NULL, };
#endif
struct A68KInter {
- void (__fastcall *DebugCallback) ();
- UINT8 (__fastcall *Read8) (UINT32 a);
- UINT16 (__fastcall *Read16)(UINT32 a);
- UINT32 (__fastcall *Read32)(UINT32 a);
- void (__fastcall *Write8) (UINT32 a, UINT8 d);
- void (__fastcall *Write16) (UINT32 a, UINT16 d);
- void (__fastcall *Write32) (UINT32 a, UINT32 d);
- void (__fastcall *ChangePc)(UINT32 a);
- UINT8 (__fastcall *PcRel8) (UINT32 a);
- UINT16 (__fastcall *PcRel16)(UINT32 a);
- UINT32 (__fastcall *PcRel32)(UINT32 a);
- UINT16 (__fastcall *Dir16)(UINT32 a);
- UINT32 (__fastcall *Dir32)(UINT32 a);
+ void ( *DebugCallback) ();
+ UINT8 ( *Read8) (UINT32 a);
+ UINT16 ( *Read16)(UINT32 a);
+ UINT32 ( *Read32)(UINT32 a);
+ void ( *Write8) (UINT32 a, UINT8 d);
+ void ( *Write16) (UINT32 a, UINT16 d);
+ void ( *Write32) (UINT32 a, UINT32 d);
+ void ( *ChangePc)(UINT32 a);
+ UINT8 ( *PcRel8) (UINT32 a);
+ UINT16 ( *PcRel16)(UINT32 a);
+ UINT32 ( *PcRel32)(UINT32 a);
+ UINT16 ( *Dir16)(UINT32 a);
+ UINT32 ( *Dir32)(UINT32 a);
};
#ifdef EMU_A68K
@@ -547,23 +550,23 @@ struct A68KInter {
struct A68KInter a68k_memory_intf;
-UINT8 __fastcall A68KRead8 (UINT32 a) { return ReadByte(a);}
-UINT16 __fastcall A68KRead16(UINT32 a) { return ReadWord(a);}
-UINT32 __fastcall A68KRead32(UINT32 a) { return ReadLong(a);}
-UINT8 __fastcall A68KFetch8 (UINT32 a) { return FetchByte(a);}
-UINT16 __fastcall A68KFetch16(UINT32 a) { return FetchWord(a);}
-UINT32 __fastcall A68KFetch32(UINT32 a) { return FetchLong(a);}
-void __fastcall A68KWrite8 (UINT32 a,UINT8 d) { WriteByte(a,d);}
-void __fastcall A68KWrite16(UINT32 a,UINT16 d) { WriteWord(a,d);}
-void __fastcall A68KWrite32(UINT32 a,UINT32 d) { WriteLong(a,d);}
+UINT8 A68KRead8 (UINT32 a) { return ReadByte(a);}
+UINT16 A68KRead16(UINT32 a) { return ReadWord(a);}
+UINT32 A68KRead32(UINT32 a) { return ReadLong(a);}
+UINT8 A68KFetch8 (UINT32 a) { return FetchByte(a);}
+UINT16 A68KFetch16(UINT32 a) { return FetchWord(a);}
+UINT32 A68KFetch32(UINT32 a) { return FetchLong(a);}
+void A68KWrite8 (UINT32 a,UINT8 d) { WriteByte(a,d);}
+void A68KWrite16(UINT32 a,UINT16 d) { WriteWord(a,d);}
+void A68KWrite32(UINT32 a,UINT32 d) { WriteLong(a,d);}
#if defined (FBA_DEBUG)
-void __fastcall A68KCheckBreakpoint() { CheckBreakpoint_PC(); }
-void __fastcall A68KSingleStep() { SingleStep_PC(); }
+void A68KCheckBreakpoint() { CheckBreakpoint_PC(); }
+void A68KSingleStep() { SingleStep_PC(); }
#endif
#ifdef EMU_A68K
-void __fastcall A68KChangePC(UINT32 pc)
+void A68KChangePC(UINT32 pc)
{
pc &= 0xFFFFFF;
@@ -576,38 +579,38 @@ void __fastcall A68KChangePC(UINT32 pc)
#endif
#ifdef EMU_M68K
-unsigned int __fastcall M68KReadByte(unsigned int a) { return (unsigned int)ReadByte(a); }
-unsigned int __fastcall M68KReadWord(unsigned int a) { return (unsigned int)ReadWord(a); }
-unsigned int __fastcall M68KReadLong(unsigned int a) { return ReadLong(a); }
+unsigned int M68KReadByte(unsigned int a) { return (unsigned int)ReadByte(a); }
+unsigned int M68KReadWord(unsigned int a) { return (unsigned int)ReadWord(a); }
+unsigned int M68KReadLong(unsigned int a) { return ReadLong(a); }
-unsigned int __fastcall M68KFetchByte(unsigned int a) { return (unsigned int)FetchByte(a); }
-unsigned int __fastcall M68KFetchWord(unsigned int a) { return (unsigned int)FetchWord(a); }
-unsigned int __fastcall M68KFetchLong(unsigned int a) { return FetchLong(a); }
+unsigned int M68KFetchByte(unsigned int a) { return (unsigned int)FetchByte(a); }
+unsigned int M68KFetchWord(unsigned int a) { return (unsigned int)FetchWord(a); }
+unsigned int M68KFetchLong(unsigned int a) { return FetchLong(a); }
#ifdef FBA_DEBUG
-UINT32 __fastcall M68KReadByteBP(UINT32 a) { return (UINT32)ReadByteBP(a); }
-UINT32 __fastcall M68KReadWordBP(UINT32 a) { return (UINT32)ReadWordBP(a); }
-UINT32 __fastcall M68KReadLongBP(UINT32 a) { return ReadLongBP(a); }
+UINT32 M68KReadByteBP(UINT32 a) { return (UINT32)ReadByteBP(a); }
+UINT32 M68KReadWordBP(UINT32 a) { return (UINT32)ReadWordBP(a); }
+UINT32 M68KReadLongBP(UINT32 a) { return ReadLongBP(a); }
-void __fastcall M68KWriteByteBP(UINT32 a, UINT32 d) { WriteByteBP(a, d); }
-void __fastcall M68KWriteWordBP(UINT32 a, UINT32 d) { WriteWordBP(a, d); }
-void __fastcall M68KWriteLongBP(UINT32 a, UINT32 d) { WriteLongBP(a, d); }
+void M68KWriteByteBP(UINT32 a, UINT32 d) { WriteByteBP(a, d); }
+void M68KWriteWordBP(UINT32 a, UINT32 d) { WriteWordBP(a, d); }
+void M68KWriteLongBP(UINT32 a, UINT32 d) { WriteLongBP(a, d); }
void M68KCheckBreakpoint() { CheckBreakpoint_PC(); }
void M68KSingleStep() { SingleStep_PC(); }
-UINT32 (__fastcall *M68KReadByteDebug)(UINT32);
-UINT32 (__fastcall *M68KReadWordDebug)(UINT32);
-UINT32 (__fastcall *M68KReadLongDebug)(UINT32);
+UINT32 (*M68KReadByteDebug)(UINT32);
+UINT32 (*M68KReadWordDebug)(UINT32);
+UINT32 (*M68KReadLongDebug)(UINT32);
-void (__fastcall *M68KWriteByteDebug)(UINT32, UINT32);
-void (__fastcall *M68KWriteWordDebug)(UINT32, UINT32);
-void (__fastcall *M68KWriteLongDebug)(UINT32, UINT32);
+void ( *M68KWriteByteDebug)(UINT32, UINT32);
+void ( *M68KWriteWordDebug)(UINT32, UINT32);
+void ( *M68KWriteLongDebug)(UINT32, UINT32);
#endif
-void __fastcall M68KWriteByte(unsigned int a, unsigned int d) { WriteByte(a, d); }
-void __fastcall M68KWriteWord(unsigned int a, unsigned int d) { WriteWord(a, d); }
-void __fastcall M68KWriteLong(unsigned int a, unsigned int d) { WriteLong(a, d); }
+void M68KWriteByte(unsigned int a, unsigned int d) { WriteByte(a, d); }
+void M68KWriteWord(unsigned int a, unsigned int d) { WriteWord(a, d); }
+void M68KWriteLong(unsigned int a, unsigned int d) { WriteLong(a, d); }
#endif
#ifdef EMU_C68K
@@ -620,7 +623,6 @@ void C68KWriteWord(UINT32 a, UINT16 d) { WriteWord(a, d); }
UINT32 C68KRebasePC(UINT32 pc)
{
- // bprintf(PRINT_NORMAL, _T("C68KRebasePC 0x%08x\n"), pc);
pc &= 0xFFFFFF;
SekC68KCurrentContext->BasePC = (UINT32)FIND_F(pc) - (pc & ~SEK_PAGEM);
return SekC68KCurrentContext->BasePC + pc;
@@ -628,7 +630,7 @@ UINT32 C68KRebasePC(UINT32 pc)
INT32 C68KInterruptCallBack(INT32 irqline)
{
- if (nSekIRQPending[nSekActive] & (SEK_IRQSTATUS_AUTO << 12))
+ if (nSekIRQPending[nSekActive] & (CPU_IRQSTATUS_AUTO << 12))
{
SekC68KContext[nSekActive]->IRQState = 0; //CLEAR_LINE
SekC68KContext[nSekActive]->IRQLine = 0;
@@ -714,41 +716,38 @@ void SekWriteLongROM(UINT32 a, UINT32 d) { WriteLongROM(a, d); }
#ifdef EMU_A68K
static INT32 A68KIRQAcknowledge(INT32 nIRQ)
{
- if (nSekIRQPending[nSekActive] & SEK_IRQSTATUS_AUTO) {
+ if (nSekIRQPending[nSekActive] & (CPU_IRQSTATUS_AUTO << 12))
+ {
M68000_regs.irq &= 0x78;
nSekIRQPending[nSekActive] = 0;
}
nSekIRQPending[nSekActive] = 0;
- if (pSekExt->IrqCallback) {
+ if (pSekExt->IrqCallback)
return pSekExt->IrqCallback(nIRQ);
- }
return -1;
}
static INT32 A68KResetCallback()
{
- if (pSekExt->ResetCallback == NULL) {
+ if (pSekExt->ResetCallback == NULL)
return 0;
- }
return pSekExt->ResetCallback();
}
static INT32 A68KRTECallback()
{
- if (pSekExt->RTECallback == NULL) {
+ if (pSekExt->RTECallback == NULL)
return 0;
- }
return pSekExt->RTECallback();
}
static INT32 A68KCmpCallback(UINT32 val, INT32 reg)
{
- if (pSekExt->CmpCallback == NULL) {
+ if (pSekExt->CmpCallback == NULL)
return 0;
- }
return pSekExt->CmpCallback(val, reg);
}
@@ -769,14 +768,14 @@ static INT32 SekSetup(struct A68KContext* psr)
#ifdef EMU_M68K
int M68KIRQAcknowledge(int nIRQ)
{
- if (nSekIRQPending[nSekActive] & SEK_IRQSTATUS_AUTO) {
+ if (nSekIRQPending[nSekActive] & (CPU_IRQSTATUS_AUTO << 12))
+ {
m68k_set_irq(0);
nSekIRQPending[nSekActive] = 0;
}
- if (pSekExt->IrqCallback) {
+ if (pSekExt->IrqCallback)
return pSekExt->IrqCallback(nIRQ);
- }
return M68K_INT_ACK_AUTOVECTOR;
}
@@ -807,17 +806,15 @@ void M68KcmpildCallback(unsigned int val, int reg)
#ifdef EMU_A68K
static INT32 SekInitCPUA68K(INT32 nCount, INT32 nCPUType)
{
- if (nCPUType != 0x68000) {
+ if (nCPUType != 0x68000)
return 1;
- }
nSekCPUType[nCount] = 0;
// Allocate emu-specific cpu states
SekRegs[nCount] = (struct A68KContext*)malloc(sizeof(struct A68KContext));
- if (SekRegs[nCount] == NULL) {
+ if (SekRegs[nCount] == NULL)
return 1;
- }
// Setup each cpu context
memset(SekRegs[nCount], 0, sizeof(struct A68KContext));
@@ -835,25 +832,25 @@ static INT32 SekInitCPUM68K(INT32 nCount, INT32 nCPUType)
{
nSekCPUType[nCount] = nCPUType;
- switch (nCPUType) {
- case 0x68000:
- m68k_set_cpu_type(M68K_CPU_TYPE_68000);
- break;
- case 0x68010:
- m68k_set_cpu_type(M68K_CPU_TYPE_68010);
- break;
- case 0x68EC020:
- m68k_set_cpu_type(M68K_CPU_TYPE_68EC020);
- break;
- default:
- return 1;
- }
+ switch (nCPUType)
+ {
+ case 0x68000:
+ m68k_set_cpu_type(M68K_CPU_TYPE_68000);
+ break;
+ case 0x68010:
+ m68k_set_cpu_type(M68K_CPU_TYPE_68010);
+ break;
+ case 0x68EC020:
+ m68k_set_cpu_type(M68K_CPU_TYPE_68EC020);
+ break;
+ default:
+ return 1;
+ }
nSekM68KContextSize[nCount] = m68k_context_size();
SekM68KContext[nCount] = (INT8*)malloc(nSekM68KContextSize[nCount]);
- if (SekM68KContext[nCount] == NULL) {
+ if (SekM68KContext[nCount] == NULL)
return 1;
- }
memset(SekM68KContext[nCount], 0, nSekM68KContextSize[nCount]);
m68k_get_context(SekM68KContext[nCount]);
@@ -926,10 +923,6 @@ INT32 SekInit(INT32 nCount, INT32 nCPUType)
{
struct SekExt* ps = NULL;
-#if !defined BUILD_A68K
- bBurnUseASMCPUEmulation = FALSE;
-#endif
-
if (nSekActive >= 0)
{
SekClose();
@@ -939,9 +932,13 @@ INT32 SekInit(INT32 nCount, INT32 nCPUType)
if (nCount > nSekCount)
nSekCount = nCount;
+ // only m68k supports 68010 and 68EC020
+ if(nCount == 0 && nCPUType != 0x68000 && nSekCpuCore != SEK_CORE_M68K) nSekCpuCore = SEK_CORE_M68K;
+
// Allocate cpu extenal data (memory map etc)
SekExt[nCount] = (struct SekExt*)malloc(sizeof(struct SekExt));
- if (SekExt[nCount] == NULL) {
+ if (SekExt[nCount] == NULL)
+ {
SekExit();
return 1;
}
@@ -1035,42 +1032,55 @@ INT32 SekInit(INT32 nCount, INT32 nCPUType)
// Map the normal memory handlers
SekDbgDisableBreakpoints();
+#ifdef FBA_DEBUG
+ SekDbgFetchByteDisassembler = &SekFetchByte;
+ SekDbgFetchWordDisassembler = &SekFetchWord;
+ SekDbgFetchLongDisassembler = &SekFetchLong;
+#endif
+
#ifdef EMU_A68K
- if (bBurnUseASMCPUEmulation && nCPUType == 0x68000) {
- if (SekInitCPUA68K(nCount, nCPUType)) {
- SekExit();
- return 1;
- }
- }
- else
+ if(nSekCpuCore == SEK_CORE_A68K)
{
+ if (nCPUType == 0x68000)
+ {
+ if (SekInitCPUA68K(nCount, nCPUType))
+ {
+ SekExit();
+ return 1;
+ }
+ }
+ }
#endif
-#if defined(EMU_M68K)
- m68k_init();
- if (SekInitCPUM68K(nCount, nCPUType))
+#ifdef EMU_M68K
+ if(nSekCpuCore == SEK_CORE_M68K)
+ {
+ m68k_init();
+ if (SekInitCPUM68K(nCount, nCPUType))
{
- SekExit();
- return 1;
- }
-#elif defined(EMU_C68K)
+ SekExit();
+ return 1;
+ }
+ }
+#endif
+
+#ifdef EMU_C68K
+ if(nSekCpuCore == SEK_CORE_C68K)
+ {
if(SekInitCPUC68K(nCount, nCPUType))
{
SekExit();
return 1;
}
C68k_Init( SekC68KCurrentContext );
+ }
#endif
-#ifdef EMU_A68K
- }
-#endif
-
- nSekCycles[nCount] = 0;
+ nSekCycles[nCount] = 0;
nSekIRQPending[nCount] = 0;
- nSekCyclesTotal = 0;
- nSekCyclesScanline = 0;
+ nSekCyclesTotal = 0;
+ nSekCyclesScanline = 0;
CpuCheatRegister(nCount, &SekCheatCpuConfig);
@@ -1080,20 +1090,16 @@ INT32 SekInit(INT32 nCount, INT32 nCPUType)
#ifdef EMU_A68K
static void SekCPUExitA68K(INT32 i)
{
- if (SekRegs[i]) {
- free(SekRegs[i]);
- SekRegs[i] = NULL;
- }
+ free(SekRegs[i]);
+ SekRegs[i] = NULL;
}
#endif
#ifdef EMU_M68K
static void SekCPUExitM68K(INT32 i)
{
- if(SekM68KContext[i]) {
- free(SekM68KContext[i]);
- SekM68KContext[i] = NULL;
- }
+ free(SekM68KContext[i]);
+ SekM68KContext[i] = NULL;
}
#endif
@@ -1105,33 +1111,31 @@ static void SekCPUExitC68K(INT32 i)
}
#endif
-INT32 SekExit()
+INT32 SekExit(void)
{
+ INT32 i;
// Deallocate cpu extenal data (memory map etc)
- for (INT32 i = 0; i <= nSekCount; i++) {
-
+ for (i = 0; i <= nSekCount; i++)
+ {
#ifdef EMU_A68K
- SekCPUExitA68K(i);
+ if(nSekCpuCore == SEK_CORE_A68K) SekCPUExitA68K(i);
#endif
#ifdef EMU_M68K
- SekCPUExitM68K(i);
+ if(nSekCpuCore == SEK_CORE_M68K) SekCPUExitM68K(i);
#endif
#ifdef EMU_C68K
- SekCPUExitC68K(i);
+ if(nSekCpuCore == SEK_CORE_C68K) SekCPUExitC68K(i);
#endif
- // Deallocate other context data
- if (SekExt[i]) {
- free(SekExt[i]);
- SekExt[i] = NULL;
- }
+ /* Deallocate other context data */
+ free(SekExt[i]);
+ SekExt[i] = NULL;
}
#ifdef EMU_C68K
- C68k_Exit();
+ if(nSekCpuCore == SEK_CORE_C68K) C68k_Exit();
#endif
-
pSekExt = NULL;
nSekActive = -1;
@@ -1140,34 +1144,31 @@ INT32 SekExit()
return 0;
}
-void SekReset()
+void SekReset(void)
{
-#if defined FBA_DEBUG
- if (!DebugCPU_SekInitted) bprintf(PRINT_ERROR, _T("SekReset called without init\n"));
- if (nSekActive == -1) bprintf(PRINT_ERROR, _T("SekReset called when no CPU open\n"));
-#endif
-
#ifdef EMU_A68K
- if (nSekCPUType[nSekActive] == 0) {
+ if(nSekCpuCore == SEK_CORE_A68K)
+ {
// A68K has no internal support for resetting the processor, so do what's needed ourselves
M68000_regs.a[7] = FetchLong(0); // Get initial stackpointer (register A7)
M68000_regs.pc = FetchLong(4); // Get initial PC
M68000_regs.srh = 0x27; // start in supervisor state
A68KChangePC(M68000_regs.pc);
- } else {
+ }
#endif
-#if defined(EMU_M68K)
- m68k_pulse_reset();
-#elif defined(EMU_C68K)
- C68k_Reset( SekC68KCurrentContext );
+#ifdef EMU_M68K
+ if(nSekCpuCore == SEK_CORE_M68K) m68k_pulse_reset();
#endif
-
-#ifdef EMU_A68K
- }
+#ifdef EMU_C68K
+ if(nSekCpuCore == SEK_CORE_C68K) C68k_Reset( SekC68KCurrentContext );
#endif
+#ifdef FBA_DEBUG
+ if(DebugStep)
+ SekDbgEnableSingleStep();
+#endif
}
// ----------------------------------------------------------------------------
@@ -1176,35 +1177,26 @@ void SekReset()
// Open a CPU
void SekOpen(const INT32 i)
{
-#if defined FBA_DEBUG
- if (!DebugCPU_SekInitted) bprintf(PRINT_ERROR, _T("SekOpen called without init\n"));
- if (i > nSekCount) bprintf(PRINT_ERROR, _T("SekOpen called with invalid index %x\n"), i);
- if (nSekActive != -1) bprintf(PRINT_ERROR, _T("SekOpen called when CPU already open with index %x\n"), i);
-#endif
-
- if (i != nSekActive) {
+ if (i != nSekActive)
+ {
nSekActive = i;
- pSekExt = SekExt[nSekActive]; // Point to cpu context
+ pSekExt = SekExt[nSekActive]; /* Point to cpu context */
#ifdef EMU_A68K
- if (nSekCPUType[nSekActive] == 0)
+ if(nSekCpuCore == SEK_CORE_A68K)
{
memcpy(&M68000_regs, SekRegs[nSekActive], sizeof(M68000_regs));
A68KChangePC(M68000_regs.pc);
}
- else
- {
#endif
-#if defined(EMU_M68K)
- m68k_set_context(SekM68KContext[nSekActive]);
-#elif defined(EMU_C68K)
- SekC68KCurrentContext = SekC68KContext[nSekActive];
+#ifdef EMU_M68K
+ if(nSekCpuCore == SEK_CORE_M68K) m68k_set_context(SekM68KContext[nSekActive]);
#endif
-#ifdef EMU_A68K
- }
+#ifdef EMU_C68K
+ if(nSekCpuCore == SEK_CORE_C68K) SekC68KCurrentContext = SekC68KContext[nSekActive];
#endif
nSekCyclesTotal = nSekCycles[nSekActive];
@@ -1212,20 +1204,15 @@ void SekOpen(const INT32 i)
}
// Close the active cpu
-void SekClose()
+void SekClose(void)
{
#ifdef EMU_A68K
- if (nSekCPUType[nSekActive] == 0) {
- memcpy(SekRegs[nSekActive], &M68000_regs, sizeof(M68000_regs));
- } else {
+ if(nSekCpuCore == SEK_CORE_A68K)
+ memcpy(SekRegs[nSekActive], &M68000_regs, sizeof(M68000_regs));
#endif
#ifdef EMU_M68K
- m68k_get_context(SekM68KContext[nSekActive]);
-#endif
-
-#ifdef EMU_A68K
- }
+ if(nSekCpuCore == SEK_CORE_M68K) m68k_get_context(SekM68KContext[nSekActive]);
#endif
nSekCycles[nSekActive] = nSekCyclesTotal;
@@ -1234,38 +1221,42 @@ void SekClose()
}
// Get the current CPU
-INT32 SekGetActive()
+INT32 SekGetActive(void)
{
return nSekActive;
}
// Set the status of an IRQ line on the active CPU
-void SekSetIRQLine(const INT32 line, const INT32 status)
+void SekSetIRQLine(const INT32 line, const INT32 nstatus)
{
+ INT32 status = nstatus << 12; /* needed for compatibility */
- if (status) {
+ if (status)
+ {
nSekIRQPending[nSekActive] = line | status;
#ifdef EMU_A68K
- if (nSekCPUType[nSekActive] == 0) {
+ if(nSekCpuCore == SEK_CORE_A68K)
+ {
nSekCyclesTotal += (nSekCyclesToDo - nSekCyclesDone) - m68k_ICount;
nSekCyclesDone += (nSekCyclesToDo - nSekCyclesDone) - m68k_ICount;
M68000_regs.irq = line;
m68k_ICount = nSekCyclesToDo = -1; // Force A68K to exit
- } else {
+ }
#endif
-#if defined(EMU_M68K)
- m68k_set_irq(line);
-#elif defined(EMU_C68K)
+#ifdef EMU_M68K
+ if(nSekCpuCore == SEK_CORE_M68K) m68k_set_irq(line);
+#endif
+
+#ifdef EMU_C68K
+ if(nSekCpuCore == SEK_CORE_C68K)
+ {
SekC68KCurrentContext->IRQState = 1; //ASSERT_LINE
SekC68KCurrentContext->IRQLine = line;
SekC68KCurrentContext->HaltState = 0;
-#endif
-
-#ifdef EMU_A68K
- }
+ }
#endif
return;
@@ -1274,20 +1265,20 @@ void SekSetIRQLine(const INT32 line, const INT32 status)
nSekIRQPending[nSekActive] = 0;
#ifdef EMU_A68K
- if (nSekCPUType[nSekActive] == 0) {
+ if (nSekCPUType[nSekActive] == 0)
M68000_regs.irq &= 0x78;
- } else {
#endif
-#if defined(EMU_M68K)
- m68k_set_irq(0);
-#elif defined(EMU_C68K)
- SekC68KCurrentContext->IRQState = 0; //CLEAR_LINE
- SekC68KCurrentContext->IRQLine = 0;
+#ifdef EMU_M68K
+ if(nSekCpuCore == SEK_CORE_M68K) m68k_set_irq(0);
#endif
-#ifdef EMU_A68K