This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
forked from gek169/SISA64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emu_frontend.c
69 lines (59 loc) · 1.71 KB
/
emu_frontend.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
/*
* Loader for SISA64
* Loads binaries from disk into memory.
Written by Escapechar
*/
#include <stdio.h>
#include "sisa64.h"
#include "stringutil.h"
#include <stdlib.h>
int main(int argc, char **argv) {
FILE *fhandle;
char *image_path = "a.bin";
unsigned long long image_length;
/*
if (argc == 1) {
fprintf(stderr, "sisa64_loader: a binary image must be specified.\n");
return -1;
}
*/
if(argc > 1){
if(streq(argv[1], "-v")){
puts("SISA64 emulator frontend, written originally by Escapechar-dev");
puts("He has agreed to place it into the public domain.");
puts("\nUsage: s64e /path/to/image.bin");
exit(0);
}
}
if(argc > 1)
image_path = argv[1];
fhandle = fopen(image_path, "rb");
if (!fhandle) {
fprintf(stderr, "sisa64_loader: binary image '%s' cannot be found or cannot be accessed.\n",
image_path);
return -1;
}
fseek(fhandle, 0, SEEK_END);
image_length = ftell(fhandle);
rewind(fhandle);
if (image_length > SYS_MEMORY_SIZE) {
fprintf(stderr, "sisa64_loader: binary image is too large (max is %llu)\n",
(unsigned long long)SYS_MEMORY_SIZE);
return -1;
}
if(!sisa64_mem) sisa64_mem = malloc((int64_t)SYS_MEMORY_SIZE);
if(!sisa64_mem) {
puts("Initial memory allocation failed.");
exit(1);
}
if (fread(sisa64_mem, 1, image_length, fhandle) < image_length) {
fprintf(stderr, "sisa64_loader: failed to read byte(s) from image.\n");
return -1;
}
di();
sisa64_emulate();
/*TODO: if the system still has cores running, do not call dcl()*/
dcl();
fclose(fhandle);
return 0;
}