mirror of
https://github.com/jscrane/Apple1.git
synced 2024-06-10 05:29:27 +00:00
61 lines
961 B
C++
61 lines
961 B
C++
#include <Arduino.h>
|
|
#include <memory.h>
|
|
#include "pia.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();
|
|
}
|