Updating ROM library object

This commit is contained in:
Justin Scofield
2022-06-10 13:07:01 -04:00
parent afb7e33de9
commit ccb4e588d6
2 changed files with 35 additions and 8 deletions

View File

@@ -4,6 +4,8 @@ namespace yaze {
namespace Application { namespace Application {
namespace Utils { namespace Utils {
using namespace Graphics;
void ROM::LoadFromFile(const std::string& path) { void ROM::LoadFromFile(const std::string& path) {
std::cout << "filename: " << path << std::endl; std::cout << "filename: " << path << std::endl;
std::ifstream stream(path, std::ios::in | std::ios::binary); std::ifstream stream(path, std::ios::in | std::ios::binary);
@@ -32,6 +34,32 @@ int ROM::SnesToPc(int addr) {
return (temp + 0x0); return (temp + 0x0);
} }
// TODO: FIXME
int ROM::PcToSnes(int addr) {
byte b[4];
// = BitConverter.GetBytes(addr)
b[2] = (byte)(b[2] * 2);
if (b[1] >= 0x80) {
b[2] += 1;
} else {
b[1] += 0x80;
}
//return BitConverter.ToInt32(b, 0);
// snes always have + 0x8000 no matter what, the bank on pc is always / 2
return ((addr * 2) & 0xFF0000) + (addr & 0x7FFF) + 0x8000;
}
int ROM::AddressFromBytes(byte addr1, byte addr2, byte addr3) {
return (addr1 << 16) | (addr2 << 8) | addr3;
}
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) { working_rom_[addr] = value; }
void ROM::WriteLong(int addr, int value) { void ROM::WriteLong(int addr, int value) {

View File

@@ -11,7 +11,7 @@
#include <vector> #include <vector>
#include "Core/Constants.h" #include "Core/Constants.h"
#include "Data/Tile.h" #include "Graphics/Tile.h"
namespace yaze { namespace yaze {
namespace Application { namespace Application {
@@ -19,29 +19,28 @@ namespace Utils {
using byte = unsigned char; using byte = unsigned char;
using ushort = unsigned short; using ushort = unsigned short;
using namespace Data;
class ROM { class ROM {
public: public:
int SnesToPc(int addr); int SnesToPc(int addr);
int PcToSnes(int addr);
int AddressFromBytes(byte addr1, byte addr2, byte addr3);
short AddressFromBytes(byte addr1, byte addr2);
ushort ReadShort(int addr); ushort ReadShort(int addr);
void Write(int addr, byte value); void Write(int addr, byte value);
short ReadReverseShort(int addr); short ReadReverseShort(int addr);
ushort ReadByte(int addr); ushort ReadByte(int addr);
short ReadRealShort(int addr); short ReadRealShort(int addr);
Tile16 ReadTile16(int addr); Graphics::Tile16 ReadTile16(int addr);
void WriteShort(int addr, int value); void WriteShort(int addr, int value);
int ReadLong(int addr); int ReadLong(int addr);
void WriteLong(int addr, int value) ; void WriteLong(int addr, int value);
void LoadFromFile(const std::string& path); void LoadFromFile(const std::string& path);
inline const char * GetRawData() { inline const char* GetRawData() { return working_rom_.data(); }
return working_rom_.data();
}
private: private:
std::vector<char> original_rom_; std::vector<char> original_rom_;
std::vector<char> working_rom_; std::vector<char> working_rom_;
}; };
} // namespace Utils } // namespace Utils