OSDN Git Service

[VM][General] Merge upstream 2016-02-13. Still don't implement OSD/Gui part of joysti...
[csp-qt/common_source_project-fm7.git] / source / src / vm / pcengine / pce.cpp
index db5d856..22694c3 100644 (file)
@@ -70,7 +70,6 @@ void PCE::initialize()
 {
        // get context
        joy_stat = emu->joy_buffer();
-       key_stat = emu->key_buffer();
        
        // register event
        register_vline_event(this);
@@ -1576,10 +1575,10 @@ void PCE::mix(int32* buffer, int cnt)
                        int32 wav = ((int32)psg[ch].wav[0] - 16) * 702;
                        int32 vol = max((psg_vol >> 3) & 0x1e, (psg_vol << 1) & 0x1e) + (psg[ch].regs[4] & 0x1f) + max((psg[ch].regs[5] >> 3) & 0x1e, (psg[ch].regs[5] << 1) & 0x1e) - 60;
                        vol = (vol < 0) ? 0 : (vol > 31) ? 31 : vol;
-                       vol = wav * vol_tbl[vol] / 16384;
+                       int32 outvol = wav * vol_tbl[vol] / 16384;
                        for(int i = 0, j = 0; i < cnt; i++, j += 2) {
-                               buffer[j    ] += vol; // L
-                               buffer[j + 1] += vol; // R
+                               buffer[j    ] += apply_volume(outvol, volume_l); // L
+                               buffer[j + 1] += apply_volume(outvol, volume_r); // R
                        }
                }
                else if(ch >= 4 && (psg[ch].regs[7] & 0x80)) {
@@ -1603,8 +1602,8 @@ void PCE::mix(int32* buffer, int cnt)
                                        psg[ch].remain -= sample_rate * t;
                                }
                                int32 outvol = (int32)((psg[ch].noise ? 10 * 702 : -10 * 702) * vol / 16384);
-                               buffer[j    ] += outvol; // L
-                               buffer[j + 1] += outvol; // R
+                               buffer[j    ] += apply_volume(outvol, volume_l); // L
+                               buffer[j + 1] += apply_volume(outvol, volume_r); // R
                        }
                }
                else {
@@ -1619,8 +1618,8 @@ void PCE::mix(int32* buffer, int cnt)
                                vol = vol_tbl[vol];
                                for(int i = 0, j = 0; i < cnt; i++, j += 2) {
                                        int32 outvol = wav[psg[ch].genptr] * vol / 16384;
-                                       buffer[j    ] += outvol; // L
-                                       buffer[j + 1] += outvol; // R
+                                       buffer[j    ] += apply_volume(outvol, volume_l); // L
+                                       buffer[j + 1] += apply_volume(outvol, volume_r); // R
                                        psg[ch].remain += 32 * 1118608 / freq;
                                        uint32 t = psg[ch].remain / (10 * sample_rate);
                                        psg[ch].genptr = (psg[ch].genptr + t) & 0x1f;
@@ -1631,6 +1630,12 @@ void PCE::mix(int32* buffer, int cnt)
        }
 }
 
+void PCE::set_volume(int ch, int decibel_l, int decibel_r)
+{
+       volume_l = decibel_to_volume(decibel_l);
+       volume_r = decibel_to_volume(decibel_r);
+}
+
 // joypad (non multipad)
 
 void PCE::joy_reset()
@@ -1662,22 +1667,8 @@ uint8 PCE::joy_read(uint16 addr)
        uint8 val = 0xf;
        uint32 stat = 0;
        
-       if(joy_count == 0) {
-               stat = joy_stat[0];
-               if(key_stat[0x26]) stat |= 0x001;       // up
-               if(key_stat[0x28]) stat |= 0x002;       // down
-               if(key_stat[0x25]) stat |= 0x004;       // left
-               if(key_stat[0x27]) stat |= 0x008;       // right
-               if(key_stat[0x44]) stat |= 0x010;       // d (1)
-               if(key_stat[0x53]) stat |= 0x020;       // s (2)
-               if(key_stat[0x20]) stat |= 0x040;       // space (select)
-               if(key_stat[0x0d]) stat |= 0x080;       // enter (run)
-               if(key_stat[0x41]) stat |= 0x100;       // a (3)
-               if(key_stat[0x51]) stat |= 0x200;       // q (4)
-               if(key_stat[0x57]) stat |= 0x400;       // w (5)
-               if(key_stat[0x45]) stat |= 0x800;       // e (6)
-       } else if(joy_count == 1) {
-               stat = joy_stat[1];
+       if(joy_count < 4) {
+               stat = joy_stat[joy_count];
        }
        if(support_6btn && joy_bank) {
                if(joy_sel) {