From d93facbaf4d241aaa63c1d0138ee5cf262409620 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sun, 11 Apr 2021 18:00:18 -0600 Subject: [PATCH] fix wrapping math errors. Part of https://github.com/rust-console/gba/issues/129 --- examples/test_savegame.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/test_savegame.rs b/examples/test_savegame.rs index 2529a77..8affb7c 100644 --- a/examples/test_savegame.rs +++ b/examples/test_savegame.rs @@ -1,6 +1,11 @@ #![no_std] #![no_main] +// Note(Lokathor): this demo must be run in release mode or it'll just be way +// too slow. When testing is running the screen fills from yellow to green. If +// there's a panic you should see red. If all tests complete the screen turns +// blue at the end. + use core::cmp; use gba::{fatal, prelude::*, save::*, warn}; @@ -29,7 +34,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! { struct Rng(u32); impl Rng { fn iter(&mut self) { - self.0 = self.0 * 2891336453 + 100001; + self.0 = self.0.wrapping_mul(2891336453).wrapping_add(100001); } fn next_u8(&mut self) -> u8 { self.iter(); @@ -165,6 +170,7 @@ fn main() -> ! { } // show a pattern so we know it worked - set_screen_color(0, 31, 0); + set_screen_color(0, 29, 29); + output!("All tests complete!"); loop {} }