Skip to content

Commit

Permalink
decode frame
Browse files Browse the repository at this point in the history
  • Loading branch information
warycat committed May 22, 2022
1 parent 80ff6be commit cdcad10
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 29 deletions.
10 changes: 3 additions & 7 deletions nes/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::any::{Any, TypeId};
#[derive(Default)]
pub struct Console {
auto_save_manager: AutoSaveManager,
hd_pack_builder: HdPackBuilder,
hd_audio_device: HdAudioDevice,
paused: bool,
stop: bool,
running: bool,
Expand All @@ -29,13 +27,13 @@ pub struct Console {
pub control_manager: ControlManager,
pub memory_manager: MemoryManager,
pub cheat_manager: CheatManager,
pub rewind_manager: RewindManager,
pub history_viewer: HistoryViewer,
pub system_action_manager: SystemActionManager,
pub debugger: Debugger,
pub rom_file: VirtualFile,
pub patch_file: VirtualFile,
pub nes_model: NesModel,
pub hd_pack_data: HdPackData,
pub internal_ram: InternalRam,
pub open_bus: OpenBus,
}
Expand Down Expand Up @@ -79,6 +77,8 @@ impl Console {
this.ppu = Ppu::new();
this.emulation_settings = EmulationSettings::new();
this.video_renderer = VideoRenderer::new(renderer);
this.video_decoder = VideoDecoder::new();
this.rewind_manager = RewindManager::new();
Ppu::reset(&mut this);
Cpu::reset(&mut this, false);
this
Expand Down Expand Up @@ -170,10 +170,6 @@ impl Console {
todo!()
}

pub fn get_frame_count(&self) -> u32 {
todo!()
}

pub fn get_lag_counter(&self) -> u32 {
todo!()
}
Expand Down
8 changes: 8 additions & 0 deletions nes/src/frame_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[derive(Default)]
pub struct FrameInfo {
width: usize,
height: usize,
original_width: usize,
original_height: usize,
bits_per_pixel: usize,
}
2 changes: 0 additions & 2 deletions nes/src/hd_audio_device.rs

This file was deleted.

2 changes: 0 additions & 2 deletions nes/src/hd_pack_builder.rs

This file was deleted.

2 changes: 0 additions & 2 deletions nes/src/hd_pack_data.rs

This file was deleted.

19 changes: 13 additions & 6 deletions nes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ mod emulation_settings;
mod event_manager;
mod expression_data;
mod expression_evaluator;
mod hd_audio_device;
mod hd_pack_builder;
mod hd_pack_data;
mod frame_info;
mod history_viewer;
mod hook;
mod instruction_progress;
Expand All @@ -45,8 +43,11 @@ mod ppu;
mod prg_rom;
mod profiler;
mod renderer;
mod rewind_manager;
mod rom;
mod rotate_filter;
mod save_state_manager;
mod scale_filter;
mod screen;
mod sound;
mod sound_mixer;
Expand All @@ -57,6 +58,8 @@ mod system_action_manager;
mod timer;
mod trace_logger;
mod video_decoder;
mod video_filter;
mod video_hud;
mod video_renderer;
mod virtual_file;

Expand All @@ -82,9 +85,7 @@ pub use emulation_settings::*;
pub use event_manager::*;
pub use expression_data::*;
pub use expression_evaluator::*;
pub use hd_audio_device::*;
pub use hd_pack_builder::*;
pub use hd_pack_data::*;
pub use frame_info::*;
pub use history_viewer::*;
pub use hook::*;
pub use instruction_progress::*;
Expand All @@ -103,8 +104,12 @@ pub use ppu::*;
pub use prg_rom::*;
pub use profiler::*;
pub use renderer::*;
pub use rewind_manager::*;
pub use rewind_manager::*;
pub use rom::*;
pub use rotate_filter::*;
pub use save_state_manager::*;
pub use scale_filter::*;
pub use screen::*;
pub use sound::*;
pub use sound_mixer::*;
Expand All @@ -115,5 +120,7 @@ pub use system_action_manager::*;
pub use timer::*;
pub use trace_logger::*;
pub use video_decoder::*;
pub use video_filter::*;
pub use video_hud::*;
pub use video_renderer::*;
pub use virtual_file::*;
17 changes: 8 additions & 9 deletions nes/src/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl Ppu {
tile.palette_offset + background_color
}

fn current_buffer(&mut self) -> &mut Vec<u16> {
fn current_output_buffer(&mut self) -> &mut Vec<u16> {
&mut self.output_buffers[self.current_output_buffer_index as usize]
}

Expand All @@ -689,20 +689,19 @@ impl Ppu {
let color = Ppu::get_pixel_color(console);
let ppu = &mut console.ppu;
let color = if color & 0x03 != 0 { color as usize } else { 0 };
ppu.current_buffer()[offset] = ppu.palette_ram[color] as u16;
ppu.current_output_buffer()[offset] = ppu.palette_ram[color] as u16;
} else {
let color = (ppu.video_ram_addr & 0x1F) as usize;
ppu.current_buffer()[offset] = ppu.palette_ram[color] as u16;
ppu.current_output_buffer()[offset] = ppu.palette_ram[color] as u16;
}
}

fn update_grayscale_and_intensify_bits(&mut self) {
todo!()
}

fn send_frame(console: &mut Console) {
todo!();
// console.video_decoder.update_frame();
VideoDecoder::update_frame_sync(console);
console.ppu.enable_oam_decay = console
.emulation_settings
.flags
.contains(EmulationFlags::EnableOamDecay);
}

fn update_state(&mut self) {
Expand Down
11 changes: 11 additions & 0 deletions nes/src/rewind_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::ControlManager;

#[derive(Default)]
pub struct RewindManager {}

impl RewindManager {
pub fn new() -> Self {
let this = RewindManager::default();
this
}
}
2 changes: 2 additions & 0 deletions nes/src/rotate_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Default)]
pub struct RotateFilter {}
2 changes: 2 additions & 0 deletions nes/src/scale_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Default)]
pub struct ScaleFilter {}
76 changes: 75 additions & 1 deletion nes/src/video_decoder.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,76 @@
use crate::*;

