forked from udo-munk/Arduino8080
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.h
144 lines (129 loc) · 3.04 KB
/
config.h
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
//
// Intel 8080 CPU emulation on an Arduino Nano
// derived from Z80PACK
// Copyright 2024, Udo Munk
//
// With this module the machine can be configured to run standalone
// software loaded from a file. Also allows to mount/unmount disk
// images with OS's and application software.
//
// History:
// 19-MAY-2024 implemented configuration dialog
// 21-MAY-2024 added mount/unmount of disk images
//
#define BS 0x08 // backspace
#define DEL 0x7f // delete
// read a config command line from the terminal
void get_cmdline(char *buf, int len)
{
int i = 0;
char c;
while (i < len - 1) {
while (!Serial.available())
;
c = Serial.read();
if ((c == BS) || (c == DEL)) {
if (i >= 1) {
Serial.write(BS);
Serial.write(' ');
Serial.write(BS);
i--;
}
} else if (c != '\r') {
buf[i] = c;
Serial.write(c);
i++;
} else {
break;
}
}
buf[i] = '\0';
}
// promt for a filename
static void prompt_fn(char *s)
{
Serial.print(F("Filename: "));
get_cmdline(s, 9);
Serial.println();
}
// configuration dialog for the machine
void config(void)
{
const char *cfg = "/CONF80/CFG.TXT";
char s[10];
int go_flag = 0;
// try to read config file
if (sd_file.openExistingSFN(cfg)) {
sd_file.read(&fp_value, 1);
sd_file.read(&disks[0], 22);
sd_file.read(&disks[1], 22);
sd_file.close();
}
while (!go_flag) {
Serial.print(F("1 - port 255: 0x"));
Serial.println(fp_value, HEX);
Serial.println(F("2 - load file"));
Serial.print(F("3 - Disk 0: "));
Serial.println(disks[0]);
Serial.print(F("4 - Disk 1: "));
Serial.println(disks[1]);
Serial.println(F("5 - run machine\n"));
Serial.print(F("Command: "));
get_cmdline(s, 2);
Serial.println(F("\n"));
switch (*s) {
case '1':
again:
Serial.print(F("Value: "));
get_cmdline(s, 3);
Serial.println(F("\n"));
if ((*s >= 'a') && (*s <= 'f'))
*s = toupper(*s);
if ((*(s + 1) >= 'a') && (*(s + 1) <= 'f'))
*(s + 1) = toupper(*(s + 1));
if (!isxdigit(*s) || !isxdigit(*(s + 1))) {
Serial.println(F("What?"));
goto again;
}
fp_value = (*s <= '9') ? (*s - '0') : (*s - 'A' + 10);
fp_value <<= 4;
fp_value += (*(s + 1) <= '9') ? (*(s + 1) - '0') :
(*(s + 1) - 'A' + 10);
break;
case '2':
prompt_fn(s);
load_file(s);
break;
case '3':
prompt_fn(s);
if (strlen(s) == 0) {
disks[0][0] = 0x0;
Serial.println();
} else {
mount_disk(0, s);
}
break;
case '4':
prompt_fn(s);
if (strlen(s) == 0) {
disks[1][0] = 0x0;
Serial.println();
} else {
mount_disk(1, s);
}
break;
case '5':
go_flag = 1;
break;
default:
break;
}
}
// try to save config file
if (sd_file.openExistingSFN(cfg)) {
sd_file.write(&fp_value, 1);
sd_file.write(&disks[0], 22);
sd_file.write(&disks[1], 22);
sd_file.close();
}
}