Nascom ROM BASIC Dis–Assembled

Part 7

```Dis-assembly of NASCOM ROM BASIC Ver 4.7                PAGE    91

FB8B CD13F8     RND:    CALL    TSTSGN          ; Test sign of FPREG
FB8E 211910             LD      HL,SEED+2       ; Random number seed
FB91 FAECFB             JP      M,RESEED        ; Negative - Re-seed
FB94 213A10             LD      HL,LSTRND       ; Last random number
FB97 CD51F8             CALL    PHLTFP          ; Move last RND to FPREG
FB9A 211910             LD      HL,SEED+2       ; Random number seed
FB9D C8                 RET     Z               ; Return if RND(0)
FB9F E607               AND     00000111B       ; 0 to 7
FBA1 0600               LD      B,0
FBA3 77                 LD      (HL),A          ; Re-save seed
FBA4 23                 INC     HL              ; Move to coefficient table
FBA5 87                 ADD     A,A             ; 4 bytes
FBA6 87                 ADD     A,A             ; per entry
FBA7 4F                 LD      C,A             ; BC = Offset into table
FBA8 09                 ADD     HL,BC           ; Point to coefficient
FBA9 CD62F8             CALL    LOADFP          ; Coefficient to BCDE
FBAC CD08F7             CALL    FPMULT          ; Multiply FPREG by coefficient
FBAF 3A1810             LD      A,(SEED+1)      ; Get (SEED+1)
FBB2 3C                 INC     A               ; Add 1
FBB3 E603               AND     00000011B       ; 0 to 3
FBB5 0600               LD      B,0
FBB7 FE01               CP      1               ; Is it zero?
FBB9 88                 ADC     A,B             ; Yes - Make it 1
FBBA 321810             LD      (SEED+1),A      ; Re-save seed
FBBD 21F0FB             LD      HL,RNDTAB-4     ; Addition table
FBC0 87                 ADD     A,A             ; 4 bytes
FBC1 87                 ADD     A,A             ; per entry
FBC2 4F                 LD      C,A             ; BC = Offset into table
FBC3 09                 ADD     HL,BC           ; Point to value
FBC7 CD5FF8     RND1:   CALL    BCDEFP          ; Move FPREG to BCDE
FBCA 7B                 LD      A,E             ; Get LSB
FBCB 59                 LD      E,C             ; LSB = MSB
FBCC EE4F               XOR     01001111B       ; Fiddle around
FBCE 4F                 LD      C,A             ; New MSB
FBCF 3680               LD      (HL),80H        ; Set exponent
FBD1 2B                 DEC     HL              ; Point to MSB
FBD2 46                 LD      B,(HL)          ; Get MSB
FBD3 3680               LD      (HL),80H        ; Make value -0.5
FBD5 211710             LD      HL,SEED         ; Random number seed
FBD8 34                 INC     (HL)            ; Count seed
FBD9 7E                 LD      A,(HL)          ; Get seed
FBDA D6AB               SUB     171             ; Do it modulo 171
FBDC C2E3FB             JP      NZ,RND2         ; Non-zero - Ok
FBDF 77                 LD      (HL),A          ; Zero seed
FBE0 0C                 INC     C               ; Fillde about
FBE1 15                 DEC     D               ; with the
FBE2 1C                 INC     E               ; number
FBE3 CD1EF6     RND2:   CALL    BNORM           ; Normalise number
FBE6 213A10             LD      HL,LSTRND       ; Save random number
FBE9 C36BF8             JP      FPTHL           ; Move FPREG to last and return
```

Go to part 6 of NASCOM ROM BASIC dis-assembled.

NASCOM ROM BASIC dis-assembled is available in ASM and LST file format.