home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / GRDBDL17.ZIP / DUMP.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-10-26  |  3.8 KB  |  184 lines

  1. ;
  2. ; GRDP
  3. ;
  4. ; Copyright(c) LADsoft
  5. ;
  6. ; David Lindauer, camille@bluegrass.net
  7. ;
  8. ;
  9. ; Dump.asm
  10. ;
  11. ; Function: Handle the Dump command
  12. ;
  13.     
  14.     ;MASM MODE
  15.     .model small
  16.     .386
  17.  
  18.  
  19. include  eprints.inc 
  20. include  einput.inc 
  21. include  emtrap.inc 
  22. include  eoptions.inc
  23.  
  24. DUMPLEN = 80h
  25.     PUBLIC    dump
  26.     PUBLIC  index,indexseg
  27.     .data
  28. index    dd    0        ; Default for next dump
  29. indexseg dw    0        ;
  30.  
  31. ;Debug reads each memory paragraph twice, once for the hex values and a
  32. ;second time for the ASCII values. This screws up at least two types of
  33. ;memory: memory-mapped IO when reads change the state of the device, and
  34. ;and FIFO devices with internal counters. So we read each location only once
  35. ;into this buffer, and then read the buffer to create the ASCII.
  36.  
  37. linedata db    16 DUP (?)    ;holds line so we read it only once
  38.  
  39.     .code
  40. ;
  41. ; Dump one line
  42. ;
  43. dumpline    PROC
  44.     push    esi
  45.     push    dx
  46.     push    ebx                ; EBX MUST be on second of stack
  47.     push    ecx            ; ECX MUST be on top of stack
  48.     sub    ax,ax
  49.     mov    al,bl          ; AL = lower byte of address
  50.     and    al,15        ; AL = lower nibble
  51.     mov    ecx,16        ; Total bytes to dump
  52.     jz    short doline    ; Go do hexdump if start of line = 0
  53.     neg    al        ; Else calculate number of bytes in line
  54.     add    al,16        ;
  55.     movzx    Ecx,ax        ; To ECX
  56.  
  57. doline:
  58.     sub    [esp],ecx    ; Decrement count which is on stack
  59.     add    [esp+4],ecx    ; Increment address which is on stack
  60.     mov    al,16        ; Get count of amount to space over
  61.     sub    al,cl        ;
  62.     jz    short puthex    ; Don't space over any, just put out hex
  63.  
  64.     push    cx        ; Else ecx = spacecount * 3
  65.     mov    cx,ax        ;
  66.     add    cx,cx        ;
  67.     add    cx,ax        ;
  68. blanklp1:
  69.     call    PrintSpace      ; Dump spaces
  70.     loop    blanklp1    ;
  71.     pop    cx
  72.  
  73. puthex:
  74.     push    cx
  75.     mov    di,offset linedata    ; Now get the bytes to our buffer
  76.     movzx    edi,di
  77.     push    ds
  78.     push    fs             ; fs:si was source
  79.     pop    ds
  80.     movzx    ecx,cx
  81.     db    67h        ; addrsize
  82.     rep    movsb
  83.     pop    ds
  84.     pop    cx
  85.     mov    si,offset linedata    
  86.     push    cx        ;
  87. hexlp:
  88.     call    PrintSpace    ; Print a space
  89.     lodsb
  90.     call    PrintByte    ; Print byte in hex
  91.     loop    hexlp        ; Loop till done
  92.     pop    cx        ;
  93.  
  94.     call    printSpace    ; Print two spaces to seperate ASCII dump
  95.     call    PrintSpace    ;
  96.  
  97.     mov    si,offset linedata    
  98.     sub    ax,ax        ; Calculate amoun to space over
  99.     mov    al,16        ;
  100.     sub    al,cl        ;
  101.     jz    short putascii    ; None to space over, put ascii
  102.     push    cx        ; ECX = space value
  103.     mov    cx,ax
  104. blanklp2:
  105.     call    PrintSpace    ; Space over
  106.     loop    blanklp2    ;
  107.     pop    cx        ;
  108.     mov    si,offset linedata    
  109.  
  110. putascii:
  111.     mov    dl,[si]        ; Get char
  112.     inc    si        ; Increment buffer
  113.     call    PureChar
  114.     loop    putascii
  115.     pop    ecx        ; Get count from stack
  116.     pop    ebx        ; Get address from stack
  117.     pop    dx
  118.     pop    esi
  119.     ret
  120. dumpline    ENDP    
  121. ;
  122. ; Main DUMP routine
  123. ;
  124. dump    PROC    
  125.     mov    ecx,DUMPLEN    ; Default amount to dump
  126.     call    WadeSpace    ; Wade to end of spaces
  127.     jz    short atindex    ;
  128.     call    ReadAddress    ; Else read start address
  129.     jc    dudone        ; Quit on error
  130.     call    WadeSpace    ; Wade through spaces
  131.     jz    short dodump    ;
  132.     call    ReadNumber    ; Else read end offset
  133.     jc    short dudone    ;
  134.     sub    eax,ebx        ; Calculate length of dump
  135.     mov    ecx,eax        ;
  136.     jmp    short dodump    ; Go do dump
  137. atIndex:
  138.     mov    ebx,[index]    ; Assume we want to dump from last index
  139.     mov    dx,[indexseg]    ;
  140. dodump:
  141.     
  142.     call    defDS        ; get DS
  143.     mov    fs,dx
  144.     test    [optdwordcommand],-1
  145.     jnz    dumplp
  146.     movzx    ebx,bx
  147.     mov    eax,10000h
  148.     sub    eax,ebx
  149.     cmp    eax,ecx
  150.     jnc    dumplp
  151.     mov    ecx,eax
  152. dumplp:
  153.     call    scankey
  154.     jnz    dusetadr
  155.     push    ebx        ;
  156.     call    crlf
  157.     pop    ebx        ;
  158.     mov    ax,dx        ; Print the selector
  159.     call    PrintWord    ;
  160.     push    dx        ;
  161.     mov    dl,':'        ; Print a ':'
  162.     call    PutChar
  163.     pop    dx        ;
  164.     mov    eax,ebx        ;
  165.     mov    esi,ebx
  166.     and    eax,0fffffff0h  ; Address low nibble = 0
  167.     test    [optdwordcommand],0ffh
  168.     jz    adrword
  169.     call    PrintdWord    ; Print address
  170.     jmp    adrcmb
  171. adrword:
  172.     call    PrintWord
  173. adrcmb:
  174.     call    dumpline    ; Dump a line
  175.     or    ecx,ecx        ; Continue while count > 0
  176.     jg    dumplp
  177. dusetadr:        ;
  178.     mov    [index],ebx    ; Save new index value
  179.     mov    [indexseg],dx    ;
  180.     clc            ; No errors
  181. dudone:
  182.     ret
  183. dump    ENDP    
  184. END