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
|
#![allow(dead_code)]
use core::cell::RefCell;
#[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: RefCell<Vec<u8>>,
prg_rom: RefCell<Vec<u8>>,
sram: RefCell<Vec<u8>>,
pub mirror_type: MirrorType
}
impl Cartridge {
pub fn get_size(&self, kind: BankType) -> usize {
match kind {
BankType::PrgRom => self.prg_rom.borrow().len(),
BankType::ChrRom => self.chr_rom.borrow().len(),
BankType::Sram => self.sram.borrow().len()
}
}
pub fn get_bank(&self, base: usize, size: usize, kind: BankType) -> *mut [u8] {
&mut (match kind {
BankType::PrgRom => self.prg_rom.borrow_mut(),
BankType::ChrRom => self.chr_rom.borrow_mut(),
BankType::Sram => self.sram.borrow_mut(),
})[base..base + size]
}
pub fn new(chr_rom: Vec<u8>,
prg_rom: Vec<u8>,
sram: Vec<u8>,
mirror_type: MirrorType) -> Self {
Cartridge{chr_rom: RefCell::new(chr_rom),
prg_rom: RefCell::new(prg_rom),
sram: RefCell::new(sram), mirror_type}
}
}
|