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 bool SUB::process_state(FILEIO* state_fio, bool loading)
392 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
395 if(!state_fio->StateCheckInt32(this_device_id)) {
398 state_fio->StateInt32(p1_out);
399 state_fio->StateInt32(p2_in);
400 state_fio->StateBool(drec_in);
401 state_fio->StateBool(rxrdy_in);
402 state_fio->StateBool(update_key);
403 state_fio->StateBool(rec);
404 state_fio->StateBool(is_wav);
405 state_fio->StateBool(is_p6t);
406 state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
408 int length_tmp = state_fio->FgetInt32_LE();
410 fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
411 while(length_tmp != 0) {
412 uint8_t buffer_tmp[1024];
413 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
414 state_fio->Fread(buffer_tmp, length_rw, 1);
415 if(fio->IsOpened()) {
416 fio->Fwrite(buffer_tmp, length_rw, 1);
418 length_tmp -= length_rw;
422 if(rec && fio->IsOpened()) {
423 int length_tmp = (int)fio->Ftell();
424 fio->Fseek(0, FILEIO_SEEK_SET);
425 state_fio->FputInt32_LE(length_tmp);
426 while(length_tmp != 0) {
427 uint8_t buffer_tmp[1024];
428 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
429 fio->Fread(buffer_tmp, length_rw, 1);
430 state_fio->Fwrite(buffer_tmp, length_rw, 1);
431 length_tmp -= length_rw;
434 state_fio->FputInt32_LE(0);
437 state_fio->StateInt32(prev_command);
438 state_fio->StateInt32(baud);
439 state_fio->StateInt32(index);
440 state_fio->StateBool(skip);
441 state_fio->StateBuffer(buffer, sizeof(buffer), 1);