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>
|
2024-08-22 15:02:42 +00:00
|
|
|
#include <serial_kbd.h>
|
2024-08-29 06:03:46 +00:00
|
|
|
#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"
|
2024-08-29 06:03:46 +00:00
|
|
|
#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() {
|
2024-08-29 06:03:46 +00:00
|
|
|
_dsp.reset();
|
2024-08-22 15:02:42 +00:00
|
|
|
_kbd.reset();
|
|
|
|
|
2014-11-14 11:45:28 +00:00
|
|
|
_loading = false;
|
2023-09-27 09:35:18 +00:00
|
|
|
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) {
|
2023-09-27 09:35:18 +00:00
|
|
|
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;
|
2024-08-29 06:03:46 +00:00
|
|
|
_dsp.write(b);
|
2023-09-27 09:35:18 +00:00
|
|
|
PIA::write_portb(b);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 09:35:18 +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;
|
2024-08-22 15:02:42 +00:00
|
|
|
} else if (_kbd.available()) {
|
|
|
|
int c = _kbd.read();
|
|
|
|
if (c != -1)
|
|
|
|
enter(c);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
2024-08-22 15:02:42 +00:00
|
|
|
|
2023-09-27 09:35:18 +00:00
|
|
|
return PIA::read_cra();
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void io::checkpoint(Stream &s) {
|
2023-09-27 09:35:18 +00:00
|
|
|
PIA::checkpoint(s);
|
2024-08-29 06:03:46 +00:00
|
|
|
_dsp.checkpoint(s);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void io::restore(Stream &s) {
|
2023-09-27 09:35:18 +00:00
|
|
|
PIA::restore(s);
|
2024-08-29 06:03:46 +00:00
|
|
|
_dsp.restore(s);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|