mirror of
https://github.com/FranLMSP/snes.git
synced 2026-08-03 08:30:01 -04:00
Fix issues when displaying the background tiles
This commit is contained in:
@@ -24,7 +24,7 @@ impl CPUInstruction for BRL {
|
||||
}
|
||||
|
||||
fn mnemonic(&self, registers: &Registers, bus: &Bus, opcode: u8) -> String {
|
||||
decoder_common::mnemonic_absolute(opcode, INSTR_NAME, registers, bus)
|
||||
decoder_common::mnemonic_absolute_16bit(opcode, INSTR_NAME, registers, bus)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@ pub fn mnemonic_arithmetic(is_16bit: bool, opcode: u8, instr_name: &str, address
|
||||
true => mnemonic_16bit_immediate(opcode, instr_name, registers, bus),
|
||||
false => mnemonic_8bit_immediate(opcode, instr_name, registers, bus),
|
||||
},
|
||||
A::Absolute => mnemonic_absolute(opcode, instr_name, registers, bus),
|
||||
A::Absolute => match is_16bit {
|
||||
true => mnemonic_absolute_16bit(opcode, instr_name, registers, bus),
|
||||
false => mnemonic_absolute_8bit(opcode, instr_name, registers, bus),
|
||||
},
|
||||
A::AbsoluteLong => mnemonic_absolute_long(opcode, instr_name, registers, bus),
|
||||
A::DirectPage => mnemonic_direct_page(opcode, instr_name, registers, bus),
|
||||
A::DirectPageIndirect => mnemonic_direct_page_indirect(opcode, instr_name, registers, bus),
|
||||
@@ -38,14 +41,21 @@ pub fn mnemonic_8bit_immediate(opcode: u8, instr_name: &str, registers: &Registe
|
||||
pub fn mnemonic_16bit_immediate(opcode: u8, instr_name: &str, registers: &Registers, bus: &Bus) -> String {
|
||||
let next_byte = bus.read_external(registers.get_pc_address() + 1);
|
||||
let next_second_byte = bus.read_external(registers.get_pc_address() + 2);
|
||||
let word = (next_byte as u16) | ((next_byte as u16) << 8);
|
||||
let word = (next_byte as u16) | ((next_second_byte as u16) << 8);
|
||||
format!("{:02X} {:02X} {:02X} __ | {} #${:04X}", opcode, next_byte, next_second_byte, instr_name, word)
|
||||
}
|
||||
|
||||
pub fn mnemonic_absolute(opcode: u8, instr_name: &str, registers: &Registers, bus: &Bus) -> String {
|
||||
pub fn mnemonic_absolute_8bit(opcode: u8, instr_name: &str, registers: &Registers, bus: &Bus) -> String {
|
||||
let next_byte = bus.read_external(registers.get_pc_address() + 1);
|
||||
let next_second_byte = bus.read_external(registers.get_pc_address() + 2);
|
||||
let word = (next_byte as u16) | ((next_byte as u16) << 8);
|
||||
let word = (next_byte as u16) | ((next_second_byte as u16) << 8);
|
||||
format!("{:02X} {:02X} {:02X} __ | {} ${:04X}", opcode, next_byte, next_second_byte, instr_name, word)
|
||||
}
|
||||
|
||||
pub fn mnemonic_absolute_16bit(opcode: u8, instr_name: &str, registers: &Registers, bus: &Bus) -> String {
|
||||
let next_byte = bus.read_external(registers.get_pc_address() + 1);
|
||||
let next_second_byte = bus.read_external(registers.get_pc_address() + 2);
|
||||
let word = (next_byte as u16) | ((next_second_byte as u16) << 8);
|
||||
format!("{:02X} {:02X} {:02X} __ | {} ${:04X}", opcode, next_byte, next_second_byte, instr_name, word)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ impl CPUInstruction for PEA {
|
||||
}
|
||||
|
||||
fn mnemonic(&self, registers: &Registers, bus: &Bus, opcode: u8) -> String {
|
||||
decoder_common::mnemonic_absolute(opcode, INSTR_NAME, registers, bus)
|
||||
decoder_common::mnemonic_absolute_16bit(opcode, INSTR_NAME, registers, bus)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ impl CPUInstruction for PER {
|
||||
}
|
||||
|
||||
fn mnemonic(&self, registers: &Registers, bus: &Bus, opcode: u8) -> String {
|
||||
decoder_common::mnemonic_absolute(opcode, INSTR_NAME, registers, bus)
|
||||
decoder_common::mnemonic_absolute_16bit(opcode, INSTR_NAME, registers, bus)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,9 +57,11 @@ impl InternalRegisters {
|
||||
}
|
||||
|
||||
fn read_vblank_nmi_mut(&self, ppu_registers: &mut PPURegisters) -> u8 {
|
||||
let byte = self._read(RDNMI);
|
||||
let result = self.read_vblank_nmi(ppu_registers);
|
||||
if result == 0x80 {
|
||||
println!("nmi set");
|
||||
}
|
||||
// When register is read, bit 7 is cleared
|
||||
let result = (byte & 0x7F) | ((ppu_registers.vblank_nmi as u8) << 7);
|
||||
ppu_registers.vblank_nmi = false;
|
||||
result
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ impl ROM for LoROM {
|
||||
let address = LoROM::adjust_address(address);
|
||||
match self.data.get(address as usize) {
|
||||
Some(byte) => *byte,
|
||||
None => 0xFF,
|
||||
None => 0x00,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ pub struct PPUDebugControlOptions {
|
||||
pub show_registers: bool,
|
||||
pub show_vram: bool,
|
||||
pub vram_inputs: VramInputs,
|
||||
pub vram_inputs_result: VramInputs,
|
||||
pub backgrounds: [BgDebug; 4],
|
||||
}
|
||||
|
||||
@@ -113,6 +114,7 @@ impl PPUDebugControlOptions {
|
||||
show_registers: true,
|
||||
show_vram: true,
|
||||
vram_inputs: VramInputs::new(),
|
||||
vram_inputs_result: VramInputs::new(),
|
||||
backgrounds: [
|
||||
BgDebug::new(PPUBg::Bg1),
|
||||
BgDebug::new(PPUBg::Bg2),
|
||||
|
||||
@@ -164,13 +164,15 @@ fn build_vram_window(ctx: &egui::Context, ppu_debug_options: &mut PPUDebugContro
|
||||
if ui.button("Search").clicked() {
|
||||
sanitize_input(&mut ppu_debug_options.vram_inputs.address_start, false);
|
||||
sanitize_input(&mut ppu_debug_options.vram_inputs.address_end, false);
|
||||
ppu_debug_options.vram_inputs_result.address_start = ppu_debug_options.vram_inputs.address_start.to_string();
|
||||
ppu_debug_options.vram_inputs_result.address_end = ppu_debug_options.vram_inputs.address_end.to_string();
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
egui::ScrollArea::both().show(ui, |ui| {
|
||||
let address_start = u16::from_str_radix(&ppu_debug_options.vram_inputs.address_start, 16).unwrap();
|
||||
let address_end = u16::from_str_radix(&ppu_debug_options.vram_inputs.address_end, 16).unwrap();
|
||||
let address_start = u16::from_str_radix(&ppu_debug_options.vram_inputs_result.address_start, 16).unwrap();
|
||||
let address_end = u16::from_str_radix(&ppu_debug_options.vram_inputs_result.address_end, 16).unwrap();
|
||||
let mut header = String::from(" | ");
|
||||
for page in 0x00..=0x0F {
|
||||
header = format!("{} {:02X} ", header, page);
|
||||
|
||||
@@ -134,7 +134,8 @@ fn compute_2bpp_bg_background_framebuffer(background: Background, framebuffer: &
|
||||
for y in 0..height {
|
||||
for x in 0..width {
|
||||
let current_tile = (x / tile_size_width) + ((y / tile_size_height) * bg_size_width);
|
||||
let char_index = vram[(tileset_vram_base_address + current_tile) & 0x7FFF] & 0b11_11111111;
|
||||
let tile_byte = vram[tileset_vram_base_address + current_tile];
|
||||
let char_index = tile_byte & 0b11_11111111;
|
||||
let current_char_column = x.rem_euclid(tile_size_width);
|
||||
let current_char_row = y.rem_euclid(tile_size_height);
|
||||
// 8x8 pixels, 2 bitplanes, each word (16bit) holds 8 pixels
|
||||
@@ -225,7 +226,7 @@ fn paint_texture(ui: &mut Ui, texture: &mut Option<TextureHandle>, framebuffer:
|
||||
TextureOptions::default(),
|
||||
);
|
||||
let (whole_rect, _) =
|
||||
ui.allocate_exact_size(Vec2::from([width as f32, height as f32]), egui::Sense::focusable_noninteractive());
|
||||
ui.allocate_exact_size(Vec2::from([(width * 2) as f32, (height * 2) as f32]), egui::Sense::focusable_noninteractive());
|
||||
egui::Image::new((
|
||||
txt.id(),
|
||||
txt.size_vec2(),
|
||||
|
||||
Reference in New Issue
Block a user