aboutsummaryrefslogtreecommitdiff
path: root/src/cartridge.rs
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2017-11-12 23:28:55 -0500
committerDeterminant <ted.sybil@gmail.com>2017-11-12 23:28:55 -0500
commit7febfa1567252a891a512e3c1e3e5a1f838a853f (patch)
tree8392fc6f9a93c83a74619110f04480a50639640d /src/cartridge.rs
parent0edff96acccceb102fd97a9200f5504200d5fa50 (diff)
fix various bugs
Diffstat (limited to 'src/cartridge.rs')
-rw-r--r--src/cartridge.rs37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/cartridge.rs b/src/cartridge.rs
index f96c234..b8d2b68 100644
--- a/src/cartridge.rs
+++ b/src/cartridge.rs
@@ -1,3 +1,4 @@
+#![allow(dead_code)]
use core::cell::RefCell;
#[derive(Copy, Clone)]
@@ -16,23 +17,33 @@ pub enum BankType {
}
pub struct Cartridge {
- chr_rom: [u8; 8192],
- prg_rom: RefCell<[u8; 8192]>,
- sram: [u8; 8192],
+ chr_rom: RefCell<Vec<u8>>,
+ prg_rom: RefCell<Vec<u8>>,
+ sram: RefCell<Vec<u8>>,
pub mirror_type: MirrorType
}
impl Cartridge {
- pub fn get_bank_num(&self, kind: BankType) -> usize {0}
- pub fn get_bank(&self, idx: usize, kind: BankType) -> *mut [u8] {
- &mut *self.prg_rom.borrow_mut()
- }
- pub fn new() -> Self {
- Cartridge {
- chr_rom: [0; 8192],
- prg_rom: RefCell::new([0; 8192]),
- sram: [0; 8192],
- mirror_type: MirrorType::Horizontal
+ 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}
+ }
}