-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrom_device.cpp
57 lines (40 loc) · 1.15 KB
/
rom_device.cpp
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
#include <stdlib.h>
#include <stdio.h>
#include "rom_device.h"
ROMDevice::ROMDevice(char* image_path, word32 base, word32 size) {
auto image_file = fopen(image_path, "rb");
if(!image_file)
return;
this->_StorageArea = (byte*)malloc(size);
if (this->_StorageArea == NULL) {
fclose(image_file);
return;
}
#ifdef _WIN32
fread_s(this->_StorageArea, size, 1, size, image_file);
#else
fread(this->_StorageArea, 1, size, image_file);
#endif
fclose(image_file);
this->AddResponseRange(base, base + size - 1, RW_MASK_R);
this->_InitOk = true;
}
ROMDevice::~ROMDevice() {
if(this->_StorageArea != NULL)
free(this->_StorageArea);
}
bool ROMDevice::_InternalReadByte(word32 address, word32 timestamp, word32 emulFlags, ResponseRange* range, byte &b) {
b = this->_StorageArea != NULL ?
this->_StorageArea[address - range->Start()] :
0xFF;
return true;
}
bool ROMDevice::_InternalWriteByte(word32 address, word32 timestamp, ResponseRange* range, byte b) {
//We didn't register to respond to a writable area, so this should actually
//never get called
return false;
}
bool ROMDevice::Refresh(word32 timestamp) {
//Nothing to refresh
return false;
}