OSDN Git Service

[VM][General][WIP] Apply new (Upstream 2016-02-21) APIs to VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / msx / joystick.cpp
1 /*
2         ASCII MSX1 Emulator 'yaMSX1'
3         ASCII MSX2 Emulator 'yaMSX2'
4         Pioneer PX-7 Emulator 'ePX-7'
5
6         Author : tanam
7         Date   : 2013.06.29-
8
9         modified by Takeda.Toshiya
10         modified by umaiboux
11
12         [ joystick ]
13 */
14
15 #include "joystick.h"
16 #include "../ym2203.h"
17
18 void JOYSTICK::initialize()
19 {
20         joy_stat = emu->get_joy_buffer();
21         select = 0;
22         
23         // register event to update the key status
24         register_frame_event(this);
25 }
26
27 void JOYSTICK::event_frame()
28 {
29         d_psg->write_signal(SIG_YM2203_PORT_A, ~(joy_stat[select] & 0x3f), 0x7f);
30 }
31
32 void JOYSTICK::write_signal(int id, uint32 data, uint32 mask)
33 {
34         if(id == SIG_JOYSTICK_SEL) {
35                 if(select != ((data & mask) != 0)) {
36                         select = ((data & mask) != 0);
37                         d_psg->write_signal(SIG_YM2203_PORT_A, ~(joy_stat[select] & 0x3f), 0x7f);
38                 }
39         }
40 }
41
42 #define STATE_VERSION   1
43
44 void JOYSTICK::save_state(FILEIO* state_fio)
45 {
46         state_fio->FputUint32(STATE_VERSION);
47         state_fio->FputInt32(this_device_id);
48         
49         state_fio->FputInt32(select);
50 }
51
52 bool JOYSTICK::load_state(FILEIO* state_fio)
53 {
54         if(state_fio->FgetUint32() != STATE_VERSION) {
55                 return false;
56         }
57         if(state_fio->FgetInt32() != this_device_id) {
58                 return false;
59         }
60         select = state_fio->FgetInt32();
61         return true;
62 }
63