OSDN Git Service

[GENERAL] Merge Upstream 2017-11-28.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 3 Dec 2017 07:58:05 +0000 (16:58 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 3 Dec 2017 07:58:05 +0000 (16:58 +0900)
85 files changed:
source/build-cmake/cmake/config_mz5500.cmake
source/build-cmake/cmake/config_pc98ha.cmake
source/build-cmake/fm16pi/CMakeLists.txt
source/build-cmake/fmr30_i286/CMakeLists.txt
source/build-cmake/fmr30_i86/CMakeLists.txt
source/build-cmake/pc100/CMakeLists.txt
source/history.txt
source/revision.txt
source/src/debugger.cpp
source/src/res/credits.html
source/src/res/j3100.rc
source/src/res/n5200.rc
source/src/vm/common_vm/CMakeLists.txt
source/src/vm/device.h
source/src/vm/fm16pi/fm16pi.h
source/src/vm/fmr30/fmr30.cpp
source/src/vm/fmr30/fmr30.h
source/src/vm/fmr50/bios.cpp
source/src/vm/fmr50/bios.h
source/src/vm/hd6301.cpp
source/src/vm/huc6280.cpp
source/src/vm/huc6280.h
source/src/vm/huc6280_base.cpp
source/src/vm/i286.cpp
source/src/vm/i386.cpp
source/src/vm/i8080.cpp
source/src/vm/i8080_base.cpp
source/src/vm/i8080_base.h
source/src/vm/j3100/j3100.cpp
source/src/vm/j3100/j3100.h
source/src/vm/jx/i286.cpp [new file with mode: 0644]
source/src/vm/jx/i286.h [new file with mode: 0644]
source/src/vm/jx/jx.cpp
source/src/vm/jx/jx.h
source/src/vm/libcpu_newdev/device.h
source/src/vm/libcpu_newdev/libcpu_i386/i386_opdef.cpp
source/src/vm/libcpu_newdev/libcpu_i386/i386_real.cpp
source/src/vm/libcpu_newdev/libcpu_i386/i386op16.cpp
source/src/vm/libcpu_newdev/libcpu_i386/i386op16_real.cpp
source/src/vm/libcpu_newdev/libcpu_i386/i386priv.h
source/src/vm/m6502.cpp
source/src/vm/m6502.h
source/src/vm/m6502_base.cpp
source/src/vm/mame/emu/cpu/i386/i386.c
source/src/vm/mame/emu/cpu/i386/i386op16.c
source/src/vm/mame/emu/cpu/i386/i386priv.h
source/src/vm/mame/emu/cpu/i86/i286.c
source/src/vm/mame/emu/cpu/i86/i86.c
source/src/vm/mame/emu/cpu/i86/instr86.c
source/src/vm/mc6800.cpp
source/src/vm/mc6800.h
source/src/vm/mc6801.cpp
source/src/vm/mz5500/mz5500.cpp
source/src/vm/mz5500/mz5500.h
source/src/vm/n5200/n5200.cpp
source/src/vm/n5200/n5200.h
source/src/vm/pc100/pc100.cpp
source/src/vm/pc100/pc100.h
source/src/vm/pc8801/pc88.cpp
source/src/vm/pc98ha/pc98ha.cpp
source/src/vm/pc98ha/pc98ha.h
source/src/vm/tms9995.cpp
source/src/vm/tms9995.h
source/src/vm/upd7801.cpp
source/src/vm/upd7801.h
source/src/vm/upd7810.cpp
source/src/vm/upd7810.h
source/src/vm/z80.cpp
source/vc++2008/j3100gt.vcproj
source/vc++2008/j3100sl.vcproj
source/vc++2008/jx.vcproj
source/vc++2008/n5200.vcproj
source/vc++2008/smb80te.vcproj
source/vc++2013/familybasic.vcxproj.filters
source/vc++2013/j3100gt.vcxproj
source/vc++2013/j3100gt.vcxproj.filters
source/vc++2013/j3100sl.vcxproj
source/vc++2013/j3100sl.vcxproj.filters
source/vc++2013/jx.vcxproj
source/vc++2013/jx.vcxproj.filters
source/vc++2013/n5200.vcxproj
source/vc++2013/n5200.vcxproj.filters
source/vc++2013/smb80te.vcxproj
source/vc++2013/smb80te.vcxproj.filters
source/vc++2013/yis.vcxproj.filters

index ed7257a..bc7e740 100644 (file)
@@ -7,7 +7,7 @@ set(WITH_JOYSTICK ON)
 set(WITH_MOUSE ON)
 
 set(VMFILES
-#                 i286.cpp
+                  i286.cpp
                   i8237.cpp
                   mz1p17.cpp
                   
@@ -47,12 +47,12 @@ set(CMAKE_SYSTEM_PROCESSOR ${ARCHITECTURE} CACHE STRING "Set processor to build.
 if(BUILD_MZ5500)
   add_definitions(-D_MZ5500)
   set(EXEC_TARGET emumz5500)
-  set(FLAG_USE_I86 ON)
+  set(FLAG_USE_I86 OFF)
   set(RESOURCE ${CMAKE_SOURCE_DIR}/../../src/qt/common/qrc/mz5500.qrc)
 elseif(BUILD_MZ6500)
   add_definitions(-D_MZ6500)
   set(EXEC_TARGET emumz6500)
-  set(FLAG_USE_I86 ON)
+  set(FLAG_USE_I86 OFF)
   set(RESOURCE ${CMAKE_SOURCE_DIR}/../../src/qt/common/qrc/mz6500.qrc)
 else()
   add_definitions(-D_MZ6550)
index b85c520..5578998 100644 (file)
@@ -5,6 +5,7 @@ set(WITH_JOYSTICK ON)
 set(WITH_MOUSE ON)
 
 set(VMFILES
+                  i286.cpp
                   event.cpp
                   io.cpp
                   memory.cpp
@@ -45,7 +46,7 @@ if(BUILD_PC98HA)
    set(VMFILES_LIB ${VMFILES_LIB}
                   upd4991a.cpp
    )
-   set(FLAG_USE_I86 ON)
+   set(FLAG_USE_I86 OFF)
    set(RESOURCE ${CMAKE_SOURCE_DIR}/../../src/qt/common/qrc/pc98ha.qrc)
 elseif(BUILD_PC98LT)
    add_definitions(-D_PC98LT)
@@ -53,7 +54,7 @@ elseif(BUILD_PC98LT)
    set(VMFILES ${VMFILES}
                   upd1990a.cpp
    )
-   set(FLAG_USE_I86 ON)
+   set(FLAG_USE_I86 OFF)
    set(RESOURCE ${CMAKE_SOURCE_DIR}/../../src/qt/common/qrc/pc98lt.qrc)
 endif()
 
index b160735..89f6a7c 100644 (file)
@@ -21,7 +21,7 @@ set(WITH_JOYSTICK OFF)
 set(WITH_MOUSE ON)
 
 set(VMFILES
-#                 i286.cpp
+                  i286.cpp
                   msm58321.cpp
                   event.cpp
                   io.cpp
@@ -43,7 +43,7 @@ set(VMFILES_LIB
                   ym2203.cpp
 )
 
-set(FLAG_USE_I86 ON)
+#set(FLAG_USE_I86 ON)
 set(BUILD_SHARED_LIBS OFF)
 set(USE_OPENMP ON CACHE BOOL "Build using OpenMP")
 set(USE_OPENGL ON CACHE BOOL "Build using OpenGL")
index df34220..3e1f0a8 100644 (file)
@@ -46,7 +46,10 @@ set(BUILD_FMR30_86 OFF CACHE BOOL "Build for FM-R30, i86 version")
 set(BUILD_FMR30_286 ON CACHE BOOL "Build for FM-R30, i286 version")
 if(BUILD_FMR30_86)
   set(EXEC_TARGET emufmr30_i86)
-  set(FLAG_USE_I86 ON)
+  set(FLAG_USE_I86 OFF)
+  set(VMFILES ${VMFILES}
+       i286.cpp
+  )
   add_definitions(-DHAS_I86)
 elseif(BUILD_FMR30_286)
   set(EXEC_TARGET emufmr30_i286)
index 667065a..ef6b7dc 100644 (file)
@@ -47,7 +47,10 @@ set(BUILD_FMR30_86 ON CACHE BOOL "Build for FM-R30, i86 version")
 set(BUILD_FMR30_286 OFF CACHE BOOL "Build for FM-R30, i286 version")
 if(BUILD_FMR30_86)
   set(EXEC_TARGET emufmr30_i86)
-  set(FLAG_USE_I86 ON)
+  set(FLAG_USE_I86 OFF)
+  set(VMFILES ${VMFILES}
+       i286.cpp
+  )
   add_definitions(-DHAS_I86)
 elseif(BUILD_FMR30_286)
   set(EXEC_TARGET emufmr30_i286)
index beca16c..a8c67bb 100644 (file)
@@ -19,7 +19,7 @@ set(WITH_JOYSTICK OFF)
 set(WITH_MOUSE ON)
 
 set(VMFILES
-#                 i286.cpp
+                  i286.cpp
                   msm58321.cpp
                   
                   memory.cpp
@@ -38,7 +38,7 @@ set(VMFILES_LIB
                   upd765a.cpp
                   disk.cpp
 )
-set(FLAG_USE_I86 ON)
+set(FLAG_USE_I86 OFF)
 
 set(BUILD_SHARED_LIBS OFF)
 set(USE_OPENMP ON CACHE BOOL "Build using OpenMP")
index 864d3b3..9c44bcc 100644 (file)
@@ -1,3 +1,36 @@
+11/28/2017
+
+[EMU/DEBUGGER] fix ut command to show correct range of cpu trace
+
+[VM/DEVICE] rename bios_call_i86() to bios_call_far_i86()
+[VM/HUC6280] support to show total cpu clocks in debugger
+[VM/HUC6280] support cpu trace
+[VM/I286] support to show total cpu clocks in debugger
+[VM/I286] support cpu trace
+[VM/I386] support to show total cpu clocks in debugger
+[VM/I386] support cpu trace
+[VM/M6502] support to show total cpu clocks in debugger
+[VM/M6502] support cpu trace
+[VM/MC6800] support to show total cpu clocks in debugger
+[VM/MC6800] support cpu trace
+[VM/MC6800] fix issue that can not break at instruction following tap/cli/sei
+[VM/MC6809] support to show total cpu clocks in debugger
+[VM/MC6809] support cpu trace
+[VM/MCS48] fix to add clocks for interrupt to total cpu clocks
+[VM/TMS9995] support to show total cpu clocks in debugger
+[VM/TMS9995] support cpu trace
+[VM/UPD7801] support to show total cpu clocks in debugger
+[VM/UPD7801] support cpu trace
+[VM/UPD7810] support to show total cpu clocks in debugger
+[VM/UPD7810] support cpu trace
+[VM/Z80] fix to add clocks for interrupt to total cpu clocks
+
+
+11/26/2017
+
+[PC8801MA] fix text attribute when dma underrun occurs
+
+
 11/25/2017
 
 [EMU/DEBUGGER] support command history
index d9b2e42..aabf474 100644 (file)
@@ -1,3 +1,3 @@
-<B><FONT SIZE=-1>Upstream 2017-11-25<BR>
-Qt Port and FM7 series 2017-10-18<BR>
+<B><FONT SIZE=-1>Upstream 2017-11-28<BR>
+Qt Port and FM7 series 2017-12-03(TMP)<BR>
 </FONT></B>
index 76ea572..488a98b 100644 (file)
@@ -511,7 +511,7 @@ void* debugger_thread(void *lpx)
                                        if(num >= 2) {
                                                steps = min(my_hexatoi(debugger->first_symbol, params[1]), (uint32_t)MAX_CPU_TRACE);
                                        }
-                                       for(int i = 0; i < steps; i++) {
+                                       for(int i = MAX_CPU_TRACE - steps; i < MAX_CPU_TRACE; i++) {
                                                int index = (debugger->cpu_trace_ptr + i) & (MAX_CPU_TRACE - 1);
                                                if(!(debugger->cpu_trace[index] & ~prog_addr_mask)) {
                                                        const _TCHAR *name = get_symbol(debugger->first_symbol, debugger->cpu_trace[index] & prog_addr_mask);
index 9a71a21..e985ff7 100644 (file)
@@ -8,13 +8,13 @@
 <body>
 <h1>Common Source Code Project</h1>
 <DIV ALIGN=RIGHT><FONT SIZE=2>
-Upstream Version: 2017-11-25<BR>
-Qt Port and FM7 series 2017-10-18<BR>
+Upstream Version: 2017-11-28<BR>
+Qt Port and FM7 series 2017-12-03(TMP)<BR>
 libCSPavio 2.6.10<BR>
 libCSPgui 2.10.4<BR>
-libCSPosd 2.9.10<BR>
+libCSPosd 2.9.11<BR>
 libCSPemu_utils 2.6.1<BR>
-libCSPcommon_vm 1.1.18<BR>
+libCSPcommon_vm 1.1.20<BR>
 libCSPfmgen 1.1.0<BR>
 FFMPEG 3.2.2 + liblame 3.99 + libx264-152<BR>
 Build Version: <BR>
@@ -70,5 +70,5 @@ See also:<BR>
 </FONT>
 <hr>
 <address></address>
-<!-- hhmts start -->Last modified: Wed 18, Oct 2017 16:49:12<!-- hhmts end -->
+<!-- hhmts start -->Last modified: Sun 03, Dec 2017 16:35:35<!-- hhmts end -->
 </body> </html>
index 3f74d31..e37f4d5 100644 (file)
@@ -94,6 +94,9 @@ BEGIN
         MENUITEM "Stop",                        ID_AUTOKEY_STOP
         MENUITEM "Romaji to Kana",              ID_ROMAJI_TO_KANA
         MENUITEM SEPARATOR
+        MENUITEM "Debug Main CPU",              ID_OPEN_DEBUGGER0
+        MENUITEM "Close Debugger",              ID_CLOSE_DEBUGGER
+        MENUITEM SEPARATOR
         MENUITEM "Exit",                        ID_EXIT
     END
     POPUP "FD1"
index b305cc5..09213e9 100644 (file)
@@ -94,6 +94,9 @@ BEGIN
         MENUITEM "Stop",                        ID_AUTOKEY_STOP
         MENUITEM "Romaji to Kana",              ID_ROMAJI_TO_KANA
         MENUITEM SEPARATOR
+        MENUITEM "Debug Main CPU",              ID_OPEN_DEBUGGER0
+        MENUITEM "Close Debugger",              ID_CLOSE_DEBUGGER
+        MENUITEM SEPARATOR
         MENUITEM "Exit",                        ID_EXIT
     END
     POPUP "FD1"
index 8776f35..4cad950 100644 (file)
@@ -1,6 +1,6 @@
 message("* vm/common_vm")
 
-SET(THIS_LIB_VERSION 1.1.19)
+SET(THIS_LIB_VERSION 1.1.20)
 set(s_vm_common_vm_srcs
        ../315-5124.cpp
        ../am9511.cpp
@@ -94,7 +94,7 @@ set(s_vm_common_vm_srcs
        ../z80pio.cpp
        ../z80sio.cpp
 
-       ../libcpu_newdev/i86_base.cpp
+#      ../libcpu_newdev/i86_base.cpp
 
        ../libcpu_newdev/libcpu_i386/i386_opdef.cpp
        ../libcpu_newdev/libcpu_i386/i386_base_ext.cpp
index 1cf0b0e..d4f74e1 100644 (file)
@@ -514,7 +514,7 @@ public:
        }
        
        // bios
-       virtual bool bios_call_i86(uint32_t PC, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag)
+       virtual bool bios_call_far_i86(uint32_t PC, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag)
        {
                return false;
        }
index 248d1f3..08a7fd8 100644 (file)
@@ -57,7 +57,7 @@ class I8251;
 class I8253;
 class I8255;
 class I8259;
-class I86;
+class I286;
 class IO;
 class MB8877;
 class MEMORY;
@@ -79,7 +79,7 @@ protected:
        I8253* pit;
        I8255* pio;
        I8259* pic;
-       I86* cpu;
+       I286* cpu;
        IO* io;
        MB8877* fdc;
        MEMORY* memory;
index 9322a1f..7e2db47 100644 (file)
 #include "../i8251.h"
 #include "../i8253.h"
 #include "../i8259.h"
-#if defined(HAS_I86)
-#include "../i86.h"
-#else
+//#if defined(HAS_I86)
+//#include "../i86.h"
+//#else
 #include "../i286.h"
-#endif
+//#endif
 #include "../io.h"
 #include "../mb8877.h"
 #include "../noise.h"
@@ -66,11 +66,11 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        sio_ch2->set_device_name(_T("8251 SIO (RS-232C #2)"));
        pit = new I8253(this, emu);
        pic = new I8259(this, emu);
-#if defined(HAS_I86)
-       cpu = new I86(this, emu);
-#else
+//#if defined(HAS_I86)
+//     cpu = new I86(this, emu);
+//#else
        cpu = new I286(this, emu);
-#endif
+//#endif
        io = new IO(this, emu);
        fdc = new MB8877(this, emu);
        fdc->set_context_noise_seek(new NOISE(this, emu));
index d56bcbe..ca1e49a 100644 (file)
@@ -67,11 +67,11 @@ class I8237;
 class I8251;
 class I8253;
 class I8259;
-#if defined(HAS_I86)
-class I86;
-#else
+//#if defined(HAS_I86)
+//class I86;
+//#else
 class I286;
-#endif
+//#endif
 class IO;
 class MB8877;
 class SCSI_HDD;
@@ -104,11 +104,11 @@ protected:
        I8251* sio_ch2;
        I8253* pit;
        I8259* pic;
-#if defined(HAS_I86)
-       I86* cpu;
-#else
+//#if defined(HAS_I86)
+//     I86* cpu;
+//#else
        I286* cpu;
-#endif
+//#endif
        IO* io;
        MB8877* fdc;
        SCSI_HDD* scsi_hdd[7];
index 9d7f674..15e2d6d 100644 (file)
@@ -307,7 +307,7 @@ void BIOS::event_frame()
        timeout++;
 }
 
-bool BIOS::bios_call_i86(uint32_t PC, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag)
+bool BIOS::bios_call_far_i86(uint32_t PC, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag)
 {
        uint8_t *regs8 = (uint8_t *)regs;
        int drv = AL & 0xf;
@@ -1080,7 +1080,7 @@ bool BIOS::bios_int_i86(int intnum, uint16_t regs[], uint16_t sregs[], int32_t*
        
        if(intnum == 0x93) {
                // disk bios
-               return bios_call_i86(0xfffc4, regs, sregs, ZeroFlag, CarryFlag);
+               return bios_call_far_i86(0xfffc4, regs, sregs, ZeroFlag, CarryFlag);
        }
        return false;
 }
index 815e4cf..e082f8e 100644 (file)
@@ -47,7 +47,7 @@ public:
        void initialize();
        void reset();
        void event_frame();
-       bool bios_call_i86(uint32_t PC, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag);
+       bool bios_call_far_i86(uint32_t PC, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag);
        bool bios_int_i86(int intnum, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag);
        uint32_t read_signal(int ch);
        void save_state(FILEIO* state_fio);
index 77b84fc..796e333 100644 (file)
@@ -594,7 +594,7 @@ int HD6301::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
        return 0;
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
 void HD6301::save_state(FILEIO* state_fio)
 {
@@ -610,6 +610,7 @@ void HD6301::save_state(FILEIO* state_fio)
        state_fio->FputUint8(cc);
        state_fio->FputInt32(wai_state);
        state_fio->FputInt32(int_state);
+       if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
        state_fio->FputInt32(icount);
 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
        for(int i = 0; i < 4; i++) {
@@ -665,6 +666,7 @@ bool HD6301::load_state(FILEIO* state_fio)
        cc = state_fio->FgetUint8();
        wai_state = state_fio->FgetInt32();
        int_state = state_fio->FgetInt32();
+       if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
        icount = state_fio->FgetInt32();
 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
        for(int i = 0; i < 4; i++) {
index b87104e..100cec0 100644 (file)
@@ -75,14 +75,13 @@ int HUC6280::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
-#ifdef USE_DEBUGGER
-                       return exec_call_debug();
-#else
-                       return exec_call();
-#endif
+                       return run_one_opecode();
                }
        } else {
                icount += clock;
@@ -90,29 +89,44 @@ int HUC6280::run(int clock)
                
                // run cpu while given clocks
                while(icount > 0 && !busreq) {
-#ifdef USE_DEBUGGER
-                       icount -= exec_call_debug();
-#else
-                       icount -= exec_call();
-#endif
+                       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;
        }
 }
 
-#define STATE_VERSION  4
+int HUC6280::run_one_opecode()
+{
+       h6280_Regs *cpustate = (h6280_Regs *)opaque;
+#ifdef USE_DEBUGGER
+       d_debugger->add_cpu_trace(cpustate->pc.w.l);
+#endif
+       int passed_icount = CPU_EXECUTE_CALL(h6280);
+#ifdef USE_DEBUGGER
+       total_icount += passed_icount;
+#endif
+       return passed_icount;
+}
+
+#define STATE_VERSION  5
 
 void HUC6280::save_state(FILEIO* state_fio)
 {
        state_fio->FputUint32(STATE_VERSION);
        state_fio->FputInt32(this_device_id);
        
-       //state_fio->Fwrite(opaque, sizeof(h6280_Regs), 1);
+
        save_state_registers(state_fio);
+#ifdef USE_DEBUGGER
+       state_fio->FputUint64(total_icount);
+#endif
        state_fio->FputInt32(icount);
        state_fio->FputBool(busreq);
 }
@@ -125,7 +139,9 @@ bool HUC6280::load_state(FILEIO* state_fio)
        if(state_fio->FgetInt32() != this_device_id) {
                return false;
        }
-       //state_fio->Fread(opaque, sizeof(h6280_Regs), 1);
+#ifdef USE_DEBUGGER
+       total_icount = prev_total_icount = state_fio->FgetUint64();
+#endif
        load_state_registers(state_fio);
        icount = state_fio->FgetInt32();
        busreq = state_fio->FgetBool();
index b0d1d82..98fc0ba 100644 (file)
@@ -31,9 +31,14 @@ protected:
        bool busreq;
        int exec_call(void);
        int exec_call_debug(void);
+       uint64_t total_icount;
+       uint64_t prev_total_icount;
+
+       virtual int run_one_opecode();
        
 public:
        HUC6280_BASE(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {
+               total_icount = prev_total_icount = 0;
                set_device_name(_T("HuC6280 CPU"));
        }
        ~HUC6280_BASE() {}
@@ -88,7 +93,8 @@ public:
 class HUC6280 : public HUC6280_BASE
 {
 private:
-       
+protected:
+       int run_one_opecode() override;
 public:
        HUC6280(VM* parent_vm, EMU* parent_emu) : HUC6280_BASE(parent_vm, parent_emu) {
                set_device_name(_T("HuC6280 CPU"));
index e8dfb2c..cb76b80 100644 (file)
@@ -115,17 +115,13 @@ int HUC6280_BASE::run(int clocks)
        return 0;
 }
 
-int HUC6280_BASE::exec_call(void)
+int HUC6280_BASE::run_one_opecode()
 {
        h6280_Regs *cpustate = (h6280_Regs *)opaque;
-       return CPU_EXECUTE_CALL(h6280);
+       int passed_icount = CPU_EXECUTE_CALL(h6280);
+       return passed_icount;
 }
 
-int HUC6280_BASE::exec_call_debug(void)
-{
-       h6280_Regs *cpustate = (h6280_Regs *)opaque;
-       return CPU_EXECUTE_CALL(h6280_debug);
-}
 
 void HUC6280_BASE::write_signal(int id, uint32_t data, uint32_t mask)
 {
@@ -226,8 +222,10 @@ void HUC6280_BASE::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
 {
        h6280_Regs *cpustate = (h6280_Regs *)opaque;
        my_stprintf_s(buffer, buffer_len,
-       _T("PC = %04X SP = %04X ZP = %04X EA = %04X A = %02X X = %02X Y = %02X P = %02X"),
-       cpustate->pc.w.l, cpustate->sp.w.l, cpustate->zp.w.l, cpustate->ea.w.l, cpustate->a, cpustate->x, cpustate->y, cpustate->p);
+       _T("PC = %04X SP = %04X ZP = %04X EA = %04X A = %02X X = %02X Y = %02X P = %02X\nTotal CPU Clocks = %llu (%llu)"),
+       cpustate->pc.w.l, cpustate->sp.w.l, cpustate->zp.w.l, cpustate->ea.w.l, cpustate->a, cpustate->x, cpustate->y, cpustate->p,
+       total_icount, total_icount - prev_total_icount);
+       prev_total_icount = total_icount;
 }
 
 // disassembler
index eae7fe4..5a12802 100644 (file)
@@ -350,11 +350,13 @@ void I286::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
 {
        cpu_state *cpustate = (cpu_state *)opaque;
        my_stprintf_s(buffer, buffer_len,
-       _T("AX=%04X  BX=%04X CX=%04X DX=%04X SP=%04X  BP=%04X  SI=%04X  DI=%04X\nDS=%04X  ES=%04X SS=%04X CS=%04X IP=%04X  FLAG=[%c%c%c%c%c%c%c%c%c]"),
+       _T("AX=%04X  BX=%04X CX=%04X DX=%04X SP=%04X  BP=%04X  SI=%04X  DI=%04X\nDS=%04X  ES=%04X SS=%04X CS=%04X IP=%04X  FLAG=[%c%c%c%c%c%c%c%c%c]\nTotal CPU Clocks = %llu (%llu)"),
        cpustate->regs.w[AX], cpustate->regs.w[BX], cpustate->regs.w[CX], cpustate->regs.w[DX], cpustate->regs.w[SP], cpustate->regs.w[BP], cpustate->regs.w[SI], cpustate->regs.w[DI],
        cpustate->sregs[DS], cpustate->sregs[ES], cpustate->sregs[SS], cpustate->sregs[CS], cpustate->pc - cpustate->base[CS],
        OF ? _T('O') : _T('-'), DF ? _T('D') : _T('-'), cpustate->IF ? _T('I') : _T('-'), cpustate->TF ? _T('T') : _T('-'),
-       SF ? _T('S') : _T('-'), ZF ? _T('Z') : _T('-'), AF ? _T('A') : _T('-'), PF ? _T('P') : _T('-'), CF ? _T('C') : _T('-'));
+       SF ? _T('S') : _T('-'), ZF ? _T('Z') : _T('-'), AF ? _T('A') : _T('-'), PF ? _T('P') : _T('-'), CF ? _T('C') : _T('-'),
+       cpustate->total_icount, cpustate->total_icount - cpustate->prev_total_icount);
+       cpustate->prev_total_icount = cpustate->total_icount;
 }
 
 int I286::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
@@ -658,7 +660,7 @@ void I286::load_state_cpustate(FILEIO* state_fio)
 }
 
 
-#define STATE_VERSION  3
+#define STATE_VERSION  4
 
 void I286::save_state(FILEIO* state_fio)
 {
index 1742009..1da58ac 100644 (file)
@@ -200,20 +200,22 @@ typedef UINT32    offs_t;
                REG16(AX) = regs[0]; REG16(CX) = regs[1]; REG16(DX) = regs[2]; REG16(BX) = regs[3]; \
                REG16(SP) = regs[4]; REG16(BP) = regs[5]; REG16(SI) = regs[6]; REG16(DI) = regs[7]; \
                cpustate->ZF = (UINT8)ZeroFlag; cpustate->CF = (UINT8)CarryFlag; \
+               CYCLES(cpustate,CYCLES_IRET); \
                return; \
        } \
 }
-#define BIOS_CALL(address) if(cpustate->bios != NULL) { \
+#define BIOS_CALL_FAR(address) if(cpustate->bios != NULL) { \
        uint16_t regs[8], sregs[4]; \
        regs[0] = REG16(AX); regs[1] = REG16(CX); regs[2] = REG16(DX); regs[3] = REG16(BX); \
        regs[4] = REG16(SP); regs[5] = REG16(BP); regs[6] = REG16(SI); regs[7] = REG16(DI); \
        sregs[0] = cpustate->sreg[ES].selector; sregs[1] = cpustate->sreg[CS].selector; \
        sregs[2] = cpustate->sreg[SS].selector; sregs[3] = cpustate->sreg[DS].selector; \
        int32_t ZeroFlag = cpustate->ZF, CarryFlag = cpustate->CF; \
-       if(cpustate->bios->bios_call_i86(address, regs, sregs, &ZeroFlag, &CarryFlag)) { \
+       if(cpustate->bios->bios_call_far_i86(address, regs, sregs, &ZeroFlag, &CarryFlag)) { \
                REG16(AX) = regs[0]; REG16(CX) = regs[1]; REG16(DX) = regs[2]; REG16(BX) = regs[3]; \
                REG16(SP) = regs[4]; REG16(BP) = regs[5]; REG16(SI) = regs[6]; REG16(DI) = regs[7]; \
                cpustate->ZF = (UINT8)ZeroFlag; cpustate->CF = (UINT8)CarryFlag; \
+               CYCLES(cpustate,CYCLES_RET_INTERSEG); \
                return; \
        } \
 }
@@ -437,11 +439,13 @@ void I386::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
 {
        i386_state *cpustate = (i386_state *)opaque;
        my_stprintf_s(buffer, buffer_len,
-       _T("AX=%04X  BX=%04X CX=%04X DX=%04X SP=%04X  BP=%04X  SI=%04X  DI=%04X\nDS=%04X  ES=%04X SS=%04X CS=%04X IP=%04X  FLAG=[%c%c%c%c%c%c%c%c%c]"),
+       _T("AX=%04X  BX=%04X CX=%04X DX=%04X SP=%04X  BP=%04X  SI=%04X  DI=%04X\nDS=%04X  ES=%04X SS=%04X CS=%04X IP=%04X  FLAG=[%c%c%c%c%c%c%c%c%c]\nTotal CPU Clocks = %llu (%llu)"),
        REG16(AX), REG16(BX), REG16(CX), REG16(DX), REG16(SP), REG16(BP), REG16(SI), REG16(DI),
        cpustate->sreg[DS].selector, cpustate->sreg[ES].selector, cpustate->sreg[SS].selector, cpustate->sreg[CS].selector, cpustate->eip,
        cpustate->OF ? _T('O') : _T('-'), cpustate->DF ? _T('D') : _T('-'), cpustate->IF ? _T('I') : _T('-'), cpustate->TF ? _T('T') : _T('-'),
-       cpustate->SF ? _T('S') : _T('-'), cpustate->ZF ? _T('Z') : _T('-'), cpustate->AF ? _T('A') : _T('-'), cpustate->PF ? _T('P') : _T('-'), cpustate->CF ? _T('C') : _T('-'));
+       cpustate->SF ? _T('S') : _T('-'), cpustate->ZF ? _T('Z') : _T('-'), cpustate->AF ? _T('A') : _T('-'), cpustate->PF ? _T('P') : _T('-'), cpustate->CF ? _T('C') : _T('-'),
+       cpustate->total_cycles, cpustate->total_cycles - cpustate->prev_total_cycles);
+       cpustate->prev_total_cycles = cpustate->total_cycles;
 }
 
 int I386::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
@@ -490,7 +494,7 @@ int I386::get_shutdown_flag()
        return cpustate->shutdown;
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
 void I386::save_state(FILEIO* state_fio)
 {
index b81282f..c53cb2e 100644 (file)
@@ -337,6 +337,9 @@ int I8080::run(int clock)
        if(clock == -1) {
                if(BUSREQ) {
                        // don't run cpu!
+#ifdef USE_DEBUGGER
+                       total_count += 1;
+#endif
                        return 1;
                } else {
                        // run only one opcode
@@ -354,6 +357,9 @@ int I8080::run(int clock)
                }
                // if busreq is raised, spin cpu while remained clock
                if(count > 0 && BUSREQ) {
+#ifdef USE_DEBUGGER
+                       total_count += count;
+#endif
                        count = 0;
                }
                return first_count - count;
@@ -382,7 +388,10 @@ void I8080::run_one_opecode()
                }
                
                afterHALT = afterEI = false;
+               d_debugger->add_cpu_trace(PC);
+               int first_count = count;
                OP(FETCHOP());
+               total_count += first_count - count;
                if(!afterEI) {
                        check_interrupt();
                }
@@ -397,7 +406,14 @@ void I8080::run_one_opecode()
        } else {
 #endif
                afterHALT = afterEI = false;
+#ifdef USE_DEBUGGER
+               d_debugger->add_cpu_trace(PC);
+               int first_count = count;
+#endif
                OP(FETCHOP());
+#ifdef USE_DEBUGGER
+               total_count += first_count - count;
+#endif
                if(!afterEI) {
                        check_interrupt();
                }
@@ -426,7 +442,10 @@ void I8080::run_one_opecode()
                        }
                        
                        afterHALT = false;
+                       d_debugger->add_cpu_trace(PC);
+                       int first_count = count;
                        OP(FETCHOP());
+                       total_count += first_count - count;
                        d_pic->notify_intr_ei();
                        check_interrupt();
                        
@@ -440,7 +459,14 @@ void I8080::run_one_opecode()
                } else {
 #endif
                        afterHALT = false;
+#ifdef USE_DEBUGGER
+                       d_debugger->add_cpu_trace(PC);
+                       int first_count = count;
+#endif
                        OP(FETCHOP());
+#ifdef USE_DEBUGGER
+                       total_count += first_count - count;
+#endif
                        d_pic->notify_intr_ei();
                        check_interrupt();
 #ifdef USE_DEBUGGER
@@ -451,6 +477,9 @@ void I8080::run_one_opecode()
 
 void I8080::check_interrupt()
 {
+#ifdef USE_DEBUGGER
+       int first_count = count;
+#endif
        // check interrupt
        if(IM & IM_REQ) {
                if(IM & IM_NMI) {
@@ -537,17 +566,23 @@ void I8080::check_interrupt()
                        }
                }
        }
+#ifdef USE_DEBUGGER
+       total_count += first_count - count;
+#endif
 }
 
 
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
 void I8080::save_state(FILEIO* state_fio)
 {
        state_fio->FputUint32(STATE_VERSION);
        state_fio->FputInt32(this_device_id);
        
+#ifdef USE_DEBUGGER
+       state_fio->FputUint64(total_count);
+#endif
        state_fio->FputInt32(count);
        state_fio->Fwrite(regs, sizeof(regs), 1);
        state_fio->FputUint16(SP);
@@ -569,6 +604,9 @@ bool I8080::load_state(FILEIO* state_fio)
        if(state_fio->FgetInt32() != this_device_id) {
                return false;
        }
+#ifdef USE_DEBUGGER
+       total_count = prev_total_count = state_fio->FgetUint64();
+#endif
        count = state_fio->FgetInt32();
        state_fio->Fread(regs, sizeof(regs), 1);
        SP = state_fio->FgetUint16();
index f00103e..3911f06 100644 (file)
@@ -1310,16 +1310,19 @@ void I8080_BASE::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
 /*
 F = [--------]  A = 00  BC = 0000  DE = 0000  HL = 0000  SP = 0000  PC = 0000
 IM= [--------]         (BC)= 0000 (DE)= 0000 (HL)= 0000 (SP)= 0000
+Total CPU Clocks = 0 (0)
 */
        int wait;
        my_stprintf_s(buffer, buffer_len,
-       _T("F = [%c%c%c%c%c%c%c%c]  A = %02X  BC = %04X  DE = %04X  HL = %04X  SP = %04X  PC = %04X\nIM= [%c%c%c%c%c%c%c%c]         (BC)= %04X (DE)= %04X (HL)= %04X (SP)= %04X"),
-       (_F & CF) ? _T('C') : _T('-'), (_F & NF) ? _T('N') : _T('-'), (_F & VF) ? _T('V') : _T('-'), (_F & XF) ? _T('X') : _T('-'),
-       (_F & HF) ? _T('H') : _T('-'), (_F & YF) ? _T('Y') : _T('-'), (_F & ZF) ? _T('Z') : _T('-'), (_F & SF) ? _T('S') : _T('-'),
-       _A, BC, DE, HL, SP, PC,
-       (IM & 0x80) ? _T('S') : _T('-'), (IM & 0x40) ? _T('7') : _T('-'), (IM & 0x20) ? _T('6') : _T('-'), (IM & 0x10) ? _T('5') : _T('-'),
-       (IM & 0x08) ? _T('E') : _T('-'), (IM & 0x04) ? _T('7') : _T('-'), (IM & 0x02) ? _T('6') : _T('-'), (IM & 0x01) ? _T('5') : _T('-'),
-       d_mem_stored->read_data16w(BC, &wait), d_mem_stored->read_data16w(DE, &wait), d_mem_stored->read_data16w(HL, &wait), d_mem_stored->read_data16w(SP, &wait));
+       _T("F = [%c%c%c%c%c%c%c%c]  A = %02X  BC = %04X  DE = %04X  HL = %04X  SP = %04X  PC = %04X\nIM= [%c%c%c%c%c%c%c%c]         (BC)= %04X (DE)= %04X (HL)= %04X (SP)= %04X\nTotal CPU Clocks = %llu (%llu)"),
+       (_F & CF) ? _T('C') : _T('-'), (_F & NF) ? _T('N') : _T('-'), (_F & VF) ? _T('V') : _T('-'), (_F & XF) ? _T('X') : _T('-'),
+       (_F & HF) ? _T('H') : _T('-'), (_F & YF) ? _T('Y') : _T('-'), (_F & ZF) ? _T('Z') : _T('-'), (_F & SF) ? _T('S') : _T('-'),
+       _A, BC, DE, HL, SP, PC,
+       (IM & 0x80) ? _T('S') : _T('-'), (IM & 0x40) ? _T('7') : _T('-'), (IM & 0x20) ? _T('6') : _T('-'), (IM & 0x10) ? _T('5') : _T('-'),
+       (IM & 0x08) ? _T('E') : _T('-'), (IM & 0x04) ? _T('7') : _T('-'), (IM & 0x02) ? _T('6') : _T('-'), (IM & 0x01) ? _T('5') : _T('-'),
+       d_mem_stored->read_data16w(BC, &wait), d_mem_stored->read_data16w(DE, &wait), d_mem_stored->read_data16w(HL, &wait), d_mem_stored->read_data16w(SP, &wait),
+       total_count, total_count - prev_total_count);
+       prev_total_count = total_count;
 }
 
 // disassembler
index cd65461..b5c44f1 100644 (file)
@@ -106,6 +106,9 @@ protected:
        inline void RST(uint16_t n);
 
        void OP(uint8_t code);
+
+       uint64_t total_count;
+       uint64_t prev_total_count;
 public:
        I8080_BASE(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
        {
@@ -116,6 +119,7 @@ public:
                d_mem = d_pic = d_io = NULL;
                d_mem_stored = d_io_stored = NULL;
                d_debugger = NULL;
+               total_count = prev_total_count = 0;
                set_device_name(_T("i8080 CPU"));
        }
        ~I8080_BASE() {}
index bbcc2b4..cd6b447 100644 (file)
 //#include "../i8250.h"
 #include "../i8253.h"
 #include "../i8259.h"
-#if defined(HAS_I286)
+//#if defined(HAS_I286)
 #include "../i286.h"
-#else
-#include "../i86.h"
-#endif
+//#else
+//#include "../i86.h"
+//#endif
 #include "../io.h"
 #include "../noise.h"
 #include "../pcm1bit.h"
 #include "../hd146818p.h"
 #endif
 
+#ifdef USE_DEBUGGER
+#include "../debugger.h"
+#endif
+
 #include "display.h"
 #include "dmareg.h"
 #include "floppy.h"
@@ -71,11 +75,11 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
 //     sio = new I8250(this, emu);
        pit = new I8253(this, emu);     // i8254
        pic = new I8259(this, emu);
-#if defined(HAS_I286)
+//#if defined(HAS_I286)
        cpu = new I286(this, emu);
-#else
-       cpu = new I86(this, emu);
-#endif
+//#else
+//     cpu = new I86(this, emu);
+//#endif
        io = new IO(this, emu);
        pcm = new PCM1BIT(this, emu);
        fdc = new UPD765A(this, emu);
@@ -106,6 +110,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        cpu->set_context_mem(memory);
        cpu->set_context_io(io);
        cpu->set_context_intr(pic);
+#ifdef USE_DEBUGGER
+       cpu->set_context_debugger(new DEBUGGER(this, emu));
+#endif
        
        // dmac
        io->set_iomap_range_rw(0x00, 0x0f, dma);
@@ -294,6 +301,20 @@ void VM::run()
 }
 
 // ----------------------------------------------------------------------------
+// debugger
+// ----------------------------------------------------------------------------
+
+#ifdef USE_DEBUGGER
+DEVICE *VM::get_cpu(int index)
+{
+       if(index == 0) {
+               return cpu;
+       }
+       return NULL;
+}
+#endif
+
+// ----------------------------------------------------------------------------
 // draw screen
 // ----------------------------------------------------------------------------
 
index 92d9033..d979573 100644 (file)
@@ -76,11 +76,11 @@ class I8237;
 //class I8250;
 class I8253;
 class I8259;
-#if defined(HAS_I286)
+//#if defined(HAS_I286)
 class I286;
-#else
-class I86;
-#endif
+//#else
+//class I86;
+//#endif
 class IO;
 class PCM1BIT;
 class UPD765A;
@@ -111,11 +111,11 @@ protected:
 //     I8250* sio;
        I8253* pit;
        I8259* pic;
-#if defined(HAS_I286)
+//#if defined(HAS_I286)
        I286* cpu;
-#else
-       I86* cpu;
-#endif
+//#else
+//     I86* cpu;
+//#endif
        IO* io;
        PCM1BIT* pcm;
        UPD765A* fdc;
@@ -151,6 +151,11 @@ public:
        void notify_power_off();
        void run();
        
+#ifdef USE_DEBUGGER
+       // debugger
+       DEVICE *get_cpu(int index);
+#endif
+       
        // draw screen
        void draw_screen();
        
diff --git a/source/src/vm/jx/i286.cpp b/source/src/vm/jx/i286.cpp
new file mode 100644 (file)
index 0000000..60a15cb
--- /dev/null
@@ -0,0 +1,456 @@
+/*
+       Skelton for retropc emulator
+
+       Author : Takeda.Toshiya
+       Date  : 2012.10.18-
+
+       [ i286 ]
+*/
+
+#include "i286.h"
+#ifdef USE_DEBUGGER
+#include "../debugger.h"
+#endif
+
+/* ----------------------------------------------------------------------------
+       MAME i286
+---------------------------------------------------------------------------- */
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+#pragma warning( disable : 4018 )
+#pragma warning( disable : 4146 )
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4996 )
+#endif
+
+#if defined(HAS_I86)
+       #define CPU_MODEL i8086
+#elif defined(HAS_I88)
+       #define CPU_MODEL i8088
+#elif defined(HAS_I186)
+       #define CPU_MODEL i80186
+#elif defined(HAS_V30)
+       #define CPU_MODEL v30
+#elif defined(HAS_I286)
+       #define CPU_MODEL i80286
+#endif
+
+#ifndef __BIG_ENDIAN__
+#define LSB_FIRST
+#endif
+
+#ifndef INLINE
+#define INLINE inline
+#endif
+
+#define logerror(...)
+
+/*****************************************************************************/
+/* src/emu/devcpu.h */
+
+// CPU interface functions
+#define CPU_INIT_NAME(name)                    cpu_init_##name
+#define CPU_INIT(name)                         void* CPU_INIT_NAME(name)()
+#define CPU_INIT_CALL(name)                    CPU_INIT_NAME(name)()
+
+#define CPU_RESET_NAME(name)                   cpu_reset_##name
+#define CPU_RESET(name)                                void CPU_RESET_NAME(name)(cpu_state *cpustate)
+#define CPU_RESET_CALL(name)                   CPU_RESET_NAME(name)(cpustate)
+
+#define CPU_EXECUTE_NAME(name)                 cpu_execute_##name
+#define CPU_EXECUTE(name)                      int CPU_EXECUTE_NAME(name)(cpu_state *cpustate, int icount)
+#define CPU_EXECUTE_CALL(name)                 CPU_EXECUTE_NAME(name)(cpustate, icount)
+
+#define CPU_DISASSEMBLE_NAME(name)             cpu_disassemble_##name
+#define CPU_DISASSEMBLE(name)                  int CPU_DISASSEMBLE_NAME(name)(_TCHAR *buffer, offs_t eip, const UINT8 *oprom)
+#define CPU_DISASSEMBLE_CALL(name)             CPU_DISASSEMBLE_NAME(name)(buffer, eip, oprom)
+
+/*****************************************************************************/
+/* src/emu/didisasm.h */
+
+// Disassembler constants
+const UINT32 DASMFLAG_SUPPORTED     = 0x80000000;   // are disassembly flags supported?
+const UINT32 DASMFLAG_STEP_OUT      = 0x40000000;   // this instruction should be the end of a step out sequence
+const UINT32 DASMFLAG_STEP_OVER     = 0x20000000;   // this instruction should be stepped over by setting a breakpoint afterwards
+const UINT32 DASMFLAG_OVERINSTMASK  = 0x18000000;   // number of extra instructions to skip when stepping over
+const UINT32 DASMFLAG_OVERINSTSHIFT = 27;           // bits to shift after masking to get the value
+const UINT32 DASMFLAG_LENGTHMASK    = 0x0000ffff;   // the low 16-bits contain the actual length
+
+/*****************************************************************************/
+/* src/emu/diexec.h */
+
+// I/O line states
+enum line_state
+{
+       CLEAR_LINE = 0,                         // clear (a fired or held) line
+       ASSERT_LINE,                            // assert an interrupt immediately
+       HOLD_LINE,                              // hold interrupt line until acknowledged
+       PULSE_LINE                              // pulse interrupt line instantaneously (only for NMI, RESET)
+};
+
+enum
+{
+       INPUT_LINE_IRQ = 0,
+       INPUT_LINE_NMI
+};
+
+/*****************************************************************************/
+/* src/emu/emucore.h */
+
+// constants for expression endianness
+enum endianness_t
+{
+       ENDIANNESS_LITTLE,
+       ENDIANNESS_BIG
+};
+
+// declare native endianness to be one or the other
+#ifdef LSB_FIRST
+const endianness_t ENDIANNESS_NATIVE = ENDIANNESS_LITTLE;
+#else
+const endianness_t ENDIANNESS_NATIVE = ENDIANNESS_BIG;
+#endif
+// endian-based value: first value is if 'endian' is little-endian, second is if 'endian' is big-endian
+#define ENDIAN_VALUE_LE_BE(endian,leval,beval) (((endian) == ENDIANNESS_LITTLE) ? (leval) : (beval))
+// endian-based value: first value is if native endianness is little-endian, second is if native is big-endian
+#define NATIVE_ENDIAN_VALUE_LE_BE(leval,beval) ENDIAN_VALUE_LE_BE(ENDIANNESS_NATIVE, leval, beval)
+// endian-based value: first value is if 'endian' matches native, second is if 'endian' doesn't match native
+#define ENDIAN_VALUE_NE_NNE(endian,leval,beval)        (((endian) == ENDIANNESS_NATIVE) ? (neval) : (nneval))
+
+/*****************************************************************************/
+/* src/emu/memory.h */
+
+// offsets and addresses are 32-bit (for now...)
+typedef UINT32 offs_t;
+
+/*****************************************************************************/
+/* src/osd/osdcomm.h */
+
+/* Highly useful macro for compile-time knowledge of an array size */
+#define ARRAY_LENGTH(x)     (sizeof(x) / sizeof(x[0]))
+
+#if defined(HAS_I86) || defined(HAS_I88) || defined(HAS_I186) || defined(HAS_V30)
+#define cpu_state i8086_state
+#include "../mame/emu/cpu/i86/i86.c"
+#elif defined(HAS_I286)
+#define cpu_state i80286_state
+#include "../mame/emu/cpu/i86/i286.c"
+#endif
+#ifdef USE_DEBUGGER
+#ifdef HAS_V30
+#include "../mame/emu/cpu/nec/necdasm.c"
+#else
+#include "../mame/emu/cpu/i386/i386dasm.c"
+#endif
+#endif
+
+void I286::initialize()
+{
+       opaque = CPU_INIT_CALL(CPU_MODEL);
+       
+       cpu_state *cpustate = (cpu_state *)opaque;
+       cpustate->pic = d_pic;
+       cpustate->program = d_mem;
+       cpustate->io = d_io;
+#ifdef I86_PSEUDO_BIOS
+       cpustate->bios = d_bios;
+#endif
+#ifdef SINGLE_MODE_DMA
+       cpustate->dma = d_dma;
+#endif
+#ifdef USE_DEBUGGER
+       cpustate->emu = emu;
+       cpustate->debugger = d_debugger;
+       cpustate->program_stored = d_mem;
+       cpustate->io_stored = d_io;
+       
+       d_debugger->set_context_mem(d_mem);
+       d_debugger->set_context_io(d_io);
+#endif
+}
+
+void I286::release()
+{
+       free(opaque);
+}
+
+void I286::reset()
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       int busreq = cpustate->busreq;
+       
+       CPU_RESET_CALL(CPU_MODEL);
+       
+       cpustate->pic = d_pic;
+       cpustate->program = d_mem;
+       cpustate->io = d_io;
+#ifdef I86_PSEUDO_BIOS
+       cpustate->bios = d_bios;
+#endif
+#ifdef SINGLE_MODE_DMA
+       cpustate->dma = d_dma;
+#endif
+#ifdef USE_DEBUGGER
+       cpustate->emu = emu;
+       cpustate->debugger = d_debugger;
+       cpustate->program_stored = d_mem;
+       cpustate->io_stored = d_io;
+#endif
+       cpustate->busreq = busreq;
+}
+
+int I286::run(int icount)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+#ifdef _JX
+       // ugly patch for PC/JX hardware diagnostics :-(
+#ifdef TIMER_HACK
+       if(cpustate->pc == 0xff040) cpustate->pc = 0xff04a;
+       if(cpustate->pc == 0xff17d) cpustate->pc = 0xff18f;
+#endif
+#ifdef KEYBOARD_HACK
+       if(cpustate->pc == 0xfa909) { cpustate->regs.b[BH] = read_port_byte(0xa1); cpustate->pc = 0xfa97c; }
+       if(cpustate->pc == 0xff6e1) { cpustate->regs.b[AL] = 0x0d; cpustate->pc += 2; }
+#endif
+#endif
+       return CPU_EXECUTE_CALL(CPU_MODEL);
+}
+
+void I286::write_signal(int id, uint32_t data, uint32_t mask)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       
+       if(id == SIG_CPU_NMI) {
+               set_irq_line(cpustate, INPUT_LINE_NMI, (data & mask) ? HOLD_LINE : CLEAR_LINE);
+       } else if(id == SIG_CPU_IRQ) {
+               set_irq_line(cpustate, INPUT_LINE_IRQ, (data & mask) ? HOLD_LINE : CLEAR_LINE);
+       } else if(id == SIG_CPU_BUSREQ) {
+               cpustate->busreq = (data & mask) ? 1 : 0;
+       } else if(id == SIG_I86_TEST) {
+               cpustate->test_state = (data & mask) ? 1 : 0;
+#ifdef HAS_I286
+       } else if(id == SIG_I286_A20) {
+               i80286_set_a20_line(cpustate, data & mask);
+#endif
+       }
+}
+
+void I286::set_intr_line(bool line, bool pending, uint32_t bit)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       set_irq_line(cpustate, INPUT_LINE_IRQ, line ? HOLD_LINE : CLEAR_LINE);
+}
+
+void I286::set_extra_clock(int icount)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       cpustate->extra_cycles += icount;
+}
+
+int I286::get_extra_clock()
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       return cpustate->extra_cycles;
+}
+
+uint32_t I286::get_pc()
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       return cpustate->prevpc;
+}
+
+uint32_t I286::get_next_pc()
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       return cpustate->pc;
+}
+
+#ifdef USE_DEBUGGER
+void I286::write_debug_data8(uint32_t addr, uint32_t data)
+{
+       int wait;
+       d_mem->write_data8w(addr, data, &wait);
+}
+
+uint32_t I286::read_debug_data8(uint32_t addr)
+{
+       int wait;
+       return d_mem->read_data8w(addr, &wait);
+}
+
+void I286::write_debug_data16(uint32_t addr, uint32_t data)
+{
+       int wait;
+       d_mem->write_data16w(addr, data, &wait);
+}
+
+uint32_t I286::read_debug_data16(uint32_t addr)
+{
+       int wait;
+       return d_mem->read_data16w(addr, &wait);
+}
+
+void I286::write_debug_io8(uint32_t addr, uint32_t data)
+{
+       int wait;
+       d_io->write_io8w(addr, data, &wait);
+}
+
+uint32_t I286::read_debug_io8(uint32_t addr) {
+       int wait;
+       return d_io->read_io8w(addr, &wait);
+}
+
+void I286::write_debug_io16(uint32_t addr, uint32_t data)
+{
+       int wait;
+       d_io->write_io16w(addr, data, &wait);
+}
+
+uint32_t I286::read_debug_io16(uint32_t addr) {
+       int wait;
+       return d_io->read_io16w(addr, &wait);
+}
+
+bool I286::write_debug_reg(const _TCHAR *reg, uint32_t data)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       if(_tcsicmp(reg, _T("IP")) == 0) {
+               cpustate->pc = ((data & 0xffff) + cpustate->base[CS]) & AMASK;
+               CHANGE_PC(cpustate->pc);
+       } else if(_tcsicmp(reg, _T("AX")) == 0) {
+               cpustate->regs.w[AX] = data;
+       } else if(_tcsicmp(reg, _T("BX")) == 0) {
+               cpustate->regs.w[BX] = data;
+       } else if(_tcsicmp(reg, _T("CX")) == 0) {
+               cpustate->regs.w[CX] = data;
+       } else if(_tcsicmp(reg, _T("DX")) == 0) {
+               cpustate->regs.w[DX] = data;
+       } else if(_tcsicmp(reg, _T("SP")) == 0) {
+               cpustate->regs.w[SP] = data;
+       } else if(_tcsicmp(reg, _T("BP")) == 0) {
+               cpustate->regs.w[BP] = data;
+       } else if(_tcsicmp(reg, _T("SI")) == 0) {
+               cpustate->regs.w[SI] = data;
+       } else if(_tcsicmp(reg, _T("DI")) == 0) {
+               cpustate->regs.w[DI] = data;
+       } else if(_tcsicmp(reg, _T("AL")) == 0) {
+               cpustate->regs.b[AL] = data;
+       } else if(_tcsicmp(reg, _T("AH")) == 0) {
+               cpustate->regs.b[AH] = data;
+       } else if(_tcsicmp(reg, _T("BL")) == 0) {
+               cpustate->regs.b[BL] = data;
+       } else if(_tcsicmp(reg, _T("BH")) == 0) {
+               cpustate->regs.b[BH] = data;
+       } else if(_tcsicmp(reg, _T("CL")) == 0) {
+               cpustate->regs.b[CL] = data;
+       } else if(_tcsicmp(reg, _T("CH")) == 0) {
+               cpustate->regs.b[CH] = data;
+       } else if(_tcsicmp(reg, _T("DL")) == 0) {
+               cpustate->regs.b[DL] = data;
+       } else if(_tcsicmp(reg, _T("DH")) == 0) {
+               cpustate->regs.b[DH] = data;
+       } else {
+               return false;
+       }
+       return true;
+}
+
+void I286::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       my_stprintf_s(buffer, buffer_len,
+       _T("AX=%04X  BX=%04X CX=%04X DX=%04X SP=%04X  BP=%04X  SI=%04X  DI=%04X\nDS=%04X  ES=%04X SS=%04X CS=%04X IP=%04X  FLAG=[%c%c%c%c%c%c%c%c%c]\nTotal CPU Clocks = %llu (%llu)"),
+       cpustate->regs.w[AX], cpustate->regs.w[BX], cpustate->regs.w[CX], cpustate->regs.w[DX], cpustate->regs.w[SP], cpustate->regs.w[BP], cpustate->regs.w[SI], cpustate->regs.w[DI],
+       cpustate->sregs[DS], cpustate->sregs[ES], cpustate->sregs[SS], cpustate->sregs[CS], cpustate->pc - cpustate->base[CS],
+       OF ? _T('O') : _T('-'), DF ? _T('D') : _T('-'), cpustate->IF ? _T('I') : _T('-'), cpustate->TF ? _T('T') : _T('-'),
+       SF ? _T('S') : _T('-'), ZF ? _T('Z') : _T('-'), AF ? _T('A') : _T('-'), PF ? _T('P') : _T('-'), CF ? _T('C') : _T('-'),
+       cpustate->total_icount, cpustate->total_icount - cpustate->prev_total_icount);
+       cpustate->prev_total_icount = cpustate->total_icount;
+}
+
+int I286::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       UINT64 eip = pc - cpustate->base[CS];
+       UINT8 ops[16];
+       for(int i = 0; i < 16; i++) {
+               int wait;
+               ops[i] = d_mem->read_data8w(pc + i, &wait);
+       }
+       UINT8 *oprom = ops;
+       
+#ifdef HAS_V30
+       return CPU_DISASSEMBLE_CALL(nec_generic) & DASMFLAG_LENGTHMASK;
+#else
+       return CPU_DISASSEMBLE_CALL(x86_16) & DASMFLAG_LENGTHMASK;
+#endif
+}
+#endif
+
+#ifdef HAS_I286
+void I286::set_address_mask(uint32_t mask)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       cpustate->amask = mask;
+}
+
+uint32_t I286::get_address_mask()
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       return cpustate->amask;
+}
+
+void I286::set_shutdown_flag(int shutdown)
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       cpustate->shutdown = shutdown;
+}
+
+int I286::get_shutdown_flag()
+{
+       cpu_state *cpustate = (cpu_state *)opaque;
+       return cpustate->shutdown;
+}
+#endif
+
+#define STATE_VERSION  4
+
+void I286::save_state(FILEIO* state_fio)
+{
+       state_fio->FputUint32(STATE_VERSION);
+       state_fio->FputInt32(this_device_id);
+       
+       state_fio->Fwrite(opaque, sizeof(cpu_state), 1);
+}
+
+bool I286::load_state(FILEIO* state_fio)
+{
+       if(state_fio->FgetUint32() != STATE_VERSION) {
+               return false;
+       }
+       if(state_fio->FgetInt32() != this_device_id) {
+               return false;
+       }
+       state_fio->Fread(opaque, sizeof(cpu_state), 1);
+       
+       // post process
+       cpu_state *cpustate = (cpu_state *)opaque;
+       cpustate->pic = d_pic;
+       cpustate->program = d_mem;
+       cpustate->io = d_io;
+#ifdef I86_PSEUDO_BIOS
+       cpustate->bios = d_bios;
+#endif
+#ifdef SINGLE_MODE_DMA
+       cpustate->dma = d_dma;
+#endif
+#ifdef USE_DEBUGGER
+       cpustate->emu = emu;
+       cpustate->debugger = d_debugger;
+       cpustate->program_stored = d_mem;
+       cpustate->io_stored = d_io;
+#endif
+       return true;
+}
+
diff --git a/source/src/vm/jx/i286.h b/source/src/vm/jx/i286.h
new file mode 100644 (file)
index 0000000..340e2d6
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+       Skelton for retropc emulator
+
+       Author : Takeda.Toshiya
+       Date  : 2012.10.18-
+
+       [ i286 ]
+*/
+
+#ifndef _I286_H_ 
+#define _I286_H_
+
+#include "../vm.h"
+#include "../../emu.h"
+#include "../device.h"
+
+#define SIG_I86_TEST   0
+#define SIG_I286_A20   1
+
+#ifdef USE_DEBUGGER
+class DEBUGGER;
+#endif
+
+class I286 : public DEVICE
+{
+private:
+       DEVICE *d_mem, *d_io, *d_pic;
+#ifdef I86_PSEUDO_BIOS
+       DEVICE *d_bios;
+#endif
+#ifdef SINGLE_MODE_DMA
+       DEVICE *d_dma;
+#endif
+#ifdef USE_DEBUGGER
+       DEBUGGER *d_debugger;
+#endif
+       void *opaque;
+       
+public:
+       I286(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
+       {
+#ifdef I86_PSEUDO_BIOS
+               d_bios = NULL;
+#endif
+#ifdef SINGLE_MODE_DMA
+               d_dma = NULL;
+#endif
+#if defined(HAS_I86)
+               set_device_name(_T("8086 CPU"));
+#elif defined(HAS_I88)
+               set_device_name(_T("8088 CPU"));
+#elif defined(HAS_I186)
+               set_device_name(_T("80186 CPU"));
+#elif defined(HAS_V30)
+               set_device_name(_T("V30 CPU"));
+#elif defined(HAS_I286)
+               set_device_name(_T("80286 CPU"));
+#endif
+       }
+       ~I286() {}
+       
+       // common functions
+       void initialize();
+       void release();
+       void reset();
+       int run(int icount);
+       void write_signal(int id, uint32_t data, uint32_t mask);
+       void set_intr_line(bool line, bool pending, uint32_t bit);
+       void set_extra_clock(int icount);
+       int get_extra_clock();
+       uint32_t get_pc();
+       uint32_t get_next_pc();
+#ifdef USE_DEBUGGER
+       void *get_debugger()
+       {
+               return d_debugger;
+       }
+       uint32_t get_debug_prog_addr_mask()
+       {
+#ifdef HAS_I286
+               return 0xffffff;
+#else
+               return 0xfffff;
+#endif
+       }
+       uint32_t get_debug_data_addr_mask()
+       {
+#ifdef HAS_I286
+               return 0xffffff;
+#else
+               return 0xfffff;
+#endif
+       }
+       void write_debug_data8(uint32_t addr, uint32_t data);
+       uint32_t read_debug_data8(uint32_t addr);
+       void write_debug_data16(uint32_t addr, uint32_t data);
+       uint32_t read_debug_data16(uint32_t addr);
+       void write_debug_io8(uint32_t addr, uint32_t data);
+       uint32_t read_debug_io8(uint32_t addr);
+       void write_debug_io16(uint32_t addr, uint32_t data);
+       uint32_t read_debug_io16(uint32_t addr);
+       bool write_debug_reg(const _TCHAR *reg, uint32_t data);
+       void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
+       int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
+#endif
+       void save_state(FILEIO* state_fio);
+       bool load_state(FILEIO* state_fio);
+       
+       // unique function
+       void set_context_mem(DEVICE* device)
+       {
+               d_mem = device;
+       }
+       void set_context_io(DEVICE* device)
+       {
+               d_io = device;
+       }
+       void set_context_intr(DEVICE* device)
+       {
+               d_pic = device;
+       }
+#ifdef I86_PSEUDO_BIOS
+       void set_context_bios(DEVICE* device)
+       {
+               d_bios = device;
+       }
+#endif
+#ifdef SINGLE_MODE_DMA
+       void set_context_dma(DEVICE* device)
+       {
+               d_dma = device;
+       }
+#endif
+#ifdef USE_DEBUGGER
+       void set_context_debugger(DEBUGGER* device)
+       {
+               d_debugger = device;
+       }
+#endif
+#ifdef HAS_I286
+       void set_address_mask(uint32_t mask);
+       uint32_t get_address_mask();
+       void set_shutdown_flag(int shutdown);
+       int get_shutdown_flag();
+#endif
+};
+
+#endif
index cadc185..823d49f 100644 (file)
@@ -18,7 +18,8 @@
 #include "../i8253.h"
 #include "../i8255.h"
 #include "../i8259.h"
-#include "../i86.h"
+//#include "../i286.h"
+#include "./i286.h"
 #include "../io.h"
 #include "../memory.h"
 #include "../noise.h"
@@ -52,7 +53,7 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        pit = new I8253(this, emu);
        pio = new I8255(this, emu);
        pic = new I8259(this, emu);
-       cpu = new I86(this, emu);       // 8088
+       cpu = new I286(this, emu);      // 8088
        io = new IO(this, emu);
        mem = new MEMORY(this, emu);
        pcm = new PCM1BIT(this, emu);
index 82f7a06..3b59975 100644 (file)
@@ -66,7 +66,7 @@ class I8251;
 class I8253;
 class I8255;
 class I8259;
-class I86;
+class I286;
 class IO;
 class MEMORY;
 class PCM1BIT;
@@ -91,7 +91,7 @@ protected:
        I8253* pit;
        I8255* pio;
        I8259* pic;
-       I86* cpu;
+       I286* cpu;
        IO* io;
        MEMORY* mem;
        PCM1BIT* pcm;
index 4fd95c1..9446e09 100644 (file)
@@ -483,7 +483,7 @@ public:
        }
        
        // bios
