From ee452e816e83cbf96387c760c4c6a17577ae1d3b Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 26 Sep 2023 10:41:35 +0100 Subject: [PATCH] PIA cleanup --- io.cpp | 10 +++++----- io.h | 8 +++++--- pia.cpp | 17 ++++++++--------- pia.h | 9 +++++---- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/io.cpp b/io.cpp index 16b9a48..4b5ac88 100644 --- a/io.cpp +++ b/io.cpp @@ -28,7 +28,7 @@ void io::reset() { screen[j][i] = ' '; _loading = false; - pia::reset(); + PIA::reset(); } void io::load() { @@ -142,11 +142,11 @@ void io::display(uint8_t b) { void io::write_portb(uint8_t b) { b &= 0x7f; display(b); - pia::write_portb(b); + PIA::write_portb(b); } uint8_t io::read_porta_cr() { - uint8_t b = pia::read_porta_cr(); + uint8_t b = PIA::read_porta_cr(); if (b != 0xa7) return b; @@ -160,7 +160,7 @@ uint8_t io::read_porta_cr() { } void io::checkpoint(Stream &s) { - pia::checkpoint(s); + PIA::checkpoint(s); s.write(r); s.write(c); for (int j = 0; j < ROWS; j++) @@ -169,7 +169,7 @@ void io::checkpoint(Stream &s) { } void io::restore(Stream &s) { - pia::restore(s); + PIA::restore(s); r = s.read(); c = s.read(); for (int j = 0; j < ROWS; j++) diff --git a/io.h b/io.h index 9d19df9..e11a40e 100644 --- a/io.h +++ b/io.h @@ -1,15 +1,17 @@ #ifndef _IO_H #define _IO_H -// http://mamedev.org/source/src/mess/machine/apple1.c.html -class io: public Display, Keyboard, public pia { +class io: public Memory::Device, public Display, Keyboard, public PIA { public: - io(filer &files): files(files) {} + io(filer &files): Memory::Device(Memory::page_size), files(files) {} virtual void reset(); virtual void down(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 restore(Stream &); diff --git a/pia.cpp b/pia.cpp index a5e06fb..82fa487 100644 --- a/pia.cpp +++ b/pia.cpp @@ -2,15 +2,15 @@ #include #include "pia.h" -void pia::operator=(uint8_t b) { +void PIA::write(Memory::address a, uint8_t b) { #if defined(DEBUGGING) Serial.print(millis()); Serial.print(" > "); - Serial.print(_acc, 16); + Serial.print(a, 16); Serial.print(' '); Serial.println(b, 16); #endif - switch(_acc % 4) { + switch(a % 4) { case 0: write_porta(b); 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) Serial.print(millis()); Serial.print(" < "); - Serial.println(_acc, 16); + Serial.println(a, 16); #endif - switch (_acc % 4) { + switch (a % 4) { case 0: return read_porta(); case 1: @@ -45,17 +45,16 @@ pia::operator uint8_t() { return 0xff; } -void pia::checkpoint(Stream &s) { +void PIA::checkpoint(Stream &s) { s.write(portb_cr); s.write(portb); s.write(porta_cr); s.write(porta); } -void pia::restore(Stream &s) { +void PIA::restore(Stream &s) { portb_cr = s.read(); portb = s.read(); porta_cr = s.read(); porta = s.read(); } - diff --git a/pia.h b/pia.h index 1818429..3e0906f 100644 --- a/pia.h +++ b/pia.h @@ -1,13 +1,14 @@ #ifndef __PIA_H__ #define __PIA_H__ -class pia: public Memory::Device { +// https://en.wikipedia.org/wiki/Peripheral_Interface_Adapter +class PIA { 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; } - void operator=(uint8_t); - operator uint8_t(); + void write(Memory::address, uint8_t); + uint8_t read(Memory::address); void checkpoint(Stream &); void restore(Stream &);