home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / BROWSR10.ZIP / SUPERHEX.ASM < prev    next >
Assembly Source File  |  1993-07-11  |  5KB  |  183 lines

  1. ; =========== SuperHEX 1.1 ===============
  2. ; by Victor Yiu, July 1993
  3. ;
  4. ; Ultra-fast ASCII to HEX conversion...
  5. ; designed for calling up from a file
  6. ; or memory viewer to display hex/ascii
  7. ; codes like Norton's DiskEdit, or PCTool's
  8. ; View... except much faster!
  9. ;
  10. ; This code is released into public domain.
  11. ; =========================================
  12.  
  13. CODE SEGMENT PARA PUBLIC 'CODE'
  14.     PUBLIC SuperHex, MemCopy, Scroll
  15.     ASSUME CS:code, DS:nothing, ES:nothing, SS:nothing
  16.  
  17. CharsPerLine    = 80        ; set-up hard coded constant
  18. FilterReplaceChar   EQU '.' ; replace bad chars. with what?
  19.  
  20. SuperHex PROC FAR
  21.     PUSH BP             ; set up stack frame
  22.     MOV BP, SP
  23.     PUSH DS             ; save registers
  24.     PUSH SI
  25.     PUSH DI
  26. ; ===========================================================================
  27. ;VidSeg, Row, OffsetHex, OffsetASCii, Seg:Off memory (16 byte)
  28. ; BP+20  BP+18  BP+16       BP+14            BP+10 [DWORD]
  29.  
  30. ; BG Color    Filter
  31. ;   BP+8       BP+6
  32. ; ===========================================================================
  33.  
  34.     LES AX, SS:[BP+18]  ; VidSeg --> ES
  35.     DEC AX              ; Row --> AX  (adjust to 0-24 range)
  36.     JZ NoMul            ; if 0, don't multiply to save time
  37.     MOV BL, CharsPerLine; get # chars per line
  38.     MUL BL              ; multiply
  39. NoMul:
  40.     SHL AX, 1           ; *2, since disp. memory alternates ASCii/color
  41.     MOV DX, AX          ; save into DX
  42.  
  43.     LDS SI, SS:[BP+10]  ; get source memory into DS:SI
  44.     PUSH SI             ; save it for later
  45.  
  46. ; ====== Setup to write the 16 bytes of ASCii first
  47.     MOV AH, SS:[BP+8]   ; get attribute into AH
  48.     MOV DI, DX          ; move start of row offset into DI
  49.     MOV BX, SS:[BP+14]  ; get offset of ASCii
  50.     DEC BX
  51.     SHL BX, 1           ; *2 because of vid. mem.
  52.     ADD DI, BX          ; compute final offset
  53.     CMP WORD PTR [BP+6], 0       ; filter on?
  54.     JNE FilterOn
  55.  
  56. REPT 16                ; repeat 16 times
  57.     LODSB               ; get byte
  58.     STOSW               ; store byte + attribute
  59. ENDM
  60.     JMP SHORT Continue
  61. EVEN
  62. FilterOn:
  63.     MOV CX, 16
  64.     MOV BX, '~ '        ; preload constants
  65. EVEN
  66. FilterTop:
  67.     LODSB
  68.     CMP AL, BL          ; below 32?
  69.     JL NoShow
  70.     CMP AL, BH          ; more than 127
  71.     JG NoShow
  72.     STOSW
  73.     LOOP FilterTop
  74.     JMP SHORT Continue
  75. EVEN
  76. NoShow:
  77.     MOV AL,FilterReplaceChar
  78.     STOSW
  79.     LOOP FilterTop
  80.  
  81. ; ======= Set up for HEX conversion to screen
  82. Continue:
  83.     MOV BX, SS:[BP+16]  ; get offset of HEX
  84.     DEC BX
  85.     SHL BX, 1           ; *2 for vid. mem
  86.     ADD DX, BX          ; add to original row offset
  87.     MOV DI, DX          ; put it into the index register
  88.     POP SI              ; get previous SI
  89.     MOV CX, 16          ; do sixteen characters
  90.  
  91.     MOV BL, AH          ; attribute into BL
  92.     MOV DX, (256*9) + ('A'-'9'-1) 
  93.     MOV BP, '00'        ; preload stuff to make it scream
  94.  
  95. ; BP = '00'
  96. ; BL = attribute
  97. ; BH = -- reserved for temporary digit
  98. ; DL = 'A'-'9'-1
  99. ; DH = 9
  100. EVEN
  101. LoopTop:
  102.     MOV BH, 16          ; load divisor
  103.     LODSB               ; get character
  104.     MOV AH, 0           ; clear AH
  105.     DIV BH              ; to get tens in AL, ones in AH.
  106.     CMP AL, DH          ; > '9'?
  107.     JLE NextDigit       ; no -- don't fix
  108. EVEN
  109.     ADD AL, DL          ; fix it
  110. NextDigit:
  111.     CMP AH, DH          ; > '9'?
  112.     JLE WriteOut        ; no -- don't fix
  113.     ADD AH, DL          ; fix it
  114. WriteOut:
  115.     ADD AX, BP          ; add '00' to digits to make them ASCii
  116.     MOV BH, AH          ; save ones digit for next character
  117.     MOV AH, BL          ; get attribute
  118.     STOSW               ; write digit
  119.     MOV AL, BH          ; get next
  120.     STOSW               ; write
  121.     MOV AL, ' '         ; write space
  122.     STOSW
  123.     CMP CX, 9           ; between the 8th and 9th HEX digits
  124.     JE AddSpace
  125.     LOOP LoopTop
  126.     JMP SHORT OttaHere
  127. EVEN
  128. AddSpace: STOSW
  129.     LOOP LoopTop
  130.  
  131. OttaHere:
  132.     POP DI              ; restore registers
  133.     POP SI
  134.     POP DS
  135.     POP BP
  136.     RET 16              ; shave off 16 bytes of passed in parameters
  137. SuperHex ENDP
  138.  
  139. MemCopy PROC FAR
  140.     PUSH BP
  141.     MOV BP, SP          ; set up stack frame
  142.     PUSH DS
  143.     PUSH SI
  144.     PUSH DI
  145.  
  146.     CLD
  147.     MOV CX, [BP+6]      ; # to copy in CX
  148.     LES DI, [BP+8]      ; get dest.
  149.     LDS SI, [BP+12]     ; get source
  150.  
  151.     SHR CX, 1           ; odd byte
  152.     JNC CopyStart
  153.     MOVSB
  154. CopyStart: REP MOVSW    ; do copy
  155.  
  156.     POP DI
  157.     POP SI
  158.     POP DS
  159.     POP BP
  160.     RET 10
  161. MemCopy ENDP
  162.  
  163. Scroll PROC FAR
  164.     PUSH BP
  165.     MOV BP, SP      ; set up stack frame
  166.  
  167. ; BP+8 = MoveUp?   BP+6 = attribute
  168.  
  169.     MOV BH, [BP+6]  ; load up attribute
  170.     MOV AX, 0601h   ; 1 line
  171.     CMP BYTE PTR [BP+8], 0    ; zero?
  172.     JE Down        ; yes; go up
  173.     INC AH          ; go down (AX=0701)
  174. Down:
  175.     MOV CX, 0202h   ; (3,3) top left
  176.     MOV DX, 0164Ch  ; (23,77) bottom right
  177.     INT 010h        ; call vid. interrupt
  178.     POP BP
  179.     RET 4
  180. Scroll ENDP
  181.     CODE ENDS
  182. END
  183.