OSDN Git Service

[VM] Add PC-8001/mk2/8801/mk2.
[csp-qt/common_source_project-fm7.git] / source / src / vm / upd7810.cpp
index dc3b7c6..afd4b43 100644 (file)
@@ -31,7 +31,7 @@
        MAME uPD7810
 ---------------------------------------------------------------------------- */
 
-#define PAIR pair_t
+#define PAIR pair32_t
 #define offs_t UINT16
 
 /*****************************************************************************/
@@ -164,10 +164,13 @@ int UPD7810::run(int clock)
        if(clock == -1) {
                if(busreq) {
                        // don't run cpu!
+#ifdef USE_DEBUGGER
+                       total_icount += 1;
+#endif
                        return 1;
                } else {
                        // run only one opcode
-                       return CPU_EXECUTE_CALL(upd7810);
+                       return run_one_opecode();
                }
        } else {
                icount += clock;
@@ -175,16 +178,32 @@ int UPD7810::run(int clock)
                
                // run cpu while given clocks
                while(icount > 0 && !busreq) {
-                       icount -= CPU_EXECUTE_CALL(upd7810);
+                       icount -= run_one_opecode();
                }
                // if busreq is raised, spin cpu while remained clock
                if(icount > 0 && busreq) {
+#ifdef USE_DEBUGGER
+                       total_icount += icount;
+#endif
                        icount = 0;
                }
                return first_icount - icount;
        }
 }
 
+int UPD7810::run_one_opecode()
+{
+#ifdef USE_DEBUGGER
+       upd7810_state *cpustate = (upd7810_state *)opaque;
+       d_debugger->add_cpu_trace(cpustate->pc.w.l);
+#endif
+       int passed_icount = CPU_EXECUTE_CALL(upd7810);
+#ifdef USE_DEBUGGER
+       total_icount += passed_icount;
+#endif
+       return passed_icount;
+}
+
 void UPD7810::write_signal(int id, uint32_t data, uint32_t mask)
 {
        upd7810_state *cpustate = (upd7810_state *)opaque;
@@ -315,16 +334,20 @@ void UPD7810::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
 VA = 0000  BC = 0000  DE = 0000 HL = 0000  PSW= 00 [Z SK HC L1 L0 CY]
 VA'= 0000  BC'= 0000  DE'= 0000 HL'= 0000  SP = 0000  PC = 0000
           (BC)= 0000 (DE)=0000 (HL)= 0000 (SP)= 0000 <DI>
+Clocks = 0 (0)  Since Scanline = 0/0 (0/0)
 */
        upd7810_state *cpustate = (upd7810_state *)opaque;
        int wait;
        my_stprintf_s(buffer, buffer_len,
-       _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>"),
+       _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>\nClocks = %llu (%llu) Since Scanline = %d/%d (%d/%d)"),
        VA, BC, DE, HL, PSW,
        (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("--"),
        VA2, BC2, DE2, HL2, SP, PC,
        d_mem->read_data16w(BC, &wait), d_mem->read_data16w(DE, &wait), d_mem->read_data16w(HL, &wait), d_mem->read_data16w(SP, &wait),
-       IFF ? _T("EI") : _T("DI"));
+       IFF ? _T("EI") : _T("DI"),
+       total_icount, total_icount - prev_total_icount,
+       get_passed_clock_since_vline(), get_cur_vline_clocks(), get_cur_vline(), get_lines_per_frame());
+       prev_total_icount = total_icount;
 }
 
 // disassembler
@@ -342,41 +365,108 @@ int UPD7810::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
 }
 #endif
 
-#define STATE_VERSION  3
-
-void UPD7810::save_state(FILEIO* state_fio)
-{
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
-       state_fio->Fwrite(opaque, sizeof(upd7810_state), 1);
-       state_fio->FputInt32(icount);
-       state_fio->FputBool(busreq);
-}
+#define STATE_VERSION  5
 
-bool UPD7810::load_state(FILEIO* state_fio)
+bool UPD7810::process_state(FILEIO* state_fio, bool loading)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
-       state_fio->Fread(opaque, sizeof(upd7810_state), 1);
-       icount = state_fio->FgetInt32();
-       busreq = state_fio->FgetBool();
-       
-       // post process
        upd7810_state *cpustate = (upd7810_state *)opaque;
