1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-11-01 05:05:32 +00:00
millfork/include/random_6502.mfk

43 lines
661 B
Plaintext
Raw Normal View History

import random
#if not(ARCH_6502)
#warn random_6502 module should be only used on 6502-compatible targets
#endif
asm byte rand() {
? ldx #8
? lda rand_seed+0
__rand_loop:
asl
? rol rand_seed+1
bcc __no_eor
eor #$2D
__no_eor:
dex
bne __rand_loop
? sta rand_seed+0
? rts
}
2019-06-26 15:06:55 +00:00
#if CBM_64_COMPAT
void init_rand_seed() {
poke($D40E, $ff)
poke($D40F, $ff)
poke($D412, $80)
while vic_raster != $70 {}
rand_seed.hi = peek($D41B)
while vic_raster != $40 {}
rand_seed.lo = peek($D41B)
}
#else
inline void init_rand_seed() {
// TODO: find a better source of randomness
rand_seed = 1
}
#endif