Apple1-esp/apple1.ino

94 lines
1.6 KiB
Arduino
Raw Normal View History

2014-11-11 17:13:25 +00:00
#include <stdarg.h>
#include <SPI.h>
2018-11-13 18:09:14 +00:00
2018-11-16 10:26:53 +00:00
#include <r65emu.h>
2014-12-08 13:24:09 +00:00
#include <r6502.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 "config.h"
#if defined(KRUSADER)
#include "roms/krusader6502.h"
prom b(krusader6502, sizeof(krusader6502));
#else
#include "roms/basic.h"
#include "roms/monitor.h"
2014-11-11 17:13:25 +00:00
prom b(basic, sizeof(basic));
prom m(monitor, sizeof(monitor));
#endif
2014-11-11 17:13:25 +00:00
ram pages[RAM_SIZE / 1024];
io io;
2016-01-23 21:15:44 +00:00
r6502 cpu(memory);
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
}
void setup() {
Serial.begin(115200);
hardware_init(cpu);
for (unsigned i = 0; i < RAM_SIZE; i += 1024)
memory.put(pages[i / 1024], i);
2018-11-16 10:26:53 +00:00
#if defined(USE_SPIRAM)
2014-11-14 12:27:56 +00:00
memory.put(sram, SPIRAM_BASE, SPIRAM_EXTENT);
2018-11-13 18:09:14 +00:00
#endif
2014-11-11 17:13:25 +00:00
memory.put(io, 0xd000);
#if defined(KRUSADER)
memory.put(b, 0xe000);
#else
2014-11-11 17:13:25 +00:00
memory.put(b, 0xe000);
memory.put(m, 0xff00);
#endif
2014-11-11 17:13:25 +00:00
reset();
}
void loop() {
if (ps2.available()) {
2014-12-17 15:12:38 +00:00
unsigned scan = ps2.read2();
byte key = scan & 0xff;
2014-12-17 15:26:16 +00:00
if (is_down(scan))
2014-11-11 17:13:25 +00:00
io.down(key);
2014-11-14 13:28:48 +00:00
else
2014-11-11 17:13:25 +00:00
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-14 13:28:48 +00:00
case PS2_F6:
io.status(checkpoint(io.tape, PROGRAMS));
break;
case PS2_F7:
if (filename)
restore(io.tape, PROGRAMS, filename);
break;
2014-11-11 17:13:25 +00:00
default:
io.up(key);
break;
}
2016-01-23 21:15:44 +00:00
} else if (!cpu.halted())
2014-11-11 17:13:25 +00:00
cpu.run(CPU_INSTRUCTIONS);
}