OSDN Git Service

[VM][OSD][EMU][MOUSE][JOYSTICK] Should LOCK/UNLOCK per referring buffers of joystick...
authorK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 22 Jun 2021 04:10:06 +0000 (13:10 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 22 Jun 2021 04:10:06 +0000 (13:10 +0900)
Note: This is MAJOR API CHANGE around mouse and joystick.
      See DIFFs of this commit.

53 files changed:
source/src/emu.cpp
source/src/emu.h
source/src/emu_template.h
source/src/qt/CMakeLists.txt
source/src/qt/avio/CMakeLists.txt
source/src/qt/emuutils/CMakeLists.txt
source/src/qt/gui/CMakeLists.txt
source/src/qt/gui/joy_thread.cpp
source/src/qt/osd_base.cpp
source/src/qt/osd_base.h
source/src/qt/osd_input.cpp
source/src/vm/bubcom80/keyboard.cpp
source/src/vm/cefucom21/mcu.cpp
source/src/vm/colecovision/keyboard.cpp
source/src/vm/common_vm/CMakeLists.txt
source/src/vm/familybasic/memory.cpp
source/src/vm/fm7/joystick.cpp
source/src/vm/fmtowns/joypad.cpp
source/src/vm/fmtowns/joystick.cpp
source/src/vm/fmtowns/joystick.h
source/src/vm/fmtowns/mouse.cpp
source/src/vm/gamegear/keyboard.cpp
source/src/vm/gamegear/system.cpp
source/src/vm/jr100/memory.cpp
source/src/vm/m5/keyboard.cpp
source/src/vm/msx/joystick.cpp
source/src/vm/mz2500/joystick.cpp
source/src/vm/mz2500/mouse.cpp
source/src/vm/mz2800/joystick.cpp
source/src/vm/mz2800/mouse.cpp
source/src/vm/mz5500/keyboard.cpp
source/src/vm/mz700/joystick.cpp
source/src/vm/pasopia/joypac2.cpp
source/src/vm/pasopia7/joypac2.cpp
source/src/vm/pc100/ioctrl.cpp
source/src/vm/pc6001/joystick.cpp
source/src/vm/pc8801/pc88.cpp
source/src/vm/pc9801/joystick.cpp
source/src/vm/pc9801/mouse.cpp
source/src/vm/pcengine/pce.cpp
source/src/vm/phc25/joystick.cpp
source/src/vm/pv1000/joystick.cpp
source/src/vm/pv2000/keyboard.cpp
source/src/vm/pyuta/memory.cpp
source/src/vm/rx78/keyboard.cpp
source/src/vm/sc3000/keyboard.cpp
source/src/vm/scv/io.cpp
source/src/vm/smc777/memory.cpp
source/src/vm/svi3x8/joystick.cpp
source/src/vm/x1/joystick.cpp
source/src/vm/x1/mouse.cpp
source/src/vm/z80tvgame/joystick.cpp
source/src/win32/osd.h

index f1f2797..385d3ee 100644 (file)
@@ -1495,10 +1495,15 @@ void EMU::update_auto_key()
 #ifdef USE_JOYSTICK
 void EMU::update_joystick()
 {
-       uint32_t *joy_buffer = osd->get_joy_buffer();
        uint8_t *key_buffer = osd->get_key_buffer();
        
+       uint32_t *joyp = osd->get_joy_buffer();
+       uint32_t joy_buffer[4];
        memset(joy_status, 0, sizeof(joy_status));
+       for(int i = 0; i < 4; i++) {
+               joy_buffer[i] = joyp[i];
+       }
+       osd->release_joy_buffer(joyp);
        
        for(int i = 0; i < 4; i++) {
                for(int j = 0; j < 16; j++) {
@@ -1529,8 +1534,14 @@ const uint8_t* EMU::get_key_buffer()
 #ifdef USE_JOYSTICK
 const uint32_t* EMU::get_joy_buffer()
 {
+       // Update joystick data per query joystick buffer.
+       update_joystick();
        return (const uint32_t*)joy_status;
 }
+void EMU::release_joy_buffer(const uint32_t* ptr)
+{
+       // ToDo: Unlock buffer.
+}
 #endif
 
 #ifdef USE_MOUSE
@@ -1538,6 +1549,16 @@ const int32_t* EMU::get_mouse_buffer()
 {
        return (const int32_t*)osd->get_mouse_buffer();
 }
+void EMU::release_mouse_buffer(const int32_t* ptr)
+{
+       // ToDo: Unlock buffer.
+       osd->release_mouse_buffer(ptr);
+}
+const int32_t EMU::get_mouse_button()
+{
+       return (const int32_t)osd->get_mouse_button();
+}
+
 #endif
 
 // ----------------------------------------------------------------------------
index d63ac5e..6ad4d85 100644 (file)
@@ -179,10 +179,15 @@ public:
        
        const uint8_t* get_key_buffer();
 #ifdef USE_JOYSTICK
+       // Joystick buffer should be with locking and sampling.
        const uint32_t* get_joy_buffer();
+       void release_joy_buffer(const uint32_t* ptr);
 #endif 
 #ifdef USE_MOUSE
-       const int* get_mouse_buffer();
+       // Mouse buffer should be with locking and sampling.
+       const int32_t* get_mouse_buffer();
+       const int32_t  get_mouse_button();
+       void release_mouse_buffer(const uint32_t* ptr);
        void enable_mouse();
        void disable_mouse();
        void toggle_mouse();
index 095497a..de159d1 100644 (file)
@@ -212,10 +212,16 @@ public:
        virtual void stop_auto_key() {}
        virtual bool is_auto_key_running() { return false; }
        virtual FIFO* get_auto_key_buffer() { return NULL; }
-       // Mouse
+       // Keyboard
        virtual const uint8_t* get_key_buffer() { return dummy_key_buffer; }
+       // Joystick buffer should be with locking and sampling.
        virtual const uint32_t* get_joy_buffer() { return dummy_joy_buffer; }
-       virtual const int* get_mouse_buffer() { return dummy_mouse_buffer; }
+       virtual void release_joy_buffer(const uint32_t* ptr) { };
+       
+       // Mouse buffer should be with locking and sampling.
+       virtual const int32_t* get_mouse_buffer() { return dummy_mouse_buffer; }
+       virtual const int32_t  get_mouse_button() { return 0; }
+       virtual void release_mouse_buffer(const int* ptr) { };
        virtual void enable_mouse() {}
        virtual void disable_mouse() {}
        virtual void toggle_mouse() {}
index 26d2b82..7078e7b 100644 (file)
@@ -1,5 +1,5 @@
 message("* qt/osd")
-SET(THIS_LIB_VERSION 3.5.0)
+SET(THIS_LIB_VERSION 3.6.0)
 
 set(s_qt_osd_headers
        osd_base.h
index 64c53be..398c67c 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/avio")
 
-SET(THIS_LIB_VERSION 3.2.3)
+SET(THIS_LIB_VERSION 3.3.0)
 set(s_qt_avio_headers
          movie_saver.h
          movie_loader.h
index 2da677b..41ba45a 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/emuutils")
 
-SET(THIS_LIB_VERSION 2.22.5)
+SET(THIS_LIB_VERSION 3.0.0)
 
 set(s_qt_emuutils_headers
        ../gui/csp_logger.h
index 2249025..d19602a 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/gui")
 
-set(THIS_LIB_VERSION 3.5.1)
+set(THIS_LIB_VERSION 3.6.0)
 
 set(s_qt_gui_headers
          qt_dialogs.h
index aac7b12..b6d07af 100644 (file)
@@ -418,6 +418,7 @@ void JoyThreadClass::x_axis_changed(int idx, int type, int value)
                        break;
                }
        }
+       p_osd->release_joy_buffer(joy_status);
        p_osd->unlock_vm();
 }
           
@@ -430,7 +431,6 @@ void JoyThreadClass::y_axis_changed(int idx, int type, int value)
        if((true_index < 0) || (true_index >= 4)) return;
        p_osd->lock_vm();
        uint32_t *joy_status = p_osd->get_joy_buffer();
-   
        //debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_JOYSTICK, "Y AXIS Changed #%d/%d, TYPE=%d VAL=%d", idx, true_index, type, value);
        if(joy_status != NULL) {
                switch(type) {
@@ -451,6 +451,7 @@ void JoyThreadClass::y_axis_changed(int idx, int type, int value)
                        break;
                }
        }
+       p_osd->release_joy_buffer(joy_status);
        p_osd->unlock_vm();
 }
 
@@ -475,6 +476,7 @@ void JoyThreadClass::button_down(int idx, unsigned int button)
                        break;
                }
        }
+       p_osd->release_joy_buffer(joy_status);
        p_osd->unlock_vm();
 }
 
@@ -519,6 +521,7 @@ void JoyThreadClass::controller_button_down(int idx, unsigned int button)
                        break;
                }
        }
+       p_osd->release_joy_buffer(joy_status);
        p_osd->unlock_vm();
 }
 
@@ -541,6 +544,7 @@ void JoyThreadClass::button_up(int idx, unsigned int button)
                        break;
                }
        }
+       p_osd->release_joy_buffer(joy_status);
        p_osd->unlock_vm();
 }
 
@@ -580,6 +584,7 @@ void JoyThreadClass::controller_button_up(int idx, unsigned int button)
                        break;
                }
        }
+       p_osd->release_joy_buffer(joy_status);
        p_osd->unlock_vm();
 }
 
index eed4321..14884c3 100644 (file)
@@ -52,6 +52,7 @@ OSD_BASE::OSD_BASE(USING_FLAGS *p, CSP_Logger *logger) : QObject(0)
        vm_mutex = new QMutex(QMutex::Recursive);
        locked_vm = false;
        screen_mutex = new QMutex(QMutex::Recursive);
+       joystick_mutex = new QMutex(QMutex::Recursive);
        mouse_mutex = new QMutex(QMutex::Recursive);
        log_mutex = new QMutex(QMutex::Recursive);
        
@@ -77,6 +78,7 @@ OSD_BASE::~OSD_BASE()
                QMutexLocker l(log_mutex);
                p_logger->set_osd(NULL);
        }
+       delete joystick_mutex;
        delete mouse_mutex;
        delete vm_mutex;
        delete screen_mutex;
