Compare commits
3 Commits
c129e717d8
...
f2abbe9dfd
Author | SHA1 | Date |
---|---|---|
Stephen Crane | f2abbe9dfd | |
Stephen Crane | 48529fae16 | |
Stephen Crane | 44c3cc1ea7 |
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
#include <r65emu.h>
|
#include <r65emu.h>
|
||||||
#include <r6502.h>
|
#include <r6502.h>
|
||||||
|
#include <pia.h>
|
||||||
|
|
||||||
#include "pia.h"
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ void reset() {
|
||||||
io.status("Reset failed");
|
io.status("Reset failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
io.files.start();
|
io.start();
|
||||||
#if defined(KRUSADER)
|
#if defined(KRUSADER)
|
||||||
io.status("Krusader: F000R / Basic: E000R");
|
io.status("Krusader: F000R / Basic: E000R");
|
||||||
#else
|
#else
|
||||||
|
|
11
TODO.md
11
TODO.md
|
@ -1,11 +0,0 @@
|
||||||
- more PIA: check out vice
|
|
||||||
|
|
||||||
PIA init-sequence
|
|
||||||
5021 > 12 7F
|
|
||||||
5021 > 11 A7
|
|
||||||
5022 > 13 A7
|
|
||||||
5023 > 12 5C
|
|
||||||
5025 > 12 D
|
|
||||||
5026 > 12 0
|
|
||||||
|
|
||||||
http://mamedev.org/source/src/mess/machine/apple1.c.html
|
|
53
io.cpp
53
io.cpp
|
@ -1,22 +1,16 @@
|
||||||
#include <Stream.h>
|
#include <Arduino.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <display.h>
|
#include <display.h>
|
||||||
#include <serialio.h>
|
#include <serialio.h>
|
||||||
#include <filer.h>
|
#include <filer.h>
|
||||||
#include <keyboard.h>
|
#include <keyboard.h>
|
||||||
|
#include <pia.h>
|
||||||
#include <timed.h>
|
#include <timed.h>
|
||||||
|
|
||||||
#include "pia.h"
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#define ROWS 24
|
|
||||||
#define COLS 40
|
|
||||||
static unsigned r, c;
|
|
||||||
static char screen[ROWS][COLS];
|
|
||||||
|
|
||||||
void io::reset() {
|
void io::reset() {
|
||||||
Display::begin(BG_COLOUR, FG_COLOUR, ORIENT);
|
Display::begin(BG_COLOUR, FG_COLOUR, ORIENT);
|
||||||
clear();
|
clear();
|
||||||
|
@ -28,7 +22,29 @@ void io::reset() {
|
||||||
screen[j][i] = ' ';
|
screen[j][i] = ' ';
|
||||||
|
|
||||||
_loading = false;
|
_loading = false;
|
||||||
pia::reset();
|
PIA::reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static io *i;
|
||||||
|
|
||||||
|
const int TICK_FREQ = 2;
|
||||||
|
|
||||||
|
bool io::start() {
|
||||||
|
|
||||||
|
i = this;
|
||||||
|
timer_create(TICK_FREQ, io::on_tick);
|
||||||
|
return files.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR io::on_tick() {
|
||||||
|
|
||||||
|
static int tick = 0;
|
||||||
|
tick = ++tick % 3;
|
||||||
|
i->cursor(tick < 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void io::cursor(bool on) {
|
||||||
|
draw(on? '_': ' ', c, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::load() {
|
void io::load() {
|
||||||
|
@ -78,13 +94,14 @@ static const uint8_t shiftmap[] PROGMEM = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void io::down(uint8_t scan) {
|
void io::down(uint8_t scan) {
|
||||||
set_porta(0);
|
|
||||||
if (isshift(scan))
|
if (isshift(scan))
|
||||||
_shift = true;
|
_shift = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::enter(uint8_t key) {
|
void io::enter(uint8_t key) {
|
||||||
set_porta(key + 0x80);
|
PIA::write_ca1(false);
|
||||||
|
PIA::write_porta_in(key + 0x80);
|
||||||
|
PIA::write_ca1(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::up(uint8_t scan) {
|
void io::up(uint8_t scan) {
|
||||||
|
@ -142,25 +159,21 @@ 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_cra() {
|
||||||
uint8_t b = pia::read_porta_cr();
|
|
||||||
if (b != 0xa7)
|
|
||||||
return b;
|
|
||||||
|
|
||||||
if (_loading) {
|
if (_loading) {
|
||||||
if (files.more())
|
if (files.more())
|
||||||
enter(files.read());
|
enter(files.read());
|
||||||
else
|
else
|
||||||
_loading = false;
|
_loading = false;
|
||||||
}
|
}
|
||||||
return b;
|
return PIA::read_cra();
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +182,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++)
|
||||||
|
|
36
io.h
36
io.h
|
@ -1,30 +1,42 @@
|
||||||
#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();
|
void reset();
|
||||||
virtual void down(uint8_t scan);
|
bool start();
|
||||||
virtual void up(uint8_t scan);
|
|
||||||
|
|
||||||
virtual void checkpoint(Stream &);
|
static void on_tick();
|
||||||
virtual void restore(Stream &);
|
|
||||||
|
|
||||||
virtual void write_portb(uint8_t);
|
void down(uint8_t);
|
||||||
virtual uint8_t read_porta_cr();
|
void up(uint8_t);
|
||||||
|
|
||||||
|
void operator=(uint8_t b) { PIA::write(_acc, b); }
|
||||||
|
operator uint8_t() { return PIA::read(_acc); }
|
||||||
|
|
||||||
|
void checkpoint(Stream &);
|
||||||
|
void restore(Stream &);
|
||||||
|
|
||||||
|
void write_portb(uint8_t);
|
||||||
|
uint8_t read_cra();
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
filer &files;
|
filer &files;
|
||||||
|
|
||||||
|
static const uint8_t ROWS = 24;
|
||||||
|
static const uint8_t COLS = 40;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void cursor(bool on);
|
||||||
void display(uint8_t);
|
void display(uint8_t);
|
||||||
void draw(char, int, int);
|
void draw(char, int, int);
|
||||||
void enter(uint8_t);
|
void enter(uint8_t);
|
||||||
|
|
||||||
bool _shift;
|
bool _shift, _loading;
|
||||||
bool _loading;
|
uint8_t r, c;
|
||||||
|
char screen[ROWS][COLS];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
61
pia.cpp
61
pia.cpp
|
@ -1,61 +0,0 @@
|
||||||
#include <Arduino.h>
|
|
||||||
#include <memory.h>
|
|
||||||
#include "pia.h"
|
|
||||||
|
|
||||||
void pia::operator=(uint8_t b) {
|
|
||||||
#if defined(DEBUGGING)
|
|
||||||
Serial.print(millis());
|
|
||||||
Serial.print(" > ");
|
|
||||||
Serial.print(_acc, 16);
|
|
||||||
Serial.print(' ');
|
|
||||||
Serial.println(b, 16);
|
|
||||||
#endif
|
|
||||||
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 uint8_t() {
|
|
||||||
#if defined(DEBUGGING)
|
|
||||||
Serial.print(millis());
|
|
||||||
Serial.print(" < ");
|
|
||||||
Serial.println(_acc, 16);
|
|
||||||
#endif
|
|
||||||
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
51
pia.h
|
@ -1,51 +0,0 @@
|
||||||
#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=(uint8_t);
|
|
||||||
operator uint8_t();
|
|
||||||
|
|
||||||
void checkpoint(Stream &);
|
|
||||||
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; }
|
|
||||||
|
|
||||||
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_portb(uint8_t b) { portb = b; }
|
|
||||||
void write_portb_cr(uint8_t b) {
|
|
||||||
if (portb_cr < 0x80)
|
|
||||||
portb_cr = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t portb_cr, portb, porta_cr, porta;
|
|
||||||
};
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue