mirror of
https://github.com/jscrane/Apple1.git
synced 2024-11-24 19:33:20 +00:00
68 lines
1.1 KiB
C++
68 lines
1.1 KiB
C++
#include <Arduino.h>
|
|
#include <memory.h>
|
|
#include <display.h>
|
|
#include <serialio.h>
|
|
#include <filer.h>
|
|
#include <serial_kbd.h>
|
|
#include <serial_dsp.h>
|
|
#include <pia.h>
|
|
#include <hardware.h>
|
|
|
|
#include "io.h"
|
|
#include "disp.h"
|
|
#include "config.h"
|
|
|
|
void io::reset() {
|
|
_loading = false;
|
|
_dsp.reset();
|
|
_kbd.reset();
|
|
_pia.reset();
|
|
_ch = 0;
|
|
}
|
|
|
|
bool io::start() {
|
|
hardware_interval_timer(10, [this]() { poll(); });
|
|
_pia.register_portb_write_handler([this](uint8_t b) { _dsp.write(b & 0x7f); });
|
|
_pia.register_porta_read_handler([this]() { uint8_t c = _ch; _ch = 0; return c; });
|
|
return files.start();
|
|
}
|
|
|
|
void io::load() {
|
|
if (files.more()) {
|
|
_loading = true;
|
|
enter(files.read());
|
|
}
|
|
}
|
|
|
|
void io::enter(uint8_t key) {
|
|
_pia.write_ca1(false);
|
|
_ch = key | 0x80;
|
|
_pia.write_ca1(true);
|
|
}
|
|
|
|
void io::poll() {
|
|
if (_ch)
|
|
return;
|
|
|
|
if (_loading) {
|
|
if (files.more())
|
|
enter(files.read());
|
|
else
|
|
_loading = false;
|
|
} else if (_kbd.available()) {
|
|
int c = _kbd.read();
|
|
if (c != -1)
|
|
enter(c);
|
|
}
|
|
}
|
|
|
|
void io::checkpoint(Stream &s) {
|
|
_pia.checkpoint(s);
|
|
_dsp.checkpoint(s);
|
|
}
|
|
|
|
void io::restore(Stream &s) {
|
|
_pia.restore(s);
|
|
_dsp.restore(s);
|
|
}
|