Skip to content
Snippets Groups Projects
main.rs 3.19 KiB
use boytacean::{gb::GameBoy, ppu::{DISPLAY_WIDTH, DISPLAY_HEIGHT}};
use sdl2::{video::Window, pixels::PixelFormatEnum, VideoSubsystem, TimerSubsystem, EventPump};

/// The base title to be used in the window.
static TITLE: &'static str = "Boytacean";

pub struct Graphics {
    window: Window,
    video_subsystem: VideoSubsystem,
    timer_subsystem: TimerSubsystem,
    event_pump: EventPump,
}

fn start_sdl() -> Graphics {
    // initializes the SDL sub-system, making it ready to be
    // used for display of graphics and audio
    let sdl = sdl2::init().unwrap();
    let video_subsystem = sdl.video().unwrap();
    let timer_subsystem = sdl.timer().unwrap();
    let audio_subsystem = sdl.audio().unwrap();
    let event_pump = sdl.event_pump().unwrap();

    // initialized the fonts context to be used
    // in the loading of fonts
    let ttf_context = sdl2::ttf::init().unwrap();

    // creates the system window that is going to be used to
    // show the emulator and sets it to the central are o screen
    let mut window = video_subsystem
        .window(
            TITLE,
            2 as u32 * DISPLAY_WIDTH as u32, //@todo check screen scale
            2 as u32 * DISPLAY_HEIGHT as u32, //@todo check screen scale
        )
        .resizable()
        .position_centered()
        .opengl()
        .build()
        .unwrap();

    Graphics {
        window: window,
        video_subsystem: video_subsystem,
        timer_subsystem: timer_subsystem,
        event_pump: event_pump
    }
}

fn main() {
    let mut graphics = start_sdl();

    let mut canvas = graphics.window.into_canvas().accelerated().build().unwrap();
    canvas.clear();
    canvas.present();

    let texture_creator = canvas.texture_creator();

    // creates the texture streaming that is going to be used
    // as the target for the pixel buffer
    let mut texture = texture_creator
        .create_texture_streaming(
            PixelFormatEnum::RGB24,
            DISPLAY_WIDTH as u32,
            DISPLAY_HEIGHT as u32,
        )
        .unwrap();

    let mut game_boy = GameBoy::new();
    game_boy.load_boot_default();