home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol089 / syslibs.ws < prev    next >
Text File  |  1985-02-09  |  42KB  |  1,676 lines

  1. 21.0 Sample Programs Using SYSLIB
  2.  
  3. 21.01 The Classic File Dump Program
  4.  
  5. B>;  Demo of File Dump Program
  6.  
  7. B>type systest.mac
  8. ;
  9. ;  PROGRAM:  SYSTEST
  10. ;  AUTHOR:  Richard Conn
  11. ;  PURPOSE:  This program dumps the disk file specified by the user
  12. ;        in hexadecimal and ASCII
  13. ;  NOTE:  This test demonstrates the use of the SYSLIB Byte-Oriented
  14. ;        File Input routines
  15. ;
  16.  
  17. ;  External CP/M Buffers
  18. fcb    equ    5ch    ; address of FCB filled in by CP/M's CCP
  19.             ; (or ZCPR2)
  20.  
  21. ;  External References for SYSLIB routines used
  22.     ext    fi1$open    ; Open File for Byte-Oriented Input
  23.     ext    fi1$close    ; Close File
  24.     ext    f1$get        ; Get Byte from File
  25.     ext    cout        ; Character Output
  26.     ext    pa2hc        ; Print A as 2 Hex Chars
  27.     ext    phldc        ; Print HL as up to 5 decimal digits
  28.     ext    print        ; String Print
  29.     ext    crlf        ; New Line
  30.  
  31. ;
  32. ;  Start of Routine -- Print Banner
  33. ;
  34.     call    print
  35.     db    'SYSTEST - Sample DUMP Program to Illustrate SYSLIB '
  36.     db    'Byte-Oriented File Input'
  37.     db    0
  38.     call    crlf    ; new line
  39.  
  40. ;
  41. ;  Set Offset Counter
  42. ;
  43.     lxi    h,0    ; Init to zero
  44.     shld    counter
  45.  
  46. ;
  47. ;  Open File for Input
  48. ;
  49.     lxi    d,fcb    ; pt to FCB filled in by Operating System
  50.     call    fi1$open    ; try to open it
  51.     jz    loop    ; continue if OK
  52.     call    print    ; not ok, so file must not have been found
  53.     db    'File Not Found',0
  54.     ret        ; return to Operating System
  55. è;
  56. ;  Main Loop
  57. ;
  58. loop:
  59.     lhld    counter    ; get counter value
  60.     call    phldc    ; print as decimal number
  61.     lxi    d,16    ; add 16 to counter for next print
  62.     dad    d
  63.     shld    counter    ; save count away
  64.     call    print
  65.     db    ': ',0
  66.     mvi    b,0    ; set byte count to zero
  67.     lxi    h,buffer    ; point to first byte of buffer
  68. readlp:
  69.     call    f1$get    ; get next byte
  70.     jnz    readdn    ; done if past EOF
  71.     mov    m,a    ; store byte into buffer
  72.     inx    h    ; point to next byte in buffer
  73.     inr    b    ; increment byte count
  74.     mov    a,b    ; check for done
  75.     cpi    16    ; read in 16 bytes?
  76.     jnz    readlp
  77.     call    bufprint    ; print contents of buffer
  78.     call    crlf    ; new line
  79.     jmp    loop    ; continue until End of File
  80.  
  81. ;
  82. ;  Done with Read -- Print current Buffer and Exit
  83. ;  B = Number of bytes to print
  84. ;
  85. readdn:
  86.     call    bufprint    ; print buffer
  87.     call    crlf        ; new line
  88.     call    fi1$close    ; close file
  89.     ret
  90.  
  91. ;
  92. ;  Buffer print routine; print the contents of the buffer for B bytes
  93. ;
  94. bufprint:
  95.     lxi    h,buffer    ; point to first byte of buffer
  96.     push    b    ; save character count
  97. bufploop:
  98.     mov    a,b    ; check count first (in case it is zero)
  99.     ora    a    ; done?
  100.     jz    ascprint    ; print as ASCII chars if done
  101.     dcr    b    ; count down
  102.     mov    a,m    ; get byte from buffer
  103.     inx    h    ; point to next byte in buffer
  104.     call    pa2hc    ; print byte as 2 Hex chars
  105.     mvi    a,' '    ; print a space
  106.     call    cout
  107.     jmp    bufploop
  108. ;  Now print buffer as ASCII characters
  109. ascprint:è    lxi    h,buffer    ; point to first character
  110.     pop    b    ; get character count
  111.     call    print    ; print a separator
  112.     db    '! ',0
  113. ascploop:
  114.     mov    a,b    ; check for empty buffer
  115.     ora    a    ; done if zero
  116.     rz        ; return to caller if so
  117.     dcr    b    ; count down
  118.     mov    a,m    ; get byte to output
  119.     ani    7fh    ; mask out most significant bit
  120.     mov    c,a    ; save character in C
  121.     cpi    ' '    ; test for printable character
  122.     jnc    ascp    ; print character if printable
  123.     mvi    c,'.'    ; print dot if not printable character
  124. ascp:
  125.     mov    a,c    ; get char to print
  126.     call    cout    ; print it
  127.     inx    h    ; point to next character
  128.     jmp    ascploop    ; continue until count is exhausted
  129.  
  130. counter:
  131.     ds    2    ; Offset Counter
  132. buffer:
  133.     ds    16    ; 16-byte buffer for input bytes
  134.  
  135.     end
  136.  
  137.  
  138. B>; Now to assemble the file
  139. B>sub m80 systest
  140. SUB for ZCPR2, Version 2.0
  141. Process SUBMIT File
  142. Writing SUBMIT Execution File to Disk
  143. B$;  M80.SUB -- MACRO-80 ASSEMBLER AND LINKER
  144. B$M80 =SYSTEST
  145.  
  146. No  Fatal error(s)
  147.  
  148. B$SUB /A  PLEASE ABORT IF ERROR(S) EXIST
  149. SUB for ZCPR2, Version 2.0
  150. Abort SUBMIT File
  151. Do you wish to abort execution?
  152.   Enter A or ^C to Abort or anything else to continue -  
  153. Continuing Execution
  154. B$ERA SYSTEST.BAK
  155. No File
  156. B$ERA SYSTEST.COM
  157. SYSTEST .COM
  158. B$L80 /P:100,SYSTEST,A:SYSLIB/S,SYSTEST/N,/U,/E
  159.  
  160. Link-80  3.37  08-May-80  Copyright 1979,80 (C) Microsoft
  161.  
  162. Data    0100    0745
  163.  
  164.  
  165.  
  166. Data    0100    0745
  167.  
  168.  
  169. [0000   0745    7]
  170.  
  171. B$ERA SYSTEST.REL
  172. SYSTEST .REL
  173. B$;  ASSEMBLY COMPLETE
  174.  
  175.  
  176. B>;  Now to create a file to test the dump program on
  177. B>ed demo.txt
  178.  
  179. NEW FILE
  180.      : *i
  181.     1:  This is a very short demonstration file to test the operation
  182.     2:  of SYSTEST, whose function is to dump the contents of this
  183.     3:  file in hexadecimal and ascii.
  184.     4:  
  185.     5:  Bye for now.
  186.     6:  
  187.      : *e
  188.  
  189. B>type demo.txt
  190. This is a very short demonstration file to test the operation
  191. of SYSTEST, whose function is to dump the contents of this
  192. file in hexadecimal and ascii.
  193.  
  194. Bye for now.
  195.  
  196. B>;  Test the dump program
  197. B>systest demo.txt
  198. SYSTEST - Sample DUMP Program to Illustrate SYSLIB Byte-Oriented File Input
  199.     0: 54 68 69 73 20 69 73 20 61 20 76 65 72 79 20 73 ! This is a very s
  200.    16: 68 6F 72 74 20 64 65 6D 6F 6E 73 74 72 61 74 69 ! hort demonstrati
  201.    32: 6F 6E 20 66 69 6C 65 20 74 6F 20 74 65 73 74 20 ! on file to test 
  202.    48: 74 68 65 20 6F 70 65 72 61 74 69 6F 6E 0D 0A 6F ! the operation..o
  203.    64: 66 20 53 59 53 54 45 53 54 2C 20 77 68 6F 73 65 ! f SYSTEST, whose
  204.    80: 20 66 75 6E 63 74 69 6F 6E 20 69 73 20 74 6F 20 !  function is to 
  205.    96: 64 75 6D 70 20 74 68 65 20 63 6F 6E 74 65 6E 74 ! dump the content
  206.   112: 73 20 6F 66 20 74 68 69 73 20 66 69 6C 65 0D 0A ! s of this file..
  207.   128: 69 6E 20 68 65 78 61 64 65 63 69 6D 61 6C 20 61 ! in hexadecimal a
  208.   144: 6E 64 20 61 73 63 69 69 2E 0D 0A 0D 0A 42 79 65 ! nd ascii.....Bye
  209.   160: 20 66 6F 72 20 6E 6F 77 2E 0D 0A 1A 1A 1A 1A 1A !  for now........
  210.   176: 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A ! ................
  211.   192: 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A ! ................
  212.   208: 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A ! ................
  213.   224: 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A ! ................
  214.   240: 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A 1A ! ................
  215.   256: ! 
  216.  
  217.  
  218. 21.02 Byte-Oriented File Input Demonstration
  219.  
  220.  
  221. B>;  Demo of Byte-Oriented File Input
  222. B>type systest1.mac
  223. ;
  224. ;  PROGRAM:  SYSTEST1
  225. ;  AUTHOR:  Richard Conn
  226. ;  PURPOSE:  This program creates a file and then accepts lines
  227. ;        of text to input into that file.
  228. ;  NOTE:  This test illustrates the use of the byte-oriented file
  229. ;        output routines and the use of SYSLIB.
  230. ;
  231.  
  232. ;  Define the <CR> and <LF> constants
  233. cr    equ    0dh
  234. lf    equ    0ah
  235.  
  236. ;  External Definitions of Routines to be Used
  237.     ext    fname        ; Convert file name into FCB format
  238.     ext    print        ; Print string
  239.     ext    bbline        ; Input Line Editor
  240.     ext    fo0$open    ; Open File for Output
  241.     ext    fo0$close    ; Close File
  242.     ext    f0$put        ; Write Byte to File
  243.  
  244. ;
  245. ;  This part of the program prompts the user and inputs a line
  246. ;
  247.     call    print    ; print prompt to user
  248.     db    'SYSTEST1 - Byte-Oriented File Output Demonstration'
  249.     db    cr,lf,'Name of File to Create? ',0
  250.     xra    a    ; A=0 so BBLINE does not capitalize line
  251.     call    bbline    ; input file name from user
  252.     ora    a    ; check char count for zero
  253.     rz        ; return to CP/M if no line input
  254.  
  255. ;
  256. ;  The file name specified by the user is converted into the FCB
  257. ;  format and stored into an FCB
  258. ;
  259. ;  First char of filename is pointed to by HL, as returned by BBLINE
  260. ;
  261.     lxi    d,fcb    ; load fcb
  262.     call    fname
  263.  
  264. ;
  265. ;  Now we open the file for byte-oriented output; since FNAME does
  266. ;  not affect DE, DE still points to the FCB
  267. ;
  268.     call    fo0$open    ; open file for output
  269.     jz    loop    ; ok to proceed
  270.  
  271. ;è;  File could not be opened -- print error message and abort
  272. ;
  273.     call    print
  274.     db    cr,lf,'Cannot Open File -- Abort',0
  275.     ret
  276.  
  277. ;
  278. ;  This loop prompts the user for a line and stores it in the file.
  279. ;  If the user types an empty line (just <CR>), we exit and close the
  280. ;  output file.
  281. ;
  282. loop:
  283.     call    print    ; print prompt
  284.     db    cr,lf,'Input Line (<CR>=Done)? ',0
  285.     xra    a    ; A=0 so BBLINE does not capitalize line
  286.     call    bbline    ; get line from user
  287.     ora    a    ; check char count
  288.     jz    done    ; done if no chars
  289.  
  290. ;
  291. ;  This loop writes the string pted to by HL (from BBLINE) to disk.
  292. ;
  293. oloop:
  294.     mov    a,m    ; get char
  295.     ora    a    ; done if zero
  296.     jz    odone
  297.     call    f0$put    ; write to disk
  298.     jnz    derr    ; check for disk error
  299.     inx    h    ; pt to next char to output
  300.     jmp    oloop
  301.  
  302. ;
  303. ;  This routine terminates the string just written to disk with a
  304. ;  <CR> <LF> pair, and the creation of the file is continued.
  305. ;
  306. odone:
  307.     mvi    a,cr    ; new line
  308.     call    f0$put
  309.     mvi    a,lf
  310.     call    f0$put
  311.     jmp    loop
  312.  
  313. ;
  314. ;  The user has typed an empty line (just <CR>), so we close the file
  315. ;  and exit.
  316. ;
  317. done:
  318.     call    fo0$close    ; close file
  319.     ret
  320.  
  321.  
  322. ;
  323. ;  Error message and abort if error occurs while writing to disk.
  324. ;
  325. derr:
  326.     call    print
  327.     db    cr,lf,'Disk Output Error',0
  328.     ret
  329.  
  330. ;
  331. ;  FCB used by program
  332. ;
  333. fcb:
  334.     ds    36
  335.  
  336.     end
  337.  
  338. B>;  Assemble the Program
  339. B>sub m80 systest1
  340. SUB for ZCPR2, Version 2.0
  341. Process SUBMIT File
  342. Writing SUBMIT Execution File to Disk
  343. B$;  M80.SUB -- MACRO-80 ASSEMBLER AND LINKER
  344. B$M80 =SYSTEST1
  345.  
  346. No  Fatal error(s)
  347.  
  348. B$SUB /A  PLEASE ABORT IF ERROR(S) EXIST
  349. SUB for ZCPR2, Version 2.0
  350. Abort SUBMIT File
  351. Do you wish to abort execution?
  352.   Enter A or ^C to Abort or anything else to continue -  
  353. Continuing Execution
  354. B$ERA SYSTEST1.BAK
  355. No File
  356. B$ERA SYSTEST1.COM
  357. SYSTEST1.COM
  358. B$L80 /P:100,SYSTEST1,A:SYSLIB/S,SYSTEST1/N,/U,/E
  359.  
  360. Link-80  3.37  08-May-80  Copyright 1979,80 (C) Microsoft
  361.  
  362. Data    0100    08E1
  363.  
  364.  
  365.  
  366. Data    0100    08E1
  367.  
  368.  
  369. [0000   08E1    8]
  370.  
  371. B$ERA SYSTEST1.REL
  372. SYSTEST1.REL
  373. B$;  ASSEMBLY COMPLETE
  374.  
  375. B>era demo.txt
  376. DEMO    .TXT
  377. B>systest1
  378. SYSTEST1 - Byte-Oriented File Output Demonstration
  379. Name of File to Create? demo.txt
  380. Input Line (<CR>=Done)? This is a test
  381. Input Line (<CR>=Done)? This is only a test
  382. Input Line (<CR>=Done)? Bye for now
  383. Input Line (<CR>=Done)? 
  384. B>type demo.txt
  385. This is a test
  386. This is only a test
  387. Bye for now
  388.  
  389.  
  390. 21.03 Directory Access Demonstration
  391.  
  392.  
  393. B>;  Demo of Directory Routines in SYSLIB
  394. B>type systest2.mac
  395. ;
  396. ;  PROGRAM:  SYSTEST2
  397. ;  AUTHOR:  Richard Conn
  398. ;  PURPOSE:  To demonstrate the SYSLIB routines for directory
  399. ;              manipulation.
  400. ;  NOTE:  This program loads the disk directory and selects and
  401. ;              prints files which match the ambiguous file spec
  402. ;              given by the user
  403. ;
  404.  
  405. ;
  406. ;  Externals
  407. ;
  408.     ext    dirf    ; Fast Directory Load/Select/Alpha/Pack
  409.     ext    print    ; Print String
  410.     ext    cout    ; Char out
  411.     ext    crlf    ; New Line
  412.     ext    retud    ; Return User and Disk
  413.     ext    codend    ; End of Code/Beginning of Buffer
  414.  
  415. ;
  416. ;  CP/M Equates
  417. ;
  418. fcb    equ    5ch    ; address of FCB loaded by CP/M
  419. cr    equ    0dh
  420. lf    equ    0ah
  421.  
  422. ;
  423. ;  I would normally look at the FCB to see if any file was specified
  424. ;  and make it wild (all ?'s) if so, but I won't do this so we can
  425. ;  get right to the problem at hand.  Hence, if the user simply
  426. ;  types SYSTEST2 as his command, the FCB will be all spaces and
  427. ;  no file will match it.
  428. ;
  429.     call    print
  430.     db    'SYSTEST2 - Demo of Directory Routines in SYSLIB'
  431.         db      cr,lf,0
  432.     call    codend    ; get buffer address in HL
  433.     lxi    d,fcb    ; pt to fcb in DE
  434.     call    retud    ; get user number in C
  435.     mov    a,c    ; user number in A
  436.     ori    10000000b    ; Mask in MSB so only Non-System
  437.                         ; files selected
  438.     call    dirf    ; load dir/select files/alphabetize/pack
  439.  
  440.  
  441. ;
  442. ;  We now have a set of fixed-length records in memory, the first
  443. ;  one being pointed to by HL.  The number of records is in BC,
  444. ;  and the length of each record is 16 bytes.  These are the first
  445. ;  16 bytes of the FCBs of all files which matched the files we
  446. ;  were looking for.
  447. ;
  448. ;  I will now print out these file names horizontally across the
  449. ;  screen.
  450. ;
  451.     mvi    d,0    ; set 4 count (new line every 4 entries)
  452.     mov    a,b    ; any file names?
  453.     ora    c    ; zero if so
  454.     jnz    loop    ; continue if any names
  455.     call    print
  456.     db    cr,lf,'No Files Match Ambiguous File Name',0
  457.     ret        ; return to OS
  458.  
  459. ;
  460. ;  This is the main loop to print the matching file names.
  461. ;
  462. loop:
  463.     push    d    ; save 4-count in D
  464.     call    prfile    ; print file name (HL, BC not affected)
  465.     lxi    d,16    ; point to next file name by adding 16 to HL
  466.     dad    d
  467.     pop    d    ; get 4-count in D
  468.     inr    d    ; add 1 to 4-count
  469.     mov    a,d    ; check to see if it is a 4 multiple
  470.     ani    3    ; zero if so
  471.     cz    crlf    ; ... and new line
  472.     dcx    b    ; count down
  473.     mov    a,b
  474.     ora    c
  475.     jnz    loop
  476.     ret        ; return to Operating System when done
  477.  
  478.  
  479. ;
  480. ;  Print file name whose FCB is pointed to by HL.  Do not affect
  481. ;  HL or BC.
  482. ;
  483. prfile:
  484.     push    b    ; save regs
  485.     push    h
  486.     inx    h    ; pt to first char of file name
  487.     mvi    b,8    ; print 8 bytes
  488.     call    prch    ; my routine to do this (not in SYSLIB)
  489.     mvi    a,'.'    ; print dot
  490.     call    cout
  491.     mvi    b,3    ; print 3 bytes
  492.     call    prch
  493.     call    print
  494.     db    '  !  ',0    ; print name separator
  495.     pop    h    ; restore regs
  496.     pop    b
  497.     ret
  498.  
  499. ;
  500. ;  Print B chars pointed to by HL
  501. ;
  502. prch:
  503.     mov    a,m    ; get char
  504.     inx    h    ; pt to next
  505.     call    cout    ; print char
  506.     dcr    b    ; count down
  507.     jnz    prch
  508.     ret
  509.  
  510.     end
  511.  
  512.  
  513. B>;  Assemble the Program
  514. B>sub m80 systest2
  515. SUB for ZCPR2, Version 2.0
  516. Process SUBMIT File
  517. Writing SUBMIT Execution File to Disk
  518. B$;  M80.SUB -- MACRO-80 ASSEMBLER AND LINKER
  519. B$M80 =SYSTEST2
  520.  
  521. No  Fatal error(s)
  522.  
  523. B$SUB /A  PLEASE ABORT IF ERROR(S) EXIST
  524. SUB for ZCPR2, Version 2.0
  525. Abort SUBMIT File
  526. Do you wish to abort execution?
  527.   Enter A or ^C to Abort or anything else to continue -  
  528. Continuing Execution
  529. B$ERA SYSTEST2.BAK
  530. No File
  531. B$ERA SYSTEST2.COM
  532. SYSTEST2.COM
  533. B$L80 /P:100,SYSTEST2,A:SYSLIB/S,SYSTEST2/N,/U,/E
  534.  
  535. Link-80  3.37  08-May-80  Copyright 1979,80 (C) Microsoft
  536.  
  537. Data    0100    0867
  538.  
  539.  
  540.  
  541. Data    0100    0867
  542.  
  543.  
  544. [0000   0867    8]
  545.  
  546. B$ERA SYSTEST2.REL
  547. SYSTEST2.REL
  548. B$;  ASSEMBLY COMPLETE
  549.  
  550. B>era demo.txt
  551. DEMO    .TXT
  552. B>;  Display files so the reader can see what files are on disk
  553. B>;  NOTE:  I select all files that do NOT match *.COM in Non-Sys
  554. B>xdir *.com /n
  555. XDIR III, Version 1.2    Vertical Listing by File Type and Name
  556.  Disk: B  User:   0, File Attributes:  Non-System
  557.  
  558. Filename.Typ Size K RS   Filename.Typ Size K RS   Filename.Typ Size K RS
  559. -------- --- ------ --   -------- --- ------ --   -------- --- ------ --
  560.  DD0    .-40      0 R    MLONGINT.MAC     10      SYSTEST3.MAC      4      
  561. FNDFILE .ASM      4      SYSTEST .MAC      4      SYSTEST4.MAC      6      
  562. MCHECK  .ASM     12      SYSTEST1.MAC      4      SYSTEST5.MAC      2      
  563. LU      .DOC     24      SYSTEST2.MAC      4      SYSTEST6.MAC      6      
  564. MCOPY   .MAC     22      
  565.    13 Files Occupying   102K,    26 Files on Disk and   426K Free
  566.  
  567. B>systest2
  568. SYSTEST2 - Demo of Directory Routines in SYSLIB
  569.  
  570. No Files Match Ambiguous File Name
  571. B>systest2 *.mac
  572. SYSTEST2 - Demo of Directory Routines in SYSLIB
  573. MCOPY   .MAC  !  MLONGINT.MAC  !  SYSTEST .MAC  !  SYSTEST1.MAC  !  
  574. SYSTEST2.MAC  !  SYSTEST3.MAC  !  SYSTEST4.MAC  !  SYSTEST5.MAC  !  
  575. SYSTEST6.MAC  !  
  576. B>systest2 *.asm
  577. SYSTEST2 - Demo of Directory Routines in SYSLIB
  578. FNDFILE .ASM  !  MCHECK  .ASM  !  
  579.  
  580.  
  581.  
  582. 21.04 Math Demonstration
  583.  
  584.  
  585. B>;  Demo of Evaluation and Math Routines
  586. B>type systest3.mac
  587. ;
  588. ;  PROGRAM:  SYSTEST3
  589. ;  AUTHOR:  Richard Conn
  590. ;  PURPOSE:  This program demonstrates the EVAL routines and the
  591. ;        Math routines within SYSLIB
  592. ;
  593.  
  594. ;
  595. ;  Externals
  596. ;
  597.     EXT    ADDHD    ; HL = HL + DE
  598.     EXT    SUBHD    ; HL = HL - DE
  599.     EXT    NEGH    ; HL = NEGATE OF HL
  600.     EXT    MULHD    ; HL = HL * DE
  601.     EXT    DIVHD    ; HL = HL / DE
  602.     EXT    ANDHD    ; HL = HL AND DE
  603.     EXT    ORHD    ; HL = HL OR DE
  604.     EXT    XORHD    ; HL = HL XOR DE
  605.     EXT    SHFTRH    ; HL = HL shifted right one bit position
  606.     EXT    SHFTLH    ; HL = HL shifted left one bit position
  607.     EXT    ROTRH    ; HL = HL rotated right one bit position
  608.     EXT    ROTLH    ; HL = HL rotated left one bit position
  609.  
  610.     EXT    PRINT    ; Print String
  611.     EXT    BBLINE    ; Input Line Editor
  612.     EXT    EVAL    ; Number Evaluator
  613.     EXT    PHLDC    ; Print HL as up to 5 decimal chars
  614.     EXT    PHL4HC    ; Print HL as 4 Hex chars
  615.  
  616. ;
  617. ;  ASCII Char defns
  618. ;
  619. cr    equ    0dh
  620. lf    equ    0ah
  621.  
  622. ;
  623. ;  Print Banner
  624. ;
  625.     call    print
  626.     db    'SYSTEST3 -- Math Routines and Evaluation Demo',0
  627.  
  628.  
  629. ;
  630. ;  This is the main loop and a prompt to the user.
  631. ;
  632. loop:
  633.     call    print
  634.     db    cr,lf,'Input Two Numbers, Separated by a Comma '
  635.         db      '(<CR> to Stop) -- ',0
  636.     call    bbline    ; get user input
  637.     ora    a    ; no input if A=0
  638.     rz        ; return to Operating System
  639.     call    eval    ; evaluate the first number (pted to by HL)
  640.     xchg        ; place number in HL
  641.     shld    num1    ; save it away as 1st number
  642.     xchg        ; restore ptr to comma after number in HL
  643.     inx    h    ; skip comma
  644.     call    eval    ; evaluate the 2nd number (returned in DE)
  645.  
  646. ;
  647. ;  Through the rest of this loop, DE contains the 2nd number.
  648. ;  Note that none of the routines affect it.
  649. ;
  650.     call    print
  651.     db    cr,lf,'First Number is ',0
  652.     lhld    num1    ; get and print first number
  653.     call    phldc    ; print in decimal
  654.     call    print
  655.     db    ' in Decimal or ',0
  656.     call    phl4hc    ; print in hex
  657.     call    print
  658.     db    ' in Hex',cr,lf,0
  659.     call    print
  660.     db    'The Second Number is ',0
  661.     xchg        ; get 2nd number into HL
  662.     call    phldc    ; print in decimal
  663.     call    print
  664.     db    ' in Decimal or ',0
  665.     call    phl4hc    ; print in hex
  666.     call    print
  667.     db    ' in Hex',cr,lf,0
  668.     xchg        ; save 2nd number in DE for rest of loop
  669.     call    print
  670.     db    cr,lf,'Sum = ',0
  671.     lhld    num1    ; get first number again
  672.     call    addhd    ; HL = HL + DE
  673.     call    phldc    ; print sum
  674.     call    print
  675.     db    '  Difference = ',0
  676.     lhld    num1    ; get first number (since destroyed by ADDHD)
  677.     call    subhd    ; ... and so on ...
  678.     call    phldc    ; print difference
  679.  
  680.     call    print
  681.     db    '  Product = ',0
  682.     lhld    num1
  683.     call    mulhd
  684.     call    phldc    ; print product
  685.     call    print
  686.     db    '  Quotient = ',0
  687.     lhld    num1
  688.     call    divhd
  689.     call    phldc    ; print quotient
  690.     call    print
  691.     db    cr,lf,'  Negative of First Argument = ',0
  692.     lhld    num1
  693.     call    negh
  694.     call    phldc    ; print negative
  695.     call    print
  696.     db    cr,lf,'AND = ',0
  697.     lhld    num1    ; get first number
  698.     call    andhd
  699.     call    phl4hc
  700.     call    print
  701.     db    '  OR = ',0
  702.     lhld    num1
  703.     call    orhd
  704.     call    phl4hc
  705.     call    print
  706.     db    '  XOR = ',0
  707.     lhld    num1
  708.     call    xorhd
  709.     call    phl4hc
  710.     call    print
  711.     db    cr,lf,'First Argument:  SHIFT L = ',0
  712.     lhld    num1
  713.     call    shftlh
  714.     call    phl4hc
  715.     call    print
  716.     db    '  SHIFT R = ',0
  717.     lhld    num1
  718.     call    shftrh
  719.     call    phl4hc
  720.     call    print
  721.     db    '  ROT L = ',0
  722.     lhld    num1
  723.     call    rotlh
  724.     call    phl4hc
  725.     call    print
  726.     db    '  ROT R = ',0
  727.     lhld    num1
  728.     call    rotrh
  729.     call    phl4hc
  730.     jmp    loop
  731.  
  732.  
  733. num1:    ds    2    ; first number
  734.  
  735.     db    0
  736.  
  737.     end
  738.  
  739. B>;  Assemble the Program
  740. B>sub m80 systest3
  741. SUB for ZCPR2, Version 2.0
  742. Process SUBMIT File
  743. Writing SUBMIT Execution File to Disk
  744. B$;  M80.SUB -- MACRO-80 ASSEMBLER AND LINKER
  745. B$M80 =SYSTEST3
  746.  
  747. No  Fatal error(s)
  748.  
  749. B$SUB /A  PLEASE ABORT IF ERROR(S) EXIST
  750. SUB for ZCPR2, Version 2.0
  751. Abort SUBMIT File
  752. Do you wish to abort execution?
  753.   Enter A or ^C to Abort or anything else to continue -  
  754. Continuing Execution
  755. B$ERA SYSTEST3.BAK
  756. No File
  757. B$ERA SYSTEST3.COM
  758. SYSTEST3.COM
  759. B$L80 /P:100,SYSTEST3,A:SYSLIB/S,SYSTEST3/N,/U,/E
  760.  
  761. Link-80  3.37  08-May-80  Copyright 1979,80 (C) Microsoft
  762.  
  763. Data    0100    07F6
  764.  
  765.  
  766.  
  767. Data    0100    07F6
  768.  
  769.  
  770. [0000   07F6    7]
  771.  
  772. B$ERA SYSTEST3.REL
  773. SYSTEST3.REL
  774. B$;  ASSEMBLY COMPLETE
  775.  
  776.  
  777. B>;  Run the assembled program
  778. B>systest3
  779. SYSTEST3 -- Math Routines and Evaluation Demo
  780. Input Two Numbers, Separated by a Comma (<CR> to Stop) -- 10,5
  781. First Number is    10 in Decimal or 000A in Hex
  782. The Second Number is     5 in Decimal or 0005 in Hex
  783.  
  784. Sum =    15  Difference =     5  Product =    50  Quotient =     2
  785.   Negative of First Argument = 65526
  786. AND = 0000  OR = 000F  XOR = 000F
  787. First Argument:  SHIFT L = 0014  SHIFT R = 0005  ROT L = 0014
  788.                                              >>  ROT R = 0005
  789. Input Two Numbers, Separated by a Comma (<CR> to Stop) -- 11,5
  790. First Number is    11 in Decimal or 000B in Hex
  791. The Second Number is     5 in Decimal or 0005 in Hex
  792.  
  793. Sum =    16  Difference =     6  Product =    55  Quotient =     2
  794.   Negative of First Argument = 65525
  795. AND = 0001  OR = 000F  XOR = 000E
  796. First Argument:  SHIFT L = 0016  SHIFT R = 0005  ROT L = 0016
  797.                                              >>  ROT R = 8005
  798. Input Two Numbers, Separated by a Comma (<CR> to Stop) -- 825,15
  799. First Number is   825 in Decimal or 0339 in Hex
  800. The Second Number is    15 in Decimal or 000F in Hex
  801.  
  802. Sum =   840  Difference =   810  Product = 12375  Quotient =    55
  803.   Negative of First Argument = 64711
  804. AND = 0009  OR = 033F  XOR = 0336
  805. First Argument:  SHIFT L = 0672  SHIFT R = 019C  ROT L = 0672
  806.                                              >>  ROT R = 819C
  807. Input Two Numbers, Separated by a Comma (<CR> to Stop) -- 9999,2
  808. First Number is  9999 in Decimal or 270F in Hex
  809. The Second Number is     2 in Decimal or 0002 in Hex
  810.  
  811. Sum = 10001  Difference =  9997  Product = 19998  Quotient =  4999
  812.   Negative of First Argument = 55537
  813. AND = 0002  OR = 270F  XOR = 270D
  814. First Argument:  SHIFT L = 4E1E  SHIFT R = 1387  ROT L = 4E1E
  815.                                              >>  ROT R = 9387
  816. Input Two Numbers, Separated by a Comma (<CR> to Stop) -- 
  817.  
  818.  
  819. 21.05 Sort Demonstration
  820.  
  821. B>;  Demo of Sort Routines in SYSLIB
  822. B>type systest4.mac
  823. ;
  824. ;  PROGRAM:  SYSTEST4
  825. ;  AUTHOR:  Richard Conn
  826. ;  PURPOSE:  To allow the user to input a list of text elements
  827. ;               and then sort that list in alphabetical order
  828. ;  NOTE:  This program demonstrates the use of SYSLIB and its
  829. ;               Sort Routines
  830. ;
  831.  
  832. ;
  833. ;  External Routines
  834. ;
  835.     ext    ssbinit    ; Initialize Sort Specification Block (SSB)
  836.     ext    sort    ; SORT Routine
  837.     ext    crlf    ; New Line
  838.     ext    cin    ; Char In
  839.     ext    caps    ; Capitalize char
  840.     ext    print    ; Print string
  841.     ext    bbline    ; Input Line Editor
  842.     ext    cout    ; Print Char
  843.     ext    codend    ; End of code/beginning of scratch buffer
  844.  
  845. ;
  846. ;  Equates
  847. ;
  848. cr    equ    0dh
  849. lf    equ    0ah
  850.  
  851. ;
  852. ;  Start of Program
  853. ;
  854.     jmp    go
  855. done:
  856.     ret        ; placed here for testing purposes
  857.  
  858. ;
  859. ;  First we have to use the routine CODEND to determine where the
  860. ;  first free byte in the scratch data area which follows the
  861. ;  program is.
  862. ;
  863. go:
  864.     call    print
  865.     db    'SYSTEST4 -- Sort Demonstration',cr,lf,0
  866. go1:
  867.     call    codend    ; get address of end of code
  868.     shld    start    ; save address of first byte of first record
  869.     xchg        ; ... in DE
  870.  
  871. ;
  872. ;  I will use BC to contain a count of the number of records entered
  873. ;  and DE to point to the next location in memory to store the
  874. ;  next record.
  875. ;
  876.     lxi    b,0    ; set record count
  877.  
  878. ;
  879. ;  Prompt user for input and get a line of text from him.
  880. ;
  881. loop:
  882.     call    print
  883.     db    cr,lf,'Entry (<CR>=Done)? ',0
  884.     xra    a    ; do not capitalize input line
  885.     call    bbline    ; get line from user
  886.     ora    a    ; A=char count=0 if done (just <CR> typed)
  887.     jz    sort1    ; do sort if done
  888.     inx    b    ; incr record count
  889.     push    b    ; save record count
  890.     mvi    b,40    ; copy user input into next record
  891.                         ; (pted to by DE)
  892.  
  893. ;
  894. ;  This loop copies the user's string, which was input by BBLINE
  895. ;  and pointed to by HL, into the next record position, which is
  896. ;  pointed to by DE.
  897. ;
  898. lp1:
  899.     mov    a,m    ; get byte
  900.     ora    a    ; done if zero
  901.     jz    lp2
  902.     stax    d    ; put byte
  903.     inx    h    ; pt to next
  904.     inx    d
  905.     dcr    b    ; count down
  906.     jmp    lp1
  907.  
  908. ;
  909. ;  This loop fills the rest of the record with spaces.  This is not
  910. ;  a very good program in the sense that it does not do any error
  911. ;  checking to see if the user typed more than 40 chars, but it
  912. ;  is OK for this demo.
  913. ;
  914. lp2:
  915.     mvi    a,' '    ; store <SP>
  916.     stax    d    ; put byte
  917.     inx    d    ; pt to next
  918.     dcr    b    ; count down
  919.     jnz    lp2
  920.  
  921. ;
  922. ;  Now we get our record count back and continue the program.
  923. ;
  924.     pop    b    ; get rec count
  925.     jmp    loop    ; continue until done
  926.  
  927. ;
  928. ;  The user has typed an empty line, and the number of records
  929. ;  is in BC.
  930. ;
  931. sort1:
  932.  
  933. ;
  934. ;  Set up record count field of SSB
  935. ;
  936.     mov    h,b    ; save record count
  937.     mov    l,c
  938.     shld    recnt    ; save record count field of Sort
  939.                         ; Specification Block
  940.  
  941. ;
  942. ;  Test for no records and abort if so
  943. ;
  944.     mov    a,h    ; any records?
  945.     ora    l
  946.     jnz    sort2
  947.     call    print
  948.     db    cr,lf,'No Records -- Aborting Sort',0
  949.     ret        ; Return to OS
  950.  
  951. ;
  952. ;  Set up record size field of SSB
  953. ;
  954. sort2:
  955.     lxi    h,40    ; 40 bytes/record
  956.     shld    recsiz    ; save record size field of Sort Spec
  957.                         ; Block (SSB)
  958.  
  959. ;
  960. ;  Set up compare routine address field of SSB
  961. ;
  962.     lxi    h,comp    ; address of compare routine
  963.     shld    cmpadr    ; save compare address in proper field
  964.                         ; of SSB
  965.  
  966.  
  967. ;
  968. ;  I shall now use SSBINIT to set up the ORDER buffer and check
  969. ;  to see that it does not overflow the TPA.  SSBINIT will also
  970. ;  set FIRSTP to the byte after the order buffer, but I will
  971. ;  discard this and reset FIRSTP to point to the first byte of
  972. ;  my first record.
  973. ;
  974.     xchg        ; HL pts to next available entry
  975.     lxi    d,ssb    ; Pt to SSB
  976.     call    ssbinit    ; initialize the SSB FIRSTP and ORDER buffers
  977.     lhld    start    ; set start address field of SSB since
  978.                         ; ORDER buffer
  979.     shld    firstp    ; is located AFTER the FIRSTP buffer
  980.  
  981. ;
  982. ;  Set the flag to tell SORT to use pointers to do the sort.
  983. ;
  984.     mvi    a,0ffh    ; non-zero
  985.     sta    sflag    ; set flag in SSB
  986.  
  987. ;
  988. ;  The Sort Specification Block (SSB) is now properly loaded, so
  989. ;  let's sort!
  990. ;
  991.     call    print
  992.     db    cr,lf,'Starting Sort --',cr,lf,0
  993.     lxi    d,ssb    ; pt to ssb
  994.     call    sort    ; sort it
  995.  
  996. ;
  997. ;  Buffer is now sorted -- print out results
  998. ;
  999.     call    print
  1000.     db    cr,lf,'Buffer After Sort --',cr,lf,0
  1001.     call    prbuf
  1002.  
  1003. ;
  1004. ;  Prompt the user to continue
  1005. ;
  1006.     call    print
  1007.     db    cr,lf,'Do you wish to run this test again (Y/N)? '
  1008.         db      0
  1009.     call    cin
  1010.     call    caps
  1011.     call    cout
  1012.     call    crlf    ; new line
  1013.     cpi    'N'
  1014.     jnz    go    ; rerun if not No
  1015.     jmp    done
  1016.  
  1017.  
  1018. ;
  1019. ;  Print the contents of the buffer containing all loaded records
  1020. ;
  1021. prbuf:
  1022.     lhld    recnt    ; get record count
  1023.     xchg        ; ... in DE
  1024.     lhld    firstp    ; pt to address of first record
  1025. prloop:
  1026.     call    crlf    ; new line
  1027.     mvi    b,40    ; print 40 chars
  1028. prl1:
  1029.     mov    a,m    ; get char
  1030.     inx    h    ; pt to next
  1031.     call    cout    ; print char
  1032.     dcr    b    ; count down chars
  1033.     jnz    prl1
  1034.     dcx    d    ; count recs
  1035.     mov    a,d
  1036.     ora    e
  1037.     jnz    prloop
  1038.     ret
  1039.  
  1040. ;
  1041. ;  Compare Routine for SORT
  1042. ;  This is a simple byte-for-byte comparison routine, which exists
  1043. ;  as soon as two bytes which are not equal are encountered.
  1044. ;
  1045. ;  This routine returns with the Zero Flag Set (Z) if the two records
  1046. ;  pointed to by HL and DE are equal (each byte the same).  It returns
  1047. ;  with the Carry Flag Set (C) if the record pointed to by DE is
  1048. ;  less than the record pointed to by HL in ASCII sorting sequence.
  1049. ;
  1050. comp:
  1051.     push    h    ; save regs
  1052.     push    d
  1053.     push    b
  1054.     mvi    b,40    ; 40 bytes max
  1055. cmpl:
  1056.     ldax    d    ; get byte
  1057.     cmp    m    ; compare
  1058.     jz    cmpok    ; continue or fall thru with proper flags
  1059. cmpd:
  1060.     pop    b    ; restore regs -- flag set
  1061.     pop    d
  1062.     pop    h
  1063.     ret
  1064. cmpok:
  1065.     inx    h    ; pt to next
  1066.     inx    d
  1067.     dcr    b    ; count down
  1068.     jnz    cmpl    ; continue
  1069.     jmp    cmpd    ; done
  1070.  
  1071.  
  1072. ;
  1073. ; Buffers
  1074. ;
  1075. start:    ds    2    ; address of 1st record
  1076. ssb:            ; this is the Sort Specification Block
  1077. firstp:    ds    2    ; Pointer to the first byte of first record
  1078. recnt:    ds    2    ; Number of records
  1079. recsiz:    ds    2    ; Size of record
  1080. cmpadr:    ds    2    ; Address of comparison routine
  1081. order:    ds    2    ; Address of pointer table (if used)
  1082. sflag:    ds    2    ; Flag telling SORT to use pointers (0=no)
  1083.  
  1084.     end
  1085.  
  1086. B>;  Assemble Program
  1087. B>sub m80 systest4
  1088. SUB for ZCPR2, Version 2.0
  1089. Process SUBMIT File
  1090. Writing SUBMIT Execution File to Disk
  1091. B$;  M80.SUB -- MACRO-80 ASSEMBLER AND LINKER
  1092. B$M80 =SYSTEST4
  1093.  
  1094. No  Fatal error(s)
  1095.  
  1096. B$SUB /A  PLEASE ABORT IF ERROR(S) EXIST
  1097. SUB for ZCPR2, Version 2.0
  1098. Abort SUBMIT File
  1099. Do you wish to abort execution?
  1100.   Enter A or ^C to Abort or anything else to continue -  
  1101. Continuing Execution
  1102. B$ERA SYSTEST4.BAK
  1103. No File
  1104. B$ERA SYSTEST4.COM
  1105. SYSTEST4.COM
  1106. B$L80 /P:100,SYSTEST4,A:SYSLIB/S,SYSTEST4/N,/U,/E
  1107.  
  1108. Link-80  3.37  08-May-80  Copyright 1979,80 (C) Microsoft
  1109.  
  1110. Data    0100    06E6
  1111.  
  1112.  
  1113.  
  1114. Data    0100    06E6
  1115.  
  1116.  
  1117. [0000   06E6    6]
  1118.  
  1119. B$ERA SYSTEST4.REL
  1120. SYSTEST4.REL
  1121. B$;  ASSEMBLY COMPLETE
  1122.  
  1123. B>; Run Sort
  1124. B>systest4
  1125. SYSTEST4 -- Sort Demonstration
  1126.  
  1127. Entry (<CR>=Done)? Rick
  1128. Entry (<CR>=Done)? Jane
  1129. Entry (<CR>=Done)? David
  1130. Entry (<CR>=Done)? Debbie
  1131. Entry (<CR>=Done)? Arnold
  1132. Entry (<CR>=Done)? Scott
  1133. Entry (<CR>=Done)? 
  1134. Starting Sort --
  1135.  
  1136. Buffer After Sort --
  1137.  
  1138. Arnold                                  
  1139. David                                   
  1140. Debbie                                  
  1141. Jane                                    
  1142. Rick                                    
  1143. Scott                                   
  1144. Do you wish to run this test again (Y/N)? N
  1145.  
  1146.  
  1147.  
  1148.  
  1149. 21.06 Random Number Generator Demonstration
  1150.  
  1151.  
  1152. B>;  Demo of Random Number Generator
  1153. B>type systest5.mac
  1154. ;
  1155. ;  PROGRAM:  SYSTEST5
  1156. ;  AUTHOR:  Richard Conn
  1157. ;  PURPOSE:  This program obtains a seed value and then generates
  1158. ;        10 random numbers
  1159. ;
  1160.  
  1161. ;
  1162. ;  Externals
  1163. ;
  1164.     ext    cin    ; char in
  1165.     ext    cout    ; char out
  1166.     ext    print    ; print string
  1167.     ext    rndinit    ; init random number generator by keypress
  1168.     ext    rnd    ; return random number
  1169.     ext    rndseed    ; init random number generator by user seed
  1170.     ext    crlf    ; new line
  1171.     ext    padc    ; print A as up to 3 decimal digits
  1172.     ext    caps    ; capitalize char
  1173.     ext    bbline    ; get line from user
  1174.     ext    eval    ; evaulate string
  1175.  
  1176. ;
  1177. ;  Constants
  1178. ;
  1179. cr    equ    0dh
  1180. lf    equ    0ah
  1181.  
  1182.     call    print
  1183.     db    'SYSTEST5 - Random Number Demo',0
  1184.  
  1185. ;
  1186. ;  Start of main loop, which generates 10 random numbers each
  1187. ;  time it is executed.
  1188. ;
  1189. start:
  1190.  
  1191. ;
  1192. ;  Prompt user to see if he wants to select his own seed
  1193. ;
  1194.     call    print
  1195.     db    cr,lf,'Do you want to pick your own seed (Y/N)? '
  1196.         db      0
  1197.     call    cin    ; get single-char response from user
  1198.     call    caps
  1199.     call    cout
  1200.     cpi    'N'
  1201.     jz    rseed
  1202. è;
  1203. ;  Input a seed value from the user.
  1204. ;
  1205.     call    print
  1206.     db    cr,lf,'What is your seed value? ',0
  1207.     xra    a    ; no caps
  1208.     call    bbline    ; get string
  1209.     call    eval    ; evaluate string and return value in HL
  1210.                         ; and A=L
  1211.     call    rndseed    ; set seed from 8-bit value in A
  1212.     call    print    ; print seed stored
  1213.     db    cr,lf,'Your seed is: ',0
  1214.     call    padc
  1215.     jmp    rseed1
  1216.  
  1217. ;
  1218. ;  Prompt user and wait for keypress to set seed.
  1219. ;
  1220. rseed:
  1221.     call    print
  1222.     db    cr,lf,'Wait a little and then press a key to set'
  1223.         db      ' the seed - ',0
  1224.     call    rndinit
  1225.  
  1226. ;
  1227. ;  Generate 10 random numbers
  1228. ;
  1229. rseed1:
  1230.     call    print
  1231.     db    cr,lf,'10 Random Numbers follow --',cr,lf,0
  1232.     mvi    b,10    ; 10 numbers
  1233. loop:
  1234.     call    rnd    ; get number
  1235.     call    padc    ; print it as decimal
  1236.     mvi    a,' '    ; print <SP>
  1237.     call    cout
  1238.     dcr    b    ; count down
  1239.     jnz    loop
  1240.  
  1241. ;
  1242. ;  Prompt user to continue
  1243. ;
  1244.     call    print
  1245.     db    cr,lf,'Do you want to run this test again (Y/N)? '
  1246.         db      0
  1247.     call    cin    ; get response
  1248.     call    caps
  1249.     call    cout
  1250.     cpi    'N'
  1251.     jnz    start
  1252.     ret        ; return to OS if done
  1253.  
  1254.     end
  1255.  
  1256. B>;  Assemble the Program
  1257. B>sub m80 systest5
  1258. SUB for ZCPR2, Version 2.0
  1259. Process SUBMIT File
  1260. Writing SUBMIT Execution File to Disk
  1261. B$;  M80.SUB -- MACRO-80 ASSEMBLER AND LINKER
  1262. B$M80 =SYSTEST5
  1263.  
  1264. No  Fatal error(s)
  1265.  
  1266. B$SUB /A  PLEASE ABORT IF ERROR(S) EXIST
  1267. SUB for ZCPR2, Version 2.0
  1268. Abort SUBMIT File
  1269. Do you wish to abort execution?
  1270.   Enter A or ^C to Abort or anything else to continue -  
  1271. Continuing Execution
  1272. B$ERA SYSTEST5.BAK
  1273. No File
  1274. B$ERA SYSTEST5.COM
  1275. SYSTEST5.COM
  1276. B$L80 /P:100,SYSTEST5,A:SYSLIB/S,SYSTEST5/N,/U,/E
  1277.  
  1278. Link-80  3.37  08-May-80  Copyright 1979,80 (C) Microsoft
  1279.  
  1280. Data    0100    0615
  1281.  
  1282.  
  1283.  
  1284. Data    0100    0615
  1285.  
  1286.  
  1287. [0000   0615    6]
  1288.  
  1289. B$ERA SYSTEST5.REL
  1290. SYSTEST5.REL
  1291. B$;  ASSEMBLY COMPLETE
  1292.  
  1293. B>;  Run the Program
  1294. B>systest5
  1295. SYSTEST5 - Random Number Demo
  1296. Do you want to pick your own seed (Y/N)? N
  1297. Wait a little and then press a key to set the seed - 
  1298. 10 Random Numbers follow --
  1299.  21 170  12  25 166   8  33 200 197  66 
  1300. Do you want to run this test again (Y/N)? Y
  1301. Do you want to pick your own seed (Y/N)? N
  1302. Wait a little and then press a key to set the seed - 
  1303. 10 Random Numbers follow --
  1304. 112 232  62 196  75 148 134 111 131 239 
  1305. Do you want to run this test again (Y/N)? Y
  1306. Do you want to pick your own seed (Y/N)? Y
  1307. What is your seed value? 25
  1308. Your seed is:  25
  1309. 10 Random Numbers follow --
  1310. 171 196 237 100 161 189 176  54 125  21 
  1311. Do you want to run this test again (Y/N)? Y
  1312. Do you want to pick your own seed (Y/N)? Y
  1313. What is your seed value? 25
  1314. Your seed is:  25
  1315. 10 Random Numbers follow --
  1316.   7 112  53 158 194 150 210 178 228 145 
  1317. Do you want to run this test again (Y/N)? Y
  1318. Do you want to pick your own seed (Y/N)? Y
  1319. What is your seed value? 0
  1320. Your seed is:   0
  1321. 10 Random Numbers follow --
  1322.   1 129  67 230 155  94 123 210 201  61 
  1323. Do you want to run this test again (Y/N)? N
  1324.  
  1325.  
  1326.  
  1327. 21.07 ZCPR2-Specific Function Demonstration
  1328.  
  1329. B>type systest6.mac
  1330. ;
  1331. ;  PROGRAM:  SYSTEST6
  1332. ;  AUTHOR:  Richard Conn
  1333. ;  PURPOSE:  To illustrate the ZCPR2-specific routines in SYSLIB
  1334. ;
  1335.  
  1336. ;
  1337. ;  Externals
  1338. ;
  1339.     EXT    ZCPRSET        ; Set DMA, et al
  1340.     EXT    ZINIEXT        ; Set External Path Address
  1341.     EXT    ZPFIND        ; Find File Along Path
  1342.     EXT    ZFSTAT        ; Return Status of File
  1343.     EXT    ZFNAME        ; Extended File Name Parser
  1344.  
  1345.     EXT    RETUD        ; Return Current User/Disk
  1346.     EXT    CRLF        ; New Line
  1347.     EXT    BBLINE        ; Input Line Editor
  1348.     EXT    PRINT        ; Print String
  1349.     EXT    PSTR        ; Another Print String
  1350.     EXT    CIN        ; Char in
  1351.     EXT    COUT        ; Char out
  1352.     EXT    CAPS        ; Capitalize char
  1353.     EXT    PADC        ; Print A as decimal
  1354.     EXT    BDOS        ; BDOS Call
  1355.     EXT    PHL4HC        ; Print HL as 4 Hex chars
  1356.     EXT    CODEND        ; End of code/beginning of buffer
  1357.  
  1358. ;
  1359. ;  Constants
  1360. ;
  1361. CR    EQU    0DH
  1362. LF    EQU    0AH
  1363.  
  1364. ;
  1365. ;  THIS INITIALIZATION MUST BE DONE WHENEVER THE ZCPR-ORIENTED
  1366. ;    ROUTINES ARE TO BE USED WITH THE USER'S EXTERNAL PATH
  1367. ;
  1368.     LXI    H,40H        ; BASE OF EXTERNAL PATHS
  1369.     CALL    ZINIEXT        ; SET BASE ADDRESS
  1370.  
  1371. ;
  1372. ;  THIS INITIALIZATION NEED NOT ALWAYS BE DONE, ESPECIALLY WHEN THE
  1373. ;    DEFAULTS ARE USED, BUT I'M DOING IT HERE FOR PURPOSE OF
  1374. ;       EXAMPLE
  1375. ;
  1376.     MVI    A,'$'    ; CURRENT INDICATOR
  1377.     LXI    H,80H    ; DMA ADDRESS
  1378.     CALL    ZCPRSET    ; SET THESE VALUES FOR ZCPR ROUTINES
  1379.  
  1380.  
  1381. ;
  1382. ;  SINCE I AM PLAYING WITH DISKS AND USER AREAS, GET THE CURRENT
  1383. ;  DISK/USER
  1384. ;
  1385.     CALL    RETUD    ; GET CURRENT USER AND DISK
  1386.     MOV    A,B    ; SAVE DISK
  1387.     STA    CDISK
  1388.     MOV    A,C    ; SAVE USER
  1389.     STA    CUSER
  1390.  
  1391. ;
  1392. ;  TEST LOOP
  1393. ;
  1394. LOOP:
  1395.     CALL    PRINT
  1396.     DB    CR,LF,'Current Disk is ',0
  1397.     LDA    CDISK    ; GET DISK
  1398.     PUSH    PSW    ; SAVE IF
  1399.     ADI    'A'    ; CONVERT TO ASCII
  1400.     CALL    COUT
  1401.     POP    PSW    ; GET DISK
  1402.     MOV    E,A
  1403.     MVI    C,14    ; SELECT DISK
  1404.     CALL    BDOS
  1405.     CALL    PRINT
  1406.     DB    ', and Current User is ',0
  1407.     LDA    CUSER    ; GET USER
  1408.     CALL    PADC    ; PRINT AS DECIMAL
  1409.     MOV    E,A    ; SELECT USER
  1410.     MVI    C,32
  1411.     CALL    BDOS
  1412.     CALL    PRINT
  1413.     DB    CR,LF,'Name of File to Search For (<CR>=Done)? ',0
  1414.     XRA    A    ; NO CAP
  1415.     CALL    BBLINE    ; GET LINE FROM USER
  1416.     ORA    A    ; ANY INPUT?
  1417.     RZ
  1418.     CALL    PRINT
  1419.     DB    CR,LF,'File Name: ',0
  1420.     PUSH    H    ; SAVE HL, SINCE MODIFIED BY PSTR
  1421.     CALL    PSTR
  1422.     CALL    CODEND    ; GET ADDRESS OF SCRATCH AREA FOR ZFNAME
  1423.     MOV    B,H    ; ... IN BC
  1424.     MOV    C,L
  1425.     POP    H
  1426.     LXI    D,FCB    ; PT TO FCB
  1427.     CALL    ZFNAME    ; CONVERT TO FCB FORM
  1428.     JZ    UDERR    ; USER OR DISK ERROR?
  1429.  
  1430.     CALL    PRINT
  1431.     DB    CR,LF,'Selected Disk is ',0
  1432.     MOV    A,B    ; GET DISK NUMBER
  1433.     CPI    0FFH    ; CURRENT?
  1434.     JNZ    DN1
  1435.     CALL    PRINT
  1436.     DB    'Current',0
  1437.     JMP    DN2
  1438. DN1:
  1439.     DCR    A    ; CONVERT TO 0-15
  1440.     ADI    'A'    ; CONVERT TO LETTER
  1441.     CALL    COUT
  1442.     SUI    'A'    ; CONVERT BACK
  1443.     MOV    E,A    ; IN E
  1444.     PUSH    B    ; SAVE BC
  1445.     MVI    C,14    ; SELECT DISK
  1446.     CALL    BDOS
  1447.     POP    B    ; GET BC
  1448. DN2:
  1449.     CALL    PRINT
  1450.     DB    ', and Selected User is ',0
  1451.     MOV    A,C    ; GET USER
  1452.     CPI    0FFH    ; CURRENT?
  1453.     JNZ    DN3
  1454.     CALL    PRINT
  1455.     DB    'Current',0
  1456.     JMP    DN4
  1457. DN3:
  1458.     CALL    PADC    ; PRINT AS DECIMAL
  1459.     MOV    E,A    ; USER IN E
  1460.     MVI    C,32    ; SELECT USER
  1461.     CALL    BDOS
  1462. DN4:
  1463.     CALL    PRINT
  1464.     DB    CR,LF,'Selected User and Disk Now Logged In'
  1465.     DB    CR,LF,'File Name from FCB: ',0
  1466.     LXI    H,FCB+1
  1467.     MVI    C,8    ; PRINT 8 CHARS
  1468.     CALL    PCH
  1469.     MVI    A,'.'
  1470.     CALL    COUT
  1471.     MVI    C,3    ; PRINT 3 MORE CHARS
  1472.     CALL    PCH
  1473.     CALL    CRLF
  1474.     LXI    D,FCB    ; PT TO FCB
  1475.     MVI    B,0    ; DON'T SEARCH CURRENT
  1476.     CALL    ZPFIND    ; SEARCH FOR FILE ALONG PATH (DE PTS TO FCB)
  1477.     JZ    FNF    ; FILE NOT FOUND IF A=0 AND ZERO FLAG SET
  1478.     CALL    PRINT
  1479.     DB    CR,LF,'File Found on Disk ',0
  1480.     MOV    A,B    ; GET DISK NUMBER
  1481.     ADI    'A'    ; CONVERT TO LETTER
  1482.     CALL    COUT
  1483.  
  1484.     CALL    PRINT
  1485.     DB    ' in User ',0
  1486.     MOV    A,C    ; GET USER NUMBER
  1487.     CALL    PADC    ; PRINT AS DECIMAL
  1488.     PUSH    D    ; SAVE FCB PTR
  1489.     PUSH    B    ; SAVE USER/DISK
  1490.     MOV    E,B    ; SELECT DISK
  1491.     MVI    C,14    ; BDOS FCT
  1492.     CALL    BDOS    ; SELECT USER
  1493.     POP    B    ; GET USER
  1494.     MOV    E,C
  1495.     MVI    C,32    ; BDOS FCT
  1496.     CALL    BDOS    ; SELECT USER
  1497.     POP    D    ; GET FCB PTR
  1498.     CALL    ZFSTAT    ; GET STATUS OF FILE
  1499.     JNZ    FNF1    ; FILE NOT FOUND?  SHOULD NOT HAPPEN
  1500.     CALL    PRINT
  1501.     DB    CR,LF,'File is ',0
  1502.     MOV    A,C    ; GET R/O FLAG
  1503.     ORA    A    ; 0=NOT R/O
  1504.     JNZ    LOOP1
  1505.     CALL    PRINT
  1506.     DB    'NOT ',0
  1507. LOOP1:
  1508.     CALL    PRINT
  1509.     DB    'Read/Only, and File is ',0
  1510.     MOV    A,B    ; GET SYSTEM FLAG
  1511.     ORA    A    ; 0=NOT SYSTEM
  1512.     JNZ    LOOP2
  1513.     CALL    PRINT
  1514.     DB    'Non-',0
  1515. LOOP2:
  1516.     CALL    PRINT
  1517.     DB    'System',0
  1518.     JMP    LOOP
  1519. FNF1:
  1520.     CALL    PRINT
  1521.     DB    CR,LF,'This should not happen',0
  1522. FNF:
  1523.     CALL    PRINT
  1524.     DB    CR,LF,'File Not Found',0
  1525.     JMP    LOOP
  1526. UDERR:
  1527.     CALL    PRINT
  1528.     DB    CR,LF,'Error in User or Disk Numbers',0
  1529.     JMP    LOOP
  1530. PCH:
  1531.     MOV    A,M    ; GET CHAR
  1532.     CALL    COUT    ; PRINT CHAR
  1533.     INX    H    ; PT TO NEXT
  1534.     DCR    C    ; COUNT DOWN
  1535.     JNZ    PCH
  1536.     RET
  1537. èCDISK:
  1538.     DS    1    ; CURRENT DISK
  1539. CUSER:
  1540.     DS    1    ; CURRENT USER
  1541. FCB:
  1542.     DS    36
  1543.  
  1544.     END
  1545.  
  1546.  
  1547. B>;  I won't repeat the assembly on this one (because I'm tired
  1548. B>;  of going thru all those assemblies!)
  1549.  
  1550. B>;  Demo of ZCPR2-Specific Routines in SYSLIB, Particularly Path
  1551. B>;  Search I will now look around on the various disks to show
  1552. B>;  you what files are "hanging around"
  1553. B>xdir *.com /aa
  1554. XDIR III, Version 1.2    Vertical Listing by File Type and Name
  1555.  Disk: B  User:   0, File Attributes:  Non-System System
  1556.  
  1557. Filename.Typ Size K RS   Filename.Typ Size K RS   Filename.Typ Size K RS
  1558. -------- --- ------ --   -------- --- ------ --   -------- --- ------ --
  1559. GETSYS  .COM     10 RS   SYSTEST .COM      2      SYSTEST4.COM      2      
  1560. LU      .COM     18      SYSTEST1.COM      2      SYSTEST5.COM      2      
  1561. MCOPY   .COM      4 RS   SYSTEST2.COM      2      SYSTEST6.COM      4      
  1562. PIP     .COM      8 RS   SYSTEST3.COM      2      XDIR    .COM     10 RS   
  1563.    12 Files Occupying    66K,    26 Files on Disk and   426K Free
  1564.  
  1565. B>xdir a:*.com /aa
  1566. XDIR III, Version 1.2    Vertical Listing by File Type and Name
  1567.  Disk: A  User:   0, File Attributes:  Non-System System
  1568.  
  1569. Filename.Typ Size K RS   Filename.Typ Size K RS   Filename.Typ Size K RS
  1570. -------- --- ------ --   -------- --- ------ --   -------- --- ------ --
  1571. ASM2    .COM      8      HELP    .COM      4 RS   PROTECT .COM      4 RS   
  1572. CALC    .COM      4 RS   INUSE   .COM      4 RS   RENAME  .COM      4 RS   
  1573. CHDIR   .COM     14 RS   IOLOADER.COM      2 RS   SGEN    .COM      2 RS   
  1574. COMPARE .COM      2 RS   L80     .COM     10      SUB     .COM      4 RS   
  1575. DASM    .COM     10 RS   LIB     .COM      6      SYSGEN  .COM      2      
  1576. DASMT   .COM      8 RS   LOAD    .COM      2      TIME    .COM      6 RS   
  1577. DEVICE  .COM     10 RS   M80     .COM     20      TINIT   .COM      6 RS   
  1578. DIFF    .COM      4 RS   MAC     .COM     12      WM      .COM     10 RS   
  1579. ED      .COM      8      MCOPY   .COM      4 RS   XDIR    .COM     10 RS   
  1580. ERASE   .COM      6 RS   PATH    .COM     12 RS   XLATE2  .COM      6 RS   
  1581. FINDBAD .COM      4 RS   PIP     .COM      8 RS   ZSID    .COM     10 RS   
  1582. GETSYS  .COM     10 RS   PRINT   .COM      6 RS   
  1583.    35 Files Occupying   242K,    58 Files on Disk and   222K Free
  1584.  
  1585.  
  1586. B>xdir 5:
  1587. XDIR III, Version 1.2    Vertical Listing by File Type and Name
  1588.  Disk: B  User:   5, File Attributes:  Non-System
  1589.  
  1590. Filename.Typ Size K RS   Filename.Typ Size K RS   Filename.Typ Size K RS
  1591. -------- --- ------ --   -------- --- ------ --   -------- --- ------ --
  1592. TEST    .TXT      2      
  1593.     1 Files Occupying     2K,    26 Files on Disk and   426K Free
  1594.  
  1595.  
  1596. B>;  To display the current named directories --
  1597.  
  1598. B>chdir /d
  1599. CHDIR, Version 2.0  -- Option: Display Directory Names
  1600. Defined Directory Names --
  1601.         A0: ROOT        B0: DEV B5: TEST
  1602. 5 Directory Names Defined, Space Left for 59 More Names
  1603.  
  1604. Current Directory --    B0: DEV
  1605.  
  1606.  
  1607. B>;  To display the path --
  1608.  
  1609. B>path
  1610. PATH Version 2.1
  1611. Current Symbolic Path --
  1612.         $$: --> $0: --> A$: --> A0:
  1613. Current Absolute Path --
  1614.         B0: --> B0: --> A0: --> A0:
  1615. Current Named Path --
  1616.         DEV: --> DEV: --> ROOT: --> ROOT:
  1617. B>user 5
  1618. B5>path
  1619. PATH Version 2.1
  1620. Current Symbolic Path --
  1621.         $$: --> $0: --> A$: --> A0:
  1622. Current Absolute Path --
  1623.         B5: --> B0: --> A5: --> A0:
  1624. Current Named Path --
  1625.         TEST: --> DEV: --> Noname: --> ROOT:
  1626.  
  1627. B5>;  Now to run the test program
  1628. B5>systest6
  1629.  
  1630. Current Disk is B, and Current User is   5
  1631. Name of File to Search For (<CR>=Done)? xdir.com
  1632. File Name: xdir.com
  1633. Selected Disk is Current, and Selected User is Current
  1634. Selected User and Disk Now Logged In
  1635. File Name from FCB: XDIR    .COM
  1636.  
  1637. File Found on Disk B in User   0
  1638. File is Read/Only, and File is System
  1639. Current Disk is B, and Current User is   5
  1640. Name of File to Search For (<CR>=Done)? test.txt
  1641. File Name: test.txt
  1642. Selected Disk is Current, and Selected User is Current
  1643. Selected User and Disk Now Logged In
  1644. File Name from FCB: TEST    .TXT
  1645.  
  1646. File Found on Disk B in User   5
  1647. File is NOT Read/Only, and File is Non-System
  1648. Current Disk is B, and Current User is   5
  1649. Name of File to Search For (<CR>=Done)? zsid.com
  1650. File Name: zsid.com
  1651. Selected Disk is Current, and Selected User is Current
  1652. Selected User and Disk Now Logged In
  1653. File Name from FCB: ZSID    .COM
  1654.  
  1655. File Found on Disk A in User   0
  1656. File is Read/Only, and File is System
  1657. Current Disk is B, and Current User is   5
  1658. Name of File to Search For (<CR>=Done)? aa.com
  1659. File Name: aa.com
  1660. Selected Disk is Current, and Selected User is Current
  1661. Selected User and Disk Now Logged In
  1662. File Name from FCB: AA      .COM
  1663.  
  1664. File Not Found
  1665. Current Disk is B, and Current User is   5
  1666. Name of File to Search For (<CR>=Done)? a10:xdir.com
  1667. File Name: a10:xdir.com
  1668. Selected Disk is A, and Selected User is  10
  1669. Selected User and Disk Now Logged In
  1670. File Name from FCB: XDIR    .COM
  1671.  
  1672. File Found on Disk A in User   0
  1673. File is Read/Only, and File is System
  1674. Current Disk is B, and Current User is   5
  1675. Name of File to Search For (<CR>=Done)? 
  1676.