Encode word size into OverlayLBA structure
This commit is contained in:
parent
d452a022cf
commit
ffc0666935
|
@ -5,13 +5,13 @@
|
|||
namespace JabyEngine {
|
||||
struct __attribute__((packed)) OverlayHeader {
|
||||
void (*execute)();
|
||||
uint16_t lba_size;
|
||||
uint16_t lba_size; //< The size of the OverlayLBA section
|
||||
};
|
||||
|
||||
// Maybe encode attributes like "isLZ4" into size parameter
|
||||
struct __attribute__((packed)) OverlayLBA {
|
||||
uint16_t lba;
|
||||
uint16_t size;
|
||||
uint16_t size_words;
|
||||
};
|
||||
}
|
||||
#endif //!__JABYENGINE_OVERLAY__HPP__
|
|
@ -20,17 +20,27 @@ impl OverlayHeader {
|
|||
|
||||
#[repr(packed)]
|
||||
struct LBAEntry {
|
||||
lba: u16,
|
||||
sectors: u16,
|
||||
lba: u16,
|
||||
size_words: u16,
|
||||
}
|
||||
|
||||
impl LBAEntry {
|
||||
pub fn write_entry(&mut self, lba: u16, sectors: u16) {
|
||||
let lba = lba.to_le_bytes();
|
||||
let sectors = sectors.to_le_bytes();
|
||||
pub fn write_entry(&mut self, lba: u16, mut size_bytes: usize) -> Result<(), Error> {
|
||||
const WORD_SIZE:usize = std::mem::size_of::<u32>();
|
||||
|
||||
self.lba = u16::from_ne_bytes(lba);
|
||||
self.sectors = u16::from_ne_bytes(sectors);
|
||||
size_bytes = (size_bytes + (WORD_SIZE - 1))/WORD_SIZE;
|
||||
|
||||
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;
|
||||
for lba_name in lba_names {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue