diff options
Diffstat (limited to 'src/globals.rs')
-rw-r--r-- | src/globals.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/globals.rs b/src/globals.rs new file mode 100644 index 0000000..27d3bbd --- /dev/null +++ b/src/globals.rs @@ -0,0 +1,58 @@ +use std::cell::RefCell; +use std::rc::Rc; + +use rustv::isa; +use rustv::memory::{Memory, MemoryInterface, Mmu}; + +use memory_tracker::MemoryTracker; + +pub const HOME_STATUS: isa::Address = 0xFFF00; + +/// Update the various global data structures as requested by other +/// subsystems. +// Intended to be passed around as &'a GlobalsUpdater +pub struct GlobalsUpdater<'a> { + // TODO: weak reference? + memory: Rc<RefCell<MemoryTracker>>, + mmu1: Box<Mmu + 'a>, + mmu2: Box<Mmu + 'a>, +} + +impl<'a> GlobalsUpdater<'a> { + pub fn new(memory: Rc<RefCell<MemoryTracker>>, + mmu1: Box<Mmu + 'a>, mmu2: Box<Mmu + 'a>) -> GlobalsUpdater<'a> { + GlobalsUpdater { + memory: memory, + mmu1: mmu1, + mmu2: mmu2, + } + } + + pub fn init_memory(&self) { + // Initialize taunt array to all -1 + for offset in 0..(228 / 4) { + let address1 = self.mmu1.translate(HOME_STATUS + 28 + offset); + let address2 = self.mmu2.translate(HOME_STATUS + 28 + offset); + let _ = self.memory.borrow_mut().write_word( + address1, + (-1 as i32) as isa::Word); + let _ = self.memory.borrow_mut().write_word( + address2, + (-1 as i32) as isa::Word); + } + } + + // TODO: how to distinguish which player? + pub fn fetch_tag(&self, tag: isa::Address, index: u32) { + // TODO: assert index is 0 or 1 + let address = HOME_STATUS; + } + + pub fn finish_tag(&self, tag: isa::Address, index: u32) { + + } + + pub fn update_score(&self, player1: i64, player2: i64) { + + } +} |