diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-04-16 10:51:13 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-04-16 10:51:26 +1200 |
commit | 6b3796c9a0d3a2f1422bcbde4790c43417659722 (patch) | |
tree | 6429a5fa2f8c4d3b26790775e07e46e6338b61d3 /src/devices/system/read_only_text_buffer.rs | |
parent | 28101de56231252ca0cfa6a9f107b75112c9acad (diff) | |
download | bedrock-pc-6b3796c9a0d3a2f1422bcbde4790c43417659722.zip |
Update devices to match new specifications
Diffstat (limited to 'src/devices/system/read_only_text_buffer.rs')
-rw-r--r-- | src/devices/system/read_only_text_buffer.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/devices/system/read_only_text_buffer.rs b/src/devices/system/read_only_text_buffer.rs new file mode 100644 index 0000000..7c59025 --- /dev/null +++ b/src/devices/system/read_only_text_buffer.rs @@ -0,0 +1,23 @@ +pub struct ReadOnlyTextBuffer { + chars: Vec<u8>, + pointer: usize, +} + +impl ReadOnlyTextBuffer { + pub fn from_text(text: &str) -> Self { + Self { + chars: text.chars().map(|c| c as u32 as u8).collect(), + pointer: 0, + } + } + + pub fn read_byte(&mut self) -> u8 { + let byte = self.chars[self.pointer]; + self.pointer += 1; + return byte; + } + + pub fn reset_pointer(&mut self) { + self.pointer = 0; + } +} |