Emulator: Add bitmask for additional safety in read/write functions

This commit is contained in:
Riyyi
2022-08-23 13:47:02 +02:00
parent 16235b4663
commit 80e15531f2
+5 -5
View File
@@ -392,27 +392,27 @@ void CPU::jp16()
uint32_t CPU::pcRead() uint32_t CPU::pcRead()
{ {
uint32_t data = Emu::the().readMemory(m_pc); uint32_t data = Emu::the().readMemory(m_pc) & 0x00ff;
m_pc = (m_pc + 1) & 0xffff; m_pc = (m_pc + 1) & 0xffff;
return data; return data;
} }
void CPU::write(uint32_t address, uint32_t value) void CPU::write(uint32_t address, uint32_t value)
{ {
Emu::the().writeMemory(address, value); Emu::the().writeMemory(address, value & 0x00ff);
} }
uint32_t CPU::read(uint32_t address) uint32_t CPU::read(uint32_t address)
{ {
return Emu::the().readMemory(address); return Emu::the().readMemory(address) & 0x00ff;
} }
void CPU::ffWrite(uint32_t address, uint32_t value) void CPU::ffWrite(uint32_t address, uint32_t value)
{ {
Emu::the().writeMemory(address | (0xff << 8), value); Emu::the().writeMemory(address | (0xff << 8), value & 0x00ff);
} }
uint32_t CPU::ffRead(uint32_t address) uint32_t CPU::ffRead(uint32_t address)
{ {
return Emu::the().readMemory(address | (0xff << 8)); return Emu::the().readMemory(address | (0xff << 8)) & 0x00ff;
} }