chore: rename Cycles newtype to Cycle
This commit is contained in:
parent
bce14348f8
commit
2b05571c49
|
@ -1,6 +1,6 @@
|
||||||
use super::cartridge::Cartridge;
|
use super::cartridge::Cartridge;
|
||||||
use super::high_ram::HighRam;
|
use super::high_ram::HighRam;
|
||||||
use super::instruction::Cycles;
|
use super::instruction::Cycle;
|
||||||
use super::interrupt::{Interrupt, InterruptFlag};
|
use super::interrupt::{Interrupt, InterruptFlag};
|
||||||
use super::joypad::Joypad;
|
use super::joypad::Joypad;
|
||||||
use super::ppu::Ppu;
|
use super::ppu::Ppu;
|
||||||
|
@ -63,7 +63,7 @@ impl Bus {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn step(&mut self, cycles: Cycles) {
|
pub fn step(&mut self, cycles: Cycle) {
|
||||||
self.timer.step(cycles);
|
self.timer.step(cycles);
|
||||||
self.sound.step(cycles);
|
self.sound.step(cycles);
|
||||||
self.ppu.step(cycles);
|
self.ppu.step(cycles);
|
||||||
|
|
10
src/cpu.rs
10
src/cpu.rs
|
@ -1,5 +1,5 @@
|
||||||
use super::bus::Bus;
|
use super::bus::Bus;
|
||||||
use super::instruction::{Cycles, Instruction};
|
use super::instruction::{Cycle, Instruction};
|
||||||
use super::interrupt::{InterruptEnable, InterruptFlag};
|
use super::interrupt::{InterruptEnable, InterruptFlag};
|
||||||
use super::ppu::Ppu;
|
use super::ppu::Ppu;
|
||||||
use bitfield::bitfield;
|
use bitfield::bitfield;
|
||||||
|
@ -81,11 +81,11 @@ impl Cpu {
|
||||||
Instruction::from_byte(self, opcode)
|
Instruction::from_byte(self, opcode)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(&mut self, instruction: Instruction) -> Cycles {
|
pub fn execute(&mut self, instruction: Instruction) -> Cycle {
|
||||||
Instruction::execute(self, instruction)
|
Instruction::execute(self, instruction)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn step(&mut self) -> Cycles {
|
pub fn step(&mut self) -> Cycle {
|
||||||
if self.reg.pc > 0x100 {
|
if self.reg.pc > 0x100 {
|
||||||
self.log_state().unwrap();
|
self.log_state().unwrap();
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ impl Cpu {
|
||||||
use HaltState::*;
|
use HaltState::*;
|
||||||
|
|
||||||
match state {
|
match state {
|
||||||
ImeSet | NonePending => Cycles::new(4),
|
ImeSet | NonePending => Cycle::new(4),
|
||||||
SomePending => todo!("Implement HALT bug"),
|
SomePending => todo!("Implement HALT bug"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ impl Cpu {
|
||||||
self.set_ime(false);
|
self.set_ime(false);
|
||||||
self.execute(Instruction::RST(register))
|
self.execute(Instruction::RST(register))
|
||||||
}
|
}
|
||||||
None => Cycles::new(0), // NO Interrupts were enabled and / or requested
|
None => Cycle::new(0), // NO Interrupts were enabled and / or requested
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
||||||
pub use cpu::Cpu as LR35902;
|
pub use cpu::Cpu as LR35902;
|
||||||
pub use instruction::Cycles;
|
pub use instruction::Cycle;
|
||||||
|
|
||||||
pub const GB_WIDTH: usize = 160;
|
pub const GB_WIDTH: usize = 160;
|
||||||
pub const GB_HEIGHT: usize = 144;
|
pub const GB_HEIGHT: usize = 144;
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};
|
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};
|
||||||
use gb::LR35902_CLOCK_SPEED;
|
use gb::LR35902_CLOCK_SPEED;
|
||||||
use gb::{Cycles, LR35902};
|
use gb::{Cycle, LR35902};
|
||||||
use pixels::{Pixels, SurfaceTexture};
|
use pixels::{Pixels, SurfaceTexture};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use winit::dpi::LogicalSize;
|
use winit::dpi::LogicalSize;
|
||||||
|
@ -16,7 +16,7 @@ const GB_HEIGHT: u32 = 144;
|
||||||
const SCALE: f64 = 5.0;
|
const SCALE: f64 = 5.0;
|
||||||
|
|
||||||
const LR35902_CYCLE_TIME: f64 = 1.0f64 / LR35902_CLOCK_SPEED as f64;
|
const LR35902_CYCLE_TIME: f64 = 1.0f64 / LR35902_CLOCK_SPEED as f64;
|
||||||
const CYCLES_IN_FRAME: Cycles = Cycles::new(70224);
|
const CYCLES_IN_FRAME: Cycle = Cycle::new(70224);
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let app = App::new(crate_name!())
|
let app = App::new(crate_name!())
|
||||||
|
@ -65,7 +65,7 @@ fn main() -> Result<()> {
|
||||||
let mut pixels = create_pixels(&window)?;
|
let mut pixels = create_pixels(&window)?;
|
||||||
|
|
||||||
let mut now = Instant::now();
|
let mut now = Instant::now();
|
||||||
let mut cycles_in_frame = Cycles::default();
|
let mut cycles_in_frame = Cycle::default();
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
if let Event::RedrawRequested(_) = event {
|
if let Event::RedrawRequested(_) = event {
|
||||||
if pixels
|
if pixels
|
||||||
|
@ -93,9 +93,9 @@ fn main() -> Result<()> {
|
||||||
now = Instant::now();
|
now = Instant::now();
|
||||||
|
|
||||||
let cycle_time = Duration::from_secs_f64(LR35902_CYCLE_TIME).subsec_nanos();
|
let cycle_time = Duration::from_secs_f64(LR35902_CYCLE_TIME).subsec_nanos();
|
||||||
let pending_cycles = Cycles::new(delta / cycle_time);
|
let pending_cycles = Cycle::new(delta / cycle_time);
|
||||||
|
|
||||||
let mut elapsed_cycles = Cycles::default();
|
let mut elapsed_cycles = Cycle::default();
|
||||||
while elapsed_cycles <= pending_cycles {
|
while elapsed_cycles <= pending_cycles {
|
||||||
elapsed_cycles += game_boy.step();
|
elapsed_cycles += game_boy.step();
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ fn main() -> Result<()> {
|
||||||
ppu.copy_to_gui(frame);
|
ppu.copy_to_gui(frame);
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
|
|
||||||
cycles_in_frame = Cycles::default()
|
cycles_in_frame = Cycle::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::Cycles;
|
use crate::Cycle;
|
||||||
use crate::GB_HEIGHT;
|
use crate::GB_HEIGHT;
|
||||||
use crate::GB_WIDTH;
|
use crate::GB_WIDTH;
|
||||||
use bitfield::bitfield;
|
use bitfield::bitfield;
|
||||||
|
@ -22,7 +22,7 @@ pub struct Ppu {
|
||||||
pub oam: Box<[u8; OAM_SIZE]>,
|
pub oam: Box<[u8; OAM_SIZE]>,
|
||||||
frame_buf: [u8; GB_WIDTH * GB_HEIGHT * 4],
|
frame_buf: [u8; GB_WIDTH * GB_HEIGHT * 4],
|
||||||
pub stat: LCDStatus,
|
pub stat: LCDStatus,
|
||||||
cycles: Cycles,
|
cycles: Cycle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ppu {
|
impl Ppu {
|
||||||
|
@ -36,7 +36,7 @@ impl Ppu {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ppu {
|
impl Ppu {
|
||||||
pub fn step(&mut self, cycles: Cycles) {
|
pub fn step(&mut self, cycles: Cycle) {
|
||||||
self.cycles += cycles;
|
self.cycles += cycles;
|
||||||
|
|
||||||
match self.stat.mode() {
|
match self.stat.mode() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::instruction::Cycles;
|
use crate::instruction::Cycle;
|
||||||
use bitfield::bitfield;
|
use bitfield::bitfield;
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Debug, Clone, Copy, Default)]
|
||||||
pub struct Sound {
|
pub struct Sound {
|
||||||
|
@ -7,7 +7,7 @@ pub struct Sound {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sound {
|
impl Sound {
|
||||||
pub fn step(&mut self, _cycles: Cycles) {
|
pub fn step(&mut self, _cycles: Cycle) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::Cycles;
|
use crate::Cycle;
|
||||||
use bitfield::bitfield;
|
use bitfield::bitfield;
|
||||||
|
|
||||||
// const DIVIDER_REGISTER_HZ: u32 = 16384;
|
// const DIVIDER_REGISTER_HZ: u32 = 16384;
|
||||||
|
@ -14,7 +14,7 @@ pub struct Timer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Timer {
|
impl Timer {
|
||||||
pub fn step(&mut self, cycles: Cycles) {
|
pub fn step(&mut self, cycles: Cycle) {
|
||||||
use TimerSpeed::*;
|
use TimerSpeed::*;
|
||||||
|
|
||||||
for _ in 0..cycles.into() {
|
for _ in 0..cycles.into() {
|
||||||
|
|
Loading…
Reference in New Issue