move Apple1-dependent bits onto io class
This commit is contained in:
parent
ee452e816e
commit
ba05ac5d74
23
io.cpp
23
io.cpp
|
@ -78,13 +78,14 @@ static const uint8_t shiftmap[] PROGMEM = {
|
|||
};
|
||||
|
||||
void io::down(uint8_t scan) {
|
||||
set_porta(0);
|
||||
PIA::write_porta(0);
|
||||
if (isshift(scan))
|
||||
_shift = true;
|
||||
}
|
||||
|
||||
void io::enter(uint8_t key) {
|
||||
set_porta(key + 0x80);
|
||||
PIA::write_porta(key + 0x80);
|
||||
PIA::write_porta_cr(0xa7);
|
||||
}
|
||||
|
||||
void io::up(uint8_t scan) {
|
||||
|
@ -145,8 +146,17 @@ void io::write_portb(uint8_t b) {
|
|||
PIA::write_portb(b);
|
||||
}
|
||||
|
||||
void io::write_portb_cr(uint8_t b) {
|
||||
if (PIA::read_portb_cr() < 0x80)
|
||||
PIA::write_portb_cr(b);
|
||||
}
|
||||
|
||||
uint8_t io::read_porta_cr() {
|
||||
uint8_t b = PIA::read_porta_cr();
|
||||
if (b & 0x80) {
|
||||
PIA::write_porta_cr(0);
|
||||
b = 0xa7;
|
||||
}
|
||||
if (b != 0xa7)
|
||||
return b;
|
||||
|
||||
|
@ -159,6 +169,15 @@ uint8_t io::read_porta_cr() {
|
|||
return b;
|
||||
}
|
||||
|
||||
void io::write_porta_cr(uint8_t b) {
|
||||
uint8_t cr = PIA::read_porta_cr();
|
||||
if (!(cr & 0x80) && b >= 0x80)
|
||||
cr |= 0x80;
|
||||
else
|
||||
cr = b;
|
||||
PIA::write_porta_cr(cr);
|
||||
}
|
||||
|
||||
void io::checkpoint(Stream &s) {
|
||||
PIA::checkpoint(s);
|
||||
s.write(r);
|
||||
|
|
2
io.h
2
io.h
|
@ -16,7 +16,9 @@ public:
|
|||
virtual void restore(Stream &);
|
||||
|
||||
virtual void write_portb(uint8_t);
|
||||
virtual void write_portb_cr(uint8_t);
|
||||
virtual uint8_t read_porta_cr();
|
||||
virtual void write_porta_cr(uint8_t);
|
||||
|
||||
void load();
|
||||
filer &files;
|
||||
|
|
3
pia.cpp
3
pia.cpp
|
@ -2,6 +2,9 @@
|
|||
#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());
|
||||
|
|
39
pia.h
39
pia.h
|
@ -4,8 +4,8 @@
|
|||
// https://en.wikipedia.org/wiki/Peripheral_Interface_Adapter
|
||||
class PIA {
|
||||
public:
|
||||
PIA(): portb_cr(0), porta_cr(0) {}
|
||||
virtual void reset() { portb_cr = porta_cr = 0; }
|
||||
PIA(): portb(0), portb_cr(0), porta(0), porta_cr(0) {}
|
||||
virtual void reset() { portb = portb_cr = porta = porta_cr = 0; }
|
||||
|
||||
void write(Memory::address, uint8_t);
|
||||
uint8_t read(Memory::address);
|
||||
|
@ -14,37 +14,16 @@ public:
|
|||
void restore(Stream &);
|
||||
|
||||
protected:
|
||||
// write to the "external" side of the port
|
||||
void set_porta(uint8_t b) {
|
||||
porta = b;
|
||||
if (b & 0x80)
|
||||
porta_cr = 0xa7;
|
||||
}
|
||||
|
||||
// "device-side" operations (called from memory interface)
|
||||
uint8_t read_porta() { return porta; }
|
||||
virtual uint8_t read_porta_cr() {
|
||||
if (porta_cr & 0x80) {
|
||||
porta_cr = 0;
|
||||
return 0xa7;
|
||||
}
|
||||
return porta_cr;
|
||||
}
|
||||
uint8_t read_portb() { return portb; }
|
||||
uint8_t read_portb_cr() { return portb_cr; }
|
||||
virtual uint8_t read_porta() { return porta; }
|
||||
virtual uint8_t read_porta_cr() { return porta_cr; }
|
||||
virtual uint8_t read_portb() { return portb; }
|
||||
virtual uint8_t read_portb_cr() { return portb_cr; }
|
||||
|
||||
void write_porta(uint8_t b) { porta = b; }
|
||||
void write_porta_cr(uint8_t b) {
|
||||
if (!(porta_cr & 0x80) && b >= 0x80)
|
||||
porta_cr |= 0x80;
|
||||
else
|
||||
porta_cr = b;
|
||||
}
|
||||
virtual void write_porta(uint8_t b) { porta = b; }
|
||||
virtual void write_porta_cr(uint8_t b) { porta_cr = b; }
|
||||
virtual void write_portb(uint8_t b) { portb = b; }
|
||||
void write_portb_cr(uint8_t b) {
|
||||
if (portb_cr < 0x80)
|
||||
portb_cr = b;
|
||||
}
|
||||
virtual void write_portb_cr(uint8_t b) { portb_cr = b; }
|
||||
|
||||
private:
|
||||
uint8_t portb_cr, portb, porta_cr, porta;
|
||||
|
|
Loading…
Reference in New Issue