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

  1. ;
  2. ;  PROGRAM:  SYSTEST2
  3. ;  AUTHOR:  Richard Conn
  4. ;  PURPOSE:  To demonstrate the SYSLIB routines for directory manipulation.
  5. ;  NOTE:  This program loads the disk directory and selects and prints files
  6. ;        which match the ambiguous file spec given by the user
  7. ;
  8.  
  9. ;
  10. ;  Externals
  11. ;
  12.     ext    dirf    ; Fast Directory Load/Select/Alphabetize/Pack
  13.     ext    print    ; Print String
  14.     ext    cout    ; Char out
  15.     ext    crlf    ; New Line
  16.     ext    retud    ; Return User and Disk
  17.     ext    codend    ; End of Code/Beginning of Buffer
  18.  
  19. ;
  20. ;  CP/M Equates
  21. ;
  22. fcb    equ    5ch    ; address of FCB loaded by CP/M
  23. cr    equ    0dh
  24. lf    equ    0ah
  25.  
  26. ;
  27. ;  I would normally look at the FCB to see if any file was specified and
  28. ;  make it wild (all ?'s) if so, but I won't do this so we can get right
  29. ;  to the problem at hand.  Hence, if the user simply types SYSTEST2 as
  30. ;  his command, the FCB will be all spaces and no file will match it.
  31. ;
  32.     call    print
  33.     db    'SYSTEST2 - Demo of Directory Routines in SYSLIB',cr,lf,0
  34.     call    codend    ; get buffer address in HL
  35.     lxi    d,fcb    ; pt to fcb in DE
  36.     call    retud    ; get user number in C (and disk in B, but not needed)
  37.     mov    a,c    ; user number in A
  38.     ori    10000000b    ; Mask in MSB so only Non-System files selected
  39.     call    dirf    ; load dir/select files/alphabetize/pack
  40.  
  41. ;
  42. ;  We now have a set of fixed-length records in memory, the first one being
  43. ;  pointed to by HL.  The number of records is in BC, and the length of each
  44. ;  record is 16 bytes.  These are the first 16 bytes of the FCBs of all files
  45. ;  which matched the files we were looking for.
  46. ;
  47. ;  I will now print out these file names horizontally across the screen.
  48. ;
  49.     mvi    d,0    ; set 4 count (new line every 4 entries)
  50.     mov    a,b    ; any file names?
  51.     ora    c    ; zero if so
  52.     jnz    loop    ; continue if any names
  53.     call    print
  54.     db    cr,lf,'No Files Match Ambiguous File Name',0
  55.     ret        ; return to OS
  56.  
  57. ;
  58. ;  This is the main loop to print the matching file names.
  59. ;
  60. loop:
  61.     push    d    ; save 4-count in D
  62.     call    prfile    ; print file name (HL, BC not affected)
  63.     lxi    d,16    ; point to next file name by adding 16 to HL
  64.     dad    d
  65.     pop    d    ; get 4-count in D
  66.     inr    d    ; add 1 to 4-count
  67.     mov    a,d    ; check to see if it is a 4 multiple
  68.     ani    3    ; zero if so
  69.     cz    crlf    ; ... and new line
  70.     dcx    b    ; count down
  71.     mov    a,b
  72.     ora    c
  73.     jnz    loop
  74.     ret        ; return to Operating System when done
  75.  
  76. ;
  77. ;  Print file name whose FCB is pointed to by HL.  Do not affect HL or BC.
  78. ;
  79. prfile:
  80.     push    b    ; save regs
  81.     push    h
  82.     inx    h    ; pt to first char of file name
  83.     mvi    b,8    ; print 8 bytes
  84.     call    prch    ; my routine to do this (not in SYSLIB)
  85.     mvi    a,'.'    ; print dot
  86.     call    cout
  87.     mvi    b,3    ; print 3 bytes
  88.     call    prch
  89.     call    print
  90.     db    '  !  ',0    ; print name separator
  91.     pop    h    ; restore regs
  92.     pop    b
  93.     ret
  94.  
  95. ;
  96. ;  Print B chars pointed to by HL
  97. ;
  98. prch:
  99.     mov    a,m    ; get char
  100.     inx    h    ; pt to next
  101.     call    cout    ; print char
  102.     dcr    b    ; count down
  103.     jnz    prch
  104.     ret
  105.  
  106.     end
  107.