OSDN Git Service

[VM][FMTOWNS][JOYPAD][MOUSE][WIP] Around MOUSE/Joystick.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 21 Jun 2021 18:14:07 +0000 (03:14 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 21 Jun 2021 18:14:07 +0000 (03:14 +0900)
source/src/vm/fmtowns/fmtowns.cpp
source/src/vm/fmtowns/joypad.cpp
source/src/vm/fmtowns/joystick.cpp
source/src/vm/fmtowns/mouse.cpp
source/src/vm/fmtowns/mouse.h

index 63b2d06..a7fdba1 100644 (file)
@@ -436,6 +436,8 @@ VM::VM(EMU_TEMPLATE* parent_emu) : VM_TEMPLATE(parent_emu)
        
        joypad[0]->set_context_com(joystick, SIG_JOYPORT_CH0 | SIG_JOYPORT_TYPE_2BUTTONS | SIG_JOYPORT_COM, 0xffffffff);
        joypad[1]->set_context_com(joystick, SIG_JOYPORT_CH1 | SIG_JOYPORT_TYPE_2BUTTONS | SIG_JOYPORT_COM, 0xffffffff);
+       mouse->set_context_com(joystick);
+
        // cpu bus
        cpu->set_context_mem(memory);
        cpu->set_context_io(io);
index 1b6037d..29ee64c 100644 (file)
@@ -20,11 +20,12 @@ void JOYPAD::initialize()
        set_device_name(_T("%s"), tmps);
 //     rawdata = emu->get_joy_buffer();
        register_frame_event(this);
+       sel_line = false;
 }
 
 void JOYPAD::reset()
 {
-       sel_line = true;
+//     sel_line = true;
 //     write_signals(&line_dat,   0);
        query_joystick();
        write_signals(&line_com,   (enabled) ? 0xffffffff : 0x00000000);
@@ -108,12 +109,14 @@ void JOYPAD::write_signal(int id, uint32_t data, uint32_t mask)
                break;
        case SIG_JOYPAD_SELECT_BUS:
 //             out_debug_log(_T("SIG_JOYPAD_SELECT_BUS, VALUE=%08X"), ndata);
-               if(ndata != 0) {
-                       sel_line = true;
-               } else {
-                       sel_line = false;
+               if(enabled) {
+                       if(ndata != 0) {
+                               sel_line = true;
+                       } else {
+                               sel_line = false;
+                       }
+                       write_signals(&line_com, (sel_line) ? 0xffffffff : 0x00000000);
                }
-               write_signals(&line_com, (sel_line) ? 0xffffffff : 0x00000000);
                break;
        }
 }
