mirror of
https://github.com/italicsjenga/gba.git
synced 2025-01-11 03:21:30 +11:00
cargo-make Makefile.toml
This commit is contained in:
parent
8aa1bb0065
commit
3a355db578
|
@ -14,9 +14,6 @@ publish = false
|
|||
[dependencies]
|
||||
gba-proc-macro = "0.2.1"
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
panic = "abort"
|
||||
|
|
59
Makefile.toml
Normal file
59
Makefile.toml
Normal file
|
@ -0,0 +1,59 @@
|
|||
[config]
|
||||
skip_core_tasks = true
|
||||
|
||||
[tasks.create-target-dir]
|
||||
script_runner = "@rust"
|
||||
script = [
|
||||
'''
|
||||
fn main() {
|
||||
std::fs::DirBuilder::new().recursive(true).create("./target/").unwrap();
|
||||
}
|
||||
'''
|
||||
]
|
||||
|
||||
[tasks.assemble]
|
||||
dependencies = ["create-target-dir"]
|
||||
command = "arm-none-eabi-as"
|
||||
args = ["crt0.s", "-o", "target/crt0.o"]
|
||||
|
||||
[tasks.build-debug]
|
||||
dependencies = ["assemble"]
|
||||
command = "cargo"
|
||||
args = ["xbuild", "--examples", "--target", "thumbv4-none-agb.json"]
|
||||
|
||||
[tasks.build-release]
|
||||
dependencies = ["assemble"]
|
||||
command = "cargo"
|
||||
args = ["xbuild", "--examples", "--target", "thumbv4-none-agb.json", "--release"]
|
||||
|
||||
[tasks.pack-roms]
|
||||
script_runner = "@rust"
|
||||
script = [
|
||||
'''
|
||||
fn main() -> std::io::Result<()> {
|
||||
for entry in std::fs::read_dir("examples/")? {
|
||||
let entry = entry?;
|
||||
let mut path = entry.path();
|
||||
if path.is_dir() {
|
||||
continue;
|
||||
} else {
|
||||
path.set_extension("");
|
||||
let name = path.file_name().unwrap().to_str().unwrap();
|
||||
println!("{:?}", name);
|
||||
std::process::Command::new("arm-none-eabi-objcopy").args(
|
||||
&["-O", "binary",
|
||||
&format!("target/thumbv4-none-agb/release/examples/{}",name),
|
||||
&format!("target/example-{}.gba",name)])
|
||||
.output().expect("failed to objcopy!");
|
||||
std::process::Command::new("gbafix").args(
|
||||
&[&format!("target/example-{}.gba",name)])
|
||||
.output().expect("failed to gbafix!");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
'''
|
||||
]
|
||||
|
||||
[tasks.build]
|
||||
dependencies = ["build-debug", "build-release", "pack-roms"]
|
|
@ -34,7 +34,6 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
|||
let key = ((this_frame_key_raw >> i) & 1) > 0;
|
||||
mode3_draw_pixel(15 - i, 0, if key { green } else { red });
|
||||
mode3_draw_pixel(15 - i, 1, if key { green } else { red });
|
||||
mode3_draw_pixel(50 - i, 10 / i, if key { green } else { red });
|
||||
}
|
||||
|
||||
wait_until_vdraw();
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
//! Intrinsics that LLVM looks for when compiling.
|
||||
|
||||
/// Signed division
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "aapcs" fn __aeabi_idiv(n: i32, d: i32) -> i32 {
|
||||
assert!(d != 0);
|
||||
let div_out: i32;
|
||||
let _mod_out: i32;
|
||||
unsafe {
|
||||
asm!(/* assembly template */ "swi 0x06"
|
||||
:/* output operands */ "={r0}"(div_out), "={r1}"(_mod_out)
|
||||
:/* input operands */ "{r0}"(n), "{r1}"(d)
|
||||
:/* clobbers */ "r3"
|
||||
:/* options */
|
||||
);
|
||||
}
|
||||
div_out
|
||||
}
|
||||
|
||||
/// Signed division alias for glibc reasons
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "aapcs" fn __divsi3(n: i32, d: i32) -> i32 {
|
||||
// Note the different naming scheme.
|
||||
__aeabi_idiv(n, d)
|
||||
}
|
||||
|
||||
/// Unsigned division gets cast into signed values, divided, and cast back
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "aapcs" fn __aeabi_uidiv(n: u32, d: u32) -> u32 {
|
||||
__aeabi_idiv(n as i32, d as i32) as u32
|
||||
}
|
||||
|
||||
/// Unsigned division alias for glibc reasons
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "aapcs" fn __udivsi3(n: u32, d: u32) -> u32 {
|
||||
// Note the different naming scheme.
|
||||
__aeabi_uidiv(n, d)
|
||||
}
|
||||
|
||||
/// Count leading zeroes, required in debug mode for unknown reasons
|
||||
#[no_mangle]
|
||||
#[inline]
|
||||
pub extern "aapcs" fn __clzsi2(x: i32) -> i32 {
|
||||
let mut y = -(x >> 16); // If left half of x is 0,
|
||||
let mut m = (y >> 16) & 16; // set n = 16. If left half
|
||||
let mut n = 16 - m; // is nonzero, set n = 0 and
|
||||
let mut x = x >> m; // shift x right 16.
|
||||
// Now x is of the form 0000xxxx.
|
||||
y = x - 0x100; // If positions 8-15 are 0,
|
||||
m = (y >> 16) & 8; // add 8 to n and shift x left 8.
|
||||
n = n + m;
|
||||
x = x << m;
|
||||
|
||||
y = x - 0x1000; // If positions 12-15 are 0,
|
||||
m = (y >> 16) & 4; // add 4 to n and shift x left 4.
|
||||
n = n + m;
|
||||
x = x << m;
|
||||
|
||||
y = x - 0x4000; // If positions 14-15 are 0,
|
||||
m = (y >> 16) & 2; // add 2 to n and shift x left 2.
|
||||
n = n + m;
|
||||
x = x << m;
|
||||
|
||||
y = x >> 14; // Set y = 0, 1, 2, or 3.
|
||||
m = y & !(y >> 1); // Set m = 0, 1, 2, or 2 resp.
|
||||
n + 2 - m
|
||||
}
|
35
src/lib.rs
35
src/lib.rs
|
@ -31,8 +31,6 @@ pub mod io_registers;
|
|||
pub mod video_ram;
|
||||
pub(crate) use crate::video_ram::*;
|
||||
|
||||
pub mod intrinsics;
|
||||
|
||||
/// Combines the Red, Blue, and Green provided into a single color value.
|
||||
pub const fn rgb16(red: u16, green: u16, blue: u16) -> u16 {
|
||||
blue << 10 | green << 5 | red
|
||||
|
@ -40,18 +38,37 @@ pub const fn rgb16(red: u16, green: u16, blue: u16) -> u16 {
|
|||
|
||||
/// BIOS Call: Div (GBA SWI 0x06).
|
||||
///
|
||||
/// Gives the DIV and MOD output of `numerator / denominator`.
|
||||
/// Gives just the DIV output of `numerator / denominator`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If `denominator` is 0.
|
||||
#[inline]
|
||||
pub fn div_mod(numerator: i32, denominator: i32) -> (i32, i32) {
|
||||
// The BIOS includes several System Call Functions which can be accessed by
|
||||
// SWI instructions. Incoming parameters are usually passed through registers
|
||||
// R0,R1,R2,R3. Outgoing registers R0,R1,R3 are typically containing either
|
||||
// garbage, or return value(s). All other registers (R2,R4-R14) are kept
|
||||
// unchanged. --GBATEK
|
||||
pub fn div(numerator: i32, denominator: i32) -> i32 {
|
||||
div_modulus(numerator, denominator).0
|
||||
}
|
||||
|
||||
/// BIOS Call: Div (GBA SWI 0x06).
|
||||
///
|
||||
/// Gives just the MOD output of `numerator / denominator`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If `denominator` is 0.
|
||||
#[inline]
|
||||
pub fn modulus(numerator: i32, denominator: i32) -> i32 {
|
||||
div_modulus(numerator, denominator).1
|
||||
}
|
||||
|
||||
/// BIOS Call: Div (GBA SWI 0x06).
|
||||
///
|
||||
/// Gives both the DIV and MOD output of `numerator / denominator`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If `denominator` is 0.
|
||||
#[inline]
|
||||
pub fn div_modulus(numerator: i32, denominator: i32) -> (i32, i32) {
|
||||
assert!(denominator != 0);
|
||||
let div_out: i32;
|
||||
let mod_out: i32;
|
||||
|
|
Loading…
Reference in a new issue