Encode word size into OverlayLBA structure
This commit is contained in:
parent
d452a022cf
commit
ffc0666935
|
@ -5,13 +5,13 @@
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
struct __attribute__((packed)) OverlayHeader {
|
struct __attribute__((packed)) OverlayHeader {
|
||||||
void (*execute)();
|
void (*execute)();
|
||||||
uint16_t lba_size;
|
uint16_t lba_size; //< The size of the OverlayLBA section
|
||||||
};
|
};
|
||||||
|
|
||||||
// Maybe encode attributes like "isLZ4" into size parameter
|
// Maybe encode attributes like "isLZ4" into size parameter
|
||||||
struct __attribute__((packed)) OverlayLBA {
|
struct __attribute__((packed)) OverlayLBA {
|
||||||
uint16_t lba;
|
uint16_t lba;
|
||||||
uint16_t size;
|
uint16_t size_words;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif //!__JABYENGINE_OVERLAY__HPP__
|
#endif //!__JABYENGINE_OVERLAY__HPP__
|
|
@ -20,17 +20,27 @@ impl OverlayHeader {
|
||||||
|
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
struct LBAEntry {
|
struct LBAEntry {
|
||||||
lba: u16,
|
lba: u16,
|
||||||
sectors: u16,
|
size_words: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LBAEntry {
|
impl LBAEntry {
|
||||||
pub fn write_entry(&mut self, lba: u16, sectors: u16) {
|
pub fn write_entry(&mut self, lba: u16, mut size_bytes: usize) -> Result<(), Error> {
|
||||||
let lba = lba.to_le_bytes();
|
const WORD_SIZE:usize = std::mem::size_of::<u32>();
|
||||||
let sectors = sectors.to_le_bytes();
|
|
||||||
|
|
||||||
self.lba = u16::from_ne_bytes(lba);
|
size_bytes = (size_bytes + (WORD_SIZE - 1))/WORD_SIZE;
|
||||||
self.sectors = u16::from_ne_bytes(sectors);
|
|
||||||
|
if (size_bytes as u16) as usize != size_bytes {
|
||||||
|
return Err(Error::from_text(format!("{} words can not be incoded into 16bit", size_bytes)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let lba = lba.to_le_bytes();
|
||||||
|
let size_bytes = (size_bytes as u16).to_le_bytes();
|
||||||
|
|
||||||
|
self.lba = u16::from_ne_bytes(lba);
|
||||||
|
self.size_words = u16::from_ne_bytes(size_bytes);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,13 +59,13 @@ pub fn update_content(content: &mut Vec<u8>, lba_names: &LBANameVec, file_map: &
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
for lba_name in lba_names {
|
for lba_name in lba_names {
|
||||||
if let Some(file) = file_map.get(lba_name) {
|
if let Some(file) = file_map.get(lba_name) {
|
||||||
let (lba, sector_count) = (file.borrow().get_track_rel_lba(), length_func(&Layout::File(file.clone())).sectors);
|
let (lba, bytes) = (file.borrow().get_track_rel_lba(), length_func(&Layout::File(file.clone())).bytes);
|
||||||
|
|
||||||
if idx >= lba_count {
|
if idx >= lba_count {
|
||||||
return Err(Error::from_text(format!("Trying to write more LBAs then there is space!")));
|
return Err(Error::from_text(format!("Trying to write more LBAs then there is space!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
lba_header[idx].write_entry(lba as u16, sector_count as u16);
|
lba_header[idx].write_entry(lba as u16, bytes.ok_or(Error::from_text(format!("{} does not contain a size!", lba_name)))?)?;
|
||||||
idx += 1;
|
idx += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue