Update SnesToPc and PcToSnes

This commit is contained in:
scawful
2023-08-18 10:28:11 -04:00
parent 26f6531c9d
commit 7776dd1a15
2 changed files with 11 additions and 3 deletions

View File

@@ -7,14 +7,20 @@ namespace yaze {
namespace app { namespace app {
namespace core { namespace core {
unsigned int SnesToPc(unsigned int addr) { uint32_t SnesToPc(uint32_t addr) {
if (addr >= 0x808000) { if (addr >= 0x808000) {
addr -= 0x808000; addr -= 0x808000;
} }
unsigned int temp = (addr & 0x7FFF) + ((addr / 2) & 0xFF8000); uint32_t temp = (addr & 0x7FFF) + ((addr / 2) & 0xFF8000);
return (temp + 0x0); return (temp + 0x0);
} }
uint32_t PcToSnes(uint32_t addr) {
if (addr >= 0x400000) return -1;
addr = ((addr << 1) & 0x7F0000) | (addr & 0x7FFF) | 0x8000;
return addr;
}
int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) { int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) {
return (addr1 << 16) | (addr2 << 8) | addr3; return (addr1 << 16) | (addr2 << 8) | addr3;
} }

View File

@@ -9,7 +9,9 @@ namespace yaze {
namespace app { namespace app {
namespace core { namespace core {
unsigned int SnesToPc(unsigned int addr); uint32_t SnesToPc(uint32_t addr);
uint32_t PcToSnes(uint32_t addr);
int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3); int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3);
int HexToDec(char *input, int length); int HexToDec(char *input, int length);
bool StringReplace(std::string &str, const std::string &from, bool StringReplace(std::string &str, const std::string &from,