-       virtual bool bios_call_i86(uint32_t PC, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag)
+       virtual bool bios_call_far_i86(uint32_t PC, uint16_t regs[], uint16_t sregs[], int32_t* ZeroFlag, int32_t* CarryFlag)
        {
                return false;
        }
index eab4796..7abffff 100644 (file)
@@ -3056,6 +3056,10 @@ void I386_OPS_BASE::zero_state()
 {
        memset( &cpustate->reg, 0, sizeof(cpustate->reg) );
        memset( cpustate->sreg, 0, sizeof(cpustate->sreg) );
+
+       cpustate->total_cycles = 0;
+       cpustate->prev_total_cycles = 0;
+       
        cpustate->eip = 0;
        cpustate->pc = 0;
        cpustate->prev_eip = 0;
@@ -3268,6 +3272,8 @@ void I386_OPS_BASE::pentium_smi()
 
 void I386_OPS_BASE::i386_set_irq_line(int irqline, int state)
 {
+    int first_cycles = cpustate->cycles;
+
        if (state != CLEAR_LINE && cpustate->halted)
        {
                cpustate->halted = 0;
@@ -3288,6 +3294,8 @@ void I386_OPS_BASE::i386_set_irq_line(int irqline, int state)
        {
                cpustate->irq_state = state;
        }
+       cpustate->extra_cycles += first_cycles - cpustate->cycles;
+       cpustate->cycles = first_cycles;
 }
 
 void I386_OPS_BASE::i386_set_a20_line(int state)
@@ -3305,6 +3313,7 @@ void I386_OPS_BASE::i386_set_a20_line(int state)
 }
 
 // BASE execution : EXECUTE without DMA, BIOS and debugger.
+#include "../../debugger.h"
 int I386_OPS_BASE::cpu_execute_i386(int cycles)
 {
        CHANGE_PC(cpustate->eip);
@@ -3316,6 +3325,7 @@ int I386_OPS_BASE::cpu_execute_i386(int cycles)
                        // this is main cpu, cpustate->cycles is not used
                        /*cpustate->cycles = */cpustate->extra_cycles = 0;
                        cpustate->tsc += passed_cycles;
+                       cpustate->total_cycles += passed_cycles;
                        return passed_cycles;
                } else {
                        cpustate->cycles += cycles;
@@ -3331,6 +3341,7 @@ int I386_OPS_BASE::cpu_execute_i386(int cycles)
                        }
                        int passed_cycles = cpustate->base_cycles - cpustate->cycles;
                        cpustate->tsc += passed_cycles;
+                       cpustate->total_cycles += passed_cycles;
                        return passed_cycles;
                }
        }
