Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alloncm committed Jul 20, 2024
1 parent dca30f1 commit 9b9e114
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions core/src/ppu/gb_ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<GFX:GfxDevice> GbPpu<GFX>{

#[cfg(feature = "dbg")]
fn get_sprite_layer(&self)->[Pixel; crate::debugger::PPU_BUFFER_SIZE]{
use crate::{debugger::PPU_BUFFER_WIDTH, ppu::color};
use crate::{debugger::{PPU_BUFFER_SIZE, PPU_BUFFER_WIDTH}, ppu::color};

let oam_table = self.oam
.chunks_exact(OAM_ENTRY_SIZE as usize)
Expand Down Expand Up @@ -211,7 +211,11 @@ impl<GFX:GfxDevice> GbPpu<GFX>{
Mode::DMG => self.get_dmg_sprite_pixel(&sprite, sprite_pixel),
Mode::CGB => Self::get_color_from_color_ram(&self.obj_color_ram, sprite.gbc_palette_number, sprite_pixel.color_index),
};
buffer[index_prefix + (8 - k - 1)] = color.into();
let index = index_prefix + (8 - k - 1);
// Some could be placed at x/y = 247 -- 255 and it could crash the program, not sure how to fix it
if index < PPU_BUFFER_SIZE{
buffer[index] = color.into();
}
}
}
oam_entry += 1;
Expand Down
10 changes: 8 additions & 2 deletions sdl/src/sdl/sdl_gfx_device.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ffi::{CString, c_void};
use sdl2::sys::*;
use magenboy_core::{ppu::gb_ppu::{SCREEN_HEIGHT, SCREEN_WIDTH}, GfxDevice, Pixel};
use magenboy_core::{debugger::{PPU_BUFFER_HEIGHT, PPU_BUFFER_WIDTH}, ppu::gb_ppu::{SCREEN_HEIGHT, SCREEN_WIDTH}, GfxDevice, Pixel};
use crate::sdl::utils::get_sdl_error_message;

pub struct SdlGfxDevice{
Expand Down Expand Up @@ -123,11 +123,17 @@ impl PpuLayerWindow{
let window:*mut SDL_Window = SDL_CreateWindow(
c_name.as_ptr(),
SDL_WINDOWPOS_UNDEFINED_MASK as i32, SDL_WINDOWPOS_UNDEFINED_MASK as i32,
0x100, 0x100, 0);
0x100, 0x100, SDL_WindowFlags::SDL_WINDOW_RESIZABLE as u32);
let renderer: *mut SDL_Renderer = SDL_CreateRenderer(window, -1, 0);
let texture: *mut SDL_Texture = SDL_CreateTexture(renderer, SDL_PIXEL_FORMAT,
SDL_TextureAccess::SDL_TEXTUREACCESS_STREAMING as i32, 0x100, 0x100);

if SDL_RenderSetLogicalSize(renderer, (PPU_BUFFER_WIDTH as u32) as i32, (PPU_BUFFER_HEIGHT as u32) as i32) != 0{
std::panic!("Error while setting logical rendering\nError:{}", get_sdl_error_message());
}

SDL_SetWindowMinimumSize(window, PPU_BUFFER_WIDTH as i32, PPU_BUFFER_HEIGHT as i32);

return PpuLayerWindow { _window_name: c_name, window, renderer, texture};
}
}
Expand Down

0 comments on commit 9b9e114

Please sign in to comment.