mirror of
https://github.com/jscrane/Apple1.git
synced 2024-09-27 15:57:46 +00:00
factor out pia
This commit is contained in:
parent
2256502943
commit
82c51380f1
2
TODO.md
2
TODO.md
@ -1,2 +0,0 @@
|
|||||||
- break out PIA abstraction
|
|
||||||
- checkpoint and restore images (i.e., startrek)
|
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "roms/basic.h"
|
#include "roms/basic.h"
|
||||||
#include "roms/monitor.h"
|
#include "roms/monitor.h"
|
||||||
|
#include "pia.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
105
io.cpp
105
io.cpp
@ -5,13 +5,11 @@
|
|||||||
#include <keyboard.h>
|
#include <keyboard.h>
|
||||||
#include <timed.h>
|
#include <timed.h>
|
||||||
|
|
||||||
|
#include "pia.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
|
|
||||||
static byte dsp_cr, dsp, kbd_cr, kbd;
|
|
||||||
static unsigned kbd_int, dsp_out;
|
|
||||||
|
|
||||||
#define ROWS 24
|
#define ROWS 24
|
||||||
#define COLS 40
|
#define COLS 40
|
||||||
static unsigned r, c;
|
static unsigned r, c;
|
||||||
@ -28,10 +26,7 @@ void io::reset() {
|
|||||||
screen[j][i] = ' ';
|
screen[j][i] = ' ';
|
||||||
|
|
||||||
_loading = false;
|
_loading = false;
|
||||||
|
pia::reset();
|
||||||
// PIA state
|
|
||||||
dsp_cr = kbd_cr = 0;
|
|
||||||
kbd_int = dsp_out = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::load() {
|
void io::load() {
|
||||||
@ -81,14 +76,13 @@ static const byte shiftmap[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void io::down(byte scan) {
|
void io::down(byte scan) {
|
||||||
kbd = 0;
|
set_porta(0);
|
||||||
if (isshift(scan))
|
if (isshift(scan))
|
||||||
_shift = true;
|
_shift = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::enter(byte key) {
|
void io::enter(byte key) {
|
||||||
kbd = key + 0x80;
|
set_porta(key + 0x80);
|
||||||
kbd_cr = 0xa7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::up(byte scan) {
|
void io::up(byte scan) {
|
||||||
@ -143,95 +137,27 @@ void io::display(byte b) {
|
|||||||
draw('_', c, r);
|
draw('_', c, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::operator=(byte b) {
|
void io::write_portb(byte b) {
|
||||||
|
b &= 0x7f;
|
||||||
Serial.print(">");
|
|
||||||
Serial.print(_acc, 16);
|
|
||||||
Serial.print(" ");
|
|
||||||
Serial.println(b, 16);
|
|
||||||
|
|
||||||
switch(_acc % 4) {
|
|
||||||
case 0:
|
|
||||||
kbd = b;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if (!kbd_int && b >= 0x80)
|
|
||||||
kbd_int = 1;
|
|
||||||
else
|
|
||||||
kbd_cr = b;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (b >= 0x80)
|
|
||||||
b -= 0x80;
|
|
||||||
display(b);
|
display(b);
|
||||||
dsp = b;
|
pia::write_portb(b);
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
if (!dsp_out && dsp_cr >= 0x80)
|
|
||||||
dsp_out = 1;
|
|
||||||
else
|
|
||||||
dsp_cr = b;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
io::operator byte() {
|
byte io::read_porta_cr() {
|
||||||
|
byte b = pia::read_porta_cr();
|
||||||
switch (_acc % 4) {
|
if (b == 0xa7) {
|
||||||
case 0:
|
|
||||||
/*
|
|
||||||
Serial.print("<");
|
|
||||||
Serial.print(_acc, 16);
|
|
||||||
Serial.print(" ");
|
|
||||||
Serial.println(kbd, 16);
|
|
||||||
*/
|
|
||||||
return kbd;
|
|
||||||
case 1:
|
|
||||||
if (kbd_int && kbd_cr >= 0x80) {
|
|
||||||
kbd_cr = 0;
|
|
||||||
/*
|
|
||||||
Serial.print("<");
|
|
||||||
Serial.print(_acc, 16);
|
|
||||||
Serial.print(" ");
|
|
||||||
Serial.println(0xa7, 16);
|
|
||||||
*/
|
|
||||||
if (_loading) {
|
if (_loading) {
|
||||||
if (tape.more())
|
if (tape.more())
|
||||||
enter(tape.read());
|
enter(tape.read());
|
||||||
else
|
else
|
||||||
_loading = false;
|
_loading = false;
|
||||||
}
|
}
|
||||||
return 0xa7;
|
|
||||||
}
|
}
|
||||||
//Serial.println(kbd_cr, 16);
|
return b;
|
||||||
return kbd_cr;
|
|
||||||
case 2:
|
|
||||||
/*
|
|
||||||
Serial.print("<");
|
|
||||||
Serial.print(_acc, 16);
|
|
||||||
Serial.print(" ");
|
|
||||||
Serial.println(dsp, 16);
|
|
||||||
*/
|
|
||||||
return dsp;
|
|
||||||
case 3:
|
|
||||||
/*
|
|
||||||
Serial.print("<");
|
|
||||||
Serial.print(_acc, 16);
|
|
||||||
Serial.print(" ");
|
|
||||||
Serial.println(dsp_cr, 16);
|
|
||||||
*/
|
|
||||||
return dsp_cr;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::checkpoint(Stream &s) {
|
void io::checkpoint(Stream &s) {
|
||||||
s.write(dsp_cr);
|
pia::checkpoint(s);
|
||||||
s.write(dsp);
|
|
||||||
s.write(kbd_cr);
|
|
||||||
s.write(kbd);
|
|
||||||
s.write(kbd_int);
|
|
||||||
s.write(dsp_out);
|
|
||||||
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++)
|
||||||
@ -240,12 +166,7 @@ void io::checkpoint(Stream &s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void io::restore(Stream &s) {
|
void io::restore(Stream &s) {
|
||||||
dsp_cr = s.read();
|
pia::restore(s);
|
||||||
dsp = s.read();
|
|
||||||
kbd_cr = s.read();
|
|
||||||
kbd = s.read();
|
|
||||||
kbd_int = s.read();
|
|
||||||
dsp_out = s.read();
|
|
||||||
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++)
|
||||||
|
15
io.h
15
io.h
@ -1,19 +1,18 @@
|
|||||||
#ifndef _IO_H
|
#ifndef _IO_H
|
||||||
#define _IO_H
|
#define _IO_H
|
||||||
|
|
||||||
class io: public UTFTDisplay, Keyboard {
|
// http://mamedev.org/source/src/mess/machine/apple1.c.html
|
||||||
|
class io: public UTFTDisplay, Keyboard, public pia {
|
||||||
public:
|
public:
|
||||||
io(): UTFTDisplay(256) {}
|
|
||||||
|
|
||||||
void operator=(byte);
|
|
||||||
operator byte();
|
|
||||||
|
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual void down(byte scan);
|
virtual void down(byte scan);
|
||||||
virtual void up(byte scan);
|
virtual void up(byte scan);
|
||||||
|
|
||||||
void checkpoint(Stream &);
|
virtual void checkpoint(Stream &);
|
||||||
void restore(Stream &);
|
virtual void restore(Stream &);
|
||||||
|
|
||||||
|
virtual void write_portb(byte);
|
||||||
|
virtual byte read_porta_cr();
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
sdtape tape;
|
sdtape tape;
|
||||||
|
49
pia.cpp
Normal file
49
pia.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <Energia.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include "pia.h"
|
||||||
|
|
||||||
|
void pia::operator=(byte b) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pia::operator byte() {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
51
pia.h
Normal file
51
pia.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef __PIA_H__
|
||||||
|
#define __PIA_H__
|
||||||
|
|
||||||
|
class pia: public Memory::Device {
|
||||||
|
public:
|
||||||
|
pia(): Memory::Device(256), portb_cr(0), porta_cr(0) {}
|
||||||
|
virtual void reset() { portb_cr = porta_cr = 0; }
|
||||||
|
|
||||||
|
void operator=(byte);
|
||||||
|
operator byte();
|
||||||
|
|
||||||
|
void checkpoint(Stream &);
|
||||||
|
void restore(Stream &);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// write to the "external" side of the port
|
||||||
|
void set_porta(byte b) {
|
||||||
|
porta = b;
|
||||||
|
if (b & 0x80)
|
||||||
|
porta_cr = 0xa7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "device-side" operations (called from memory interface)
|
||||||
|
byte read_porta() { return porta; }
|
||||||
|
virtual byte read_porta_cr() {
|
||||||
|
if (porta_cr & 0x80) {
|
||||||
|
porta_cr = 0;
|
||||||
|
return 0xa7;
|
||||||
|
}
|
||||||
|
return porta_cr;
|
||||||
|
}
|
||||||
|
byte read_portb() { return portb; }
|
||||||
|
byte read_portb_cr() { return portb_cr; }
|
||||||
|
|
||||||
|
void write_porta(byte b) { porta = b; }
|
||||||
|
void write_porta_cr(byte b) {
|
||||||
|
if (!(porta_cr & 0x80) && b >= 0x80)
|
||||||
|
porta_cr |= 0x80;
|
||||||
|
else
|
||||||
|
porta_cr = b;
|
||||||
|
}
|
||||||
|
virtual void write_portb(byte b) { portb = b; }
|
||||||
|
void write_portb_cr(byte b) {
|
||||||
|
if (portb_cr < 0x80)
|
||||||
|
portb_cr = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
byte portb_cr, portb, porta_cr, porta;
|
||||||
|
};
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user