From cf80e313b17aecad8e1d0fe332c79185e0364054 Mon Sep 17 00:00:00 2001 From: xokz <106196742+xokz@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:46:32 -0400 Subject: [PATCH 1/4] Update bitmap4.rs colors of lower values can now overwrite colors of higher values. --- agb/src/display/bitmap4.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agb/src/display/bitmap4.rs b/agb/src/display/bitmap4.rs index b40eff9c..91fe3a48 100644 --- a/agb/src/display/bitmap4.rs +++ b/agb/src/display/bitmap4.rs @@ -48,9 +48,9 @@ impl Bitmap4 { let c = addr.get(x_in_screen, y_in_screen); if x & 0b1 != 0 { - addr.set(x_in_screen, y_in_screen, c | u16::from(colour) << 8); + addr.set(x_in_screen, y_in_screen, (c & 0xff) | u16::from(colour) << 8); } else { - addr.set(x_in_screen, y_in_screen, c | u16::from(colour)); + addr.set(x_in_screen, y_in_screen, (c & 0xff00) | u16::from(colour)); } } From 575976bf527a50dc2389e461b279d0a8e3ed3f90 Mon Sep 17 00:00:00 2001 From: xokz <106196742+xokz@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:03:24 -0400 Subject: [PATCH 2/4] Update bitmap4.rs --- agb/src/display/bitmap4.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agb/src/display/bitmap4.rs b/agb/src/display/bitmap4.rs index 91fe3a48..4ef454e2 100644 --- a/agb/src/display/bitmap4.rs +++ b/agb/src/display/bitmap4.rs @@ -48,9 +48,9 @@ impl Bitmap4 { let c = addr.get(x_in_screen, y_in_screen); if x & 0b1 != 0 { - addr.set(x_in_screen, y_in_screen, (c & 0xff) | u16::from(colour) << 8); + addr.set(x_in_screen, y_in_screen, c & 0xff | u16::from(colour) << 8); } else { - addr.set(x_in_screen, y_in_screen, (c & 0xff00) | u16::from(colour)); + addr.set(x_in_screen, y_in_screen, c & 0xff00 | u16::from(colour)); } } From 74ccdfcd7fc77c975f7197cd10fd01e6c6224605 Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 28 Sep 2023 21:19:07 +0100 Subject: [PATCH 3/4] update example to excersise the broken case --- agb/examples/bitmap4.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/agb/examples/bitmap4.rs b/agb/examples/bitmap4.rs index a46f6c72..3084cfa4 100644 --- a/agb/examples/bitmap4.rs +++ b/agb/examples/bitmap4.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] -use agb::display; +use agb::display::{self, HEIGHT, WIDTH}; #[agb::entry] fn main(mut gba: agb::Gba) -> ! { @@ -11,25 +11,22 @@ fn main(mut gba: agb::Gba) -> ! { bitmap.set_palette_entry(1, 0x001F); bitmap.set_palette_entry(2, 0x03E0); - bitmap.draw_point_page( - display::WIDTH / 2, - display::HEIGHT / 2, - 1, - display::bitmap4::Page::Front, - ); - bitmap.draw_point_page( - display::WIDTH / 2 + 5, - display::HEIGHT / 2, - 2, - display::bitmap4::Page::Back, - ); + for y in 0..HEIGHT { + for x in 0..WIDTH { + bitmap.draw_point_page(x, y, 0xF, display::bitmap4::Page::Front); + bitmap.draw_point_page(x, y, 1, display::bitmap4::Page::Front); + bitmap.draw_point_page(x, y, 0xFF, display::bitmap4::Page::Back); + bitmap.draw_point_page(x, y, 2, display::bitmap4::Page::Back); + } + } - let mut count = 0; + let mut input = agb::input::ButtonController::new(); loop { vblank.wait_for_vblank(); - count += 1; - if count % 6 == 0 { + input.update(); + + if input.is_just_pressed(agb::input::Button::A) { bitmap.flip_page(); } } From e2bff6dffff73d4558964c98df432bfae94c05ad Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 28 Sep 2023 21:20:56 +0100 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11497da3..568443f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Text renderer can now be re-used which is useful for rpg style character/word at a time text boxes. +### Fixed +- Fixed a bug in bitmap4 that caused setting pixels to be always incorrect. + ## [0.12.2] - 2022/10/22 This is a minor release to fix an alignment issue with background tiles.