start of Disk
This commit is contained in:
parent
38004e0bc4
commit
66eaa8a64f
@ -0,0 +1,52 @@
|
||||
use core::panic;
|
||||
use std::{fs::{File, self}, io::{BufReader, Read, Seek, SeekFrom, Write}};
|
||||
|
||||
pub const SECTORS_PER_TRACK : i32 = 32;
|
||||
pub const NUM_TRACKS : i32 = 64;
|
||||
pub const NUM_SECTORS : i32 = SECTORS_PER_TRACK * NUM_TRACKS;
|
||||
pub const SECTOR_SIZE : i32 = 128;
|
||||
|
||||
pub struct Disk {
|
||||
pub file : File,
|
||||
pub last_selector : i32,
|
||||
pub active : bool
|
||||
}
|
||||
|
||||
impl Disk {
|
||||
|
||||
pub fn init_disk(path : String) -> Disk {
|
||||
Disk {
|
||||
file : fs::File::open(path).unwrap(),
|
||||
last_selector : 0,
|
||||
active : false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_request(disk : &mut Disk, sector_number : i32, data : &mut Vec<u8>) {
|
||||
if disk.active {
|
||||
panic!("Only one request at time");
|
||||
}
|
||||
|
||||
if sector_number < 0 || sector_number >= NUM_SECTORS {
|
||||
panic!("sector_number isn't right");
|
||||
}
|
||||
|
||||
disk.file.seek(SeekFrom::Start((sector_number * SECTOR_SIZE) as u64));
|
||||
let mut reader = BufReader::new(&disk.file);
|
||||
reader.read(data);
|
||||
|
||||
}
|
||||
|
||||
pub fn write_request(disk : &mut Disk, sector_number : i32, data : &mut Vec<u8>) {
|
||||
if disk.active {
|
||||
panic!("Only one request at time");
|
||||
}
|
||||
|
||||
if sector_number < 0 || sector_number >= NUM_SECTORS {
|
||||
panic!("sector_number isn't right");
|
||||
}
|
||||
|
||||
disk.file.seek(SeekFrom::Start((sector_number * SECTOR_SIZE) as u64));
|
||||
disk.file.write(data);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ pub mod loader;
|
||||
pub mod interrupt;
|
||||
pub mod translationtable;
|
||||
pub mod mmu;
|
||||
pub mod disk;
|
||||
|
||||
pub mod global {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user