summaryrefslogtreecommitdiff
path: root/src/devices/file/circular_path_buffer.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-10-28 20:25:01 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2024-10-28 20:29:12 +1300
commit1a830a3d1b9d99653322d5ae49ea8165de7ed9d0 (patch)
tree798e77b6fcf2438b1c2538a67efe856a2f7cb979 /src/devices/file/circular_path_buffer.rs
parent03c4b069e1806af256730639cefdae115b24401a (diff)
downloadbedrock-pc-1a830a3d1b9d99653322d5ae49ea8165de7ed9d0.zip
Rewrite emulatorv1.0.0-alpha1
This is a complete rewrite and restructure of the entire emulator project, as part of the effort in locking down the Bedrock specification and in creating much better tooling for creating and using Bedrock programs. This commit adds a command-line argument scheme, an embedded assembler, a headless emulator for use in non-graphical environments, deferred window creation for programs that do not access the screen device, and new versions of phosphor and bedrock-core. The new version of phosphor supports multi-window programs, which will make it possible to implement program forking in the system device later on, and the new version of bedrock-core implements the final core specification.
Diffstat (limited to 'src/devices/file/circular_path_buffer.rs')
-rw-r--r--src/devices/file/circular_path_buffer.rs60
1 files changed, 0 insertions, 60 deletions
diff --git a/src/devices/file/circular_path_buffer.rs b/src/devices/file/circular_path_buffer.rs
deleted file mode 100644
index 9d1dea6..0000000
--- a/src/devices/file/circular_path_buffer.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-pub struct CircularPathBuffer {
- buffer: [u8; 256],
- pointer: u8,
-}
-
-impl CircularPathBuffer {
- pub fn new() -> Self {
- Self { buffer: [0; 256] , pointer: 0 }
- }
-
- /// Clear the buffer, returning the previous buffer contents.
- pub fn clear(&mut self) -> [u8; 256] {
- self.pointer = 0;
- std::mem::replace(&mut self.buffer, [0; 256])
- }
-
- /// Reset the pointer and hot-swap the byte buffer.
- pub fn populate(&mut self, buffer: [u8; 256]) {
- self.pointer = 0;
- self.buffer = buffer;
- }
-
- /// Move internal pointer to either the start of the path or the file name.
- ///
- /// If value is non-zero, the pointer will be moved to the byte
- /// directly following the final forward-slash.
- pub fn set_pointer(&mut self, value: u8) {
- self.pointer = 0;
- // Set the pointer to the start of the filename if value is truthy.
- if value != 0x00 {
- for (i, c) in self.buffer.iter().enumerate() {
- match c {
- b'/' => self.pointer = (i as u8).saturating_add(1),
- 0x00 => break,
- _ => continue,
- }
- }
- }
- }
-
- /// Read a single byte from the buffer.
- pub fn read_byte(&mut self) -> u8 {
- let pointer = self.pointer as usize;
- self.pointer = self.pointer.wrapping_add(1);
- self.buffer[pointer]
- }
-
- /// Write a single byte to the buffer.
- ///
- /// If a null-byte is written, the buffer will be cleared and returned.
- pub fn push_byte(&mut self, byte: u8) -> Option<[u8; 256]> {
- if byte == 0x00 {
- Some(self.clear())
- } else {
- self.buffer[self.pointer as usize] = byte;
- self.pointer = self.pointer.wrapping_add(1);
- None
- }
- }
-}