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
18 #include "../../fileio.h"
22 void TIMER::initialize()
24 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
25 memset(sr_vectors, 0, sizeof(sr_vectors));
39 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
50 void TIMER::write_io8(uint32 addr, uint32 data)
53 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
62 sr_vectors[addr & 7] = data;
67 // d_mem->set_portF3(data);
81 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
92 uint32 TIMER::read_io8(uint32 addr)
95 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
104 return sr_vectors[addr & 7];
116 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
127 void TIMER::event_callback(int event_id, int err)
129 if(event_id == EVENT_TIMER) {
130 write_signal(SIG_TIMER_IRQ_TIMER, 1, 1);
132 // register next event
134 register_event(this, EVENT_TIMER, 2000.0, false, &timer_id);
136 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
138 register_event(this, EVENT_TIMER, 2000.0 * (portF6 + 1) / 0x80, false, &timer_id);
141 register_event(this, EVENT_TIMER, 2000.0 * (portF6 + 1) / 4, false, &timer_id);
146 void TIMER::set_portB0(uint32 data)
151 cancel_event(this, timer_id);
158 // first period is 1msec
159 register_event(this, EVENT_TIMER, 1000.0, false, &timer_id);
161 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
163 register_event(this, EVENT_TIMER, 2000.0 * (portF6 + 1) / 0x80, false, &timer_id);
166 register_event(this, EVENT_TIMER, 2000.0 * (portF6 + 1) / 4, false, &timer_id);
172 void TIMER::write_signal(int id, uint32 data, uint32 mask)
182 uint32 TIMER::intr_ack()
184 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
186 for(int i = 0, bit = 1; i < 8; i++, bit <<= 1) {
190 return sr_vectors[i];
197 if(NewIRQ & 0x01) { // Sub-CPU
204 return d_sub->intr_ack();
207 else if(NewIRQ & 0x02) { // Joystick
215 else if(NewIRQ & 0x04) { // Timer
224 else if(NewIRQ & 0x08) { // Voice
228 else if(NewIRQ & 0x10) { // VRTC
232 else if(NewIRQ & 0x20) { // RS-232C
236 else if(NewIRQ & 0x40) { // Printer
240 else if(NewIRQ & 0x80) { // Ext Int
245 return 0x06; // dummy
248 void TIMER::intr_reti()
253 void TIMER::update_intr()
257 NewIRQ &= 0x05; // Only Sub-CPU and Timer
259 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
277 d_cpu->write_signal(SIG_CPU_IRQ, 1, 1);
279 // d_cpu->write_signal(SIG_CPU_IRQ, 0, 1);
283 #define STATE_VERSION 1
285 void TIMER::save_state(FILEIO* state_fio)
287 state_fio->FputUint32(STATE_VERSION);
288 state_fio->FputInt32(this_device_id);
290 state_fio->FputUint8(IRQ);
291 state_fio->FputUint8(NewIRQ);
292 state_fio->FputInt32(timer_id);
294 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
295 state_fio->Fwrite(sr_vectors, sizeof(sr_vectors), 1);
296 state_fio->FputUint8(portFA);
297 state_fio->FputUint8(portFB);
299 state_fio->FputUint8(portF3);
300 state_fio->FputUint8(portF4);
301 state_fio->FputUint8(portF5);
302 state_fio->FputUint8(portF6);
303 state_fio->FputUint8(portF7);
307 bool TIMER::load_state(FILEIO* state_fio)
309 if(state_fio->FgetUint32() != STATE_VERSION) {
312 if(state_fio->FgetInt32() != this_device_id) {
315 IRQ = state_fio->FgetUint8();
316 NewIRQ = state_fio->FgetUint8();
317 timer_id = state_fio->FgetInt32();
319 #if defined(_PC6601SR) || defined(_PC6001MK2SR)
320 state_fio->Fread(sr_vectors, sizeof(sr_vectors), 1);
321 portFA = state_fio->FgetUint8();
322 portFB = state_fio->FgetUint8();
324 portF3 = state_fio->FgetUint8();
325 portF4 = state_fio->FgetUint8();
326 portF5 = state_fio->FgetUint8();
327 portF6 = state_fio->FgetUint8();
328 portF7 = state_fio->FgetUint8();