2 Skelton for retropc emulator
5 Author : Takeda.Toshiya
15 #define NMI_VEC 0xfffa
16 #define RST_VEC 0xfffc
17 #define IRQ_VEC 0xfffe
29 // some shortcuts for improved readability
52 // virtual machine interface
53 #define RDMEM_ID(addr) d_mem->read_data8(addr)
54 #define WRMEM_ID(addr, data) d_mem->write_data8(addr, data)
56 #define RDOP() d_mem->read_data8(PCW++)
57 #define PEEKOP() d_mem->read_data8(PCW)
58 #define RDOPARG() d_mem->read_data8(PCW++)
60 #define RDMEM(addr) d_mem->read_data8(addr)
61 #define WRMEM(addr, data) d_mem->write_data8(addr, data)
63 #define CYCLES(c) icount -= (c)
66 #define PUSH(Rg) WRMEM(SPD, Rg); S--
67 #define PULL(Rg) S++; Rg = RDMEM(SPD)
69 void M6502_BASE::OP(uint8_t code)
73 inline void M6502_BASE::update_irq()
84 // call back the cpuintrf to let it clear the line
85 d_pic->notify_intr_reti();
93 void M6502_BASE::initialize()
97 SPD = EAD = ZPD = PCD = 0;
100 void M6502_BASE::reset()
102 PCL = RDMEM(RST_VEC);
103 PCH = RDMEM(RST_VEC + 1);
105 P = F_T | F_I | F_Z | F_B | (P & F_D);
108 pending_irq = after_cli = false;
109 irq_state = nmi_state = so_state = false;
112 int M6502_BASE::run(int clock)
119 // run only one opcode
126 int first_icount = icount;
128 // run cpu while given clocks
129 while(icount > 0 && !busreq) {
132 // if busreq is raised, spin cpu while remained clock
133 if(icount > 0 && busreq) {
136 return first_icount - icount;
140 void M6502_BASE::run_one_opecode()
142 int first_icount = icount;
143 // if an irq is pending, take it now
150 P |= F_I; // set I flag
152 PCH = RDMEM(EAD + 1);
154 } else if(pending_irq) {
155 if(d_debugger != NULL) d_debugger->add_cpu_trace(PCW);
159 uint8_t code = RDOP();
162 // check if the I flag was just reset (interrupts enabled)
168 } else if(pending_irq) {
172 void M6502_BASE::write_signal(int id, uint32_t data, uint32_t mask)
174 bool state = ((data & mask) != 0);
176 if(id == SIG_CPU_NMI) {
178 } else if(id == SIG_CPU_IRQ) {
183 } else if(id == SIG_M6502_OVERFLOW) {
184 if(so_state && !state) {
188 } else if(id == SIG_CPU_BUSREQ) {
189 busreq = ((data & mask) != 0);
193 //#ifdef USE_DEBUGGER
194 void M6502_BASE::write_debug_data8(uint32_t addr, uint32_t data)
197 d_mem_stored->write_data8w(addr, data, &wait);
200 uint32_t M6502_BASE::read_debug_data8(uint32_t addr)
203 return d_mem_stored->read_data8w(addr, &wait);
206 bool M6502_BASE::write_debug_reg(const _TCHAR *reg, uint32_t data)
208 if(_tcsicmp(reg, _T("PC")) == 0) {
210 } else if(_tcsicmp(reg, _T("A")) == 0) {
212 } else if(_tcsicmp(reg, _T("X")) == 0) {
214 } else if(_tcsicmp(reg, _T("Y")) == 0) {
216 } else if(_tcsicmp(reg, _T("S")) == 0) {
218 } else if(_tcsicmp(reg, _T("P")) == 0) {
226 void M6502_BASE::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
228 my_stprintf_s(buffer, buffer_len,
229 _T("PC = %04X A = %02X X = %02X Y = %02X S = %02X P = %02X [%c%c%c%c%c%c%c%c]\nClocks = %llu (%llu) Since Scanline = %d/%d (%d/%d)"),
231 (P & F_N) ? _T('N') : _T('-'), (P & F_V) ? _T('V') : _T('-'), (P & F_T) ? _T('T') : _T('-'), (P & F_B) ? _T('B') : _T('-'),
232 (P & F_D) ? _T('D') : _T('-'), (P & F_I) ? _T('I') : _T('-'), (P & F_Z) ? _T('Z') : _T('-'), (P & F_C) ? _T('C') : _T('-'),
233 total_icount, total_icount - prev_total_icount,
234 get_passed_clock_since_vline(), get_cur_vline_clocks(), get_cur_vline(), get_lines_per_frame());
235 prev_total_icount = total_icount;
240 #define offs_t UINT16
242 /*****************************************************************************/
243 /* src/emu/devcpu.h */
245 // CPU interface functions
246 #define CPU_DISASSEMBLE_NAME(name) cpu_disassemble_##name
247 #define CPU_DISASSEMBLE(name) int CPU_DISASSEMBLE_NAME(name)(_TCHAR *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, symbol_t *first_symbol)
248 #define CPU_DISASSEMBLE_CALL(name) CPU_DISASSEMBLE_NAME(name)(buffer, pc, oprom, oprom, d_debugger->first_symbol)
250 /*****************************************************************************/
251 /* src/emu/didisasm.h */
253 // Disassembler constants
254 const UINT32 DASMFLAG_SUPPORTED = 0x80000000; // are disassembly flags supported?
255 const UINT32 DASMFLAG_STEP_OUT = 0x40000000; // this instruction should be the end of a step out sequence
256 const UINT32 DASMFLAG_STEP_OVER = 0x20000000; // this instruction should be stepped over by setting a breakpoint afterwards
257 const UINT32 DASMFLAG_OVERINSTMASK = 0x18000000; // number of extra instructions to skip when stepping over
258 const UINT32 DASMFLAG_OVERINSTSHIFT = 27; // bits to shift after masking to get the value
259 //const UINT32 DASMFLAG_LENGTHMASK = 0x0000ffff; // the low 16-bits contain the actual length
261 #include "mame/emu/cpu/m6502/6502dasm.c"
263 int M6502_BASE::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)