started work on pseudorandom number generator
This commit is contained in:
1 parent
5d887217df
commit
103325cc53
4 files changed
+70
-1
No files matched your search
@@ -237,6 +237,7 @@ Floating point mathematical routines - not official, but well known and broadly
|
||||
| `$BFED` | `exp_FAC1` | NOT DONE | |
|
||||
| `$E043` | `poly1_FAC1` | NOT DONE | |
|
||||
| `$E059` | `poly2_FAC1` | NOT DONE | |
|
||||
| `$E0BE` | `rnd_generate` | DONE | |
|
||||
| `$E264` | `cos_FAC1` | NOT DONE | |
|
||||
| `$E26B` | `sin_FAC1` | NOT DONE | |
|
||||
| `$E2B4` | `tan_FAC1` | NOT DONE | |
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
.label FBUFPT = $71 // $71-$72 -- NOT IMPLEMENTED --
|
||||
.label CHRGET = $73 // $73-$8A -- NOT IMPLEMENTED --
|
||||
.label TXTPTR = $7A // $7A-$7B current BASIC statement pointer
|
||||
.label RNDX = $8B // $8B-$8F -- NOT IMPLEMENTED --
|
||||
.label RNDX = $8B // $8B-$8F random number seed
|
||||
|
||||
//
|
||||
// Page 0 - Kernal area ($90-$FF)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
This is an important floating point math routine, see:
|
||||
|
||||
- https://www.atarimagazines.com/compute/issue72/random_numbers.php
|
||||
|
||||
XXX - try to find real-life example
|
||||
@@ -0,0 +1,63 @@
|
||||
// #LAYOUT# STD * #TAKE
|
||||
// #LAYOUT# * BASIC_0 #TAKE
|
||||
// #LAYOUT# * * #IGNORE
|
||||
|
||||
//
|
||||
// A fast random generator, idea from:
|
||||
// - https://codebase64.org/doku.php?id=base:32bit_galois_lfsr
|
||||
//
|
||||
// Output:
|
||||
// - FAC1
|
||||
//
|
||||
// See also:
|
||||
// - https://www.atarimagazines.com/compute/issue72/random_numbers.php
|
||||
//
|
||||
|
||||
rnd_generate:
|
||||
|
||||
// Generate new 4-byte random number
|
||||
|
||||
asl RNDX+1
|
||||
rol RNDX+2
|
||||
rol RNDX+3
|
||||
rol RNDX+4
|
||||
|
||||
bcs rnd_generate_copy
|
||||
|
||||
lda RNDX+1
|
||||
eor #$B7
|
||||
sta RNDX+1
|
||||
lda RNDX+2
|
||||
eor #$1D
|
||||
sta RNDX+2
|
||||
lda RNDX+3
|
||||
eor #$C1
|
||||
sta RNDX+3
|
||||
lda RNDX+4
|
||||
eor #$04
|
||||
sta RNDX+4
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
rnd_generate_copy:
|
||||
|
||||
// Copy the number to FAC1, order changed on purpose
|
||||
|
||||
lda RNDX+3
|
||||
sta FAC1_mantissa+0
|
||||
lda RNDX+1
|
||||
sta FAC1_mantissa+1
|
||||
lda RNDX+2
|
||||
sta FAC1_mantissa+2
|
||||
lda RNDX+4
|
||||
sta FAC1_mantissa+3
|
||||
|
||||
lda #$00
|
||||
sta FACOV
|
||||
sta FAC1_sign
|
||||
|
||||
lda #$80
|
||||
sta FAC1_exponent
|
||||
sta RNDX+0 // in case someone tries to use the float directly
|
||||
|
||||
jmp normal_FAC1
|
||||
Reference in new issue
Block a user