Skip to content

Commit

Permalink
Implement Vertical Scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
Miwgt committed Jun 14, 2024
1 parent 67516c2 commit 1cb74af
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/rendering/line_rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,33 @@ pub fn draw_pixels(cpu: &mut CPU, game_diplay: &mut Image, palette: &[Color; 4])
let scy = cpu.get_lcd_scy();
let line: u8 = cpu.get_lcd_y_coordinate();

for xtile in 0..20 {
let mut display_x: u32 = 0;
let mut line_x_pos = scx as u32 % 8;

for xtile in 0..21 {
let tile_index = cpu.get_vram_tile_map(
high_map,
(((line + scy) / 8) as u16 % 0x100) * 32 + (xtile + (scx as u16 / 8)) % 32,
);
let line_data =
cpu.get_vram_tile_line(high_addressing, tile_index as u16, (line + scy) % 8);

for x_pixel in 0..8 {
//log::info!("Drawing pixel at x: {}, y: {}, xtile: {}, line: {}, color: {}", xtile as u32 * 8 + x_pixel, line as u32, xtile, line, line_data[x_pixel as usize]);

let width = game_diplay.width();
let x = xtile as u32 * 8 + x_pixel;
let y = line as u32;
let image_len = game_diplay.get_image_data().len();
for x_pixel in (line_x_pos % 8)..8 {
if display_x >= game_diplay.width() as u32 {
break;
}

if (y * width as u32 + x) as usize >= image_len {
log::warn!("Pixel out of bounds: x: {}, y: {}", x, y);
if (line as usize * game_diplay.width() + display_x as usize)
>= game_diplay.get_image_data().len()
{
log::warn!("Pixel out of bounds: x: {}, y: {}", display_x, line);
continue;
}

game_diplay.set_pixel(x, y, palette[line_data[x_pixel as usize] as usize]);
game_diplay.set_pixel(display_x, line as u32, palette[line_data[x_pixel as usize] as usize]);

display_x += 1;
line_x_pos += 1;
}
}
}
Expand Down

0 comments on commit 1cb74af

Please sign in to comment.