diff --git a/atlantico/atlantico.asm b/atlantico/atlantico.asm index 610ef11..1db2e67 100755 --- a/atlantico/atlantico.asm +++ b/atlantico/atlantico.asm @@ -44,6 +44,8 @@ PrevOAMCount: .res 1 ; Store the previous number of bytes that were sent ActorsArray: .res MAX_ACTORS * .sizeof(Actor) +Seed: .res 1 ; Used as the RANDOM NUMBER GENERATOR SEED + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PRG-ROM code located at $8000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -512,6 +514,31 @@ EndRoutine: rts .endproc + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Returns a random 8 bit number inside A (0-255), clobbers Y (0) +;; requires 1-byte value on the Zero Page called Seed +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; this is an 8 bit galois LFSR with polynomial $1D +;; The sequence of numbers it generates will repeat after 255 calls +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +.proc GetRandomNumber + ldy #8 ; Loop counter (generates 8 bits) + lda Seed ; + +Loop8Times: + asl ; Shift the register left + bcc :+ ; + eor #$1D ; Apply XOR feebback when a 1bit is shifted out + : ; + dey ; + bne Loop8Times ; + + sta Seed ; Saves the value in A + cmp #0 ; + rts ; +.endproc + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Reset handler (called when the NES resets or powers on) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;