some stuff in progress, moving work to desktop

main
aprzn 12 months ago
parent a7f58b3128
commit d6fc597ffa

@ -0,0 +1 @@
# ZING: Z-machine Implementation for ruNning Games

@ -0,0 +1,38 @@
struct ZChar(u8);
struct ZsciiChar(u8);
struct ZsciiString(Vec<ZsciiChar>);
/// Returns:
/// - a result that wraps a ZsciiString, erroring if the slice terminates before the string ends
/// - a usize indicating how many bytes were consumed
pub fn decode_zchars(zchars: &[u8]) -> Option<(ZsciiString, usize)> {
fn cut_string(zchars: &[u8]) -> Option<Vec<u16>> {
for (i, word) in zchars.chunks_exact(2).map(|c| u16::from_be_bytes([c[0], c[1]])).enumerate() {
}
}
let zchars = slice_string(zchars);
// let mut index: usize = 0;
// let mut out = Vec::new();
// loop {
// let word = u16::from_be_bytes([zchars[index], zchars[index + 1]]);
// let end_bit_set = word & 0x8000 != 0;
// let chars = [
// (word & (0b11111 << 10)) >> 10,
// (word & (0b11111 << 5)) >> 5,
// (word & (0b11111 << 0)) >> 0,
// ].map(|c| ZChar(c as u8));
// out.extend(chars);
// index += 2;
// if index >= zchars.len() - 1 { break (Err(out), index); }
// if end_bit_set { break (Ok(out), index); }
// // TODO: finish
// }
}
/// Returns:
pub fn decode_instruction(memory: &[u8], address: usize) {
}

@ -1,5 +1,9 @@
#![allow(dead_code)] #![allow(dead_code)]
mod encoding;
use std::fs::File;
// see §11 (page 61) of the spec // see §11 (page 61) of the spec
#[repr(usize)] #[repr(usize)]
enum HeaderFields { enum HeaderFields {
@ -40,10 +44,44 @@ enum ExtensionTableFields {
UnicodeTranslationTableAddr = 3, UnicodeTranslationTableAddr = 3,
} }
#[repr(u8)]
enum InputStream {
Keyboard = 0,
File = 1,
}
#[repr(u8)]
enum OutputStream {
Screen = 1,
Transcript = 2,
Memory = 3,
InputRecord = 4,
}
struct AllOutputStreams {
screen_enabled: bool,
transcript_enabled: bool,
transcript_path: Option<File>,
memory_stack: [usize; 16],
memory_stack_length: usize,
input_record_enable: bool,
input_record_path: Option<File>,
}
struct ZMachine5 { struct ZMachine5 {
memory: Box<[u8]>, memory: Box<[u8]>,
} }
impl AllOutputStreams {
fn print(&mut self, memory: &mut [u8]) {
if self.memory_stack_length > 0 {
} else {
}
}
}
fn main() { fn main() {
println!("Hello, world!"); println!("Hello, world!");
} }

Loading…
Cancel
Save