diff --git a/README.md b/README.md index 0c93550..4df526e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ - quick drop -- better rng - fix asm loader - document everything - prettier pictures \ No newline at end of file diff --git a/tetros/src/lib.rs b/tetros/src/lib.rs index 5e48eb9..7eb0c7d 100644 --- a/tetros/src/lib.rs +++ b/tetros/src/lib.rs @@ -6,7 +6,7 @@ use core::arch::asm; use lazy_static::lazy_static; -use rand::{rngs::SmallRng, SeedableRng}; +use rand::{rngs::SmallRng, Rng, SeedableRng}; use spin::Mutex; use drivers::{pic::PICDriver, vga::Vga13h}; @@ -89,6 +89,16 @@ enum InputKey { } extern "x86-interrupt" fn keyboard_handler(_stack_frame: InterruptStackFrame) { + { + // Re-seed our rng using user input. + // This is a simple hack that makes our + // "random" tile selector less deterministic. + let mut rng = RNG.lock(); + let past: u64 = rng.random(); + let tcr = u64::from(*TICK_COUNTER.lock()); + *rng = SmallRng::seed_from_u64(past + tcr); + } + 'key_block: { let scancode = unsafe { inb(0x60) }; let key = match scancode {