2 NEC TK-80BS (COMPO BS/80) Emulator 'eTK-80BS'
3 NEC TK-80 Emulator 'eTK-80'
5 Author : Takeda.Toshiya
12 #include "../datarec.h"
20 void CMT::initialize()
22 mic = ear = pulse = false;
24 register_event(this, EVENT_PULSE, 1000000 / 4000, true, NULL);
46 void CMT::write_signal(int id, uint32_t data, uint32_t mask)
48 if(id == SIG_CMT_MIC) {
49 // recv mic signal from pio
50 mic = ((data & mask) != 0);
51 } else if(id == SIG_CMT_EAR) {
52 // recv ear signal from datarec
53 bool next = ((data & mask) != 0);
59 } else if(id == SIG_CMT_OUT) {
62 buffer[bufcnt++] = data & mask;
63 if(bufcnt >= BUFFER_SIZE) {
64 fio->Fwrite(buffer, bufcnt, 1);
72 void CMT::event_callback(int event_id, int err)
74 // send mic signal to datarec
75 d_drec->write_signal(SIG_DATAREC_MIC, (mic && pulse) ? 1 : 0, 1);
78 // send ear signal to pio
80 // ear signal is not changed for 1 msec or more
81 d_pio->write_signal(SIG_I8255_PORT_B, 0, 1);
83 d_pio->write_signal(SIG_I8255_PORT_B, 1, 1);
89 void CMT::play_tape(const _TCHAR* file_path)
93 if(fio->Fopen(file_path, FILEIO_READ_BINARY)) {
94 fio->Fseek(0, FILEIO_SEEK_END);
95 int size = (fio->Ftell() + 9) & (BUFFER_SIZE - 1);
96 fio->Fseek(0, FILEIO_SEEK_SET);
97 memset(buffer, 0, sizeof(buffer));
98 fio->Fread(buffer, sizeof(buffer), 1);
102 // this implement does not care the sio buffer size... :-(
103 for(int i = 0; i < size; i++) {
104 d_sio->write_signal(SIG_I8251_RECV, buffer[i], 0xff);
110 void CMT::rec_tape(const _TCHAR* file_path)
114 if(fio->Fopen(file_path, FILEIO_WRITE_BINARY)) {
115 my_tcscpy_s(rec_file_path, _MAX_PATH, file_path);
121 void CMT::close_tape()
127 d_sio->write_signal(SIG_I8251_CLEAR, 0, 0);
130 void CMT::release_tape()
133 if(fio->IsOpened()) {
135 fio->Fwrite(buffer, bufcnt, 1);
143 #define STATE_VERSION 2
145 #include "../../statesub.h"
147 void CMT::decl_state()
149 enter_decl_state(STATE_VERSION);
151 DECL_STATE_ENTRY_BOOL(mic);
152 DECL_STATE_ENTRY_BOOL(ear);
153 DECL_STATE_ENTRY_BOOL(pulse);
154 DECL_STATE_ENTRY_INT32(pulse_count);
156 DECL_STATE_ENTRY_BOOL(play);
157 DECL_STATE_ENTRY_BOOL(rec);
158 DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path) / sizeof(_TCHAR));
160 DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path);
162 DECL_STATE_ENTRY_INT32(bufcnt);
163 DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
168 void CMT::save_state(FILEIO* state_fio)
170 if(state_entry != NULL) {
171 state_entry->save_state(state_fio);
173 // state_fio->FputUint32(STATE_VERSION);
174 // state_fio->FputInt32(this_device_id);
176 // state_fio->FputBool(mic);
177 // state_fio->FputBool(ear);
178 // state_fio->FputBool(pulse);
179 // state_fio->FputInt32(pulse_count);
181 // state_fio->FputBool(play);
182 // state_fio->FputBool(rec);
183 // state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
184 // if(rec && fio->IsOpened()) {
185 // int length_tmp = (int)fio->Ftell();
186 // fio->Fseek(0, FILEIO_SEEK_SET);
187 // state_fio->FputInt32(length_tmp);
188 // while(length_tmp != 0) {
189 // uint8_t buffer_tmp[1024];
190 // int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
191 // fio->Fread(buffer_tmp, length_rw, 1);
192 // state_fio->Fwrite(buffer_tmp, length_rw, 1);
193 // length_tmp -= length_rw;
196 // state_fio->FputInt32(0);
198 // state_fio->FputInt32(bufcnt);
199 // state_fio->Fwrite(buffer, sizeof(buffer), 1);
203 bool CMT::load_state(FILEIO* state_fio)
208 if(state_entry != NULL) {
209 mb = state_entry->load_state(state_fio);
214 // if(state_fio->FgetUint32() != STATE_VERSION) {
217 // if(state_fio->FgetInt32() != this_device_id) {
220 // mic = state_fio->FgetBool();
221 // ear = state_fio->FgetBool();
222 // pulse = state_fio->FgetBool();
223 // pulse_count = state_fio->FgetInt32();
224 //#if defined(_TK80BS)
225 // play = state_fio->FgetBool();
226 // rec = state_fio->FgetBool();
227 // state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
228 // int length_tmp = state_fio->FgetInt32();
230 // fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
231 // while(length_tmp != 0) {
232 // uint8_t buffer_tmp[1024];
233 // int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
234 // state_fio->Fread(buffer_tmp, length_rw, 1);
235 // if(fio->IsOpened()) {
236 // fio->Fwrite(buffer_tmp, length_rw, 1);
238 // length_tmp -= length_rw;
241 // bufcnt = state_fio->FgetInt32();
242 // state_fio->Fread(buffer, sizeof(buffer), 1);
247 bool CMT::process_state(FILEIO* state_fio, bool loading)
249 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
252 if(!state_fio->StateCheckInt32(this_device_id)) {
255 state_fio->StateBool(mic);
256 state_fio->StateBool(ear);
257 state_fio->StateBool(pulse);
258 state_fio->StateInt32(pulse_count);
260 state_fio->StateBool(play);
261 state_fio->StateBool(rec);
262 state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
264 int length_tmp = state_fio->FgetInt32_LE();
266 fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
267 while(length_tmp != 0) {
268 uint8_t buffer_tmp[1024];
269 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
270 state_fio->Fread(buffer_tmp, length_rw, 1);
271 if(fio->IsOpened()) {
272 fio->Fwrite(buffer_tmp, length_rw, 1);
274 length_tmp -= length_rw;
278 if(rec && fio->IsOpened()) {
279 int length_tmp = (int)fio->Ftell();
280 fio->Fseek(0, FILEIO_SEEK_SET);
281 state_fio->FputInt32_LE(length_tmp);
282 while(length_tmp != 0) {
283 uint8_t buffer_tmp[1024];
284 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
285 fio->Fread(buffer_tmp, length_rw, 1);
286 state_fio->Fwrite(buffer_tmp, length_rw, 1);
287 length_tmp -= length_rw;
290 state_fio->FputInt32_LE(0);
293 state_fio->StateInt32(bufcnt);
294 state_fio->StateBuffer(buffer, sizeof(buffer), 1);