Skip to content
Open
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mmio = []
glam_compat = ["glam"]
default_alloc_handler = []
default_panic_handler = []
experimental = []

[dependencies]
bitflags = "1.3"
Expand All @@ -34,3 +35,5 @@ ogc-sys = { path = "./ogc-sys/"}
glam = { version = "0.19.0", default-features = false, features = ["libm"], optional = true }
voladdress = "1.2.2"
bit_field = "0.10.1"
bitfrob = { version = "1.3.1", default-features = false }
num-traits = { version = "0.2.19", features = ["libm"], default-features = false }
24 changes: 24 additions & 0 deletions examples/colored-tri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 26 additions & 15 deletions examples/colored-tri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
use core::mem::ManuallyDrop;

use ogc_rs::{
ffi::{
GX_CLR_RGBA, GX_COLOR0A0, GX_PASSCLR, GX_POS_XYZ, GX_RGBA8, GX_S16, GX_TEXCOORDNULL,
GX_TEXMAP_NULL, GX_VA_CLR0, GX_VA_POS,
},
gu::{Gu, RotationAxis},
gx::{types::VtxDest, CmpFn, Color, CullMode, Gx, Primitive, ProjectionType, VtxAttr},
gx::{
types::{ComponentSize, ComponentType, TexCoordSlot, TexMapSlot, VtxDest},
CmpFn, Color, CullMode, Gx, Primitive, ProjectionType, VtxAttr,
},
video::Video,
};

extern crate alloc;

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
let vi = Video::init();
Expand All @@ -25,7 +23,8 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
Video::set_black(false);
Video::flush();

let fifo = ManuallyDrop::new(Gx::init(256 * 1024));
let _fifo = ManuallyDrop::new(Gx::init(256 * 1024));
// let fifo = ManuallyDrop::new(Gx::init(256 * 1024));
// Set values to use when video is flipped / cleared
Gx::set_copy_clear(Color::new(0x00, 0x00, 0x00), 0x00_FF_FF_FF);

Expand Down Expand Up @@ -76,20 +75,32 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
Gx::clear_vtx_desc();
Gx::set_vtx_desc(VtxAttr::Pos, VtxDest::INDEX8);
Gx::set_vtx_desc(VtxAttr::Color0, VtxDest::INDEX8);
Gx::set_vtx_attr_fmt(0, VtxAttr::Pos, GX_POS_XYZ, GX_S16, 0);
Gx::set_vtx_attr_fmt(0, VtxAttr::Color0, GX_CLR_RGBA, GX_RGBA8, 0);
Gx::set_vtx_attr_fmt(
0,
VtxAttr::Pos,
ComponentType::POSITION_XYZ,
ComponentSize::I16,
0,
);
Gx::set_vtx_attr_fmt(
0,
VtxAttr::Color0,
ComponentType::COLOR_RGBA,
ComponentSize::COLOR_RGBA8,
0,
);

let positions: [[i16; 3]; 3] = [[0, 15, 0], [-15, -15, 0], [15, -15, 0]];
let colors: [[u8; 4]; 3] = [[255, 0, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255]];

Gx::set_array(
GX_VA_POS,
VtxAttr::Pos,
&positions,
core::mem::size_of::<[i16; 3]>().try_into().unwrap(),
);

Gx::set_array(
GX_VA_CLR0,
VtxAttr::Color0,
&colors,
core::mem::size_of::<[u8; 4]>().try_into().unwrap(),
);
Expand All @@ -99,11 +110,11 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {

Gx::set_tev_order(
0,
GX_TEXCOORDNULL.try_into().unwrap(),
GX_TEXMAP_NULL,
GX_COLOR0A0.try_into().unwrap(),
TexCoordSlot::None,
TexMapSlot::Zero,
ogc_rs::gx::types::ColorSlot::Color0Alpha0,
);
Gx::set_tev_op(0, GX_PASSCLR.try_into().unwrap());
Gx::set_tev_op(0, ogc_rs::gx::types::TevOp::PassColor);

let mut i: u16 = 0;
loop {
Expand Down
7 changes: 7 additions & 0 deletions examples/ios/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 42 additions & 1 deletion examples/ios/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,52 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
};

println!("{:?}", bytes);

let _ = ios::close(fd);
}

println!("Format: {:?}", get_video_format());
loop {
core::hint::spin_loop();
}
}

#[derive(Copy, Clone, Debug)]
pub enum VideoFormat {
Ntsc,
Pal,
MPal,
}

fn get_video_format() -> Option<VideoFormat> {
if let Ok(fd) = ios::open(c"/title/00000001/00000002/data/setting.txt", Mode::Read) {
let mut bytes = [0u8; 256];
if let Ok(bytes_read) = ios::read(fd, &mut bytes) {
debug_assert!(bytes_read == 256);
}

let mut key: u32 = 0x73B5DBFA;
for byte in &mut bytes {
*byte ^= u8::try_from(key & 0xff).unwrap();
key = (key << 1) | (key >> 31);
}

let text = if let Err(vld) = core::str::from_utf8(&bytes) {
unsafe { core::str::from_utf8_unchecked(&bytes[..vld.valid_up_to()]) }
} else {
return None;
};

for line in text.lines() {
if let Some(char) = line.find("VIDEO=") {
return match line[char + 6..].trim() {
"NTSC" => Some(VideoFormat::Ntsc),
"PAL" => Some(VideoFormat::Pal),
"MPAL" => Some(VideoFormat::MPal),
_ => None,
};
}
}
let _ = ios::close(fd);
}
None
}
24 changes: 24 additions & 0 deletions examples/texture-tri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading