mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2026-02-10 22:15:24 +00:00
ugh
This commit is contained in:
@@ -24,7 +24,7 @@ codegen-units = 1
|
|||||||
lto = true
|
lto = true
|
||||||
debug = false
|
debug = false
|
||||||
opt-level = "z"
|
opt-level = "z"
|
||||||
panic = "abort"
|
panic = "unwind"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
lto = true
|
lto = true
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ unsafe impl GlobalAlloc for Alloc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! print {
|
macro_rules! println {
|
||||||
($($arg:tt)*) => {{
|
($($arg:tt)*) => {{
|
||||||
let s = $crate::format!($($arg)*);
|
let s = $crate::format!($($arg)*);
|
||||||
$crate::print(s.as_ptr(), s.len());
|
$crate::print(s.as_ptr(), s.len());
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use abi::{
|
|||||||
display::Display,
|
display::Display,
|
||||||
get_key,
|
get_key,
|
||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print,
|
println,
|
||||||
};
|
};
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use abi::{
|
|||||||
display::Display,
|
display::Display,
|
||||||
get_key,
|
get_key,
|
||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print,
|
println,
|
||||||
};
|
};
|
||||||
use alloc::{format, string::String, vec, vec::Vec};
|
use alloc::{format, string::String, vec, vec::Vec};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
@@ -28,7 +28,7 @@ use embedded_layout::{
|
|||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
println!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ pub extern "Rust" fn _start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
print!("Starting Calculator app");
|
println!("Starting Calculator app");
|
||||||
let mut display = Display::take().unwrap();
|
let mut display = Display::take().unwrap();
|
||||||
|
|
||||||
let mut input = vec!['e', 'x', 'p', 'r', ':', ' '];
|
let mut input = vec!['e', 'x', 'p', 'r', ':', ' '];
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use abi::{
|
|||||||
fs::{Entries, list_dir, read_file},
|
fs::{Entries, list_dir, read_file},
|
||||||
get_key,
|
get_key,
|
||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print,
|
println,
|
||||||
};
|
};
|
||||||
use alloc::{format, vec};
|
use alloc::{format, vec};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
@@ -20,7 +20,7 @@ use tinybmp::Bmp;
|
|||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location());
|
println!("user panic: {} @ {:?}", info.message(), info.location());
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ pub extern "Rust" fn _start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
print!("Starting Gallery app");
|
println!("Starting Gallery app");
|
||||||
let mut bmp_buf = vec![0_u8; 100_000];
|
let mut bmp_buf = vec![0_u8; 100_000];
|
||||||
let mut display = Display::take().unwrap();
|
let mut display = Display::take().unwrap();
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ pub fn main() {
|
|||||||
break; // only draw 3x3
|
break; // only draw 3x3
|
||||||
}
|
}
|
||||||
|
|
||||||
print!("file: {}", file);
|
println!("file: {}", file);
|
||||||
if file.extension().unwrap_or("") == "bmp" || file.extension().unwrap_or("") == "BMP" {
|
if file.extension().unwrap_or("") == "bmp" || file.extension().unwrap_or("") == "BMP" {
|
||||||
let file_path = format!("/images/{}", file);
|
let file_path = format!("/images/{}", file);
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ fn bindgen() {
|
|||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
.header("Peanut-GB/peanut_gb.h")
|
.header("Peanut-GB/peanut_gb.h")
|
||||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||||
|
.disable_nested_struct_naming()
|
||||||
.clang_arg("-I../../picolibc/newlib/libc/include/")
|
.clang_arg("-I../../picolibc/newlib/libc/include/")
|
||||||
.clang_arg("-I../../picolibc/build/")
|
.clang_arg("-I../../picolibc/build/")
|
||||||
.use_core()
|
.use_core()
|
||||||
@@ -46,6 +47,7 @@ fn bindgen() {
|
|||||||
|
|
||||||
cc::Build::new()
|
cc::Build::new()
|
||||||
.define("PEANUT_GB_IS_LITTLE_ENDIAN", None)
|
.define("PEANUT_GB_IS_LITTLE_ENDIAN", None)
|
||||||
|
.define("ENABLE_LCD", None)
|
||||||
.file("peanut_gb_stub.c")
|
.file("peanut_gb_stub.c")
|
||||||
.include("Peanut-GB")
|
.include("Peanut-GB")
|
||||||
// optimization flags
|
// optimization flags
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ use abi::{
|
|||||||
fs::{Entries, file_len, list_dir, read_file, write_file},
|
fs::{Entries, file_len, list_dir, read_file, write_file},
|
||||||
get_key,
|
get_key,
|
||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print,
|
println,
|
||||||
};
|
};
|
||||||
use alloc::{string::String, vec, vec::Vec};
|
use alloc::{vec, vec::Vec};
|
||||||
use core::{cell::LazyCell, ffi::c_void, mem::MaybeUninit, panic::PanicInfo};
|
use core::{cell::LazyCell, mem::MaybeUninit, panic::PanicInfo};
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
mono_font::{MonoTextStyle, ascii::FONT_6X10},
|
mono_font::{MonoTextStyle, ascii::FONT_6X10},
|
||||||
pixelcolor::Rgb565,
|
pixelcolor::Rgb565,
|
||||||
@@ -26,7 +26,7 @@ use peanut::gb_run_frame;
|
|||||||
use crate::peanut::{
|
use crate::peanut::{
|
||||||
JOYPAD_A, JOYPAD_B, JOYPAD_DOWN, JOYPAD_LEFT, JOYPAD_RIGHT, JOYPAD_SELECT, JOYPAD_START,
|
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,
|
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());
|
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]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
println!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,11 +49,8 @@ const GAME_PATH: &'static str = "/games/gameboy";
|
|||||||
|
|
||||||
static mut GAME_ROM: Option<Vec<u8>> = None;
|
static mut GAME_ROM: Option<Vec<u8>> = None;
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
struct Priv {}
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
print!("Starting Gameboy app");
|
println!("Starting Gameboy app");
|
||||||
|
|
||||||
let mut entries = Entries::new();
|
let mut entries = Entries::new();
|
||||||
list_dir(GAME_PATH, &mut entries);
|
list_dir(GAME_PATH, &mut entries);
|
||||||
@@ -93,9 +90,8 @@ pub fn main() {
|
|||||||
unsafe { GAME_ROM = Some(vec![0_u8; size]) };
|
unsafe { GAME_ROM = Some(vec![0_u8; size]) };
|
||||||
let read = read_file(&file_name, 0, unsafe { GAME_ROM.as_mut().unwrap() });
|
let read = read_file(&file_name, 0, unsafe { GAME_ROM.as_mut().unwrap() });
|
||||||
assert!(size == read);
|
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 mut gb = MaybeUninit::<gb_s>::uninit();
|
||||||
|
|
||||||
let init_status = unsafe {
|
let init_status = unsafe {
|
||||||
@@ -105,10 +101,10 @@ pub fn main() {
|
|||||||
Some(gb_cart_ram_read),
|
Some(gb_cart_ram_read),
|
||||||
Some(gb_cart_ram_write),
|
Some(gb_cart_ram_write),
|
||||||
Some(gb_error),
|
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 {
|
unsafe {
|
||||||
load_save(&mut gb.assume_init());
|
load_save(&mut gb.assume_init());
|
||||||
@@ -118,7 +114,7 @@ pub fn main() {
|
|||||||
gb_init_lcd(gb.as_mut_ptr(), Some(lcd_draw_line));
|
gb_init_lcd(gb.as_mut_ptr(), Some(lcd_draw_line));
|
||||||
|
|
||||||
// enable frame skip
|
// enable frame skip
|
||||||
gb.assume_init().direct.set_frame_skip(!true); // active low
|
// gb.assume_init().direct.set_frame_skip(!true); // active low
|
||||||
};
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@@ -128,6 +124,10 @@ pub fn main() {
|
|||||||
unsafe { write_save(&mut gb.assume_init()) };
|
unsafe { write_save(&mut gb.assume_init()) };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
KeyCode::Char('r') => {
|
||||||
|
unsafe { gb_reset(gb.as_mut_ptr()) };
|
||||||
|
continue;
|
||||||
|
}
|
||||||
KeyCode::Tab => JOYPAD_START as u8,
|
KeyCode::Tab => JOYPAD_START as u8,
|
||||||
KeyCode::Del => JOYPAD_SELECT as u8,
|
KeyCode::Del => JOYPAD_SELECT as u8,
|
||||||
KeyCode::Enter => JOYPAD_A as u8,
|
KeyCode::Enter => JOYPAD_A as u8,
|
||||||
@@ -140,14 +140,19 @@ pub fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if button != 0 {
|
if button != 0 {
|
||||||
let mut joypad = unsafe { (*gb.as_mut_ptr()).direct.__bindgen_anon_1.joypad };
|
unsafe {
|
||||||
match event.state {
|
// bindgen incorrectly generates direct so manual manipulation is required :(
|
||||||
KeyState::Pressed => joypad &= !button,
|
let direct_ptr = &mut gb.assume_init().direct as *mut _ as *mut u8;
|
||||||
KeyState::Released => joypad |= button,
|
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 {
|
unsafe {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::{DISPLAY, GAME_ROM, RAM};
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
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};
|
use embedded_graphics::{Drawable, pixelcolor::Rgb565, prelude::Point};
|
||||||
|
|
||||||
pub const GBOY_WIDTH: usize = 160;
|
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!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
print!("PeanutGB error: {}, addr: {}", e, addr);
|
println!("PeanutGB error: {}, addr: {}", e, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const NUM_PALETTES: usize = 3;
|
const NUM_PALETTES: usize = 3;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use abi::{
|
|||||||
fs::{Entries, file_len, list_dir, read_file},
|
fs::{Entries, file_len, list_dir, read_file},
|
||||||
get_key, get_ms,
|
get_key, get_ms,
|
||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print, sleep,
|
println, sleep,
|
||||||
};
|
};
|
||||||
use alloc::{format, vec, vec::Vec};
|
use alloc::{format, vec, vec::Vec};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
@@ -23,7 +23,7 @@ use tinygif::Gif;
|
|||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
println!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ pub extern "Rust" fn _start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
print!("Starting Gif app");
|
println!("Starting Gif app");
|
||||||
let mut display = Display::take().unwrap();
|
let mut display = Display::take().unwrap();
|
||||||
|
|
||||||
let mut entries = Entries::new();
|
let mut entries = Entries::new();
|
||||||
@@ -67,7 +67,7 @@ pub fn main() {
|
|||||||
let size = file_len(&file_name);
|
let size = file_len(&file_name);
|
||||||
let mut buf = vec![0_u8; size];
|
let mut buf = vec![0_u8; size];
|
||||||
let read = read_file(&file_name, 0, &mut buf);
|
let read = read_file(&file_name, 0, &mut buf);
|
||||||
print!("read: {}, file size: {}", read, size);
|
println!("read: {}, file size: {}", read, size);
|
||||||
assert!(read == size);
|
assert!(read == size);
|
||||||
|
|
||||||
let gif = Gif::<Rgb565>::from_slice(&buf).expect("Failed to parse gif");
|
let gif = Gif::<Rgb565>::from_slice(&buf).expect("Failed to parse gif");
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use abi::{
|
|||||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||||
get_key,
|
get_key,
|
||||||
keyboard::{KeyCode, KeyState},
|
keyboard::{KeyCode, KeyState},
|
||||||
print, sleep,
|
println, sleep,
|
||||||
};
|
};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
|
use embedded_graphics::{pixelcolor::Rgb565, prelude::RgbColor};
|
||||||
@@ -15,7 +15,7 @@ use embedded_snake::{Direction, SnakeGame};
|
|||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
print!("user panic: {} @ {:?}", info.message(), info.location(),);
|
println!("user panic: {} @ {:?}", info.message(), info.location(),);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ pub extern "Rust" fn _start() {
|
|||||||
const CELL_SIZE: usize = 8;
|
const CELL_SIZE: usize = 8;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
print!("Starting Snake app");
|
println!("Starting Snake app");
|
||||||
let mut display = Display::take().unwrap();
|
let mut display = Display::take().unwrap();
|
||||||
|
|
||||||
let mut game = SnakeGame::<100, Rgb565, Rng>::new(
|
let mut game = SnakeGame::<100, Rgb565, Rng>::new(
|
||||||
|
|||||||
Reference in New Issue
Block a user