hex/ascii serial output
This commit is contained in:
parent
431e3a1fca
commit
7ae1afedc2
|
@ -7,6 +7,7 @@ use debug::Debugger;
|
|||
use gb_emu_lib::{
|
||||
connect::{
|
||||
EmulatorCoreTrait, EmulatorMessage, EmulatorOptions, NoCamera, RomFile, SerialTarget,
|
||||
StdoutType,
|
||||
},
|
||||
EmulatorCore,
|
||||
};
|
||||
|
@ -27,6 +28,7 @@ mod window;
|
|||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
|
||||
#[command(group(ArgGroup::new("link").args(["ascii","hex"])))]
|
||||
struct Args {
|
||||
/// Path to ROM
|
||||
rom: String,
|
||||
|
@ -43,9 +45,13 @@ struct Args {
|
|||
#[arg(short, long)]
|
||||
bootrom: Option<String>,
|
||||
|
||||
/// Connect the serial port output to stdout
|
||||
/// Output link port to stdout as ASCII
|
||||
#[arg(long)]
|
||||
connect_serial: bool,
|
||||
ascii: bool,
|
||||
|
||||
/// Output link port to stdout as hex values
|
||||
#[arg(long)]
|
||||
hex: bool,
|
||||
|
||||
/// Show tile window
|
||||
#[arg(short, long)]
|
||||
|
@ -123,8 +129,10 @@ impl EmulatorHandler {
|
|||
|
||||
let options = EmulatorOptions::new(window, rom, output)
|
||||
.with_save_path(args.save)
|
||||
.with_serial_target(if args.connect_serial {
|
||||
SerialTarget::Stdout
|
||||
.with_serial_target(if args.ascii {
|
||||
SerialTarget::Stdout(StdoutType::Ascii)
|
||||
} else if args.hex {
|
||||
SerialTarget::Stdout(StdoutType::Hex)
|
||||
} else {
|
||||
SerialTarget::None
|
||||
})
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex, RwLock};
|
|||
|
||||
pub use crate::processor::memory::mmio::gpu::Colour;
|
||||
pub use crate::processor::memory::mmio::joypad::{JoypadButtons, JoypadState};
|
||||
pub use crate::processor::memory::mmio::serial::SerialTarget;
|
||||
pub use crate::processor::memory::mmio::serial::{SerialTarget, StdoutType};
|
||||
pub use crate::{HEIGHT, WIDTH};
|
||||
use async_ringbuf::{AsyncHeapConsumer, AsyncHeapProducer, AsyncHeapRb};
|
||||
|
||||
|
@ -224,7 +224,7 @@ where
|
|||
}
|
||||
|
||||
pub fn with_stdout(mut self) -> Self {
|
||||
self.serial_target = SerialTarget::Stdout;
|
||||
self.serial_target = SerialTarget::Stdout(StdoutType::Ascii);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Default for SerialControl {
|
|||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum SerialTarget {
|
||||
Stdout,
|
||||
Stdout(StdoutType),
|
||||
Custom {
|
||||
#[serde(skip)]
|
||||
rx: Option<Receiver<u8>>,
|
||||
|
@ -51,6 +51,12 @@ pub enum SerialTarget {
|
|||
None,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum StdoutType {
|
||||
Ascii,
|
||||
Hex,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Default)]
|
||||
struct InputByte {
|
||||
byte: Option<u8>,
|
||||
|
@ -164,8 +170,11 @@ impl Serial {
|
|||
self.control.transfer_in_progress = false;
|
||||
will_interrupt = true;
|
||||
match &self.target {
|
||||
SerialTarget::Stdout => {
|
||||
print!("{}", self.output_byte as char);
|
||||
SerialTarget::Stdout(stdout_type) => {
|
||||
match stdout_type {
|
||||
StdoutType::Ascii => print!("{}", self.output_byte as char),
|
||||
StdoutType::Hex => print!("{:0>2X} ", self.output_byte),
|
||||
}
|
||||
stdout().flush().unwrap();
|
||||
}
|
||||
SerialTarget::Custom { rx: _, tx } => {
|
||||
|
|
Loading…
Reference in a new issue