mirror of
https://github.com/Creased/RCM-Emulator.git
synced 2026-12-06 02:48:11 +01:00
Track per-port UART TX log and host-injected RX FIFO
This commit is contained in:
1 parent
76ebbf2f98
commit
e527872acb
2 files changed
+65
-19
No files matched your search
+21
@@ -4,6 +4,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <deque>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -289,6 +290,26 @@ struct EmuState {
|
|||||||
std::atomic<uint32_t> touch_fw_id{0x32000001}; // displayed as 4CD60D/<n>
|
std::atomic<uint32_t> touch_fw_id{0x32000001}; // displayed as 4CD60D/<n>
|
||||||
std::atomic<uint16_t> touch_ftb_ver{0x0123};
|
std::atomic<uint16_t> touch_ftb_ver{0x0123};
|
||||||
std::atomic<uint16_t> touch_fw_rev{0x4567}; // Hekate byte-swaps before printing
|
std::atomic<uint16_t> touch_fw_rev{0x4567}; // Hekate byte-swaps before printing
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Per-UART scratch state used by the in-emulator UART console.
|
||||||
|
// ============================================================
|
||||||
|
// Tegra X1 has UART_A..UART_E (5 ports). The mmio dispatcher for the
|
||||||
|
// 0x70006000 region uses (addr & 0x1FF) / 0x40 to derive the port idx.
|
||||||
|
//
|
||||||
|
// - uart_tx_log[idx] mirrors every byte the payload writes to that
|
||||||
|
// port's TX register, so the console window can render scrolling
|
||||||
|
// history without having to re-parse stdout. Capped at ~64 KB by a
|
||||||
|
// simple "drop the front when too big" trim.
|
||||||
|
// - uart_rx_fifo[idx] is bytes the host has typed in the console
|
||||||
|
// window awaiting consumption by the next UART read (RBR via
|
||||||
|
// offset 0x00, with bit 0 of LSR at offset 0x14 set when non-empty).
|
||||||
|
//
|
||||||
|
// The CPU-emulation hooks and the ImGui console both run on the main
|
||||||
|
// thread between SDL polls, so no locking is required.
|
||||||
|
static constexpr size_t N_UARTS = 5;
|
||||||
|
std::string uart_tx_log[N_UARTS];
|
||||||
|
std::deque<uint8_t> uart_rx_fifo[N_UARTS];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EMU_STATE_H
|
#endif // EMU_STATE_H
|
||||||
+44
-19
@@ -554,9 +554,26 @@ uint32_t misc_read(EmuState *state, uint64_t addr) {
|
|||||||
|
|
||||||
// UART
|
// UART
|
||||||
if (addr >= 0x70006000 && addr < 0x70006500) {
|
if (addr >= 0x70006000 && addr < 0x70006500) {
|
||||||
|
uint32_t port = (addr - 0x70006000) / 0x40;
|
||||||
uint32_t offset = (addr - 0x70006000) % 0x40;
|
uint32_t offset = (addr - 0x70006000) % 0x40;
|
||||||
if (offset == 0x14)
|
if (offset == 0x14) {
|
||||||
return 0x60; // LSR: THRE | TMTY always ready
|
// LSR: THRE | TMTY (0x60) always ready, plus RDR (bit 0) when our
|
||||||
|
// host-side RX FIFO has bytes queued by the console window.
|
||||||
|
uint32_t lsr = 0x60;
|
||||||
|
if (port < EmuState::N_UARTS && !state->uart_rx_fifo[port].empty())
|
||||||
|
lsr |= 0x01;
|
||||||
|
return lsr;
|
||||||
|
}
|
||||||
|
if (offset == 0x00) {
|
||||||
|
// RBR (read alias of THR/DLL when DLAB=0). Pop the next host-injected
|
||||||
|
// byte; if the FIFO is empty return 0 (the payload should have
|
||||||
|
// checked LSR.RDR first).
|
||||||
|
if (port < EmuState::N_UARTS && !state->uart_rx_fifo[port].empty()) {
|
||||||
|
uint8_t b = state->uart_rx_fifo[port].front();
|
||||||
|
state->uart_rx_fifo[port].pop_front();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// DSI
|
// DSI
|
||||||
@@ -1673,30 +1690,38 @@ static void hook_mmio_write(uc_engine *uc, uc_mem_type type, uint64_t address,
|
|||||||
} else if (address >= SDMMC4_BASE && address < SDMMC4_BASE + 0x200) {
|
} else if (address >= SDMMC4_BASE && address < SDMMC4_BASE + 0x200) {
|
||||||
misc_write(uc, state, address, value, size);
|
misc_write(uc, state, address, value, size);
|
||||||
} else if (address >= 0x70006000 && address < 0x70006500) {
|
} else if (address >= 0x70006000 && address < 0x70006500) {
|
||||||
|
uint32_t port = (address - 0x70006000) / 0x40;
|
||||||
uint32_t offset = (address - 0x70006000) % 0x40;
|
uint32_t offset = (address - 0x70006000) % 0x40;
|
||||||
if (offset == 0) {
|
if (offset == 0 && port < EmuState::N_UARTS) {
|
||||||
// UART_THR. Hekate's UART carries Joy-Con HID protocol bytes (binary)
|
uint8_t b = (uint8_t)val;
|
||||||
// in addition to occasional debug text. We buffer printable ASCII into
|
|
||||||
// a per-line buffer and flush on \n / \r / overflow so that a
|
// Append every byte to the per-port TX log — the console window
|
||||||
// gfx_putc-mirrored println shows up as a single [uart] line.
|
// renders this as scrolling text. Trim from the front if it grows
|
||||||
static char uart_line[512];
|
// past 64 KB so ImGui rendering stays responsive.
|
||||||
static size_t uart_len = 0;
|
std::string &log = state->uart_tx_log[port];
|
||||||
auto flush_uart_line = []() {
|
if (b == '\n' || (b >= 0x20 && b < 0x7F))
|
||||||
if (uart_len > 0) {
|
log.push_back((char)b);
|
||||||
uart_line[uart_len] = 0;
|
if (log.size() > 64 * 1024)
|
||||||
printf("[uart] %s\n", uart_line);
|
log.erase(0, log.size() - 48 * 1024);
|
||||||
|
|
||||||
|
// Mirror to host stdout in line-buffered form so existing
|
||||||
|
// `grep '[uart]'` workflows still work.
|
||||||
|
static char uart_line[5][512];
|
||||||
|
static size_t uart_len[5] = {0};
|
||||||
|
auto flush_uart_line = [&](uint32_t p) {
|
||||||
|
if (uart_len[p] > 0) {
|
||||||
|
uart_line[p][uart_len[p]] = 0;
|
||||||
|
printf("[uart%c] %s\n", 'A' + (char)p, uart_line[p]);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
uart_len = 0;
|
uart_len[p] = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
uint8_t b = (uint8_t)val;
|
|
||||||
if (b == '\n' || b == '\r') {
|
if (b == '\n' || b == '\r') {
|
||||||
flush_uart_line();
|
flush_uart_line(port);
|
||||||
} else if (b >= 0x20 && b < 0x7F) {
|
} else if (b >= 0x20 && b < 0x7F) {
|
||||||
if (uart_len + 1 >= sizeof(uart_line)) flush_uart_line();
|
if (uart_len[port] + 1 >= sizeof(uart_line[port])) flush_uart_line(port);
|
||||||
uart_line[uart_len++] = (char)b;
|
uart_line[port][uart_len[port]++] = (char)b;
|
||||||
}
|
}
|
||||||
// Non-printables (Joy-Con HID etc.) are dropped silently.
|
|
||||||
}
|
}
|
||||||
} else if (address >= VIC_BASE && address < VIC_BASE + VIC_SIZE) {
|
} else if (address >= VIC_BASE && address < VIC_BASE + VIC_SIZE) {
|
||||||
vic_write(state, address, val);
|
vic_write(state, address, val);
|
||||||
|
|||||||
Reference in new issue
Block a user