system: Enable DUART log & BIOS stdout patching

This commit is contained in:
Jakub Czekański 2021-12-21 18:12:01 +01:00
parent dd517d8843
commit 6fe429ee76
2 changed files with 31 additions and 6 deletions

View file

@ -1,4 +1,5 @@
#include "expansion2.h"
#include "config.h"
#include <cstdio>
Expansion2::Expansion2() { reset(); }
@ -6,16 +7,26 @@ Expansion2::Expansion2() { reset(); }
void Expansion2::reset() { post = 0; }
uint8_t Expansion2::read(uint32_t address) {
(void)address;
if (address == 0x21) { // DUART Status
return 1 << 2; // Tx Empty
}
return 0;
}
void Expansion2::write(uint32_t address, uint8_t data) {
if (address == 0x41) {
if (address == 0x22) { // DUART Command
// Ignore (Enable Tx/Rx, reset/flush commands)
} else if (address == 0x23) { // DUART Tx
if (config.debug.log.system) {
putchar(data);
}
} else if (address == 0x24) { // DUART Aux Control
// Ignore (baud rate, int flags)
} else if (address == 0x41) {
post = data;
}
// PCSX-Redux/Openbios stdout channel
if (address == 0x80) {
putchar(data);
} else if (address == 0x80) { // PCSX-Redux/Openbios stdout channel
if (config.debug.log.system) {
putchar(data);
}
}
}

View file

@ -498,6 +498,20 @@ bool System::loadBios(const std::string& path) {
this->biosPath = path;
state = State::run;
biosLoaded = true;
auto patch = [&](uint32_t address, uint32_t opcode) {
address &= bios.size() - 1;
for (int i = 0; i < 4; i++) {
bios[address + i] = (opcode >> (i * 8)) & 0xff;
}
};
if (config.debug.log.system) {
fmt::print("[INFO] Patching BIOS for system log\n");
patch(0x6F0C, 0x24010001);
patch(0x6F14, 0xAF81A9C0);
}
return true;
}