diff --git a/CHANGELOG.md b/CHANGELOG.md index 56e042b9..ba7d11d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ * Implemented `readline` and `readword` for VIC-20. +* `init_rand_seed` uses the POKEY on Atari. + * Fix: more instances of memset loops should be detected and optimized (#59). * Fix: things mentioned in the segment layout should not be deleted even if unused. diff --git a/docs/stdlib/other.md b/docs/stdlib/other.md index 6a3dfa42..f4900c89 100644 --- a/docs/stdlib/other.md +++ b/docs/stdlib/other.md @@ -32,6 +32,8 @@ Current implementation: * On C64, spends two frames reading noise data from the SID chip. +* On Atari computers, reads the POKEY random register. + * On Z80, reads the refresh register. * On all other targets, sets the seed to 1. diff --git a/include/m6502/random_6502.mfk b/include/m6502/random_6502.mfk index 4783d33a..b6737263 100644 --- a/include/m6502/random_6502.mfk +++ b/include/m6502/random_6502.mfk @@ -33,6 +33,21 @@ void init_rand_seed() { rand_seed.lo = peek($D41B) } +#elseif ATARI_8 + +noinline asm void init_rand_seed() { + lda $D20A + sta rand_seed.lo + lda #1 + .loop: + asl + bne .loop + lda $D20A + sta rand_seed.hi + rts +} + + #else inline void init_rand_seed() {