@@ -3348,6 +3359,7 @@ int I386_OPS_BASE::cpu_execute_i386(int cycles)
 
        while( cpustate->cycles > 0 && !cpustate->busreq )
        {
+                       int first_cycles = cpustate->cycles;
                        i386_check_irq_line();
                        cpustate->operand_size = cpustate->sreg[CS].d;
                        cpustate->xmm_operand_size = 0;
@@ -3358,6 +3370,7 @@ int I386_OPS_BASE::cpu_execute_i386(int cycles)
                        cpustate->ext = 1;
                        int old_tf = cpustate->TF;
 
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
                        cpustate->segment_prefix = 0;
                        cpustate->prev_eip = cpustate->eip;
                        cpustate->prev_pc = cpustate->pc;
@@ -3391,14 +3404,17 @@ int I386_OPS_BASE::cpu_execute_i386(int cycles)
                        /* adjust for any interrupts that came in */
                        cpustate->cycles -= cpustate->extra_cycles;
                        cpustate->extra_cycles = 0;
+                       cpustate->total_cycles += first_cycles - cpustate->cycles;
        }
 
        /* if busreq is raised, spin cpu while remained clock */
        if (cpustate->cycles > 0 && cpustate->busreq) {
+               cpustate->total_cycles += cpustate->cycles;
                cpustate->cycles = 0;
        }
        int passed_cycles = cpustate->base_cycles - cpustate->cycles;
        cpustate->tsc += passed_cycles;
