Apple1-esp/io.cpp

72 lines
1.0 KiB
C++
Raw Normal View History

2023-09-27 12:55:10 +00:00
#include <Arduino.h>
2014-11-11 17:13:25 +00:00
#include <memory.h>
2023-07-25 15:51:34 +00:00
#include <display.h>
2019-02-13 07:47:59 +00:00
#include <serialio.h>
#include <filer.h>
#include <serial_kbd.h>
#include <serial_dsp.h>
2023-09-27 10:31:46 +00:00
#include <pia.h>
2014-11-14 11:45:28 +00:00
#include <timed.h>
2014-11-11 17:13:25 +00:00
#include "io.h"
#include "disp.h"
2014-11-11 17:13:25 +00:00
#include "hardware.h"
2018-11-18 12:48:10 +00:00
#include "config.h"
2014-11-11 17:13:25 +00:00
void io::reset() {
_dsp.reset();
_kbd.reset();
2014-11-14 11:45:28 +00:00
_loading = false;
PIA::reset();
2014-11-11 17:13:25 +00:00
}
2023-09-27 12:55:10 +00:00
bool io::start() {
return files.start();
}
2014-11-14 11:45:28 +00:00
void io::load() {
2019-02-13 07:47:59 +00:00
if (files.more()) {
2014-11-14 11:45:28 +00:00
_loading = true;
2019-02-13 07:47:59 +00:00
enter(files.read());
2014-11-14 11:45:28 +00:00
}
}
2018-08-14 10:00:03 +00:00
void io::enter(uint8_t key) {
PIA::write_ca1(false);
PIA::write_porta_in(key + 0x80);
PIA::write_ca1(true);
2014-11-14 11:45:28 +00:00
}
2018-08-14 10:00:03 +00:00
void io::write_portb(uint8_t b) {
2014-11-17 20:00:40 +00:00
b &= 0x7f;
_dsp.write(b);
PIA::write_portb(b);
2014-11-11 17:13:25 +00:00
}
uint8_t io::read_cra() {
2014-11-24 19:37:04 +00:00
if (_loading) {
2019-02-13 07:47:59 +00:00
if (files.more())
enter(files.read());
2014-11-24 19:37:04 +00:00
else
_loading = false;
} else if (_kbd.available()) {
int c = _kbd.read();
if (c != -1)
enter(c);
2014-11-11 17:13:25 +00:00
}
return PIA::read_cra();
2014-11-11 17:13:25 +00:00
}
void io::checkpoint(Stream &s) {
PIA::checkpoint(s);
_dsp.checkpoint(s);
2014-11-11 17:13:25 +00:00
}
void io::restore(Stream &s) {
PIA::restore(s);
_dsp.restore(s);
2014-11-11 17:13:25 +00:00
}