loading programs

This commit is contained in:
Stephen Crane 2014-11-14 11:45:28 +00:00
parent 56b1e7e6ed
commit b68f563dc6
5 changed files with 47 additions and 13 deletions

View File

@ -1,4 +1,3 @@
- make TinyFont hardware-default?
- break out PIA abstraction
- loading programs from, e.g., http://www.brielcomputers.com/files/games.zip
- checkpoint and restore images (i.e., startrek)

View File

@ -29,10 +29,16 @@ void status(const char *fmt, ...) {
jmp_buf ex;
r6502 cpu(&memory, &ex, status);
bool halted = false;
const char *filename;
void reset() {
bool sd = hardware_reset();
io.reset();
if (sd)
io.tape.start(PROGRAMS);
else
io.status("No SD Card");
halted = (setjmp(ex) != 0);
}
@ -62,6 +68,17 @@ void loop() {
case PS2_F1:
reset();
break;
case PS2_F2:
filename = io.tape.advance();
io.status(filename);
break;
case PS2_F3:
filename = io.tape.rewind();
io.status(filename);
break;
case PS2_F4:
io.load();
break;
default:
io.up(key);
break;

View File

@ -6,5 +6,6 @@
#define TFT_FG VGA_LIME
#define TFT_BG VGA_BLACK
#define PROGRAMS "/apple1/"
#endif

35
io.cpp
View File

@ -1,7 +1,9 @@
#include <UTFT.h>
#include <memory.h>
#include <utftdisplay.h>
#include <sdtape.h>
#include <keyboard.h>
#include <timed.h>
#include "io.h"
#include "config.h"
@ -18,8 +20,7 @@ static char screen[ROWS][COLS];
#include "TinyFont.h"
void io::reset() {
utft.setFont((uint8_t *)TinyFont);
UTFTDisplay::begin(TFT_BG, TFT_FG);
UTFTDisplay::begin(TFT_BG, TFT_FG, (uint8_t *)TinyFont);
clear();
_cy += 2;
@ -28,11 +29,20 @@ void io::reset() {
for (int i = 0; i < COLS; i++)
screen[j][i] = ' ';
_loading = false;
// PIA state
dsp_cr = kbd_cr = 0;
kbd_int = dsp_out = 0;
}
void io::load() {
if (tape.more()) {
_loading = true;
enter(tape.read());
}
}
// ascii map for scan-codes
static const byte scanmap[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 0x00
@ -78,14 +88,17 @@ void io::down(byte scan) {
_shift = true;
}
void io::enter(byte key) {
kbd = key + 0x80;
kbd_cr = 0xa7;
}
void io::up(byte scan) {
if (isshift(scan)) {
_shift = false;
return;
}
byte m = _shift? shiftmap[scan]: scanmap[scan];
kbd = m + 0x80;
kbd_cr = 0xa7;
enter(_shift? shiftmap[scan]: scanmap[scan]);
}
void io::draw(char ch, int i, int j) {
@ -134,12 +147,10 @@ void io::display(byte b) {
void io::operator=(byte b) {
/*
Serial.print(">");
Serial.print(_acc, 16);
Serial.print(" ");
Serial.println(b, 16);
*/
switch(_acc % 4) {
case 0:
@ -170,22 +181,24 @@ io::operator byte() {
switch (_acc % 4) {
case 0:
/*
Serial.print("<");
Serial.print(_acc, 16);
Serial.print(" ");
Serial.println(kbd, 16);
*/
return kbd;
case 1:
if (kbd_int && kbd_cr >= 0x80) {
kbd_cr = 0;
/*
Serial.print("<");
Serial.print(_acc, 16);
Serial.print(" ");
Serial.println(0xa7, 16);
*/
if (_loading) {
if (tape.more())
enter(tape.read());
else
_loading = false;
}
return 0xa7;
}
//Serial.println(kbd_cr, 16);

6
io.h
View File

@ -1,7 +1,7 @@
#ifndef _IO_H
#define _IO_H
class io: public UTFTDisplay, public Keyboard {
class io: public UTFTDisplay, Keyboard {
public:
io(): UTFTDisplay(256) {}
@ -15,11 +15,15 @@ public:
void checkpoint(Stream &);
void restore(Stream &);
void load();
sdtape tape;
private:
void display(byte);
void draw(char, int, int);
void enter(byte);
bool _shift;
bool _loading;
};
#endif