home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / UNIFLEX / UNIFLEX / UniFLEX_Std.Utils1.tar.Z / UniFLEX_Std.Utils1.tar / utils1 / dump < prev    next >
Text File  |  1982-01-28  |  4KB  |  238 lines

  1.  opt pag,nol
  2.  ttl File Dump
  3.  pag
  4.  lib sysdef
  5.  opt lis
  6.  pag
  7.  
  8. * program starts here
  9.  
  10.  org 0
  11.  
  12. dump ldd 0,s get arg count
  13.  cmpd #2 is it 1?
  14.  beq dump0 yes - continue
  15.  cmpd #3 is it 2?
  16.  bne dump6
  17.  ldy #pos get starting position
  18.  ldx 6,s point at argument
  19.  jsr gethex
  20. dump0 ldx #line point to text line
  21.  lda #$20 setup space
  22.  ldb #76 set counter
  23. dump1 sta 0,x+ space out line
  24.  decb dec the count
  25.  bne dump1
  26.  ldd 4,s get name pointer
  27.  std iopn2 set in call
  28.  sys ind,iopn
  29.  bes dump6 errors?
  30.  pshs d save file desc
  31.  ldd pos position file
  32.  std start
  33.  ldd pos+2
  34.  std start+2
  35.  ldd 0,s get file desc
  36.  sys ind,iseek
  37.  bes dump9
  38. dump2 lbsr zerbuf zero out buffer
  39.  ldd 0,s get file desc
  40.  sys read,buffer,16 read in file
  41.  bes dump4
  42.  cmpd #0 eof?
  43.  beq dump4
  44.  std count
  45.  lbsr fillin fill in text line
  46.  ldd #1 set file desc
  47.  sys write,line,77 output line
  48.  ldd pos+2 get pos count
  49.  addd #16 bump by 16
  50.  std pos+2
  51.  bcc dump2 if no carry
  52.  ldd pos propagate carry
  53.  addd #1
  54.  std pos
  55.  bra dump2 repeat
  56. dump4 puls d get file desc
  57.  sys close close the file
  58. dump6 sys term exit!
  59. *
  60. dump9 pshs d
  61.  ldd #0 write out error
  62.  sys write,err0,err0sz
  63.  puls d
  64.  sys term
  65.  
  66. *
  67. *  gethex - parse hex number from command line
  68. *
  69. gethex ldd #0 set value
  70.  std 0,y
  71.  std 2,y
  72.  ldb ,x+ get character
  73.  cmpb #'+ ignore +
  74.  bne geth0
  75.  ldb ,x+
  76.  beq geth9
  77. geth0 cmpb #'0 legal value
  78.  blt geth9 no - error
  79.  cmpb #'9
  80.  ble geth1
  81.  cmpb #'a is it a hex digit?
  82.  blt geth9 no - abort
  83.  cmpb #'f
  84.  bgt geth9
  85.  subb #'a-10
  86.  bra geth2
  87. geth1 subb #'0
  88. geth2 clra
  89.  pshs d
  90.  ldd 2,y get value
  91.  aslb shift left 4
  92.  rola
  93.  rol 1,y
  94.  rol 0,y
  95.  aslb
  96.  rola
  97.  rol 1,y
  98.  rol 0,y
  99.  aslb
  100.  rola
  101.  rol 1,y
  102.  rol 0,y
  103.  aslb
  104.  rola
  105.  rol 1,y
  106.  rol 0,y
  107.  addd 0,s++ compute new value
  108.  std 2,y save result
  109.  ldb ,x+ get next character
  110.  bne geth0 continue scan
  111.  rts exit
  112. *
  113. geth9 ldd #0 error - bad hex input
  114.  sys write,err1,err1sz
  115.  ldd #0
  116.  sys term
  117.  
  118. * zerbuf
  119.  
  120. zerbuf ldb #16 set count
  121.  ldx #buffer set pointer
  122. zerbu2 clr 0,x+
  123.  decb
  124.  bne zerbu2
  125.  rts return
  126.  
  127. * fillin
  128.  
  129. fillin ldx #line point to line
  130.  lda #$20 blank line
  131.  ldb #76
  132. fill0 sta ,x+
  133.  decb
  134.  bgt fill0
  135.  ldx #line
  136.  ldy #buffer point to file data
  137.  lda pos get pos count
  138.  bsr pthex out hex
  139.  lda pos+1
  140.  bsr pthex
  141.  lda pos+2
  142.  bsr pthex
  143.  lda pos+3
  144.  bsr pthex
  145.  leax 1,x
  146.  ldb count+1 get length
  147.  cmpb #8
  148.  ble fill1
  149.  ldb #8
  150. fill1 bsr group
  151.  leax 1,x leave space
  152.  ldb count+1
  153.  subb #8
  154.  bge fill2
  155.  ldb #0
  156. fill2 bsr group
  157.  leax 2,x leave 2 spaces
  158.  bra ascii
  159.  
  160. group pshs b save input count
  161.  tstb anything here?
  162.  beq group3 no - exit
  163. group2 lda 0,y+ get byte
  164.  leax 1,x leave space
  165.  bsr pthex output hex
  166.  decb dec count
  167.  bne group2
  168. group3 ldb #8
  169.  subb 0,s+
  170.  beq group9
  171.  leax b,x
  172.  leax b,x
  173.  leax b,x
  174. group9 rts return
  175.  
  176. * pthex
  177.  
  178. pthex pshs a save char
  179.  lsra get hi part
  180.  lsra
  181.  lsra
  182.  lsra
  183.  bsr chex do char
  184.  sta 0,x+ save result
  185.  puls a get byte
  186.  bsr chex do char conv
  187.  sta 0,x+ save result
  188.  rts return
  189.  
  190. * chex
  191.  
  192. chex anda #$f mask lo bits
  193.  ora #$30 make ascii
  194.  cmpa #$39 is it digit
  195.  bls chex2
  196.  adda #7 make letter
  197. chex2 rts return
  198.  
  199. * ascii
  200.  
  201. ascii ldy #buffer point to buffer
  202.  ldb count+1
  203. ascii1 lda 0,y+ get byte
  204.  anda #$7f mask parity
  205.  cmpa #$7f printable?
  206.  beq ascii3 no - print '.'
  207.  cmpa #$20 is it control?
  208.  bhs ascii2
  209. ascii3 lda #'. if so, make period
  210. ascii2 sta 0,x+ save in line
  211.  decb end of buffer?
  212.  bne ascii1
  213.  rts return
  214.  
  215. * buffers
  216.  
  217. pos fdb 0,0
  218. iopn fcb open
  219. iopn2 fdb 0
  220.  fdb 0
  221.  
  222. iseek fcb seek
  223. start fdb 0,0
  224.  fdb 0
  225.  
  226. buffer rmb 16
  227. line rmb 76
  228.  fcb $d c.r.
  229. count fdb 0
  230.  
  231. cr equ $0d
  232. err0 fcc 'I/O error on file',cr
  233. err0sz equ *-err0
  234. err1 fcc 'Illegal hex input - abort',cr
  235. err1sz equ *-err1
  236.  
  237.  end dump
  238.