gpu actually almost works
This commit is contained in:
parent
c3c02fa539
commit
cf67c8a501
|
@ -5,7 +5,7 @@ use self::{
|
|||
},
|
||||
};
|
||||
use crate::{
|
||||
processor::{get_bit, set_bit, set_or_clear_bit, CPU},
|
||||
processor::{clear_bit, get_bit, set_bit, set_or_clear_bit, CPU},
|
||||
FACTOR, HEIGHT, WIDTH,
|
||||
};
|
||||
use minifb::{Window, WindowOptions};
|
||||
|
@ -182,6 +182,9 @@ impl CPU {
|
|||
|| (mode_0_hblank_enabled && mode_0_hblank)
|
||||
{
|
||||
self.memory.set(0xFF0F, set_bit(self.memory.get(0xFF0F), 1));
|
||||
} else {
|
||||
self.memory
|
||||
.set(0xFF0F, clear_bit(self.memory.get(0xFF0F), 1));
|
||||
}
|
||||
|
||||
stat = set_or_clear_bit(stat, 2, lyc_eq_ly);
|
||||
|
@ -200,6 +203,9 @@ impl CPU {
|
|||
}
|
||||
|
||||
fn render_scanline(&mut self, scanline: u8, lcdc: &LCDC) {
|
||||
for x in 0..WIDTH {
|
||||
self.gpu.buffer[(scanline as usize * WIDTH) + x] = Colour::from_u8_rgb(255, 0, 255);
|
||||
}
|
||||
let bg_palette = byte_to_palette(self.memory.get(0xFF47));
|
||||
if lcdc.bg_window_enable {
|
||||
self.render_scanline_bg(scanline, lcdc, bg_palette);
|
||||
|
@ -218,8 +224,8 @@ impl CPU {
|
|||
}
|
||||
|
||||
fn render_scanline_bg(&mut self, scanline: u8, lcdc: &LCDC, palette: Palette) {
|
||||
let scroll_y = self.memory.get(0xFF42);
|
||||
let scroll_x = self.memory.get(0xFF43);
|
||||
let scroll_y = 0_u8.wrapping_sub(self.memory.get(0xFF42));
|
||||
let scroll_x = 0_u8.wrapping_sub(self.memory.get(0xFF43));
|
||||
self.render_tiles(
|
||||
scanline,
|
||||
&lcdc.bg_tilemap,
|
||||
|
@ -333,8 +339,8 @@ impl CPU {
|
|||
offset_y: u8,
|
||||
wrap: bool,
|
||||
) {
|
||||
let tile_line_y = scanline.wrapping_add(offset_y);
|
||||
if ((scanline as usize + offset_y as usize) / 0xFF) > 0 && !wrap {
|
||||
let (tile_line_y, did_wrap_y) = scanline.overflowing_sub(offset_y);
|
||||
if did_wrap_y && !wrap {
|
||||
return;
|
||||
}
|
||||
let tilemap_row = tile_line_y / 8;
|
||||
|
@ -342,8 +348,8 @@ impl CPU {
|
|||
let tiledata_offset = tile_px_y * 2;
|
||||
let row_addr = ((tilemap_row as usize * 32) % 0x400) as u16;
|
||||
for x in 0..WIDTH {
|
||||
let tile_line_x = (x as u8).wrapping_add(offset_x);
|
||||
if ((x + offset_x as usize) / 0xFF) > 0 && !wrap {
|
||||
let (tile_line_x, did_wrap_x) = (x as u8).overflowing_sub(offset_x);
|
||||
if did_wrap_x && !wrap {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::processor::as_signed;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub(super) enum DrawMode {
|
||||
HBlank,
|
||||
VBlank,
|
||||
|
@ -8,7 +8,7 @@ pub(super) enum DrawMode {
|
|||
Mode3,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub(super) enum TilemapArea {
|
||||
T9800,
|
||||
T9C00,
|
||||
|
@ -23,7 +23,7 @@ impl TilemapArea {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub(super) enum TiledataArea {
|
||||
D8000,
|
||||
D9000,
|
||||
|
@ -38,7 +38,7 @@ impl TiledataArea {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub(super) enum ObjSize {
|
||||
S8x8,
|
||||
S8x16,
|
||||
|
@ -53,7 +53,7 @@ impl ObjSize {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub(super) struct LCDC {
|
||||
pub(super) enable: bool,
|
||||
pub(super) window_tilemap: TilemapArea,
|
||||
|
|
Loading…
Reference in a new issue