use crate::flash;
use crate::macros::bit;
use core::fmt::Display;
use core::fmt::Write;
use gba_utils::gfx;
use gba_utils::include_bytes_align_as;

const ROM: &'static [u8] = include_bytes_align_as!(u16, "assets/gba-hello-world.gba");

pub fn init() -> ! {
    let di = gfx::text_mode_setup(false);
    let mut writer = gfx::GfxWriter::<gfx::Default8x8>::new(0, 0, di);
    write!(writer, "init\n").ok();

    unsafe {
        let (man, dev) = flash::get_id();
        write!(writer, "Manufacturer {} Device {}\n", man, dev);
    }

    write!(
        writer,
        "ROM length: {} [{} WBLs]\nWriting...\n",
        ROM.len(),
        ROM.len() / 512
    );
    unsafe { flash::write_sector(0, ROM) };
    write!(writer, "Finished.\n");

    loop {}
}
