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

  1. ;
  2. ;  PROGRAM:  SYSTEST
  3. ;  AUTHOR:  Richard Conn
  4. ;  PURPOSE:  This program dumps the disk file specified by the user
  5. ;        in hexadecimal and ASCII
  6. ;  NOTE:  This test demonstrates the use of the SYSLIB Byte-Oriented
  7. ;        File Input routines
  8. ;
  9.  
  10. ;  External CP/M Buffers
  11. fcb    equ    5ch    ; address of FCB filled in by CP/M's CCP (or ZCPR2)
  12.  
  13. ;  External References for SYSLIB routines used
  14.     ext    fi1$open    ; Open File for Byte-Oriented Input
  15.     ext    fi1$close    ; Close File
  16.     ext    f1$get        ; Get Byte from File
  17.     ext    cout        ; Character Output
  18.     ext    pa2hc        ; Print A as 2 Hex Chars
  19.     ext    phldc        ; Print HL as up to 5 decimal digits
  20.     ext    print        ; String Print
  21.     ext    crlf        ; New Line
  22.  
  23. ;
  24. ;  Start of Routine -- Print Banner
  25. ;
  26.     call    print
  27.     db    'SYSTEST - Sample DUMP Program to Illustrate SYSLIB '
  28.     db    'Byte-Oriented File Input'
  29.     db    0
  30.     call    crlf    ; new line
  31.  
  32. ;
  33. ;  Set Offset Counter
  34. ;
  35.     lxi    h,0    ; Init to zero
  36.     shld    counter
  37.  
  38. ;
  39. ;  Open File for Input
  40. ;
  41.     lxi    d,fcb    ; pt to FCB filled in by Operating System
  42.     call    fi1$open    ; try to open it
  43.     jz    loop    ; continue if OK
  44.     call    print    ; not ok, so file must not have been found
  45.     db    'File Not Found',0
  46.     ret        ; return to Operating System
  47.  
  48. ;
  49. ;  Main Loop
  50. ;
  51. loop:
  52.     lhld    counter    ; get counter value
  53.     call    phldc    ; print as decimal number
  54.     lxi    d,16    ; add 16 to counter for next print
  55.     dad    d
  56.     shld    counter    ; save count away
  57.     call    print
  58.     db    ': ',0
  59.     mvi    b,0    ; set byte count to zero
  60.     lxi    h,buffer    ; point to first byte of buffer
  61. readlp:
  62.     call    f1$get    ; get next byte
  63.     jnz    readdn    ; done if past EOF
  64.     mov    m,a    ; store byte into buffer
  65.     inx    h    ; point to next byte in buffer
  66.     inr    b    ; increment byte count
  67.     mov    a,b    ; check for done
  68.     cpi    16    ; read in 16 bytes?
  69.     jnz    readlp
  70.     call    bufprint    ; print contents of buffer
  71.     call    crlf    ; new line
  72.     jmp    loop    ; continue until End of File
  73.  
  74. ;
  75. ;  Done with Read -- Print current Buffer and Exit
  76. ;  B = Number of bytes to print
  77. ;
  78. readdn:
  79.     call    bufprint    ; print buffer
  80.     call    crlf        ; new line
  81.     call    fi1$close    ; close file
  82.     ret
  83.  
  84. ;
  85. ;  Buffer print routine; print the contents of the buffer for B bytes
  86. ;
  87. bufprint:
  88.     lxi    h,buffer    ; point to first byte of buffer
  89.     push    b    ; save character count
  90. bufploop:
  91.     mov    a,b    ; check count first (in case it is zero)
  92.     ora    a    ; done?
  93.     jz    ascprint    ; print as ASCII chars if done
  94.     dcr    b    ; count down
  95.     mov    a,m    ; get byte from buffer
  96.     inx    h    ; point to next byte in buffer
  97.     call    pa2hc    ; print byte as 2 Hex chars
  98.     mvi    a,' '    ; print a space
  99.     call    cout
  100.     jmp    bufploop
  101. ;  Now print buffer as ASCII characters
  102. ascprint:
  103.     lxi    h,buffer    ; point to first character
  104.     pop    b    ; get character count
  105.     call    print    ; print a separator
  106.     db    '! ',0
  107. ascploop:
  108.     mov    a,b    ; check for empty buffer
  109.     ora    a    ; done if zero
  110.     rz        ; return to caller if so
  111.     dcr    b    ; count down
  112.     mov    a,m    ; get byte to output
  113.     ani    7fh    ; mask out most significant bit
  114.     mov    c,a    ; save character in C
  115.     cpi    ' '    ; test for printable character
  116.     jnc    ascp    ; print character if printable
  117.     mvi    c,'.'    ; print dot if not printable character
  118. ascp:
  119.     mov    a,c    ; get char to print
  120.     call    cout    ; print it
  121.     inx    h    ; point to next character
  122.     jmp    ascploop    ; continue until count is exhausted
  123.  
  124. counter:
  125.     ds    2    ; Offset Counter
  126. buffer:
  127.     ds    16    ; 16-byte buffer for input bytes
  128.  
  129.     end
  130.