-       cpustate->program = d_mem;
-       cpustate->io = d_io;
-       cpustate->outputs_to = (void*)&outputs_to;
-       cpustate->outputs_txd = (void*)&outputs_txd;
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateValue(cpustate->ppc);
+       state_fio->StateValue(cpustate->pc);
+       state_fio->StateValue(cpustate->sp);
+       state_fio->StateValue(cpustate->op);
+       state_fio->StateValue(cpustate->op2);
+       state_fio->StateValue(cpustate->iff);
+       state_fio->StateValue(cpustate->softi);
+       state_fio->StateValue(cpustate->psw);
+       state_fio->StateValue(cpustate->ea);
+       state_fio->StateValue(cpustate->va);
+       state_fio->StateValue(cpustate->bc);
+       state_fio->StateValue(cpustate->de);
+       state_fio->StateValue(cpustate->hl);
+       state_fio->StateValue(cpustate->ea2);
+       state_fio->StateValue(cpustate->va2);
+       state_fio->StateValue(cpustate->bc2);
+       state_fio->StateValue(cpustate->de2);
+       state_fio->StateValue(cpustate->hl2);
+       state_fio->StateValue(cpustate->cnt);
+       state_fio->StateValue(cpustate->tm);
+       state_fio->StateValue(cpustate->ecnt);
+       state_fio->StateValue(cpustate->etm);
+       state_fio->StateValue(cpustate->ma);
+       state_fio->StateValue(cpustate->mb);
+       state_fio->StateValue(cpustate->mcc);
+       state_fio->StateValue(cpustate->mc);
+       state_fio->StateValue(cpustate->mm);
+       state_fio->StateValue(cpustate->mf);
+       state_fio->StateValue(cpustate->tmm);
+       state_fio->StateValue(cpustate->etmm);
+       state_fio->StateValue(cpustate->eom);
+       state_fio->StateValue(cpustate->sml);
+       state_fio->StateValue(cpustate->smh);
+       state_fio->StateValue(cpustate->anm);
+       state_fio->StateValue(cpustate->mkl);
+       state_fio->StateValue(cpustate->mkh);
+       state_fio->StateValue(cpustate->zcm);
+       state_fio->StateValue(cpustate->pa_in);
+       state_fio->StateValue(cpustate->pb_in);
+       state_fio->StateValue(cpustate->pc_in);
+       state_fio->StateValue(cpustate->pd_in);
+       state_fio->StateValue(cpustate->pf_in);
+       state_fio->StateValue(cpustate->pa_out);
+       state_fio->StateValue(cpustate->pb_out);
+       state_fio->StateValue(cpustate->pc_out);
+       state_fio->StateValue(cpustate->pd_out);
+       state_fio->StateValue(cpustate->pf_out);
+       state_fio->StateValue(cpustate->cr0);
+       state_fio->StateValue(cpustate->cr1);
+       state_fio->StateValue(cpustate->cr2);
+       state_fio->StateValue(cpustate->cr3);
+       state_fio->StateValue(cpustate->txb);
+       state_fio->StateValue(cpustate->rxb);
+       state_fio->StateValue(cpustate->txd);
+       state_fio->StateValue(cpustate->rxd);
+       state_fio->StateValue(cpustate->sck);
+       state_fio->StateValue(cpustate->ti);
+       state_fio->StateValue(cpustate->to);
+       state_fio->StateValue(cpustate->ci);
+       state_fio->StateValue(cpustate->co0);
+       state_fio->StateValue(cpustate->co1);
+       state_fio->StateValue(cpustate->irr);
+       state_fio->StateValue(cpustate->itf);
+       state_fio->StateValue(cpustate->int1);
+       state_fio->StateValue(cpustate->int2);
+       state_fio->StateValue(cpustate->txs);
+       state_fio->StateValue(cpustate->rxs);
+       state_fio->StateValue(cpustate->txcnt);
+       state_fio->StateValue(cpustate->rxcnt);
+       state_fio->StateValue(cpustate->txbuf);
+       state_fio->StateValue(cpustate->ovc0);
+       state_fio->StateValue(cpustate->ovc1);
+       state_fio->StateValue(cpustate->ovce);
+       state_fio->StateValue(cpustate->ovcf);
+       state_fio->StateValue(cpustate->ovcs);
+       state_fio->StateValue(cpustate->ovcsio);
+       state_fio->StateValue(cpustate->edges);
+       state_fio->StateValue(cpustate->icount);
 #ifdef USE_DEBUGGER
-       cpustate->emu = emu;
-       cpustate->debugger = d_debugger;
-       cpustate->program_stored = d_mem;
-       cpustate->io_stored = d_io;
+       state_fio->StateValue(total_icount);
 #endif
-       return true;
+       state_fio->StateValue(icount);
+       state_fio->StateValue(busreq);
+       state_fio->StateValue(icount);
+       state_fio->StateValue(busreq);
+       
+#ifdef USE_DEBUGGER
+       // post process
+       if(loading) {
+               prev_total_icount = total_icount;
+       }
+#endif
+       return true;
 }