change arr_to_addr to address_from_bytes

This commit is contained in:
Sam M W 2024-04-23 17:06:00 +01:00 committed by Matthias Endler
parent 11499b6bc8
commit da30c8c67d
1 changed files with 7 additions and 8 deletions

View File

@ -31,10 +31,9 @@ use crate::Variant;
use crate::registers::{Registers, StackPointer, Status, StatusArgs};
fn arr_to_addr(arr: &[u8]) -> u16 {
debug_assert!(arr.len() == 2);
fn address_from_bytes(lo: u8, hi: u8) -> u16 {
u16::from(arr[0]) + (u16::from(arr[1]) << 8usize)
u16::from(lo) + (u16::from(hi) << 8usize)
}
#[derive(Clone)]
@ -136,17 +135,17 @@ impl<M: Bus, V: Variant> CPU<M, V> {
AddressingMode::Absolute => {
// Use [u8, ..2] from instruction as address
// (Output: a 16-bit address)
OpInput::UseAddress(arr_to_addr(&slice))
OpInput::UseAddress(address_from_bytes(slice[0], slice[1]))
}
AddressingMode::AbsoluteX => {
// Use [u8, ..2] from instruction as address, add X
// (Output: a 16-bit address)
OpInput::UseAddress(arr_to_addr(&slice).wrapping_add(x.into()))
OpInput::UseAddress(address_from_bytes(slice[0], slice[1]).wrapping_add(x.into()))
}
AddressingMode::AbsoluteY => {
// Use [u8, ..2] from instruction as address, add Y
// (Output: a 16-bit address)
OpInput::UseAddress(arr_to_addr(&slice).wrapping_add(y.into()))
OpInput::UseAddress(address_from_bytes(slice[0], slice[1]).wrapping_add(y.into()))
}
AddressingMode::Indirect => {
// Use [u8, ..2] from instruction as an address. Interpret the
@ -162,7 +161,7 @@ impl<M: Bus, V: Variant> CPU<M, V> {
// (Output: a 16-bit address)
let start = slice[0].wrapping_add(x);
let slice = read_address(memory, u16::from(start));
OpInput::UseAddress(arr_to_addr(&slice))
OpInput::UseAddress(address_from_bytes(slice[0], slice[1]))
}
AddressingMode::IndirectIndexedY => {
// Use [u8, ..1] from instruction
@ -171,7 +170,7 @@ impl<M: Bus, V: Variant> CPU<M, V> {
// (Output: a 16-bit address)
let start = slice[0];
let slice = read_address(memory, u16::from(start));
OpInput::UseAddress(arr_to_addr(&slice).wrapping_add(y.into()))
OpInput::UseAddress(address_from_bytes(slice[0], slice[1]).wrapping_add(y.into()))
}
};