2 NEC PC-6001 Emulator 'yaPC-6001'
3 NEC PC-6001mkII Emulator 'yaPC-6201'
4 NEC PC-6001mkIISR Emulator 'yaPC-6401'
5 NEC PC-6601 Emulator 'yaPC-6601'
6 NEC PC-6601SR Emulator 'yaPC-6801'
8 Author : Takeda.Toshiya
16 #include "../datarec.h"
25 static const uint8_t key_matrix[16][8] = {
26 {0x00, 0x11, 0x10, 0x12, 0x00, 0x00, 0x00, 0x00},
27 {0x31, 0x51, 0x41, 0x5a, 0x4b, 0x49, 0x38, 0xbc},
28 {0x32, 0x57, 0x53, 0x58, 0x4c, 0x4f, 0x39, 0xbe},
29 {0x33, 0x45, 0x44, 0x43, 0xbb, 0x50, 0x70, 0xbf},
30 {0x34, 0x52, 0x46, 0x56, 0xba, 0xc0, 0x71, 0xe2},
31 {0x35, 0x54, 0x47, 0x42, 0xdd, 0xdb, 0x72, 0x20},
32 {0x36, 0x59, 0x48, 0x4e, 0xbd, 0xde, 0x73, 0x30},
33 {0x37, 0x55, 0x4a, 0x4d, 0x00, 0xdc, 0x74, 0x00},
34 {0x0d, 0x13, 0x26, 0x28, 0x27, 0x25, 0x09, 0x1b},
35 {0x15, 0x2d, 0x2e, 0x23, 0x24, 0x00, 0x00, 0x00}, // ROT=END
36 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
37 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
38 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
39 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
40 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
41 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
44 void SUB::initialize()
49 key_stat = emu->get_key_buffer();
52 drec_in = rxrdy_in = false;
55 register_frame_event(this);
70 #define SET_WR(v) d_pio->write_signal(SIG_I8255_PORT_C, (v) ? 0xff : 0, 0x10)
71 #define SET_RD(v) d_pio->write_signal(SIG_I8255_PORT_C, (v) ? 0xff : 0, 0x40)
73 void SUB::write_io8(uint32_t addr, uint32_t data)
75 // FIXME: this function is referred from both 80c48 and z80
76 if((addr & 0xf0) == 0x90) {
78 if((addr & 0xff) == 0x90) {
79 if(prev_command == 0x38) {
80 if(rec && index < sizeof(buffer)) {
81 buffer[index++] = data;
88 // d_drec->write_signal(SIG_DATAREC_REMOTE, 1, 1);
89 register_event(this, EVENT_PLAY, 1000000.0, false, NULL);
92 // d_drec->write_signal(SIG_DATAREC_REMOTE, 0, 0);
93 register_event(this, EVENT_STOP, 1000000.0, false, NULL);
107 d_pio->write_io8(addr, data);
112 if((p1_out & 0x0f) != (data & 0x0f)) {
116 // d_drec->write_signal(SIG_DATAREC_MIC, data, 0x20);
117 d_timer->write_signal(SIG_TIMER_IRQ_SUB_CPU, ~data, 0x80);
123 d_pio->write_signal(SIG_I8255_PORT_A, data, 0xff);
129 uint32_t SUB::read_io8(uint32_t addr)
131 // FIXME: this function is referred from both 80c48 and z80
132 if((addr & 0xf0) == 0x90) {
134 if((addr & 0xff) == 0x90) {
135 return d_pio->read_io8(addr);
144 int column = p1_out & 0x0f;
146 for(int i = 0; i < 8; i++) {
147 if(key_stat[key_matrix[column][i]]) {
151 p2_in = (~val) & 0xff;
157 // bit3: signal from datarec
158 // bit1: rxrdy from rs-232c
159 return (rxrdy_in ? 2 : 0) | (drec_in ? 8 : 0) | (p2_in & 0xf0);
163 return (d_pio->read_signal(SIG_I8255_PORT_C) >> 5) & 1;
168 return d_pio->read_signal(SIG_I8255_PORT_A);
174 uint32_t SUB::get_intr_ack()
176 return d_pio->read_io8(0);
179 void SUB::event_frame()
182 request_skip_frames();
188 void SUB::event_callback(int event_id, int err)
190 if(event_id == EVENT_PLAY) {
191 d_drec->write_signal(SIG_DATAREC_REMOTE, 1, 1);
192 } else if(event_id == EVENT_STOP) {
193 d_drec->write_signal(SIG_DATAREC_REMOTE, 0, 0);
197 void SUB::write_signal(int id, uint32_t data, uint32_t mask)
199 if(id == SIG_SUB_DATAREC) {
200 drec_in = ((data & mask) != 0);
201 } else if(id == SIG_SUB_RXRDY) {
202 rxrdy_in = ((data & mask) != 0);
206 bool SUB::rec_tape(const _TCHAR* file_path)
210 if(fio->Fopen(file_path, FILEIO_READ_WRITE_NEW_BINARY)) {
211 my_tcscpy_s(rec_file_path, _MAX_PATH, file_path);
214 is_wav = check_file_extension(file_path, _T(".wav"));
215 is_p6t = check_file_extension(file_path, _T(".p6t"));
220 static const uint8_t pulse_1200hz[40] = {
221 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
222 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
223 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
224 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
227 static const uint8_t pulse_2400hz[20] = {
228 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
229 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
232 static const uint8_t pulse_2400hz_x2[40] = {
233 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
234 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
235 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
236 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
239 void SUB::close_tape()
241 if(fio->IsOpened()) {
244 wav_header_t wav_header;
245 wav_chunk_t wav_chunk;
246 int sample_rate = (baud == 600) ? 24000 : 48000;
248 fio->Fwrite(&wav_header, sizeof(wav_header), 1);
249 fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
251 for(int i = 0; i < 9600; i++) {
252 fio->Fwrite((void *)pulse_2400hz, sizeof(pulse_2400hz), 1);
254 for(int i = 0; i < 16; i++) {
255 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
256 for(int j = 0; j < 8; j++) {
257 if(buffer[i] & (1 << j)) {
258 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
260 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
263 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
264 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
265 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
267 // for(int i = 0; i < 1280; i++) {
268 for(int i = 0; i < 2400; i++) {
269 fio->Fwrite((void *)pulse_2400hz, sizeof(pulse_2400hz), 1);
271 for(int i = 16; i < index; i++) {
272 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
273 for(int j = 0; j < 8; j++) {
274 if(buffer[i] & (1 << j)) {
275 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
277 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
280 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
281 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
282 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
285 for(int i = 0; i < 16; i++) {
286 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
287 for(int j = 0; j < 8; j++) {
288 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
290 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
291 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
292 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
295 uint32_t length = fio->Ftell();
297 pair_t __riff_chunk_size;
298 pair_t __fmt_chunk_size;
299 pair_t __wav_chunk_size;
302 pair_t __sample_rate;
303 pair16_t __block_size;
304 pair16_t __sample_bits;
306 __riff_chunk_size.d = length - 8;
307 __fmt_chunk_size.d = 16;
310 __sample_rate.d = sample_rate;
314 memcpy(wav_header.riff_chunk.id, "RIFF", 4);
315 wav_header.riff_chunk.size = __riff_chunk_size.get_4bytes_le_to();
317 memcpy(wav_header.wave, "WAVE", 4);
318 memcpy(wav_header.fmt_chunk.id, "fmt ", 4);
319 wav_header.fmt_chunk.size = __riff_chunk_size.get_4bytes_le_to();
320 wav_header.format_id = __fmt_id.get_2bytes_le_to();
321 wav_header.channels = __channels.get_2byte_le_to();
322 wav_header.sample_rate = __sample_rate.get_4bytes_le_to();
323 wav_header.data_speed = __sample_rate.get_4bytes_le_to();
324 wav_header.block_size = __block_size.get_2bytes_le_to();
325 wav_header.sample_bits = __sample_bits_get_2bytes_le_to();
327 memcpy(wav_chunk.id, "data", 4);
328 __wav_chunk_size.d = length - sizeof(wav_header) - sizeof(wav_chunk);
329 wav_chunk.size = __wav_chunk_size.get_4bytes_le_to();
331 fio->Fseek(0, FILEIO_SEEK_SET);
332 fio->Fwrite(&wav_header, sizeof(wav_header), 1);
333 fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
335 if(set_wav_header(&wav_header, &wav_chunk, 1, sample_rate, 8, length)) {
336 fio->Fseek(0, FILEIO_SEEK_SET);
337 fio->Fwrite(&wav_header, sizeof(wav_header), 1);
338 fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
342 fio->Fwrite(buffer, index, 1);
357 for(int i = 0; i < 6; i++) {
358 fio->FputUint8(buffer[10 + i]);
360 for(int i = 6; i < 16; i++) {
363 fio->FputUint16(baud);
364 fio->FputUint16(3000);
365 fio->FputUint16(4000);
372 for(int i = 0; i < 16; i++) {
375 fio->FputUint16(baud);
377 fio->FputUint16(1000);
379 fio->FputUint32(index - 16);
381 fio->FputUint32(index);
390 #define STATE_VERSION 1
392 bool SUB::process_state(FILEIO* state_fio, bool loading)
394 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
397 if(!state_fio->StateCheckInt32(this_device_id)) {
400 state_fio->StateInt32(p1_out);
401 state_fio->StateInt32(p2_in);
402 state_fio->StateBool(drec_in);
403 state_fio->StateBool(rxrdy_in);
404 state_fio->StateBool(update_key);
405 state_fio->StateBool(rec);
406 state_fio->StateBool(is_wav);
407 state_fio->StateBool(is_p6t);
408 state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
410 int length_tmp = state_fio->FgetInt32_LE();
412 fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
413 while(length_tmp != 0) {
414 uint8_t buffer_tmp[1024];
415 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
416 state_fio->Fread(buffer_tmp, length_rw, 1);
417 if(fio->IsOpened()) {
418 fio->Fwrite(buffer_tmp, length_rw, 1);
420 length_tmp -= length_rw;
424 if(rec && fio->IsOpened()) {
425 int length_tmp = (int)fio->Ftell();
426 fio->Fseek(0, FILEIO_SEEK_SET);
427 state_fio->FputInt32_LE(length_tmp);
428 while(length_tmp != 0) {
429 uint8_t buffer_tmp[1024];
430 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
431 fio->Fread(buffer_tmp, length_rw, 1);
432 state_fio->Fwrite(buffer_tmp, length_rw, 1);
433 length_tmp -= length_rw;
436 state_fio->FputInt32_LE(0);
439 state_fio->StateInt32(prev_command);
440 state_fio->StateInt32(baud);
441 state_fio->StateInt32(index);
442 state_fio->StateBool(skip);
443 state_fio->StateBuffer(buffer, sizeof(buffer), 1);