Managed to get loading the ROM and graphics decompression/overworld tile building stuff to compile, now it's just a matter of translating that data into the Bitmap to display properly.

This commit is contained in:
Justin Scofield
2022-06-10 23:51:00 -04:00
parent 2ad2e3c199
commit 31bf9dad4b
12 changed files with 244 additions and 160 deletions

View File

@@ -7,23 +7,21 @@ namespace Utils {
using namespace Graphics;
void ROM::LoadFromFile(const std::string& path) {
std::cout << "filename: " << path << std::endl;
std::ifstream stream(path, std::ios::in | std::ios::binary);
if (!stream.good()) {
std::cout << "failure reading file" << std::endl;
return;
}
FILE * file = fopen(path.c_str(), "r+");
if (file == NULL) return;
fseek(file, 0, SEEK_END);
long int size = ftell(file);
fclose(file);
std::vector<char> contents((std::istreambuf_iterator<char>(stream)),
std::istreambuf_iterator<char>());
std::cout << "size: " << size << std::endl;
for (auto i : contents) {
int value = i;
std::cout << "working_rom_: " << value << std::endl;
}
// Reading data to array of unsigned chars
file = fopen(path.c_str(), "r+");
current_rom_ = (unsigned char *) malloc(size);
int bytes_read = fread(current_rom_, sizeof(unsigned char), size, file);
fclose(file);
std::cout << "file size: " << contents.size() << std::endl;
}
int ROM::SnesToPc(int addr) {
@@ -60,44 +58,44 @@ short ROM::AddressFromBytes(byte addr1, byte addr2) {
return (short)((addr1 << 8) | (addr2));
}
void ROM::Write(int addr, byte value) { working_rom_[addr] = value; }
void ROM::Write(int addr, byte value) { current_rom_[addr] = value; }
void ROM::WriteLong(int addr, int value) {
working_rom_[addr] = (byte)(value & 0xFF);
working_rom_[addr + 1] = (byte)((value >> 8) & 0xFF);
working_rom_[addr + 2] = (byte)((value >> 16) & 0xFF);
current_rom_[addr] = (byte)(value & 0xFF);
current_rom_[addr + 1] = (byte)((value >> 8) & 0xFF);
current_rom_[addr + 2] = (byte)((value >> 16) & 0xFF);
}
void ROM::WriteShort(int addr, int value) {
working_rom_[addr] = (byte)(value & 0xFF);
working_rom_[addr + 1] = (byte)((value >> 8) & 0xFF);
current_rom_[addr] = (byte)(value & 0xFF);
current_rom_[addr + 1] = (byte)((value >> 8) & 0xFF);
}
int ROM::ReadLong(int addr) {
return ((working_rom_[addr + 2] << 16) + (working_rom_[addr + 1] << 8) +
working_rom_[addr]);
return ((current_rom_[addr + 2] << 16) + (current_rom_[addr + 1] << 8) +
current_rom_[addr]);
}
Tile16 ROM::ReadTile16(int addr) {
ushort t1 = (ushort)((working_rom_[addr + 1] << 8) + working_rom_[addr]);
ushort t2 = (ushort)((working_rom_[addr + 3] << 8) + working_rom_[addr + 2]);
ushort t3 = (ushort)((working_rom_[addr + 5] << 8) + working_rom_[addr + 4]);
ushort t4 = (ushort)((working_rom_[addr + 7] << 8) + working_rom_[addr + 6]);
ushort t1 = (ushort)((current_rom_[addr + 1] << 8) + current_rom_[addr]);
ushort t2 = (ushort)((current_rom_[addr + 3] << 8) + current_rom_[addr + 2]);
ushort t3 = (ushort)((current_rom_[addr + 5] << 8) + current_rom_[addr + 4]);
ushort t4 = (ushort)((current_rom_[addr + 7] << 8) + current_rom_[addr + 6]);
return Tile16((unsigned long)((t1 << 48) + (t2 << 32) + (t3 << 16) + t4));
}
ushort ROM::ReadShort(int addr) {
return (ushort)((working_rom_[addr + 1] << 8) + working_rom_[addr]);
return (ushort)((current_rom_[addr + 1] << 8) + current_rom_[addr]);
}
short ROM::ReadRealShort(int addr) {
return (short)((working_rom_[addr + 1] << 8) + working_rom_[addr]);
return (short)((current_rom_[addr + 1] << 8) + current_rom_[addr]);
}
ushort ROM::ReadByte(int addr) { return (ushort)(working_rom_[addr]); }
ushort ROM::ReadByte(int addr) { return (ushort)(current_rom_[addr]); }
short ROM::ReadReverseShort(int addr) {
return (short)((working_rom_[addr] << 8) + working_rom_[addr + 1]);
return (short)((current_rom_[addr] << 8) + current_rom_[addr + 1]);
}
} // namespace Utils