aboutsummaryrefslogtreecommitdiff
path: root/src/globals.rs
blob: 27d3bbd2950fbc61d06f70890f3bfeb679c2cdf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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) {

    }
}