aboutsummaryrefslogtreecommitdiff
path: root/src/globals.rs
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2016-01-13 09:42:18 -0700
committerDavid Li <li.davidm96@gmail.com>2016-01-13 09:42:18 -0700
commit56bf151b4fd091360246b2cfe230997e4082b0bc (patch)
tree68648edceada6302c8896efd878e54b7b3bbea73 /src/globals.rs
parent12e3bb51af09c56f306a1a365e989e8fb96b8a99 (diff)
Start working on updating global data structures
Diffstat (limited to 'src/globals.rs')
-rw-r--r--src/globals.rs58
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) {
+
+ }
+}