This source file includes following definitions.
- addcerrlist_load
- loadassemble
1 #include <stdio.h>
2 #include <string.h>
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <ctype.h>
6
7 #include "word.h"
8 #include "struct.h"
9 #include "cerr.h"
10
11
12
13
14 static CERR cerr_load[] = {
15 { 210, "load - memory overflow" },
16 { 211, "object file not specified" },
17 { 212, "invalid option" },
18 { 213, "invalid argument" },
19 };
20
21
22 void addcerrlist_load()
23 {
24 addcerrlist(ARRAYSIZE(cerr_load), cerr_load);
25 }
26
27 WORD loadassemble(const char *file, WORD start)
28 {
29 FILE *fp = NULL;
30 WORD end = 0;
31
32 assert(file != NULL);
33 if((fp = fopen(file, "rb")) == NULL) {
34 perror(file);
35 return 0;
36 }
37 end = start + fread(sys->memory + start, sizeof(WORD), sys->memsize - start, fp);
38 if(end == sys->memsize) {
39 setcerr(210, file);
40 fprintf(stderr, "Load error - %d: %s\n", cerr->num, cerr->msg);
41 }
42 fclose(fp);
43 return end;
44 }