Random Routine in assembler.

By CrazyBoss

Master (209)

Аватар пользователя CrazyBoss

19-07-2012, 21:45

I try to make a random routine in assembler, but its not so random. Any better ideas ?
random: push bc
ld a,r
and %00001111
sla a
sla a
sla a
sla a
ld b,a
ld a,r
and %00001111
add a,b
pop bc
ret

//CLAUS

Для того, чтобы оставить комментарий, необходимо регистрация или !login

By Creepy

Champion (331)

Аватар пользователя Creepy

19-07-2012, 22:14

GETRNG:
        LD    A,(R_SEED)
        AND   0xB8
        SCF
        JP    PO,NO_CLR
        CCF
NO_CLR:
        LD    A,(R_SEED)
        RLA
        LD    (R_SEED),A
        RET

And fill R_SEED just once somewhere with something like r, JIFFY, or something else time based. Not my code btw, I found it somewhere on the net including an explanation, but I dont remember where I found it Found it: http://mycorner.no-ip.org/z80/prng/index.html

Or see here: http://www.msx.org/forum/development/msx-development/example...

By CrazyBoss

Master (209)

Аватар пользователя CrazyBoss

20-07-2012, 23:35

Thanks. I am using the routine in a Telebunnie port for Memotech MTX. Since the original MSX code use ld a,r to generate a "random" number, but at MSX ld a,r gives a 7bit number (bit number 7 always reset), but at Memotech MTX ld a,r can give a 8bit number, so need to put a res 7,a in the code too.

//CB