fix the terminal loader
parent
f65276bcc5
commit
fd37b9a6b8
|
@ -1,5 +1,28 @@
|
||||||
//! Text conversion utilities.
|
//! Text conversion utilities.
|
||||||
|
|
||||||
|
/// Dumps a slice of memory as text to stdout.
|
||||||
|
pub fn dump_mem(b: &[u8])
|
||||||
|
{
|
||||||
|
let mut p = 0;
|
||||||
|
|
||||||
|
for &c in b {
|
||||||
|
if p + 3 > 79 {
|
||||||
|
println!("");
|
||||||
|
p = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.is_ascii_graphic() {
|
||||||
|
print!(" {} ", c as char);
|
||||||
|
} else {
|
||||||
|
print!("{:02X} ", c);
|
||||||
|
}
|
||||||
|
|
||||||
|
p += 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("");
|
||||||
|
}
|
||||||
|
|
||||||
/// Formats a binary size string for any given number.
|
/// Formats a binary size string for any given number.
|
||||||
pub fn to_binsize(n: u64) -> String
|
pub fn to_binsize(n: u64) -> String
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,71 +1,72 @@
|
||||||
use crate::durandal::{bin::*, err::*, text::*};
|
use crate::durandal::{bin::*, err::*, text::*};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
impl Terminal
|
pub fn read_group(b: &[u8], text: &[u8]) -> ResultS<Group>
|
||||||
{
|
{
|
||||||
pub fn read(b: &[u8]) -> ResultS<(usize, Terminal)>
|
// flags = b.c_u16b( 0)?;
|
||||||
|
let ttype = b.c_u16b( 2)?.into();
|
||||||
|
let pdata = b.c_i16b( 4)?;
|
||||||
|
let start = b.c_u16b( 6)? as usize;
|
||||||
|
let size = b.c_u16b( 8)? as usize;
|
||||||
|
let lines = b.c_u16b(10)?;
|
||||||
|
let text = mac_roman_conv(&text[start..start+size]);
|
||||||
|
|
||||||
|
Ok(Group{ttype, pdata, lines, text})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_face(b: &[u8]) -> ResultS<Face>
|
||||||
|
{
|
||||||
|
let start = b.c_u16b(0)? as usize;
|
||||||
|
let face = b.c_u16b(2)?;
|
||||||
|
let color = b.c_u16b(4)?;
|
||||||
|
|
||||||
|
Ok(Face{start, face, color})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_terminal(b: &[u8]) -> ResultS<(usize, Terminal)>
|
||||||
{
|
{
|
||||||
const SIZE_HEAD : usize = 10;
|
|
||||||
const SIZE_GROUP: usize = 12;
|
const SIZE_GROUP: usize = 12;
|
||||||
const SIZE_FACE : usize = 6;
|
const SIZE_FACE : usize = 6;
|
||||||
|
|
||||||
let len = b.c_u16b(0)? as usize;
|
let end = b.c_u16b(0)? as usize;
|
||||||
let enc = b.c_u16b(2)? & 1 != 0;
|
let encoded = b.c_u16b(2)? & 1 != 0;
|
||||||
let lns = b.c_u16b(4)?;
|
let lines = b.c_u16b(4)?;
|
||||||
let gnu = b.c_u16b(6)? as usize;
|
let group_n = b.c_u16b(6)? as usize;
|
||||||
let fnu = b.c_u16b(8)? as usize;
|
let face_n = b.c_u16b(8)? as usize;
|
||||||
|
|
||||||
let mut grp = Vec::with_capacity(gnu);
|
let mut groups = Vec::with_capacity(group_n);
|
||||||
let mut fcs = Vec::with_capacity(fnu);
|
let mut faces = Vec::with_capacity( face_n);
|
||||||
let end = SIZE_GROUP * gnu + SIZE_FACE * fnu + SIZE_HEAD;
|
|
||||||
|
|
||||||
let mut p = SIZE_HEAD;
|
let mut p = 10; // size of header
|
||||||
|
|
||||||
for _ in 0..gnu {
|
let text_st = p + SIZE_GROUP * group_n + SIZE_FACE * face_n;
|
||||||
// flg = b.c_u16b(p )?;
|
let text = &b[text_st..end];
|
||||||
let typ = b.c_u16b(p+ 2)?.into();
|
let text = if encoded {fuck_string(text)} else {text.to_vec()};
|
||||||
let per = b.c_i16b(p+ 4)?;
|
|
||||||
let beg = b.c_u16b(p+ 6)? as usize;
|
|
||||||
let len = b.c_u16b(p+ 8)? as usize;
|
|
||||||
let lns = b.c_u16b(p+10)?;
|
|
||||||
|
|
||||||
let sta = end + beg;
|
|
||||||
|
|
||||||
let txt = &b[sta..sta+len];
|
|
||||||
let txt = if enc {mac_roman_conv(&fuck_string(txt))}
|
|
||||||
else {mac_roman_conv(&txt)};
|
|
||||||
|
|
||||||
grp.push(Group{typ, per, lns, txt});
|
|
||||||
|
|
||||||
|
for _ in 0..group_n {
|
||||||
|
groups.push(read_group(&b[p..], &text)?);
|
||||||
p += SIZE_GROUP;
|
p += SIZE_GROUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
for _ in 0..fnu {
|
for _ in 0..face_n {
|
||||||
let ind = b.c_u16b(p )?;
|
faces.push(read_face(&b[p..])?);
|
||||||
let fce = b.c_u16b(p+2)?;
|
|
||||||
let col = b.c_u16b(p+4)?;
|
|
||||||
|
|
||||||
fcs.push(Face{ind, fce, col});
|
|
||||||
|
|
||||||
p += SIZE_FACE;
|
p += SIZE_FACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((len, Terminal{enc, lns, grp, fcs}))
|
Ok((end, Terminal{lines, groups, faces}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Terminal
|
||||||
|
{
|
||||||
pub fn chunk(b: &[u8]) -> ResultS<Vec<Terminal>>
|
pub fn chunk(b: &[u8]) -> ResultS<Vec<Terminal>>
|
||||||
{
|
{
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
let mut p = 0;
|
let mut p = 0;
|
||||||
|
|
||||||
while p < b.len() {
|
while p < b.len() {
|
||||||
let sta = p;
|
let (size, trm) = read_terminal(&b[p..])?;
|
||||||
|
|
||||||
let (len, trm) = Terminal::read(&b[p..])?;
|
|
||||||
|
|
||||||
v.push(trm);
|
v.push(trm);
|
||||||
|
p += size;
|
||||||
p = sta + len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(v)
|
Ok(v)
|
||||||
|
@ -75,25 +76,24 @@ impl Terminal
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Terminal
|
pub struct Terminal
|
||||||
{
|
{
|
||||||
enc: bool,
|
lines: u16,
|
||||||
lns: u16,
|
groups: Vec<Group>,
|
||||||
grp: Vec<Group>,
|
faces: Vec<Face>,
|
||||||
fcs: Vec<Face>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Face
|
pub struct Face
|
||||||
{
|
{
|
||||||
ind: u16,
|
start: usize,
|
||||||
fce: u16,
|
face: u16,
|
||||||
col: u16,
|
color: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Group
|
pub struct Group
|
||||||
{
|
{
|
||||||
typ: Type,
|
ttype: Type,
|
||||||
per: i16,
|
pdata: i16,
|
||||||
lns: u16,
|
lines: u16,
|
||||||
txt: String,
|
text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -103,10 +103,10 @@ pub enum Type
|
||||||
Unfinished,
|
Unfinished,
|
||||||
Success,
|
Success,
|
||||||
Failure,
|
Failure,
|
||||||
Information,
|
Info,
|
||||||
End,
|
End,
|
||||||
InterlevelTeleport,
|
TeleInter,
|
||||||
IntralevelTeleport,
|
TeleIntra,
|
||||||
Checkpoint,
|
Checkpoint,
|
||||||
Sound,
|
Sound,
|
||||||
Movie,
|
Movie,
|
||||||
|
@ -115,7 +115,7 @@ pub enum Type
|
||||||
Logoff,
|
Logoff,
|
||||||
Camera,
|
Camera,
|
||||||
Static,
|
Static,
|
||||||
TagActivate,
|
Tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u16> for Type
|
impl From<u16> for Type
|
||||||
|
@ -127,10 +127,10 @@ impl From<u16> for Type
|
||||||
1 => Type::Unfinished,
|
1 => Type::Unfinished,
|
||||||
2 => Type::Success,
|
2 => Type::Success,
|
||||||
3 => Type::Failure,
|
3 => Type::Failure,
|
||||||
4 => Type::Information,
|
4 => Type::Info,
|
||||||
5 => Type::End,
|
5 => Type::End,
|
||||||
6 => Type::InterlevelTeleport,
|
6 => Type::TeleInter,
|
||||||
7 => Type::IntralevelTeleport,
|
7 => Type::TeleIntra,
|
||||||
8 => Type::Checkpoint,
|
8 => Type::Checkpoint,
|
||||||
9 => Type::Sound,
|
9 => Type::Sound,
|
||||||
10 => Type::Movie,
|
10 => Type::Movie,
|
||||||
|
@ -139,7 +139,7 @@ impl From<u16> for Type
|
||||||
13 => Type::Logoff,
|
13 => Type::Logoff,
|
||||||
14 => Type::Camera,
|
14 => Type::Camera,
|
||||||
15 => Type::Static,
|
15 => Type::Static,
|
||||||
16 => Type::TagActivate,
|
16 => Type::Tag,
|
||||||
_ => panic!("invalid terminal group type {}", n),
|
_ => panic!("invalid terminal group type {}", n),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ impl fmt::Debug for Face
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
||||||
{
|
{
|
||||||
write!(f, "Face{{{} {} {}}}", self.ind, self.fce, self.col)
|
write!(f, "Face{{{} {} {}}}", self.start, self.face, self.color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +157,8 @@ impl fmt::Debug for Group
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
||||||
{
|
{
|
||||||
write!(f, "Group{{{:?} {} {}", self.typ, self.per, self.lns)?;
|
write!(f, "Group{{{:?} {} {}", self.ttype, self.pdata, self.lines)?;
|
||||||
if self.txt.len() != 0 {write!(f, ";\n{}\n", self.txt)?;}
|
if self.text.len() != 0 {write!(f, ";\n{}\n", self.text)?;}
|
||||||
write!(f, "}}")
|
write!(f, "}}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue