aboutsummaryrefslogtreecommitdiff
path: root/src/cartridge.rs
blob: 0d21a42d3d11f41388755f04544304fca342eb1f (plain) (blame)
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
#![allow(dead_code)]

#[derive(Copy, Clone)]
pub enum MirrorType {
    Horizontal = 0,
    Vertical = 1,
    Single0 = 2,
    Single1 = 3,
    Four = 4
}

pub enum BankType {
    PrgRom, /* program rom */
    ChrRom, /* pattern rom */
    Sram,    /* save ram */
}

pub struct Cartridge {
    chr_rom: Vec<u8>,
    prg_rom: Vec<u8>,
    sram: Vec<u8>,
    pub mirror_type: MirrorType
}

impl Cartridge {
    pub fn get_size(&self, kind: BankType) -> usize {
        match kind {
            BankType::PrgRom => self.prg_rom.len(),
            BankType::ChrRom => self.chr_rom.len(),
            BankType::Sram => self.sram.len()
        }
    }
    pub fn get_bank(&mut self, base: usize, size: usize, kind: BankType) -> *mut [u8] {
        &mut (match kind {
            BankType::PrgRom => &mut self.prg_rom,
            BankType::ChrRom => &mut self.chr_rom,
            BankType::Sram => &mut self.sram,
        })[base..base + size]
    }
    pub fn new(chr_rom: Vec<u8>,
               prg_rom: Vec<u8>,
               sram: Vec<u8>,
               mirror_type: MirrorType) -> Self {
        Cartridge{chr_rom, prg_rom, sram, mirror_type}
    }
}