-
Notifications
You must be signed in to change notification settings - Fork 0
/
Apple1.ino
145 lines (121 loc) · 2.32 KB
/
Apple1.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <stdarg.h>
#include <SPI.h>
#include <r65emu.h>
#include <r6502.h>
#include <pia.h>
#include <sd_filer.h>
#include "io.h"
#include "disp.h"
#include "screen_disp.h"
#include "terminal_disp.h"
#include "config.h"
#if defined(KRUSADER)
#include "roms/krusader6502.h"
prom k(krusader6502, sizeof(krusader6502));
#else
#include "roms/basic.h"
#include "roms/monitor.h"
prom b(basic, sizeof(basic));
prom m(monitor, sizeof(monitor));
#endif
ram<> pages[RAM_PAGES];
//socket_filer files("apple1");
#if defined(USE_SD)
sd_filer files(PROGRAMS);
#else
flash_filer files(PROGRAMS);
#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);
Memory memory;
r6502 cpu(memory);
void reset() {
bool ok = hardware_reset();
io.reset();
if (!ok) {
dsp.status("Reset failed");
return;
}
if (!io.start()) {
dsp.status("IO Start failed");
return;
}
#if defined(KRUSADER)
dsp.status("Krusader: F000R / Basic: E000R");
#else
dsp.status("Basic: E000R");
#endif
}
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:
filename = open(io.files.advance());
break;
case 3:
filename = open(io.files.rewind());
break;
case 5:
io.load();
break;
case 7:
dsp.status(io.files.checkpoint());
break;
case 8:
if (filename)
io.files.restore(filename);
break;
case 10:
hardware_debug_cpu();
break;
}
}
void setup() {
hardware_init(cpu);
DBG(print("RAM: "));
DBG(print(RAM_PAGES));
DBG(print("kB at 0x0000"));
DBG(println());
for (unsigned i = 0; i < RAM_PAGES; i++)
memory.put(pages[i], i * ram<>::page_size);
#if defined(USE_SPIRAM)
DBG(print("SpiRAM: "));
DBG(print(SPIRAM_EXTENT * Memory::page_size / 1024));
DBG(print("kB at 0x"));
DBG(print(SPIRAM_BASE, 16));
DBG(println());
memory.put(sram, SPIRAM_BASE, SPIRAM_EXTENT);
#endif
memory.put(io, 0xd000);
#if defined(KRUSADER)
memory.put(k, 0xe000);
#else
memory.put(b, 0xe000);
memory.put(m, 0xff00);
#endif
kbd.register_fnkey_handler(function_key);
reset();
}
void loop() {
hardware_run();
}