Reduce warnings

This commit is contained in:
Franco Colmenarez 2021-11-05 10:08:17 -05:00
parent e490228c39
commit 62071d7310
8 changed files with 25 additions and 51 deletions

View File

@ -1,9 +1,6 @@
use rmg_001::render::start_eventloop;
use rmg_001::emulator::Emulator;
fn main() -> std::io::Result<()> {
start_eventloop();
/* let mut emulator = Emulator::new();
emulator.cpu_loop(); */
Ok(())
}

View File

@ -1,14 +1,10 @@
use crate::utils::{
get_bit,
set_bit,
BitIndex,
join_bytes
};
use crate::rom::ROM;
use crate::ppu::{
PPU,
LCDStatus,
LCDStatusModeFlag,
LCD_STATUS_ADDRESS,
LCD_CONTROL_ADDRESS,
LCD_Y_ADDRESS,
@ -139,6 +135,8 @@ impl Bus {
if address <= 0xDDFF {
self.data[(ECHO_RAM.begin() + (address - WORK_RAM_1.begin())) as usize] = data;
}
} else if EXTERNAL_RAM.in_range(address) {
// self.game_rom.write(address, data);
} else if ECHO_RAM.in_range(address) {
self.data[address as usize] = data;
self.data[(WORK_RAM_1.begin() + (address - ECHO_RAM.begin())) as usize] = data; // Copy to the working RAM

View File

@ -871,10 +871,6 @@ impl CPU {
self.cycles.0 += cycles.0;
}
fn decrement_cycles(&mut self, cycles: Cycles) {
self.cycles.0 -= cycles.0;
}
pub fn reset_cycles(&mut self) {
self.cycles = Cycles(0);
}
@ -2132,7 +2128,16 @@ mod tests {
let mut cpu = CPU::new();
let mut bus = Bus::new();
cpu.exec(Opcode::DI, &mut bus);
assert_eq!(bus.read(0xFFFF), 0x00);
assert_eq!(cpu.ime, false);
assert_eq!(cpu.registers.get(Register::PC), 0x101);
}
#[test]
fn test_ei_instructions() {
let mut cpu = CPU::new();
let mut bus = Bus::new();
cpu.exec(Opcode::EI, &mut bus);
assert_eq!(cpu.ime, true);
assert_eq!(cpu.registers.get(Register::PC), 0x101);
}

View File

@ -1,4 +1,4 @@
use std::{thread, time};
// use std::{thread, time};
use winit_input_helper::WinitInputHelper;
use winit::event::{VirtualKeyCode};
@ -6,7 +6,7 @@ use crate::cpu::{CPU, Cycles, Interrupt};
use crate::ppu::PPU;
use crate::bus::Bus;
use crate::timer::Timer;
use crate::joypad::{Joypad, Button, JOYPAD_ADDRESS};
use crate::joypad::{Button};
pub struct Emulator {
cpu: CPU,

View File

@ -1,4 +1,3 @@
use crate::bus::{Bus};
use crate::utils::{BitIndex, get_bit};
pub const JOYPAD_ADDRESS: u16 = 0xFF00;

View File

@ -2,9 +2,8 @@ use crate::utils::{
BitIndex,
get_bit,
set_bit,
to_bit_index,
};
use crate::bus::{Bus, AddressRange, BANK_ZERO, VIDEO_RAM, SPRITE_ATTRIBUTE_TABLE};
use crate::bus::{Bus, SPRITE_ATTRIBUTE_TABLE};
use crate::cpu::{Cycles, Interrupt};
pub const LCD_WIDTH: u32 = 160;
@ -93,7 +92,6 @@ pub enum LCDStatus {
pub struct PPU {
prev_state: bool,
cycles: Cycles,
rgba_frame: [[u8; 4]; FRAME_BUFFER_LENGTH as usize],
sprite_buffer: Vec<Sprite>,
}
@ -118,6 +116,10 @@ impl Sprite {
return None;
}
if self.over_bg {
// todo!("Implement over_bg sprite property");
}
let height: u8 = match self.is_long {
true => 16,
false => 8,
@ -171,7 +173,6 @@ impl PPU {
Self {
prev_state: false,
cycles: Cycles(0),
rgba_frame: [[0xFF, 0xFF, 0xFF, 0]; FRAME_BUFFER_LENGTH as usize],
sprite_buffer: Vec::new(),
}
}
@ -237,11 +238,9 @@ impl PPU {
fn stat_interrupt(&mut self, bus: &mut Bus) {
let state = self.prev_state;
self.prev_state = (
(PPU::get_lcd_status(bus, LCDStatus::Mode2OAMInterrupt) && PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::SearchingOAM))) ||
self.prev_state = (PPU::get_lcd_status(bus, LCDStatus::Mode2OAMInterrupt) && PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::SearchingOAM))) ||
(PPU::get_lcd_status(bus, LCDStatus::Mode0HBlankInterrupt) && PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::HBlank))) ||
(PPU::get_lcd_status(bus, LCDStatus::Mode1VBlankInterrupt) && PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::VBlank)))
);
(PPU::get_lcd_status(bus, LCDStatus::Mode1VBlankInterrupt) && PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::VBlank)));
if self.prev_state && !state {
bus.set_interrupt_flag(Interrupt::LCDSTAT, true);
}
@ -350,11 +349,6 @@ impl PPU {
control.get(byte)
}
fn set_lcd_control(bus: &mut Bus, control: LCDControl, val: bool) {
let mut byte = bus.read(LCD_CONTROL_ADDRESS);
bus.force_write(LCD_CONTROL_ADDRESS, control.set(byte, val));
}
pub fn get_lcd_status(bus: &Bus, status: LCDStatus) -> bool {
let byte = bus.read(LCD_STATUS_ADDRESS);
match status {
@ -460,7 +454,7 @@ impl PPU {
frame_buffer[idx + 1] = rgba[1];
frame_buffer[idx + 2] = rgba[2];
if let Some(window_pixel) = PPU::get_window_pixel(lcd_x, bus) {
let rgba = PPU::get_rgba(pixel);
let rgba = PPU::get_rgba(window_pixel);
frame_buffer[idx] = rgba[0];
frame_buffer[idx + 1] = rgba[1];
frame_buffer[idx + 2] = rgba[2];

View File

@ -1,11 +1,11 @@
use crate::emulator::Emulator;
use crate::cpu::{CPU, Cycles};
use crate::cpu::{Cycles};
use crate::ppu::{WIDTH, HEIGHT};
use std::{thread, time};
use log::error;
use pixels::{Error, Pixels, SurfaceTexture};
use pixels::{Pixels, SurfaceTexture};
use winit::dpi::LogicalSize;
use winit::event::{Event, VirtualKeyCode, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
@ -67,7 +67,7 @@ pub fn start_eventloop() {
emulator.run(Cycles(70224), pixels.get_frame());
// emulator.draw(pixels.get_frame());
thread::sleep(time::Duration::from_millis(10));
thread::sleep(time::Duration::from_millis(1));
window.request_redraw();
},
Event::RedrawRequested(_) => {

View File

@ -1,12 +1,6 @@
use std::fs::File;
use std::io::Read;
pub struct ROMInfo {
}
impl ROMInfo {
}
pub struct ROM {
bytes: Vec<u8>,
}
@ -27,17 +21,4 @@ impl ROM {
None => 0xFF,
}
}
pub fn from_bytes(bytes: &[u8]) -> Self {
Self {
bytes: bytes.to_vec(),
}
}
pub fn print_content(&self, address: Option<u16>) {
match address {
Some(address) => println!("{:02X?}", self.read(address)),
None => println!("{:02X?}", self.bytes),
};
}
}