Guest User

ccpm86 hexdump

a guest
Mar 31st, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ccpmint equ 224
  2. p_termcpm equ 0
  3. c_read equ 1
  4. c_write equ 2
  5. c_writestr equ 9
  6. f_open equ 15
  7. f_close equ 16
  8. f_read equ 20
  9. f_dmaoff equ 26
  10.  
  11. cseg
  12.  
  13. start:
  14.  
  15.     ; copy filename to fcb
  16.     mov cx, 16
  17.     mov di, offset fcb
  18.     mov si, 05ch
  19.     cld
  20.     rep movsb
  21.  
  22.     ; set current dma to dma in dseg
  23.     mov cl, f_dmaoff
  24.     mov dx, offset dma
  25.     call ccpm
  26.  
  27.     ; open the file
  28.     mov cl, f_open
  29.     mov dx, offset fcb
  30.     call ccpm
  31.     cmp al, 0
  32.     jnz error
  33.  
  34.     ; read the file
  35.     mov readcnt, 0
  36.     mov cl, f_read
  37.     mov dx, offset fcb
  38.     call ccpm
  39.     cmp al, 0
  40.     jnz read_end
  41.     call print_dma
  42.     inc readcnt
  43. read_loop:
  44.     mov cl, f_read
  45.     mov dx, offset fcb
  46.     call ccpm
  47.     cmp al, 0
  48.     jnz read_end
  49.  
  50.     mov cl, c_read
  51.     call ccpm
  52.     cmp al, 'q'
  53.     jz terminate
  54.     mov cl, c_writestr
  55.     mov dx, offset crlf
  56.     call ccpm
  57.     call print_dma
  58.     inc readcnt
  59.     jmp read_loop
  60. read_end:
  61.     cmp al, 01h
  62.     jnz error
  63.  
  64.     ; close the file
  65.     mov cl, f_close
  66.     mov dx, offset fcb
  67.     call ccpm
  68.     cmp al, 0
  69.     jnz error
  70.  
  71. terminate:
  72.     ; terminate the program
  73.     mov cl, p_termcpm
  74.     xor dx, dx
  75.     call ccpm
  76.  
  77. error:
  78.     ; error handling
  79.     mov tmp, ax
  80.     mov cl, c_writestr
  81.     mov dx, offset errmsg
  82.     int ccpmint
  83.     mov al, last_cl
  84.     call print_byte
  85.     mov cl, c_writestr
  86.     mov dx, offset erral
  87.     int ccpmint
  88.     mov ax, tmp
  89.     call print_byte
  90.     mov cl, c_writestr
  91.     mov dx, offset errah
  92.     int ccpmint
  93.     mov ax, tmp
  94.     mov al, ah
  95.     call print_byte
  96.     mov cl, c_writestr
  97.     mov dx, offset crlf
  98.     int ccpmint
  99.     jmp terminate
  100.  
  101. print_dma:
  102.     ; fill lines of 16 bytes and prints each line
  103.     xor cl, cl
  104.     mov si, offset dma
  105. pdmaloop:
  106.     mov di, offset buf
  107. pdmalp_in:
  108.     movsb
  109.     inc cl
  110.     test cl, 15
  111.     jnz pdmalp_in
  112.     call print_line
  113.     cmp cl, 128
  114.     jnz pdmaloop
  115.     ret
  116.  
  117. print_line:
  118.     ; prints a single dma line: address, bytes, chars
  119.     ; address = readcnt*128 + cx - 16
  120.     push cx
  121.     mov dx, cx
  122.     mov ax, readcnt
  123.     mov cl, 7
  124.     shl ax, cl
  125.     add ax, dx
  126.     sub ax, 16
  127.     call print_word
  128.     mov cl, c_write
  129.     mov dl, 32
  130.     call ccpm
  131.  
  132.     ; print bytes
  133.     mov di, offset buf
  134.     xor cx, cx
  135. plbloop:
  136.     mov tmp, cx
  137.     mov al, [di]
  138.     call print_byte
  139.     mov cl, c_write
  140.     mov dl, 32
  141.     call ccpm
  142.     mov cx, tmp
  143.     inc cx
  144.     inc di
  145.     cmp cx, 16
  146.     jnz plbloop
  147.  
  148.     ; print chars
  149.     mov di, offset buf
  150.     mov cx, 0
  151. plcloop:
  152.     mov tmp, cx
  153.     mov al, [di]
  154.     cmp al, 32
  155.     jb plcpdot
  156.     cmp al, 126
  157.     jbe plcpchr
  158. plcpdot:
  159.     mov al, '.'
  160. plcpchr:
  161.     mov cl, c_write
  162.     mov dl, al
  163.     call ccpm
  164.     mov cx, tmp
  165.     inc di
  166.     inc cx
  167.     cmp cx, 16
  168.     jb plcloop
  169.  
  170.     ; write crlf and return
  171.     mov cl, c_writestr
  172.     mov dx, offset crlf
  173.     call ccpm
  174.     pop cx
  175.     ret
  176.  
  177. print_word:
  178.     ; prints a word: the highest byte, then the lowest
  179.     push ax
  180.     mov al, ah
  181.     call print_byte
  182.     pop ax
  183. print_byte:
  184.     ; prints the two characters of a byte in al
  185.     push ax
  186.     and al, 0f0h
  187.     mov cl, 4
  188.     shr al, cl
  189.     call print_nibble
  190.     pop ax
  191.     and al, 0fh
  192. print_nibble:
  193.     ; prints a single hexadecimal digit
  194.     cmp al, 10
  195.     jb pnib
  196.     add al, 'A'-10-'0'
  197. pnib:
  198.     add al, '0'
  199.     mov cl, c_write
  200.     mov dl, al
  201.     int ccpmint
  202.     ret
  203.  
  204. ccpm:
  205.     mov last_cl, cl
  206.     int ccpmint
  207.     ret
  208.  
  209. dseg
  210. org 100h
  211.  
  212. errmsg  db  'error: function=$'
  213. erral   db  ', al=$'
  214. errah   db  ', ah=$'
  215. crlf    db  10,13,'$'
  216. fcb rs  33
  217. dma rs  180
  218. buf rs  16
  219. tmp rw  1
  220. readcnt rw  1
  221. last_cl db  0
  222.  
  223. end
Add Comment
Please, Sign In to add comment