-
Notifications
You must be signed in to change notification settings - Fork 0
/
emutos.c
81 lines (60 loc) · 1.71 KB
/
emutos.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
#ifdef WITH_EMUTOS
#include "proto.h"
#include "pffs/pff.h"
#define TOS_ROM_BASE 0x00e00000
typedef __attribute__((noreturn)) void (*entry_function)(void);
static const char *emutos_image_name = "EMUTOS.SYS";
static void
emutos_load()
{
uint8_t fs_buffer[4096];
FATFS fs;
board_status(8);
if (pf_mount(&fs) != FR_OK) {
putln("disk mount failed");
return;
}
if (pf_open(emutos_image_name) != FR_OK) {
fmt("%s not found\n", emutos_image_name);
return;
}
uintptr_t bp = TOS_ROM_BASE;
UINT resid = fs.fsize;
UINT br;
fmt("loading %s", emutos_image_name);
init_loader();
while (resid > 0) {
size_t to_read = (resid > sizeof(fs_buffer)) ? sizeof(fs_buffer) : resid;
if ((pf_read(fs_buffer, to_read, &br) != FR_OK)
|| (br == 0)) {
putln(" read error");
return;
}
loader_load_bytes(bp, fs_buffer, br);
resid -= br;
bp += br;
putc('.');
}
putc('\n');
const char *emutos_buffer = (const char *)TOS_ROM_BASE;
if (strncmp((char *)emutos_buffer + 0x2c, "ETOS", 4)) {
fmt("%s is not an EmuTOS image\n", emutos_image_name);
return;
}
uint32_t version_offset = *(uint32_t *)(emutos_buffer + 0x40);
fmt("EmuTOS version %s\n", emutos_buffer + version_offset);
loader_set_entry(TOS_ROM_BASE);
loader_go(0, 0);
}
COMMAND(emutos);
static int
emutos(const char *input_buffer)
{
if (input_buffer == NULL) {
putln("emutos load and run EMUTOS.SYS");
} else if (!strncasecmp(input_buffer, "emutos", 6)) {
emutos_load();
}
return -1;
}
#endif // WITH_EMUTOS