+       cpustate->total_cycles += passed_cycles;
        return passed_cycles;
 }
 
index b15ff2e..8fecf91 100644 (file)
@@ -774,11 +774,14 @@ void I386_OPS::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
 {
 #if defined(USE_DEBUGGER)
        my_stprintf_s(buffer, buffer_len,
-       _T("AX=%04X  BX=%04X CX=%04X DX=%04X SP=%04X  BP=%04X  SI=%04X  DI=%04X\nDS=%04X  ES=%04X SS=%04X CS=%04X IP=%04X  FLAG=[%c%c%c%c%c%c%c%c%c]"),
-       REG16(AX), REG16(BX), REG16(CX), REG16(DX), REG16(SP), REG16(BP), REG16(SI), REG16(DI),
-       cpustate->sreg[DS].selector, cpustate->sreg[ES].selector, cpustate->sreg[SS].selector, cpustate->sreg[CS].selector, cpustate->eip,
-       cpustate->OF ? _T('O') : _T('-'), cpustate->DF ? _T('D') : _T('-'), cpustate->IF ? _T('I') : _T('-'), cpustate->TF ? _T('T') : _T('-'),
-       cpustate->SF ? _T('S') : _T('-'), cpustate->ZF ? _T('Z') : _T('-'), cpustate->AF ? _T('A') : _T('-'), cpustate->PF ? _T('P') : _T('-'), cpustate->CF ? _T('C') : _T('-'));
+                                 _T("AX=%04X  BX=%04X CX=%04X DX=%04X SP=%04X  BP=%04X  SI=%04X  DI=%04X\nDS=%04X  ES=%04X SS=%04X CS=%04X IP=%04X  FLAG=[%c%c%c%c
+%c%c%c%c%c]\nTotal CPU Clocks = %llu (%llu)"),
+                                 cpustate->sreg[DS].selector, cpustate->sreg[ES].selector, cpustate->sreg[SS].selector, cpustate->sreg[CS].selector, cpustate->eip,
+                                 cpustate->OF ? _T('O') : _T('-'), cpustate->DF ? _T('D') : _T('-'), cpustate->IF ? _T('I') : _T('-'), cpustate->TF ? _T('T') : _T('-'),
+                                 cpustate->SF ? _T('S') : _T('-'), cpustate->ZF ? _T('Z') : _T('-'), cpustate->AF ? _T('A') : _T('-'), cpustate->PF ? _T('P') : _T('-'),
+                                 cpustate->CF ? _T('C') : _T('-'),
+                                 cpustate->total_cycles, cpustate->total_cycles - cpustate->prev_total_cycles);
+       cpustate->prev_total_cycles = cpustate->total_cycles;
 #endif
 }
 
index dd67891..b567b2a 100644 (file)
@@ -497,6 +497,7 @@ void I386_OPS_BASE::I386OP(call_abs16)()        // Opcode 0x9a
        UINT16 offset = FETCH16();
        UINT16 ptr = FETCH16();
 
+    CYCLES(CYCLES_CALL_INTERSEG);      /* TODO: Timing = 17 + m */
        if( PROTECTED_MODE && !V8086_MODE)
        {
                i386_protected_mode_call(ptr,offset,0,0);
@@ -510,7 +511,6 @@ void I386_OPS_BASE::I386OP(call_abs16)()        // Opcode 0x9a
                cpustate->eip = offset;
                i386_load_segment_descriptor(CS);
        }
-       CYCLES(CYCLES_CALL_INTERSEG);      /* TODO: Timing = 17 + m */
        CHANGE_PC(cpustate->eip);
 }
 
index c4a9293..f551b6d 100644 (file)
                return; \
        } \
 }
-#define BIOS_CALL(address) if(cpustate->bios != NULL) {        \
+
+#define BIOS_CALL_FAR(address) if(cpustate->bios != NULL) {    \
        uint16_t regs[8], sregs[4]; \
        regs[0] = REG16(AX); regs[1] = REG16(CX); regs[2] = REG16(DX); regs[3] = REG16(BX); \
        regs[4] = REG16(SP); regs[5] = REG16(BP); regs[6] = REG16(SI); regs[7] = REG16(DI); \
        sregs[0] = cpustate->sreg[ES].selector; sregs[1] = cpustate->sreg[CS].selector; \
        sregs[2] = cpustate->sreg[SS].selector; sregs[3] = cpustate->sreg[DS].selector; \
        int32_t ZeroFlag = cpustate->ZF, CarryFlag = cpustate->CF; \
-       if(cpustate->bios->bios_call_i86(address, regs, sregs, &ZeroFlag, &CarryFlag)) { \
+       if(cpustate->bios->bios_call_far_i86(address, regs, sregs, &ZeroFlag, &CarryFlag)) { \
                REG16(AX) = regs[0]; REG16(CX) = regs[1]; REG16(DX) = regs[2]; REG16(BX) = regs[3]; \
                REG16(SP) = regs[4]; REG16(BP) = regs[5]; REG16(SI) = regs[6]; REG16(DI) = regs[7]; \
                cpustate->ZF = (UINT8)ZeroFlag; cpustate->CF = (UINT8)CarryFlag; \
-               return; \
+               CYCLES(cpustate,CYCLES_RET_INTERSEG);                                                   \
+               return;                                                                                                                 \
        } \
 }
 #endif
@@ -38,8 +40,10 @@ void I386_OPS::i386_call_abs16()        // Opcode 0x9a
 {
        UINT16 offset = FETCH16();
        UINT16 ptr = FETCH16();
+    CYCLES(cpustate,CYCLES_CALL_INTERSEG);      /* TODO: Timing = 17 + m */
+
 #ifdef I386_PSEUDO_BIOS
-       BIOS_CALL(((ptr << 4) + offset) & cpustate->a20_mask)
+       BIOS_CALL_FAR(((ptr << 4) + offset) & cpustate->a20_mask)
 #endif
                //printf(" \n");
 
@@ -56,7 +60,6 @@ void I386_OPS::i386_call_abs16()        // Opcode 0x9a
                cpustate->eip = offset;
                i386_load_segment_descriptor(CS);
        }
-       CYCLES(CYCLES_CALL_INTERSEG);      /* TODO: Timing = 17 + m */
        CHANGE_PC(cpustate->eip);
 }
 
