aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-09 11:25:53 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-09 11:25:53 -0400
commit88e83296cd6b401bfb794e3b3869063a309ef172 (patch)
treef12065e94b359643a8155e847681773918307d41
parent2067b846e7d9a8a58650b24cee45a86d0d23ba43 (diff)
downloadnes-snake-88e83296cd6b401bfb794e3b3869063a309ef172.tar.gz
nes-snake-88e83296cd6b401bfb794e3b3869063a309ef172.zip
simple rng
-rw-r--r--main.s38
1 files changed, 38 insertions, 0 deletions
diff --git a/main.s b/main.s
index 3d52888..b840298 100644
--- a/main.s
+++ b/main.s
@@ -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: ; {{{