Apple1-esp/Apple1.ino

123 lines
2.2 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>
2023-09-27 10:31:46 +00:00
#include <pia.h>
2023-10-12 17:29:06 +00:00
#include <sd_filer.h>
2014-11-11 17:13:25 +00:00
#include "io.h"
#include "config.h"
#if defined(KRUSADER)
#include "roms/krusader6502.h"
2019-03-28 18:02:50 +00:00
prom k(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
2023-11-18 12:38:44 +00:00
ram<> pages[RAM_PAGES];
2019-03-28 18:02:50 +00:00
//socket_filer files("apple1");
2023-10-12 17:29:06 +00:00
#if defined(USE_SD)
sd_filer files(PROGRAMS);
#else
2019-03-27 18:25:41 +00:00
flash_filer files(PROGRAMS);
2023-10-12 17:29:06 +00:00
#endif
2019-03-27 18:25:41 +00:00
io io(files);
2014-11-11 17:13:25 +00:00
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() {
2019-03-28 18:02:50 +00:00
bool ok = hardware_reset();
2014-11-14 11:45:28 +00:00
2014-11-11 17:13:25 +00:00
io.reset();
2019-03-28 18:02:50 +00:00
if (!ok) {
io.status("Reset failed");
return;
}
2023-09-27 12:55:10 +00:00
io.start();
2019-03-28 18:02:50 +00:00
#if defined(KRUSADER)
io.status("Krusader: F000R / Basic: E000R");
#else
io.status("Basic: E000R");
#endif
2014-11-11 17:13:25 +00:00
}
void setup() {
2020-07-08 13:34:55 +00:00
#if defined(DEBUGGING) || defined(CPU_DEBUG)
Serial.begin(TERMINAL_SPEED);
2021-02-20 09:13:46 +00:00
Serial.println();
2023-07-28 12:08:15 +00:00
Serial.print("RAM: ");
Serial.print(RAM_PAGES);
Serial.print("kB at 0x0000");
2021-02-20 09:13:46 +00:00
Serial.println();
#if defined(USE_SPIRAM)
2023-07-28 12:08:15 +00:00
Serial.print("SpiRAM: ");
Serial.print(SPIRAM_EXTENT * Memory::page_size / 1024);
Serial.print("kB at 0x");
Serial.print(SPIRAM_BASE, 16);
2021-02-20 09:13:46 +00:00
Serial.println();
#endif
2020-07-08 13:34:55 +00:00
#endif
2014-11-11 17:13:25 +00:00
hardware_init(cpu);
2021-02-20 09:13:46 +00:00
for (unsigned i = 0; i < RAM_PAGES; i++)
2023-11-18 12:38:44 +00:00
memory.put(pages[i], i * ram<>::page_size);
2014-11-11 17:13:25 +00:00
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
2021-02-20 09:13:46 +00:00
2014-11-11 17:13:25 +00:00
memory.put(io, 0xd000);
2021-02-20 09:13:46 +00:00
#if defined(KRUSADER)
2019-03-28 18:02:50 +00:00
memory.put(k, 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:
2019-02-13 07:47:59 +00:00
filename = io.files.advance();
2014-11-14 11:45:28 +00:00
io.status(filename);
break;
case PS2_F3:
2019-02-13 07:47:59 +00:00
filename = io.files.rewind();
2014-11-14 11:45:28 +00:00
io.status(filename);
break;
case PS2_F4:
io.load();
break;
2014-11-14 13:28:48 +00:00
case PS2_F6:
2019-02-13 07:47:59 +00:00
io.status(io.files.checkpoint());
2014-11-14 13:28:48 +00:00
break;
case PS2_F7:
if (filename)
2019-02-13 07:47:59 +00:00
io.files.restore(filename);
2014-11-14 13:28:48 +00:00
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);
}