Apple1-esp/apple1.ino

91 lines
1.5 KiB
Arduino
Raw Normal View History

2014-11-11 17:13:25 +00:00
#include <stdarg.h>
#include <SPI.h>
#include <SD.h>
#include <SpiRAM.h>
#include <UTFT.h>
#include <r65emu.h>
#include "roms/basic.h"
#include "roms/monitor.h"
#include "io.h"
#include "config.h"
prom b(basic, sizeof(basic));
prom m(monitor, sizeof(monitor));
ram pages[RAM_SIZE / 1024];
io io;
void status(const char *fmt, ...) {
char tmp[256];
va_list args;
va_start(args, fmt);
vsnprintf(tmp, sizeof(tmp), fmt, args);
Serial.println(tmp);
io.clear();
io.error(tmp);
va_end(args);
}
jmp_buf ex;
r6502 cpu(&memory, &ex, status);
bool halted = false;
2014-11-14 11:45:28 +00:00
const char *filename;
2014-11-11 17:13:25 +00:00
void reset() {
bool sd = hardware_reset();
2014-11-14 11:45:28 +00:00
2014-11-11 17:13:25 +00:00
io.reset();
2014-11-14 11:45:28 +00:00
if (sd)
io.tape.start(PROGRAMS);
else
io.status("No SD Card");
2014-11-11 17:13:25 +00:00
halted = (setjmp(ex) != 0);
}
void setup() {
Serial.begin(115200);
Serial.println("hello world");
hardware_init(cpu);
for (unsigned i = 0; i < RAM_SIZE; i += 1024)
memory.put(pages[i / 1024], i);
2014-11-14 12:27:56 +00:00
memory.put(sram, SPIRAM_BASE, SPIRAM_EXTENT);
2014-11-11 17:13:25 +00:00
memory.put(io, 0xd000);
memory.put(b, 0xe000);
memory.put(m, 0xff00);
reset();
}
void loop() {
if (ps2.available()) {
unsigned key = ps2.read();
if (!ps2.isbreak())
io.down(key);
else {
switch (key) {
case PS2_F1:
reset();
break;
2014-11-14 11:45:28 +00:00
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;
2014-11-11 17:13:25 +00:00
default:
io.up(key);
break;
}
}
} else if (!halted)
cpu.run(CPU_INSTRUCTIONS);
}