Apple1-esp/pia.cpp

62 lines
946 B
C++
Raw Normal View History

2018-11-16 08:03:43 +00:00
#include <Arduino.h>
2014-11-17 20:00:40 +00:00
#include <memory.h>
#include "pia.h"
2018-08-14 10:00:03 +00:00
void pia::operator=(uint8_t b) {
2018-11-12 22:15:16 +00:00
#if defined(DEBUGGING)
Serial.print(millis());
Serial.print(" > ");
Serial.print(_acc, 16);
Serial.print(' ');
Serial.println(b, 16);
#endif
2014-11-17 20:00:40 +00:00
switch(_acc % 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;
}
}
2018-08-14 10:00:03 +00:00
pia::operator uint8_t() {
2018-11-12 22:15:16 +00:00
#if defined(DEBUGGING)
Serial.print(millis());
Serial.print(" < ");
Serial.println(_acc, 16);
#endif
2014-11-17 20:00:40 +00:00
switch (_acc % 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();
}