OSDN Git Service

[VM][STATE] Use namespace {VMNAME} to separate per VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / device.h
index de42c4e..bae0fef 100644 (file)
 #define USE_DEVICE_NAME
 #endif
 
-#if defined(USE_DEVICES_SHARED_LIB)
+#if defined(USE_SHARED_DLL)
 #include "libcpu_newdev/device.h"
+
+#else
 // max devices connected to the output port
 #define MAX_OUTPUT     16
 
@@ -29,7 +31,8 @@
 #define SIG_CPU_FIRQ           102
 #define SIG_CPU_NMI            103
 #define SIG_CPU_BUSREQ         104
-#define SIG_CPU_DEBUG          105
+#define SIG_CPU_HALTREQ                105
+#define SIG_CPU_DEBUG          106
 
 #define SIG_PRINTER_DATA       201
 #define SIG_PRINTER_STROBE     202
 #define SIG_SCSI_ACK           309
 #define SIG_SCSI_RST           310
 
-#else
+#if defined(_USE_QT)
+class CSP_Logger;
+extern CSP_Logger *csp_logger;
+
+#endif
 class DEVICE
 {
 protected:
-       VM* vm;
+       VM_TEMPLATE* vm;
        EMU* emu;
+       OSD* osd;
+#if defined(_USE_QT)
+       CSP_Logger *p_logger;
+#endif
+
 public:
-       DEVICE(VM* parent_vm, EMU* parent_emu) : vm(parent_vm), emu(parent_emu)
+       DEVICE(VM_TEMPLATE* parent_vm, EMU* parent_emu) : vm(parent_vm), emu(parent_emu)
        {
-               strncpy(this_device_name, "Base Device", 128);
+#if defined(_USE_QT)
+               osd = emu->get_osd();
+               p_logger = csp_logger;
+#else
+               osd = NULL;
+#endif
+               memset(this_device_name, 0x00, sizeof(this_device_name));
+               strncpy(this_device_name, "Base Device", 128 - 1);
                prev_device = vm->last_device;
                next_device = NULL;
                if(vm->first_device == NULL) {
@@ -81,8 +100,13 @@ public:
        // destructor might cause undefined behavior [-Wdelete-non-virtual-dtor]".
        ~DEVICE(void) {}
        
-       virtual void initialize() {}
+       virtual void initialize() {     /* osd = emu->get_osd(); */ /* Initializing VM must be after initializing OSD. */ }
+#if defined(_USE_QT)
+       virtual void release() {
+       }
+#else
        virtual void release() {}
+#endif
        
        virtual void update_config() {}
        virtual void save_state(FILEIO* state_fio) {}
@@ -90,13 +114,21 @@ public:
        {
                return true;
        }
-       
        // control
        virtual void reset() {}
        virtual void special_reset()
        {
                reset();
        }
+       virtual bool process_state(FILEIO* state_fio, bool loading)
+       {
+               if(loading) {
+                       return load_state(state_fio);
+               } else {
+                       save_state(state_fio);
+                       return true;
+               }
+       }
        
        // NOTE: the virtual bus interface functions for 16/32bit access invite the cpu is little endian.
        // if the cpu is big endian, you need to implement them in the virtual machine memory/io classes.
@@ -506,7 +538,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;
        }
@@ -607,6 +639,34 @@ public:
                }
                return event_manager->get_passed_usec(prev);
        }
+       virtual uint32_t get_passed_clock_since_vline()
+       {
+               if(event_manager == NULL) {
+                       event_manager = vm->first_device->next_device;
+               }
+               return event_manager->get_passed_clock_since_vline();
+       }
+       virtual double get_passed_usec_since_vline()
+       {
+               if(event_manager == NULL) {
+                       event_manager = vm->first_device->next_device;
+               }
+               return event_manager->get_passed_usec_since_vline();
+       }
+       virtual int get_cur_vline()
+       {
+               if(event_manager == NULL) {
+                       event_manager = vm->first_device->next_device;
+               }
+               return event_manager->get_cur_vline();
+       }
+       virtual int get_cur_vline_clocks()
+       {
+               if(event_manager == NULL) {
+                       event_manager = vm->first_device->next_device;
+               }
+               return event_manager->get_cur_vline_clocks();
+       }
        virtual uint32_t get_cpu_pc(int index)
        {
                if(event_manager == NULL) {
@@ -635,6 +695,13 @@ public:
                }
                event_manager->set_lines_per_frame(lines);
        }
