-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrom.c
More file actions
39 lines (29 loc) · 753 Bytes
/
rom.c
File metadata and controls
39 lines (29 loc) · 753 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
#include <stdio.h>
#include <string.h>
#include "rom.h"
#include "MMU.h"
struct rom rom;
void romInit(char* filename) {
FILE *f;
unsigned char header[HEADER_SIZE];
int len;
int i;
f = fopen(filename,"rb");
fseek(f, 0, SEEK_END);
len = ftell(f);
rom.romBytes = malloc(len);
rewind(f);
fread(rom.romBytes, len, 1, f);
rewind(f);
fread(header, 1, HEADER_SIZE, f);
rom.romType = header[ROM_TYPE_OFFSET];
for (i = 0; i<16; i++) {
rom.gameTitle[i] = header[ROM_TITLE_OFFSET+i];
}
rom.romSize = header[ROM_SIZE_OFFSET];
rom.romSize = pow(2,rom.romSize+1) * 16;
rom.ramSize = header[ROM_RAM_OFFSET];
rom.ramSize = pow(4, rom.ramSize)/2;
memcpy(&cart[0x0000], &rom.romBytes[0x0000], 0x8000);
fclose(f);
}