2 MITSUBISHI Electric MULTI8 Emulator 'EmuLTI8'
4 Author : Takeda.Toshiya
13 void CMT::initialize()
16 play = rec = remote = false;
28 play = rec = remote = false;
31 void CMT::write_signal(int id, uint32_t data, uint32_t mask)
33 if(id == SIG_CMT_REMOTE) {
34 remote = ((data & mask) != 0);
35 } else if(id == SIG_CMT_OUT) {
38 buffer[bufcnt++] = data & mask;
39 if(bufcnt >= BUFFER_SIZE) {
40 fio->Fwrite(buffer, bufcnt, 1);
47 void CMT::play_tape(const _TCHAR* file_path)
51 if(fio->Fopen(file_path, FILEIO_READ_BINARY)) {
52 fio->Fseek(0, FILEIO_SEEK_END);
53 int size = (fio->Ftell() + 9) & (BUFFER_SIZE - 1);
54 fio->Fseek(0, FILEIO_SEEK_SET);
55 memset(buffer, 0, sizeof(buffer));
56 fio->Fread(buffer, sizeof(buffer), 1);
60 // this implement does not care the sio buffer size... :-(
61 for(int i = 0; i < size; i++) {
62 d_sio->write_signal(SIG_I8251_RECV, buffer[i], 0xff);
68 void CMT::rec_tape(const _TCHAR* file_path)
72 if(fio->Fopen(file_path, FILEIO_READ_WRITE_NEW_BINARY)) {
73 my_tcscpy_s(rec_file_path, _MAX_PATH, file_path);
79 void CMT::close_tape()
85 d_sio->write_signal(SIG_I8251_CLEAR, 0, 0);
88 void CMT::release_tape()
93 fio->Fwrite(buffer, bufcnt, 1);
100 #define STATE_VERSION 2
102 #include "../../statesub.h"
104 void CMT::decl_state()
106 enter_decl_state(STATE_VERSION);
108 DECL_STATE_ENTRY_BOOL(play);
109 DECL_STATE_ENTRY_BOOL(rec);
110 DECL_STATE_ENTRY_BOOL(remote);
111 DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path));
112 DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path);
114 DECL_STATE_ENTRY_INT32(bufcnt);
115 DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
119 void CMT::save_state(FILEIO* state_fio)
121 if(state_entry != NULL) {
122 state_entry->save_state(state_fio);
124 // state_fio->FputUint32(STATE_VERSION);
125 // state_fio->FputInt32(this_device_id);
127 // state_fio->FputBool(play);
128 // state_fio->FputBool(rec);
129 // state_fio->FputBool(remote);
130 // state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
131 // if(rec && fio->IsOpened()) {
132 // int length_tmp = (int)fio->Ftell();
133 // fio->Fseek(0, FILEIO_SEEK_SET);
134 // state_fio->FputInt32(length_tmp);
135 // while(length_tmp != 0) {
136 // uint8_t buffer_tmp[1024];
137 // int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
138 // fio->Fread(buffer_tmp, length_rw, 1);
139 // state_fio->Fwrite(buffer_tmp, length_rw, 1);
140 // length_tmp -= length_rw;
143 // state_fio->FputInt32(0);
145 // state_fio->FputInt32(bufcnt);
146 // state_fio->Fwrite(buffer, sizeof(buffer), 1);
149 bool CMT::load_state(FILEIO* state_fio)
154 if(state_entry != NULL) {
155 mb = state_entry->load_state(state_fio);
160 // if(state_fio->FgetUint32() != STATE_VERSION) {
163 // if(state_fio->FgetInt32() != this_device_id) {
166 // play = state_fio->FgetBool();
167 // rec = state_fio->FgetBool();
168 // remote = state_fio->FgetBool();
169 // state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
170 // int length_tmp = state_fio->FgetInt32();
172 // fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
173 // while(length_tmp != 0) {
174 // uint8_t buffer_tmp[1024];
175 // int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
176 // state_fio->Fread(buffer_tmp, length_rw, 1);
177 // if(fio->IsOpened()) {
178 // fio->Fwrite(buffer_tmp, length_rw, 1);
180 // length_tmp -= length_rw;
183 // bufcnt = state_fio->FgetInt32();
184 // state_fio->Fread(buffer, sizeof(buffer), 1);
188 bool CMT::process_state(FILEIO* state_fio, bool loading)
190 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
193 if(!state_fio->StateCheckInt32(this_device_id)) {
196 state_fio->StateBool(play);
197 state_fio->StateBool(rec);
198 state_fio->StateBool(remote);
199 state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
201 int length_tmp = state_fio->FgetInt32_LE();
203 fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
204 while(length_tmp != 0) {
205 uint8_t buffer_tmp[1024];
206 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
207 state_fio->Fread(buffer_tmp, length_rw, 1);
208 if(fio->IsOpened()) {
209 fio->Fwrite(buffer_tmp, length_rw, 1);
211 length_tmp -= length_rw;
215 if(rec && fio->IsOpened()) {
216 int length_tmp = (int)fio->Ftell();
217 fio->Fseek(0, FILEIO_SEEK_SET);
218 state_fio->FputInt32_LE(length_tmp);
219 while(length_tmp != 0) {
220 uint8_t buffer_tmp[1024];
221 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
222 fio->Fread(buffer_tmp, length_rw, 1);
223 state_fio->Fwrite(buffer_tmp, length_rw, 1);
224 length_tmp -= length_rw;
227 state_fio->FputInt32_LE(0);
230 state_fio->StateInt32(bufcnt);
231 state_fio->StateBuffer(buffer, sizeof(buffer), 1);