index 61daa40..30278a8 100644 (file)
@@ -66,31 +66,44 @@ uint32_t JOYSTICK::read_io8(uint32_t address)
        case 0x04d0:
        case 0x04d2:
                {
-                       retval = 0xff;
-                       uint8_t mask2 = (mouse_mask >> (port_num + 4)) & 0x01;
-                       if((mask2 & 0x01) == 0) { // COM
-                               retval = retval & ~0x40;
-                       }
                        if(emulate_mouse[port_num]) {
+                               uint8_t mask2 = (mouse_mask >> (port_num + 4)) & 0x01;
+                               retval = 0x00;
+                               if((mask2 & 0x01) != 0) { // COM
+                                       retval = 0x40;
+                               }
+                               if(!(stat_com[port_num])) { // COM
+                                       retval &= ~0x40;
+                               }
                                if(d_mouse != nullptr) {
-                                       retval &= d_mouse->read_signal(SIG_MOUSE_DATA);
+                                       retval |= d_mouse->read_signal(SIG_MOUSE_DATA);
                                }
                        } else {
                                uint8_t trig = (mouse_mask >> (port_num << 1)) & 0x03;
+                               retval = 0xff;
+                               uint8_t mask2 = (mouse_mask >> (port_num + 4)) & 0x01;
+                               if((mask2 & 0x01) == 0) { // COM
+                                       retval &= ~0x40;
+                               }
                                if(connected_type[port_num] == SIG_JOYPORT_TYPE_NULL) {
                                        // None Connected
                                        return retval;
                                }
+                               if(!(stat_com[port_num])) { // COM
+                                       retval &= ~0x40;
+                               }
                                // Trigger independents from direction keys.
+                               if((trig & 0x02) == 0) { // TRIG2
+                                       retval = retval & ~0x20;
+                               }
                                if((joydata[port_num] & LINE_JOYPORT_B) != 0) {
-                                       if((trig & 0x02) != 0) { // TRIG2
-                                               retval = retval & ~0x20;
-                                       }
+                                       retval = retval & ~0x20;
+                               }
+                               if((trig & 0x01) == 0) { // TRIG1
+                                       retval = retval & ~0x10;
                                }
                                if((joydata[port_num] & LINE_JOYPORT_A) != 0) {
-                                       if((trig & 0x01) != 0) { // TRIG1
-                                               retval = retval & ~0x10;
-                                       }
+                                       retval = retval & ~0x10;
                                }
                                //if((mask & (0x10 << port_num)) == 0) {
 //                             if((mask2 & 0x01) == 0) { // COM
index 8a34d18..5f89ff6 100644 (file)
@@ -9,6 +9,7 @@
 */
 
 #include "./mouse.h"
+#include "./joystick.h"
 
 namespace FMTOWNS {
 
@@ -46,13 +47,34 @@ void MOUSE::reset()
        // Values around mouse aren't initialized on reset.
 //     mouse_state = emu->get_mouse_buffer();
 //     update_config(); // Update MOUSE PORT.
+       if(mouse_connected) {
+               uint32_t com_d = SIG_JOYPORT_TYPE_MOUSE;
+               if(port_num != 0) {
+                       com_d |= SIG_JOYPORT_CH1;
+               }
+               if(strobe) {
+                       com_d |= SIG_JOYPORT_COM;
+               }
+               if(d_joyport != nullptr) {
+                       d_joyport->write_signal(com_d, 0xffffffff, 0xffffffff);
+               }
+       }
 }
 
 void MOUSE::update_strobe()
 {
+
        bool _bak = strobe;
        uint8_t _mask = ((port_num & 1) != 0) ? 0x20 : 0x10;
        strobe = ((mouse_mask & _mask) != 0) ? true : false;
+       
+       uint32_t com_d = SIG_JOYPORT_TYPE_MOUSE;
+       if(port_num != 0) {
+               com_d |= SIG_JOYPORT_CH1;
+       }
+       if(strobe) {
+               com_d |= SIG_JOYPORT_COM;
+       }
        if((_bak != strobe)/* && (flag)*/) {
                if(phase == 0) {
                        if(strobe) {
@@ -67,9 +89,15 @@ void MOUSE::update_strobe()
                                force_register_event(this, EVENT_MOUSE_TIMEOUT, 2000.0, false, event_timeout);
                                phase = 2; // SYNC from MAME 0.225. 20201126 K.O
                        }
+                       if(d_joyport != nullptr) {
+                               d_joyport->write_signal(com_d, 0xffffffff, 0xffffffff);
+                       }
                        return;
                }
                phase++;
+               if(d_joyport != nullptr) {
+                       d_joyport->write_signal(com_d, 0xffffffff, 0xffffffff);
+               }
        }
 }
 
@@ -112,17 +140,19 @@ uint32_t MOUSE::read_signal(int ch)
                        
                        rval |= (update_mouse() & 0x0f);
                        mouse_state = emu->get_mouse_buffer();
+                       if((trig & 0x01) == 0) {
+                               rval &= ~0x10; // Button LEFT
+                       }
+                       if((trig & 0x02) == 0) {
+                               rval &= ~0x20; // Button RIGHT
+                       }
                        if(mouse_state != NULL) {
                                uint32_t stat = mouse_state[2];
-                               if((trig & 0x01) != 0) {
-                                       if((stat & 0x01) == 0) {
-                                               rval &= ~0x10; // Button LEFT
-                                       }
+                               if((stat & 0x01) == 0) {
+                                       rval &= ~0x10; // Button LEFT
                                }
-                               if((trig & 0x02) != 0) {
-                                       if((stat & 0x02) == 0) {
-                                               rval &= ~0x20; // Button LEFT
-                                       }
+                               if((stat & 0x02) == 0) {
+                                       rval &= ~0x20; // Button RIGHT
                                }
                        }
                        if(!(strobe)) { // COM
index b24f9fb..cc6baaa 100644 (file)
@@ -22,6 +22,7 @@ namespace FMTOWNS {
 class MOUSE : public DEVICE
 {
 private:
+       DEVICE* d_joyport;
        const int32_t* mouse_state;
        
        int phase;
@@ -43,6 +44,7 @@ private:
 public:
        MOUSE(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
        {
+               d_joyport = NULL;
                set_device_name(_T("FM-Towns MOUSE"));
        }
        ~MOUSE() {}
@@ -58,6 +60,11 @@ public:
        void __FASTCALL write_signal(int id, uint32_t data, uint32_t mask);
 
        bool process_state(FILEIO* state_fio, bool loading);
+       
+       void set_context_com(DEVICE* dev)
+       {
+               d_joyport = dev;
+       }
 };
 
 }