+       virtual int get_lines_per_frame()
+       {
+               if(event_manager == NULL) {
+                       event_manager = vm->first_device->next_device;
+               }
+               return event_manager->get_lines_per_frame();
+       }
        // Force reder sound immediately when device's status has changed.
        // You must call this after you changing registers (or enything).
        // If has problems, try set_realtime_render.
@@ -650,13 +717,17 @@ public:
        // Force render per 1 sample automatically.
        // See pcm1bit.cpp .
        // -- 20161010 K.O
-       virtual void set_realtime_render(DEVICE* device = this, bool flag)
+       virtual void set_realtime_render(DEVICE* device, bool flag = true)
        {
                if(event_manager == NULL) {
                        event_manager = vm->first_device->next_device;
                }
                if(device != event_manager) event_manager->set_realtime_render(device, flag);
        }
+       virtual void set_realtime_render(bool flag)
+       {
+               set_realtime_render(this, flag);
+       }
        virtual void update_timing(int new_clocks, double new_frames_per_sec, int new_lines_per_frame) {}
        
        // event callback
@@ -669,36 +740,43 @@ public:
        // sound
        virtual void mix(int32_t* buffer, int cnt) {}
        virtual void set_volume(int ch, int decibel_l, int decibel_r) {} // +1 equals +0.5dB (same as fmgen)
+       virtual void set_device_name(const _TCHAR *format, ...)
+       {
+               if(format != NULL) {
+                       va_list ap;
+                       _TCHAR buffer[1024];
+                       
+                       va_start(ap, format);
+                       my_vstprintf_s(buffer, 1024, format, ap);
+                       va_end(ap);
+                       
+                       my_tcscpy_s(this_device_name, 128, buffer);
 #ifdef _USE_QT
-       virtual void set_device_name(const _TCHAR *name) {
-               if(name == NULL) return;
-               strncpy(this_device_name, name, 128);
-               emu->get_osd()->set_vm_node(this_device_id, (_TCHAR *)name);
-       }
-       virtual void out_debug_log(const char *fmt, ...) {
+                       emu->get_osd()->set_vm_node(this_device_id, buffer);
+#endif
+               }
+       }
+       virtual void out_debug_log(const char *fmt, ...)
+       {
                char strbuf[4096];
                va_list ap;
 
                va_start(ap, fmt);
                vsnprintf(strbuf, 4095, fmt, ap);
-               csp_logger->debug_log(CSP_LOG_DEBUG, this_device_id + CSP_LOG_TYPE_VM_DEVICE_0, "%s", strbuf);
+               emu->out_debug_log("%s", strbuf);
                va_end(ap);
        }
-#else
-       virtual void set_device_name(const _TCHAR *name) {
-               if(name == NULL) return;
-               strncpy(this_device_name, name, 128);
-       }
-       virtual void out_debug_log(const char *fmt, ...) {
+       virtual void force_out_debug_log(const char *fmt, ...)
+       {
                char strbuf[4096];
                va_list ap;
 
                va_start(ap, fmt);
                vsnprintf(strbuf, 4095, fmt, ap);
-               emu->out_debug_log("%s", strbuf);
+               emu->force_out_debug_log("%s", strbuf);
                va_end(ap);
        }
-#endif
+
 #ifdef USE_DEBUGGER
        // debugger
        virtual void *get_debugger()
@@ -771,6 +849,10 @@ public:
        {
                return false;
        }
+       virtual uint32_t read_debug_reg(const _TCHAR *reg)
+       {
+               return 0;
+       }
        virtual void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len) {}
        virtual int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len)
        {
@@ -783,6 +865,6 @@ public:
        DEVICE* next_device;
        int this_device_id;
 };
-#endif //USE_DEVICES_SHARED_LIB
+#endif // USE_SHARED_DLL
 
 #endif