@@ -64,10 +67,6 @@ void I386_OPS::i386_call_rel16()        // Opcode 0xe8
 {
        INT16 disp = FETCH16();
 
-#ifdef I386_PSEUDO_BIOS
-       BIOS_CALL((cpustate->pc + disp) & cpustate->a20_mask)
-#endif
-
        PUSH16( cpustate->eip );
        if (cpustate->sreg[CS].d)
        {
@@ -126,9 +125,6 @@ void I386_OPS::i386_groupFF_16()        // Opcode 0xff
                                        address = READ16(ea);
                                        CYCLES(CYCLES_CALL_MEM);       /* TODO: Timing = 10 + m */
                                }
-#ifdef I386_PSEUDO_BIOS
-                               BIOS_CALL(((cpustate->sreg[CS].selector << 4) + address) & cpustate->a20_mask)
-#endif
                                PUSH16( cpustate->eip );
                                cpustate->eip = address;
                                CHANGE_PC(cpustate->eip);
@@ -148,7 +144,7 @@ void I386_OPS::i386_groupFF_16()        // Opcode 0xff
                                        selector = READ16(ea + 2);
                                        CYCLES(CYCLES_CALL_MEM_INTERSEG);      /* TODO: Timing = 10 + m */
 #ifdef I386_PSEUDO_BIOS
-                                       BIOS_CALL(((selector << 4) + address) & cpustate->a20_mask)
+                                       BIOS_CALL_FAR(((selector << 4) + address) & cpustate->a20_mask)
 #endif
                                        if(PROTECTED_MODE && !V8086_MODE)
                                        {
index fe3ea82..68ac84f 100644 (file)
@@ -486,6 +486,9 @@ struct i386_state
        int segment_prefix;
        int segment_override;
 
+       uint64_t total_cycles;
+       uint64_t prev_total_cycles;
+       
        int cycles;
        int extra_cycles;
        int base_cycles;
index 0401652..40da8d8 100644 (file)
@@ -1000,6 +1000,9 @@ int M6502::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
@@ -1079,10 +1082,16 @@ int M6502::run(int clock)
                }
                // 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;
        }
+#ifdef USE_DEBUGGER
+       total_icount += first_icount - icount;
+#endif
 }
 
 #define offs_t UINT16
@@ -1108,3 +1117,37 @@ int M6502::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
        return (int)(pc & DASMFLAG_LENGTHMASK);
 #endif
 }
+
+#define STATE_VERSION  2
+
+void M6502::save_state(FILEIO* state_fio)
+{
+       state_fio->FputUint32(STATE_VERSION);
+       state_fio->FputInt32(this_device_id);
+
+       save_state_regs(state_fio);
+#ifdef USE_DEBUGGER
+       state_fio->FputUint64(total_icount);
+#endif
+       state_fio->FputInt32(icount);
+       state_fio->FputBool(busreq);
+}
+
+bool M6502::load_state(FILEIO* state_fio)
+{
+       if(state_fio->FgetUint32() != STATE_VERSION) {
+               return false;
+       }
+       if(state_fio->FgetInt32() != this_device_id) {
+               return false;
+       }
+
+       load_state_regs(state_fio);
+#ifdef USE_DEBUGGER
+       total_icount = prev_total_icount = state_fio->FgetUint64();
+#endif
+       icount = state_fio->FgetInt32();
+       busreq = state_fio->FgetBool();
+       return true;
+}
+
index 5b3f992..2f926a2 100644 (file)
@@ -35,6 +35,10 @@ protected:
        uint8_t a, x, y, p;
        bool pending_irq, after_cli;
        bool nmi_state, irq_state, so_state;
+
+       uint64_t total_icount;
+       uint64_t prev_total_icount;
+
        int icount;
        bool busreq;
        
@@ -42,9 +46,12 @@ protected:
        virtual void OP(uint8_t code);
        void update_irq();
        
+       void save_state_regs(FILEIO* state_fio);
+       void load_state_regs(FILEIO* state_fio);
 public:
        M6502_BASE(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
        {
+               total_icount = prev_total_icount = 0;
                busreq = false;
                set_device_name(_T("M6502 CPU"));
        }
@@ -86,8 +93,6 @@ public:
        void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
        virtual int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
 //#endif
-       void save_state(FILEIO* state_fio);
-       bool load_state(FILEIO* state_fio);
        
        // unique functions
        void set_context_mem(DEVICE* device)
@@ -119,6 +124,8 @@ public:
        void reset();
        int run(int clock);
        int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
+       void save_state(FILEIO* state_fio);
+       bool load_state(FILEIO* state_fio);
 };     
 
 class N2A03 : public M6502_BASE
@@ -134,6 +141,8 @@ public:
        void reset();
        int run(int clock);
        int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
+       void save_state(FILEIO* state_fio);
+       bool load_state(FILEIO* state_fio);
 };     
 
 #endif
index 81cd568..8857b4b 100644 (file)
@@ -9,6 +9,7 @@
 */
 
 #include "m6502.h"
+#include "debugger.h"
 
 // vectors
 #define NMI_VEC        0xfffa
@@ -138,6 +139,7 @@ int M6502_BASE::run(int clock)
 
 void M6502_BASE::run_one_opecode()
 {
+       int first_icount = icount;
        // if an irq is pending, take it now
        if(nmi_state) {
                EAD = NMI_VEC;
@@ -150,6 +152,7 @@ void M6502_BASE::run_one_opecode()
                PCH = RDMEM(EAD + 1);
                nmi_state = false;
        } else if(pending_irq) {
+               if(d_debugger != NULL) d_debugger->add_cpu_trace(PCW);
                update_irq();
        }
        prev_pc = PCW;
@@ -223,10 +226,12 @@ bool M6502_BASE::write_debug_reg(const _TCHAR *reg, uint32_t data)
 void M6502_BASE::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
 {
        my_stprintf_s(buffer, buffer_len,
-       _T("PC = %04X  A = %02X  X = %02X  Y = %02X  S = %02X  P = %02X [%c%c%c%c%c%c%c%c]"),
-       PCW, A, X, Y, S, P,
-       (P & F_N) ? _T('N') : _T('-'), (P & F_V) ? _T('V') : _T('-'), (P & F_T) ? _T('T') : _T('-'), (P & F_B) ? _T('B') : _T('-'), 
-       (P & F_D) ? _T('D') : _T('-'), (P & F_I) ? _T('I') : _T('-'), (P & F_Z) ? _T('Z') : _T('-'), (P & F_C) ? _T('C') : _T('-'));
+       _T("PC = %04X  A = %02X  X = %02X  Y = %02X  S = %02X  P = %02X [%c%c%c%c%c%c%c%c]\nTotal CPU Clocks = %llu (%llu)"),
+       PCW, A, X, Y, S, P,
+       (P & F_N) ? _T('N') : _T('-'), (P & F_V) ? _T('V') : _T('-'), (P & F_T) ? _T('T') : _T('-'), (P & F_B) ? _T('B') : _T('-'), 
+       (P & F_D) ? _T('D') : _T('-'), (P & F_I) ? _T('I') : _T('-'), (P & F_Z) ? _T('Z') : _T('-'), (P & F_C) ? _T('C') : _T('-'),
+       total_icount, total_icount - prev_total_icount);
+       prev_total_icount = total_icount;
 }
 
 // disassembler
@@ -259,13 +264,8 @@ int M6502_BASE::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
 }
 //#endif
 
-#define STATE_VERSION  1
-
-void M6502_BASE::save_state(FILEIO* state_fio)
+void M6502_BASE::save_state_regs(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       state_fio->FputInt32(this_device_id);
-       
        state_fio->FputUint32(pc.d);
        state_fio->FputUint32(sp.d);
        state_fio->FputUint32(zp.d);
@@ -280,18 +280,10 @@ void M6502_BASE::save_state(FILEIO* state_fio)
        state_fio->FputBool(nmi_state);
        state_fio->FputBool(irq_state);
        state_fio->FputBool(so_state);
-       state_fio->FputInt32(icount);
-       state_fio->FputBool(busreq);
 }
 
-bool M6502_BASE::load_state(FILEIO* state_fio)
+void M6502_BASE::load_state_regs(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       if(state_fio->FgetInt32() != this_device_id) {
-               return false;
-       }
        pc.d = state_fio->FgetUint32();
        sp.d = state_fio->FgetUint32();
        zp.d = state_fio->FgetUint32();
@@ -308,6 +300,5 @@ bool M6502_BASE::load_state(FILEIO* state_fio)
        so_state = state_fio->FgetBool();
        icount = state_fio->FgetInt32();
        busreq = state_fio->FgetBool();
-       return true;
 }
 
index cc641a3..ffbba86 100644 (file)
@@ -3317,6 +3317,8 @@ static void pentium_smi(i386_state *cpustate)
 
 static void i386_set_irq_line(i386_state *cpustate,int irqline, int state)
 {
+       int first_cycles = cpustate->cycles;
+
        if (state != CLEAR_LINE && cpustate->halted)
        {
                cpustate->halted = 0;
@@ -3337,6 +3339,8 @@ static void i386_set_irq_line(i386_state *cpustate,int irqline, int state)
        {
                cpustate->irq_state = state;
        }
+       cpustate->extra_cycles += first_cycles - cpustate->cycles;
+       cpustate->cycles = first_cycles;
 }
 
 static void i386_set_a20_line(i386_state *cpustate,int state)
@@ -3369,6 +3373,9 @@ static CPU_EXECUTE( i386 )
                        // this is main cpu, cpustate->cycles is not used
                        /*cpustate->cycles = */cpustate->extra_cycles = 0;
                        cpustate->tsc += passed_cycles;
+#ifdef USE_DEBUGGER
+                       cpustate->total_cycles += passed_cycles;
+#endif
                        return passed_cycles;
                } else {
                        cpustate->cycles += cycles;
@@ -3384,6 +3391,9 @@ static CPU_EXECUTE( i386 )
                        }
                        int passed_cycles = cpustate->base_cycles - cpustate->cycles;
                        cpustate->tsc += passed_cycles;
+#ifdef USE_DEBUGGER
+                       cpustate->total_cycles += passed_cycles;
+#endif
                        return passed_cycles;
                }
        }
@@ -3396,6 +3406,9 @@ static CPU_EXECUTE( i386 )
        cpustate->base_cycles = cpustate->cycles;
 
        /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+       cpustate->total_cycles += cpustate->extra_cycles;
+#endif
        cpustate->cycles -= cpustate->extra_cycles;
        cpustate->extra_cycles = 0;
 
@@ -3418,6 +3431,7 @@ static CPU_EXECUTE( i386 )
                        } else {
                                now_debugging = false;
                        }
+                       int first_cycles = cpustate->cycles;
                        i386_check_irq_line(cpustate);
                        cpustate->operand_size = cpustate->sreg[CS].d;
                        cpustate->xmm_operand_size = 0;
@@ -3428,6 +3442,7 @@ static CPU_EXECUTE( i386 )
                        cpustate->ext = 1;
                        int old_tf = cpustate->TF;
 
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
                        cpustate->segment_prefix = 0;
                        cpustate->prev_eip = cpustate->eip;
                        cpustate->prev_pc = cpustate->pc;
@@ -3466,6 +3481,7 @@ static CPU_EXECUTE( i386 )
                        /* adjust for any interrupts that came in */
                        cpustate->cycles -= cpustate->extra_cycles;
                        cpustate->extra_cycles = 0;
+                       cpustate->total_cycles += first_cycles - cpustate->cycles;
                        
                        if(now_debugging) {
                                if(!cpustate->debugger->now_going) {
@@ -3475,6 +3491,7 @@ static CPU_EXECUTE( i386 )
                                cpustate->io = cpustate->io_stored;
                        }
                } else {
+                       int first_cycles = cpustate->cycles;
 #endif
                        i386_check_irq_line(cpustate);
                        cpustate->operand_size = cpustate->sreg[CS].d;
@@ -3486,6 +3503,9 @@ static CPU_EXECUTE( i386 )
                        cpustate->ext = 1;
                        int old_tf = cpustate->TF;
 
+#ifdef USE_DEBUGGER
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+#endif
                        cpustate->segment_prefix = 0;
                        cpustate->prev_eip = cpustate->eip;
                        cpustate->prev_pc = cpustate->pc;
@@ -3525,12 +3545,16 @@ static CPU_EXECUTE( i386 )
                        cpustate->cycles -= cpustate->extra_cycles;
                        cpustate->extra_cycles = 0;
 #ifdef USE_DEBUGGER
+                       cpustate->total_cycles += first_cycles - cpustate->cycles;
                }
 #endif
        }
 
        /* if busreq is raised, spin cpu while remained clock */
        if (cpustate->cycles > 0 && cpustate->busreq) {
+#ifdef USE_DEBUGGER
+               cpustate->total_cycles += cpustate->cycles;
+#endif
                cpustate->cycles = 0;
        }
        int passed_cycles = cpustate->base_cycles - cpustate->cycles;
index e4b7006..758bef5 100644 (file)
@@ -492,8 +492,10 @@ static void I386OP(call_abs16)(i386_state *cpustate)        // Opcode 0x9a
        UINT16 offset = FETCH16(cpustate);
        UINT16 ptr = FETCH16(cpustate);
 
+       CYCLES(cpustate,CYCLES_CALL_INTERSEG);      /* TODO: Timing = 17 + m */
+
 #ifdef I386_PSEUDO_BIOS
-       BIOS_CALL(((ptr << 4) + offset) & cpustate->a20_mask)
+       BIOS_CALL_FAR(((ptr << 4) + offset) & cpustate->a20_mask)
 #endif
 
        if( PROTECTED_MODE && !V8086_MODE)
@@ -509,7 +511,6 @@ static void I386OP(call_abs16)(i386_state *cpustate)        // Opcode 0x9a
                cpustate->eip = offset;
                i386_load_segment_descriptor(cpustate,CS);
        }
-       CYCLES(cpustate,CYCLES_CALL_INTERSEG);      /* TODO: Timing = 17 + m */
        CHANGE_PC(cpustate,cpustate->eip);
 }
 
@@ -517,10 +518,6 @@ static void I386OP(call_rel16)(i386_state *cpustate)        // Opcode 0xe8
 {
        INT16 disp = FETCH16(cpustate);
 
-#ifdef I386_PSEUDO_BIOS
-       BIOS_CALL((cpustate->pc + disp) & cpustate->a20_mask)
-#endif
-
        PUSH16(cpustate, cpustate->eip );
        if (cpustate->sreg[CS].d)
        {
@@ -3023,9 +3020,6 @@ static void I386OP(groupFF_16)(i386_state *cpustate)        // Opcode 0xff
                                        address = READ16(cpustate,ea);
                                        CYCLES(cpustate,CYCLES_CALL_MEM);       /* TODO: Timing = 10 + m */
                                }
-#ifdef I386_PSEUDO_BIOS
-                               BIOS_CALL(((cpustate->sreg[CS].selector << 4) + address) & cpustate->a20_mask)
-#endif
                                PUSH16(cpustate, cpustate->eip );
                                cpustate->eip = address;
                                CHANGE_PC(cpustate,cpustate->eip);
@@ -3045,7 +3039,7 @@ static void I386OP(groupFF_16)(i386_state *cpustate)        // Opcode 0xff
                                        selector = READ16(cpustate,ea + 2);
                                        CYCLES(cpustate,CYCLES_CALL_MEM_INTERSEG);      /* TODO: Timing = 10 + m */
 #ifdef I386_PSEUDO_BIOS
-                                       BIOS_CALL(((selector << 4) + address) & cpustate->a20_mask)
+                                       BIOS_CALL_FAR(((selector << 4) + address) & cpustate->a20_mask)
 #endif
                                        if(PROTECTED_MODE && !V8086_MODE)
                                        {
index 8d8b95f..bc88a1a 100644 (file)
@@ -402,6 +402,10 @@ struct i386_state
        int segment_prefix;
        int segment_override;
 
+#ifdef USE_DEBUGGER
+       uint64_t total_cycles;
+       uint64_t prev_total_cycles;
+#endif
        int cycles;
        int extra_cycles;
        int base_cycles;
index 3ea9976..16a9b9b 100644 (file)
@@ -85,6 +85,10 @@ struct i80286_state
        int trap_level;
        int shutdown;
 
+#ifdef USE_DEBUGGER
+       uint64_t total_icount;
+       uint64_t prev_total_icount;
+#endif
        int icount;
        char seg_prefix;
        UINT8   prefix_seg;
@@ -103,6 +107,9 @@ static struct i80x86_timing timing;
 bool i286_call_pseudo_bios(i80286_state *cpustate, uint32_t PC)
 {
 #ifdef I86_PSEUDO_BIOS
+       if(cpustate->bios != NULL) {
+               if(cpustate->bios->bios_call_far_i86(PC & AMASK, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal)) return true;
+       }
        if(cpustate->bios != NULL) return cpustate->bios->bios_call_i86(PC, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal);
 #endif
        return false;
@@ -196,6 +203,8 @@ static CPU_RESET( i80286 )
 
 static void set_irq_line(i80286_state *cpustate, int irqline, int state)
 {
+       int first_icount = cpustate->icount;
+
        if (state != CLEAR_LINE && cpustate->halted)
        {
                cpustate->halted = 0;
@@ -229,6 +238,8 @@ static void set_irq_line(i80286_state *cpustate, int irqline, int state)
        {
                i80286_trap2(cpustate, e);
        }
+       cpustate->extra_cycles += first_icount - cpustate->icount;
+       cpustate->icount = first_icount;
 }
 
 static CPU_EXECUTE( i80286 )
@@ -244,6 +255,9 @@ static CPU_EXECUTE( i80286 )
                        int passed_icount = max(1, cpustate->extra_cycles);
                        // this is main cpu, cpustate->icount is not used
                        /*cpustate->icount = */cpustate->extra_cycles = 0;
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += passed_icount;
+#endif
                        return passed_icount;
                } else {
                        cpustate->icount += icount;
@@ -257,6 +271,9 @@ static CPU_EXECUTE( i80286 )
                        if (cpustate->icount > 0) {
                                cpustate->icount = 0;
                        }
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += base_icount - cpustate->icount;
+#endif
                        return base_icount - cpustate->icount;
                }
        }
@@ -273,6 +290,9 @@ static CPU_EXECUTE( i80286 )
                timing = i80286_cycles;
 
        /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+       cpustate->total_icount += cpustate->extra_cycles;
+#endif
        cpustate->icount -= cpustate->extra_cycles;
        cpustate->extra_cycles = 0;
 
@@ -296,6 +316,8 @@ static CPU_EXECUTE( i80286 )
                        } else {
                                now_debugging = false;
                        }
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+                       int first_icount = cpustate->icount;
                        cpustate->seg_prefix=FALSE;
                        try
                        {
@@ -309,6 +331,7 @@ static CPU_EXECUTE( i80286 )
                        {
                                i80286_trap2(cpustate,e);
                        }
+                       cpustate->total_icount += first_icount - cpustate->icount;
 #ifdef SINGLE_MODE_DMA
                        if (cpustate->dma != NULL) {
                                cpustate->dma->do_dma();
@@ -322,6 +345,8 @@ static CPU_EXECUTE( i80286 )
                                cpustate->io = cpustate->io_stored;
                        }
                } else {
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+                       int first_icount = cpustate->icount;
 #endif
                        cpustate->seg_prefix=FALSE;
                        try
@@ -336,6 +361,9 @@ static CPU_EXECUTE( i80286 )
                        {
                                i80286_trap2(cpustate,e);
                        }
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += first_icount - cpustate->icount;
+#endif
 #ifdef SINGLE_MODE_DMA
                        if (cpustate->dma != NULL) {
                                cpustate->dma->do_dma();
@@ -345,12 +373,18 @@ static CPU_EXECUTE( i80286 )
                }
 #endif
                /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+               cpustate->total_icount += cpustate->extra_cycles;
+#endif
                cpustate->icount -= cpustate->extra_cycles;
                cpustate->extra_cycles = 0;
        }
 
        /* if busreq is raised, spin cpu while remained clock */
        if (cpustate->icount > 0 && cpustate->busreq) {
+#ifdef USE_DEBUGGER
+               cpustate->total_icount += cpustate->icount;
+#endif
                cpustate->icount = 0;
        }
        return base_icount - cpustate->icount;
index 4a24684..24d83a0 100644 (file)
@@ -68,6 +68,8 @@ struct i8086_state
        DEBUGGER *debugger;
        DEVICE *program_stored;
        DEVICE *io_stored;
+       uint64_t total_icount;
+       uint64_t prev_total_icount;
 #endif
        int icount;
 
@@ -108,7 +110,9 @@ static UINT8 parity_table[256];
 bool i86_call_pseudo_bios(i8086_state *cpustate, uint32_t PC)
 {
 #ifdef I86_PSEUDO_BIOS
-       if(cpustate->bios != NULL) return cpustate->bios->bios_call_i86(PC, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal);
+       if(cpustate->bios != NULL) {
+               if(cpustate->bios->bios_call_far_i86(PC, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal)) return true;
+       }
 #endif
        return false;
 }
@@ -190,6 +194,8 @@ static CPU_RESET( v30 )
 
 static void set_irq_line(i8086_state *cpustate, int irqline, int state)
 {
+       int first_icount = cpustate->icount;
+
        if (state != CLEAR_LINE && cpustate->halted)
        {
                cpustate->halted = 0;
@@ -218,6 +224,8 @@ static void set_irq_line(i8086_state *cpustate, int irqline, int state)
                        cpustate->irq_state = CLEAR_LINE;
                }
        }
+       cpustate->extra_cycles += first_icount - cpustate->icount;
+       cpustate->icount = first_icount;
 }
 
 static void set_drq_line(i8086_state *cpustate, int irqline, int state)
