diff options
author | Determinant <ted.sybil@gmail.com> | 2018-01-08 00:32:32 +0800 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2018-01-08 00:32:32 +0800 |
commit | 96c7c1e4fee261ecf386fb2fff2155f06a2f7973 (patch) | |
tree | a7d32d2173ca7ae277a97e47ed78fe654545c31b /src/controller.rs | |
parent | df6acf714c3ea975e75057b8b5a1d5e0fdf83109 (diff) |
support console state load/save (minor bugs still present)
Diffstat (limited to 'src/controller.rs')
-rw-r--r-- | src/controller.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/controller.rs b/src/controller.rs index f2ed4f7..bb78769 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -1,11 +1,15 @@ #![allow(dead_code)] +use utils::{Read, Write}; pub trait Controller { fn read(&self) -> u8; fn write(&self, data: u8); + fn load(&mut self, reader: &mut Read) -> bool; + fn save(&self, writer: &mut Write) -> bool; } pub mod stdctl { + use utils::{Read, Write, load_prefix, save_prefix}; use core::cell::Cell; use controller::Controller; pub const A: u8 = 1 << 0; @@ -18,6 +22,7 @@ pub mod stdctl { pub const RIGHT: u8 = 1 << 7; pub const NULL: u8 = 0; + #[repr(C)] pub struct Joystick { strobe: Cell<bool>, reg: Cell<u8>, @@ -48,5 +53,13 @@ pub mod stdctl { self.strobe.set(data & 1 == 1); self.reg.set(self.back_reg.get()); } + + fn load(&mut self, reader: &mut Read) -> bool { + load_prefix(self, 0, reader) + } + + fn save(&self, writer: &mut Write) -> bool { + save_prefix(self, 0, writer) + } } } |