2 Skelton for retropc emulator
5 Author : Takeda.Toshiya
16 #if defined(HAS_UPD7810)
17 #define CPU_MODEL upd7810
18 #elif defined(HAS_UPD7807)
19 #define CPU_MODEL upd7807
20 #elif defined(HAS_UPD7801)
21 #define CPU_MODEL upd7801
22 #elif defined(HAS_UPD78C05)
23 #define CPU_MODEL upd78c05
24 #elif defined(HAS_UPD78C06)
25 #define CPU_MODEL upd78c06
26 #elif defined(HAS_UPD7907)
27 #define CPU_MODEL upd7907
30 /* ----------------------------------------------------------------------------
32 ---------------------------------------------------------------------------- */
37 /*****************************************************************************/
38 /* src/emu/devcpu.h */
40 // CPU interface functions
41 #define CPU_INIT_NAME(name) cpu_init_##name
42 #define CPU_INIT(name) void* CPU_INIT_NAME(name)()
43 #define CPU_INIT_CALL(name) CPU_INIT_NAME(name)()
45 #define CPU_RESET_NAME(name) cpu_reset_##name
46 #define CPU_RESET(name) void CPU_RESET_NAME(name)(upd7810_state *cpustate)
47 #define CPU_RESET_CALL(name) CPU_RESET_NAME(name)(cpustate)
49 #define CPU_EXECUTE_NAME(name) cpu_execute_##name
50 #define CPU_EXECUTE(name) int CPU_EXECUTE_NAME(name)(upd7810_state *cpustate)
51 #define CPU_EXECUTE_CALL(name) CPU_EXECUTE_NAME(name)(cpustate)
53 #define CPU_DISASSEMBLE_NAME(name) cpu_disassemble_##name
54 #define CPU_DISASSEMBLE(name) int CPU_DISASSEMBLE_NAME(name)(_TCHAR *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, symbol_t *first_symbol)
55 #define CPU_DISASSEMBLE_CALL(name) CPU_DISASSEMBLE_NAME(name)(buffer, pc, oprom, oprom, d_debugger->first_symbol)
57 /*****************************************************************************/
58 /* src/emu/didisasm.h */
60 // Disassembler constants
61 const UINT32 DASMFLAG_SUPPORTED = 0x80000000; // are disassembly flags supported?
62 const UINT32 DASMFLAG_STEP_OUT = 0x40000000; // this instruction should be the end of a step out sequence
63 const UINT32 DASMFLAG_STEP_OVER = 0x20000000; // this instruction should be stepped over by setting a breakpoint afterwards
64 const UINT32 DASMFLAG_OVERINSTMASK = 0x18000000; // number of extra instructions to skip when stepping over
65 const UINT32 DASMFLAG_OVERINSTSHIFT = 27; // bits to shift after masking to get the value
66 const UINT32 DASMFLAG_LENGTHMASK = 0x0000ffff; // the low 16-bits contain the actual length
68 /*****************************************************************************/
69 /* src/emu/diexec.h */
74 CLEAR_LINE = 0, // clear (a fired or held) line
75 ASSERT_LINE // assert an interrupt immediately
88 #define fatalerror(...)
93 #include "mame/emu/cpu/upd7810/upd7810.c"
96 #include "mame/emu/cpu/upd7810/7810dasm.c"
101 void UPD7810::initialize()
103 DEVICE::initialize();
104 opaque = CPU_INIT_CALL(upd7810);
106 upd7810_state *cpustate = (upd7810_state *)opaque;
107 #if defined(HAS_UPD7810)
108 cpustate->config.type = TYPE_7810;
109 #elif defined(HAS_UPD7807)
110 cpustate->config.type = TYPE_7807;
111 #elif defined(HAS_UPD7801)
112 cpustate->config.type = TYPE_7801;
113 #elif defined(HAS_UPD78C05)
114 cpustate->config.type = TYPE_78C05;
115 #elif defined(HAS_UPD78C06)
116 cpustate->config.type = TYPE_78C06;
117 #elif defined(HAS_UPD7907)
118 cpustate->config.type = TYPE_78C06;
120 cpustate->program = d_mem;
122 cpustate->outputs_to = (void*)&outputs_to;
123 cpustate->outputs_txd = (void*)&outputs_txd;
126 cpustate->debugger = d_debugger;
127 cpustate->program_stored = d_mem;
128 cpustate->io_stored = d_io;
130 d_debugger->set_context_mem(d_mem);
131 d_debugger->set_context_io(d_io);
135 void UPD7810::release()
140 void UPD7810::reset()
142 upd7810_state *cpustate = (upd7810_state *)opaque;
144 CPU_RESET_CALL(CPU_MODEL);
146 cpustate->program = d_mem;
148 cpustate->outputs_to = (void*)&outputs_to;
149 cpustate->outputs_txd = (void*)&outputs_txd;
152 cpustate->debugger = d_debugger;
153 cpustate->program_stored = d_mem;
154 cpustate->io_stored = d_io;
160 int UPD7810::run(int clock)
162 upd7810_state *cpustate = (upd7810_state *)opaque;
169 // run only one opcode
170 return CPU_EXECUTE_CALL(upd7810);
174 int first_icount = icount;
176 // run cpu while given clocks
177 while(icount > 0 && !busreq) {
178 icount -= CPU_EXECUTE_CALL(upd7810);
180 // if busreq is raised, spin cpu while remained clock
181 if(icount > 0 && busreq) {
184 return first_icount - icount;
188 void UPD7810::write_signal(int id, uint32_t data, uint32_t mask)
190 upd7810_state *cpustate = (upd7810_state *)opaque;
193 case SIG_UPD7810_INTF1:
194 set_irq_line(cpustate, UPD7810_INTF1, (data & mask) ? ASSERT_LINE : CLEAR_LINE);
196 case SIG_UPD7810_INTF2:
197 set_irq_line(cpustate, UPD7810_INTF2, (data & mask) ? ASSERT_LINE : CLEAR_LINE);
199 case SIG_UPD7810_INTF0:
200 set_irq_line(cpustate, UPD7810_INTF0, (data & mask) ? ASSERT_LINE : CLEAR_LINE);
202 case SIG_UPD7810_INTFE1:
203 set_irq_line(cpustate, UPD7810_INTFE1, (data & mask) ? ASSERT_LINE : CLEAR_LINE);
205 case SIG_UPD7810_NMI:
206 set_irq_line(cpustate, INPUT_LINE_NMI, (data & mask) ? ASSERT_LINE : CLEAR_LINE);
209 busreq = ((data & mask) != 0);
214 uint32_t UPD7810::get_pc()
216 upd7810_state *cpustate = (upd7810_state *)opaque;
217 return cpustate->ppc.w.l;
220 uint32_t UPD7810::get_next_pc()
222 upd7810_state *cpustate = (upd7810_state *)opaque;
223 return cpustate->pc.w.l;
227 void UPD7810::write_debug_data8(uint32_t addr, uint32_t data)
230 d_mem->write_data8w(addr, data, &wait);
233 uint32_t UPD7810::read_debug_data8(uint32_t addr)
236 return d_mem->read_data8w(addr, &wait);
239 void UPD7810::write_debug_io8(uint32_t addr, uint32_t data)
242 d_io->write_io8w(addr, data, &wait);
245 uint32_t UPD7810::read_debug_io8(uint32_t addr) {
247 return d_io->read_io8w(addr, &wait);
250 bool UPD7810::write_debug_reg(const _TCHAR *reg, uint32_t data)
252 upd7810_state *cpustate = (upd7810_state *)opaque;
254 if(_tcsicmp(reg, _T("PC")) == 0) {
256 } else if(_tcsicmp(reg, _T("SP")) == 0) {
258 } else if(_tcsicmp(reg, _T("VA")) == 0) {
260 } else if(_tcsicmp(reg, _T("BC")) == 0) {
262 } else if(_tcsicmp(reg, _T("DE")) == 0) {
264 } else if(_tcsicmp(reg, _T("HL")) == 0) {
266 } else if(_tcsicmp(reg, _T("V")) == 0) {
268 } else if(_tcsicmp(reg, _T("A")) == 0) {
270 } else if(_tcsicmp(reg, _T("B")) == 0) {
272 } else if(_tcsicmp(reg, _T("C")) == 0) {
274 } else if(_tcsicmp(reg, _T("D")) == 0) {
276 } else if(_tcsicmp(reg, _T("E")) == 0) {
278 } else if(_tcsicmp(reg, _T("H")) == 0) {
280 } else if(_tcsicmp(reg, _T("L")) == 0) {
282 } else if(_tcsicmp(reg, _T("VA'")) == 0) {
284 } else if(_tcsicmp(reg, _T("BC'")) == 0) {
286 } else if(_tcsicmp(reg, _T("DE'")) == 0) {
288 } else if(_tcsicmp(reg, _T("HL'")) == 0) {
290 } else if(_tcsicmp(reg, _T("V'")) == 0) {
292 } else if(_tcsicmp(reg, _T("A'")) == 0) {
294 } else if(_tcsicmp(reg, _T("B'")) == 0) {
296 } else if(_tcsicmp(reg, _T("C'")) == 0) {
298 } else if(_tcsicmp(reg, _T("D'")) == 0) {
300 } else if(_tcsicmp(reg, _T("E'")) == 0) {
302 } else if(_tcsicmp(reg, _T("H'")) == 0) {
304 } else if(_tcsicmp(reg, _T("L'")) == 0) {
312 void UPD7810::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
315 VA = 0000 BC = 0000 DE = 0000 HL = 0000 PSW= 00 [Z SK HC L1 L0 CY]
316 VA'= 0000 BC'= 0000 DE'= 0000 HL'= 0000 SP = 0000 PC = 0000
317 (BC)= 0000 (DE)=0000 (HL)= 0000 (SP)= 0000 <DI>
319 upd7810_state *cpustate = (upd7810_state *)opaque;
321 my_stprintf_s(buffer, buffer_len,
322 _T("VA = %04X BC = %04X DE = %04X HL = %04X PSW= %02x [%s %s %s %s %s %s]\nVA'= %04X BC'= %04X DE'= %04X HL'= %04X SP = %04X PC = %04X\n (BC)= %04X (DE)=%04X (HL)= %04X (SP)= %04X <%s>"),
324 (PSW & Z) ? _T("Z") : _T("-"), (PSW & SK) ? _T("SK") : _T("--"), (PSW & HC) ? _T("HC") : _T("--"), (PSW & L1) ? _T("L1") : _T("--"), (PSW & L0) ? _T("L0") : _T("--"), (PSW & CY) ? _T("CY") : _T("--"),
325 VA2, BC2, DE2, HL2, SP, PC,
326 d_mem->read_data16w(BC, &wait), d_mem->read_data16w(DE, &wait), d_mem->read_data16w(HL, &wait), d_mem->read_data16w(SP, &wait),
327 IFF ? _T("EI") : _T("DI"));
332 int UPD7810::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
335 uint8_t *opram = oprom;
337 for(int i = 0; i < 8; i++) {
339 oprom[i] = d_mem->read_data8w(pc + i, &wait);
341 return CPU_DISASSEMBLE_CALL(CPU_MODEL) & DASMFLAG_LENGTHMASK;
345 #define STATE_VERSION 3
347 void UPD7810::save_state(FILEIO* state_fio)
349 state_fio->FputUint32(STATE_VERSION);
350 state_fio->FputInt32(this_device_id);
352 state_fio->Fwrite(opaque, sizeof(upd7810_state), 1);
353 state_fio->FputInt32(icount);
354 state_fio->FputBool(busreq);
357 bool UPD7810::load_state(FILEIO* state_fio)
359 if(state_fio->FgetUint32() != STATE_VERSION) {
362 if(state_fio->FgetInt32() != this_device_id) {
365 state_fio->Fread(opaque, sizeof(upd7810_state), 1);
366 icount = state_fio->FgetInt32();
367 busreq = state_fio->FgetBool();
370 upd7810_state *cpustate = (upd7810_state *)opaque;
371 cpustate->program = d_mem;
373 cpustate->outputs_to = (void*)&outputs_to;
374 cpustate->outputs_txd = (void*)&outputs_txd;
377 cpustate->debugger = d_debugger;
378 cpustate->program_stored = d_mem;
379 cpustate->io_stored = d_io;