-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
347 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use gba::{ | ||
bios::VBlankIntrWait, | ||
mmio::{DISPCNT, DISPSTAT, IE, IME, KEYINPUT, MODE3_VRAM}, | ||
video::{Color, DisplayControl, DisplayStatus}, | ||
IrqBits, | ||
}; | ||
|
||
gba::panic_handler!(empty_loop); | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() -> ! { | ||
IME.write(true); | ||
IE.write(IrqBits::new().with_vblank(true)); | ||
DISPSTAT.write(DisplayStatus::new().with_vblank_irq(true)); | ||
|
||
DISPCNT.write(DisplayControl::new().with_bg_mode(3).with_bg2(true)); | ||
|
||
let max_x = MODE3_VRAM.width() as i16 - 1; | ||
let max_y = MODE3_VRAM.height() as i16 - 1; | ||
let mut x: i16 = 5; | ||
let mut y: i16 = 15; | ||
let mut color = Color(0b0_11100_11110_11111); | ||
|
||
loop { | ||
VBlankIntrWait(); | ||
color.0 = color.0.rotate_left(1); | ||
|
||
let keys = KEYINPUT.read(); | ||
x = (x + i16::from(keys.dx())).clamp(0, max_x); | ||
y = (y + i16::from(keys.dy())).clamp(0, max_y); | ||
|
||
let addr = MODE3_VRAM.index(x as usize, (max_y - y) as usize); | ||
addr.write(color); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use gba::{ | ||
bios::VBlankIntrWait, | ||
mmio::{BG_PALRAM, DISPCNT, DISPSTAT, IE, IME, KEYINPUT, MODE4_VRAM}, | ||
video::{Color, DisplayControl, DisplayStatus}, | ||
IrqBits, | ||
}; | ||
|
||
gba::panic_handler!(empty_loop); | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() -> ! { | ||
IME.write(true); | ||
IE.write(IrqBits::new().with_vblank(true)); | ||
DISPSTAT.write(DisplayStatus::new().with_vblank_irq(true)); | ||
|
||
DISPCNT.write(DisplayControl::new().with_bg_mode(4).with_bg2(true)); | ||
|
||
let max_x = 2 * MODE4_VRAM.get_frame(0).unwrap().width() as i16 - 1; | ||
let max_y = MODE4_VRAM.get_frame(0).unwrap().height() as i16 - 1; | ||
let mut x: i16 = 5; | ||
let mut y: i16 = 15; | ||
let mut frame: usize = 0; | ||
let mut pal_index: u8 = 0; | ||
|
||
{ | ||
let mut red = 1; | ||
let mut green = 3; | ||
let mut blue = 5; | ||
BG_PALRAM.iter().for_each(|addr| { | ||
red = (red + 3) % 256; | ||
green = (green + 5) % 256; | ||
blue = (blue + 7) % 256; | ||
let color = Color::from_rgb(red, green, blue); | ||
addr.write(color) | ||
}); | ||
} | ||
|
||
loop { | ||
VBlankIntrWait(); | ||
pal_index = pal_index.wrapping_add(1); | ||
|
||
// keypad moves the update point | ||
let keys = KEYINPUT.read(); | ||
x = (x + i16::from(keys.dx())).clamp(0, max_x); | ||
y = (y + i16::from(keys.dy())).clamp(0, max_y); | ||
|
||
// L and R pick the frame | ||
if keys.r() && frame == 0 { | ||
frame = 1; | ||
} | ||
if keys.l() && frame == 1 { | ||
frame = 0; | ||
} | ||
DISPCNT.write( | ||
DisplayControl::new() | ||
.with_bg_mode(4) | ||
.with_bg2(true) | ||
.with_frame1_active(frame > 0), | ||
); | ||
|
||
// we have to do some silly dancing here because we can't write just a `u8` | ||
// in VRAM. We have to read a `u8x2` combo, update part of it, then write it | ||
// back to VRAM. | ||
let addr = MODE4_VRAM | ||
.get_frame(frame) | ||
.unwrap() | ||
.index((x / 2) as usize, (max_y - y) as usize); | ||
let old = addr.read(); | ||
addr.write(if (x & 1) != 0 { | ||
old.with_high(pal_index) | ||
} else { | ||
old.with_low(pal_index) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use gba::{ | ||
bios::VBlankIntrWait, | ||
mmio::{DISPCNT, DISPSTAT, IE, IME, KEYINPUT, MODE5_VRAM}, | ||
video::{Color, DisplayControl, DisplayStatus}, | ||
IrqBits, | ||
}; | ||
|
||
gba::panic_handler!(empty_loop); | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main() -> ! { | ||
IME.write(true); | ||
IE.write(IrqBits::new().with_vblank(true)); | ||
DISPSTAT.write(DisplayStatus::new().with_vblank_irq(true)); | ||
|
||
DISPCNT.write(DisplayControl::new().with_bg_mode(5).with_bg2(true)); | ||
|
||
let max_x = MODE5_VRAM.get_frame(0).unwrap().width() as i16 - 1; | ||
let max_y = MODE5_VRAM.get_frame(0).unwrap().height() as i16 - 1; | ||
let mut x: i16 = 5; | ||
let mut y: i16 = 15; | ||
let mut frame: usize = 0; | ||
let mut color = Color(0b0_11100_11110_11111); | ||
|
||
loop { | ||
VBlankIntrWait(); | ||
color.0 = color.0.rotate_left(1); | ||
|
||
// keypad moves the update point | ||
let keys = KEYINPUT.read(); | ||
x = (x + i16::from(keys.dx())).clamp(0, max_x); | ||
y = (y + i16::from(keys.dy())).clamp(0, max_y); | ||
|
||
// L and R pick the frame | ||
if keys.r() && frame == 0 { | ||
frame = 1; | ||
} | ||
if keys.l() && frame == 1 { | ||
frame = 0; | ||
} | ||
DISPCNT.write( | ||
DisplayControl::new() | ||
.with_bg_mode(5) | ||
.with_bg2(true) | ||
.with_frame1_active(frame > 0), | ||
); | ||
|
||
let addr = MODE5_VRAM | ||
.get_frame(frame) | ||
.unwrap() | ||
.index(x as usize, (max_y - y) as usize); | ||
addr.write(color); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.