This commit is contained in:
Stephen Crane 2018-08-14 11:00:03 +01:00
parent b85e982433
commit db9de4bdde
4 changed files with 32 additions and 30 deletions

18
io.cpp
View File

@ -37,7 +37,7 @@ void io::load() {
} }
// ascii map for scan-codes // ascii map for scan-codes
static const byte scanmap[] = { static const uint8_t scanmap[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x00 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x00
0xff, 0xff, 0xff, 0xff, 0xff, 0x09, 0x60, 0xff, // 0x08 0xff, 0xff, 0xff, 0xff, 0xff, 0x09, 0x60, 0xff, // 0x08
0xff, 0xff, 0xff, 0xff, 0xff, 0x51, 0x31, 0xff, // 0x10 0xff, 0xff, 0xff, 0xff, 0xff, 0x51, 0x31, 0xff, // 0x10
@ -56,7 +56,7 @@ static const byte scanmap[] = {
0xff, 0x2b, 0x33, 0x2d, 0x2a, 0x39, 0xff, 0xff, // 0x78 0xff, 0x2b, 0x33, 0x2d, 0x2a, 0x39, 0xff, 0xff, // 0x78
}; };
static const byte shiftmap[] = { static const uint8_t shiftmap[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x00 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x00
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x08 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x08
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x21, 0xff, // 0x10 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x21, 0xff, // 0x10
@ -75,17 +75,17 @@ static const byte shiftmap[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x78 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x78
}; };
void io::down(byte scan) { void io::down(uint8_t scan) {
set_porta(0); set_porta(0);
if (isshift(scan)) if (isshift(scan))
_shift = true; _shift = true;
} }
void io::enter(byte key) { void io::enter(uint8_t key) {
set_porta(key + 0x80); set_porta(key + 0x80);
} }
void io::up(byte scan) { void io::up(uint8_t scan) {
if (isshift(scan)) { if (isshift(scan)) {
_shift = false; _shift = false;
return; return;
@ -101,7 +101,7 @@ void io::draw(char ch, int i, int j) {
} }
} }
void io::display(byte b) { void io::display(uint8_t b) {
char ch = (char)b; char ch = (char)b;
switch(ch) { switch(ch) {
case 0x5f: case 0x5f:
@ -137,14 +137,14 @@ void io::display(byte b) {
draw('_', c, r); draw('_', c, r);
} }
void io::write_portb(byte b) { void io::write_portb(uint8_t b) {
b &= 0x7f; b &= 0x7f;
display(b); display(b);
pia::write_portb(b); pia::write_portb(b);
} }
byte io::read_porta_cr() { uint8_t io::read_porta_cr() {
byte b = pia::read_porta_cr(); uint8_t b = pia::read_porta_cr();
if (b != 0xa7) if (b != 0xa7)
return b; return b;

12
io.h
View File

@ -5,21 +5,21 @@
class io: public UTFTDisplay, Keyboard, public pia { class io: public UTFTDisplay, Keyboard, public pia {
public: public:
virtual void reset(); virtual void reset();
virtual void down(byte scan); virtual void down(uint8_t scan);
virtual void up(byte scan); virtual void up(uint8_t scan);
virtual void checkpoint(Stream &); virtual void checkpoint(Stream &);
virtual void restore(Stream &); virtual void restore(Stream &);
virtual void write_portb(byte); virtual void write_portb(uint8_t);
virtual byte read_porta_cr(); virtual uint8_t read_porta_cr();
void load(); void load();
sdtape tape; sdtape tape;
private: private:
void display(byte); void display(uint8_t);
void draw(char, int, int); void draw(char, int, int);
void enter(byte); void enter(uint8_t);
bool _shift; bool _shift;
bool _loading; bool _loading;

View File

@ -1,13 +1,15 @@
#include <Energia.h> #include <Arduino.h>
#include <memory.h> #include <memory.h>
#include "pia.h" #include "pia.h"
void pia::operator=(byte b) { void pia::operator=(uint8_t b) {
/*
Serial.print(millis()); Serial.print(millis());
Serial.print(" > "); Serial.print(" > ");
Serial.print(_acc, 16); Serial.print(_acc, 16);
Serial.print(' '); Serial.print(' ');
Serial.println(b, 16); Serial.println(b, 16);
*/
switch(_acc % 4) { switch(_acc % 4) {
case 0: case 0:
write_porta(b); write_porta(b);
@ -24,7 +26,7 @@ Serial.println(b, 16);
} }
} }
pia::operator byte() { pia::operator uint8_t() {
/* /*
Serial.print(millis()); Serial.print(millis());
Serial.print(" < "); Serial.print(" < ");

24
pia.h
View File

@ -6,46 +6,46 @@ public:
pia(): Memory::Device(256), portb_cr(0), porta_cr(0) {} pia(): Memory::Device(256), portb_cr(0), porta_cr(0) {}
virtual void reset() { portb_cr = porta_cr = 0; } virtual void reset() { portb_cr = porta_cr = 0; }
void operator=(byte); void operator=(uint8_t);
operator byte(); operator uint8_t();
void checkpoint(Stream &); void checkpoint(Stream &);
void restore(Stream &); void restore(Stream &);
protected: protected:
// write to the "external" side of the port // write to the "external" side of the port
void set_porta(byte b) { void set_porta(uint8_t b) {
porta = b; porta = b;
if (b & 0x80) if (b & 0x80)
porta_cr = 0xa7; porta_cr = 0xa7;
} }
// "device-side" operations (called from memory interface) // "device-side" operations (called from memory interface)
byte read_porta() { return porta; } uint8_t read_porta() { return porta; }
virtual byte read_porta_cr() { virtual uint8_t read_porta_cr() {
if (porta_cr & 0x80) { if (porta_cr & 0x80) {
porta_cr = 0; porta_cr = 0;
return 0xa7; return 0xa7;
} }
return porta_cr; return porta_cr;
} }
byte read_portb() { return portb; } uint8_t read_portb() { return portb; }
byte read_portb_cr() { return portb_cr; } uint8_t read_portb_cr() { return portb_cr; }
void write_porta(byte b) { porta = b; } void write_porta(uint8_t b) { porta = b; }
void write_porta_cr(byte b) { void write_porta_cr(uint8_t b) {
if (!(porta_cr & 0x80) && b >= 0x80) if (!(porta_cr & 0x80) && b >= 0x80)
porta_cr |= 0x80; porta_cr |= 0x80;
else else
porta_cr = b; porta_cr = b;
} }
virtual void write_portb(byte b) { portb = b; } virtual void write_portb(uint8_t b) { portb = b; }
void write_portb_cr(byte b) { void write_portb_cr(uint8_t b) {
if (portb_cr < 0x80) if (portb_cr < 0x80)
portb_cr = b; portb_cr = b;
} }
private: private:
byte portb_cr, portb, porta_cr, porta; uint8_t portb_cr, portb, porta_cr, porta;
}; };
#endif #endif