oncecell
This commit is contained in:
parent
4496316f07
commit
26e5cc3431
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -414,6 +414,7 @@ dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"gilrs",
|
"gilrs",
|
||||||
"minifb",
|
"minifb",
|
||||||
|
"once_cell",
|
||||||
"rand",
|
"rand",
|
||||||
"ringbuf",
|
"ringbuf",
|
||||||
"samplerate",
|
"samplerate",
|
||||||
|
@ -863,9 +864,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.17.0"
|
version = "1.17.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "orbclient"
|
name = "orbclient"
|
||||||
|
|
|
@ -16,3 +16,4 @@ cpal = "0.15.0"
|
||||||
ringbuf = "0.3.2"
|
ringbuf = "0.3.2"
|
||||||
async-ringbuf = "0.1.2"
|
async-ringbuf = "0.1.2"
|
||||||
futures = "0.3.26"
|
futures = "0.3.26"
|
||||||
|
once_cell = "1.17.1"
|
||||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -6,6 +6,7 @@ mod util;
|
||||||
use clap::{ArgGroup, Parser};
|
use clap::{ArgGroup, Parser};
|
||||||
use gilrs::Gilrs;
|
use gilrs::Gilrs;
|
||||||
use minifb::{Window, WindowOptions};
|
use minifb::{Window, WindowOptions};
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use processor::{
|
use processor::{
|
||||||
memory::{Memory, Rom},
|
memory::{Memory, Rom},
|
||||||
Cpu,
|
Cpu,
|
||||||
|
@ -13,9 +14,10 @@ use processor::{
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
io::{self, stdout, Write},
|
io::{self, stdout, Write},
|
||||||
sync::RwLock,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::processor::gpu;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! verbose_println {
|
macro_rules! verbose_println {
|
||||||
($($tts:tt)*) => {
|
($($tts:tt)*) => {
|
||||||
|
@ -66,23 +68,34 @@ struct Args {
|
||||||
/// Step emulation by...
|
/// Step emulation by...
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
step_by: Option<usize>,
|
step_by: Option<usize>,
|
||||||
|
|
||||||
|
/// Step emulation by...
|
||||||
|
#[arg(short, long)]
|
||||||
|
scale_factor: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut PAUSE_ENABLED: bool = false;
|
static mut PAUSE_ENABLED: bool = false;
|
||||||
static mut PAUSE_QUEUED: bool = false;
|
static mut PAUSE_QUEUED: bool = false;
|
||||||
|
|
||||||
static VERBOSE: RwLock<bool> = RwLock::new(false);
|
static VERBOSE: OnceCell<bool> = OnceCell::new();
|
||||||
|
|
||||||
const WIDTH: usize = 160;
|
const WIDTH: usize = 160;
|
||||||
const HEIGHT: usize = 144;
|
const HEIGHT: usize = 144;
|
||||||
const FACTOR: usize = 3;
|
static FACTOR: OnceCell<usize> = OnceCell::new();
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
{
|
|
||||||
let mut v = VERBOSE.write().unwrap();
|
VERBOSE.set(args.verbose).unwrap();
|
||||||
*v = args.verbose;
|
|
||||||
}
|
FACTOR
|
||||||
|
.set(if let Some(factor) = args.scale_factor {
|
||||||
|
factor
|
||||||
|
} else {
|
||||||
|
3
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
gpu::init_statics();
|
||||||
|
|
||||||
let rom: Rom = match fs::read(args.rom) {
|
let rom: Rom = match fs::read(args.rom) {
|
||||||
Ok(data) => Rom::load(data),
|
Ok(data) => Rom::load(data),
|
||||||
|
@ -101,8 +114,8 @@ fn main() {
|
||||||
|
|
||||||
let mut window = Window::new(
|
let mut window = Window::new(
|
||||||
format!("{} on {}", rom.get_title(), rom.mbc_type()).as_str(),
|
format!("{} on {}", rom.get_title(), rom.mbc_type()).as_str(),
|
||||||
WIDTH * FACTOR,
|
WIDTH * FACTOR.get().unwrap(),
|
||||||
HEIGHT * FACTOR,
|
HEIGHT * FACTOR.get().unwrap(),
|
||||||
WindowOptions::default(),
|
WindowOptions::default(),
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
|
@ -196,8 +209,8 @@ fn print_cycles(cycles: &i32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_verbose() -> bool {
|
fn is_verbose() -> bool {
|
||||||
match VERBOSE.read() {
|
match VERBOSE.get() {
|
||||||
Ok(v) => *v,
|
Some(v) => *v,
|
||||||
Err(_) => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,24 @@ use crate::{
|
||||||
FACTOR, HEIGHT, WIDTH,
|
FACTOR, HEIGHT, WIDTH,
|
||||||
};
|
};
|
||||||
use minifb::{Window, WindowOptions};
|
use minifb::{Window, WindowOptions};
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
mod tile_window;
|
mod tile_window;
|
||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
const TILE_WINDOW_WIDTH: usize = 16 * 8;
|
const TILE_WINDOW_WIDTH: usize = 16 * 8;
|
||||||
const TILE_WINDOW_HEIGHT: usize = 24 * 8;
|
const TILE_WINDOW_HEIGHT: usize = 24 * 8;
|
||||||
const TILE_WINDOW_WIDTH_SCALED: usize = TILE_WINDOW_WIDTH * FACTOR;
|
static TILE_WINDOW_WIDTH_SCALED: OnceCell<usize> = OnceCell::new();
|
||||||
const TILE_WINDOW_HEIGHT_SCALED: usize = TILE_WINDOW_HEIGHT * FACTOR;
|
static TILE_WINDOW_HEIGHT_SCALED: OnceCell<usize> = OnceCell::new();
|
||||||
|
|
||||||
|
pub fn init_statics() {
|
||||||
|
TILE_WINDOW_WIDTH_SCALED
|
||||||
|
.set(TILE_WINDOW_WIDTH * FACTOR.get().unwrap())
|
||||||
|
.unwrap();
|
||||||
|
TILE_WINDOW_HEIGHT_SCALED
|
||||||
|
.set(TILE_WINDOW_HEIGHT * FACTOR.get().unwrap())
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Gpu {
|
pub struct Gpu {
|
||||||
pub buffer: Vec<u32>,
|
pub buffer: Vec<u32>,
|
||||||
|
@ -35,15 +45,15 @@ impl Gpu {
|
||||||
let tile_window = if enable_tile_window {
|
let tile_window = if enable_tile_window {
|
||||||
let mut window = Window::new(
|
let mut window = Window::new(
|
||||||
"Tiles",
|
"Tiles",
|
||||||
TILE_WINDOW_WIDTH_SCALED,
|
*TILE_WINDOW_WIDTH_SCALED.get().unwrap(),
|
||||||
TILE_WINDOW_HEIGHT_SCALED,
|
*TILE_WINDOW_HEIGHT_SCALED.get().unwrap(),
|
||||||
WindowOptions::default(),
|
WindowOptions::default(),
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
panic!("{e}");
|
panic!("{e}");
|
||||||
});
|
});
|
||||||
|
|
||||||
window.set_position((550 + (WIDTH * FACTOR)) as isize, 50);
|
window.set_position((550 + (WIDTH * FACTOR.get().unwrap())) as isize, 50);
|
||||||
window.topmost(true);
|
window.topmost(true);
|
||||||
Some(TileWindow::new(window))
|
Some(TileWindow::new(window))
|
||||||
} else {
|
} else {
|
||||||
|
@ -406,9 +416,14 @@ impl Cpu {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_window(&mut self) {
|
fn render_window(&mut self) {
|
||||||
self.gpu.scaled_buffer = scale_buffer(&self.gpu.buffer, WIDTH, HEIGHT, FACTOR);
|
self.gpu.scaled_buffer =
|
||||||
|
scale_buffer(&self.gpu.buffer, WIDTH, HEIGHT, *FACTOR.get().unwrap());
|
||||||
self.window
|
self.window
|
||||||
.update_with_buffer(&self.gpu.scaled_buffer, WIDTH * FACTOR, HEIGHT * FACTOR)
|
.update_with_buffer(
|
||||||
|
&self.gpu.scaled_buffer,
|
||||||
|
WIDTH * FACTOR.get().unwrap(),
|
||||||
|
HEIGHT * FACTOR.get().unwrap(),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,11 @@ impl TileWindow {
|
||||||
pub(super) fn new(window: Window) -> Self {
|
pub(super) fn new(window: Window) -> Self {
|
||||||
Self {
|
Self {
|
||||||
sprite_buffer: vec![0; TILE_WINDOW_WIDTH * TILE_WINDOW_HEIGHT],
|
sprite_buffer: vec![0; TILE_WINDOW_WIDTH * TILE_WINDOW_HEIGHT],
|
||||||
sprite_buffer_scaled: vec![0; TILE_WINDOW_WIDTH_SCALED * TILE_WINDOW_HEIGHT_SCALED],
|
sprite_buffer_scaled: vec![
|
||||||
|
0;
|
||||||
|
TILE_WINDOW_WIDTH_SCALED.get().unwrap()
|
||||||
|
* TILE_WINDOW_HEIGHT_SCALED.get().unwrap()
|
||||||
|
],
|
||||||
sprite_window: window,
|
sprite_window: window,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,13 +57,13 @@ impl TileWindow {
|
||||||
&self.sprite_buffer,
|
&self.sprite_buffer,
|
||||||
TILE_WINDOW_WIDTH,
|
TILE_WINDOW_WIDTH,
|
||||||
TILE_WINDOW_HEIGHT,
|
TILE_WINDOW_HEIGHT,
|
||||||
FACTOR,
|
*FACTOR.get().unwrap(),
|
||||||
);
|
);
|
||||||
self.sprite_window
|
self.sprite_window
|
||||||
.update_with_buffer(
|
.update_with_buffer(
|
||||||
&self.sprite_buffer_scaled,
|
&self.sprite_buffer_scaled,
|
||||||
TILE_WINDOW_WIDTH_SCALED,
|
*TILE_WINDOW_WIDTH_SCALED.get().unwrap(),
|
||||||
TILE_WINDOW_HEIGHT_SCALED,
|
*TILE_WINDOW_HEIGHT_SCALED.get().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue