[ref] Refactor memory

This commit is contained in:
2024-02-18 09:35:58 +05:30
parent 5701808e77
commit 2f0e0b4730
4 changed files with 83 additions and 40 deletions

View File

@@ -4,6 +4,8 @@ use std::fmt::Debug;
pub enum DeviceType {
RAM,
MMU,
/// Program counter
PC,
KEYBOARD,
AUDIO,
GRAPHICS,

View File

@@ -1,18 +1,13 @@
use byteorder::{BigEndian, ByteOrder};
pub struct MemoryOperations();
impl MemoryOperations {
/// read a 24bit endian value, and place it in a u32 num
pub fn read_big_endian_u24(input: &[u8; 3]) -> u32 {
BigEndian::read_u24(input)
}
pub fn read_big_endian_u16(input: &[u8; 2]) -> u16 {
BigEndian::read_u16(input)
}
/// Write 24-bit endian number into slice
pub fn write_big_endian_u24(input: u32, output_slice: &mut [u8; 3]) {
BigEndian::write_u24(output_slice, input);
}
pub fn read_big_endian_u24(input: &[u8; 3]) -> u32 {
BigEndian::read_u24(input)
}
pub fn read_big_endian_u16(input: &[u8; 2]) -> u16 {
BigEndian::read_u16(input)
}
/// Write 24-bit endian number into slice
pub fn write_big_endian_u24(input: u32, output_slice: &mut [u8; 3]) {
BigEndian::write_u24(output_slice, input);
}