psx_rt/tty.rs
1//! TTY output for debug printing.
2//!
3//! The PS1 BIOS has a `putchar` handler that forwards bytes to the
4//! Expansion 2 TTY port -- PCSX-Redux reads that port and prints to
5//! stdout. Our emulator does the same. So calling [`print`] /
6//! [`println`] from homebrew lands in the host terminal, which is
7//! the canonical PS1 debug channel.
8
9use crate::bios;
10
11/// Write a string to TTY. Each byte is emitted via the BIOS
12/// `putchar` trampoline.
13pub fn print(s: &str) {
14 for b in s.bytes() {
15 bios::write_char(b);
16 }
17}
18
19/// [`print`] + a trailing `\n`.
20pub fn println(s: &str) {
21 print(s);
22 bios::write_char(b'\n');
23}
24
25/// Write a single u32 as 8 hex digits, no prefix, uppercase.
26pub fn print_hex_u32(v: u32) {
27 const DIGITS: &[u8; 16] = b"0123456789ABCDEF";
28 for shift in (0..8).rev() {
29 let nib = ((v >> (shift * 4)) & 0xF) as usize;
30 bios::write_char(DIGITS[nib]);
31 }
32}