View Full Version: pseudorandom number generator

camerahacks >>Applications / Developers >>pseudorandom number generator


<< Prev | Next >>

zapped- 07-30-2005
pseudorandom number generator
Hope someone finds this useful or something ; random.s - play random notes of random duration ; press shutter button to start playing or hold power button to exit ; feel free to use this random code for more interesting stuff .ORG $90 JMP PAST RAND0: .DB $00 RAND1: .DB $00 RAND2: .DB $00 RAND3: .DB $00 RANDSEQ: .DSB 256 $00 PAST: JSR GETKEY JSR RBS JMP PAST ;generate random byte sequence that is stored in RANDSEQ LDI R6,#$00 ;initialize RANDSEQ counter LDI R7,#$00 ;R7:R6 RBS: LDI R4,#$00 ;R4 is loop counter for RANDSEQ RSEQ: LDI R5,#$07 ;R5 is our bit countdown index RBLOOP: JSR RANDOM ;get a random bit DEC R5 BNZ RBLOOP ;loop until R5 goes negative LDA R0,RAND3 ;put random byte into R0 STO R6,RANDSEQ ;store random byte into RANDSEQ indexed by R7:R6 UPP R6 ;Play tone STA R0,$f700 ;Random duration STA R0,$f701 ;Random pitch LDI R1,#$01 STA R1,$f702 ;Play note LDI R0,#$00 LABEL: LDA R0,$f703 BNZ LABEL LDA R0,$f726 ;load power button status into R0 BTT 1 ;Is the power button pressed? BNZ RESET ; if not, reset camera INC R4 BNC RSEQ RTS RANDOM: LDA R0,RAND3 ;subroutine to generate pseudorandom bit JSR WATCH ROL R0 ROL R0 LDA R3,RAND3 XOR R3 STA R0,RAND3 ROL R0 ROL R0 LDA R1,RAND0 ROL R1 STA R1,RAND0 LDA R1,RAND1 ROL R1 STA R1,RAND1 LDA R1,RAND2 ROL R1 STA R1,RAND2 LDA R1,RAND3 ROL R1 STA R1,RAND3 RTS GETKEY: INC R1 ;R1 here is to seed the PRNG STA R1,RAND3 JSR WATCH LDI R0,#$00 LDA R0,$f726 ;load power button status into R0 BTT 1 ;Is the power button pressed? BRZ CHECK2 ; if not, continue checking ;Check if power button stays down LDI R0,#$89 ;0x89 is about 1.5 sec delay STA R0,$f704 ;Store delay in timer register $f704 S6LOOP: LDA R0,$f726 ;load power button status into R0 BTT 1 ;Is the power button still down? BRZ S6UP ; power button has been released LDA R0,$f705 ;Has timer run out? BRZ S6LOOP ; if not, keep checking button and timer LDI R0,#$01 ;Button stayed down and timer ran out so reset camera STA R0,$F715 S6UP: CHECK2: LDA R0,$f722 ;load key-press status into R0 again BTT 5 ;Is the shutter/take-pic button pressed? BRZ GETKEY ; if not, branch to the top RTS ;if so, return WATCH: LDI R2,#$01 ; value used to reset watchdog timer STA R2,$f716 ; - Reset watchdog timer RTS RESET: LDI R0,#$01 ;reset camera STA R0,$f715


Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.