Apple1-esp/Apple1.ino

146 lines
2.3 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 "disp.h"
#include "screen_disp.h"
#include "terminal_disp.h"
2014-11-11 17:13:25 +00:00
#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
#if defined(PS2_SERIAL_KBD)
ps2_serial_kbd kbd;
#else
hw_serial_kbd kbd(Serial);
#endif
#if defined(SCREEN_SERIAL_DSP)
screen_disp dsp;
#else
terminal_disp dsp(Serial);
#endif
io io(files, kbd, dsp);
2014-11-11 17:13:25 +00:00
2024-09-22 08:19:19 +00:00
Memory memory;
2016-01-23 21:15:44 +00:00
r6502 cpu(memory);
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) {
dsp.status("Reset failed");
2019-03-28 18:02:50 +00:00
return;
}
2024-10-12 13:40:22 +00:00
if (!io.start()) {
dsp.status("IO Start failed");
return;
}
2019-03-28 18:02:50 +00:00
#if defined(KRUSADER)
dsp.status("Krusader: F000R / Basic: E000R");
2019-03-28 18:02:50 +00:00
#else
dsp.status("Basic: E000R");
2019-03-28 18:02:50 +00:00
#endif
2014-11-11 17:13:25 +00:00
}
2024-10-12 13:40:22 +00:00
static const char *open(const char *filename) {
if (filename) {
dsp.status(filename);
return filename;
}
dsp.status("No file");
return 0;
}
void function_key(uint8_t fn) {
static const char *filename;
switch(fn) {
case 1:
reset();
break;
case 2:
2024-10-12 13:40:22 +00:00
filename = open(io.files.advance());
break;
case 3:
2024-10-12 13:40:22 +00:00
filename = open(io.files.rewind());
break;
2024-10-12 13:40:22 +00:00
case 5:
io.load();
break;
2024-10-12 13:40:22 +00:00
case 7:
dsp.status(io.files.checkpoint());
break;
2024-10-12 13:40:22 +00:00
case 8:
if (filename)
io.files.restore(filename);
break;
case 10:
hardware_debug_cpu();
break;
}
}
2014-11-11 17:13:25 +00:00
void setup() {
2024-10-12 13:40:22 +00:00
2014-11-11 17:13:25 +00:00
hardware_init(cpu);
2024-10-12 13:40:22 +00:00
DBG(print("RAM: "));
DBG(print(RAM_PAGES));
DBG(print("kB at 0x0000"));
DBG(println());
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)
2024-10-12 13:40:22 +00:00
DBG(print("SpiRAM: "));
DBG(print(SPIRAM_EXTENT * Memory::page_size / 1024));
DBG(print("kB at 0x"));
DBG(print(SPIRAM_BASE, 16));
DBG(println());
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
kbd.register_fnkey_handler(function_key);
2014-11-11 17:13:25 +00:00
reset();
}
void loop() {
hardware_run();
2014-11-11 17:13:25 +00:00
}