2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
12 /* note: ca2/cb2 output signals are not implemented */
16 for(int i = 0; i < 2; i++) {
19 port[i].c1 = port[i].c2 = false;
24 void MC6820::write_io8(uint32_t addr, uint32_t data)
26 int ch = (addr & 2) >> 1;
31 if(port[ch].ctrl & 4) {
32 if(port[ch].wreg != data || port[ch].first) {
33 write_signals(&port[ch].outputs, data);
35 port[ch].first = false;
44 port[ch].ctrl &= ~0x40;
46 port[ch].ctrl = (port[ch].ctrl & 0xc0) | (data & 0x3f);
51 uint32_t MC6820::read_io8(uint32_t addr)
53 int ch = (addr & 2) >> 1;
58 if(port[ch].ctrl & 4) {
59 write_signals(&port[ch].outputs_irq, 0);
60 port[ch].ctrl &= ~0xc0;
61 return (port[ch].rreg & ~port[ch].ddr) | (port[ch].wreg & port[ch].ddr);
72 void MC6820::write_signal(int id, uint32_t data, uint32_t mask)
74 bool signal = ((data & mask) != 0);
78 case SIG_MC6820_PORT_A:
79 case SIG_MC6820_PORT_B:
80 port[ch].rreg = (port[ch].rreg & ~mask) | (data & mask);
84 if(((port[ch].ctrl & 2) && !port[ch].c1 && signal) || (!(port[ch].ctrl & 2) && port[ch].c1 && !signal)) {
85 if(port[ch].ctrl & 1) {
86 write_signals(&port[ch].outputs_irq, 0xffffffff);
88 port[ch].ctrl |= 0x80;
94 if(port[ch].ctrl & 0x20) {
98 if(((port[ch].ctrl & 0x10) && !port[ch].c2 && signal) || (!(port[ch].ctrl & 0x10) && port[ch].c2 && !signal)) {
99 if(port[ch].ctrl & 8) {
100 write_signals(&port[ch].outputs_irq, 0xffffffff);
102 port[ch].ctrl |= 0x40;
104 port[ch].c2 = signal;
109 #define STATE_VERSION 1
111 bool MC6820::process_state(FILEIO* state_fio, bool loading)
113 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
116 if(!state_fio->StateCheckInt32(this_device_id)) {
119 for(int i = 0; i < 2; i++) {
120 state_fio->StateValue(port[i].wreg);
121 state_fio->StateValue(port[i].rreg);
122 state_fio->StateValue(port[i].ctrl);
123 state_fio->StateValue(port[i].ddr);
124 state_fio->StateValue(port[i].c1);
125 state_fio->StateValue(port[i].c2);
126 state_fio->StateValue(port[i].first);