index df340f6..d392cb2 100644 (file)
@@ -368,6 +368,7 @@ public:
        QMutex *screen_mutex;
        QMutex *vm_mutex;
        QMutex *debug_mutex;
+       QMutex *joystick_mutex;
        QMutex *mouse_mutex;
        QMutex *log_mutex;
        
@@ -458,11 +459,13 @@ public:
        //QImage *getPseudoVramClass(void) { return pPseudoVram;}
        void set_mouse_pointer(int x, int y);
        void set_mouse_button(int button);
-       int get_mouse_button();
        void modify_key_buffer(int code, uint8_t val);
        uint8_t* get_key_buffer();
        uint32_t* get_joy_buffer();
+       void release_joy_buffer(uint32_t* ptr);
+       int32_t get_mouse_button();
        int32_t* get_mouse_buffer();
+       void release_mouse_buffer(int32_t* ptr);
        // common printer
        void reset_printer();
        void update_printer();
index 4b8eaf2..3d4bc8e 100644 (file)
@@ -54,10 +54,16 @@ void OSD_BASE::initialize_input()
 {
        // initialize status
        memset(key_status, 0, sizeof(key_status));
-       memset(joy_status, 0, sizeof(joy_status));
-       memset(mouse_status, 0, sizeof(mouse_status));
-       // mouse emulation is disenabled
-       mouse_enabled = false;
+       {
+               QMutexLocker n(joystick_mutex);
+               memset(joy_status, 0, sizeof(joy_status));
+       }
+       {
+               QMutexLocker n(mouse_mutex);
+               memset(mouse_status, 0, sizeof(mouse_status));
+               // mouse emulation is disenabled
+               mouse_enabled = false;
+       }
 
        mouse_ptrx = mouse_oldx = get_screen_width() / 2;
        mouse_ptry = mouse_oldy = get_screen_height() / 2;
@@ -97,9 +103,29 @@ void OSD_BASE::do_assign_js_setting(int jsnum, int axis_idx, int assigned_value)
        if((jsnum < 0) || (jsnum >= 4)) return;
        if((axis_idx < 0) || (axis_idx >= 16)) return;
        if((assigned_value < -256) || (assigned_value >= 0x10000)) return;
+
+       QMutexLocker n(joystick_mutex);
        p_config->joy_buttons[jsnum][axis_idx] = assigned_value;
 }
 
