summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt4
-rw-r--r--Cargo.toml2
-rw-r--r--src/luma.rs4
-rw-r--r--src/luma/application.rs3
-rw-r--r--src/luma/application/initialise.rs4
-rw-r--r--src/luma/application/run.rs18
-rw-r--r--src/luma/device.rs2
-rw-r--r--src/luma/device/palette.rs34
-rw-r--r--src/luma/device/video.rs34
9 files changed, 101 insertions, 4 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 66f1bd1..c27d5d0 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,7 @@
+# 0.2C
+
+* Fill window according to first palette entry;
+
# 0.2B
* Update messages
diff --git a/Cargo.toml b/Cargo.toml
index 53447d4..d763c67 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "luma"
-version = "0.43.0"
+version = "0.44.0"
authors = ["Gabriel Jensen"]
edition = "2021"
description = "AGB emulator."
diff --git a/src/luma.rs b/src/luma.rs
index 000cb45..6587db4 100644
--- a/src/luma.rs
+++ b/src/luma.rs
@@ -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> {
@@ -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,
diff --git a/src/luma/application.rs b/src/luma/application.rs
index 7894b29..1b4c879 100644
--- a/src/luma/application.rs
+++ b/src/luma/application.rs
@@ -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;
@@ -39,7 +40,7 @@ pub struct Application {
configuration: Configuration,
sdl: Sdl,
sdl_video: VideoSubsystem,
- window: Window,
+ canvas: WindowCanvas,
device: Device,
}
diff --git a/src/luma/application/initialise.rs b/src/luma/application/initialise.rs
index 02b05bf..c813e23 100644
--- a/src/luma/application/initialise.rs
+++ b/src/luma/application/initialise.rs
@@ -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(),
};
}
diff --git a/src/luma/application/run.rs b/src/luma/application/run.rs
index 2e47712..9fc033b 100644
--- a/src/luma/application/run.rs
+++ b/src/luma/application/run.rs
@@ -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;
@@ -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));
}
}
diff --git a/src/luma/device.rs b/src/luma/device.rs
index 30f1bb1..240535d 100644
--- a/src/luma/device.rs
+++ b/src/luma/device.rs
@@ -37,6 +37,7 @@ 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;
@@ -44,6 +45,7 @@ pub mod shift;
pub mod store;
pub mod thumb;
pub mod trap;
+pub mod video;
pub mod write;
pub enum Trap {
diff --git a/src/luma/device/palette.rs b/src/luma/device/palette.rs
new file mode 100644
index 0000000..f7c17fb
--- /dev/null
+++ b/src/luma/device/palette.rs
@@ -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) };
+ }
+} \ No newline at end of file
diff --git a/src/luma/device/video.rs b/src/luma/device/video.rs
new file mode 100644
index 0000000..9c97806
--- /dev/null
+++ b/src/luma/device/video.rs
@@ -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) };
+ }
+} \ No newline at end of file