This commit is contained in:
2025-11-13 17:46:53 -07:00
parent b1a0351399
commit ce48dde824
10 changed files with 47 additions and 40 deletions

View File

@@ -24,7 +24,7 @@ codegen-units = 1
lto = true
debug = false
opt-level = "z"
panic = "abort"
panic = "unwind"
[profile.dev]
lto = true

View File

@@ -25,7 +25,7 @@ unsafe impl GlobalAlloc for Alloc {
}
#[macro_export]
macro_rules! print {
macro_rules! println {
($($arg:tt)*) => {{
let s = $crate::format!($($arg)*);
$crate::print(s.as_ptr(), s.len());

View File

@@ -6,7 +6,7 @@ use abi::{
display::Display,
get_key,
keyboard::{KeyCode, KeyState},
print,
println,
};
use alloc::vec::Vec;
use embedded_graphics::{

View File

@@ -6,7 +6,7 @@ use abi::{
display::Display,
get_key,
keyboard::{KeyCode, KeyState},
print,
println,
};
use alloc::{format, string::String, vec, vec::Vec};
use core::panic::PanicInfo;
@@ -28,7 +28,7 @@ use embedded_layout::{
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
print!("user panic: {} @ {:?}", info.message(), info.location(),);
println!("user panic: {} @ {:?}", info.message(), info.location(),);
loop {}
}
@@ -38,7 +38,7 @@ pub extern "Rust" fn _start() {
}
pub fn main() {
print!("Starting Calculator app");
println!("Starting Calculator app");
let mut display = Display::take().unwrap();
let mut input = vec!['e', 'x', 'p', 'r', ':', ' '];

View File

@@ -8,7 +8,7 @@ use abi::{
fs::{Entries, list_dir, read_file},
get_key,
keyboard::{KeyCode, KeyState},
print,
println,
};
use alloc::{format, vec};
use core::panic::PanicInfo;
@@ -20,7 +20,7 @@ use tinybmp::Bmp;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
print!("user panic: {} @ {:?}", info.message(), info.location());
println!("user panic: {} @ {:?}", info.message(), info.location());
loop {}
}
@@ -30,7 +30,7 @@ pub extern "Rust" fn _start() {
}
pub fn main() {
print!("Starting Gallery app");
println!("Starting Gallery app");
let mut bmp_buf = vec![0_u8; 100_000];
let mut display = Display::take().unwrap();
@@ -49,7 +49,7 @@ pub fn main() {
break; // only draw 3x3
}
print!("file: {}", file);
println!("file: {}", file);
if file.extension().unwrap_or("") == "bmp" || file.extension().unwrap_or("") == "BMP" {
let file_path = format!("/images/{}", file);

View File

@@ -33,6 +33,7 @@ fn bindgen() {
let bindings = bindgen::Builder::default()
.header("Peanut-GB/peanut_gb.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.disable_nested_struct_naming()
.clang_arg("-I../../picolibc/newlib/libc/include/")
.clang_arg("-I../../picolibc/build/")
.use_core()
@@ -46,6 +47,7 @@ fn bindgen() {
cc::Build::new()
.define("PEANUT_GB_IS_LITTLE_ENDIAN", None)
.define("ENABLE_LCD", None)
.file("peanut_gb_stub.c")
.include("Peanut-GB")
// optimization flags

View File

@@ -9,10 +9,10 @@ use abi::{
fs::{Entries, file_len, list_dir, read_file, write_file},
get_key,
keyboard::{KeyCode, KeyState},
print,
println,
};
use alloc::{string::String, vec, vec::Vec};
use core::{cell::LazyCell, ffi::c_void, mem::MaybeUninit, panic::PanicInfo};
use alloc::{vec, vec::Vec};
use core::{cell::LazyCell, mem::MaybeUninit, panic::PanicInfo};
use embedded_graphics::{
mono_font::{MonoTextStyle, ascii::FONT_6X10},
pixelcolor::Rgb565,
@@ -26,7 +26,7 @@ use peanut::gb_run_frame;
use crate::peanut::{
JOYPAD_A, JOYPAD_B, JOYPAD_DOWN, JOYPAD_LEFT, JOYPAD_RIGHT, JOYPAD_SELECT, JOYPAD_START,
JOYPAD_UP, gb_cart_ram_read, gb_cart_ram_write, gb_error, gb_get_rom_name, gb_get_save_size,
gb_init, gb_init_lcd, gb_rom_read, gb_s, lcd_draw_line,
gb_init, gb_init_lcd, gb_reset, gb_rom_read, gb_s, lcd_draw_line,
};
static mut DISPLAY: LazyCell<Display> = LazyCell::new(|| Display::take().unwrap());
@@ -36,7 +36,7 @@ static mut RAM: [u8; RAM_SIZE] = [0; RAM_SIZE];
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
print!("user panic: {} @ {:?}", info.message(), info.location(),);
println!("user panic: {} @ {:?}", info.message(), info.location(),);
loop {}
}
@@ -49,11 +49,8 @@ const GAME_PATH: &'static str = "/games/gameboy";
static mut GAME_ROM: Option<Vec<u8>> = None;
#[repr(C)]
struct Priv {}
pub fn main() {
print!("Starting Gameboy app");
println!("Starting Gameboy app");
let mut entries = Entries::new();
list_dir(GAME_PATH, &mut entries);
@@ -93,9 +90,8 @@ pub fn main() {
unsafe { GAME_ROM = Some(vec![0_u8; size]) };
let read = read_file(&file_name, 0, unsafe { GAME_ROM.as_mut().unwrap() });
assert!(size == read);
print!("Rom size: {}", read);
println!("Rom size: {}", read);
let mut priv_ = MaybeUninit::<Priv>::uninit();
let mut gb = MaybeUninit::<gb_s>::uninit();
let init_status = unsafe {
@@ -105,10 +101,10 @@ pub fn main() {
Some(gb_cart_ram_read),
Some(gb_cart_ram_write),
Some(gb_error),
priv_.as_mut_ptr() as *mut c_void,
core::ptr::null_mut(),
)
};
print!("gb init status: {}", init_status);
println!("gb init status: {}", init_status);
unsafe {
load_save(&mut gb.assume_init());
@@ -118,7 +114,7 @@ pub fn main() {
gb_init_lcd(gb.as_mut_ptr(), Some(lcd_draw_line));
// enable frame skip
gb.assume_init().direct.set_frame_skip(!true); // active low
// gb.assume_init().direct.set_frame_skip(!true); // active low
};
loop {
@@ -128,6 +124,10 @@ pub fn main() {
unsafe { write_save(&mut gb.assume_init()) };
break;
}
KeyCode::Char('r') => {
unsafe { gb_reset(gb.as_mut_ptr()) };
continue;
}
KeyCode::Tab => JOYPAD_START as u8,
KeyCode::Del => JOYPAD_SELECT as u8,
KeyCode::Enter => JOYPAD_A as u8,
@@ -140,14 +140,19 @@ pub fn main() {
};
if button != 0 {
let mut joypad = unsafe { (*gb.as_mut_ptr()).direct.__bindgen_anon_1.joypad };
match event.state {
KeyState::Pressed => joypad &= !button,
KeyState::Released => joypad |= button,
_ => {}
}
unsafe {
// bindgen incorrectly generates direct so manual manipulation is required :(
let direct_ptr = &mut gb.assume_init().direct as *mut _ as *mut u8;
let joypad_ptr = direct_ptr.add(2); // this is the joypad bitfield byte
print!("joypad now: {:#010b}\n", joypad);
if let KeyState::Pressed = event.state {
*joypad_ptr &= !button;
} else if let KeyState::Released = event.state {
*joypad_ptr |= button;
}
println!("joypad: {:b}", *joypad_ptr);
}
}
unsafe {

View File

@@ -7,7 +7,7 @@ use crate::{DISPLAY, GAME_ROM, RAM};
#[allow(unused)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
use abi::{display::Pixel565, print};
use abi::{display::Pixel565, println};
use embedded_graphics::{Drawable, pixelcolor::Rgb565, prelude::Point};
pub const GBOY_WIDTH: usize = 160;
@@ -36,7 +36,7 @@ pub unsafe extern "C" fn gb_error(_gb: *mut gb_s, err: gb_error_e, addr: u16) {
_ => unreachable!(),
};
print!("PeanutGB error: {}, addr: {}", e, addr);
println!("PeanutGB error: {}, addr: {}", e, addr);
}
const NUM_PALETTES: usize = 3;

View File

@@ -7,7 +7,7 @@ use abi::{
fs::{Entries, file_len, list_dir, read_file},
get_key, get_ms,
keyboard::{KeyCode, KeyState},
print, sleep,
println, sleep,
};
use alloc::{format, vec, vec::Vec};
use core::panic::PanicInfo;
@@ -23,7 +23,7 @@ use tinygif::Gif;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
print!("user panic: {} @ {:?}", info.message(), info.location(),);
println!("user panic: {} @ {:?}", info.message(), info.location(),);
loop {}
}
@@ -33,7 +33,7 @@ pub extern "Rust" fn _start() {
}
pub fn main() {
print!("Starting Gif app");
println!("Starting Gif app");
let mut display = Display::take().unwrap();
let mut entries = Entries::new();
@@ -67,7 +67,7 @@ pub fn main() {
let size = file_len(&file_name);
let mut buf = vec![0_u8; size];
let read = read_file(&file_name, 0, &mut buf);
print!("read: {}, file size: {}", read, size);
println!("read: {}, file size: {}", read, size);
assert!(read == size);
let gif = Gif::<Rgb565>::from_slice(&buf).expect("Failed to parse gif");

View File

@@ -7,7 +7,7 @@ use abi::{
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
get_key,
keyboard::{KeyCode, KeyState},
print, sleep,
println, sleep,
};
use core::panic::PanicInfo;
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
@@ -15,7 +15,7 @@ use embedded_snake::{Direction, SnakeGame};
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
print!("user panic: {} @ {:?}", info.message(), info.location(),);
println!("user panic: {} @ {:?}", info.message(), info.location(),);
loop {}
}
@@ -27,7 +27,7 @@ pub extern "Rust" fn _start() {
const CELL_SIZE: usize = 8;
pub fn main() {
print!("Starting Snake app");
println!("Starting Snake app");
let mut display = Display::take().unwrap();
let mut game = SnakeGame::<100, Rgb565, Rng>::new(