+void OSD_BASE::update_input_mouse()
+{
+       QMutexLocker n(mouse_mutex);
+       memset(mouse_status, 0, sizeof(mouse_status));
+       //bool hid = false;
+       if(mouse_enabled) {
+               int xx = mouse_ptrx;
+               int yy = mouse_ptry;
+               mouse_status[0] = xx - mouse_oldx;
+               mouse_status[1] = yy - mouse_oldy; 
+               mouse_status[2] = mouse_button;
+               //printf("Mouse delta(%d, %d)\n", delta_x, delta_y);
+               mouse_oldx = xx;
+               mouse_oldy = yy;
+       }
+
+}
+
 void OSD_BASE::update_input()
 {
        bool press_flag = false;
@@ -136,6 +162,7 @@ void OSD_BASE::update_input()
        if(p_config->use_joy_to_key) {
                int status[256] = {0};
                if(p_config->joy_to_key_type == 0) { // Cursor
+                       QMutexLocker n(joystick_mutex);
                        static const int vk[] = {VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT};
                        for(int i = 0; i < 4; i++) {
                                if(joy_status[0] & (1 << i)) {
@@ -143,6 +170,7 @@ void OSD_BASE::update_input()
                                }
                        }
                } else if(p_config->joy_to_key_type == 1) { // 2468                     
+                       QMutexLocker n(joystick_mutex);
                        static const int vk[] = {VK_NUMPAD8, VK_NUMPAD2, VK_NUMPAD4, VK_NUMPAD6};
                        for(int i = 0; i < 4; i++) {
                                if(joy_status[0] & (1 << i)) {
@@ -151,6 +179,7 @@ void OSD_BASE::update_input()
                        }
                } else if(p_config->joy_to_key_type == 2) { // 24681379
                        // numpad key (8-directions)
+                       QMutexLocker n(joystick_mutex);
                        switch(joy_status[0] & 0x0f) {
                        case 0x02 + 0x04: status[VK_NUMPAD1] = 1; break; // down-left
                        case 0x02       : status[VK_NUMPAD2] = 1; break; // down
@@ -164,6 +193,7 @@ void OSD_BASE::update_input()
                        }
                } else if(p_config->joy_to_key_type == 3) { // 1235                     
                        static const int vk[] = {VK_NUMPAD5, VK_NUMPAD2, VK_NUMPAD1, VK_NUMPAD3};
+                       QMutexLocker n(joystick_mutex);
                        for(int i = 0; i < 4; i++) {
                                if(joy_status[0] & (1 << i)) {
                                        status[vk[i]] = 1;
@@ -172,6 +202,7 @@ void OSD_BASE::update_input()
                }
                if(p_config->joy_to_key_type == 1 || p_config->joy_to_key_type == 2) {
                        // numpad key
+                       QMutexLocker n(joystick_mutex);
                        if(p_config->joy_to_key_numpad5 && !(joy_status[0] & 0x0f)) {
                                if(!numpad_5_pressed) {
                                        status[VK_NUMPAD5] = 1;
@@ -180,6 +211,7 @@ void OSD_BASE::update_input()
                        }
                } else if(p_config->joy_to_key_type == 3) {
                        // numpad key
+                       QMutexLocker n(joystick_mutex);
                        if(p_config->joy_to_key_numpad5 && !(joy_status[0] & 0x0f)) {
                                if(!numpad_5_pressed) {
                                        status[VK_NUMPAD8] = 1;
@@ -189,6 +221,7 @@ void OSD_BASE::update_input()
                }
 
                for(int i = 0; i < 16; i++) {
+                       QMutexLocker n(joystick_mutex);
                        if(joy_status[0] & (1 << (i + 4))) {
                                if(p_config->joy_to_key_buttons[i] < 0 && -p_config->joy_to_key_buttons[i] < 256) {
                                        status[-p_config->joy_to_key_buttons[i]] = 1;
@@ -251,25 +284,8 @@ void OSD_BASE::update_input()
        }
        lost_focus = false;
 
-
        // update mouse status
-
-       //if(mouse_enabled) {
-       memset(mouse_status, 0, sizeof(mouse_status));
-       //bool hid = false;
-       if(mouse_enabled) {
-               QMutexLocker n(mouse_mutex);
-               int xx = mouse_ptrx;
-               int yy = mouse_ptry;
-               mouse_status[0] = xx - mouse_oldx;
-               mouse_status[1] = yy - mouse_oldy; 
-               mouse_status[2] = mouse_button;
-               //printf("Mouse delta(%d, %d)\n", delta_x, delta_y);
-               mouse_oldx = xx;
-               mouse_oldy = yy;
-       }
-       //}
-       // move mouse cursor to the center of window
+       update_input_mouse();
        
 }
 
@@ -765,14 +781,29 @@ uint8_t* OSD_BASE::get_key_buffer()
 
 uint32_t* OSD_BASE::get_joy_buffer()
 {
+       if(joystick_mutex != NULL) {
+               joystick_mutex->lock();
+       }
        return joy_status;
 }
 
+void OSD_BASE::release_joy_buffer(uint32_t* ptr)
+{
+//     if(ptr != nullptr) {
+               if(joystick_mutex != NULL) {
+                       joystick_mutex->unlock();
+               }
+//     }
+}
+
 int32_t* OSD_BASE::get_mouse_buffer()
 {
-       QMutexLocker n(mouse_mutex);
+       update_input_mouse();
        return mouse_status;
 }
+void OSD_BASE::release_mouse_buffer(int32_t* ptr)
+{
+}
 
 void OSD_BASE::press_button(int num)
 {
@@ -854,7 +885,7 @@ void OSD_BASE::set_mouse_button(int button)
        mouse_button = button;
 }
 
-int OSD_BASE::get_mouse_button() 
+int32_t OSD_BASE::get_mouse_button() 
 {
        QMutexLocker n(mouse_mutex);
        return mouse_button;
index fce463f..6be4afc 100644 (file)
@@ -50,18 +50,24 @@ static const uint32_t joy_bits[5] = {
 void KEYBOARD::initialize()
 {
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
 }
 
 uint32_t KEYBOARD::read_io8(uint32_t addr)
 {
+       joy_stat = emu->get_joy_buffer();
+       uint32_t __joy_stat[2];
+       __joy_stat[0] = joy_stat[0];
+       __joy_stat[1] = joy_stat[1];
+       emu->release_joy_buffer(joy_stat);
+
        switch(addr & 0x7f) {
        case 0x70:
        case 0x71:
        case 0x72:
        case 0x73:
        case 0x74:
-               if(joy_stat[0] & joy_bits[addr - 0x70]) {
+               if(__joy_stat[0] & joy_bits[addr - 0x70]) {
                        return 0xff;
                }
                break;
@@ -70,7 +76,7 @@ uint32_t KEYBOARD::read_io8(uint32_t addr)
        case 0x77:
        case 0x78:
        case 0x79:
-               if(joy_stat[1] & joy_bits[addr - 0x75]) {
+               if(__joy_stat[1] & joy_bits[addr - 0x75]) {
                        return 0xff;
                }
                break;
index 1eb80ca..d7f8302 100644 (file)
@@ -73,8 +73,12 @@ void MCU::event_frame()
                }
                key_status[i] = val;
        }
-       d_psg->write_signal(SIG_AY_3_891X_PORT_A, ~(joy_stat[0] & 0x1f), 0xff);
-       d_psg->write_signal(SIG_AY_3_891X_PORT_B, ~(joy_stat[1] & 0x1f), 0xff);
+       uint32_t _n[2];
+       _n[0] = joy_stat[0];
+       _n[1] = joy_stat[1];
+       emu->release_joy_buffer(joy_stat);
+       d_psg->write_signal(SIG_AY_3_891X_PORT_A, ~(_n[0] & 0x1f), 0xff);
+       d_psg->write_signal(SIG_AY_3_891X_PORT_B, ~(_n[1] & 0x1f), 0xff);
 }
 
 void MCU::write_signal(int id, uint32_t data, uint32_t mask)
index e60841d..3aab73c 100644 (file)
@@ -13,16 +13,22 @@ namespace COLECOVISION {
 void KEYBOARD::initialize()
 {
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        // register event to update the key status
 //     register_frame_event(this); // is this needed?
 }
 
 void KEYBOARD::event_frame()
 {
-       if (joy_stat[0] & 0x04 || joy_stat[0] & 0x08) {
+       joy_stat = emu->get_joy_buffer();
+       uint32_t _n[2];
+       _n[0] = joy_stat[0];
+       _n[1] = joy_stat[1];
+       emu->release_joy_buffer(joy_stat);
+       if (_n[0] & 0x04 || _n[0] & 0x08) {
                d_cpu->write_signal(SIG_CPU_IRQ, 1, 1);
        }
+
 }
 
 void KEYBOARD::write_io8(uint32_t addr, uint32_t data)
@@ -39,18 +45,23 @@ void KEYBOARD::write_io8(uint32_t addr, uint32_t data)
 uint32_t KEYBOARD::read_io8(uint32_t addr)
 {
        // Controller 1
+       joy_stat = emu->get_joy_buffer();
+       uint32_t __joy_stat[2];
+       __joy_stat[0] = joy_stat[0];
+       __joy_stat[1] = joy_stat[1];
+       emu->release_joy_buffer(joy_stat);
        if ((addr & 0x000000ff)==0xfc) {
                uint32_t button=0x70;//0xf0;
                if (!tenkey) {
                        uint32_t joystick=0x7f;//0xff;
-                       if (joy_stat[0] & 0x01) joystick &= 0xfe;       // U
-                       if (joy_stat[0] & 0x02) joystick &= 0xfb;       // D
-                       if (joy_stat[0] & 0x04) joystick &= 0xf7;       // L
-                       if (joy_stat[0] & 0x08) joystick &= 0xfd;       // R
-                       if (joy_stat[0] & 0x20) joystick &= 0xbf;       // F1
+                       if (__joy_stat[0] & 0x01) joystick &= 0xfe;     // U
+                       if (__joy_stat[0] & 0x02) joystick &= 0xfb;     // D
+                       if (__joy_stat[0] & 0x04) joystick &= 0xf7;     // L
+                       if (__joy_stat[0] & 0x08) joystick &= 0xfd;     // R
+                       if (__joy_stat[0] & 0x20) joystick &= 0xbf;     // F1
                        return joystick;
                }
-               if (joy_stat[0] & 0x10)
+               if (__joy_stat[0] & 0x10)
                        button &= 0xbf;         // F2
                if ((key_stat[0x31] & 0x80) || (key_stat[0x61] & 0x80))
                        return (button | 0x0d); // 1
@@ -87,14 +98,14 @@ uint32_t KEYBOARD::read_io8(uint32_t addr)
                uint32_t button=0x70;//0xf0;
                if (!tenkey) {
                        uint32_t joystick=0x7f;//0xff;
-                       if (joy_stat[1] & 0x01) joystick &= 0xfe;       // U
-                       if (joy_stat[1] & 0x02) joystick &= 0xfb;       // D
-                       if (joy_stat[1] & 0x04) joystick &= 0xf7;       // L
-                       if (joy_stat[1] & 0x08) joystick &= 0xfd;       // R
-                       if (joy_stat[1] & 0x20) joystick &= 0xbf;       // F1
+                       if (__joy_stat[1] & 0x01) joystick &= 0xfe;     // U
+                       if (__joy_stat[1] & 0x02) joystick &= 0xfb;     // D
+                       if (__joy_stat[1] & 0x04) joystick &= 0xf7;     // L
+                       if (__joy_stat[1] & 0x08) joystick &= 0xfd;     // R
+                       if (__joy_stat[1] & 0x20) joystick &= 0xbf;     // F1
                        return joystick;
                }
-               if (joy_stat[1] & 0x10)
+               if (__joy_stat[1] & 0x10)
                        button &= 0xbf;         // F2
                if (key_stat[0x51] & 0x80)
                        return (button | 0x0d); // 1 'q'
index 911bbe1..e3559e1 100644 (file)
@@ -1,6 +1,6 @@
 message("* vm/common_vm")
 
-SET(THIS_LIB_VERSION 3.7.0)
+SET(THIS_LIB_VERSION 3.8.0)
 
 #include(cotire)
 set(s_vm_common_vm_srcs
index 1d38d5d..98d4464 100644 (file)
@@ -20,7 +20,7 @@ namespace FAMILYBASIC {
 void MEMORY::initialize()
 {
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        // register event
        register_vline_event(this);
@@ -144,6 +144,7 @@ void MEMORY::write_data8(uint32_t addr, uint32_t data)
                        pad_strobe = false;
                        // joypad #1
                        pad1_bits = 0;
+                       joy_stat = emu->get_joy_buffer();
                        if(joy_stat[0] & 0x10) pad1_bits |= 0x01;       // A
                        if(joy_stat[0] & 0x20) pad1_bits |= 0x02;       // B
                        if(joy_stat[0] & 0x40) pad1_bits |= 0x04;       // SEL
@@ -160,6 +161,7 @@ void MEMORY::write_data8(uint32_t addr, uint32_t data)
                        if(joy_stat[1] & 0x02) pad2_bits |= 0x20;       // DOWN
                        if(joy_stat[1] & 0x04) pad2_bits |= 0x40;       // LEFT
                        if(joy_stat[1] & 0x08) pad2_bits |= 0x80;       // RIGHT
+                       emu->release_joy_buffer(joy_stat);
                }
                // keyboard
                if((data & 0x07) == 0x04) {
index d357c08..dd8fce7 100644 (file)
@@ -33,8 +33,8 @@ JOYSTICK::~JOYSTICK()
 
 void JOYSTICK::initialize()
 {
-       rawdata = emu->get_joy_buffer();
-       mouse_state = emu->get_mouse_buffer();
+//     rawdata = emu->get_joy_buffer();
+//     mouse_state = emu->get_mouse_buffer();
        emulate_mouse[0] = emulate_mouse[1] = false;
        joydata[0] = joydata[1] = 0xff;
        dx = dy = 0;
@@ -72,7 +72,7 @@ void JOYSTICK::reset()
                emulate_mouse[1] = false;
                break;
        }
-       mouse_state = emu->get_mouse_buffer();
+
 #endif 
        if(opn != NULL) {
                opn->write_signal(SIG_YM2203_PORT_A, 0xff, 0xff);
@@ -101,16 +101,9 @@ void JOYSTICK::event_frame()
                        dy = 127;
                }
        }               
-       if(mouse_state != NULL) {
-               stat = mouse_state[2];
-               mouse_button = 0x00;
-               if((stat & 0x01) == 0) mouse_button |= 0x10; // left
-               if((stat & 0x02) == 0) mouse_button |= 0x20; // right
-       }
-#endif 
+       emu->release_mouse_buffer(mouse_state);
+#endif
        rawdata = emu->get_joy_buffer();
-       if(rawdata == NULL) return;
-   
        for(ch = 0; ch < 2; ch++) {
                if(!emulate_mouse[ch]) { // Joystick
                        val = rawdata[ch];
@@ -128,13 +121,19 @@ void JOYSTICK::event_frame()
                } else { // MOUSE
                }
        }
+       emu->release_joy_buffer(rawdata);
 }
 
 
 uint32_t JOYSTICK::update_mouse(uint32_t mask)
 {
 #if !defined(_FM8)
+       int stat = emu->get_mouse_button();
+       mouse_button = 0x00;
+       if((stat & 0x01) == 0) mouse_button |= 0x10; // left
+       if((stat & 0x02) == 0) mouse_button |= 0x20; // right
        uint32_t button = mouse_button;
+       
        switch(mouse_phase) {
                        case 1:
                                mouse_data = lx & 0x0f;
@@ -226,7 +225,9 @@ uint32_t JOYSTICK::read_data8(uint32_t addr)
        case 3: // Get Printer Joystick (CH1)
                int ch = addr - 1;
                if(lpt_type == ch) {
+                       rawdata = emu->get_joy_buffer();
                        uint8_t raw = rawdata[ch - 1];
+                       emu->release_joy_buffer(rawdata);
                        bool f = false;
                        f |= ((raw & 0x08) && !(lpmask & 0x01));        
                        f |= ((raw & 0x04) && !(lpmask & 0x02));        
index 29ee64c..4407b2a 100644 (file)
@@ -43,9 +43,11 @@ void JOYPAD::event_frame(void)
 void JOYPAD::query_joystick(void)
 {
        // enabled
+       bool __sigf = false;
        rawdata = emu->get_joy_buffer();
        uint32_t stat = 0;
        if((rawdata != NULL) && (enabled)) {
+               __sigf = true;
                uint32_t d = rawdata[pad_num];
 //             out_debug_log(_T("DATA: %08X"), d);
                if((type_6buttons) && (sel_line)) { // 6Buttons Multiplied
@@ -75,7 +77,10 @@ void JOYPAD::query_joystick(void)
                // None Connected
                stat = 0x00;
        }
-       write_signals(&line_dat, stat);
+       emu->release_joy_buffer(rawdata);
+       if(__sigf) {
+               write_signals(&line_dat, stat);
+       }
 }
 
 void JOYPAD::write_signal(int id, uint32_t data, uint32_t mask)
index 30278a8..b9d3ff2 100644 (file)
@@ -21,7 +21,6 @@ void JOYSTICK::reset()
 
 void JOYSTICK::initialize()
 {
-       rawdata = emu->get_joy_buffer();
        joydata[0] = joydata[1] = 0x00;
 
        // Force reset pads.
index 611f3ef..749bb14 100644 (file)
@@ -54,8 +54,6 @@ private:
        uint32_t joydata[2];
        bool stat_com[2];
        
-       const uint32_t *rawdata;
-
        uint8_t mouse_mask;
        uint32_t connected_type[2];
        
index 5f89ff6..0a096ee 100644 (file)
@@ -39,7 +39,7 @@ void MOUSE::release()
 
 void MOUSE::event_pre_frame()
 {
-       event_callback(EVENT_MOUSE_SAMPLING, 0);
+//     event_callback(EVENT_MOUSE_SAMPLING, 0);
 }
        
 void MOUSE::reset()
@@ -79,6 +79,7 @@ void MOUSE::update_strobe()
                if(phase == 0) {
                        if(strobe) {
                                // Sample data from MOUSE to registers.
+                               sample_mouse_xy(); // Sample next value.
                                lx = -dx;
                                ly = -dy;
                                dx = 0;
@@ -139,7 +140,6 @@ uint32_t MOUSE::read_signal(int ch)
                        uint8_t rval = 0xf0;
                        
                        rval |= (update_mouse() & 0x0f);
-                       mouse_state = emu->get_mouse_buffer();
                        if((trig & 0x01) == 0) {
                                rval &= ~0x10; // Button LEFT
                        }
@@ -147,7 +147,7 @@ uint32_t MOUSE::read_signal(int ch)
                                rval &= ~0x20; // Button RIGHT
                        }
                        if(mouse_state != NULL) {
-                               uint32_t stat = mouse_state[2];
+                               int32_t stat = emu->get_mouse_button();
                                if((stat & 0x01) == 0) {
                                        rval &= ~0x10; // Button LEFT
                                }
@@ -184,6 +184,7 @@ void MOUSE::write_signal(int id, uint32_t data, uint32_t mask)
                                        phase = 0;
                                        dx = dy = 0;
                                        lx = ly = 0;
+                                       sample_mouse_xy();
                                        strobe = false;
                                        clear_event(this, event_timeout);
 //                                     force_register_event(this, EVENT_MOUSE_SAMPLING,
@@ -204,6 +205,25 @@ void MOUSE::write_signal(int id, uint32_t data, uint32_t mask)
        }
 }
 
+void MOUSE::sample_mouse_xy()
+{
+       mouse_state = emu->get_mouse_buffer();
+       if(mouse_state != NULL) {
+               dx += mouse_state[0];
+               dy += mouse_state[1];
+               if(dx < -127) {
+                       dx += 128;
+               } else if(dx > 127) {
+                       dx -= 128;
+               }
+               if(dy < -127) {
+                       dy += 128;
+               } else if(dy > 127) {
+                       dy -= 128;
+               }
+       }
+       emu->release_mouse_buffer(mouse_state);
+}
 void MOUSE::event_callback(int event_id, int err)
 {
        switch(event_id) {
@@ -218,21 +238,7 @@ void MOUSE::event_callback(int event_id, int err)
                lx = ly = 0;
                break;
        case EVENT_MOUSE_SAMPLING:
-               mouse_state = emu->get_mouse_buffer();
-               if(mouse_state != NULL) {
-                       dx += mouse_state[0];
-                       dy += mouse_state[1];
-                       if(dx < -127) {
-                               dx += 128;
-                       } else if(dx > 127) {
-                               dx -= 128;
-                       }
-                       if(dy < -127) {
-                               dy += 128;
-                       } else if(dy > 127) {
-                               dy -= 128;
-                       }
-               }
+               sample_mouse_xy();
                break;
        }
 }
index bb9dcf0..af70999 100644 (file)
@@ -28,7 +28,7 @@ static const uint8_t key_map[8][12] = {
 void KEYBOARD::initialize()
 {
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        column = 0;
        break_pressed = false;
@@ -80,6 +80,7 @@ void KEYBOARD::update_keyboard()
                }
        } else {
                // joystick
+               joy_stat = emu->get_joy_buffer();
                for(int i = 0; i < 12; i++) {
                        uint8_t map = key_map[7][i];
                        uint8_t stat = (map & 0x80) ? joy_stat[1] : joy_stat[0];
@@ -93,6 +94,7 @@ void KEYBOARD::update_keyboard()
                } else {
                        start_pressed=false;
                }
+               emu->release_joy_buffer(joy_stat);
        }
        d_pio->write_signal(SIG_I8255_PORT_A, ~data, 0xff);
        data >>= 8;
index 8da12a0..b1a1c6d 100644 (file)
@@ -30,8 +30,13 @@ uint32_t SYSTEM::read_io8(uint32_t addr)
        if ((addr & 0x000000ff)==0xfc) {
                const uint8_t *ten=emu->get_key_buffer();
                const uint32_t *joy=emu->get_joy_buffer();
+               uint32_t __joy[2];
+               __joy[0] = joy[0];
+               __joy[1] = joy[1];
+               emu->release_joy_buffer(joy);
+
                uint8_t button=0xf0;
-               if (joy[0] & 0x10) button=0xb0;                         // B2
+               if (__joy[0] & 0x10) button=0xb0;                               // B2
        //      Bit 7:  0\81i\8ag\92£\92[\8eq\82P\82O\83s\83\93\82ÃŒ\93à\97e\81j
        //      Bit 6:  1=Off/0=On      \83g\83\8a\83K\81[\82P\81i\8d¶\81j
        //      Bit 5:  1\81i\82i\82n\82x\92[\8eq\82V\83s\83\93\81@\96¢\8eg\97p\81j
@@ -42,13 +47,14 @@ uint32_t SYSTEM::read_io8(uint32_t addr)
        //      Bit 0:  1=Off/0=On      UP
                if (!tenkey) {
                        uint32_t joystick=0xff;
-                       if (joy[0] & 0x01) joystick &= 0xfe;    // U
-                       if (joy[0] & 0x02) joystick &= 0xfb;    // D
-                       if (joy[0] & 0x04) joystick &= 0xf7;    // L
-                       if (joy[0] & 0x08) joystick &= 0xfd;    // R
-                       if (joy[0] & 0x20) joystick &= 0xbf;    // B1
+                       if (__joy[0] & 0x01) joystick &= 0xfe;  // U
+                       if (__joy[0] & 0x02) joystick &= 0xfb;  // D
+                       if (__joy[0] & 0x04) joystick &= 0xf7;  // L
+                       if (__joy[0] & 0x08) joystick &= 0xfd;  // R
+                       if (__joy[0] & 0x20) joystick &= 0xbf;  // B1
                        return joystick;
                }
+               
        //      \83L\81[\83p\83b\83h\83}\83g\83\8a\83b\83N\83X\81i\82j\82l\82R\81|\82O\82ÃŒ\82S\82a\82\89\82\94\82È\82ÃŒ\82Ã…\82O\81|\82e\81j
        // 0=\96¢\8eg\97p     1='8'   2='4'   3='5'
        // 4=\96¢\8eg\97p     5='7'   6='#'   7='2'
@@ -76,6 +82,7 @@ uint32_t SYSTEM::read_io8(uint32_t addr)
                        return (button | 0x06); // #
                if (ten[0xde] & 0x80)
                        return (button | 0x08); // *
+
                return (button | 0x0f);
        }
        if (((KEYBOARD *)d_key)->is_start()) {
index 185dac1..7d5b61a 100644 (file)
@@ -53,7 +53,7 @@ void MEMORY::initialize()
        
        // initialize inputs
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        // initialize display
        palette_pc[0] = RGB_COLOR(0, 0, 0);
@@ -92,12 +92,16 @@ uint32_t MEMORY::read_data8(uint32_t addr)
                        return d_via->read_io8(addr);
                case 0xcc00:
                        if((addr & 0xffff) == 0xcc02) {
-                               return ((joy_stat[0] & 0x08) >> 3) |    // bit0: right
+                               joy_stat = emu->get_joy_buffer();
+                               uint8_t _ret;
+                               _ret = ((joy_stat[0] & 0x08) >> 3) |    // bit0: right
                                       ((joy_stat[0] & 0x04) >> 1) |    // bit1: left
                                       ((joy_stat[0] & 0x01) << 2) |    // bit2: up
                                       ((joy_stat[0] & 0x02) << 2) |    // bit3: down
                                       ((joy_stat[0] & 0x10)     ) |    // bit4: switch
                                       ((joy_stat[0] & 0x20) >> 1);
+                               emu->release_joy_buffer(joy_stat);
+                               return _ret;
                        }
                        break;
                }
index dbf65f4..53ede1f 100644 (file)
@@ -27,7 +27,7 @@ static const int key_map[7][8] = {
 void KEYBOARD::initialize()
 {
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
 }
 
 uint32_t KEYBOARD::read_io8(uint32_t addr)
@@ -56,13 +56,16 @@ uint32_t KEYBOARD::read_io8(uint32_t addr)
                for(int i = 0; i < 8; i++) {
                        val |= key_stat[key_map[1][i]] ? (1 << i) : 0;
                }
+               joy_stat = emu->get_joy_buffer();
                val |= (joy_stat[0] & 0x10) ? 0x01 : 0;
                val |= (joy_stat[0] & 0x20) ? 0x02 : 0;
                val |= (joy_stat[1] & 0x10) ? 0x10 : 0;
                val |= (joy_stat[1] & 0x20) ? 0x20 : 0;
+               emu->release_joy_buffer(joy_stat);
                return val;
        case 0x37:
 //     case 0x3f:
+               joy_stat = emu->get_joy_buffer();
                val |= (joy_stat[0] & 0x08) ? 0x01 : 0;
                val |= (joy_stat[0] & 0x01) ? 0x02 : 0;
                val |= (joy_stat[0] & 0x04) ? 0x04 : 0;
@@ -71,6 +74,7 @@ uint32_t KEYBOARD::read_io8(uint32_t addr)
                val |= (joy_stat[1] & 0x01) ? 0x20 : 0;
                val |= (joy_stat[1] & 0x04) ? 0x40 : 0;
                val |= (joy_stat[1] & 0x02) ? 0x80 : 0;
+               emu->release_joy_buffer(joy_stat);
                return val;
        }
        return 0xff;
index c34c2de..a52d113 100644 (file)
@@ -25,7 +25,7 @@ namespace MSX {
 
 void JOYSTICK::initialize()
 {
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        select = 0;
        
        // register event to update the key status
@@ -34,7 +34,10 @@ void JOYSTICK::initialize()
 
 void JOYSTICK::event_frame()
 {
-       d_psg->write_signal(SIG_AY_3_891X_PORT_A, PSG14_MASK & ~(joy_stat[select] & 0x3f), 0x7f);
+       joy_stat = emu->get_joy_buffer();
+       uint8_t n = joy_stat[select];
+       emu->release_joy_buffer(joy_stat);
+       d_psg->write_signal(SIG_AY_3_891X_PORT_A, PSG14_MASK & ~(n & 0x3f), 0x7f);
 }
 
 void JOYSTICK::write_signal(int id, uint32_t data, uint32_t mask)
@@ -42,7 +45,10 @@ void JOYSTICK::write_signal(int id, uint32_t data, uint32_t mask)
        if(id == SIG_JOYSTICK_SEL) {
                if(select != ((data & mask) != 0)) {
                        select = ((data & mask) != 0);
-                       d_psg->write_signal(SIG_AY_3_891X_PORT_A, PSG14_MASK & ~(joy_stat[select] & 0x3f), 0x7f);
+                       joy_stat = emu->get_joy_buffer();
+                       uint8_t n = joy_stat[select];
+                       emu->release_joy_buffer(joy_stat);
+                       d_psg->write_signal(SIG_AY_3_891X_PORT_A, PSG14_MASK & ~(n & 0x3f), 0x7f);
                }
        }
 }
index 162bc13..8d51ded 100644 (file)
@@ -14,7 +14,7 @@ namespace MZ2500 {
 void JOYSTICK::initialize()
 {
        mode = 0xf;
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
 }
 
 void JOYSTICK::write_io8(uint32_t addr, uint32_t data)
@@ -40,6 +40,7 @@ uint32_t JOYSTICK::read_io8(uint32_t addr)
        }
        
        // direction
+       joy_stat = emu->get_joy_buffer();
        if(dir) {
                if(joy_stat[num] & 0x08) val &= ~0x08;
                if(joy_stat[num] & 0x04) val &= ~0x04;
@@ -50,6 +51,7 @@ uint32_t JOYSTICK::read_io8(uint32_t addr)
        // trigger
        if(joy_stat[num] & 0x10) val &= ~0x20;
        if(joy_stat[num] & 0x20) val &= ~0x10;
+       emu->release_joy_buffer(joy_stat);
        return val;
 }
 
index 0f728fb..60214e4 100644 (file)
@@ -14,7 +14,7 @@ namespace MZ2500 {
 
 void MOUSE::initialize()
 {
-       stat = emu->get_mouse_buffer();
+//     stat = emu->get_mouse_buffer();
        select = false;
 }
 
@@ -27,11 +27,13 @@ void MOUSE::write_signal(int id, uint32_t data, uint32_t mask)
                        return;
                }
                // Z80SIO Ch.B DTR H->L
+               stat = emu->get_mouse_buffer();
                uint32_t d0 = (stat[0] >= 128 ? 0x10 : stat[0] < -128 ? 0x20 : 0) |
                            (stat[1] >= 128 ? 0x40 : stat[1] < -128 ? 0x80 : 0) |
                            ((stat[2] & 1) ? 1 : 0) | ((stat[2] & 2) ? 2 : 0);
                uint32_t d1 = (uint8_t)stat[0];
                uint32_t d2 = (uint8_t)stat[1];
+               emu->release_mouse_buffer(stat);
                
                d_sio->write_signal(SIG_Z80SIO_CLEAR_CH1, 1, 1);
                d_sio->write_signal(SIG_Z80SIO_RECV_CH1, d0, 0xff);
index 8de2ed7..3561044 100644 (file)
@@ -14,7 +14,7 @@ namespace MZ2800 {
 void JOYSTICK::initialize()
 {
        mode = 0xf;
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
 }
 
 void JOYSTICK::write_io8(uint32_t addr, uint32_t data)
@@ -40,6 +40,7 @@ uint32_t JOYSTICK::read_io8(uint32_t addr)
        }
        
        // direction
+       joy_stat = emu->get_joy_buffer();
        if(dir) {
                if(joy_stat[num] & 0x08) val &= ~0x08;
                if(joy_stat[num] & 0x04) val &= ~0x04;
@@ -50,6 +51,7 @@ uint32_t JOYSTICK::read_io8(uint32_t addr)
        // trigger
        if(joy_stat[num] & 0x10) val &= ~0x20;
        if(joy_stat[num] & 0x20) val &= ~0x10;
+       emu->release_joy_buffer(joy_stat);
        return val;
 }
 
index f382690..49ff4b3 100644 (file)
@@ -14,7 +14,7 @@ namespace MZ2800 {
 
 void MOUSE::initialize()
 {
-       stat = emu->get_mouse_buffer();
+//     stat = emu->get_mouse_buffer();
        select = false;
 }
 
@@ -27,11 +27,13 @@ void MOUSE::write_signal(int id, uint32_t data, uint32_t mask)
                        return;
                }
                // Z80SIO Ch.B DTR H->L
+               stat = emu->get_mouse_buffer();
                uint32_t d0 = (stat[0] >= 128 ? 0x10 : stat[0] < -128 ? 0x20 : 0) |
                            (stat[1] >= 128 ? 0x40 : stat[1] < -128 ? 0x80 : 0) |
                            ((stat[2] & 1) ? 1 : 0) | ((stat[2] & 2) ? 2 : 0);
                uint32_t d1 = (uint8_t)stat[0];
                uint32_t d2 = (uint8_t)stat[1];
+               emu->release_mouse_buffer(stat);
                
 //             d_sio->write_signal(SIG_Z80SIO_CLEAR_CH1, 1, 1);
                d_sio->write_signal(SIG_Z80SIO_RECV_CH1, d0, 0xff);
index 7c50c25..af256a6 100644 (file)
@@ -188,7 +188,7 @@ static const int key_table_graph_shift[256] = {
 void KEYBOARD::initialize()
 {
        key_stat = emu->get_key_buffer();
-       mouse_stat = emu->get_mouse_buffer();
+//     mouse_stat = emu->get_mouse_buffer();
        key_buf = new FIFO(64);
        rsp_buf = new FIFO(16);
        caps = kana = graph = false;
@@ -447,9 +447,11 @@ void KEYBOARD::process(int cmd)
        switch(cmd) {
        case 1:
                // mouse ???
+               mouse_stat = emu->get_mouse_buffer();
                mx = mouse_stat[0]; mx = (mx > 126) ? 126 : (mx < -128) ? -128 : mx;
                my = mouse_stat[1]; my = (my > 126) ? 126 : (my < -128) ? -128 : my;
                mb = mouse_stat[2];
+               emu->release_mouse_buffer(mouse_stat);
 //             rsp_buf->clear();
                rsp_buf->write(0x140 | (mx & 0x3f));
                rsp_buf->write(0x140 | (my & 0x3f));
index 22fdc35..9f9dfe3 100644 (file)
@@ -15,7 +15,7 @@ namespace MZ700 {
 void JOYSTICK::initialize()
 {
        val_1x03 = 0x7e;
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
 
        // register event
        register_vline_event(this);
@@ -41,7 +41,9 @@ uint32_t JOYSTICK::read_AM7J(int jnum)
        bool y0, y1;
 
        clk = get_current_clock() & 0x007f;
+       joy_stat = emu->get_joy_buffer();
        js = joy_stat[jnum];
+       emu->release_joy_buffer(joy_stat);
        y0 = y1 = false;
 
        switch (js & 0xc0) {
@@ -106,12 +108,14 @@ uint32_t JOYSTICK::read_io8(uint32_t addr)
                        break;
 
                case DEVICE_JOYSTICK_JOY700:            // TSUKUMO JOY-700
+                       joy_stat = emu->get_joy_buffer();
                        if(joy_stat[0] & 0x01) val &= ~0x10;  // up    : JB2
                        if(joy_stat[0] & 0x02) val &= ~0x08;  // down  : JB1
                        if(joy_stat[0] & 0x04) val &= ~0x02;  // left  : JA1
                        if(joy_stat[0] & 0x08) val &= ~0x04;  // right : JA2
                        if(joy_stat[0] & 0x10) val &= ~0x1e;  // trigger A : ALL
                        if(joy_stat[0] & 0x20) val &= ~0x1e;  // trigger B : ALL
+                       emu->release_joy_buffer(joy_stat);
                        break;
 
                case DEVICE_JOYSTICK_AM7J:              // AM7J ATARI Joystick adaptor
@@ -144,17 +148,21 @@ void JOYSTICK::event_vline(int v, int clock)
                if (v == 0) {
                        // trigger
                        val_1x03 = 0x7e;
+                       joy_stat = emu->get_joy_buffer();
                        if(joy_stat[0] & 0x10) val_1x03 &= ~0x02;
                        if(joy_stat[0] & 0x20) val_1x03 &= ~0x04;
                        if(joy_stat[1] & 0x10) val_1x03 &= ~0x08;
                        if(joy_stat[1] & 0x20) val_1x03 &= ~0x10;
+                       emu->release_joy_buffer(joy_stat);
                } else if (v == 200) {
                        // stick (PWM)
                        val_1x03 &= ~(0x06 | 0x18);
+                       joy_stat = emu->get_joy_buffer();
                        register_event_by_clock(this, EVENT_1X03_X1, pulse_width_1x03(joy_stat[0], 0x04, 0x08), false, NULL);
                        register_event_by_clock(this, EVENT_1X03_Y1, pulse_width_1x03(joy_stat[0], 0x01, 0x02), false, NULL);
                        register_event_by_clock(this, EVENT_1X03_X2, pulse_width_1x03(joy_stat[1], 0x04, 0x08), false, NULL);
                        register_event_by_clock(this, EVENT_1X03_Y2, pulse_width_1x03(joy_stat[1], 0x01, 0x02), false, NULL);
+                       emu->release_joy_buffer(joy_stat);
                }
        }
 }
index f530969..0b10691 100644 (file)
@@ -14,7 +14,7 @@ namespace PASOPIA {
 
 void JOYPAC2::initialize(int id)
 {
-       joy = emu->get_joy_buffer();
+//     joy = emu->get_joy_buffer();
 }
 
 void JOYPAC2::write_io8(uint32_t addr, uint32_t data)
@@ -28,20 +28,24 @@ uint32_t JOYPAC2::read_io8(uint32_t addr)
        
        switch(addr & 0xff) {
        case 0x19:
+               joy = emu->get_joy_buffer();
                if(joy[1] & 0x01) val &= ~0x01;
                if(joy[1] & 0x02) val &= ~0x02;
                if(joy[1] & 0x04) val &= ~0x04;
                if(joy[1] & 0x08) val &= ~0x08;
                if(joy[1] & 0x10) val &= ~0x10;
                if(joy[1] & 0x20) val &= ~0x20;
+               emu->release_joy_buffer(joy);
                return val;
        case 0x1a:
+               joy = emu->get_joy_buffer();
                if(joy[0] & 0x01) val &= ~0x01;
                if(joy[0] & 0x02) val &= ~0x02;
                if(joy[0] & 0x04) val &= ~0x04;
                if(joy[0] & 0x08) val &= ~0x08;
                if(joy[0] & 0x10) val &= ~0x10;
                if(joy[0] & 0x20) val &= ~0x20;
+               emu->release_joy_buffer(joy);
                return val;
        }
        return 0xff;
index db21b2b..586c291 100644 (file)
@@ -14,7 +14,7 @@ namespace PASOPIA7 {
 
 void JOYPAC2::initialize(int id)
 {
-       joy = emu->get_joy_buffer();
+//     joy = emu->get_joy_buffer();
 }
 
 void JOYPAC2::write_io8(uint32_t addr, uint32_t data)
@@ -28,20 +28,24 @@ uint32_t JOYPAC2::read_io8(uint32_t addr)
        
        switch(addr & 0xff) {
        case 0x19:
+               joy = emu->get_joy_buffer();
                if(joy[1] & 0x01) val &= ~0x01;
                if(joy[1] & 0x02) val &= ~0x02;
                if(joy[1] & 0x04) val &= ~0x04;
                if(joy[1] & 0x08) val &= ~0x08;
                if(joy[1] & 0x10) val &= ~0x10;
                if(joy[1] & 0x20) val &= ~0x20;
+               emu->release_joy_buffer(joy);
                return val;
        case 0x1a:
+               joy = emu->get_joy_buffer();
                if(joy[0] & 0x01) val &= ~0x01;
                if(joy[0] & 0x02) val &= ~0x02;
                if(joy[0] & 0x04) val &= ~0x04;
                if(joy[0] & 0x08) val &= ~0x08;
                if(joy[0] & 0x10) val &= ~0x10;
                if(joy[0] & 0x20) val &= ~0x20;
+               emu->release_joy_buffer(joy);
                return val;
        }
        return 0xff;
index 55839a5..8fc3e79 100644 (file)
@@ -45,7 +45,7 @@ void IOCTRL::initialize()
 {
        // init keyboard
        key_stat = emu->get_key_buffer();
-       mouse_stat = emu->get_mouse_buffer();
+//     mouse_stat = emu->get_mouse_buffer();
        key_buf = new FIFO(64);
        caps = kana = false;
        
@@ -147,6 +147,7 @@ void IOCTRL::event_callback(int event_id, int err)
                // mouse
                if(key_buf->empty()) {
                        uint8_t val = 0;
+                       mouse_stat = emu->get_mouse_buffer();
                        if(!(mouse_stat[2] & 1)) val |= 1;
                        if(!(mouse_stat[2] & 2)) val |= 2;
                        if(caps) val |= 0x10;
@@ -164,6 +165,7 @@ void IOCTRL::event_callback(int event_id, int err)
                                update_key();
                                key_prev = val;
                        }
+                       emu->release_mouse_buffer(mouse_stat);
                }
        } else if(event_id == EVENT_10HZ) {
                if(ts == 3) {
index a8a7622..a1fa9a2 100644 (file)
@@ -22,21 +22,27 @@ namespace PC6001 {
 
 void JOYSTICK::initialize()
 {
-       joy_stat = emu->get_joy_buffer();
-       
+//     joy_stat = emu->get_joy_buffer();
        // register event to update the key status
        register_frame_event(this);
 }
 
 void JOYSTICK::event_frame()
 {
+       joy_stat = emu->get_joy_buffer();
+       uint32_t __joy_stat[2];
+       __joy_stat[0] = joy_stat[0];
+       __joy_stat[1] = joy_stat[1];
+       emu->release_joy_buffer(joy_stat);
+       
 #if defined(_PC6001MK2SR) || defined(_PC6601SR)
-       d_psg->write_signal(SIG_YM2203_PORT_A, ~(joy_stat[0] & 0x3f), 0xff);
-       d_psg->write_signal(SIG_YM2203_PORT_B, ~(joy_stat[1] & 0x1f), 0xff);
+       d_psg->write_signal(SIG_YM2203_PORT_A, ~(__joy_stat[0] & 0x3f), 0xff);
+       d_psg->write_signal(SIG_YM2203_PORT_B, ~(__joy_stat[1] & 0x1f), 0xff);
 #else
-       d_psg->write_signal(SIG_AY_3_891X_PORT_A, ~(joy_stat[0] & 0x3f), 0xff);
-       d_psg->write_signal(SIG_AY_3_891X_PORT_B, ~(joy_stat[1] & 0x1f), 0xff);
+       d_psg->write_signal(SIG_AY_3_891X_PORT_A, ~(__joy_stat[0] & 0x3f), 0xff);
+       d_psg->write_signal(SIG_AY_3_891X_PORT_B, ~(__joy_stat[1] & 0x1f), 0xff);
 #endif
+
 }
 
 }
index b32a299..04128c2 100644 (file)
@@ -528,8 +528,8 @@ void PC88::initialize()
 #endif
        
 #ifdef SUPPORT_PC88_JOYSTICK
-       joystick_status = emu->get_joy_buffer();
-       mouse_status = emu->get_mouse_buffer();
+//     joystick_status = emu->get_joy_buffer();
+//     mouse_status = emu->get_mouse_buffer();
        mouse_strobe_clock_lim = (int)((cpu_clock_low ? 720 : 1440) * 1.25);
 #endif
        
@@ -1652,7 +1652,10 @@ uint32_t PC88::read_io8_debug(uint32_t addr)
                        if(Port44_OPNCH == 14) {
 #ifdef SUPPORT_PC88_JOYSTICK
                                if(config.joystick_type == DEVICE_JOYSTICK) {
-                                       return (~(joystick_status[0] >> 0) & 0x0f) | 0xf0;
+                                       joystick_status = emu->get_joy_buffer();
+                                       uint8_t _n = (~(joystick_status[0] >> 0) & 0x0f) | 0xf0;
+                                       emu->release_joy_buffer(joystick_status);
+                                       return _n;
                                } else if(config.joystick_type == DEVICE_MOUSE) {
                                        switch(mouse_phase) {
                                        case 0:
@@ -1671,9 +1674,13 @@ uint32_t PC88::read_io8_debug(uint32_t addr)
                        } else if(Port44_OPNCH == 15) {
 #ifdef SUPPORT_PC88_JOYSTICK
                                if(config.joystick_type == DEVICE_JOYSTICK) {
-                                       return (~(joystick_status[0] >> 4) & 0x03) | 0xfc;
+                                       joystick_status = emu->get_joy_buffer();
+                                       uint8_t _n = (~(joystick_status[0] >> 4) & 0x03) | 0xfc;
+                                       emu->release_joy_buffer(joystick_status);
+                                       return _n;
                                } else if(config.joystick_type == DEVICE_MOUSE) {
-                                       return (~mouse_status[2] & 0x03) | 0xfc;
+                                       int _m = emu->get_mouse_button();
+                                       return (~_m & 0x03) | 0xfc;
                                }
 #endif
                                return 0xff;
@@ -1818,7 +1825,10 @@ uint32_t PC88::read_io8_debug(uint32_t addr)
                        if(PortA8_OPNCH == 14) {
 #ifdef SUPPORT_PC88_JOYSTICK
                                if(config.joystick_type == DEVICE_JOYSTICK) {
-                                       return (~(joystick_status[0] >> 0) & 0x0f) | 0xf0;
+                                       joystick_status = emu->get_joy_buffer();
+                                       uint8_t _n =  (~(joystick_status[0] >> 0) & 0x0f) | 0xf0;
+                                       emu->release_joy_buffer(joystick_status);
+                                       return _n;
                                } else if(config.joystick_type == DEVICE_MOUSE) {
                                        switch(mouse_phase) {
                                        case 0:
@@ -1837,9 +1847,13 @@ uint32_t PC88::read_io8_debug(uint32_t addr)
                        } else if(PortA8_OPNCH == 15) {
 #ifdef SUPPORT_PC88_JOYSTICK
                                if(config.joystick_type == DEVICE_JOYSTICK) {
-                                       return (~(joystick_status[0] >> 4) & 0x03) | 0xfc;
+                                       joystick_status = emu->get_joy_buffer();
+                                       uint8_t _n = (~(joystick_status[0] >> 4) & 0x03) | 0xfc;
+                                       emu->release_joy_buffer(joystick_status);
+                                       return _n;
                                } else if(config.joystick_type == DEVICE_MOUSE) {
-                                       return (~mouse_status[2] & 0x03) | 0xfc;
+                                       int _m = emu->get_mouse_button();
+                                       return (~_m & 0x03) | 0xfc;
                                }
 #endif
                                return 0xff;
@@ -2439,8 +2453,10 @@ void PC88::event_frame()
        crtc.update_blink();
        
 #ifdef SUPPORT_PC88_JOYSTICK
+       mouse_status = emu->get_mouse_buffer();
        mouse_dx += mouse_status[0];
        mouse_dy += mouse_status[1];
+       emu->release_mouse_buffer(mouse_status);
 #endif
 }
 
index e50400b..e13a7cf 100644 (file)
@@ -24,7 +24,7 @@ namespace PC9801 {
 
 void JOYSTICK::initialize()
 {
-       joy_status = emu->get_joy_buffer();
+//     joy_status = emu->get_joy_buffer();
        select = 0xff;
        
        register_frame_event(this);
@@ -39,7 +39,10 @@ void JOYSTICK::write_signal(int id, uint32_t data, uint32_t mask)
 void JOYSTICK::event_frame()
 {
        if(select & 0x80) {
-               d_opn->write_signal(SIG_YM2203_PORT_A, ~joy_status[(select & 0x40) >> 6], 0x3f);
+               joy_status = emu->get_joy_buffer();
+               uint8_t _n = joy_status[(select & 0x40) >> 6];
+               emu->release_joy_buffer(joy_status);
+               d_opn->write_signal(SIG_YM2203_PORT_A, ~_n, 0x3f);
        }
 }
 
index 59dfe3e..39b1536 100644 (file)
@@ -29,7 +29,7 @@ static const int freq_table[4] = {120, 60, 30, 15};
 
 void MOUSE::initialize()
 {
-       status = emu->get_mouse_buffer();
+//     status = emu->get_mouse_buffer();
        
        ctrlreg = 0xff;
        freq = cur_freq = 0;
@@ -90,6 +90,7 @@ void MOUSE::event_callback(int event_id, int err)
 
 void MOUSE::event_frame()
 {
+       status = emu->get_mouse_buffer();
        dx += status[0];
        if(dx > 64) {
                dx = 64;
@@ -102,6 +103,7 @@ void MOUSE::event_frame()
        } else if(dy < -64) {
                dy = -64;
        }
+       emu->release_mouse_buffer(status);
        update_mouse();
 }
 
@@ -120,9 +122,10 @@ void MOUSE::update_mouse()
 {
        int val = 0;
        
-       if(!(status[2] & 1)) val |= 0x80;       // left
-       if(!(status[2] & 2)) val |= 0x20;       // right
-       if(!(status[2] & 4)) val |= 0x40;       // center
+       int32_t _button = emu->get_mouse_button();
+       if(!(_button & 1)) val |= 0x80; // left
+       if(!(_button & 2)) val |= 0x20; // right
+       if(!(_button & 4)) val |= 0x40; // center
        
        switch(ctrlreg & 0xe0) {
        case 0x00: val |= (dx >> 0) & 0x0f; break;
index 1cf7fbd..b1e361d 100644 (file)
@@ -82,7 +82,7 @@ enum
 void PCE::initialize()
 {
        // get context
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        // register event
        register_vline_event(this);
@@ -1812,6 +1812,7 @@ uint8_t PCE::joy_2btn_pad_r(uint8_t index)
 {
        uint8_t data = 0x0f;
        
+       joy_stat = emu->get_joy_buffer();
        if(joy_high_nibble) {
                if(joy_stat[index - 1] & 0x001) data &= ~0x01;  // Up
                if(joy_stat[index - 1] & 0x008) data &= ~0x02;  // Right
@@ -1823,6 +1824,7 @@ uint8_t PCE::joy_2btn_pad_r(uint8_t index)
                if(joy_stat[index - 1] & 0x040) data &= ~0x04;  // Select
                if(joy_stat[index - 1] & 0x080) data &= ~0x08;  // Run
        }
+       emu->release_joy_buffer(joy_stat);
        return data;
 }
 
@@ -1831,6 +1833,7 @@ uint8_t PCE::joy_6btn_pad_r(uint8_t index)
        uint8_t data = 0x0f;
        
        if(joy_second_byte) {
+               joy_stat = emu->get_joy_buffer();
                if(joy_high_nibble) {
                        if(joy_stat[index - 1] & 0x001) data &= ~0x01;  // Up
                        if(joy_stat[index - 1] & 0x008) data &= ~0x02;  // Right
@@ -1842,14 +1845,17 @@ uint8_t PCE::joy_6btn_pad_r(uint8_t index)
                        if(joy_stat[index - 1] & 0x040) data &= ~0x04;  // Select
                        if(joy_stat[index - 1] & 0x080) data &= ~0x08;  // Run
                }
+               emu->release_joy_buffer(joy_stat);
        } else {
                if(joy_high_nibble) {
                        return 0x00;
                } else {
+                       joy_stat = emu->get_joy_buffer();
                        if(joy_stat[index - 1] & 0x100) data &= ~0x01;  // Button #3
                        if(joy_stat[index - 1] & 0x200) data &= ~0x02;  // Button #4
                        if(joy_stat[index - 1] & 0x400) data &= ~0x04;  // Button #5
                        if(joy_stat[index - 1] & 0x800) data &= ~0x08;  // Button #6
+                       emu->release_joy_buffer(joy_stat);
                }
        }
        if(!support_multi_tap) {
index ebdee0f..a5b8f43 100644 (file)
@@ -15,7 +15,7 @@ namespace PHC25 {
 
 void JOYSTICK::initialize()
 {
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        // register event to update the key status
        register_frame_event(this);
@@ -23,8 +23,13 @@ void JOYSTICK::initialize()
 
 void JOYSTICK::event_frame()
 {
-       d_psg->write_signal(SIG_AY_3_891X_PORT_A, ~(joy_stat[0] & 0x1f), 0xff);
-       d_psg->write_signal(SIG_AY_3_891X_PORT_B, ~(joy_stat[1] & 0x1f), 0xff);
+       joy_stat = emu->get_joy_buffer();
+       uint32_t _n[2];
+       _n[0] = joy_stat[0];
+       _n[1] = joy_stat[1];
+       emu->release_joy_buffer(joy_stat);
+       d_psg->write_signal(SIG_AY_3_891X_PORT_A, ~(_n[0] & 0x1f), 0xff);
+       d_psg->write_signal(SIG_AY_3_891X_PORT_B, ~(_n[1] & 0x1f), 0xff);
 }
 
 }
index 6798a2f..f354c5d 100644 (file)
@@ -14,7 +14,7 @@ namespace PV1000 {
 void JOYSTICK::initialize()
 {
        key = emu->get_key_buffer();
-       joy = emu->get_joy_buffer();
+//     joy = emu->get_joy_buffer();
        
        // register event to interrupt
        register_frame_event(this);
@@ -50,6 +50,7 @@ uint32_t JOYSTICK::read_io8(uint32_t addr)
                break;
        case 0xfd:
                val = 0;
+               joy = emu->get_joy_buffer();
                if(column & 1) {
                        if(joy[0] & 0x40) val |= 1;     // #1 select
                        if(joy[0] & 0x80) val |= 2;     // #1 start
@@ -74,6 +75,7 @@ uint32_t JOYSTICK::read_io8(uint32_t addr)
                        if(joy[1] & 0x10) val |= 4;     // #2 trig1
                        if(joy[1] & 0x20) val |= 8;     // #2 trig2
                }
+               emu->release_joy_buffer(joy);
 //             status &= ~2;
                break;
        }
index ac69d6a..60b7c6f 100644 (file)
@@ -32,7 +32,7 @@ static const int key_map[16][8] = {
 
 void KEYBOARD::initialize()
 {
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
 }
 
 void KEYBOARD::reset()
@@ -64,6 +64,7 @@ uint32_t KEYBOARD::read_io8(uint32_t addr)
                if(key_stat[key_map[key_no][2]]) val |= 2;
                if(key_stat[key_map[key_no][1]]) val |= 4;
                if(key_stat[key_map[key_no][0]]) val |= 8;
+               joy_stat = emu->get_joy_buffer();
                if(key_no == 6) {
                        if(joy_stat[0] & 0x02) val |= 1;
                        if(joy_stat[0] & 0x08) val |= 2;
@@ -80,6 +81,7 @@ uint32_t KEYBOARD::read_io8(uint32_t addr)
                        if(joy_stat[1] & 0x10) val |= 4;
                        if(joy_stat[1] & 0x20) val |= 8;
                }
+               emu->release_joy_buffer(joy_stat);
                return val;
        case 0x40:
                if(key_stat[0x11]) val |= 1;    // COLOR (CTRL)
index 8cfd0cc..cf85c6b 100644 (file)
@@ -75,7 +75,7 @@ void MEMORY::initialize()
        
        // get keyboard and joystick buffers
        key = emu->get_key_buffer();
-       joy = emu->get_joy_buffer();
+//     joy = emu->get_joy_buffer();
        
        ctype = 0;
 }
@@ -145,12 +145,14 @@ uint32_t MEMORY::read_data8(uint32_t addr)
                return 0;       // tutor 0x42 ???
        } else if(addr == 0xe800) {
                // PyuTa Jr. JOY1
+               joy = emu->get_joy_buffer();
                if(joy[0] & 0x10) val |= 0x04;  // JOY1 B1
                if(joy[0] & 0x20) val |= 0x08;  // JOY1 B2
                if(joy[0] & 0x02) val |= 0x10;  // JOY1 DOWN
                if(joy[0] & 0x04) val |= 0x20;  // JOY1 LEFT
                if(joy[0] & 0x01) val |= 0x40;  // JOY1 UP
                if(joy[0] & 0x08) val |= 0x80;  // JOY1 RIGHT
+               emu->release_joy_buffer(joy);
                return val;
        } else if(addr == 0xe820) {
                // printer busy
@@ -175,12 +177,14 @@ uint32_t MEMORY::read_data8(uint32_t addr)
                return val;
        } else if(addr == 0xee00) {
                // PyuTa Jr. JOY2
+               joy = emu->get_joy_buffer();
                if(joy[1] & 0x10) val |= 0x04;  // JOY2 B1
                if(joy[1] & 0x20) val |= 0x08;  // JOY2 B2
                if(joy[1] & 0x02) val |= 0x10;  // JOY2 DOWN
                if(joy[1] & 0x04) val |= 0x20;  // JOY2 LEFT
                if(joy[1] & 0x01) val |= 0x40;  // JOY2 UP
                if(joy[1] & 0x08) val |= 0x80;  // JOY2 RIGHT
+               emu->release_joy_buffer(joy);
                return val;
        } else {
                return 0xff;    // pull up ?
@@ -239,6 +243,7 @@ uint32_t MEMORY::read_io8(uint32_t addr)
                if(key[0x4d]             ) val |= 0x80; // M
                return val;
        case 0xec4:
+               joy = emu->get_joy_buffer();
                if(key[0x30] || key[0x60]      ) val |= 0x01;   // 0
                if(key[0xbd]                   ) val |= 0x02;   // -
                if(key[0x4f] || (joy[0] & 0x10)) val |= 0x04;   // O    JOY1 B1
@@ -247,14 +252,17 @@ uint32_t MEMORY::read_io8(uint32_t addr)
                if(key[0xbb] || (joy[0] & 0x04)) val |= 0x20;   // ;    JOY1 LEFT
                if(key[0xbc] || (joy[0] & 0x01)) val |= 0x40;   // ,    JOY1 UP
                if(key[0xbe] || (joy[0] & 0x08)) val |= 0x80;   // .    JOY1 RIGHT
+               emu->release_joy_buffer(joy);
                return val;
        case 0xec5:
+               joy = emu->get_joy_buffer();
                if(key[0xdc] || (joy[1] & 0x10)) val |= 0x04;   // YEN  JOY2 B1
                if(key[0xc0] || (joy[1] & 0x20)) val |= 0x08;   // @    JOY2 B2
                if(key[0xba] || (joy[1] & 0x02)) val |= 0x10;   // :    JOY2 DOWN
                if(key[0xdd] || (joy[1] & 0x04)) val |= 0x20;   // ]    JOY2 LEFT
                if(key[0xbf] || (joy[1] & 0x01)) val |= 0x40;   // /    JOY2 UP
                if(key[0xe2] || (joy[1] & 0x08)) val |= 0x80;   // _    JOY2 RIGHT
+               emu->release_joy_buffer(joy);
                return val;
        case 0xec6:
                if(key[0x11]) val |= 0x02;      // EISUU -> CTRL
index 740bfbc..7b46dca 100644 (file)
@@ -26,7 +26,7 @@ static const int key_map[9][8] = {
 void KEYBOARD::initialize()
 {
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        // register event to update the key status
        register_frame_event(this);
@@ -60,6 +60,7 @@ void KEYBOARD::event_frame()
        }
        
        // joystick #1
+       joy_stat = emu->get_joy_buffer();
        switch(joy_stat[0] & 0x0f) {
                case 0x1: status[ 9] |= 0x11; break;    // u
                case 0x2: status[11] |= 0x11; break;    // d
@@ -85,7 +86,7 @@ void KEYBOARD::event_frame()
        }
        if(joy_stat[1] & 0x10) status[12] |= 0x88;      // b1
        if(joy_stat[1] & 0x20) status[14] |= 0x88;      // b2
-       
+       emu->release_joy_buffer(joy_stat);
        // $30
        uint8_t total = 0;
        for(int i = 0; i < 15; i++) {
index 5f670b2..5199a57 100644 (file)
@@ -26,7 +26,7 @@ static const uint8_t key_map[8][12] = {
 void KEYBOARD::initialize()
 {
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        column = 0;
        break_pressed = false;
@@ -67,6 +67,7 @@ void KEYBOARD::update_keyboard()
                }
        } else {
                // joystick
+               joy_stat = emu->get_joy_buffer();
                for(int i = 0; i < 12; i++) {
                        uint8_t map = key_map[7][i];
                        uint8_t stat = (map & 0x80) ? joy_stat[1] : joy_stat[0];
@@ -74,6 +75,7 @@ void KEYBOARD::update_keyboard()
                                data |= (1 << i);
                        }
                }
+               emu->release_joy_buffer(joy_stat);
        }
        d_pio->write_signal(SIG_I8255_PORT_A, ~data, 0xff);
        data >>= 8;
index 4da6bb3..290d925 100644 (file)
@@ -15,7 +15,7 @@ namespace SCV {
 void IO::initialize()
 {
        key = emu->get_key_buffer();
-       joy = emu->get_joy_buffer();
+//     joy = emu->get_joy_buffer();
 }
 
 void IO::reset()
@@ -53,6 +53,7 @@ uint32_t IO::read_io8(uint32_t addr)
        case P_A:
                return pa;
        case P_B:
+               joy = emu->get_joy_buffer();
                if(!(pa & 0x01)) {
                        if(joy[0] & 0x04) val &= ~0x01; // P1-L
                        if(joy[0] & 0x01) val &= ~0x02; // P1-U
@@ -69,6 +70,7 @@ uint32_t IO::read_io8(uint32_t addr)
                        if(joy[1] & 0x08) val &= ~0x10; // P2-R
                        if(joy[1] & 0x20) val &= ~0x20; // P2-TR2
                }
+               emu->release_joy_buffer(joy);
                if(!(pa & 0x04)) {
                        if(key[0x30] || key[0x60]) val &= ~0x40;        // 0
                        if(key[0x31] || key[0x61]) val &= ~0x80;        // 1
index 2127361..ee56ead 100644 (file)
@@ -158,7 +158,7 @@ void MEMORY::initialize()
        initialize_key();
        caps = kana = false;
        key_stat = emu->get_key_buffer();
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        // initialize display
        static const uint8_t color_table[16][3] = {
@@ -599,7 +599,9 @@ uint32_t MEMORY::read_io8_debug(uint32_t addr)
                        // bit1: ~B             0 = joystick back on
                        // bit0: ~F             0 = joystick forward on
                        {
+                               joy_stat = emu->get_joy_buffer();
                                uint32_t stat = joy_stat[(addr & 0x100) ? 0 : 1];
+                               emu->release_joy_buffer(joy_stat);
                                if(addr & 0x100) {
                                        if(key_stat[0x26]) stat |= 0x01; // up
                                        if(key_stat[0x28]) stat |= 0x02; // down
index 1fc475f..7ccfefc 100644 (file)
@@ -23,7 +23,7 @@ namespace SVI_3X8 {
 
 void JOYSTICK::initialize()
 {
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        select = 0;
        
        // register event to update the key status
@@ -32,9 +32,14 @@ void JOYSTICK::initialize()
 
 void JOYSTICK::event_frame()
 {
-///    d_psg->write_signal(SIG_AY_3_891X_PORT_A, PSG14_MASK & ~(joy_stat[select] & 0x3f), 0x7f);
-       d_psg->write_signal(SIG_AY_3_891X_PORT_A, ~((joy_stat[0] & 0x0f)|(joy_stat[1] & 0x0f)<<4), 0xff);
-       d_memory->write_io8(select, ~((joy_stat[0] & 0x10)|(joy_stat[1] & 0x10)<<1));
+       uint32_t _n[2];
+       joy_stat = emu->get_joy_buffer();
+       _n[0] = joy_stat[0];
+       _n[1] = joy_stat[1];
+       emu->release_joy_buffer(joy_stat);
+///    d_psg->write_signal(SIG_AY_3_891X_PORT_A, PSG14_MASK & ~(_n[select] & 0x3f), 0x7f);
+       d_psg->write_signal(SIG_AY_3_891X_PORT_A, ~((_n[0] & 0x0f)|(_n[1] & 0x0f)<<4), 0xff);
+       d_memory->write_io8(select, ~((_n[0] & 0x10)|(_n[1] & 0x10)<<1));
 }
 
 #define STATE_VERSION  1
index 530e92f..f9f2287 100644 (file)
@@ -17,7 +17,7 @@ namespace X1 {
 
 void JOYSTICK::initialize()
 {
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        
        // register event
        register_frame_event(this);
@@ -30,12 +30,14 @@ void JOYSTICK::event_frame()
 #ifdef _X1TWIN
                if(!vm->is_cart_inserted(0)) {
 #endif
+                       joy_stat = emu->get_joy_buffer();
                        if(joy_stat[i] & 0x01) val &= ~0x01;
                        if(joy_stat[i] & 0x02) val &= ~0x02;
                        if(joy_stat[i] & 0x04) val &= ~0x04;
                        if(joy_stat[i] & 0x08) val &= ~0x08;
                        if(joy_stat[i] & 0x10) val &= ~0x20;
                        if(joy_stat[i] & 0x20) val &= ~0x40;
+                       emu->release_joy_buffer(joy_stat);
 #ifdef _X1TWIN
                }
 #endif
index 51cc997..5df9515 100644 (file)
@@ -17,7 +17,7 @@ namespace X1 {
 
 void MOUSE::initialize()
 {
-       stat = emu->get_mouse_buffer();
+//     stat = emu->get_mouse_buffer();
 }
 
 void MOUSE::write_signal(int id, uint32_t data, uint32_t mask)
@@ -27,11 +27,13 @@ void MOUSE::write_signal(int id, uint32_t data, uint32_t mask)
                        return;
                }
                // Z80SIO Ch.B RTS H->L
+               stat = emu->get_mouse_buffer();
                uint32_t d0 = (stat[0] >= 128 ? 0x10 : stat[0] < -128 ? 0x20 : 0) |
                            (stat[1] >= 128 ? 0x40 : stat[1] < -128 ? 0x80 : 0) |
                            ((stat[2] & 1) ? 1 : 0) | ((stat[2] & 2) ? 2 : 0);
                uint32_t d1 = (uint8_t)stat[0];
                uint32_t d2 = (uint8_t)stat[1];
+               emu->release_mouse_buffer();
                
                d_sio->write_signal(SIG_Z80SIO_CLEAR_CH1, 1, 1);
                d_sio->write_signal(SIG_Z80SIO_RECV_CH1, d0, 0xff);
index 26c4cec..523cf30 100644 (file)
@@ -20,19 +20,21 @@ namespace Z80TVGAME {
 
 void JOYSTICK::initialize()
 {
-       joy_stat = emu->get_joy_buffer();
+//     joy_stat = emu->get_joy_buffer();
        register_frame_event(this);
 }
 
 void JOYSTICK::event_frame()
 {
        uint32_t val = 0x3f;
+       joy_stat = emu->get_joy_buffer();
        if(joy_stat[0] & 0x01) val &= ~0x01;    // up
        if(joy_stat[0] & 0x02) val &= ~0x02;    // dpwn
        if(joy_stat[0] & 0x04) val &= ~0x04;    // left
        if(joy_stat[0] & 0x08) val &= ~0x08;    // right
        if(joy_stat[0] & 0x10) val &= ~0x10;    // trigger #1
        if(joy_stat[0] & 0x20) val &= ~0x20;    // trigger #2
+       emu->release_joy_buffer(joy_stat);
 #ifdef _USE_I8255
        d_pio->write_signal(SIG_I8255_PORT_A, val, 0xff);
 #else
index a1b310f..73c3d60 100644 (file)
@@ -552,14 +552,28 @@ public:
 #ifdef USE_JOYSTICK
        uint32_t* get_joy_buffer()
        {
+               // ToDo: Lock
                return joy_status;
        }
+       void release_joy_buffer(uint32_t* ptr)
+       {
+               // ToDo: Unlock
+       }
 #endif
 #ifdef USE_MOUSE
        int32_t* get_mouse_buffer()
        {
+               // ToDo: Lock
                return mouse_status;
        }
+       void release_mouse_buffer(int32_t* ptr)
+       {
+               // ToDo: Unlock
+       }
+       int32_t get_mouse_button()
+       {
+               return mouse_status[2];
+       }
 #endif
 #ifdef USE_AUTO_KEY
        bool now_auto_key;