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