Skip to content

Commit fee2a34

Browse files
committed
Added PseudoRandom
1 parent 27e17ba commit fee2a34

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

lib/random-global.asm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "random.asm"
2+
#importonce
3+
.filenamespace c128lib
4+
5+
.macro @c128lib_PseudoRandom() { PseudoRandom() }

lib/random.asm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* c128lib (c) 2023
3+
* https://github.com/c128lib/framework
4+
*/
5+
6+
// #import "chipset/lib/vic2.asm"
7+
8+
#importonce
9+
.filenamespace c128lib
10+
11+
.namespace Random {
12+
}
13+
14+
/*
15+
Generates a random number starting from a given seed.
16+
It's not a real random number generator but generates
17+
a pseudo random number. By passing the same seed, it will
18+
generate always the same number. It is guaranteed to create a
19+
sequence touching every element just once.
20+
Seed must be provided in accumulator and can be from 0 to $ff.
21+
Output number will be available in the accumulator.
22+
23+
Params:
24+
.A - Seed
25+
26+
*/
27+
.macro PseudoRandom() {
28+
beq doEor
29+
asl
30+
beq noEor
31+
bcc noEor
32+
doEor:
33+
eor #$1d
34+
noEor:
35+
}

0 commit comments

Comments
 (0)