Skip to content

Commit

Permalink
Fill window according to first palette entry
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernager committed Jul 5, 2023
1 parent 46200e9 commit 2ff708d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.2C

* Fill window according to first palette entry;

# 0.2B

* Update messages
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "luma"
version = "0.43.0"
version = "0.44.0"
authors = ["Gabriel Jensen"]
edition = "2021"
description = "AGB emulator."
Expand Down
4 changes: 3 additions & 1 deletion src/luma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct VersionType<T> {

pub const VERSION: VersionType::<u32> = VersionType::<u32> {
major: 0x0,
minor: 0x2B,
minor: 0x2C,
};

pub struct WidthHeight<T> {
Expand All @@ -46,6 +46,8 @@ pub const MEMORY_SIZE: usize = 0x0E010000;

pub const BOOTLOADER_SIZE: usize = 0x00004000;
pub const IMAGE_SIZE: usize = 0x02000000;
pub const VIDEO_SIZE: usize = 0x00018000;
pub const PALETTE_SIZE: usize = 0x00000400;

pub const SCREEN_SIZE: WidthHeight::<u8> = WidthHeight::<u8> {
width: 0xF0,
Expand Down
3 changes: 2 additions & 1 deletion src/luma/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::luma::device::Device;
extern crate sdl2;

use sdl2::{Sdl, VideoSubsystem};
use sdl2::render::WindowCanvas;
use sdl2::video::Window;
use std::sync::atomic::AtomicBool;

Expand All @@ -39,7 +40,7 @@ pub struct Application {
configuration: Configuration,
sdl: Sdl,
sdl_video: VideoSubsystem,
window: Window,
canvas: WindowCanvas,
device: Device,
}

Expand Down
4 changes: 3 additions & 1 deletion src/luma/application/initialise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ impl Application {

let window = sdl_video.window("luma", SCREEN_SIZE.width as u32 * configuration.scale, SCREEN_SIZE.height as u32 * configuration.scale).position_centered().build().unwrap();

let canvas = window.into_canvas().build().unwrap();

return Application {
configuration: configuration.clone(),
sdl: sdl,
sdl_video: sdl_video,
window: window,
canvas: canvas,
device: Device::new(),
};
}
Expand Down
18 changes: 18 additions & 0 deletions src/luma/application/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::luma::VERSION;
use crate::luma::application::{Application, GOT_SIGNAL};

use sdl2::event::Event;
use sdl2::pixels::Color;
use std::sync::atomic::Ordering;
use std::thread::sleep;
use std::time::Duration;
Expand Down Expand Up @@ -59,6 +60,23 @@ impl Application {

(self.device.decode)(&mut self.device);

let raw_colour = self.device.palette()[0x0];

let colour = {
let red = ((raw_colour & 0b0000000000011111) << 0x3) as u8;

let green = ((raw_colour & 0b0000001111100000) >> 0x2) as u8;

let blue = ((raw_colour & 0b0111110000000000) >> 0x7) as u8;

Color::RGB(red, green, blue)
};

self.canvas.set_draw_color(colour);
self.canvas.clear();

self.canvas.present();

sleep(Duration::from_millis(250));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/luma/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ pub mod log;
pub mod memory;
pub mod r#move;
pub mod new;
pub mod palette;
pub mod pop;
pub mod push;
pub mod read;
pub mod shift;
pub mod store;
pub mod thumb;
pub mod trap;
pub mod video;
pub mod write;

pub enum Trap {
Expand Down
34 changes: 34 additions & 0 deletions src/luma/device/palette.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2021-2023 Gabriel Jensen.
This file is part of Luma.
Luma is free software: you can redistribute it
and/or modify it under the terms of the GNU
Affero General Public License as published by
the Free Software Foundation, either version 3
of the License, or (at your option) any later
version.
Luma is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU
Affero General Public License along with Luma.
If not, see <https://www.gnu.org/licenses/>.
*/

use crate::luma::PALETTE_SIZE;
use crate::luma::device::Device;

use std::slice;

impl Device {
#[allow(dead_code)]
pub fn palette<'a>(&mut self) -> &'a mut [u16] {
return unsafe { slice::from_raw_parts_mut(self.memory.offset(0x05000000) as *mut u16, PALETTE_SIZE) };
}
}
34 changes: 34 additions & 0 deletions src/luma/device/video.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2021-2023 Gabriel Jensen.
This file is part of Luma.
Luma is free software: you can redistribute it
and/or modify it under the terms of the GNU
Affero General Public License as published by
the Free Software Foundation, either version 3
of the License, or (at your option) any later
version.
Luma is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU
Affero General Public License along with Luma.
If not, see <https://www.gnu.org/licenses/>.
*/

use crate::luma::VIDEO_SIZE;
use crate::luma::device::Device;

use std::slice;

impl Device {
#[allow(dead_code)]
pub fn video<'a>(&mut self) -> &'a mut [u8] {
return unsafe { slice::from_raw_parts_mut(self.memory.offset(0x06000000), VIDEO_SIZE) };
}
}

0 comments on commit 2ff708d

Please sign in to comment.