diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-10-09 11:25:53 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-10-09 11:25:53 -0400 |
commit | 88e83296cd6b401bfb794e3b3869063a309ef172 (patch) | |
tree | f12065e94b359643a8155e847681773918307d41 | |
parent | 2067b846e7d9a8a58650b24cee45a86d0d23ba43 (diff) | |
download | nes-snake-88e83296cd6b401bfb794e3b3869063a309ef172.tar.gz nes-snake-88e83296cd6b401bfb794e3b3869063a309ef172.zip |
simple rng
-rw-r--r-- | main.s | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -40,6 +40,7 @@ length DB direction DB ; 0: up, 1: down, 2: left, 3: right frame_skip DB frame_count DB +rand_state DB .ENDE ; }}} ; }}} @@ -188,6 +189,10 @@ end_nmi: ; }}} ; subroutines {{{ start_screen_loop: ; {{{ + LDX rand_state + INX + STX rand_state + handle_start: LDA buttons_pressed AND #%00010000 @@ -422,6 +427,39 @@ end_game: ; {{{ LDA #$00 STA game_state RTS ; }}} +rand: ; {{{ + ; linear feedback shift register with taps at 8, 6, 5, and 4 + LDY rand_state + TYA + AND #%10000000 + STA rand_state + TYA + AND #%00100000 + ASL + ASL + EOR rand_state + STA rand_state + TYA + AND #%00010000 + ASL + ASL + ASL + EOR rand_state + STA rand_state + TYA + AND #%00001000 + ASL + ASL + ASL + ASL + EOR rand_state + ROL + STA rand_state + TYA + ASL + ORA rand_state + STA rand_state + RTS ; }}} ; }}} ; data {{{ palette: ; {{{ |