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"
23 static const uint8_t key_matrix[16][8] = {
24 {0x00, 0x11, 0x10, 0x12, 0x00, 0x00, 0x00, 0x00},
25 {0x31, 0x51, 0x41, 0x5a, 0x4b, 0x49, 0x38, 0xbc},
26 {0x32, 0x57, 0x53, 0x58, 0x4c, 0x4f, 0x39, 0xbe},
27 {0x33, 0x45, 0x44, 0x43, 0xbb, 0x50, 0x70, 0xbf},
28 {0x34, 0x52, 0x46, 0x56, 0xba, 0xc0, 0x71, 0xe2},
29 {0x35, 0x54, 0x47, 0x42, 0xdd, 0xdb, 0x72, 0x20},
30 {0x36, 0x59, 0x48, 0x4e, 0xbd, 0xde, 0x73, 0x30},
31 {0x37, 0x55, 0x4a, 0x4d, 0x00, 0xdc, 0x74, 0x00},
32 {0x0d, 0x13, 0x26, 0x28, 0x27, 0x25, 0x09, 0x1b},
33 {0x15, 0x2d, 0x2e, 0x23, 0x24, 0x00, 0x00, 0x00}, // ROT=END
34 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
35 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
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},
42 void SUB::initialize()
47 key_stat = emu->get_key_buffer();
50 drec_in = rxrdy_in = false;
53 register_frame_event(this);
68 #define SET_WR(v) d_pio->write_signal(SIG_I8255_PORT_C, (v) ? 0xff : 0, 0x10)
69 #define SET_RD(v) d_pio->write_signal(SIG_I8255_PORT_C, (v) ? 0xff : 0, 0x40)
71 void SUB::write_io8(uint32_t addr, uint32_t data)
73 // FIXME: this function is referred from both 80c48 and z80
74 if((addr & 0xf0) == 0x90) {
76 if((addr & 0xff) == 0x90) {
77 if(prev_command == 0x38) {
78 if(rec && index < sizeof(buffer)) {
79 buffer[index++] = data;
86 // d_drec->write_signal(SIG_DATAREC_REMOTE, 1, 1);
87 register_event(this, EVENT_PLAY, 1000000.0, false, NULL);
90 // d_drec->write_signal(SIG_DATAREC_REMOTE, 0, 0);
91 register_event(this, EVENT_STOP, 1000000.0, false, NULL);
105 d_pio->write_io8(addr, data);
110 if((p1_out & 0x0f) != (data & 0x0f)) {
114 // d_drec->write_signal(SIG_DATAREC_MIC, data, 0x20);
115 d_timer->write_signal(SIG_TIMER_IRQ_SUB_CPU, ~data, 0x80);
121 d_pio->write_signal(SIG_I8255_PORT_A, data, 0xff);
127 uint32_t SUB::read_io8(uint32_t addr)
129 // FIXME: this function is referred from both 80c48 and z80
130 if((addr & 0xf0) == 0x90) {
132 if((addr & 0xff) == 0x90) {
133 return d_pio->read_io8(addr);
142 int column = p1_out & 0x0f;
144 for(int i = 0; i < 8; i++) {
145 if(key_stat[key_matrix[column][i]]) {
149 p2_in = (~val) & 0xff;
155 // bit3: signal from datarec
156 // bit1: rxrdy from rs-232c
157 return (rxrdy_in ? 2 : 0) | (drec_in ? 8 : 0) | (p2_in & 0xf0);
161 return (d_pio->read_signal(SIG_I8255_PORT_C) >> 5) & 1;
166 return d_pio->read_signal(SIG_I8255_PORT_A);
172 uint32_t SUB::get_intr_ack()
174 return d_pio->read_io8(0);
177 void SUB::event_frame()
180 request_skip_frames();
186 void SUB::event_callback(int event_id, int err)
188 if(event_id == EVENT_PLAY) {
189 d_drec->write_signal(SIG_DATAREC_REMOTE, 1, 1);
190 } else if(event_id == EVENT_STOP) {
191 d_drec->write_signal(SIG_DATAREC_REMOTE, 0, 0);
195 void SUB::write_signal(int id, uint32_t data, uint32_t mask)
197 if(id == SIG_SUB_DATAREC) {
198 drec_in = ((data & mask) != 0);
199 } else if(id == SIG_SUB_RXRDY) {
200 rxrdy_in = ((data & mask) != 0);
204 bool SUB::rec_tape(const _TCHAR* file_path)
208 if(fio->Fopen(file_path, FILEIO_READ_WRITE_NEW_BINARY)) {
209 my_tcscpy_s(rec_file_path, _MAX_PATH, file_path);
212 is_wav = check_file_extension(file_path, _T(".wav"));
213 is_p6t = check_file_extension(file_path, _T(".p6t"));
218 static const uint8_t pulse_1200hz[40] = {
219 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
220 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
221 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
222 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
225 static const uint8_t pulse_2400hz[20] = {
226 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
227 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
230 static const uint8_t pulse_2400hz_x2[40] = {
231 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
232 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
233 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
234 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
237 void SUB::close_tape()
239 if(fio->IsOpened()) {
242 wav_header_t wav_header;
243 wav_chunk_t wav_chunk;
244 int sample_rate = (baud == 600) ? 24000 : 48000;
246 fio->Fwrite(&wav_header, sizeof(wav_header), 1);
247 fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
249 for(int i = 0; i < 9600; i++) {
250 fio->Fwrite((void *)pulse_2400hz, sizeof(pulse_2400hz), 1);
252 for(int i = 0; i < 16; i++) {
253 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
254 for(int j = 0; j < 8; j++) {
255 if(buffer[i] & (1 << j)) {
256 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
258 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
261 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
262 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
263 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
265 // for(int i = 0; i < 1280; i++) {
266 for(int i = 0; i < 2400; i++) {
267 fio->Fwrite((void *)pulse_2400hz, sizeof(pulse_2400hz), 1);
269 for(int i = 16; i < index; i++) {
270 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
271 for(int j = 0; j < 8; j++) {
272 if(buffer[i] & (1 << j)) {
273 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
275 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
278 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
279 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
280 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
283 for(int i = 0; i < 16; i++) {
284 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
285 for(int j = 0; j < 8; j++) {
286 fio->Fwrite((void *)pulse_1200hz, sizeof(pulse_1200hz), 1);
288 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
289 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
290 fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
293 uint32_t length = fio->Ftell();
295 pair_t __riff_chunk_size;
296 pair_t __fmt_chunk_size;
297 pair_t __wav_chunk_size;
300 pair_t __sample_rate;
301 pair16_t __block_size;
302 pair16_t __sample_bits;
304 __riff_chunk_size.d = length - 8;
305 __fmt_chunk_size.d = 16;
308 __sample_rate.d = sample_rate;
312 memcpy(wav_header.riff_chunk.id, "RIFF", 4);
313 wav_header.riff_chunk.size = __riff_chunk_size.get_4bytes_le_to();
315 memcpy(wav_header.wave, "WAVE", 4);
316 memcpy(wav_header.fmt_chunk.id, "fmt ", 4);
317 wav_header.fmt_chunk.size = __riff_chunk_size.get_4bytes_le_to();
318 wav_header.format_id = __fmt_id.get_2bytes_le_to();
319 wav_header.channels = __channels.get_2byte_le_to();
320 wav_header.sample_rate = __sample_rate.get_4bytes_le_to();
321 wav_header.data_speed = __sample_rate.get_4bytes_le_to();
322 wav_header.block_size = __block_size.get_2bytes_le_to();
323 wav_header.sample_bits = __sample_bits_get_2bytes_le_to();
325 memcpy(wav_chunk.id, "data", 4);
326 __wav_chunk_size.d = length - sizeof(wav_header) - sizeof(wav_chunk);
327 wav_chunk.size = __wav_chunk_size.get_4bytes_le_to();
329 fio->Fseek(0, FILEIO_SEEK_SET);
330 fio->Fwrite(&wav_header, sizeof(wav_header), 1);
331 fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
333 if(set_wav_header(&wav_header, &wav_chunk, 1, sample_rate, 8, length)) {
334 fio->Fseek(0, FILEIO_SEEK_SET);
335 fio->Fwrite(&wav_header, sizeof(wav_header), 1);
336 fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
340 fio->Fwrite(buffer, index, 1);
355 for(int i = 0; i < 6; i++) {
356 fio->FputUint8(buffer[10 + i]);
358 for(int i = 6; i < 16; i++) {
361 fio->FputUint16(baud);
362 fio->FputUint16(3000);
363 fio->FputUint16(4000);
370 for(int i = 0; i < 16; i++) {
373 fio->FputUint16(baud);
375 fio->FputUint16(1000);
377 fio->FputUint32(index - 16);
379 fio->FputUint32(index);
388 #define STATE_VERSION 1
390 #include "../../statesub.h"
392 void SUB::decl_state()
394 enter_decl_state(STATE_VERSION);
396 DECL_STATE_ENTRY_INT32(p1_out);
397 DECL_STATE_ENTRY_INT32(p2_in);
398 DECL_STATE_ENTRY_BOOL(drec_in);
399 DECL_STATE_ENTRY_BOOL(rxrdy_in);
400 DECL_STATE_ENTRY_BOOL(update_key);
401 DECL_STATE_ENTRY_BOOL(rec);
402 DECL_STATE_ENTRY_BOOL(is_wav);
403 DECL_STATE_ENTRY_BOOL(is_p6t);
404 DECL_STATE_ENTRY_STRING(rec_file_path, sizeof(rec_file_path));
405 DECL_STATE_ENTRY_CMT_RECORDING(fio, rec, rec_file_path);
406 DECL_STATE_ENTRY_INT32(prev_command);
407 DECL_STATE_ENTRY_INT32(baud);
408 DECL_STATE_ENTRY_INT32(index);
409 DECL_STATE_ENTRY_BOOL(skip);
410 DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
415 void SUB::save_state(FILEIO* state_fio)
417 if(state_entry != NULL) {
418 state_entry->save_state(state_fio);
420 // state_fio->FputUint32(STATE_VERSION);
421 // state_fio->FputInt32(this_device_id);
423 // state_fio->FputInt32(p1_out);
424 // state_fio->FputInt32(p2_in);
425 // state_fio->FputBool(drec_in);
426 // state_fio->FputBool(rxrdy_in);
427 // state_fio->FputBool(update_key);
428 // state_fio->FputBool(rec);
429 // state_fio->FputBool(is_wav);
430 // state_fio->FputBool(is_p6t);
431 // state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
432 // if(rec && fio->IsOpened()) {
433 // int length_tmp = (int)fio->Ftell();
434 // fio->Fseek(0, FILEIO_SEEK_SET);
435 // state_fio->FputInt32(length_tmp);
436 // while(length_tmp != 0) {
437 // uint8_t buffer_tmp[1024];
438 // int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
439 // fio->Fread(buffer_tmp, length_rw, 1);
440 // state_fio->Fwrite(buffer_tmp, length_rw, 1);
441 // length_tmp -= length_rw;
444 // state_fio->FputInt32(0);
446 // state_fio->FputInt32(prev_command);
447 // state_fio->FputInt32(baud);
448 // state_fio->FputInt32(index);
449 // state_fio->FputBool(skip);
450 // state_fio->Fwrite(buffer, sizeof(buffer), 1);
453 bool SUB::load_state(FILEIO* state_fio)
458 if(state_entry != NULL) {
459 mb = state_entry->load_state(state_fio);
464 // if(state_fio->FgetUint32() != STATE_VERSION) {
467 // if(state_fio->FgetInt32() != this_device_id) {
470 // p1_out = state_fio->FgetInt32();
471 // p2_in = state_fio->FgetInt32();
472 // drec_in = state_fio->FgetBool();
473 // rxrdy_in = state_fio->FgetBool();
474 // update_key = state_fio->FgetBool();
475 // rec = state_fio->FgetBool();
476 // is_wav = state_fio->FgetBool();
477 // is_p6t = state_fio->FgetBool();
478 // state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
479 // int length_tmp = state_fio->FgetInt32();
481 // fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
482 // while(length_tmp != 0) {
483 // uint8_t buffer_tmp[1024];
484 // int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
485 // state_fio->Fread(buffer_tmp, length_rw, 1);
486 // if(fio->IsOpened()) {
487 // fio->Fwrite(buffer_tmp, length_rw, 1);
489 // length_tmp -= length_rw;
492 // prev_command = state_fio->FgetInt32();
493 // baud = state_fio->FgetInt32();
494 // index = state_fio->FgetInt32();
495 // skip = state_fio->FgetBool();
496 // state_fio->Fread(buffer, sizeof(buffer), 1);
500 bool SUB::process_state(FILEIO* state_fio, bool loading)
502 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
505 if(!state_fio->StateCheckInt32(this_device_id)) {
508 state_fio->StateInt32(p1_out);
509 state_fio->StateInt32(p2_in);
510 state_fio->StateBool(drec_in);
511 state_fio->StateBool(rxrdy_in);
512 state_fio->StateBool(update_key);
513 state_fio->StateBool(rec);
514 state_fio->StateBool(is_wav);
515 state_fio->StateBool(is_p6t);
516 state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
518 int length_tmp = state_fio->FgetInt32_LE();
520 fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
521 while(length_tmp != 0) {
522 uint8_t buffer_tmp[1024];
523 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
524 state_fio->Fread(buffer_tmp, length_rw, 1);
525 if(fio->IsOpened()) {
526 fio->Fwrite(buffer_tmp, length_rw, 1);
528 length_tmp -= length_rw;
532 if(rec && fio->IsOpened()) {
533 int length_tmp = (int)fio->Ftell();
534 fio->Fseek(0, FILEIO_SEEK_SET);
535 state_fio->FputInt32_LE(length_tmp);
536 while(length_tmp != 0) {
537 uint8_t buffer_tmp[1024];
538 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
539 fio->Fread(buffer_tmp, length_rw, 1);
540 state_fio->Fwrite(buffer_tmp, length_rw, 1);
541 length_tmp -= length_rw;
544 state_fio->FputInt32_LE(0);
547 state_fio->StateInt32(prev_command);
548 state_fio->StateInt32(baud);
549 state_fio->StateInt32(index);
550 state_fio->StateBool(skip);
551 state_fio->StateBuffer(buffer, sizeof(buffer), 1);