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"
22 void CMT::initialize()
24 mic = ear = pulse = false;
26 register_event(this, EVENT_PULSE, 1000000 / 4000, true, NULL);
48 void CMT::write_signal(int id, uint32_t data, uint32_t mask)
50 if(id == SIG_CMT_MIC) {
51 // recv mic signal from pio
52 mic = ((data & mask) != 0);
53 } else if(id == SIG_CMT_EAR) {
54 // recv ear signal from datarec
55 bool next = ((data & mask) != 0);
61 } else if(id == SIG_CMT_OUT) {
64 buffer[bufcnt++] = data & mask;
65 if(bufcnt >= BUFFER_SIZE) {
66 fio->Fwrite(buffer, bufcnt, 1);
74 void CMT::event_callback(int event_id, int err)
76 // send mic signal to datarec
77 d_drec->write_signal(SIG_DATAREC_MIC, (mic && pulse) ? 1 : 0, 1);
80 // send ear signal to pio
82 // ear signal is not changed for 1 msec or more
83 d_pio->write_signal(SIG_I8255_PORT_B, 0, 1);
85 d_pio->write_signal(SIG_I8255_PORT_B, 1, 1);
91 void CMT::play_tape(const _TCHAR* file_path)
95 if(fio->Fopen(file_path, FILEIO_READ_BINARY)) {
96 fio->Fseek(0, FILEIO_SEEK_END);
97 int size = (fio->Ftell() + 9) & (BUFFER_SIZE - 1);
98 fio->Fseek(0, FILEIO_SEEK_SET);
99 memset(buffer, 0, sizeof(buffer));
100 fio->Fread(buffer, sizeof(buffer), 1);
104 // this implement does not care the sio buffer size... :-(
105 for(int i = 0; i < size; i++) {
106 d_sio->write_signal(SIG_I8251_RECV, buffer[i], 0xff);
112 void CMT::rec_tape(const _TCHAR* file_path)
116 if(fio->Fopen(file_path, FILEIO_WRITE_BINARY)) {
117 my_tcscpy_s(rec_file_path, _MAX_PATH, file_path);
123 void CMT::close_tape()
129 d_sio->write_signal(SIG_I8251_CLEAR, 0, 0);
132 void CMT::release_tape()
135 if(fio->IsOpened()) {
137 fio->Fwrite(buffer, bufcnt, 1);
145 #define STATE_VERSION 2
147 bool CMT::process_state(FILEIO* state_fio, bool loading)
149 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
152 if(!state_fio->StateCheckInt32(this_device_id)) {
155 state_fio->StateBool(mic);
156 state_fio->StateBool(ear);
157 state_fio->StateBool(pulse);
158 state_fio->StateInt32(pulse_count);
160 state_fio->StateBool(play);
161 state_fio->StateBool(rec);
162 state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
164 int length_tmp = state_fio->FgetInt32_LE();
166 fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
167 while(length_tmp != 0) {
168 uint8_t buffer_tmp[1024];
169 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
170 state_fio->Fread(buffer_tmp, length_rw, 1);
171 if(fio->IsOpened()) {
172 fio->Fwrite(buffer_tmp, length_rw, 1);
174 length_tmp -= length_rw;
178 if(rec && fio->IsOpened()) {
179 int length_tmp = (int)fio->Ftell();
180 fio->Fseek(0, FILEIO_SEEK_SET);
181 state_fio->FputInt32_LE(length_tmp);
182 while(length_tmp != 0) {
183 uint8_t buffer_tmp[1024];
184 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
185 fio->Fread(buffer_tmp, length_rw, 1);
186 state_fio->Fwrite(buffer_tmp, length_rw, 1);
187 length_tmp -= length_rw;
190 state_fio->FputInt32_LE(0);
193 state_fio->StateInt32(bufcnt);
194 state_fio->StateBuffer(buffer, sizeof(buffer), 1);