From b68f563dc60a1576715ba2068432a1ffd4174a52 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Fri, 14 Nov 2014 11:45:28 +0000 Subject: [PATCH] loading programs --- TODO.md | 1 - apple1.ino | 17 +++++++++++++++++ config.h | 1 + io.cpp | 35 ++++++++++++++++++++++++----------- io.h | 6 +++++- 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index f19eee3..18d19bc 100644 --- a/TODO.md +++ b/TODO.md @@ -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) diff --git a/apple1.ino b/apple1.ino index 1039764..3e5f160 100644 --- a/apple1.ino +++ b/apple1.ino @@ -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; diff --git a/config.h b/config.h index fe5e90f..6eaefcc 100644 --- a/config.h +++ b/config.h @@ -6,5 +6,6 @@ #define TFT_FG VGA_LIME #define TFT_BG VGA_BLACK +#define PROGRAMS "/apple1/" #endif diff --git a/io.cpp b/io.cpp index 7209e84..a561245 100644 --- a/io.cpp +++ b/io.cpp @@ -1,7 +1,9 @@ #include #include #include +#include #include +#include #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); diff --git a/io.h b/io.h index fdf0a98..b6aa086 100644 --- a/io.h +++ b/io.h @@ -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