#[derive(Default)]
pub struct VideoDecoder {}
pub struct ScreenSize {
width: usize,
height: usize,
scale: f64,
}

#[derive(Default)]
pub struct VideoDecoder {
frame_number: u32,
hud: VideoHud,
pub frame_count: u32,
previous_screen_size: ScreenSize,
previous_scale: f64,
pub frame_info: FrameInfo,
video_filter_type: VideoFilterType,
video_filter: Option<Box<dyn VideoFilter>>,
scale_filter: ScaleFilter,
rotate_filter: RotateFilter,
}

impl VideoDecoder {
fn update_video_filter(&mut self) {
todo!()
}

fn decode_thread(&mut self) {
todo!()
}

pub fn new() -> Self {
let this = VideoDecoder::default();
this
}

fn decode_frame(console: &mut Console, synchronous: bool) {
todo!()
// console.rewind_manager.send_frame();
}

fn take_screenshot(&mut self) {
todo!()
}

fn get_screen_size(&self, ignore_scale: bool) -> ScreenSize {
todo!()
}

pub fn update_frame_sync(console: &mut Console) {
if console.emulation_settings.is_run_ahead_frame {
return;
}

console.video_decoder.frame_number = console.ppu.frame_count;
VideoDecoder::decode_frame(console, true);
console.video_decoder.frame_count += 1;
}

fn update_frame(&self, ppu_output_buffer: &mut Vec<u16>) {
todo!()
}

fn is_running(&self) -> bool {
todo!()
}

fn start_thread(&mut self) {
todo!()
}

fn stop_thread(&mut self) {
todo!()
}
}
1 change: 1 addition & 0 deletions nes/src/video_filter/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub trait VideoFilter {}
2 changes: 2 additions & 0 deletions nes/src/video_hud.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Default)]
pub struct VideoHud;

0 comments on commit cdcad10

Please sign in to comment.