@@ -249,6 +257,9 @@ CPU_EXECUTE( i8086 )
                        int passed_icount = max(1, cpustate->extra_cycles);
                        // this is main cpu, cpustate->icount is not used
                        /*cpustate->icount = */cpustate->extra_cycles = 0;
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += passed_icount;
+#endif
                        return passed_icount;
                } else {
                        cpustate->icount += icount;
@@ -262,6 +273,9 @@ CPU_EXECUTE( i8086 )
                        if (cpustate->icount > 0) {
                                cpustate->icount = 0;
                        }
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += base_icount - cpustate->icount;
+#endif
                        return base_icount - cpustate->icount;
                }
        }
@@ -278,6 +292,9 @@ CPU_EXECUTE( i8086 )
                timing = i8086_cycles;
 
        /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+       cpustate->total_icount += cpustate->extra_cycles;
+#endif
        cpustate->icount -= cpustate->extra_cycles;
        cpustate->extra_cycles = 0;
 
@@ -301,9 +318,12 @@ CPU_EXECUTE( i8086 )
                        } else {
                                now_debugging = false;
                        }
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+                       int first_icount = cpustate->icount;
                        cpustate->seg_prefix = FALSE;
                        cpustate->prevpc = cpustate->pc;
                        TABLE86;
+                       cpustate->total_icount += first_icount - cpustate->icount;
 #ifdef SINGLE_MODE_DMA
                        if(cpustate->dma != NULL) {
                                cpustate->dma->do_dma();
@@ -317,10 +337,15 @@ CPU_EXECUTE( i8086 )
                                cpustate->io = cpustate->io_stored;
                        }
                } else {
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+                       int first_icount = cpustate->icount;
 #endif
                        cpustate->seg_prefix = FALSE;
                        cpustate->prevpc = cpustate->pc;
                        TABLE86;
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += first_icount - cpustate->icount;
+#endif
 #ifdef SINGLE_MODE_DMA
                        if(cpustate->dma != NULL) {
                                cpustate->dma->do_dma();
@@ -330,12 +355,18 @@ CPU_EXECUTE( i8086 )
                }
 #endif
                /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+               cpustate->total_icount += cpustate->extra_cycles;
+#endif
                cpustate->icount -= cpustate->extra_cycles;
                cpustate->extra_cycles = 0;
        }
 
        /* if busreq is raised, spin cpu while remained clock */
        if (cpustate->icount > 0 && cpustate->busreq) {
+#ifdef USE_DEBUGGER
+               cpustate->total_icount += cpustate->icount;
+#endif
                cpustate->icount = 0;
        }
        return base_icount - cpustate->icount;
@@ -373,6 +404,9 @@ CPU_EXECUTE( i80186 )
                        int passed_icount = max(1, cpustate->extra_cycles);
                        // this is main cpu, cpustate->icount is not used
                        /*cpustate->icount = */cpustate->extra_cycles = 0;
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += passed_icount;
+#endif
                        return passed_icount;
                } else {
                        cpustate->icount += icount;
@@ -386,6 +420,9 @@ CPU_EXECUTE( i80186 )
                        if (cpustate->icount > 0) {
                                cpustate->icount = 0;
                        }
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += base_icount - cpustate->icount;
+#endif
                        return base_icount - cpustate->icount;
                }
        }
@@ -402,6 +439,9 @@ CPU_EXECUTE( i80186 )
                timing = i80186_cycles;
 
        /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+       cpustate->total_icount += cpustate->extra_cycles;
+#endif
        cpustate->icount -= cpustate->extra_cycles;
        cpustate->extra_cycles = 0;
 
@@ -425,9 +465,12 @@ CPU_EXECUTE( i80186 )
                        } else {
                                now_debugging = false;
                        }
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+                       int first_icount = cpustate->icount;
                        cpustate->seg_prefix = FALSE;
                        cpustate->prevpc = cpustate->pc;
                        TABLE186;
+                       cpustate->total_icount += first_icount - cpustate->icount;
 #ifdef SINGLE_MODE_DMA
                        if (cpustate->dma != NULL) {
                                cpustate->dma->do_dma();
@@ -441,10 +484,15 @@ CPU_EXECUTE( i80186 )
                                cpustate->io = cpustate->io_stored;
                        }
                } else {
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+                       int first_icount = cpustate->icount;
 #endif
                        cpustate->seg_prefix = FALSE;
                        cpustate->prevpc = cpustate->pc;
                        TABLE186;
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += first_icount - cpustate->icount;
+#endif
 #ifdef SINGLE_MODE_DMA
                        if (cpustate->dma != NULL) {
                                cpustate->dma->do_dma();
@@ -454,12 +502,18 @@ CPU_EXECUTE( i80186 )
                }
 #endif
                /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+               cpustate->total_icount += cpustate->extra_cycles;
+#endif
                cpustate->icount -= cpustate->extra_cycles;
                cpustate->extra_cycles = 0;
        }
 
        /* if busreq is raised, spin cpu while remained clock */
        if (cpustate->icount > 0 && cpustate->busreq) {
+#ifdef USE_DEBUGGER
+               cpustate->total_icount += cpustate->icount;
+#endif
                cpustate->icount = 0;
        }
        return base_icount - cpustate->icount;
@@ -492,6 +546,9 @@ CPU_EXECUTE( v30 )
                        int passed_icount = max(1, cpustate->extra_cycles);
                        // this is main cpu, cpustate->icount is not used
                        /*cpustate->icount = */cpustate->extra_cycles = 0;
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += passed_icount;
+#endif
                        return passed_icount;
                } else {
                        cpustate->icount += icount;
@@ -505,6 +562,9 @@ CPU_EXECUTE( v30 )
                        if (cpustate->icount > 0) {
                                cpustate->icount = 0;
                        }
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += base_icount - cpustate->icount;
+#endif
                        return base_icount - cpustate->icount;
                }
        }
@@ -521,6 +581,9 @@ CPU_EXECUTE( v30 )
                timing = i80186_cycles;
 
        /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+       cpustate->total_icount += cpustate->extra_cycles;
+#endif
        cpustate->icount -= cpustate->extra_cycles;
        cpustate->extra_cycles = 0;
 
@@ -544,9 +607,12 @@ CPU_EXECUTE( v30 )
                        } else {
                                now_debugging = false;
                        }
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+                       int first_icount = cpustate->icount;
                        cpustate->seg_prefix = FALSE;
                        cpustate->prevpc = cpustate->pc;
                        TABLEV30;
+                       cpustate->total_icount += first_icount - cpustate->icount;
 #ifdef SINGLE_MODE_DMA
                        if (cpustate->dma != NULL) {
                                cpustate->dma->do_dma();
@@ -560,10 +626,15 @@ CPU_EXECUTE( v30 )
                                cpustate->io = cpustate->io_stored;
                        }
                } else {
+                       cpustate->debugger->add_cpu_trace(cpustate->pc);
+                       int first_icount = cpustate->icount;
 #endif
                        cpustate->seg_prefix = FALSE;
                        cpustate->prevpc = cpustate->pc;
                        TABLEV30;
+#ifdef USE_DEBUGGER
+                       cpustate->total_icount += first_icount - cpustate->icount;
+#endif
 #ifdef SINGLE_MODE_DMA
                        if (cpustate->dma != NULL) {
                                cpustate->dma->do_dma();
@@ -573,12 +644,18 @@ CPU_EXECUTE( v30 )
                }
 #endif
                /* adjust for any interrupts that came in */
+#ifdef USE_DEBUGGER
+               cpustate->total_icount += cpustate->extra_cycles;
+#endif
                cpustate->icount -= cpustate->extra_cycles;
                cpustate->extra_cycles = 0;
        }
 
        /* if busreq is raised, spin cpu while remained clock */
        if (cpustate->icount > 0 && cpustate->busreq) {
+#ifdef USE_DEBUGGER
+               cpustate->total_icount += cpustate->icount;
+#endif
                cpustate->icount = 0;
        }
        return base_icount - cpustate->icount;
index 4ed4f84..faf1b86 100644 (file)
@@ -1994,13 +1994,11 @@ static void PREFIX86(_call_far)(i8086_state *cpustate)
        tmp2 = FETCH;
        tmp2 += FETCH << 8;
 
-//#ifdef I86_PSEUDO_BIOS
-       //if(cpustate->bios != NULL && cpustate->bios->bios_call_i86(((tmp2 << 4) + tmp) & AMASK, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal)) {
+       ICOUNT -= timing.call_far;
        if(BIOS_CALL_86(cpustate, ((tmp2 << 4) + tmp) & AMASK)) {
-               ICOUNT -= timing.call_far;
+               ICOUNT -= timing.ret_far;
                return;
        }
-//#endif
 
        ip = cpustate->pc - cpustate->base[CS];
        cs = cpustate->sregs[CS];
@@ -2014,7 +2012,6 @@ static void PREFIX86(_call_far)(i8086_state *cpustate)
 #endif
        PUSH(cs);
        PUSH(ip);
-       ICOUNT -= timing.call_far;
        CHANGE_PC(cpustate->pc);
 }
 
@@ -2424,8 +2421,10 @@ static void PREFIX86(_int)(i8086_state *cpustate)    /* Opcode 0xcd */
 {
        unsigned int_num = FETCH;
        ICOUNT -= timing.int_imm;
+
 #ifdef I86_PSEUDO_BIOS
        if(cpustate->bios != NULL && cpustate->bios->bios_int_i86(int_num, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal)) {
+               ICOUNT -= timing.iret;
                return;
        }
 #endif
@@ -2649,13 +2648,6 @@ static void PREFIX86(_call_d16)(i8086_state *cpustate)    /* Opcode 0xe8 */
        WORD ip, tmp;
 
        FETCHWORD(tmp);
-//#ifdef I86_PSEUDO_BIOS
-       //if(cpustate->bios != NULL && cpustate->bios->bios_call_i86((cpustate->pc + tmp) & AMASK, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal)) {
-       if(BIOS_CALL_86(cpustate, (cpustate->pc + tmp) & AMASK)) {
-               ICOUNT -= timing.call_near;
-               return;
-       }
-//#endif
        ip = cpustate->pc - cpustate->base[CS];
        PUSH(ip);
        ip += tmp;
@@ -3257,13 +3249,6 @@ static void PREFIX86(_ffpre)(i8086_state *cpustate)    /* Opcode 0xff */
        case 0x10:  /* CALL ew */
                ICOUNT -= (ModRM >= 0xc0) ? timing.call_r16 : timing.call_m16;
                tmp = GetRMWord(ModRM);
-//#ifdef I86_PSEUDO_BIOS
-               //if(cpustate->bios != NULL && cpustate->bios->bios_call_i86((cpustate->base[CS] + (WORD)tmp) & AMASK, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal)) {
-               if(BIOS_CALL_86(cpustate, (cpustate->base[CS] + (WORD)tmp) & AMASK)) {
-                       ICOUNT -= timing.call_far;
-                       return;
-               }
-//#endif
                ip = cpustate->pc - cpustate->base[CS];
                PUSH(ip);
                cpustate->pc = (cpustate->base[CS] + (WORD)tmp) & AMASK;
@@ -3275,9 +3260,8 @@ static void PREFIX86(_ffpre)(i8086_state *cpustate)    /* Opcode 0xff */
                tmp = cpustate->sregs[CS];  /* HJB 12/13/98 need to skip displacements of cpustate->ea */
                tmp1 = GetRMWord(ModRM);
                tmp2 = GetnextRMWord;
-//#ifdef I86_PSEUDO_BIOS
-               //      if(cpustate->bios != NULL && cpustate->bios->bios_call_i86(((tmp2 << 4) + tmp1) & AMASK, cpustate->regs.w, cpustate->sregs, &cpustate->ZeroVal, &cpustate->CarryVal)) {
                if(BIOS_CALL_86(cpustate, ((tmp2 << 4) + tmp1) & AMASK)) {
+                       ICOUNT -= timing.ret_far;
                        return;
                }
 //#endif
index ade679f..7fc37ea 100644 (file)
@@ -62,14 +62,15 @@ void MC6800::WM16(uint32_t Addr, pair_t *p)
        WM((Addr + 1) & 0xffff, p->b.l);
 }
 
-//#if defined(HAS_MC6801) || defined(HAS_HD6301)
-//#else
+void MC6800::increment_counter(int amount)
+{
+       total_icount += amount;
+       icount -= amount;
+}
 
