Post by Malban on Sept 29, 2017 16:37:24 GMT -5
I had a look at the Random() BIOS function ... is that one of the worst pieces of software written or am I totally blind today?
edit: I WAS BLIND - SEE BELOW ANSWERS!
Not only that "LDX Vec_Seed_Ptr" is dangerous [in combination with the indexed roling] (as mentioned by Kristoff Tuts) ... what does this roling accomplish?
Can the whole "Random" function above not be reduced to:
Or am I totally blind? The other random seeds are playfull - but ultimately "A" is only loaded with seed 0 and that one is in no way influenced by any other seed...
Malban
edit: I WAS BLIND - SEE BELOW ANSWERS!
;-----------------------------------------------------------------------;
; F511 Random_3 ;
; F517 Random ;
; ;
; This routine generates a random 1-byte number, and places it in the ;
; A register. Random_3 runs through the random number generator ;
; algorithm three times. The random number seed is stored in the ;
; three bytes pointed to by $C87B. ;
; ;
; EXIT: A-reg contains the generated random number ;
; ;
; All other registers are preserved. ;
;-----------------------------------------------------------------------;
Random_3: PSHS B,X
LDB #$02
BRA LF51A
Random: PSHS B,X
CLRB
LF51A: LDX Vec_Seed_Ptr
LF51D: LDA 1,X
ROLA
ROLA
ROLA
ROLA
EORA 2,X
RORA
ROL ,X
ROL 1,X
ROL 2,X
DECB
BPL LF51D
LDA ,X
PULS B,X,PC
Not only that "LDX Vec_Seed_Ptr" is dangerous [in combination with the indexed roling] (as mentioned by Kristoff Tuts) ... what does this roling accomplish?
Can the whole "Random" function above not be reduced to:
Random:
LDA Vec_Seed_Ptr
ROLA
STA Vec_Seed_Ptr
RTS
Ok - or doing that 3 times...Or am I totally blind? The other random seeds are playfull - but ultimately "A" is only loaded with seed 0 and that one is in no way influenced by any other seed...
Malban