Skip to content

Commit

Permalink
fix: extend rom space for minish cap/eeprom
Browse files Browse the repository at this point in the history
  • Loading branch information
xkevio committed Jan 25, 2024
1 parent c63a92a commit 47bc071
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/arm/interpreter/arm7tdmi.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::collections::HashMap;

use crate::{
arm::arr_with,
fl,
mmu::{bus::Bus, game_pak::GamePak, Mcu},
arm::arr_with, box_arr, fl, mmu::{bus::Bus, game_pak::GamePak, Mcu}
};
use proc_bitfield::{bitfield, ConvRaw};

Expand Down Expand Up @@ -101,10 +99,14 @@ impl Arm7TDMI {
pub fn new(rom: &[u8]) -> Self {
let mut regs = [0; 16];

// Resize ROM to 32 MB always for OOB reads.
let mut rom_arr: Box<[u8; 0x0200_0000]> = box_arr![0; 0x0200_0000];
rom_arr[0..(rom.len())].copy_from_slice(rom);

// Initialize GamePak memory.
let bus = Bus {
game_pak: GamePak {
rom: rom.to_vec(),
rom: rom_arr,
sram: vec![0; 0x10000],
},
..Default::default()
Expand Down
5 changes: 3 additions & 2 deletions src/mmu/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Bus {
&mut self.iff
);
self.timers.tick(&mut self.iff, cycles);
self.dma_transfer();
self.dma_transfer(); // TODO: Optimize! Only call on state change.
}

fn dma_transfer(&mut self) {
Expand Down Expand Up @@ -171,8 +171,9 @@ impl Mcu for Bus {
0x05 => self.palette_ram[address as usize % 0x400],
0x06 => self.vram[address as usize % 0x0001_8000],
0x07 => self.oam[address as usize % 0x400],
0x08..=0x0D => self.game_pak.rom[address as usize - 0x0800_0000],
0x08..=0x0D => self.game_pak.rom[address as usize & 0x00FF_FFFF],
0x0E..=0x0F => {
// Flash ID workaround.
if address == 0x0E00_0000 {
0x62
} else if address == 0x0E00_0001 {
Expand Down
11 changes: 9 additions & 2 deletions src/mmu/game_pak.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#[derive(Default)]
use crate::box_arr;

pub struct GamePak {
pub rom: Vec<u8>,
pub rom: Box<[u8; 0x0200_0000]>,
pub sram: Vec<u8>,
}

impl Default for GamePak {
fn default() -> Self {
Self { rom: box_arr![0; 0x0200_0000], sram: Default::default() }
}
}

0 comments on commit 47bc071

Please sign in to comment.