Compare commits

...

3 Commits

Author SHA1 Message Date
Stephen Crane f2abbe9dfd
blink cursor (#9) 2023-09-27 13:55:10 +01:00
Stephen Crane 48529fae16
promote PIA to library (#8) 2023-09-27 11:31:46 +01:00
Stephen Crane 44c3cc1ea7
PIA refactoring (#6)
* PIA cleanup

* move Apple1-dependent bits onto io class

* implement irq_a1 and irq_b1

* irq2 + cleanups

* ddr part 1

* ddr processing part 2

* ...
2023-09-27 10:35:18 +01:00
6 changed files with 59 additions and 157 deletions

View File

@ -3,8 +3,8 @@
#include <r65emu.h>
#include <r6502.h>
#include <pia.h>
#include "pia.h"
#include "io.h"
#include "config.h"
@ -34,7 +34,7 @@ void reset() {
io.status("Reset failed");
return;
}
io.files.start();
io.start();
#if defined(KRUSADER)
io.status("Krusader: F000R / Basic: E000R");
#else

11
TODO.md
View File

@ -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
View File

@ -1,22 +1,16 @@
#include <Stream.h>
#include <stdint.h>
#include <Arduino.h>
#include <memory.h>
#include <display.h>
#include <serialio.h>
#include <filer.h>
#include <keyboard.h>
#include <pia.h>
#include <timed.h>
#include "pia.h"
#include "io.h"
#include "hardware.h"
#include "config.h"
#define ROWS 24
#define COLS 40
static unsigned r, c;
static char screen[ROWS][COLS];
void io::reset() {
Display::begin(BG_COLOUR, FG_COLOUR, ORIENT);
clear();
@ -28,7 +22,29 @@ void io::reset() {
screen[j][i] = ' ';
_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() {
@ -78,13 +94,14 @@ static const uint8_t shiftmap[] PROGMEM = {
};
void io::down(uint8_t scan) {
set_porta(0);
if (isshift(scan))
_shift = true;
}
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) {
@ -142,25 +159,21 @@ 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();
if (b != 0xa7)
return b;
uint8_t io::read_cra() {
if (_loading) {
if (files.more())
enter(files.read());
else
_loading = false;
}
return b;
return PIA::read_cra();
}
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 +182,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++)

36
io.h
View File

@ -1,30 +1,42 @@
#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);
void reset();
bool start();
virtual void checkpoint(Stream &);
virtual void restore(Stream &);
static void on_tick();
virtual void write_portb(uint8_t);
virtual uint8_t read_porta_cr();
void down(uint8_t);
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();
filer &files;
static const uint8_t ROWS = 24;
static const uint8_t COLS = 40;
private:
void cursor(bool on);
void display(uint8_t);
void draw(char, int, int);
void enter(uint8_t);
bool _shift;
bool _loading;
bool _shift, _loading;
uint8_t r, c;
char screen[ROWS][COLS];
};
#endif

61
pia.cpp
View File

@ -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
View File

@ -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