Skip to content

Commit

Permalink
Add println!() support, working in Dolphin
Browse files Browse the repository at this point in the history
Once rust-wii#9 gets fixed to work with a real USB Gecko, this will have to do
as a way to communicate with the outside world for debugging purposes.

I quite dislike how the alloc and luma_core crates must be imported
under these names in order for my macro to work, but I couldn’t figure
out a better way which still compiles.
  • Loading branch information
linkmauve committed Dec 19, 2021
1 parent 373f3dc commit 21b2d29
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions luma_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#![allow(unused_attributes)]
#![feature(asm_experimental_arch, box_into_boxed_slice, allocator_api)]

use core::arch::asm;

extern crate alloc;

// Broadway Processor Utilities
Expand All @@ -32,3 +34,19 @@ pub mod allocate;

// VI Subsystem
pub mod vi;

#[no_mangle]
#[inline(never)]
pub unsafe extern "C" fn puts(unused: u32, message: *const u8) {
// Do nothing, this is for Dolphin’s use until we get actual USB Gecko support.
asm!("/* {0} {1} */", in(reg) unused, in(reg) message);
}

#[macro_export]
macro_rules! println {
($fmt: expr, $($args: expr),*) => {{
// TODO: figure out a way to not have to import those crates with these names in user code.
let string = alloc::format!($fmt, $($args),*);
unsafe { luma_core::puts(0, string.as_ptr()) };
}}
}

0 comments on commit 21b2d29

Please sign in to comment.