mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Merge pull request #239 from gwilymk/try-to-fix-agbabi-memcpy-issue
Fix agbabi memcpy issue
This commit is contained in:
commit
e5d35e50c8
|
@ -29,6 +29,10 @@ __aeabi_memcpy:
|
|||
bmi .Lcopy1
|
||||
bcs .Lcopy2
|
||||
|
||||
// If the number of bytes to copy is less than 4, we should just copy one byte at a time
|
||||
cmp r2, #4
|
||||
bmi .Lcopy1
|
||||
|
||||
.Lcopy4:
|
||||
// Copy half and byte head
|
||||
rsb r3, r0, #4
|
||||
|
|
153
agb/src/agbabi/mod.rs
Normal file
153
agb/src/agbabi/mod.rs
Normal file
|
@ -0,0 +1,153 @@
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
mod memcpy {
|
||||
use alloc::vec;
|
||||
|
||||
use crate::Gba;
|
||||
|
||||
extern "C" {
|
||||
fn __agbabi_memcpy(dest: *mut u8, src: *const u8, n: usize);
|
||||
fn __aeabi_memcpy4(dest: *mut u32, src: *const u32, n: usize);
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_memcpy4_with_different_sizes(_gba: &mut Gba) {
|
||||
let mut input = vec![0u32; 70];
|
||||
let mut output = vec![0u32; 70];
|
||||
|
||||
for size in 0..68 {
|
||||
for (i, value) in input.iter_mut().enumerate() {
|
||||
*value = i as u32 * 6;
|
||||
}
|
||||
|
||||
output.fill(0);
|
||||
|
||||
unsafe {
|
||||
__aeabi_memcpy4(output.as_mut_ptr(), input.as_ptr(), size * 4);
|
||||
}
|
||||
|
||||
for i in 0..size {
|
||||
assert_eq!(input[i], output[i], "Failed with size = {size} at i = {i}");
|
||||
}
|
||||
|
||||
for (i, value) in output.iter().enumerate().skip(size) {
|
||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_memcpy_bytes_with_different_sizes(_gba: &mut Gba) {
|
||||
let mut input = vec![0u8; 70];
|
||||
let mut output = vec![0u8; 70];
|
||||
|
||||
for size in 0..68 {
|
||||
for (i, value) in input.iter_mut().enumerate() {
|
||||
*value = i as u8 * 3;
|
||||
}
|
||||
|
||||
output.fill(0);
|
||||
|
||||
unsafe {
|
||||
__agbabi_memcpy(output.as_mut_ptr(), input.as_ptr(), size);
|
||||
}
|
||||
|
||||
for i in 0..size {
|
||||
assert_eq!(input[i], output[i], "Failed with size = {size} at i = {i}");
|
||||
}
|
||||
|
||||
for (i, value) in output.iter().enumerate().skip(size) {
|
||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_memcpy_bytes_output_offsetted_with_different_sizes(_gba: &mut Gba) {
|
||||
let mut input = vec![0u8; 70];
|
||||
let mut output = vec![0u8; 70];
|
||||
|
||||
for size in 0..60 {
|
||||
for (i, value) in input.iter_mut().enumerate() {
|
||||
*value = i as u8 * 3;
|
||||
}
|
||||
|
||||
output.fill(0);
|
||||
|
||||
unsafe {
|
||||
__agbabi_memcpy(output.as_mut_ptr().add(1), input.as_ptr(), size);
|
||||
}
|
||||
|
||||
for i in 0..size {
|
||||
assert_eq!(
|
||||
input[i],
|
||||
output[i + 1],
|
||||
"Failed with size = {size} at i = {i}"
|
||||
);
|
||||
}
|
||||
|
||||
for (i, value) in output.iter().enumerate().skip(size + 1) {
|
||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_memcpy_bytes_input_offsetted_with_different_sizes(_gba: &mut Gba) {
|
||||
let mut input = vec![0u8; 70];
|
||||
let mut output = vec![0u8; 70];
|
||||
|
||||
for size in 0..60 {
|
||||
for (i, value) in input.iter_mut().enumerate() {
|
||||
*value = i as u8 * 3;
|
||||
}
|
||||
|
||||
output.fill(0);
|
||||
|
||||
unsafe {
|
||||
__agbabi_memcpy(output.as_mut_ptr(), input.as_ptr().add(1), size);
|
||||
}
|
||||
|
||||
for i in 0..size {
|
||||
assert_eq!(
|
||||
input[i + 1],
|
||||
output[i],
|
||||
"Failed with size = {size} at i = {i}"
|
||||
);
|
||||
}
|
||||
|
||||
for (i, value) in output.iter().enumerate().skip(size) {
|
||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_memcpy_bytes_input_output_offsetted_with_different_sizes(_gba: &mut Gba) {
|
||||
let mut input = vec![0u8; 70];
|
||||
let mut output = vec![0u8; 70];
|
||||
|
||||
for size in 0..60 {
|
||||
for (i, value) in input.iter_mut().enumerate() {
|
||||
*value = i as u8 * 3;
|
||||
}
|
||||
|
||||
output.fill(0);
|
||||
|
||||
unsafe {
|
||||
__agbabi_memcpy(output.as_mut_ptr().add(1), input.as_ptr().add(1), size);
|
||||
}
|
||||
|
||||
assert_eq!(output[0], 0);
|
||||
|
||||
for i in 1..size + 1 {
|
||||
assert_eq!(input[i], output[i], "Failed with size = {size} at i = {i}");
|
||||
}
|
||||
|
||||
for (i, value) in output.iter().enumerate().skip(size + 1) {
|
||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -157,6 +157,7 @@ pub use agb_sound_converter::include_wav;
|
|||
extern crate alloc;
|
||||
mod agb_alloc;
|
||||
|
||||
mod agbabi;
|
||||
mod bitarray;
|
||||
/// Implements everything relating to things that are displayed on screen.
|
||||
pub mod display;
|
||||
|
|
Loading…
Reference in a new issue