-#define increment_counter(amount) icount -= amount
-//#endif
 
 
-static const uint8_t MC6800::flags8i[256] = {
+const uint8_t MC6800::flags8i[256] = {
        /* increment */
        0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -89,7 +90,7 @@ static const uint8_t MC6800::flags8i[256] = {
        0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08
 };
 
-static const uint8_t MC6800::flags8d[256] = {
+const uint8_t MC6800::flags8d[256] = {
        /* decrement */
        0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -172,58 +173,30 @@ int MC6800::run(int clock)
        // run cpu
        if(clock == -1) {
                // run only one opcode
-//#if defined(HAS_MC6801) || defined(HAS_HD6301)
-//             CLEANUP_COUNTERS();
-//#endif
                icount = 0;
-//#ifdef USE_DEBUGGER
-               if(__USE_DEBUGGER) {
-                       bool now_debugging = d_debugger->now_debugging;
-                       if(now_debugging) {
-                               d_debugger->check_break_points(PC);
-                               if(d_debugger->now_suspended) {
-                                       emu->mute_sound();
-                                       d_debugger->now_waiting = true;
-                                       while(d_debugger->now_debugging && d_debugger->now_suspended) {
-                                               emu->sleep(10);
-                                       }
-                                       d_debugger->now_waiting = false;
-                               }
-                               if(d_debugger->now_debugging) {
-                                       d_mem = d_debugger;
-                               } else {
-                                       now_debugging = false;
-                               }
-                               
-                               run_one_opecode();
-                               
-                               if(now_debugging) {
-                                       if(!d_debugger->now_going) {
-                                               d_debugger->now_suspended = true;
-                                       }
-                                       d_mem = d_mem_stored;
-                               }
-
-                       } else {
-//#endif
-                               run_one_opecode();
-                       }
-               } else {
-                       run_one_opecode();
-//#ifdef USE_DEBUGGER
-               }
-//#endif
+               run_one_opecode();
                return -icount;
-       }
-       /* run cpu while given clocks */
-//#if defined(HAS_MC6801) || defined(HAS_HD6301)
-//             CLEANUP_COUNTERS();
-//#endif
+       } else {
+               /* run cpu while given clocks */
                icount += clock;
                int first_icount = icount;
-               
+                
                while(icount > 0) {
-//#ifdef USE_DEBUGGER
+                       run_one_opecode();
+               }
+               return first_icount - icount;
+       }
+       return 1;
+}
+
+
+void MC6800::run_one_opecode()
+{
+       if(wai_state & (MC6800_WAI | HD6301_SLP)) {
+               increment_counter(1);
+       } else {
+               do {
+                       one_more_insn = false;
                        if(__USE_DEBUGGER) {
                                bool now_debugging = d_debugger->now_debugging;
                                if(now_debugging) {
@@ -242,7 +215,12 @@ int MC6800::run(int clock)
                                                now_debugging = false;
                                        }
                                        
-                                       run_one_opecode();
+                                       d_debugger->add_cpu_trace(PC);
+                                       uint8_t ireg = M_RDOP(PCD);
+                                       prevpc = PC;
+                                       PC++;
+                                       insn(ireg);
+                                       increment_counter(cycles[ireg]);
                                        
                                        if(now_debugging) {
                                                if(!d_debugger->now_going) {
@@ -251,29 +229,21 @@ int MC6800::run(int clock)
                                                d_mem = d_mem_stored;
                                        }
                                } else {
-//#endif
-                                       run_one_opecode();
+                                       if(__USE_DEBUGGER) d_debugger->add_cpu_trace(PC);
+                                       uint8_t ireg = M_RDOP(PCD);
+                                       prevpc = PC;
+                                       PC++;
+                                       insn(ireg);
+                                       increment_counter(cycles[ireg]);
                                }
                        } else {
-                               run_one_opecode();
-//#ifdef USE_DEBUGGER
+                               uint8_t ireg = M_RDOP(PCD);
+                               prevpc = PC;
+                               PC++;
+                               insn(ireg);
+                               increment_counter(cycles[ireg]);
                        }
-//#endif
-               }
-               return first_icount - icount;
-}
-
-
-void MC6800::run_one_opecode()
-{
-       if(wai_state & (MC6800_WAI | HD6301_SLP)) {
-               increment_counter(1);
-       } else {
-               uint8_t ireg = M_RDOP(PCD);
-               prevpc = PC;
-               PC++;
-               insn(ireg);
-               increment_counter(cycles[ireg]);
+               } while(one_more_insn);
        }
        
        // check interrupt
@@ -356,9 +326,12 @@ bool MC6800::write_debug_reg(const _TCHAR *reg, uint32_t data)
 void MC6800::get_debug_regs_info(_TCHAR *buffer, size_t buffer_len)
 {
        my_stprintf_s(buffer, buffer_len,
-       _T("CCR = [%c%c%c%c%c%c]  A = %02X  B = %02X  IX = %04X  PC = %04X  SP = %04X"),
-       (CC & 0x01) ? _T('C') : _T('-'), (CC & 0x02) ? _T('V') : _T('-'), (CC & 0x04) ? _T('Z') : _T('-'), (CC & 0x08) ? _T('N') : _T('-'),
-       (CC & 0x10) ? _T('I') : _T('-'), (CC & 0x20) ? _T('X') : _T('-'), A, B, X, PC, S);
+                                 _T("CCR = [%c%c%c%c%c%c]  A = %02X  B = %02X  IX = %04X  PC = %04X  SP = %04X\nTotal CPU Clocks = %llu (%llu)"),                                
+                                 (CC & 0x01) ? _T('C') : _T('-'), (CC & 0x02) ? _T('V') : _T('-'), (CC & 0x04) ? _T('Z') : _T('-'), (CC & 0x08) ? _T('N') : _T('-'
+),
+                                 (CC & 0x10) ? _T('I') : _T('-'), (CC & 0x20) ? _T('X') : _T('-'), A, B, X, PC, S,
+                                 total_icount, total_icount - prev_total_icount);
+       prev_total_icount = total_icount;
 }
 
 /*
@@ -624,6 +597,7 @@ int MC6800::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
 void MC6800::enter_interrupt(uint16_t irq_vector)
 {
        if(wai_state & MC6800_WAI) {
+               total_icount += 4;
                icount -= 4;
                wai_state &= ~MC6800_WAI;
        } else {
@@ -632,6 +606,7 @@ void MC6800::enter_interrupt(uint16_t irq_vector)
                PUSHBYTE(A);
                PUSHBYTE(B);
                PUSHBYTE(CC);
+               total_icount += 12;
                icount -= 12;
        }
        SEI;
@@ -1075,7 +1050,8 @@ void MC6800::nop()
 void MC6800::tap()
 {
        CC = A;
-       ONE_MORE_INSN();
+//     ONE_MORE_INSN();
+       one_more_insn = true;
 }
 
 /* $07 TPA inherent ----- */
@@ -1128,14 +1104,16 @@ void MC6800::sec()
 void MC6800::cli()
 {
        CLI;
-       ONE_MORE_INSN();
+//     ONE_MORE_INSN();
+       one_more_insn = true;
 }
 
 /* $0f SEI */
 void MC6800::sei()
 {
        SEI;
-       ONE_MORE_INSN();
+//     ONE_MORE_INSN();
+       one_more_insn = true;
 }
 
 /* $10 SBA inherent -**** */
@@ -3068,7 +3046,7 @@ void MC6800::stx_ex()
        WM16(EAD, &pX);
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
 void MC6800::save_state(FILEIO* state_fio)
 {
@@ -3084,6 +3062,9 @@ void MC6800::save_state(FILEIO* state_fio)
        state_fio->FputUint8(cc);
        state_fio->FputInt32(wai_state);
        state_fio->FputInt32(int_state);
+//#ifdef USE_DEBUGGER
+       if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
+//#endif
        state_fio->FputInt32(icount);
 }
 
@@ -3104,6 +3085,9 @@ bool MC6800::load_state(FILEIO* state_fio)
        cc = state_fio->FgetUint8();
        wai_state = state_fio->FgetInt32();
        int_state = state_fio->FgetInt32();
+//#ifdef USE_DEBUGGER
+       if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
+//#endif
        icount = state_fio->FgetInt32();
        return true;
 }
index bfa8e38..62b5afc 100644 (file)
@@ -76,7 +76,12 @@ protected:
        int wai_state;
        int int_state;
        
+
+       uint64_t total_icount;
+       uint64_t prev_total_icount;
+
        int icount;
+       bool one_more_insn;
        
        virtual uint32_t RM(uint32_t Addr);
        virtual void WM(uint32_t Addr, uint32_t Value);
@@ -84,6 +89,7 @@ protected:
        void WM16(uint32_t Addr, pair_t *p);
        
        
+       virtual void increment_counter(int amount);
        virtual void run_one_opecode();
        void enter_interrupt(uint16_t irq_vector);
        virtual void insn(uint8_t code);
index 9b69618..34c8390 100644 (file)
@@ -279,6 +279,7 @@ void MC6801::mc6801_io_w(uint32_t offset, uint32_t data)
 
 void MC6801::increment_counter(int amount)
 {
+       total_icount += amount;
        icount -= amount;
        
        // timer
@@ -441,60 +442,37 @@ void MC6801::write_signal(int id, uint32_t data, uint32_t mask)
 
 int MC6801::run(int clock)
 {
-               // run cpu
-       if(clock == -1) {
-               // run only one opcode
-//#if defined(HAS_MC6801) || defined(HAS_HD6301)
-               CLEANUP_COUNTERS();
-//#endif
-               icount = 0;
-               if(__USE_DEBUGGER) {
-//#ifdef USE_DEBUGGER
-                       bool now_debugging = d_debugger->now_debugging;
-                       if(now_debugging) {
-                               d_debugger->check_break_points(PC);
-                               if(d_debugger->now_suspended) {
-                                       emu->mute_sound();
-                                       d_debugger->now_waiting = true;
-                                       while(d_debugger->now_debugging && d_debugger->now_suspended) {
-                                               emu->sleep(10);
-                                       }
-                                       d_debugger->now_waiting = false;
-                               }
-                               if(d_debugger->now_debugging) {
-                                       d_mem = d_debugger;
-                               } else {
-                                       now_debugging = false;
-                               }
-                               
-                               run_one_opecode();
-                       
-                               if(now_debugging) {
-                                       if(!d_debugger->now_going) {
-                                               d_debugger->now_suspended = true;
-                                       }
-                                       d_mem = d_mem_stored;
-                               }
-                       } else {
-//#endif
-                         run_one_opecode();
-                       }
-               } else {
-                       run_one_opecode();
-//#ifdef USE_DEBUGGER
-               }
-//#endif
-               return -icount;
+        // run cpu
+        if(clock == -1) {
+                // run only one opcode
+
+                CLEANUP_COUNTERS();
+
+                icount = 0;
+                run_one_opecode();
+                return -icount;
+        } else {
+                /* run cpu while given clocks */
+
+                CLEANUP_COUNTERS();
+
+                icount += clock;
+                int first_icount = icount;
+                
+                while(icount > 0) {
+                        run_one_opecode();
+                }
+                return first_icount - icount;
+        }
+}
+
+void MC6801::run_one_opecode()
+{
+       if(wai_state & (MC6800_WAI | HD6301_SLP)) {
+               increment_counter(1);
        } else {
-               /* run cpu while given clocks */
-//#if defined(HAS_MC6801) || defined(HAS_HD6301)
-               CLEANUP_COUNTERS();
-//#endif
-               icount += clock;
-               int first_icount = icount;
-               
-               while(icount > 0) {
-//#ifdef USE_DEBUGGER
+               do {
+                       one_more_insn = false;
                        if(__USE_DEBUGGER) {
                                bool now_debugging = d_debugger->now_debugging;
                                if(now_debugging) {
@@ -510,10 +488,15 @@ int MC6801::run(int clock)
                                        if(d_debugger->now_debugging) {
                                                d_mem = d_debugger;
                                        } else {
-                                       now_debugging = false;
+                                               now_debugging = false;
                                        }
                                        
-                                       run_one_opecode();
+                                       d_debugger->add_cpu_trace(PC);
+                                       uint8_t ireg = M_RDOP(PCD);
+                                       prevpc = PC;
+                                       PC++;
+                                       insn(ireg);
+                                       increment_counter(cycles[ireg]);
                                        
                                        if(now_debugging) {
                                                if(!d_debugger->now_going) {
@@ -522,29 +505,21 @@ int MC6801::run(int clock)
                                                d_mem = d_mem_stored;
                                        }
                                } else {
-//#endif
-                                       run_one_opecode();
-//#ifdef USE_DEBUGGER
+                                       if(__USE_DEBUGGER) d_debugger->add_cpu_trace(PC);
+                                       uint8_t ireg = M_RDOP(PCD);
+                                       prevpc = PC;
+                                       PC++;
+                                       insn(ireg);
+                                       increment_counter(cycles[ireg]);
                                }
                        } else {
-                               run_one_opecode();
+                               uint8_t ireg = M_RDOP(PCD);
+                               prevpc = PC;
+                               PC++;
+                               insn(ireg);
+                               increment_counter(cycles[ireg]);
                        }
-//#endif
-               }
-               return first_icount - icount;
-       }
-}
-
-void MC6801::run_one_opecode()
-{
-       if(wai_state & (MC6800_WAI | HD6301_SLP)) {
-               increment_counter(1);
-       } else {
-               uint8_t ireg = M_RDOP(PCD);
-               prevpc = PC;
-               PC++;
-               insn(ireg);
-               increment_counter(cycles[ireg]);
+               } while(one_more_insn);
        }
        
        // check interrupt
@@ -1268,7 +1243,7 @@ void MC6801::std_ex()
        WM16(EAD, &pD);
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
 void MC6801::save_state(FILEIO* state_fio)
 {
@@ -1284,6 +1259,7 @@ void MC6801::save_state(FILEIO* state_fio)
        state_fio->FputUint8(cc);
        state_fio->FputInt32(wai_state);
        state_fio->FputInt32(int_state);
+       if(__USE_DEBUGGER) state_fio->FputUint64(total_icount);
        state_fio->FputInt32(icount);
 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
        for(int i = 0; i < 4; i++) {
@@ -1339,6 +1315,7 @@ bool MC6801::load_state(FILEIO* state_fio)
        cc = state_fio->FgetUint8();
        wai_state = state_fio->FgetInt32();
        int_state = state_fio->FgetInt32();
+       if(__USE_DEBUGGER) { total_icount = prev_total_icount = state_fio->FgetUint64(); }
        icount = state_fio->FgetInt32();
 //#if defined(HAS_MC6801) || defined(HAS_HD6301)
        for(int i = 0; i < 4; i++) {
index d036b7c..3fca44a 100644 (file)
 #include "../i8237.h"
 #include "../i8255.h"
 #include "../i8259.h"
-#if defined(HAS_I286) || defined(HAS_I186)
+//#if defined(HAS_I286) || defined(HAS_I186)
 #include "../i286.h"
-#else
-#include "../i86.h"
-#endif
+//#else
+//#include "../i86.h"
+//#endif
 #include "../io.h"
 #include "../ls393.h"
 #include "../mz1p17.h"
@@ -66,11 +66,11 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        dma = new I8237(this, emu);
        pio = new I8255(this, emu);
        pic = new I8259(this, emu);
-#if defined(HAS_I286) || defined(HAS_I186)
+//#if defined(HAS_I286) || defined(HAS_I186)
        cpu = new I286(this, emu);
-#else
-       cpu = new I86(this, emu);
-#endif
+//#else
+//     cpu = new I86(this, emu);
+//#endif
        io = new IO(this, emu);
        div = new LS393(this, emu);
        not_data0 = new NOT(this, emu);
index c4778b2..c4552ea 100644 (file)
@@ -85,11 +85,11 @@ class EVENT;
 class I8237;
 class I8255;
 class I8259;
-#if defined(HAS_I286) || defined(HAS_I186)
+//#if defined(HAS_I286) || defined(HAS_I186)
 class I286;
-#else
-class I86;
-#endif
+//#else
+//class I86;
+//#endif
 class IO;
 class LS393;
 class NOT;
@@ -118,11 +118,11 @@ protected:
        I8237* dma;
        I8255* pio;
        I8259* pic;     // includes 2chips
-#if defined(HAS_I286) || defined(HAS_I186)
+//#if defined(HAS_I286) || defined(HAS_I186)
        I286* cpu;
-#else
-       I86* cpu;
-#endif
+//#else
+//     I86* cpu;
+//#endif
        IO* io;
        LS393* div;
        NOT* not_data0;
index d9fb60e..dc75e68 100644 (file)
 #include "../upd7220.h"
 #include "../upd765a.h"
 
+#ifdef USE_DEBUGGER
+#include "../debugger.h"
+#endif
+
 #include "display.h"
 #include "floppy.h"
 #include "keyboard.h"
@@ -110,6 +114,9 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        cpu->set_context_mem(memory);
        cpu->set_context_io(io);
        cpu->set_context_intr(pic);
+#ifdef USE_DEBUGGER
+       cpu->set_context_debugger(new DEBUGGER(this, emu));
+#endif
        
        // i/o bus
        io->set_iomap_alias_w(0x00, pic, 0);
@@ -286,6 +293,20 @@ void VM::run()
 }
 
 // ----------------------------------------------------------------------------
+// debugger
+// ----------------------------------------------------------------------------
+
+#ifdef USE_DEBUGGER
+DEVICE *VM::get_cpu(int index)
+{
+       if(index == 0) {
+               return cpu;
+       }
+       return NULL;
+}
+#endif
+
+// ----------------------------------------------------------------------------
 // draw screen
 // ----------------------------------------------------------------------------
 
index d38f7d7..4ed05b7 100644 (file)
@@ -37,6 +37,8 @@
 #define USE_AUTO_KEY_NUMPAD
 #define USE_SCREEN_FILTER
 #define USE_SOUND_VOLUME       2
+#define USE_DEBUGGER
+
 #include "../../common.h"
 #include "../../fileio.h"
 
@@ -113,6 +115,11 @@ public:
        void reset();
        void run();
        
+#ifdef USE_DEBUGGER
+       // debugger
+       DEVICE *get_cpu(int index);
+#endif
+       
        // draw screen
        void draw_screen();
        
index ca2e78c..fe04058 100644 (file)
@@ -18,7 +18,7 @@
 #include "../i8251.h"
 #include "../i8255.h"
 #include "../i8259.h"
-#include "../i86.h"
+#include "../i286.h"
 #include "../io.h"
 #include "../memory.h"
 #include "../msm58321.h"
@@ -53,7 +53,7 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        pio1 = new I8255(this, emu);
        pio1->set_device_name(_T("8255 PIO (CRTC)"));
        pic = new I8259(this, emu);
-       cpu = new I86(this, emu);
+       cpu = new I286(this, emu);
        io = new IO(this, emu);
        memory = new MEMORY(this, emu);
        rtc = new MSM58321(this, emu);
index c0ddece..1fe3334 100644 (file)
@@ -66,7 +66,7 @@ class BEEP;
 class I8251;
 class I8255;
 class I8259;
-class I86;
+class I286;
 class IO;
 class MEMORY;
 class MSM58321;
@@ -91,7 +91,7 @@ protected:
        I8255* pio0;
        I8255* pio1;
        I8259* pic;     // includes 2chips
-       I86* cpu;
+       I286* cpu;
        IO* io;
        MEMORY* memory;
        MSM58321* rtc;
index 8ef32e9..8f70538 100644 (file)
@@ -2789,7 +2789,7 @@ underrun:
        if(exitline != -1) {
                for(int cy = exitline; cy < 200; cy++) {
                        memset(&text.expand[cy][0], 0, width);
-                       memset(&attrib.expand[cy][0], 0, width);
+                       memset(&attrib.expand[cy][0], 0xe0, width); // color=7
                }
        }
 }
index c762da6..567277c 100644 (file)
 #include "../i8253.h"
 #include "../i8255.h"
 #include "../i8259.h"
-#if defined(HAS_V30) || defined(HAS_I86)
-# include "../i86.h"
-#else
+//#if defined(HAS_V30) || defined(HAS_I86)
+//# include "../i86.h"
+//#else
 # include "../i286.h"
-#endif
+//#endif
 #include "../io.h"
 #include "../noise.h"
 #include "../not.h"
@@ -70,11 +70,11 @@ VM::VM(EMU* parent_emu) : emu(parent_emu)
        pio_prn = new I8255(this, emu); // for printer
        pio_prn->set_device_name(_T("8251 PIO (Printer)"));
        pic = new I8259(this, emu);     // V50 internal
-#if defined(HAS_V30) || defined(HAS_I86)
-       cpu = new I86(this, emu);       // V50
-#else
+//#if defined(HAS_V30) || defined(HAS_I86)
+//     cpu = new I86(this, emu);       // V50
+//#else
        cpu = new I286(this, emu);      // V50
-#endif
+//#endif
        io = new IO(this, emu);
        not_busy = new NOT(this, emu);
 #ifdef _PC98HA
index 7c5057b..72858d2 100644 (file)
@@ -74,11 +74,11 @@ class I8251;
 class I8253;
 class I8255;
 class I8259;
-#if defined(HAS_V30) || defined(HAS_I86)
-class I86;
-#else
+//#if defined(HAS_V30) || defined(HAS_I86)
+//class I86;
+//#else
 class I286;
-#endif
+//#endif
 class IO;
 class NOT;
 #ifdef _PC98HA
@@ -112,11 +112,11 @@ protected:
        I8255* pio_sys;
        I8255* pio_prn;
        I8259* pic;
-#if defined(HAS_V30) || defined(HAS_I86)
-       I86* cpu;
-#else
+//#if defined(HAS_V30) || defined(HAS_I86)
+//     I86* cpu;
+//#else
        I286* cpu;
-#endif
+//#endif
        IO* io;
        NOT* not_busy;
 #ifdef _PC98HA
index ffdad77..40c6e02 100644 (file)
@@ -367,7 +367,9 @@ void TMS9995::run_one_opecode()
                        now_debugging = false;
                }
                
+               int first_count = count;
                run_one_opecode_tmp();
+               total_count += first_count - count;
                
                if(now_debugging) {
                        if(!d_debugger->now_going) {
@@ -376,7 +378,9 @@ void TMS9995::run_one_opecode()
                        d_mem_tmp = d_io_tmp = this;
                }
        } else {
+               int first_count = count;
                run_one_opecode_tmp();
+               total_count += first_count - count;
        }
 }
 void TMS9995::run_one_opecode_tmp()
@@ -421,6 +425,9 @@ void TMS9995::run_one_opecode_tmp()
                period += 8;
        } else {
                int_enabled = true;
+#ifdef USE_DEBUGGER
+               d_debugger->add_cpu_trace(PC);
+#endif
                prevPC = PC;
                uint16_t op = FETCH16();
                execute(op);
@@ -1603,9 +1610,10 @@ ST = 0000 [LGT:0 AGT:0 EQ:0 C:0 OV:0 OP:0 X:0 OVIE:0 IM:0]
 PC = 0000 WP = 0000
 R0 = 0000 R1 = 0000 R2 = 0000 R3 = 0000 R4 = 0000 R5 = 0000 R6 = 0000 R7 = 0000
 R8 = 0000 R9 = 0000 R10= 0000 R11= 0000 R12= 0000 R13= 0000 R14= 0000 R15= 0000
+Total CPU Clocks = 0 (0)
 */
        my_stprintf_s(buffer, buffer_len,
-       _T("ST = %04X [LGT:%01X AGT:%01X EQ:%01X C:%01X OV:%01X OP:%01X X:%01X OVIE:%01X IM:%01X]\nPC = %04X WP = %04X\nR0 = %04X R1 = %04X R2 = %04X R3 = %04X R4 = %04X R5 = %04X R6 = %04X R7 = %04X\nR8 = %04X R9 = %04X R10= %04X R11= %04X R12= %04X R13= %04X R14= %04X R15= %04X"),
+       _T("ST = %04X [LGT:%01X AGT:%01X EQ:%01X C:%01X OV:%01X OP:%01X X:%01X OVIE:%01X IM:%01X]\nPC = %04X WP = %04X\nR0 = %04X R1 = %04X R2 = %04X R3 = %04X R4 = %04X R5 = %04X R6 = %04X R7 = %04X\nR8 = %04X R9 = %04X R10= %04X R11= %04X R12= %04X R13= %04X R14= %04X R15= %04X\nTotal CPU Clocks = %llu (%llu)"),
        ST,
        (ST & ST_LGT ) ? 1 : 0,
        (ST & ST_AGT ) ? 1 : 0,
@@ -1632,7 +1640,9 @@ R8 = 0000 R9 = 0000 R10= 0000 R11= 0000 R12= 0000 R13= 0000 R14= 0000 R15= 0000
        this->read_data16((WP + R12) & 0xffff),
        this->read_data16((WP + R13) & 0xffff),
        this->read_data16((WP + R14) & 0xffff),
-       this->read_data16((WP + R15) & 0xffff));
+       this->read_data16((WP + R15) & 0xffff),
+       total_count, total_count - prev_total_count);
+       prev_total_count = total_count;
 }
 
 // disassembler
@@ -1684,13 +1694,16 @@ int TMS9995::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
 }
 #endif
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
 void TMS9995::save_state(FILEIO* state_fio)
 {
        state_fio->FputUint32(STATE_VERSION);
        state_fio->FputInt32(this_device_id);
        
+#ifdef USE_DEBUGGER
+       state_fio->FputUint64(total_count);
+#endif
        state_fio->FputInt32(count);
        state_fio->FputInt32(period);
        state_fio->FputUint16(WP);
@@ -1722,6 +1735,9 @@ bool TMS9995::load_state(FILEIO* state_fio)
        if(state_fio->FgetInt32() != this_device_id) {
                return false;
        }
+#ifdef USE_DEBUGGER
+       total_count = prev_total_count = state_fio->FgetUint64();
+#endif
        count = state_fio->FgetInt32();
        period = state_fio->FgetInt32();
        WP = state_fio->FgetUint16();
index d557058..974fa74 100644 (file)
@@ -34,6 +34,10 @@ private:
 #endif
        
        // clocks
+#ifdef USE_DEBUGGER
+       uint64_t total_count;
+       uint64_t prev_total_count;
+#endif
        int count, period;
        // register
        uint16_t WP, PC, prevPC, ST;
@@ -114,6 +118,9 @@ public:
        TMS9995(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
        {
                // init registers
+#ifdef USE_DEBUGGER
+               total_count = prev_total_count = 0;
+#endif
                WP = PC = ST = 0;
                memset(RAM, 0, sizeof(RAM));
                irq_level = int_state = int_latch = 0;
index 53f73e1..14bad4b 100644 (file)
@@ -1202,10 +1202,16 @@ void UPD7801::run_one_opecode()
                }
                
                // run 1 opecode
+#ifdef USE_DEBUGGER
+               d_debugger->add_cpu_trace(PC);
+#endif
                period = 0;
                prevPC = PC;
                OP();
        }
+
+       total_count += period;
+
        count -= period;
        
        // update serial count
@@ -1384,15 +1390,18 @@ void UPD7801::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>
+Total CPU Clocks = 0 (0)
 */
        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>\nTotal CPU Clocks = %llu (%llu)"),
        VA, BC, DE, HL, PSW,
        (PSW & F_Z) ? _T("Z") : _T("-"), (PSW & F_SK) ? _T("SK") : _T("--"), (PSW & F_HC) ? _T("HC") : _T("--"), (PSW & F_L1) ? _T("L1") : _T("--"), (PSW & F_L0) ? _T("L0") : _T("--"), (PSW & F_CY) ? _T("CY") : _T("--"),
        altVA, altBC, altDE, altHL, SP, PC,
        d_mem_stored->read_data16w(BC, &wait), d_mem_stored->read_data16w(DE, &wait), d_mem_stored->read_data16w(HL, &wait), d_mem_stored->read_data16w(SP, &wait),
-       IFF ? _T("EI") : _T("DI"));
+       IFF ? _T("EI") : _T("DI"),
+       total_count, total_count - prev_total_count);
+       prev_total_count = total_count;
 }
 
 // disassembler
