home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / HEXDISP.ZIP / HEXDISP.ASM next >
Assembly Source File  |  1988-01-24  |  9KB  |  592 lines

  1.             PAGE    80,132
  2.             TITLE    OS/2 hex browse program
  3.             .286c
  4.             .xlist
  5.             include sysmac.inc
  6.             .list
  7.  
  8.         extrn    DosRead:far
  9.  
  10. @BTHS        MACRO    FROM,TO,LEN
  11.         push    cx
  12.         push    es
  13.         push    di
  14.         push    ds
  15.         push    si
  16.         mov    cx,seg FROM
  17.         push    cx
  18.         pop    ds
  19.         mov    si,offset FROM
  20.         mov    cx,seg TO
  21.         push    cx
  22.         pop    es
  23.         mov    di,offset TO
  24.         mov    cx,LEN
  25.         call    os2bths
  26.         pop    si
  27.         pop    ds
  28.         pop    di
  29.         pop    es
  30.         pop    cx
  31.         ENDM
  32. @BTH        MACRO    FROM,TO
  33.         push    ax
  34.         push    es
  35.         push    di
  36.         mov    di,offset TO
  37.         mov    ax,seg TO
  38.         push    ax
  39.         pop    es
  40.         mov    ax,FROM
  41.         call    os2bth
  42.         pop    di
  43.         pop    es
  44.         pop    ax
  45.         ENDM
  46.  
  47.         
  48. @BTA        MACRO    FROM,TO,LEN
  49.         push    cx
  50.         push    es
  51.         push    di
  52.         push    ax
  53.         IFIDN    < ES:DI >,< TO >
  54.         ELSE
  55.         IFIDN    < DS:SI >,< TO >
  56.         push    ds
  57.         pop    es
  58.         mov    di,si
  59.         ELSE
  60.         IFIDN    < SS:BP >,< TO >
  61.         push    ss
  62.         pop    es
  63.         mov    di,si
  64.         ELSE
  65.         mov    ax,seg TO
  66.         push    ax
  67.         pop    es
  68.         mov    di,offset TO
  69.         ENDIF
  70.         ENDIF
  71.         ENDIF
  72.         mov    ax,FROM
  73.         mov    cx,LEN
  74.         call    os2bta
  75.         pop    ax
  76.         pop    di
  77.         pop    es
  78.         pop    cx
  79.         ENDM
  80.  
  81. @JAXZ        MACRO    TARGET
  82.         or    ax,ax
  83.         jnz    $+5
  84.         jmp    TARGET
  85.         nop
  86.         ENDM
  87.  
  88. @JAXNZ        MACRO    TARGET
  89.         or    ax,ax
  90.         jz    $+5
  91.         jmp    TARGET
  92.         nop
  93.         ENDM
  94.  
  95. @GETPARMS    MACRO    TO,LEN
  96.         push    es
  97.         push    di
  98.         push    cx
  99.         mov    cx,seg TO
  100.         push    cx
  101.         pop    es
  102.         mov    cx,LEN
  103.         mov    di,offset TO
  104.         call    os2parms
  105.         pop    cx
  106.         pop    di
  107.         pop    es
  108.         ENDM
  109.  
  110. charbuf        struc
  111. charascii    db    ?
  112. charscan    db    ?
  113. charstat    db    ?
  114. charDBCSs    db    ?
  115. charshift    dw    ?
  116. chartimehi    dw    ?
  117. chartimelo    dw    ?
  118. charbuf        ends
  119.  
  120. dgroup    group    HEX_data
  121.  
  122. HEX_stack    segment para stack
  123.  
  124.         dw    256 dup('s')
  125.  
  126. HEX_stack    ends
  127.  
  128. HEX_DATA    segment para public 'auto'
  129.  
  130. dline        db    '    '
  131. dofsh        db    'HHHH'
  132. dofsl        db    'HHHH    '
  133. dhex1        db    'HHHHHHHH '
  134. dhex2        db    'HHHHHHHH    '
  135. dhex3        db    'HHHHHHHH '
  136. dhex4        db    'HHHHHHHH     *'
  137. ddata        db    'dddddddddddddddd*'
  138.         db    5 dup(' ')
  139.  
  140. topmsg        db    'HEXDISP: '
  141. topfn        db    33 dup (' ')
  142.         db    '<PgUp> <PgDn> <ESC> Page '
  143. topcur        db    'xxxx of '
  144. toptot        db    'xxxx '
  145.  
  146. msg1        db    'You must enter a file name',0ah,0dh
  147. MSG1L        equ    $ - offset msg1
  148.  
  149. msg2        db    'Open error on file name : '
  150. MSG2L        equ    $ - offset msg2
  151.  
  152. keydata        charbuf    <>
  153. XX        equ    01bh
  154. UP        equ    4900h
  155. AUP        equ    49e0h
  156. DN        equ    5100h
  157. ADN        equ    51e0h
  158. STDERR        equ    2
  159.  
  160. hexsegsz    dw    0
  161. hexsegp        dw    0
  162. hexseg        dw    0
  163. hexofs        dw    0
  164. hexlaspar    dw    0
  165. hexlasbyt    dw    0
  166. shift        dw    0
  167.  
  168. green        db    2fh
  169. fill        db    ' ',1fh
  170. bytesin        dw    0
  171. bytesout    dw    0
  172. temp        dw    0
  173.  
  174. fname        db    64 dup(0)
  175. fnamel        dw    0
  176. fhand        dw    0
  177. fact        dw    0
  178. fsize        dd    0
  179. fattr        dw    0
  180. fflag        dw    00000001b
  181. fmode        dw    0000000000100000b
  182. frsv        dd    0
  183. fofsl        dw    0
  184. fofsh        dw    0
  185. nofs        dd    0
  186.  
  187. HEX_data    ends
  188.  
  189. HEX_code    segment para public 'code'
  190.         assume cs:HEX_code,ds:nothing,es:HEX_data,ss:Hex_stack
  191.  
  192. main        proc
  193.         push    ds
  194.         pop    es
  195.  
  196.         call    openf
  197.         @jaxnz    hex999
  198.         call    getfile
  199.         @jaxnz    hex999
  200.         call    showfile
  201.  
  202. hex999:        @DosExit 1,0
  203. main        endp
  204.  
  205. openf        proc
  206.         @getparms    fname,63
  207.         @jaxnz    opf010
  208.         @DosWrite    stderr,msg1,MSG1L,bytesout
  209.         mov    ax,0ffh
  210.         jmp    opf999
  211.  
  212. opf010:        mov    cx,ax
  213.         mov    di,offset fname
  214.         mov     al,' '
  215.         repne    scasb
  216.         jcxz    opf020
  217.         dec    di
  218. opf020:        mov    byte ptr [di],0
  219.         sub    di,offset fname
  220.         mov    fnamel,di
  221.         @DosOpen fname,fhand,fact,fsize,fattr,fflag,fmode,frsv
  222.         @jaxz    opf999
  223.         @DosWrite stderr,msg2,msg2l,bytesout
  224.         @DosWrite stderr,fname,63,bytesout
  225.         mov    ax,0ffh
  226. opf999:        ret
  227. openf        endp
  228.  
  229. getfile        proc
  230.         mov    fofsl,0
  231.         @DosChgFilePtr fhand,fofsl,2,fofsl
  232.         mov    word ptr nofs,0
  233.         @DosChgFilePtr fhand,nofs,0,nofs
  234.  
  235. get010:        mov    dx,fofsl
  236.         add    dx,16
  237.         mov    hexsegsz,dx
  238.         @DosAllocHuge fofsh,dx,hexsegp,0,0
  239.         cmp    ax,0
  240.         je    get015
  241.         mov    ax,0ffh
  242.         jmp    get999
  243.  
  244. get015:        push    hexsegp
  245.         pop    ds
  246.         @DosGetHugeShift shift
  247.         mov    di,1
  248.         mov    cx,shift
  249.         shl    di,cl
  250.         mov    shift,di
  251.         push    ds
  252.         xor    si,si
  253.         mov    cx,fofsh
  254.         jcxz    get030
  255.  
  256. get020:        push    fhand
  257.         push    ds
  258.         push    si
  259.         push    -1
  260.         push    ds
  261.         push    bytesin
  262.         call    DosRead
  263.         push    cx
  264.         mov    ax,ds
  265.         add    ax,shift
  266.         mov    ds,ax
  267.         pop    cx
  268.         loop    get020
  269.  
  270. get030:        push    fhand
  271.         push    ds
  272.         push    si
  273.         push    hexsegsz
  274.         push    ds
  275.         push    bytesin
  276.         call    DosRead
  277.         @DosClose fhand
  278.         xor    ax,ax
  279.         pop    ds
  280.  
  281. get999:        ret
  282. getfile        endp
  283.  
  284. showfile    proc
  285.  
  286.         push    ds
  287.         push    es
  288.         pop    ds
  289.         lea    si,fname
  290.         lea    di,topfn
  291.         mov    cx,fnamel
  292.         cmp    cx,33
  293.         jle    shf010
  294.         mov    cx,33
  295. shf010:        rep    movsb
  296.         pop    ds
  297.         mov    dx,fofsh
  298.         mov    ax,fofsl
  299.         mov    bx,16*24
  300.         div    bx
  301.         mov    temp,ax
  302.         @bta    temp,toptot,4
  303.         @VioScrollUp 0,0,-1,-1,-1,fill,0
  304.         @VioWrtCharStrAtt topmsg,80,0,0,green,0
  305.         mov    hexofs,0
  306.         mov    hexseg,0
  307.         mov    dx,fofsh
  308.         mov    bx,fofsl
  309.         call    showscreen
  310.  
  311. shf020:        @KbdCharIn keydata,0,0
  312.         cmp    keydata.charascii,XX
  313.         jne    shf030
  314.         jmp    shf999
  315. shf030:        cmp    word ptr keydata.charascii,UP
  316.         je    shf032
  317.         cmp    word ptr keydata.charascii,AUP
  318.         jne    shf040
  319. shf032:        cmp    hexofs,0
  320.         jne    shf035
  321.         cmp    hexseg,0
  322.         jne    shf035
  323.         @DosBeep 1000,200
  324.         jmp    shf020
  325. shf035:        mov    di,hexofs
  326.         sub    hexofs,16*24
  327.         cmp    hexofs,di
  328.         jb    shf037
  329.         mov    ax,ds
  330.         sub    ax,shift
  331.         mov    ds,ax
  332.         dec    hexseg
  333. shf037:        push    hexseg
  334.         push    ds
  335.         call    showscreen
  336.         pop    ds
  337.         pop    hexseg
  338.         jmp    shf020
  339. shf040:        cmp    word ptr keydata.charascii,DN
  340.         je    shf042
  341.         cmp    word ptr keydata.charascii,ADN
  342.         jne    shf050
  343. shf042:        add    hexofs,16*24
  344. shf043:        cmp    dx,hexseg
  345.         jne    shf045
  346.         cmp    bx,hexofs
  347.         jae    shf045
  348.         @DosBeep 1000,200
  349.         sub    hexofs,16*24
  350.         jmp    shf020
  351. shf045:        call    showscreen
  352.         jmp    shf020
  353. shf050:        jmp    shf020
  354. shf999:        ret
  355. showfile    endp
  356.  
  357. showscreen    proc
  358.         push    hexofs
  359.         push    dx
  360.         push    bx
  361.         mov    dx,hexseg
  362.         mov    ax,hexofs
  363.         mov    bx,16*24
  364.         div    bx
  365.         mov    temp,ax
  366.         @bta    temp,topcur,4
  367.         @VioWrtCharStrAtt topmsg,80,0,0,green,0
  368.         pop    bx
  369.         pop    dx
  370.         mov    cx,24
  371.         mov    si,1
  372. shs010:        call    formatline
  373.         @VioWrtCharStr dline,80,si,1,0
  374.         add    hexofs,16
  375.         cmp    hexofs,0
  376.         jne    shs020
  377.         mov    ax,ds
  378.         add    ax,shift
  379.         mov    ds,ax
  380.         inc    hexseg
  381. shs020:        inc    si
  382.         loop    shs010
  383.         pop    hexofs
  384.         ret
  385. showscreen    endp
  386.  
  387. formatline    proc
  388.         push    cx
  389.         push    si
  390.         cmp    dx,hexseg
  391.         jne    fmt010
  392.         cmp    bx,hexofs
  393.         jae    fmt010
  394.         mov    cx,40
  395.         mov    ax,'  '
  396.         lea    di,dline
  397.         rep    stosw
  398.         jmp    fmt999
  399. fmt010:        mov    cx,16
  400.         mov    si,hexofs
  401.         lea    di,ddata-1
  402.         mov    al,'*'
  403.         stosb
  404.         rep    movsb
  405.         stosb
  406.         @bth    hexofs,dofsl,4
  407.         @bth    hexseg,dofsh,4
  408.         @bths    ddata+00,dhex1,4
  409.         @bths    ddata+04,dhex2,4
  410.         @bths    ddata+08,dhex3,4
  411.         @bths    ddata+12,dhex4,4
  412. fmt999:        pop    si
  413.         pop    cx
  414.         ret
  415. formatline    endp
  416.  
  417. os2parms    proc
  418. public        os2parms
  419.  
  420.         push    si
  421.         push    ds
  422.         push    cx
  423.         push    di
  424.         push    es
  425.         push    ax
  426.         mov    cx,64
  427.         mov    es,ax
  428.         mov    di,bx
  429.         mov    ax,0
  430.         repne    scasb
  431.         mov    ax,' '
  432.         repe    scasb
  433.         dec    di
  434.         pop    ds
  435.         pop    es
  436.         mov    si,di
  437.         pop    di
  438.         pop    cx
  439.         xor    ax,ax
  440. par010:        cmp    byte ptr [si],0
  441.         je    par999
  442.         movsb
  443.         inc    ax
  444.         loop    par010
  445.  
  446. par999:        pop    ds
  447.         pop    si
  448.         ret
  449. os2parms    endp
  450. os2bta        proc
  451. public        os2bta
  452. WBLEN        equ    5
  453.         push    bp
  454.         sub    sp,WBLEN
  455.         mov    bp,sp
  456.         push    ax
  457.         push    bx
  458.         push    cx
  459.         push    di
  460.         push    dx
  461.         xor    dx,dx
  462.         push    cx
  463.         push    di
  464.         push    ax
  465.         mov    al,' '
  466.         rep    stosb
  467.         pop    ax
  468.         pop    di
  469.         pop    cx
  470.         push    cx
  471.         mov    cx,WBLEN
  472.         mov    bx,10000
  473.         push    bp
  474. bta010:        div    bx
  475.         aam
  476.         or    ax,'00'
  477.         mov    ss:[bp],al
  478.         inc    bp
  479.         push    dx
  480.         mov    ax,bx
  481.         xor    dx,dx
  482.         mov    bx,10
  483.         div    bx
  484.         mov    bx,ax
  485.         pop    ax
  486.         loop    bta010
  487.         pop    bp
  488.         mov    cx,WBLEN-1
  489. bta015:        cmp    byte ptr ss:[bp],'0'
  490.         jne    bta020
  491.         mov    byte ptr ss:[bp],' '
  492.         inc    bp
  493.         loop    bta015
  494. bta020:        mov    ax,cx
  495.         pop    cx
  496.         cmp    ax,cx
  497.         jl    bta030
  498.         mov    al,'*'
  499.         rep    stosb
  500.         jmp    bta999
  501. bta030:        inc    ax
  502.         add    di,cx
  503.         sub    di,ax
  504.         mov    cx,ax
  505. bta035:        mov    al,ss:[bp]
  506.         stosb
  507.         inc    bp
  508.         loop    bta035
  509. bta999:        pop    dx
  510.         pop    di
  511.         pop    cx
  512.         pop    bx
  513.         pop    ax
  514.         add    sp,WBLEN
  515.         pop    bp
  516.         ret
  517. os2bta        endp
  518. os2bths        proc
  519. public        os2bths
  520.         push    bx
  521.         push    ax
  522.         xor    ax,ax
  523.         mov    bx,offset hextab
  524. bhs010:        lodsb
  525.         push    cx
  526.         push    ax
  527.         and    al,0f0h
  528.         mov    cl,4
  529.         shr    al,cl
  530.         push    bx
  531.         add    bx,ax
  532.         mov    al,byte ptr cs:[bx]
  533.         pop    bx
  534.         stosb
  535.         pop    ax
  536.         and    al,0fh
  537.         push    bx
  538.         add    bx,ax
  539.         mov    al,byte ptr cs:[bx]
  540.         pop    bx
  541.         stosb
  542.         pop    cx
  543.         loop    bhs010
  544. bhs999:        pop    ax
  545.         pop    bx
  546.         ret
  547. hextab        db    '0123456789ABCDEF'
  548. os2bths        endp
  549.  
  550. os2bth        proc
  551. public        os2bth
  552.         push    bx
  553.         push    cx
  554.         push    si
  555.         mov    si,offset hextab
  556.         push    ax
  557.         and    ax,0f000h
  558.         mov     cl,12
  559.         shr    ax,cl
  560.         mov    bx,ax
  561.         mov    al,byte ptr cs:[bx+si]
  562.         stosb
  563.         pop    ax
  564.         push    ax
  565.         and    ax,0f00h
  566.         mov    cl,8
  567.         shr    ax,cl
  568.         mov    bx,ax
  569.         mov    al,byte ptr cs:[bx+si]
  570.         stosb
  571.         pop    ax
  572.         push    ax    
  573.         and    ax,0f0h
  574.         mov    cl,4
  575.         shr    ax,cl
  576.         mov    bx,ax
  577.         mov    al,byte ptr cs:[bx+si]
  578.         stosb
  579.         pop    ax
  580.         and    ax,0fh
  581.         mov    bx,ax
  582.         mov    al,byte ptr cs:[bx+si]
  583.         stosb
  584. bth999:        pop    si
  585.         pop    cx
  586.         pop    bx
  587.         ret
  588. os2bth        endp
  589.  
  590. HEX_code    ends
  591.         end    main
  592.