scaling & lcd enable back

This commit is contained in:
Alex Janka 2023-02-05 22:56:18 +11:00
parent 75c765b392
commit 587916ed34
2 changed files with 31 additions and 8 deletions

View file

@ -249,6 +249,7 @@ static VERBOSE: RwLock<bool> = RwLock::new(false);
const WIDTH: usize = 160;
const HEIGHT: usize = 144;
const FACTOR: usize = 3;
fn main() {
let args = Args::parse();
@ -259,10 +260,15 @@ fn main() {
// let buffer: Vec<u32> = ;
let window =
Window::new("Gameboy", WIDTH, HEIGHT, WindowOptions::default()).unwrap_or_else(|e| {
panic!("{}", e);
});
let window = Window::new(
"Gameboy",
WIDTH * FACTOR,
HEIGHT * FACTOR,
WindowOptions::default(),
)
.unwrap_or_else(|e| {
panic!("{}", e);
});
window.topmost(true);

View file

@ -1,4 +1,4 @@
use crate::{HEIGHT, WIDTH};
use crate::{FACTOR, HEIGHT, WIDTH};
use super::{clear_bit, get_bit, set_bit, set_or_clear_bit, CPU};
@ -70,6 +70,7 @@ struct Palette {
pub struct GPU {
pub buffer: Vec<u32>,
scaled_buffer: Vec<u32>,
mode: DrawMode,
mode_clock: usize,
scanline: u8,
@ -79,6 +80,7 @@ impl Default for GPU {
fn default() -> Self {
Self {
buffer: vec![0; WIDTH * HEIGHT],
scaled_buffer: vec![0; WIDTH * HEIGHT * 4],
mode: DrawMode::Mode2,
mode_clock: 0,
scanline: 0,
@ -172,10 +174,10 @@ impl CPU {
fn enter_vblank(&mut self, lcdc: &LCDC) {
self.gpu.mode = DrawMode::VBlank;
// if lcdc.enable {
if lcdc.enable {
self.render_window();
self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 0));
// }
}
}
fn exit_vblank(&mut self) {
@ -252,12 +254,27 @@ impl CPU {
}
fn render_window(&mut self) {
self.gpu.scaled_buffer = scale_buffer(&self.gpu.buffer, WIDTH, HEIGHT, FACTOR);
self.window
.update_with_buffer(&self.gpu.buffer, WIDTH, HEIGHT)
.update_with_buffer(&self.gpu.scaled_buffer, WIDTH * FACTOR, HEIGHT * FACTOR)
.unwrap();
}
}
fn scale_buffer(buffer: &Vec<u32>, width: usize, height: usize, factor: usize) -> Vec<u32> {
let mut v = vec![];
for y in 0..height {
for _ in 0..factor {
for x in 0..width {
for _ in 0..factor {
v.push(buffer[(y * width) + x]);
}
}
}
}
v
}
fn get_tilemap_offset(tilemap: &TilemapArea) -> u16 {
match tilemap {
TilemapArea::T9800 => 0x9800,