home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / cpm / alphatronic / MPM-GEN.ZIP / DUMP.ASM < prev    next >
Assembly Source File  |  1997-09-27  |  5KB  |  242 lines

  1. ; NOTE:
  2. ;    In order to execute this sample DUMP utility you
  3. ; must assemble EXTRN.ASM and then link DUMP and EXTRN to
  4. ; create the DUMP.PRL file.  This is shown below:
  5. ;
  6. ;    0A>RMAC dump
  7. ;    0A>RMAC extrn
  8. ;    0A>LINK dump,extrn[op]
  9. ;
  10.     title    'File Dump Program'
  11.     cseg
  12. ;    File dump program, reads an input file and
  13. ;      prints in hex
  14. ;
  15. ;    Copyright (C) 1975, 1976, 1977, 1978, 1979, 1980, 1981
  16. ;    Digital Research
  17. ;    Box 579, Pacific Grove
  18. ;    California, 93950
  19. ;
  20. ;    Externals
  21.     extrn    bdos
  22.     extrn    fcb
  23.     extrn    buff
  24. ;
  25. cons    equ    1    ;read console
  26. typef    equ    2    ;type function
  27. printf    equ    9    ;buffer print entry
  28. brkf    equ    11    ;break key function
  29. openf    equ    15    ;file open
  30. readf    equ    20    ;read function
  31. ;
  32. ;    non graphic characters
  33. cr    equ    0dh    ;carriage return
  34. lf    equ    0ah    ;line feed
  35. ;
  36. ;    file control block definitions
  37. ;fcbdn    equ    fcb+0    ;disk name
  38. ;fcbfn    equ    fcb+1    ;file name
  39. ;fcbft    equ    fcb+9    ;disk file type (3 characters)
  40. ;fcbrl    equ    fcb+12    ;file's current reel number
  41. ;fcbrc    equ    fcb+15    ;file's record count (0 to 128)
  42. ;fcbcr    equ    fcb+32    ;current (next) record number
  43. ;fcbln    equ    fcb+33    ;fcb length
  44. ;
  45. dump:
  46. ;    set up stack
  47.     lxi    h,0
  48.     dad    sp
  49. ;    entry stack pointer in hl from the ccp
  50.     shld    oldsp
  51. ;    set sp to local stack area (restored at finis)
  52.     lxi    sp,stktop
  53. ;    print sign on message
  54.     lxi    d,signon
  55.     call    prntmsg    
  56. ;    read and print successive buffers
  57.     call    setup    ;set up input file
  58.     cpi    255    ;255 if file not present
  59.     jnz    openok    ;skip if open is ok
  60. ;
  61. ;    file not there, give error message and return
  62.     lxi    d,opnmsg
  63.     call    prntmsg
  64.     jmp    finis    ;to return
  65. ;
  66. openok:    ;open operation ok, set buffer index to end
  67.     mvi    a,80h
  68.     sta    ibp    ;set buffer pointer to 80h
  69. ;    hl contains next address to print
  70.     lxi    h,0    ;start with 0000
  71. ;
  72. gloop:
  73.     push    h    ;save line position
  74.     call    gnb
  75.     pop    h    ;recall line position
  76.     jc    finis    ;carry set by gnb if end file
  77.     mov    b,a
  78. ;    print hex values
  79. ;    check for line fold
  80.     mov    a,l
  81.     ani    0fh    ;check low 4 bits
  82.     jnz    nonum
  83. ;    print line number
  84.     call    crlf
  85. ;
  86. ;    check for break key
  87.     call    break
  88. ;    accum lsb = 1 if character ready
  89.     rrc        ;into carry
  90.     jc    purge    ;don't print any more
  91. ;
  92.     mov    a,h
  93.     call    phex
  94.     mov    a,l
  95.     call    phex
  96. nonum:
  97.     inx    h    ;to next line number
  98.     mvi    a,' '
  99.     call    pchar
  100.     mov    a,b
  101.     call    phex
  102.     jmp    gloop
  103. ;
  104. purge:
  105.     mvi    c,cons
  106.     call    bdos
  107. finis:
  108. ;    end of dump, return to ccp
  109. ;    (note that a jmp to 0000h reboots)
  110.     call    crlf
  111.     lhld    oldsp
  112.     sphl
  113. ;    stack pointer contains ccp's stack location
  114.     ret        ;to the ccp
  115. ;
  116. ;
  117. ;    subroutines
  118. ;
  119. break:    ;check break key (actually any key will do)
  120.     push h! push d! push b; environment saved
  121.     mvi    c,brkf
  122.     call    bdos
  123.     pop b! pop d! pop h; environment restored
  124.     ret
  125. ;
  126. pchar:    ;print a character
  127.     push h! push d! push b; saved
  128.     mvi    c,typef
  129.     mov    e,a
  130.     call    bdos
  131.     pop b! pop d! pop h; restored
  132.     ret
  133. ;
  134. crlf:
  135.     mvi    a,cr
  136.     call    pchar
  137.     mvi    a,lf
  138.     call    pchar
  139.     ret
  140. ;
  141. ;
  142. pnib:    ;print nibble in reg a
  143.     ani    0fh    ;low 4 bits
  144.     cpi    10
  145.     jnc    p10
  146. ;    less than or equal to 9
  147.     adi    '0'
  148.     jmp    prn
  149. ;
  150. ;    greater or equal to 10
  151. p10:    adi    'A' - 10
  152. prn:    call    pchar
  153.     ret
  154. ;
  155. phex:    ;print hex char in reg a
  156.     push    psw
  157.     rrc
  158.     rrc
  159.     rrc
  160.     rrc
  161.     call    pnib    ;print nibble
  162.     pop    psw
  163.     call    pnib
  164.     ret
  165. ;
  166. prntmsg:    ;print message
  167. ;    d,e addresses message ending with "$"
  168.     mvi    c,printf    ;print buffer function
  169.     jmp    bdos
  170. ;    ret
  171. ;
  172. ;
  173. gnb:    ;get next byte
  174.     lda    ibp
  175.     cpi    80h
  176.     jnz    g0
  177. ;    read another buffer
  178. ;
  179. ;
  180.     call    diskr
  181.     ora    a    ;zero value if read ok
  182.     jz    g0    ;for another byte
  183. ;    end of data, return with carry set for eof
  184.     stc
  185.     ret
  186. ;
  187. g0:    ;read the byte at buff+reg a
  188.     mov    e,a    ;ls byte of buffer index
  189.     mvi    d,0    ;double precision index to de
  190.     inr    a    ;index=index+1
  191.     sta    ibp    ;back to memory
  192. ;    pointer is incremented
  193. ;    save the current file address
  194.     lxi    h,buff
  195.     dad    d
  196. ;    absolute character address is in hl
  197.     mov    a,m
  198. ;    byte is in the accumulator
  199.     ora    a    ;reset carry bit
  200.     ret
  201. ;
  202. setup:    ;set up file 
  203. ;    open the file for input
  204.     xra    a    ;zero to accum
  205.     sta    fcb+32    ;clear current record
  206. ;
  207. ;    open the file in R/O mode
  208.     lxi    h,fcb+6
  209.     mov    a,m
  210.     ori    80h
  211.     mov    m,a    ;set f6' on
  212.     lxi    d,fcb
  213.     mvi    c,openf
  214.     call    bdos
  215. ;    255 in accum if open error
  216.     ret
  217. ;
  218. diskr:    ;read disk file record
  219.     push h! push d! push b
  220.     lxi    d,fcb
  221.     mvi    c,readf
  222.     call    bdos
  223.     pop b! pop d! pop h
  224.     ret
  225. ;
  226. ;    fixed message area
  227. signon:
  228.     db    'MP/M II V2.0  File Dump'
  229.     db    cr,lf,'$'
  230. opnmsg:
  231.     db    cr,lf,'No input file present on disk$'
  232.  
  233. ;    variable area
  234. ibp:    ds    2    ;input buffer pointer
  235. oldsp:    ds    2    ;entry sp value from ccp
  236. ;
  237. ;    stack area
  238.     ds    64    ;reserve 32 level stack
  239. stktop:
  240. ;
  241.     end    dump
  242.