home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / RN.AZM / RN.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  9.3 KB  |  435 lines

  1. ;----------------------------------------------------------------
  2. ; This program tests the random number generator.
  3. ; Two tests are performed.
  4. ;
  5. ; The first test is on 8 bit numbers and uses the 8 bit output to
  6. ; increment elements in a 256 array table of 16 bit words. Each time
  7. ; a number occurs, the number is incremented. This then gives a diaplay
  8. ; of the number of occurrences that each number occurs.
  9. ;
  10. ; The second test uses a 16 bit random number divided by 256 to
  11. ; increment a 256 element table. This allows the user to see how
  12. ; many times a number occurs within a RANGE of numbers. 
  13. ;
  14. ;            Written        R.C.H.        30/11/83
  15. ;            Last Update    R.C.H.          05/01/84
  16. ;----------------------------------------------------------------
  17. ;
  18.     extrn    prolog,nibasc,pdacc,lzb,dispatch,inline
  19.     extrn    quit,coe,cie,caps,loe,listout,consout,crlf,blzb
  20.     extrn    pdde,randinit,rand8,rand16,pmenu,flushloe,cleol,cleop
  21.     extrn    cst,clear,bell,cursor,curoff,curon,xyinline
  22. ;
  23.     maclib    z80
  24. ;
  25.     call    prolog
  26.     call    blzb
  27. start:
  28.     call    clear
  29.     lxi    d,disp
  30.     call    pmenu
  31. start1:
  32.     call    cie
  33.     call    caps
  34.     cpi    '1'
  35.     jz    test$08
  36.     cpi    '2'
  37.     jz    test$16
  38.     cpi    'Q'
  39.     jz    quit
  40.     jrnz    start
  41. ;
  42. ;----------------------------------------------------------------
  43. ; 16 bit random number test. This must ....
  44. ; clear table of 256 elements
  45. ; do while console input not = Q or E
  46. ;    get a random number
  47. ;    increment table element
  48. ;    if modulus(1000) tests then display on screen
  49. ;    if console input = 'P' then send to printer
  50. ;  if console input = 'E' then restart the test
  51. ;  if console input = 'Q' then goto quit = CP/M
  52. ;----------------------------------------------------------------
  53. ;
  54. test$16:
  55.     call    clear
  56.     call    clear$table
  57.     lxi    d,seed
  58.     call    randinit
  59. ;
  60.     lxi    h,0
  61.     shld    counts            ; clear the loop counter
  62.     xra    a
  63.     sta    conchr
  64. ;
  65. mmenu16:    ; display main menu for 16 bit test
  66.     call    clear
  67.     lxi    d,menu
  68.     call    pmenu
  69. get16:    ; Get an option
  70.     call    cie
  71.     call    caps
  72.     sta    conchr
  73. ; Decode the option asked for.
  74. chk$chr$16:
  75.     lda    conchr            ; get any console characters
  76.     ora    a
  77.     jz    get16            ; re-start the loop
  78. chk$chr$17:
  79. ; Check the character
  80.     cpi    'Q'
  81.     jz    quit
  82.     cpi    'E'
  83.     jz    start
  84.     cpi    'W'
  85.     jz    wait$16
  86.     cpi    'P'
  87.     jz    print$16
  88.     cpi    'R'
  89.     jz    test$16
  90.     cpi    '?'                ; menu required again ?
  91.     jz    mmenu16
  92.     cpi    'B'
  93.     jz    do15                ; do the test now
  94.     cpi    'D'                ; display ?
  95.     jz    disp16
  96. ; Ell else is a miss-hit of the keyboard
  97.     call    bell
  98. ; clear the byte then return to main loop
  99.     xra    a
  100.     sta    conchr
  101. ; Here we call the action loop which performs the iterations. This continues 
  102. ;till a key is pressed after which we jump up to the checking routine.
  103. do15:
  104.     xra    a
  105.     sta    conchr
  106.     mvi    d,30            ; X = 30
  107.     mvi    e,23            ; y = 23, bottom line
  108.     call    cursor
  109.     call    cleol            ; clear to end of line
  110.     call    inline
  111.     db    'Thousands of iterations = $'
  112. do16:
  113.     call    t$16$4            ; call the routine
  114. ; Display the number of iterations
  115.     mvi    d,58
  116.     mvi    e,23
  117.     call    cursor            ; position for number display
  118.     lhld    counts
  119.     xchg
  120.     call    pdde            ; print as a decimal
  121. ; Check console status
  122.     lda    conchr            ; key pressed ?
  123.     ora    a
  124.     jrz    do16
  125.     jmp    chk$chr$17
  126. ;
  127. disp16:
  128.     xra    a
  129.     sta    conchr            ; clear console flag
  130.     call    clear
  131.     call    display
  132.     call    inline
  133.     db    '  Waiting $'
  134.     call    cie            ; wait for a key press
  135.     call    caps
  136.     cpi    'C'
  137.     jz    do15            ; restart with display full
  138.     jmp    mmenu16
  139. ;
  140. print$16:
  141. ; Here we print the display
  142.     call    listout
  143.     call    crlf                ; a little space
  144.     call    display
  145.     call    crlf
  146.     call    flushloe            ; flush the output
  147.     call    consout
  148.     jmp    mmenu16            ; got and display the menu
  149. ;
  150. wait$16:
  151.     call    cie
  152.     call    caps
  153.     sta    conchr
  154.     jmp    chk$chr$16 
  155. ;
  156. ;----------------------------------------------------------------
  157. ; Do 1000 iterations of incrementing the table.
  158. ;----------------------------------------------------------------
  159. ;
  160. t$16$4:
  161. ;
  162.     mvi    b,4            ; Minor loop counter
  163. t$16$250:
  164.     push    b            ; Save a major loop counter
  165.     mvi    b,250            ; Numbers
  166.     call    chk$con
  167. ;
  168. load$loop:
  169.     lxi    d,seed            ; point to the seed
  170.     call    rand16            ; Get a 16 bit number into hl
  171.     mov    e,h            ; put high byte into low byte
  172.     mvi    d,00            ; clear high byte
  173.     lxi    h,table            ; point to base of table
  174.     dad    d
  175.     dad    d            ; index into a 16 bit item in the table
  176. ; increment the table item
  177.     mov    d,m
  178.     inx    h
  179.     mov    e,m            ; get original table value
  180.     inx    d            ; Increment the count value
  181.     mov    m,e            ; write back
  182.     dcx    h
  183.     mov    m,d
  184.     djnz    load$loop        ; End of the 250 loop
  185. ;
  186.     pop    b
  187.     djnz    t$16$250        ; do the 250 loop 4 times
  188. ;
  189. ; After the loops, increment the number of loops.
  190.     lhld    counts
  191.     inx    h
  192.     shld    counts            ; bump the number of 1000 count loops
  193.     ret
  194. ;
  195. ;----------------------------------------------------------------
  196. ; ---- Do a very similar function for the 8 bit version ----
  197. ;----------------------------------------------------------------
  198. ;
  199. test$08:
  200.     call    clear
  201.     lxi    d,menu
  202.     call    pmenu
  203.     call    cie
  204. ;
  205.     call    clear
  206.     lxi    d,seed
  207.     call    randinit        ; set up generator
  208. ; Set up the table
  209.     call    clear$table        ; clear all of it to 00
  210.     lxi    h,0
  211.     shld    counts            ; clear the loop counter
  212. ;
  213.     xra    a
  214.     sta    conchr
  215. ;
  216. ; Do 1000 iterations of incrementing the table.
  217. ;
  218. t$08$4:
  219. ;
  220.     mvi    b,4            ; Minor loop counter
  221. t$08$250:
  222.     push    b            ; Save a major loop counter
  223.     mvi    b,250            ; Numbers
  224. ;
  225. load$loop$08:
  226.     call    chk$con
  227.     lxi    d,seed            ; point to the seed
  228.     call    rand8            ; Get a 16 bit number into hl
  229.     mov    e,a
  230.     mvi    d,00
  231.     lxi    h,table            ; point to base of table
  232.     dad    d
  233.     dad    d            ; index into a 16 bit item in the table
  234. ; increment the table item
  235.     mov    d,m
  236.     inx    h
  237.     mov    e,m            ; get original table value
  238.     inx    d            ; Increment the count value
  239.     mov    m,e            ; write back
  240.     dcx    h
  241.     mov    m,d
  242.     djnz    load$loop$08        ; End of the 250 loop
  243. ;
  244.     pop    b
  245.     djnz    t$08$250        ; do the 250 loop 4 times
  246. ;
  247. ; After the loops, we ned to display the values on the screen
  248. ; or on the printer as desired.
  249.     lhld    counts
  250.     inx    h
  251.     shld    counts            ; bump number of 1000 counts
  252. ;
  253.     call    display            ; show table as we go, every 1000
  254. chk$chr$08:
  255.     lda    conchr
  256.     ora    a
  257.     jz    t$08$4
  258. ; Check the character
  259.     cpi    'Q'
  260.     jz    quit
  261.     cpi    'E'
  262.     jz    start
  263.     cpi    'W'
  264.     jz    wait$08
  265.     cpi    'P'
  266.     jz    print$08
  267.     cpi    'R'
  268.     jz    test$08
  269.     cpi    '?'                ; menu required again ?
  270.     jz    menu$08
  271. ; All else is a miss-hit of the keyboard
  272.     call    bell
  273.     xra    a
  274.     sta    conchr
  275.     jmp    t$08$4
  276. ;
  277. ;
  278. print$08:
  279. ; Here we print the display
  280.     call    listout
  281.     call    crlf                ; a little space
  282.     call    display
  283.     call    crlf
  284.     call    flushloe            ; flush the output
  285.     call    consout
  286.     xra    a
  287.     sta    conchr
  288.     jmp    t$08$4                ; do next iteration then
  289. ;
  290. wait$08:
  291.     call    cie                ; get a character
  292.     call    caps
  293.     sta    conchr                ; save it
  294.     jmp    chk$chr$08             ; better check the character
  295. ;
  296. menu$08:
  297.     call    clear
  298.     lxi    d,menu
  299.     call    pmenu
  300.     call    cie
  301.     call    caps
  302.     sta    conchr
  303.     jmp    chk$chr$08
  304. ;
  305. ;
  306. ;----------------------------------------------------------------
  307. ; Display a screen of information which is a display of all the 
  308. ; boxes of the incremented counts.
  309. ;----------------------------------------------------------------
  310. ;
  311. display:
  312.     call    chk$con
  313.     xra    a
  314.     sta    pocket
  315.     lxi    d,01100h            ; column 17, line 0
  316.     call    cursor
  317.     call    inline
  318.     db    'Thousands of Iterations = $'
  319.     lhld    counts
  320.     xchg                    ; load counts into de
  321.     call    chk$con
  322.     call    pdde                ; print as a decimal
  323.     call    chk$con
  324.     call    crlf
  325. ; Now the data for the rest of the screen
  326.     lxi    h,table                ; start of table
  327.     mvi    b,21                ; 21 lines
  328.     mvi    c,12                ; elements to do in each line
  329. ;
  330. disp$loop:
  331.     call    chk$con
  332.     call    do$line
  333.     djnz    disp$loop
  334.     mvi    c,4
  335.     call    do$line
  336.     ret
  337. ;
  338. ; Diosplay (C) decimal 16 bit digits across the screen
  339. ;
  340. do$line:
  341.     push    b
  342.     push    d
  343.     mov    b,c                ; elements to be done
  344. ; Display the pocket number
  345.     call    crlf
  346.     call    chk$con
  347.     lda    pocket
  348.     call    pdacc                ; print the number
  349.     call    chk$con
  350.     call    inline
  351.     db    ' > $'
  352. ; Update the number then store back into memory
  353.     lda    pocket
  354.     add    c                ; add the number of pockets 
  355.     sta    pocket
  356. ;
  357. dol$loop:
  358.     call    chk$con
  359.     mov    d,m
  360.     inx    h
  361.     mov    e,m
  362.     inx    h                ; loaded 16 bits and updated
  363.     call    pdde
  364.     call    chk$con
  365.     mvi    a,' '
  366.     call    dispatch
  367.     djnz    dol$loop
  368. ; restore and return
  369.     pop    d
  370.     pop    b
  371.     ret
  372. ;
  373. ;
  374. ; Initialize the random number counter table to 00
  375. ;
  376. clear$table:
  377.     lxi    h,table
  378.     mvi    m,00
  379.     lxi    d,table + 1        ; Destination
  380.     lxi    b,511            ; elements
  381.     ldir                ; clear the table
  382.     ret
  383. ;
  384. ; Check the console for a character
  385. ;
  386. chk$con:
  387.     call    cst
  388.     rz
  389.     call    cie
  390.     call    caps
  391.     sta    conchr
  392.     ret
  393. ;
  394. ;----------------------------------------------------------------
  395. ;
  396. disp:
  397.     db    21,04,'Random Number Generator test$'
  398.     db    21,05,'----------------------------$'
  399.     db    21,07,'      Options are$'
  400.     db    21,08,'1) 8 Bit random number test$'
  401.     db    21,09,'2) 16 Bit random number test$'
  402.     db    21,10,'Q) Quit to CP/M$'
  403.     db    21,11,'?$'
  404.     db    0ffh
  405. ;
  406. menu:
  407.     db    21,04,'Random Number Generator test$'
  408.     db    21,05,'----------------------------$'
  409.     db    25,07,'Test options available are$'
  410.     db    21,09,'P = Send results to printer$'
  411.     db    21,10,'R = Restart the current test$'
  412.     db    21,11,'E = End the current test$'
  413.     db    21,12,'W = Wait for a key press$'
  414.     db    21,13,'B = Begin test iterations$'
  415.     db    21,14,'D = Display results$'
  416.     db    21,15,'? = Display this menu$'
  417.     db    21,16,'Q = Quit to CP/M$'
  418.     db    30,23,'Press a key to start$'
  419.     db    0ffh
  420. ;
  421. counts    db    00,00
  422. pocket    db    00,00
  423. conchr    db    00            ; console character
  424. ;
  425. ;
  426. seed:    db    7,143,7,8,11,98,179,90
  427. ;
  428. table    ds    511
  429.     db    00
  430. ;
  431. ;
  432.     end
  433. ;
  434.  
  435.