-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdurangorom.cpp
More file actions
71 lines (56 loc) · 1.82 KB
/
durangorom.cpp
File metadata and controls
71 lines (56 loc) · 1.82 KB
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
70
/*
* SPDX-License-Identifier: LGPL v3.0
* Copyright (C) 2023 Durango Computer Team (durangoretro.com)
*/
#include "durangorom.h"
#include <cstring>
#include <fstream>
void DurangoRom::setName(std::string name){
this->name=name;
}
std::string DurangoRom::getName(){
return this->name;
}
DurangoHeader DurangoRom::getHeader(){
return this->header;
}
void DurangoRom::setHeader(DurangoHeader header){
this->header=header;
}
size_t DurangoRom::getRomSize(){
return this->romSize;
}
char * DurangoRom::getRomContent(){
return this->romContent;
}
DurangoRom * DurangoRom::readDurangoROMFile(std::string path){
std::string fileName= path.substr(path.find_last_of("/")+1);
fprintf(stderr,"Reading File...%s\n",fileName.c_str());
//Read Rom From disck
std::ifstream * romFile = new std::ifstream(path.c_str(),std::ios::binary);
romFile->seekg(0,romFile->end);
//get Rom Size
size_t romSize= romFile->tellg();
romFile->seekg(0,romFile->beg);
//Read all the rom content
char* content = new char[romSize];
fprintf(stderr,"Reading Content...%s\n",fileName.c_str());
romFile->read(content,romSize);
fprintf(stderr,"Content Readed...%s\n",fileName.c_str());
romFile->close();
return readDurangoROMFile(content, romSize);
}
DurangoRom* DurangoRom::readDurangoROMFile(char * romContent, size_t romSize){
DurangoRom* rom = new DurangoRom();
rom->romContent=romContent;
rom->romSize=romSize;
fprintf(stderr,"Reading Header...\n");
//Copy Header Info (first 256 bytes)
char headercontent[256];
memcpy(headercontent,romContent,256);
fprintf(stderr,"Header Readed...\n");
DurangoHeader* header = DurangoHeader::readDurangoHeader(headercontent);
rom->setHeader(*header);
rom->setName(header->getHeaderInformation().filename);
return rom;
}