Compare commits
5 Commits
67e2d7140b
...
261fa4d78a
| Author | SHA1 | Date | |
|---|---|---|---|
| 261fa4d78a | |||
| 79e31318e0 | |||
| 368150e4c3 | |||
| 0816f74528 | |||
| 90baf0af78 |
@ -84,6 +84,9 @@ impl Cartridge {
|
||||
if let &Some(ref filename) = save_file {
|
||||
let data = super::read_file(&filename);
|
||||
if let Ok(data) = data {
|
||||
if data.len() != size {
|
||||
panic!("Ram size does not match");
|
||||
}
|
||||
data
|
||||
} else {
|
||||
// Generate empty buffer
|
||||
|
||||
@ -64,6 +64,9 @@ const MONOCHROME_PALETTE: &'static [[u8; 3]; 4] = &[
|
||||
struct CgbPalette([u8; 8]);
|
||||
impl CgbPalette {
|
||||
fn get_color(&self, n: usize) -> sdl2::pixels::Color {
|
||||
if n == 0 {
|
||||
return sdl2::pixels::Color::RGB(255, 255, 255);
|
||||
}
|
||||
let v = ((self.0[2 * n + 1] as u16) << 8) | (self.0[2 * n] as u16);
|
||||
let r = (v & 0b1_1111) as u8;
|
||||
let g = ((v >> 5) & 0b1_1111) as u8;
|
||||
@ -333,7 +336,7 @@ impl Display {
|
||||
pub fn write_byte(&mut self, addr: u16, val: u8) {
|
||||
match addr {
|
||||
0x8000..=0x9FFF => {
|
||||
if self.vram_bank == 0 {
|
||||
if (self.vram_bank & 1) == 0 {
|
||||
self.vram0[(addr - 0x8000) as usize] = val
|
||||
} else {
|
||||
self.vram1[(addr - 0x8000) as usize] = val
|
||||
@ -392,7 +395,7 @@ impl Display {
|
||||
pub fn read_byte(&self, addr: u16) -> u8 {
|
||||
match addr {
|
||||
0x8000..=0x9FFF => {
|
||||
if self.vram_bank == 0 {
|
||||
if (self.vram_bank & 1) == 0 {
|
||||
self.vram0[(addr - 0x8000) as usize]
|
||||
} else {
|
||||
self.vram1[(addr - 0x8000) as usize]
|
||||
@ -431,6 +434,8 @@ impl Display {
|
||||
let vram_offset: usize =
|
||||
background_map + ((tile_index_y as usize) * 32) + tile_index_x as usize;
|
||||
*/
|
||||
// Background attributes are only in this memory range.
|
||||
assert!(vram_offset >= 0x1800 && vram_offset < 0x2000, format!("offset: {:04X}", vram_offset));
|
||||
|
||||
BgMapAttributes(self.vram1[vram_offset])
|
||||
}
|
||||
@ -669,6 +674,11 @@ impl Display {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dump_vram(&self) {
|
||||
std::fs::File::create("vram0.dat").unwrap().write_all(&self.vram0);
|
||||
std::fs::File::create("vram1.dat").unwrap().write_all(&self.vram1);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn renderscan(&mut self) {
|
||||
// Points to the background map offset to use.
|
||||
@ -738,13 +748,9 @@ impl Display {
|
||||
let tile_id = self.vram0[vram_offset];
|
||||
|
||||
// GBC stuff
|
||||
let bg_attribs = self.get_background_attribute(vram_offset);
|
||||
// Get BG map attributes
|
||||
let vram = if bg_attribs.vram_bank_number() == 0 {
|
||||
&*self.vram0
|
||||
} else {
|
||||
&*self.vram1
|
||||
};
|
||||
let bg_attribs = self.get_background_attribute(vram_offset);
|
||||
let vram = [&*self.vram0, &*self.vram1][bg_attribs.vram_bank_number()];
|
||||
|
||||
// TODO: Priority
|
||||
let tile_offset_y = if bg_attribs.vertical_flip() {
|
||||
|
||||
@ -265,14 +265,14 @@ impl Interconnect {
|
||||
// TODO: if some flag set, use bios, otherwise only use rom
|
||||
// For now, just use bios
|
||||
match addr {
|
||||
0x0000..=0x100 => {
|
||||
if self.disable_bootrom == 0 {
|
||||
0x0000..=0x0FF | 0x200..=0x8FF => {
|
||||
if self.disable_bootrom == 0 && self.bios.len() > addr as usize {
|
||||
self.bios[addr as usize]
|
||||
} else {
|
||||
self.cartridge.read_byte(addr)
|
||||
}
|
||||
}
|
||||
0x100..=0x7FFF => self.cartridge.read_byte(addr),
|
||||
0x100..=0x1FF | 0x900..=0x7FFF => self.cartridge.read_byte(addr),
|
||||
0x8000..=0x9FFF => self.display.read_byte(addr),
|
||||
0xA000..=0xBFFF => self.cartridge.read_byte(addr),
|
||||
0xC000..=0xCFFF => self.ram[(addr - 0xC000) as usize],
|
||||
@ -344,6 +344,9 @@ impl Interconnect {
|
||||
0xD000..=0xDFFF => {
|
||||
self.ram[(addr - 0xD000) as usize + self.wram_bank as usize * 0x1000] = val;
|
||||
}
|
||||
0xE000..=0xFCFF => {
|
||||
self.ram[(addr - 0xE000) as usize] = val;
|
||||
}
|
||||
0xFE00..=0xFE9F => self.display.write_byte(addr, val), // OAM
|
||||
0xFF00 => {
|
||||
// Joystick select
|
||||
|
||||
@ -94,6 +94,11 @@ impl MBC for MBC1 {
|
||||
_ => panic!("Invalid bank mode {:02X}", val),
|
||||
}
|
||||
}
|
||||
0xA000..=0xBFFF => {
|
||||
let addr = addr - 0xA000;
|
||||
println!("Access [{:02X}] {:04X}", self.active_ram_bank(), addr);
|
||||
self.ram[self.active_ram_bank() as usize * 0x2000 + addr as usize] = val;
|
||||
}
|
||||
_ => panic!("MBC1: Writing {:02X} to {:04X} not supported", val, addr),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user