15eb0001 |
1 | \r |
4abeeb4b |
2 | // This file is part of the PicoDrive Megadrive Emulator\r |
3 | \r |
4 | // This code is licensed under the GNU General Public License version 2.0 and the MAME License.\r |
5 | // You can choose the license that has the most advantages for you.\r |
6 | \r |
7 | // SVN repository can be found at http://code.google.com/p/cyclone68000/\r |
8 | \r |
15eb0001 |
9 | #include "PicoInt.h"\r |
10 | \r |
11 | char PicoStatus[128]=""; // 68000 state for debug\r |
12 | \r |
13 | #ifdef EMU_C68K\r |
14 | // ---------------------- Cyclone 68000 ----------------------\r |
15 | \r |
16 | struct Cyclone PicoCpu;\r |
17 | \r |
18 | int SekInit()\r |
19 | {\r |
20 | memset(&PicoCpu,0,sizeof(PicoCpu));\r |
21 | return 0;\r |
22 | }\r |
23 | \r |
24 | // Reset the 68000:\r |
25 | int SekReset()\r |
26 | {\r |
27 | if (Pico.rom==NULL) return 1;\r |
28 | \r |
29 | PicoCpu.srh =0x27; // Supervisor mode\r |
30 | PicoCpu.a[7]=PicoCpu.read32(0); // Stack Pointer\r |
31 | PicoCpu.membase=0;\r |
32 | PicoCpu.pc=PicoCpu.checkpc(PicoCpu.read32(4)); // Program Counter\r |
33 | \r |
34 | return 0;\r |
35 | }\r |
36 | \r |
37 | \r |
38 | // Run the 68000 for 'cyc' number of cycles and return the number of cycles actually executed\r |
39 | static inline int DoRun(int cyc)\r |
40 | {\r |
41 | PicoCpu.cycles=cyc;\r |
42 | CycloneRun(&PicoCpu);\r |
43 | return cyc-PicoCpu.cycles;\r |
44 | }\r |
45 | \r |
46 | int SekInterrupt(int irq)\r |
47 | {\r |
48 | PicoCpu.irq=(unsigned char)irq;\r |
49 | return 0;\r |
50 | }\r |
51 | \r |
52 | int SekPc() { return PicoCpu.pc-PicoCpu.membase; }\r |
53 | \r |
54 | void SekState(unsigned char *data)\r |
55 | {\r |
56 | memcpy(data,PicoCpu.d,0x44);\r |
57 | }\r |
58 | \r |
59 | #endif\r |
60 | \r |
61 | #ifdef EMU_A68K\r |
62 | // ---------------------- A68K ----------------------\r |
63 | \r |
64 | extern "C" void __cdecl M68000_RUN();\r |
65 | extern "C" void __cdecl M68000_RESET();\r |
66 | extern "C" int m68k_ICount=0;\r |
67 | extern "C" unsigned int mem_amask=0xffffff; // 24-bit bus\r |
68 | extern "C" unsigned int mame_debug=0,cur_mrhard=0,m68k_illegal_opcode=0,illegal_op=0,illegal_pc=0,opcode_entry=0; // filler\r |
69 | \r |
70 | static int IrqCallback(int) { return -1; }\r |
71 | static int DoReset() { return 0; }\r |
72 | static int (*ResetCallback)()=DoReset;\r |
73 | \r |
74 | int SekInit()\r |
75 | {\r |
76 | memset(&M68000_regs,0,sizeof(M68000_regs));\r |
77 | M68000_regs.IrqCallback=IrqCallback;\r |
78 | M68000_regs.pResetCallback=ResetCallback;\r |
79 | M68000_RESET(); // Init cpu emulator\r |
80 | return 0;\r |
81 | }\r |
82 | \r |
83 | int SekReset()\r |
84 | {\r |
85 | // Reset CPU: fetch SP and PC\r |
86 | M68000_regs.srh=0x27; // Supervisor mode\r |
87 | M68000_regs.a[7]=PicoRead32(0);\r |
88 | M68000_regs.pc =PicoRead32(4);\r |
89 | PicoInitPc(M68000_regs.pc);\r |
90 | \r |
91 | return 0;\r |
92 | }\r |
93 | \r |
94 | static inline int DoRun(int cyc)\r |
95 | {\r |
96 | m68k_ICount=cyc;\r |
97 | M68000_RUN();\r |
98 | return cyc-m68k_ICount;\r |
99 | }\r |
100 | \r |
101 | int SekInterrupt(int irq)\r |
102 | {\r |
103 | M68000_regs.irq=irq; // raise irq (gets lowered after taken)\r |
104 | return 0;\r |
105 | }\r |
106 | \r |
107 | int SekPc() { return M68000_regs.pc; }\r |
108 | \r |
109 | void SekState(unsigned char *data)\r |
110 | {\r |
111 | memcpy(data, M68000_regs.d, 0x40);\r |
112 | memcpy(data+0x40,&M68000_regs.pc,0x04);\r |
113 | }\r |
114 | \r |
115 | #endif\r |
116 | \r |
117 | #ifdef EMU_NULL\r |
118 | // -----------------------------------------------------------\r |
119 | int SekInit() { return 0; }\r |
120 | int SekReset() { return 0; }\r |
121 | static inline int DoRun(int cyc) { return cyc; }\r |
122 | int SekInterrupt(int) { return 0; }\r |
123 | \r |
124 | int SekPc()\r |
125 | {\r |
126 | return 0;\r |
127 | }\r |
128 | \r |
129 | void SekState(unsigned char *) { }\r |
130 | \r |
131 | #endif\r |
132 | \r |
133 | int SekRun(int cyc)\r |
134 | {\r |
135 | int did=0;\r |
136 | \r |
137 | did=DoRun(cyc);\r |
138 | \r |
139 | return did;\r |
140 | }\r |