2018-11-12 07:47:06 +00:00
|
|
|
#include <Stream.h>
|
|
|
|
#include <stdint.h>
|
2014-11-11 17:13:25 +00:00
|
|
|
#include <memory.h>
|
2018-11-12 07:47:06 +00:00
|
|
|
#include <tftdisplay.h>
|
2019-02-13 07:47:59 +00:00
|
|
|
#include <serialio.h>
|
|
|
|
#include <filer.h>
|
2014-11-12 08:28:32 +00:00
|
|
|
#include <keyboard.h>
|
2014-11-14 11:45:28 +00:00
|
|
|
#include <timed.h>
|
2014-11-11 17:13:25 +00:00
|
|
|
|
2014-11-17 20:00:40 +00:00
|
|
|
#include "pia.h"
|
2014-11-11 17:13:25 +00:00
|
|
|
#include "io.h"
|
|
|
|
#include "hardware.h"
|
2018-11-18 12:48:10 +00:00
|
|
|
#include "config.h"
|
2014-11-11 17:13:25 +00:00
|
|
|
|
|
|
|
#define ROWS 24
|
|
|
|
#define COLS 40
|
|
|
|
static unsigned r, c;
|
2014-11-12 08:28:32 +00:00
|
|
|
static char screen[ROWS][COLS];
|
|
|
|
|
2014-11-11 17:13:25 +00:00
|
|
|
void io::reset() {
|
2018-11-18 12:48:10 +00:00
|
|
|
TFTDisplay::begin(TFT_BG, TFT_FG, TFT_ORIENT);
|
2014-11-11 17:13:25 +00:00
|
|
|
clear();
|
2014-11-12 19:33:11 +00:00
|
|
|
_cy += 2;
|
2014-11-11 17:13:25 +00:00
|
|
|
|
2014-11-12 08:28:32 +00:00
|
|
|
r = c = 0;
|
|
|
|
for (int j = 0; j < ROWS; j++)
|
|
|
|
for (int i = 0; i < COLS; i++)
|
|
|
|
screen[j][i] = ' ';
|
|
|
|
|
2014-11-14 11:45:28 +00:00
|
|
|
_loading = false;
|
2014-11-17 20:00:40 +00:00
|
|
|
pia::reset();
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 08:28:32 +00:00
|
|
|
// ascii map for scan-codes
|
2018-08-14 10:00:03 +00:00
|
|
|
static const uint8_t scanmap[] = {
|
2014-11-11 17:13:25 +00:00
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x00
|
2014-11-17 20:33:28 +00:00
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0x09, 0x60, 0xff, // 0x08
|
2014-11-11 17:13:25 +00:00
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0x51, 0x31, 0xff, // 0x10
|
|
|
|
0xff, 0xff, 0x5a, 0x53, 0x41, 0x57, 0x32, 0xff, // 0x18
|
|
|
|
0xff, 0x43, 0x58, 0x44, 0x45, 0x34, 0x33, 0xff, // 0x20
|
|
|
|
0xff, 0x20, 0x56, 0x46, 0x54, 0x52, 0x35, 0xff, // 0x28
|
|
|
|
0xff, 0x4e, 0x42, 0x48, 0x47, 0x59, 0x36, 0xff, // 0x30
|
|
|
|
0xff, 0xff, 0x4d, 0x4a, 0x55, 0x37, 0x38, 0xff, // 0x38
|
|
|
|
0xff, 0x2c, 0x4b, 0x49, 0x4f, 0x30, 0x39, 0xff, // 0x40
|
|
|
|
0xff, 0x2e, 0x2f, 0x4c, 0x3b, 0x50, 0x2d, 0xff, // 0x48
|
|
|
|
0xff, 0xff, 0x27, 0xff, 0x5b, 0x3d, 0xff, 0xff, // 0x50
|
|
|
|
0xff, 0xff, 0x0d, 0x5d, 0xff, 0x23, 0xff, 0xff, // 0x58
|
2014-11-12 08:28:32 +00:00
|
|
|
0xff, 0x5c, 0xff, 0xff, 0xff, 0xff, 0x5f, 0xff, // 0x60
|
2014-11-11 17:13:25 +00:00
|
|
|
0xff, 0x31, 0xff, 0x34, 0x37, 0xff, 0xff, 0xff, // 0x68
|
2014-11-17 20:33:28 +00:00
|
|
|
0x30, 0x08, 0x32, 0x35, 0x36, 0x38, 0x1b, 0xff, // 0x70
|
2014-11-11 17:13:25 +00:00
|
|
|
0xff, 0x2b, 0x33, 0x2d, 0x2a, 0x39, 0xff, 0xff, // 0x78
|
|
|
|
};
|
|
|
|
|
2018-08-14 10:00:03 +00:00
|
|
|
static const uint8_t shiftmap[] = {
|
2014-11-12 08:28:32 +00:00
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x00
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x08
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x21, 0xff, // 0x10
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x22, 0xff, // 0x18
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0x24, 0x23, 0xff, // 0x20
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x25, 0xff, // 0x28
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x5e, 0xff, // 0x30
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0x26, 0x2a, 0xff, // 0x38
|
|
|
|
0xff, 0x3c, 0xff, 0xff, 0xff, 0x29, 0x28, 0xff, // 0x40
|
|
|
|
0xff, 0x3e, 0x3f, 0xff, 0x3a, 0xff, 0x5f, 0xff, // 0x48
|
|
|
|
0xff, 0xff, 0x40, 0xff, 0x7b, 0x2b, 0xff, 0xff, // 0x50
|
|
|
|
0xff, 0xff, 0xff, 0x7d, 0xff, 0x7e, 0xff, 0xff, // 0x58
|
|
|
|
0xff, 0x7c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x60
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x68
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x70
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x78
|
|
|
|
};
|
|
|
|
|
2018-08-14 10:00:03 +00:00
|
|
|
void io::down(uint8_t scan) {
|
2014-11-17 20:00:40 +00:00
|
|
|
set_porta(0);
|
2014-11-12 08:28:32 +00:00
|
|
|
if (isshift(scan))
|
|
|
|
_shift = true;
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:03 +00:00
|
|
|
void io::enter(uint8_t key) {
|
2014-11-17 20:00:40 +00:00
|
|
|
set_porta(key + 0x80);
|
2014-11-14 11:45:28 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:03 +00:00
|
|
|
void io::up(uint8_t scan) {
|
2014-11-12 08:28:32 +00:00
|
|
|
if (isshift(scan)) {
|
|
|
|
_shift = false;
|
|
|
|
return;
|
|
|
|
}
|
2014-11-14 11:45:28 +00:00
|
|
|
enter(_shift? shiftmap[scan]: scanmap[scan]);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 08:28:32 +00:00
|
|
|
void io::draw(char ch, int i, int j) {
|
|
|
|
if (screen[j][i] != ch) {
|
|
|
|
screen[j][i] = ch;
|
2014-11-12 19:33:11 +00:00
|
|
|
char c[2] = { ch, 0 };
|
2018-11-12 07:47:06 +00:00
|
|
|
drawString(c, i*_cx, j*_cy);
|
2014-11-12 08:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:03 +00:00
|
|
|
void io::display(uint8_t b) {
|
2014-11-11 17:13:25 +00:00
|
|
|
char ch = (char)b;
|
2014-11-12 08:28:32 +00:00
|
|
|
switch(ch) {
|
2014-11-12 19:33:11 +00:00
|
|
|
case 0x5f:
|
|
|
|
draw(' ', c, r);
|
2014-11-12 08:28:32 +00:00
|
|
|
if (c-- == 0) {
|
2014-11-11 17:13:25 +00:00
|
|
|
r--;
|
|
|
|
c = COLS-1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x0d:
|
2014-11-12 19:33:11 +00:00
|
|
|
draw(' ', c, r);
|
2014-11-11 17:13:25 +00:00
|
|
|
c = 0;
|
|
|
|
r++;
|
|
|
|
break;
|
|
|
|
default:
|
2014-11-12 19:33:11 +00:00
|
|
|
if (ch >= 0x20 && ch < 0x7f) {
|
2014-11-12 08:28:32 +00:00
|
|
|
draw(ch, c, r);
|
2014-11-11 17:13:25 +00:00
|
|
|
if (++c == COLS) {
|
|
|
|
c = 0;
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r == ROWS) {
|
|
|
|
// scroll
|
|
|
|
r--;
|
|
|
|
for (int j = 0; j < (ROWS-1); j++)
|
2014-11-12 08:28:32 +00:00
|
|
|
for (int i = 0; i < COLS; i++)
|
|
|
|
draw(screen[j+1][i], i, j);
|
|
|
|
for (int i = 0; i < COLS; i++)
|
|
|
|
draw(' ', i, ROWS-1);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
2014-11-12 19:33:11 +00:00
|
|
|
draw('_', c, r);
|
2014-11-11 17:13:25 +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;
|
|
|
|
display(b);
|
|
|
|
pia::write_portb(b);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:00:03 +00:00
|
|
|
uint8_t io::read_porta_cr() {
|
|
|
|
uint8_t b = pia::read_porta_cr();
|
2014-11-24 19:37:04 +00:00
|
|
|
if (b != 0xa7)
|
|
|
|
return b;
|
|
|
|
|
|
|
|
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;
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
2014-11-17 20:00:40 +00:00
|
|
|
return b;
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void io::checkpoint(Stream &s) {
|
2014-11-17 20:00:40 +00:00
|
|
|
pia::checkpoint(s);
|
2014-11-14 13:28:48 +00:00
|
|
|
s.write(r);
|
|
|
|
s.write(c);
|
|
|
|
for (int j = 0; j < ROWS; j++)
|
|
|
|
for (int i = 0; i < COLS; i++)
|
|
|
|
s.write(screen[j][i]);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void io::restore(Stream &s) {
|
2014-11-17 20:00:40 +00:00
|
|
|
pia::restore(s);
|
2014-11-14 13:28:48 +00:00
|
|
|
r = s.read();
|
|
|
|
c = s.read();
|
|
|
|
for (int j = 0; j < ROWS; j++)
|
|
|
|
for (int i = 0; i < COLS; i++) {
|
|
|
|
char c = s.read();
|
|
|
|
screen[j][i] = c;
|
|
|
|
draw(c, i, j);
|
|
|
|
}
|
|
|
|
draw('_', c, r);
|
2014-11-11 17:13:25 +00:00
|
|
|
}
|