-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
90 lines (72 loc) · 1.55 KB
/
main.c
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
/*
* ROM for Tiny68k
*/
#include "proto.h"
#define STR(_x) #_x
#define XSTR(_x) STR(_x)
static const char *banner = "\n\n68k monitor for %s " XSTR(GITHASH) "\n";
static const char *auto_script = XSTR(AUTO_SCRIPT);
static void cmd_execute(const char *cmd);
static void cmd_script(const char *script);
void
main()
{
// initialize things
board_init();
interrupt_enable(true);
// signs of life
trace_fmt(banner, board_name);
fmt(banner, board_name);
cmd_script(auto_script);
// REPL
putln("\ntry 'help'");
for (;;) {
board_status(3);
puts("] ");
char *cmd;
if ((cmd = gets()) != NULL) {
cmd_execute(cmd);
}
}
}
static void
cmd_execute(const char *cmd)
{
int ret = -1;
if (strlen(cmd) > 0) {
for (cmd_handler_fn *cfp = &_commands; cfp < &_ecommands; cfp++) {
ret = (*cfp)(cmd);
if (ret >= 0) {
break;
}
}
}
if (ret < 0) {
putln("ERROR");
}
}
static void
cmd_script(const char *script)
{
while (*script) {
fmt("] %s\n", script);
cmd_execute(script);
script += strlen(script) + 1;
}
}
COMMAND(cmd_help);
static int
cmd_help(const char *input_buffer)
{
if (scan(input_buffer, "help") < 0) {
return -1;
}
puts("\n^K clears input line\n"
"^C aborts input\n\n"
"Commands:\n"
"=========\n");
for (cmd_handler_fn *cfp = &_commands; cfp < &_ecommands; cfp++) {
(*cfp)(NULL);
}
return 0;
}