c128lib Framework
A Commodore 128 software framework for enabling high-level development of C128 programs.
Loading...
Searching...
No Matches
random.asm File Reference

Namespaces

namespace  Random
 Random number generator module.
 

Functions

macro PseudoRandom ()
 This macro generates a pseudo-random number.
 
macro InitSid ()
 
macro GetRandomNumberFromSid ()
 

Function Documentation

◆ PseudoRandom()

macro PseudoRandom ( )

This macro generates a pseudo-random number.

The macro uses the Linear Feedback Shift Register (LFSR) method to generate a pseudo-random number. It is guaranteed to create a sequence touching every element from 0 to $ff just once. Seed must be provided in accumulator and can be from 0 to $ff. Output number will be available in the accumulator. It performs an arithmetic shift left (ASL) on the accumulator. If the result is zero or if the carry flag is set, it skips the exclusive OR (EOR) operation. Otherwise, it performs the EOR operation with the hexadecimal value 0x1D.

Note
The generated pseudo-random number is stored in the accumulator (.A register).
Remarks
Register .A must contain seed and will contain pseudo random number generated. Flags N, Z and C will be affected.
Use c128lib_PseudoRandom in random-global.asm
Since
0.1.0

◆ InitSid()

macro InitSid ( )

Init random number generator based on the Sid chip. When used, voice 3 of Sid chip can't be used for playback sounds.

Remarks
Register .A will be changed. Flags N and Z will be affected.
See also
GetRandomNumberFromSid
Note
Use c128lib_InitSid in random-global.asm
Since
0.1.0

◆ GetRandomNumberFromSid()

macro GetRandomNumberFromSid ( )

Get a new random number from the Sid chip and puts it into the .A register. Random numbers are continuously generated so each call gives a new random number. Generetor must be initialized with InitSid().

Remarks
Register .A will be changed. Flags N and Z will be affected.
See also
InitSid
Note
Use c128lib_GetRandomNumberFromSid in random-global.asm
Since
0.1.0