@@ -3898,13 +3907,16 @@ void UPD7801::OP74()
        }
 }
 
-#define STATE_VERSION  3
+#define STATE_VERSION  4
 
 void UPD7801::save_state(FILEIO* state_fio)
 {
        state_fio->FputUint32(STATE_VERSION);
        state_fio->FputInt32(this_device_id);
        
+#ifdef USE_DEBUGGER
+       state_fio->FputUint64(total_count);
+#endif
        state_fio->FputInt32(count);
        state_fio->FputInt32(period);
        state_fio->FputInt32(scount);
@@ -3942,6 +3954,9 @@ bool UPD7801::load_state(FILEIO* state_fio)
        if(state_fio->FgetInt32() != this_device_id) {
                return false;
        }
+#ifdef USE_DEBUGGER
+       total_count = prev_total_count = state_fio->FgetUint64();
+#endif
        count = state_fio->FgetInt32();
        period = state_fio->FgetInt32();
        scount = state_fio->FgetInt32();
index 569318e..ffb3004 100644 (file)
@@ -49,6 +49,10 @@ private:
        registers
        --------------------------------------------------------------------------- */
        
+
+       uint64_t total_count;
+       uint64_t prev_total_count;
+
        int count, period, scount, tcount;
        bool wait;
        
@@ -106,6 +110,9 @@ private:
 public:
        UPD7801(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
        {
+
+               total_count = prev_total_count = 0;
+
                initialize_output_signals(&outputs_so);
                SI = SCK = false;
                d_debugger = NULL;
index dc3b7c6..bc41382 100644 (file)
@@ -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,19 @@ 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>
+Total CPU Clocks = 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>\nTotal CPU Clocks = %llu (%llu)"),
        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);
+       prev_total_icount = total_icount;
 }
 
 // disassembler
@@ -342,7 +364,7 @@ int UPD7810::debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
 }
 #endif
 
-#define STATE_VERSION  3
+#define STATE_VERSION  4
 
 void UPD7810::save_state(FILEIO* state_fio)
 {
@@ -350,6 +372,9 @@ void UPD7810::save_state(FILEIO* state_fio)
        state_fio->FputInt32(this_device_id);
        
        state_fio->Fwrite(opaque, sizeof(upd7810_state), 1);
+#ifdef USE_DEBUGGER
+       state_fio->FputUint64(total_icount);
+#endif
        state_fio->FputInt32(icount);
        state_fio->FputBool(busreq);
 }
@@ -363,6 +388,9 @@ bool UPD7810::load_state(FILEIO* state_fio)
                return false;
        }
        state_fio->Fread(opaque, sizeof(upd7810_state), 1);
+#ifdef USE_DEBUGGER
+       total_icount = prev_total_icount = state_fio->FgetUint64();
+#endif
        icount = state_fio->FgetInt32();
        busreq = state_fio->FgetBool();
        
index 4cf026f..a399051 100644 (file)
@@ -35,12 +35,21 @@ private:
        outputs_t outputs_to;
        outputs_t outputs_txd;
        void *opaque;
+#ifdef USE_DEBUGGER
+       uint64_t total_icount;
+       uint64_t prev_total_icount;
+#endif
        int icount;
        bool busreq, rxd_status;
        
+       int run_one_opecode();
+       
 public:
        UPD7810(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
        {
+#ifdef USE_DEBUGGER
+               total_icount = prev_total_icount = 0;
+#endif
                initialize_output_signals(&outputs_to);
                initialize_output_signals(&outputs_txd);
                set_device_name(_T("uPD7810/7811 MCU"));
index f7d7546..03ad068 100644 (file)
@@ -389,6 +389,9 @@ void Z80::run_one_opecode()
 
 void Z80::check_interrupt()
 {
+#ifdef USE_DEBUGGER
+       int first_icount = icount;
+#endif
        // check interrupt
        if(intr_req_bit) {
                if(intr_req_bit & NMI_REQ_BIT) {
@@ -477,6 +480,9 @@ void Z80::check_interrupt()
 //#else
                }
        }
+#ifdef USE_DEBUGGER
+       total_icount += first_icount - icount;
+#endif
 }
 
 #ifdef USE_DEBUGGER
index 92b07d5..a07312a 100644 (file)
                                        </FileConfiguration>
                                </File>
                                <File
-                                       RelativePath="..\src\vm\i86.cpp"
+                                       RelativePath="..\src\vm\i286.cpp"
                                        >
                                        <FileConfiguration
                                                Name="Debug|Win32"
                                Filter="h"
                                >
                                <File
+                                       RelativePath="..\src\vm\debugger.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\src\vm\device.h"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\src\vm\i86.h"
+                                       RelativePath="..\src\vm\i286.h"
                                        >
                                </File>
                                <File
index 8234440..ad24cb6 100644 (file)
                                        </FileConfiguration>
                                </File>
                                <File
-                                       RelativePath="..\src\vm\i86.cpp"
+                                       RelativePath="..\src\vm\i286.cpp"
                                        >
                                        <FileConfiguration
                                                Name="Debug|Win32"
                                Filter="h"
                                >
                                <File
+                                       RelativePath="..\src\vm\debugger.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\src\vm\device.h"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\src\vm\i86.h"
+                                       RelativePath="..\src\vm\i286.h"
                                        >
                                </File>
                                <File
index a1b60c5..24bebd3 100644 (file)
                                        </FileConfiguration>
                                </File>
                                <File
-                                       RelativePath="..\src\vm\i86.cpp"
+                                       RelativePath="..\src\vm\jx\i286.cpp"
                                        >
                                        <FileConfiguration
                                                Name="Debug|Win32"
                                        >
                                </File>
                                <File
-                                       RelativePath="..\src\vm\i86.h"
+                                       RelativePath="..\src\vm\jx\i286.h"
                                        >
                                </File>
                                <File
index 8ad04a0..19a6bd2 100644 (file)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\src\vm\debugger.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\src\vm\device.h"
                                        >
                                </File>
index 237d2bf..5ba1375 100644 (file)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\src\vm\debugger.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\src\vm\device.h"
                                        >
                                </File>
index 904a455..edfa29e 100644 (file)
     <ClInclude Include="..\src\vm\datarec.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\src\vm\debugger.h">
+      <Filter>Header Files\VM Common Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="..\src\vm\device.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
index a7297df..8d454a0 100644 (file)
     <ClCompile Include="..\src\vm\i8237.cpp" />
     <ClCompile Include="..\src\vm\i8253.cpp" />
     <ClCompile Include="..\src\vm\i8259.cpp" />
-    <ClCompile Include="..\src\vm\i86.cpp" />
+    <ClCompile Include="..\src\vm\i286.cpp" />
     <ClCompile Include="..\src\vm\io.cpp" />
     <ClCompile Include="..\src\vm\noise.cpp" />
     <ClCompile Include="..\src\vm\pcm1bit.cpp" />
     <ClInclude Include="..\src\fileio.h" />
     <ClInclude Include="..\src\emu.h" />
     <ClInclude Include="..\src\win32\osd.h" />
+    <ClInclude Include="..\src\vm\debugger.h" />
     <ClInclude Include="..\src\vm\device.h" />
     <ClInclude Include="..\src\vm\disk.h" />
     <ClInclude Include="..\src\vm\event.h" />
     <ClInclude Include="..\src\vm\i8237.h" />
     <ClInclude Include="..\src\vm\i8253.h" />
     <ClInclude Include="..\src\vm\i8259.h" />
-    <ClInclude Include="..\src\vm\i86.h" />
+    <ClInclude Include="..\src\vm\i286.h" />
     <ClInclude Include="..\src\vm\io.h" />
     <ClInclude Include="..\src\vm\noise.h" />
     <ClInclude Include="..\src\vm\pcm1bit.h" />
index b08b9e0..44a0abd 100644 (file)
     <ClCompile Include="..\src\vm\i8259.cpp">
       <Filter>Source Files\VM Common Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\src\vm\i86.cpp">
+    <ClCompile Include="..\src\vm\i286.cpp">
       <Filter>Source Files\VM Common Source Files</Filter>
     </ClCompile>
     <ClCompile Include="..\src\vm\io.cpp">
     <ClInclude Include="..\src\win32\osd.h">
       <Filter>Header Files\OSD Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\src\vm\debugger.h">
+      <Filter>Header Files\VM Common Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="..\src\vm\device.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
     <ClInclude Include="..\src\vm\i8259.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="..\src\vm\i86.h">
+    <ClInclude Include="..\src\vm\i286.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
     <ClInclude Include="..\src\vm\io.h">
index 815287c..818a1bb 100644 (file)
     <ClCompile Include="..\src\vm\i8237.cpp" />
     <ClCompile Include="..\src\vm\i8253.cpp" />
     <ClCompile Include="..\src\vm\i8259.cpp" />
-    <ClCompile Include="..\src\vm\i86.cpp" />
+    <ClCompile Include="..\src\vm\i286.cpp" />
     <ClCompile Include="..\src\vm\io.cpp" />
     <ClCompile Include="..\src\vm\noise.cpp" />
     <ClCompile Include="..\src\vm\pcm1bit.cpp" />
     <ClInclude Include="..\src\fileio.h" />
     <ClInclude Include="..\src\emu.h" />
     <ClInclude Include="..\src\win32\osd.h" />
+    <ClInclude Include="..\src\vm\debugger.h" />
     <ClInclude Include="..\src\vm\device.h" />
     <ClInclude Include="..\src\vm\disk.h" />
     <ClInclude Include="..\src\vm\event.h" />
     <ClInclude Include="..\src\vm\i8237.h" />
     <ClInclude Include="..\src\vm\i8253.h" />
     <ClInclude Include="..\src\vm\i8259.h" />
-    <ClInclude Include="..\src\vm\i86.h" />
+    <ClInclude Include="..\src\vm\i286.h" />
     <ClInclude Include="..\src\vm\io.h" />
     <ClInclude Include="..\src\vm\noise.h" />
     <ClInclude Include="..\src\vm\pcm1bit.h" />
index 44a8686..98353d9 100644 (file)
     <ClCompile Include="..\src\vm\i8259.cpp">
       <Filter>Source Files\VM Common Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\src\vm\i86.cpp">
+    <ClCompile Include="..\src\vm\i286.cpp">
       <Filter>Source Files\VM Common Source Files</Filter>
     </ClCompile>
     <ClCompile Include="..\src\vm\io.cpp">
     <ClInclude Include="..\src\win32\osd.h">
       <Filter>Header Files\OSD Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\src\vm\debugger.h">
+      <Filter>Header Files\VM Common Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="..\src\vm\device.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
     <ClInclude Include="..\src\vm\i8259.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="..\src\vm\i86.h">
+    <ClInclude Include="..\src\vm\i286.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
     <ClInclude Include="..\src\vm\io.h">
index 710655a..6f10ac4 100644 (file)
     <ClCompile Include="..\src\vm\i8253.cpp" />
     <ClCompile Include="..\src\vm\i8255.cpp" />
     <ClCompile Include="..\src\vm\i8259.cpp" />
-    <ClCompile Include="..\src\vm\i86.cpp" />
+    <ClCompile Include="..\src\vm\jx\i286.cpp" />
     <ClCompile Include="..\src\vm\io.cpp" />
     <ClCompile Include="..\src\vm\memory.cpp" />
     <ClCompile Include="..\src\vm\noise.cpp" />
     <ClInclude Include="..\src\vm\i8253.h" />
     <ClInclude Include="..\src\vm\i8255.h" />
     <ClInclude Include="..\src\vm\i8259.h" />
-    <ClInclude Include="..\src\vm\i86.h" />
+    <ClInclude Include="..\src\vm\jx\i286.h" />
     <ClInclude Include="..\src\vm\io.h" />
     <ClInclude Include="..\src\vm\memory.h" />
     <ClInclude Include="..\src\vm\noise.h" />
index 7bc0d1c..1b6b5ef 100644 (file)
     <ClCompile Include="..\src\vm\i8259.cpp">
       <Filter>Source Files\VM Common Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\src\vm\i86.cpp">
+    <ClCompile Include="..\src\vm\jx\i286.cpp">
       <Filter>Source Files\VM Common Source Files</Filter>
     </ClCompile>
     <ClCompile Include="..\src\vm\io.cpp">
     <ClInclude Include="..\src\vm\i8259.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="..\src\vm\i86.h">
+    <ClInclude Include="..\src\vm\jx\i286.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
     <ClInclude Include="..\src\vm\io.h">
index cf25c41..fab1d64 100644 (file)
     <ClInclude Include="..\src\emu.h" />
     <ClInclude Include="..\src\win32\osd.h" />
     <ClInclude Include="..\src\vm\beep.h" />
+    <ClInclude Include="..\src\vm\debugger.h" />
     <ClInclude Include="..\src\vm\device.h" />
     <ClInclude Include="..\src\vm\disk.h" />
     <ClInclude Include="..\src\vm\event.h" />
index 872f2c9..1136584 100644 (file)
     <ClInclude Include="..\src\vm\beep.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\src\vm\debugger.h">
+      <Filter>Header Files\VM Common Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="..\src\vm\device.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
index 193ed22..0304f85 100644 (file)
     <ClInclude Include="..\src\emu.h" />
     <ClInclude Include="..\src\win32\osd.h" />
     <ClInclude Include="..\src\vm\datarec.h" />
+    <ClInclude Include="..\src\vm\debugger.h" />
     <ClInclude Include="..\src\vm\device.h" />
     <ClInclude Include="..\src\vm\event.h" />
     <ClInclude Include="..\src\vm\io.h" />
index 866a825..25ada73 100644 (file)
     <ClInclude Include="..\src\vm\datarec.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\src\vm\debugger.h">
+      <Filter>Header Files\VM Common Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="..\src\vm\device.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
index dc19aee..7fa537d 100644 (file)
     <ClInclude Include="..\src\vm\disk.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\src\vm\debugger.h">
+      <Filter>Header Files\VM Common Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="..\src\vm\device.h">
       <Filter>Header Files\VM Common Header Files</Filter>
     </ClInclude>