mirror of
https://github.com/jscrane/Apple1.git
synced 2024-06-09 13:29:32 +00:00
64 lines
1.1 KiB
C++
64 lines
1.1 KiB
C++
#include <Arduino.h>
|
|
#include <memory.h>
|
|
#include "pia.h"
|
|
|
|
// see: https://github.com/mamedev/mame/blob/master/src/devices/machine/6821pia.cpp
|
|
// and: https://github.com/mamedev/mame/blob/master/src/devices/machine/6821pia.h
|
|
|
|
void PIA::write(Memory::address a, uint8_t b) {
|
|
#if defined(DEBUGGING)
|
|
Serial.print(millis());
|
|
Serial.print(" > ");
|
|
Serial.print(a, 16);
|
|
Serial.print(' ');
|
|
Serial.println(b, 16);
|
|
#endif
|
|
switch(a % 4) {
|
|
case 0:
|
|
write_porta(b);
|
|
break;
|
|
case 1:
|
|
write_porta_cr(b);
|
|
break;
|
|
case 2:
|
|
write_portb(b);
|
|
break;
|
|
case 3:
|
|
write_portb_cr(b);
|
|
break;
|
|
}
|
|
}
|
|
|
|
uint8_t PIA::read(Memory::address a) {
|
|
#if defined(DEBUGGING)
|
|
Serial.print(millis());
|
|
Serial.print(" < ");
|
|
Serial.println(a, 16);
|
|
#endif
|
|
switch (a % 4) {
|
|
case 0:
|
|
return read_porta();
|
|
case 1:
|
|
return read_porta_cr();
|
|
case 2:
|
|
return read_portb();
|
|
case 3:
|
|
return read_portb_cr();
|
|
}
|
|
return 0xff;
|
|
}
|
|
|
|
void PIA::checkpoint(Stream &s) {
|
|
s.write(portb_cr);
|
|
s.write(portb);
|
|
s.write(porta_cr);
|
|
s.write(porta);
|
|
}
|
|
|
|
void PIA::restore(Stream &s) {
|
|
portb_cr = s.read();
|
|
portb = s.read();
|
|
porta_cr = s.read();
|
|
porta = s.read();
|
|
}
|