-
Notifications
You must be signed in to change notification settings - Fork 0
/
\
62 lines (35 loc) · 857 Bytes
/
\
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
#include <stdio.h>
#include "sc.h"
int sc_memoryInit() {
extern int memory[100];
for (int i = 0; i < 100; i++) memory[i] = 0;
return 0;
}
int sc_memorySet(int addr, int val) {
if (addr < 0 || addr > 99) return -1;
memory[addr] = val;
return 0;
}
int sc_memoryGet(int addr, int* val) {
if (addr < 0 || addr > 99) return -1;
val = memory[addr];
return 0;
}
int sc_memorySave(char* filename) {
FILE* file = fopen(filename, "wb");
if (file == NULL) return -1;
size_t count = fwrite(memory, sizeof(int), 100, file);
fclose(file);
if (count != 100) return -1;
return 0;
}
int sc_memoryLoad(char* filename) {
FILE* file = fopen(filename, "rb");
if (file == NULL) return -1;
size_t count = fread(memory, sizeof(int), 100, file);
fclose(file);
if (count != 100) return -1;
return 0;
}
int sc_regInit(void) {
}