PIA cleanup

This commit is contained in:
steve 2023-09-26 10:41:35 +01:00
parent c129e717d8
commit ee452e816e
4 changed files with 23 additions and 21 deletions

10
io.cpp
View File

@ -28,7 +28,7 @@ void io::reset() {
screen[j][i] = ' '; screen[j][i] = ' ';
_loading = false; _loading = false;
pia::reset(); PIA::reset();
} }
void io::load() { void io::load() {
@ -142,11 +142,11 @@ void io::display(uint8_t b) {
void io::write_portb(uint8_t b) { void io::write_portb(uint8_t b) {
b &= 0x7f; b &= 0x7f;
display(b); display(b);
pia::write_portb(b); PIA::write_portb(b);
} }
uint8_t io::read_porta_cr() { uint8_t io::read_porta_cr() {
uint8_t b = pia::read_porta_cr(); uint8_t b = PIA::read_porta_cr();
if (b != 0xa7) if (b != 0xa7)
return b; return b;
@ -160,7 +160,7 @@ uint8_t io::read_porta_cr() {
} }
void io::checkpoint(Stream &s) { void io::checkpoint(Stream &s) {
pia::checkpoint(s); PIA::checkpoint(s);
s.write(r); s.write(r);
s.write(c); s.write(c);
for (int j = 0; j < ROWS; j++) for (int j = 0; j < ROWS; j++)
@ -169,7 +169,7 @@ void io::checkpoint(Stream &s) {
} }
void io::restore(Stream &s) { void io::restore(Stream &s) {
pia::restore(s); PIA::restore(s);
r = s.read(); r = s.read();
c = s.read(); c = s.read();
for (int j = 0; j < ROWS; j++) for (int j = 0; j < ROWS; j++)

8
io.h
View File

@ -1,15 +1,17 @@
#ifndef _IO_H #ifndef _IO_H
#define _IO_H #define _IO_H
// http://mamedev.org/source/src/mess/machine/apple1.c.html class io: public Memory::Device, public Display, Keyboard, public PIA {
class io: public Display, Keyboard, public pia {
public: public:
io(filer &files): files(files) {} io(filer &files): Memory::Device(Memory::page_size), files(files) {}
virtual void reset(); virtual void reset();
virtual void down(uint8_t scan); virtual void down(uint8_t scan);
virtual void up(uint8_t scan); virtual void up(uint8_t scan);
virtual void operator=(uint8_t b) { PIA::write(_acc, b); }
virtual operator uint8_t() { return PIA::read(_acc); }
virtual void checkpoint(Stream &); virtual void checkpoint(Stream &);
virtual void restore(Stream &); virtual void restore(Stream &);

17
pia.cpp
View File

@ -2,15 +2,15 @@
#include <memory.h> #include <memory.h>
#include "pia.h" #include "pia.h"
void pia::operator=(uint8_t b) { void PIA::write(Memory::address a, uint8_t b) {
#if defined(DEBUGGING) #if defined(DEBUGGING)
Serial.print(millis()); Serial.print(millis());
Serial.print(" > "); Serial.print(" > ");
Serial.print(_acc, 16); Serial.print(a, 16);
Serial.print(' '); Serial.print(' ');
Serial.println(b, 16); Serial.println(b, 16);
#endif #endif
switch(_acc % 4) { switch(a % 4) {
case 0: case 0:
write_porta(b); write_porta(b);
break; break;
@ -26,13 +26,13 @@ void pia::operator=(uint8_t b) {
} }
} }
pia::operator uint8_t() { uint8_t PIA::read(Memory::address a) {
#if defined(DEBUGGING) #if defined(DEBUGGING)
Serial.print(millis()); Serial.print(millis());
Serial.print(" < "); Serial.print(" < ");
Serial.println(_acc, 16); Serial.println(a, 16);
#endif #endif
switch (_acc % 4) { switch (a % 4) {
case 0: case 0:
return read_porta(); return read_porta();
case 1: case 1:
@ -45,17 +45,16 @@ pia::operator uint8_t() {
return 0xff; return 0xff;
} }
void pia::checkpoint(Stream &s) { void PIA::checkpoint(Stream &s) {
s.write(portb_cr); s.write(portb_cr);
s.write(portb); s.write(portb);
s.write(porta_cr); s.write(porta_cr);
s.write(porta); s.write(porta);
} }
void pia::restore(Stream &s) { void PIA::restore(Stream &s) {
portb_cr = s.read(); portb_cr = s.read();
portb = s.read(); portb = s.read();
porta_cr = s.read(); porta_cr = s.read();
porta = s.read(); porta = s.read();
} }

9
pia.h
View File

@ -1,13 +1,14 @@
#ifndef __PIA_H__ #ifndef __PIA_H__
#define __PIA_H__ #define __PIA_H__
class pia: public Memory::Device { // https://en.wikipedia.org/wiki/Peripheral_Interface_Adapter
class PIA {
public: public:
pia(): Memory::Device(256), portb_cr(0), porta_cr(0) {} PIA(): portb_cr(0), porta_cr(0) {}
virtual void reset() { portb_cr = porta_cr = 0; } virtual void reset() { portb_cr = porta_cr = 0; }
void operator=(uint8_t); void write(Memory::address, uint8_t);
operator uint8_t(); uint8_t read(Memory::address);
void checkpoint(Stream &); void checkpoint(Stream &);
void restore(Stream &); void restore(Stream &);