OSDN Git Service

e1e2d2f28952e0bcffffb87dfe5d2de9c6735f70
[csp-qt/common_source_project-fm7.git] / source / src / vm / rx78 / cmt.cpp
1 /*
2         BANDAI RX-78 Emulator 'eRX-78'
3
4         Author : Takeda.Toshiya
5         Date   : 2006.08.21 -
6
7         [ cmt ]
8 */
9
10 #include "cmt.h"
11 #include "../datarec.h"
12
13 void CMT::initialize()
14 {
15         // data recorder
16         in = out = remote = now_acc = false;
17         framecnt = 0;
18         
19         // register event to detect the end of access
20         register_frame_event(this);
21 }
22
23 void CMT::write_io8(uint32_t addr, uint32_t data)
24 {
25         // data recorder
26         if(!remote) {
27                 // motor on
28                 d_drec->write_signal(SIG_DATAREC_REMOTE, 1, 1);
29                 remote = true;
30         }
31         bool signal = ((data & 1) != 0);
32         if(signal != out) {
33                 d_drec->write_signal(SIG_DATAREC_MIC, signal ? 1 : 0, 1);
34                 out = signal;
35         }
36         now_acc = true;
37 }
38
39 uint32_t CMT::read_io8(uint32_t addr)
40 {
41         if(!remote) {
42                 // motor on
43                 d_drec->write_signal(SIG_DATAREC_REMOTE, 1, 1);
44                 remote = true;
45         }
46         now_acc = true;
47         return in ? 1 : 0;
48 }
49
50 void CMT::write_signal(int id, uint32_t data, uint32_t mask)
51 {
52         if(id == SIG_CMT_IN) {
53                 in = ((data & mask) != 0);
54         }
55 }
56
57 void CMT::event_frame()
58 {
59         if(remote) {
60                 if(now_acc) {
61                         framecnt = 0;
62                 } else if(++framecnt >= FRAMES_PER_SEC) {
63                         // motor off if not accessed for past 1 sec
64                         d_drec->write_signal(SIG_DATAREC_REMOTE, 0, 1);
65                         remote = false;
66                 }
67                 now_acc = false;
68         }
69 }
70
71 #define STATE_VERSION   1
72
73 #include "../../statesub.h"
74
75 void CMT::decl_state()
76 {
77         enter_decl_state(STATE_VERSION);
78
79         DECL_STATE_ENTRY_BOOL(in);
80         DECL_STATE_ENTRY_BOOL(out);
81         DECL_STATE_ENTRY_BOOL(remote);
82         DECL_STATE_ENTRY_BOOL(now_acc);
83         DECL_STATE_ENTRY_INT32(framecnt);
84         
85         leave_decl_state();
86 }
87
88 void CMT::save_state(FILEIO* state_fio)
89 {
90         if(state_entry != NULL) {
91                 state_entry->save_state(state_fio);
92         }
93 //      state_fio->FputUint32(STATE_VERSION);
94 //      state_fio->FputInt32(this_device_id);
95         
96 //      state_fio->FputBool(in);
97 //      state_fio->FputBool(out);
98 //      state_fio->FputBool(remote);
99 //      state_fio->FputBool(now_acc);
100 //      state_fio->FputInt32(framecnt);
101 }
102
103 bool CMT::load_state(FILEIO* state_fio)
104 {
105         bool mb = false;
106         if(state_entry != NULL) {
107                 mb = state_entry->load_state(state_fio);
108         }
109         if(!mb) {
110                 return false;
111         }
112 //      if(state_fio->FgetUint32() != STATE_VERSION) {
113 //              return false;
114 //      }
115 //      if(state_fio->FgetInt32() != this_device_id) {
116 //              return false;
117 //      }
118 //      in = state_fio->FgetBool();
119 //      out = state_fio->FgetBool();
120 //      remote = state_fio->FgetBool();
121 //      now_acc = state_fio->FgetBool();
122 //      framecnt = state_fio->FgetInt32();
123         return true;
124 }
125