PM development, programming, hacking and all that fun stuff.
zoranc
Posts: 299 Joined: August 13th, 2010, 18:13
Contact:
Post
by zoranc » October 11th, 2022, 00:54
Just found a nice pseudo random number generator algorithm suitable for S1C88. It uses only 16 bit numbers and is very fast when implemented in assembly:
Code: Select all
uint16_t xs = 1; // initialised with a non-zero seed
xs ^= xs << 7
xs ^= xs >> 9
xs ^= xs << 8
Here is implementation for several processors including z80 which is very similar to S1C88:
https://github.com/impomatic/xorshift798
YasaSheep
Posts: 205 Joined: November 20th, 2005, 04:04
Location: Portland (Also the discord)
Contact:
Post
by YasaSheep » October 25th, 2022, 04:20
Nice! Here's a 36 cycle version in Epson syntax, best I could get:
Code: Select all
xorshift:
LD HL,#XSHFT
LD BA,[HL]
RR B
RR A
XOR [HL],A
LD BA,[HL]
RR B
XOR A,B
XOR [HL],A
INC HL
LD [HL],A
RET
xor is fairly limited (the only two register version is a,b) so I switched to xoring in memory where possible.