I need a source of random values between $00 and $0f. Initially, I found some simple LFSRs and tried them. However, the byte stream output masked down to 4 bits repeated too frequently to be useful. I tried tweaking the LFSR, but did not have much luck. I use the data to populate parts of the name-table with background tiles, so patterns emerge visually really quick.
I got frustrated and implemented the full RC4 byte-stream generator as my pseudo-random number generator. The result works BEAUTIFULLY. But it is probably overkill. It is probably the most hard-core random number generator ever implemented on a NES (well, it could be?)
If anyone wants the rc4 code, I'll post it when I have time. It is tweaked for my specific use and not for doing real encryption (although changing it to do crypto would not be difficult). I always thought that it would be neat to encrypt level data and in-game text in such a way that one can't just "skip ahead". That the key to decrypt this text is large and the result of the game's state machine at the successful completion of some game objective. So that level 2 map won't be available until level-1 is won, and level-3 requires level-2 and so on. I like rc4 for this because it is easy to implement in C and not too bad in hand-coded 6502 asm. However, it does require 258 bytes of state (2 bytes in ZP and an entire page at $0700).
I was doing some further research (ok, googling and blindly changing the xor polynomials) and found a post from 2001 on an Atari 2600 forum by kevtris:
http://www.biglist.com/lists/stella/arc ... 00121.html
Has anyone else had success with large-period (2^16-1 or greater) LFSRs and would be willing to share their wisdom?
My main concern is that while a 16-bit LSFR might have a period of 2^16-1, but the period of that LSFR mod $0010 would be smaller. I have not written any test code for this yet (beyond my one failed experiment).
I got frustrated and implemented the full RC4 byte-stream generator as my pseudo-random number generator. The result works BEAUTIFULLY. But it is probably overkill. It is probably the most hard-core random number generator ever implemented on a NES (well, it could be?)
If anyone wants the rc4 code, I'll post it when I have time. It is tweaked for my specific use and not for doing real encryption (although changing it to do crypto would not be difficult). I always thought that it would be neat to encrypt level data and in-game text in such a way that one can't just "skip ahead". That the key to decrypt this text is large and the result of the game's state machine at the successful completion of some game objective. So that level 2 map won't be available until level-1 is won, and level-3 requires level-2 and so on. I like rc4 for this because it is easy to implement in C and not too bad in hand-coded 6502 asm. However, it does require 258 bytes of state (2 bytes in ZP and an entire page at $0700).
I was doing some further research (ok, googling and blindly changing the xor polynomials) and found a post from 2001 on an Atari 2600 forum by kevtris:
http://www.biglist.com/lists/stella/arc ... 00121.html
Has anyone else had success with large-period (2^16-1 or greater) LFSRs and would be willing to share their wisdom?
My main concern is that while a 16-bit LSFR might have a period of 2^16-1, but the period of that LSFR mod $0010 would be smaller. I have not written any test code for this yet (beyond my one failed experiment).