Apple1-esp/Apple1.ino

138 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
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;
}
2023-09-27 12:55:10 +00:00
io.start();
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
}
void function_key(uint8_t fn) {
static const char *filename;
switch(fn) {
case 1:
reset();
break;
case 2:
filename = io.files.advance();
dsp.status(filename);
break;
case 3:
filename = io.files.rewind();
dsp.status(filename);
break;
case 4:
io.load();
break;
case 6:
dsp.status(io.files.checkpoint());
break;
case 7:
if (filename)
io.files.restore(filename);
break;
case 10:
hardware_debug_cpu();
break;
}
}
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
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
}