1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-11-01 05:05:32 +00:00
millfork/include/random_i80.mfk
Karol Stasiak 75e572f58c Library improvements:
– random module
– ensure_mixedcase() function
2018-12-30 18:59:32 +01:00

47 lines
651 B
Plaintext

import random
#if not(ARCH_I80)
#warn stdlib_i80 module should be only used on Intel 8080-like targets
#endif
#pragma zilog_syntax
asm byte rand() {
ld b,8
ld hl,(rand_seed)
__rand_loop:
add hl,hl
? jp nc, __no_eor
ld a,l
xor $2D
ld l,a
__no_eor:
#if CPUFEATURE_Z80
djnz __rand_loop
#else
dec b
? jp nz, __rand_loop
#endif
ld (rand_seed),hl
? ret
}
#if CPUFEATURE_Z80
inline asm void init_rand_seed() {
ld a,r
ld (rand_seed), a
ld a,r
ld (rand_seed+1), a
? ret
}
#else
inline void init_rand_seed() {
// TODO: find a better source of randomness
rand_seed = 1
}
#endif