mirror of
https://github.com/italicsjenga/gba.git
synced 2024-12-24 03:11:29 +11:00
Update bios module to just build on x86
the actual functions are all unimplemented!() but oh well
This commit is contained in:
parent
e3c3b572dd
commit
8ff32b0304
189
src/bios.rs
189
src/bios.rs
|
@ -8,6 +8,8 @@
|
||||||
//! whatever value is necessary for that function). Some functions also perform
|
//! whatever value is necessary for that function). Some functions also perform
|
||||||
//! necessary checks to save you from yourself, such as not dividing by zero.
|
//! necessary checks to save you from yourself, such as not dividing by zero.
|
||||||
|
|
||||||
|
#![cfg_attr(not(all(target_vendor = "nintendo", target_env = "agb")), allow(unused_variables))]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
//TODO: ALL functions in this module should have `if cfg!(test)` blocks. The
|
//TODO: ALL functions in this module should have `if cfg!(test)` blocks. The
|
||||||
|
@ -51,9 +53,12 @@ use super::*;
|
||||||
/// perform UB, but such a scenario might exist.
|
/// perform UB, but such a scenario might exist.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn soft_reset() -> ! {
|
pub unsafe fn soft_reset() -> ! {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
panic!("Attempted soft reset during testing");
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
asm!(/* ASM */ "swi 0x00"
|
asm!(/* ASM */ "swi 0x00"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
:/* INP */ // none
|
:/* INP */ // none
|
||||||
|
@ -91,9 +96,12 @@ pub unsafe fn soft_reset() -> ! {
|
||||||
/// that. If you do then you return to nothing and have a bad time.
|
/// that. If you do then you return to nothing and have a bad time.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn register_ram_reset(flags: RegisterRAMResetFlags) {
|
pub unsafe fn register_ram_reset(flags: RegisterRAMResetFlags) {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
asm!(/* ASM */ "swi 0x01"
|
asm!(/* ASM */ "swi 0x01"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
:/* INP */ "{r0}"(flags.0)
|
:/* INP */ "{r0}"(flags.0)
|
||||||
|
@ -127,9 +135,12 @@ impl RegisterRAMResetFlags {
|
||||||
/// any enabled interrupt triggers.
|
/// any enabled interrupt triggers.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn halt() {
|
pub fn halt() {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x02"
|
asm!(/* ASM */ "swi 0x02"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -151,9 +162,12 @@ pub fn halt() {
|
||||||
/// optional externals such as rumble and infra-red.
|
/// optional externals such as rumble and infra-red.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn stop() {
|
pub fn stop() {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x03"
|
asm!(/* ASM */ "swi 0x03"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -180,9 +194,12 @@ pub fn stop() {
|
||||||
/// acknowledgement.
|
/// acknowledgement.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn interrupt_wait(ignore_current_flags: bool, target_flags: u16) {
|
pub fn interrupt_wait(ignore_current_flags: bool, target_flags: u16) {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x04"
|
asm!(/* ASM */ "swi 0x04"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -201,9 +218,12 @@ pub fn interrupt_wait(ignore_current_flags: bool, target_flags: u16) {
|
||||||
/// must follow the same guidelines that `interrupt_wait` outlines.
|
/// must follow the same guidelines that `interrupt_wait` outlines.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn vblank_interrupt_wait() {
|
pub fn vblank_interrupt_wait() {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x04"
|
asm!(/* ASM */ "swi 0x04"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -223,9 +243,12 @@ pub fn vblank_interrupt_wait() {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn div_rem(numerator: i32, denominator: i32) -> (i32, i32) {
|
pub fn div_rem(numerator: i32, denominator: i32) -> (i32, i32) {
|
||||||
assert!(denominator != 0);
|
assert!(denominator != 0);
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
|
{
|
||||||
(numerator / denominator, numerator % denominator)
|
(numerator / denominator, numerator % denominator)
|
||||||
} else {
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
let div_out: i32;
|
let div_out: i32;
|
||||||
let rem_out: i32;
|
let rem_out: i32;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -262,9 +285,12 @@ pub fn rem(numerator: i32, denominator: i32) -> i32 {
|
||||||
/// by `2n` bits to get `n` more bits of fractional precision in your output.
|
/// by `2n` bits to get `n` more bits of fractional precision in your output.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn sqrt(val: u32) -> u16 {
|
pub fn sqrt(val: u32) -> u16 {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
0 // TODO: simulate this properly during testing builds.
|
{
|
||||||
} else {
|
0 // TODO: simulate this properly when not on GBA
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
let out: u16;
|
let out: u16;
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x08"
|
asm!(/* ASM */ "swi 0x08"
|
||||||
|
@ -286,9 +312,12 @@ pub fn sqrt(val: u32) -> u16 {
|
||||||
/// Accuracy suffers if `theta` is less than `-pi/4` or greater than `pi/4`.
|
/// Accuracy suffers if `theta` is less than `-pi/4` or greater than `pi/4`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn atan(theta: i16) -> i16 {
|
pub fn atan(theta: i16) -> i16 {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
0 // TODO: simulate this properly during testing builds.
|
{
|
||||||
} else {
|
0 // TODO: simulate this properly when not on GBA
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
let out: i16;
|
let out: i16;
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x09"
|
asm!(/* ASM */ "swi 0x09"
|
||||||
|
@ -311,9 +340,12 @@ pub fn atan(theta: i16) -> i16 {
|
||||||
/// integral, 14 bits for fractional.
|
/// integral, 14 bits for fractional.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn atan2(y: i16, x: i16) -> u16 {
|
pub fn atan2(y: i16, x: i16) -> u16 {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
0 // TODO: simulate this properly during testing builds.
|
{
|
||||||
} else {
|
0 // TODO: simulate this properly when not on GBA
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
let out: u16;
|
let out: u16;
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x0A"
|
asm!(/* ASM */ "swi 0x0A"
|
||||||
|
@ -338,9 +370,12 @@ pub fn atan2(y: i16, x: i16) -> u16 {
|
||||||
/// * Both pointers must be aligned
|
/// * Both pointers must be aligned
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn cpu_set16(src: *const u16, dest: *mut u16, count: u32, fixed_source: bool) {
|
pub unsafe fn cpu_set16(src: *const u16, dest: *mut u16, count: u32, fixed_source: bool) {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
let control = count + ((fixed_source as u32) << 24);
|
let control = count + ((fixed_source as u32) << 24);
|
||||||
asm!(/* ASM */ "swi 0x0B"
|
asm!(/* ASM */ "swi 0x0B"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -362,9 +397,12 @@ pub unsafe fn cpu_set16(src: *const u16, dest: *mut u16, count: u32, fixed_sourc
|
||||||
/// * Both pointers must be aligned
|
/// * Both pointers must be aligned
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn cpu_set32(src: *const u32, dest: *mut u32, count: u32, fixed_source: bool) {
|
pub unsafe fn cpu_set32(src: *const u32, dest: *mut u32, count: u32, fixed_source: bool) {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
let control = count + ((fixed_source as u32) << 24) + (1 << 26);
|
let control = count + ((fixed_source as u32) << 24) + (1 << 26);
|
||||||
asm!(/* ASM */ "swi 0x0B"
|
asm!(/* ASM */ "swi 0x0B"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -387,9 +425,12 @@ pub unsafe fn cpu_set32(src: *const u32, dest: *mut u32, count: u32, fixed_sourc
|
||||||
/// * Both pointers must be aligned
|
/// * Both pointers must be aligned
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn cpu_fast_set(src: *const u32, dest: *mut u32, count: u32, fixed_source: bool) {
|
pub unsafe fn cpu_fast_set(src: *const u32, dest: *mut u32, count: u32, fixed_source: bool) {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
let control = count + ((fixed_source as u32) << 24);
|
let control = count + ((fixed_source as u32) << 24);
|
||||||
asm!(/* ASM */ "swi 0x0C"
|
asm!(/* ASM */ "swi 0x0C"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -410,9 +451,12 @@ pub unsafe fn cpu_fast_set(src: *const u32, dest: *mut u32, count: u32, fixed_so
|
||||||
/// some other value I guess you're probably running on an emulator that just
|
/// some other value I guess you're probably running on an emulator that just
|
||||||
/// broke the fourth wall.
|
/// broke the fourth wall.
|
||||||
pub fn get_bios_checksum() -> u32 {
|
pub fn get_bios_checksum() -> u32 {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
0
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
let out: u32;
|
let out: u32;
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x0D"
|
asm!(/* ASM */ "swi 0x0D"
|
||||||
|
@ -447,9 +491,12 @@ pub fn get_bios_checksum() -> u32 {
|
||||||
///
|
///
|
||||||
/// The final sound level setting will be `level` * `0x200`.
|
/// The final sound level setting will be `level` * `0x200`.
|
||||||
pub fn sound_bias(level: u32) {
|
pub fn sound_bias(level: u32) {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x19"
|
asm!(/* ASM */ "swi 0x19"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -489,9 +536,12 @@ pub fn sound_bias(level: u32) {
|
||||||
/// * 10: 40137
|
/// * 10: 40137
|
||||||
/// * 11: 42048
|
/// * 11: 42048
|
||||||
pub fn sound_driver_mode(mode: u32) {
|
pub fn sound_driver_mode(mode: u32) {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x1B"
|
asm!(/* ASM */ "swi 0x1B"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -513,9 +563,12 @@ pub fn sound_driver_mode(mode: u32) {
|
||||||
/// executed." --what?
|
/// executed." --what?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn sound_driver_main() {
|
pub fn sound_driver_main() {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x1C"
|
asm!(/* ASM */ "swi 0x1C"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -533,9 +586,12 @@ pub fn sound_driver_main() {
|
||||||
/// vblank interrupt (every 1/60th of a second).
|
/// vblank interrupt (every 1/60th of a second).
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn sound_driver_vsync() {
|
pub fn sound_driver_vsync() {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x1D"
|
asm!(/* ASM */ "swi 0x1D"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -555,9 +611,12 @@ pub fn sound_driver_vsync() {
|
||||||
/// --what?
|
/// --what?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn sound_channel_clear() {
|
pub fn sound_channel_clear() {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x1E"
|
asm!(/* ASM */ "swi 0x1E"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -580,9 +639,12 @@ pub fn sound_channel_clear() {
|
||||||
/// noise.
|
/// noise.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn sound_driver_vsync_off() {
|
pub fn sound_driver_vsync_off() {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x28"
|
asm!(/* ASM */ "swi 0x28"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
@ -601,9 +663,12 @@ pub fn sound_driver_vsync_off() {
|
||||||
/// interrupt followed by a `sound_driver_vsync` within 2/60th of a second.
|
/// interrupt followed by a `sound_driver_vsync` within 2/60th of a second.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn sound_driver_vsync_on() {
|
pub fn sound_driver_vsync_on() {
|
||||||
if cfg!(test) {
|
#[cfg(not(all(target_vendor = "nintendo", target_env = "agb")))]
|
||||||
// do nothing in test mode
|
{
|
||||||
} else {
|
unimplemented!()
|
||||||
|
}
|
||||||
|
#[cfg(all(target_vendor = "nintendo", target_env = "agb"))]
|
||||||
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!(/* ASM */ "swi 0x29"
|
asm!(/* ASM */ "swi 0x29"
|
||||||
:/* OUT */ // none
|
:/* OUT */ // none
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
#![feature(const_int_wrapping)]
|
#![feature(const_int_wrapping)]
|
||||||
#![feature(const_int_rotate)]
|
#![feature(const_int_rotate)]
|
||||||
|
#![feature(cfg_target_vendor)]
|
||||||
#![allow(clippy::cast_lossless)]
|
#![allow(clippy::cast_lossless)]
|
||||||
#![deny(clippy::float_arithmetic)]
|
#![deny(clippy::float_arithmetic)]
|
||||||
//#![warn(missing_docs)]
|
//#![warn(missing_docs)]
|
||||||
|
|
Loading…
Reference in a new issue