Random number generator

  push de
  push hl
    ; Get stored value
    ld hl, (RNGState)
    ; Multiply by 3
    ld d, h
    ld e, l
    add hl, de
    add hl, de
    ; add low byte to high
    ld a, e
    add a, h
    ld h, a
    ; set high byte to that
    ld (RNGState), hl
    ; add controller state derived value
    ld hl, RNG_ControllerEntropy
    add a, (hl)
  pop hl
  pop de

RNGState is a 16-bit value, seeded with $55aa initially. RNG_ControllerEntropy seems to be a sum of all controller inputs since the start of the game. This function therefore gives some user-influenced random data.

Return to top