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