File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -30,15 +30,17 @@ use chirp8::peripherals::*;
3030struct Board {
3131 fb_dirty : bool ,
3232 fb_pixels : [ [ u8 ; ( pcd8544:: SCREEN_HEIGHT / 8 ) as usize ] ; pcd8544:: SCREEN_WIDTH as usize ] ,
33- countdown : u8
33+ countdown : u8 ,
34+ prng_state : u16 ,
3435}
3536
3637impl Board {
3738 pub const fn new ( ) -> Board {
3839 Board {
3940 fb_dirty : false ,
4041 fb_pixels : [ [ 0 ; ( pcd8544:: SCREEN_HEIGHT / 8 ) as usize ] ; pcd8544:: SCREEN_WIDTH as usize ] ,
41- countdown : 0
42+ countdown : 0 ,
43+ prng_state : 0x0001
4244 }
4345 }
4446}
@@ -134,7 +136,12 @@ impl Peripherals for Board {
134136 serial_ram:: write_ram ( addr, v)
135137 }
136138
137- fn get_random ( & mut self ) -> Byte { 0x42 }
139+ fn get_random ( & mut self ) -> Byte {
140+ let lsb = self . prng_state & 1 ;
141+ self . prng_state >>= 1 ;
142+ if lsb != 0 { self . prng_state ^= 0xd008 } // Covers full u16 space
143+ self . prng_state as Byte
144+ }
138145}
139146
140147fn redraw ( board : & mut Board ) {
@@ -147,6 +154,7 @@ fn redraw(board: &mut Board) {
147154pub fn tick ( ) {
148155 let board = unsafe { & mut BOARD } ;
149156 if board. countdown > 0 { board. countdown -= 1 ; } ;
157+ board. get_random ( ) ;
150158 redraw ( board) ;
151159}
152160
You can’t perform that action at this time.
0 commit comments