Porting ROM functions from ZScream
This commit is contained in:
@@ -18,19 +18,58 @@ void ROM::LoadFromFile(const std::string& path) {
|
||||
|
||||
for (auto i : contents) {
|
||||
int value = i;
|
||||
std::cout << "data: " << value << std::endl;
|
||||
std::cout << "working_rom_: " << value << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "file size: " << contents.size() << std::endl;
|
||||
}
|
||||
|
||||
unsigned int uncompressed_data_size = 0;
|
||||
unsigned int compressed_length = 0;
|
||||
auto gfx_decompressed_data = alttp_compressor_.DecompressGfx(
|
||||
contents.data(), 0, contents.size(), &uncompressed_data_size,
|
||||
&compressed_length);
|
||||
auto overworld_decompressed = alttp_compressor_.DecompressOverworld(
|
||||
contents.data(), 0, contents.size(), &uncompressed_data_size,
|
||||
&compressed_length);
|
||||
int ROM::SnesToPc(int addr) {
|
||||
if (addr >= 0x808000) {
|
||||
addr -= 0x808000;
|
||||
}
|
||||
int temp = (addr & 0x7FFF) + ((addr / 2) & 0xFF8000);
|
||||
return (temp + 0x0);
|
||||
}
|
||||
|
||||
void ROM::Write(int addr, byte value) { working_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);
|
||||
}
|
||||
|
||||
void ROM::WriteShort(int addr, int value) {
|
||||
working_rom_[addr] = (byte)(value & 0xFF);
|
||||
working_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]);
|
||||
}
|
||||
|
||||
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]);
|
||||
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]);
|
||||
}
|
||||
|
||||
short ROM::ReadRealShort(int addr) {
|
||||
return (short)((working_rom_[addr + 1] << 8) + working_rom_[addr]);
|
||||
}
|
||||
|
||||
ushort ROM::ReadByte(int addr) { return (ushort)(working_rom_[addr]); }
|
||||
|
||||
short ROM::ReadReverseShort(int addr) {
|
||||
return (short)((working_rom_[addr] << 8) + working_rom_[addr + 1]);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -10,22 +10,38 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Compression.h"
|
||||
#include "Core/Constants.h"
|
||||
#include "Data/Tile.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Utils {
|
||||
|
||||
using byte = unsigned char;
|
||||
using ushort = unsigned short;
|
||||
using namespace Data;
|
||||
|
||||
class ROM {
|
||||
public:
|
||||
int SnesToPc(int addr);
|
||||
ushort ReadShort(int addr);
|
||||
void Write(int addr, byte value);
|
||||
short ReadReverseShort(int addr);
|
||||
ushort ReadByte(int addr);
|
||||
short ReadRealShort(int addr);
|
||||
Tile16 ReadTile16(int addr);
|
||||
void WriteShort(int addr, int value);
|
||||
int ReadLong(int addr);
|
||||
void WriteLong(int addr, int value) ;
|
||||
void LoadFromFile(const std::string& path);
|
||||
inline const char * GetRawData() {
|
||||
return working_rom_.data();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<char*> original_rom_;
|
||||
std::vector<std::unique_ptr<char>> working_rom_;
|
||||
std::vector<char> original_rom_;
|
||||
std::vector<char> working_rom_;
|
||||
|
||||
ALTTPCompression alttp_compressor_;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user