home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol090 / systest5.mac < prev    next >
Encoding:
Text File  |  1984-04-29  |  1.8 KB  |  99 lines

  1. ;
  2. ;  PROGRAM:  SYSTEST5
  3. ;  AUTHOR:  Richard Conn
  4. ;  PURPOSE:  This program obtains a seed value and then generates
  5. ;        10 random numbers
  6. ;
  7.  
  8. ;
  9. ;  Externals
  10. ;
  11.     ext    cin    ; char in
  12.     ext    cout    ; char out
  13.     ext    print    ; print string
  14.     ext    rndinit    ; init random number generator by keypress
  15.     ext    rnd    ; return random number
  16.     ext    rndseed    ; init random number generator by user seed
  17.     ext    crlf    ; new line
  18.     ext    padc    ; print A as up to 3 decimal digits
  19.     ext    caps    ; capitalize char
  20.     ext    bbline    ; get line from user
  21.     ext    eval    ; evaulate string
  22.  
  23. ;
  24. ;  Constants
  25. ;
  26. cr    equ    0dh
  27. lf    equ    0ah
  28.  
  29.     call    print
  30.     db    'SYSTEST5 - Random Number Demo',0
  31.  
  32. ;
  33. ;  Start of main loop, which generates 10 random numbers each time it is
  34. ;  executed.
  35. ;
  36. start:
  37.  
  38. ;
  39. ;  Prompt user to see if he wants to select his own seed
  40. ;
  41.     call    print
  42.     db    cr,lf,'Do you want to pick your own seed (Y/N)? ',0
  43.     call    cin    ; get single-char response from user
  44.     call    caps
  45.     call    cout
  46.     cpi    'N'
  47.     jz    rseed
  48.  
  49. ;
  50. ;  Input a seed value from the user.
  51. ;
  52.     call    print
  53.     db    cr,lf,'What is your seed value? ',0
  54.     xra    a    ; no caps
  55.     call    bbline    ; get string
  56.     call    eval    ; evaluate string and return value in HL and A=L
  57.     call    rndseed    ; set seed from 8-bit value in A
  58.     call    print    ; print seed stored
  59.     db    cr,lf,'Your seed is: ',0
  60.     call    padc
  61.     jmp    rseed1
  62.  
  63. ;
  64. ;  Prompt user and wait for keypress to set seed.
  65. ;
  66. rseed:
  67.     call    print
  68.     db    cr,lf,'Wait a little and then press a key to set the seed - ',0
  69.     call    rndinit
  70.  
  71. ;
  72. ;  Generate 10 random numbers
  73. ;
  74. rseed1:
  75.     call    print
  76.     db    cr,lf,'10 Random Numbers follow --',cr,lf,0
  77.     mvi    b,10    ; 10 numbers
  78. loop:
  79.     call    rnd    ; get number
  80.     call    padc    ; print it as decimal
  81.     mvi    a,' '    ; print <SP>
  82.     call    cout
  83.     dcr    b    ; count down
  84.     jnz    loop
  85.  
  86. ;
  87. ;  Prompt user to continue
  88. ;
  89.     call    print
  90.     db    cr,lf,'Do you want to run this test again (Y/N)? ',0
  91.     call    cin    ; get response
  92.     call    caps
  93.     call    cout
  94.     cpi    'N'
  95.     jnz    start
  96.     ret        ; return to OS if done
  97.  
  98.     end
  99.