diff --git a/README.md b/README.md new file mode 100644 index 0000000..a5a5387 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# ZING: Z-machine Implementation for ruNning Games diff --git a/src/encoding.rs b/src/encoding.rs new file mode 100644 index 0000000..686cf72 --- /dev/null +++ b/src/encoding.rs @@ -0,0 +1,38 @@ +struct ZChar(u8); +struct ZsciiChar(u8); + +struct ZsciiString(Vec); + +/// 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> { + 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) { + +} diff --git a/src/main.rs b/src/main.rs index 8cd17b0..242897e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,9 @@ #![allow(dead_code)] +mod encoding; + +use std::fs::File; + // see ยง11 (page 61) of the spec #[repr(usize)] enum HeaderFields { @@ -40,10 +44,44 @@ enum ExtensionTableFields { 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, + memory_stack: [usize; 16], + memory_stack_length: usize, + input_record_enable: bool, + input_record_path: Option, +} + struct ZMachine5 { memory: Box<[u8]>, } +impl AllOutputStreams { + fn print(&mut self, memory: &mut [u8]) { + if self.memory_stack_length > 0 { + + } else { + + } + } +} + fn main() { println!("Hello, world!"); }