mirror of
https://github.com/FranLMSP/rmg-001.git
synced 2024-11-23 10:12:11 +00:00
Reduce warnings
This commit is contained in:
parent
e490228c39
commit
62071d7310
@ -1,9 +1,6 @@
|
|||||||
use rmg_001::render::start_eventloop;
|
use rmg_001::render::start_eventloop;
|
||||||
use rmg_001::emulator::Emulator;
|
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
start_eventloop();
|
start_eventloop();
|
||||||
/* let mut emulator = Emulator::new();
|
|
||||||
emulator.cpu_loop(); */
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
get_bit,
|
get_bit,
|
||||||
set_bit,
|
|
||||||
BitIndex,
|
BitIndex,
|
||||||
join_bytes
|
join_bytes
|
||||||
};
|
};
|
||||||
use crate::rom::ROM;
|
use crate::rom::ROM;
|
||||||
use crate::ppu::{
|
use crate::ppu::{
|
||||||
PPU,
|
|
||||||
LCDStatus,
|
|
||||||
LCDStatusModeFlag,
|
|
||||||
LCD_STATUS_ADDRESS,
|
LCD_STATUS_ADDRESS,
|
||||||
LCD_CONTROL_ADDRESS,
|
LCD_CONTROL_ADDRESS,
|
||||||
LCD_Y_ADDRESS,
|
LCD_Y_ADDRESS,
|
||||||
@ -139,6 +135,8 @@ impl Bus {
|
|||||||
if address <= 0xDDFF {
|
if address <= 0xDDFF {
|
||||||
self.data[(ECHO_RAM.begin() + (address - WORK_RAM_1.begin())) as usize] = data;
|
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) {
|
} else if ECHO_RAM.in_range(address) {
|
||||||
self.data[address as usize] = data;
|
self.data[address as usize] = data;
|
||||||
self.data[(WORK_RAM_1.begin() + (address - ECHO_RAM.begin())) as usize] = data; // Copy to the working RAM
|
self.data[(WORK_RAM_1.begin() + (address - ECHO_RAM.begin())) as usize] = data; // Copy to the working RAM
|
||||||
|
15
src/cpu.rs
15
src/cpu.rs
@ -871,10 +871,6 @@ impl CPU {
|
|||||||
self.cycles.0 += cycles.0;
|
self.cycles.0 += cycles.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decrement_cycles(&mut self, cycles: Cycles) {
|
|
||||||
self.cycles.0 -= cycles.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset_cycles(&mut self) {
|
pub fn reset_cycles(&mut self) {
|
||||||
self.cycles = Cycles(0);
|
self.cycles = Cycles(0);
|
||||||
}
|
}
|
||||||
@ -2132,7 +2128,16 @@ mod tests {
|
|||||||
let mut cpu = CPU::new();
|
let mut cpu = CPU::new();
|
||||||
let mut bus = Bus::new();
|
let mut bus = Bus::new();
|
||||||
cpu.exec(Opcode::DI, &mut bus);
|
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);
|
assert_eq!(cpu.registers.get(Register::PC), 0x101);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{thread, time};
|
// use std::{thread, time};
|
||||||
use winit_input_helper::WinitInputHelper;
|
use winit_input_helper::WinitInputHelper;
|
||||||
use winit::event::{VirtualKeyCode};
|
use winit::event::{VirtualKeyCode};
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ use crate::cpu::{CPU, Cycles, Interrupt};
|
|||||||
use crate::ppu::PPU;
|
use crate::ppu::PPU;
|
||||||
use crate::bus::Bus;
|
use crate::bus::Bus;
|
||||||
use crate::timer::Timer;
|
use crate::timer::Timer;
|
||||||
use crate::joypad::{Joypad, Button, JOYPAD_ADDRESS};
|
use crate::joypad::{Button};
|
||||||
|
|
||||||
pub struct Emulator {
|
pub struct Emulator {
|
||||||
cpu: CPU,
|
cpu: CPU,
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use crate::bus::{Bus};
|
|
||||||
use crate::utils::{BitIndex, get_bit};
|
use crate::utils::{BitIndex, get_bit};
|
||||||
|
|
||||||
pub const JOYPAD_ADDRESS: u16 = 0xFF00;
|
pub const JOYPAD_ADDRESS: u16 = 0xFF00;
|
||||||
|
22
src/ppu.rs
22
src/ppu.rs
@ -2,9 +2,8 @@ use crate::utils::{
|
|||||||
BitIndex,
|
BitIndex,
|
||||||
get_bit,
|
get_bit,
|
||||||
set_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};
|
use crate::cpu::{Cycles, Interrupt};
|
||||||
|
|
||||||
pub const LCD_WIDTH: u32 = 160;
|
pub const LCD_WIDTH: u32 = 160;
|
||||||
@ -93,7 +92,6 @@ pub enum LCDStatus {
|
|||||||
pub struct PPU {
|
pub struct PPU {
|
||||||
prev_state: bool,
|
prev_state: bool,
|
||||||
cycles: Cycles,
|
cycles: Cycles,
|
||||||
rgba_frame: [[u8; 4]; FRAME_BUFFER_LENGTH as usize],
|
|
||||||
sprite_buffer: Vec<Sprite>,
|
sprite_buffer: Vec<Sprite>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +116,10 @@ impl Sprite {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.over_bg {
|
||||||
|
// todo!("Implement over_bg sprite property");
|
||||||
|
}
|
||||||
|
|
||||||
let height: u8 = match self.is_long {
|
let height: u8 = match self.is_long {
|
||||||
true => 16,
|
true => 16,
|
||||||
false => 8,
|
false => 8,
|
||||||
@ -171,7 +173,6 @@ impl PPU {
|
|||||||
Self {
|
Self {
|
||||||
prev_state: false,
|
prev_state: false,
|
||||||
cycles: Cycles(0),
|
cycles: Cycles(0),
|
||||||
rgba_frame: [[0xFF, 0xFF, 0xFF, 0]; FRAME_BUFFER_LENGTH as usize],
|
|
||||||
sprite_buffer: Vec::new(),
|
sprite_buffer: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,11 +238,9 @@ impl PPU {
|
|||||||
|
|
||||||
fn stat_interrupt(&mut self, bus: &mut Bus) {
|
fn stat_interrupt(&mut self, bus: &mut Bus) {
|
||||||
let state = self.prev_state;
|
let state = self.prev_state;
|
||||||
self.prev_state = (
|
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::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::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 {
|
if self.prev_state && !state {
|
||||||
bus.set_interrupt_flag(Interrupt::LCDSTAT, true);
|
bus.set_interrupt_flag(Interrupt::LCDSTAT, true);
|
||||||
}
|
}
|
||||||
@ -350,11 +349,6 @@ impl PPU {
|
|||||||
control.get(byte)
|
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 {
|
pub fn get_lcd_status(bus: &Bus, status: LCDStatus) -> bool {
|
||||||
let byte = bus.read(LCD_STATUS_ADDRESS);
|
let byte = bus.read(LCD_STATUS_ADDRESS);
|
||||||
match status {
|
match status {
|
||||||
@ -460,7 +454,7 @@ impl PPU {
|
|||||||
frame_buffer[idx + 1] = rgba[1];
|
frame_buffer[idx + 1] = rgba[1];
|
||||||
frame_buffer[idx + 2] = rgba[2];
|
frame_buffer[idx + 2] = rgba[2];
|
||||||
if let Some(window_pixel) = PPU::get_window_pixel(lcd_x, bus) {
|
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] = rgba[0];
|
||||||
frame_buffer[idx + 1] = rgba[1];
|
frame_buffer[idx + 1] = rgba[1];
|
||||||
frame_buffer[idx + 2] = rgba[2];
|
frame_buffer[idx + 2] = rgba[2];
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use crate::emulator::Emulator;
|
use crate::emulator::Emulator;
|
||||||
use crate::cpu::{CPU, Cycles};
|
use crate::cpu::{Cycles};
|
||||||
use crate::ppu::{WIDTH, HEIGHT};
|
use crate::ppu::{WIDTH, HEIGHT};
|
||||||
|
|
||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use pixels::{Error, Pixels, SurfaceTexture};
|
use pixels::{Pixels, SurfaceTexture};
|
||||||
use winit::dpi::LogicalSize;
|
use winit::dpi::LogicalSize;
|
||||||
use winit::event::{Event, VirtualKeyCode, WindowEvent};
|
use winit::event::{Event, VirtualKeyCode, WindowEvent};
|
||||||
use winit::event_loop::{ControlFlow, EventLoop};
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
@ -67,7 +67,7 @@ pub fn start_eventloop() {
|
|||||||
emulator.run(Cycles(70224), pixels.get_frame());
|
emulator.run(Cycles(70224), pixels.get_frame());
|
||||||
// emulator.draw(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();
|
window.request_redraw();
|
||||||
},
|
},
|
||||||
Event::RedrawRequested(_) => {
|
Event::RedrawRequested(_) => {
|
||||||
|
19
src/rom.rs
19
src/rom.rs
@ -1,12 +1,6 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
pub struct ROMInfo {
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ROMInfo {
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ROM {
|
pub struct ROM {
|
||||||
bytes: Vec<u8>,
|
bytes: Vec<u8>,
|
||||||
}
|
}
|
||||||
@ -27,17 +21,4 @@ impl ROM {
|
|||||||
None => 0xFF,
|
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),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user