home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm_kit / dpath.asm < prev    next >
Assembly Source File  |  1984-12-08  |  9KB  |  291 lines

  1.         page    60,132
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ;  Copyright (C) 1984  David Micon
  5. ;
  6. ;  This code may be freely copied or modified, but not sold for
  7. ;  profit.
  8. ;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.         title   data path
  11.         name    dpath
  12.  
  13. CR      equ     0dh
  14.  
  15. intseg  segment at 0
  16.         org     21h*4
  17. int21   label   word
  18. intseg  ends
  19.  
  20. code    segment para
  21.         assume  cs:code
  22.         org     100h
  23. start:
  24.         jmp     loaddpath
  25. oldint21 dd     ?               ;old interrupt
  26. lstptr  dw      ?               ;dir lst ptr
  27. defdrv  db      ?               ;default drive
  28. func    db      ?               ;interrupt function
  29. alsave  db      ?               ;interrupt al
  30. loadflag db     ?               ;load interrupt flag
  31.  
  32.         even
  33. dpathid equ     4213h
  34. id      dw      0
  35. newint21 label  far
  36.         sti
  37.         cmp     ah,0fh          ;open?
  38.         je      doint0f         ;yes
  39.         cmp     ah,17h          ;rename?
  40.         je      doint0f         ;yes
  41.         jmp     oldint21
  42. doint0f:
  43.         mov     func,ah         ;save function
  44.         mov     alsave,al       ;save al
  45.         pushf
  46.         call    oldint21        ;do open
  47.         cmp     al,0            ;in current dir?
  48.         jne     notincurrent    ;no
  49.         iret
  50. notincurrent:
  51.         mov     lstptr,81h      ;initialize lstptr
  52.         mov     ah,19h
  53.         int     21h             ;get default drive
  54.         mov     defdrv,al       ;save default drive
  55.         push    dx
  56.         push    si
  57.         push    ds
  58.         push    cs
  59.         pop     ds
  60.         mov     si,0
  61.         mov     byte ptr [si],'\' ;put in initial char
  62.         inc     si              ;to next char
  63.         xor     dl,dl           ;do default drive
  64.         mov     ah,47h
  65.         int     21h             ;get current directory
  66.         pop     ds
  67.         pop     si
  68.         pop     dx
  69. lstloop:
  70.         push    di
  71.         push    ds
  72.         push    cs
  73.         pop     ds              ;ds=cs
  74.         mov     di,ds:lstptr
  75.         cmp     byte ptr [di],0 ;done?
  76.         je      lstdone         ;yes
  77.         push    dx
  78.         mov     dl,defdrv       ;get default drive
  79.         mov     ah,0eh
  80.         int     21h             ;set default drive
  81.         cmp     byte ptr [di+1],':' ;drive change needed?
  82.         jne     nochgdrv        ;no
  83.         mov     dl,[di]         ;get drive letter
  84.         and     dl,0dfh         ;make upper case
  85.         sub     dl,'A'          ;convert to binary
  86.         mov     ah,0eh
  87.         int     21h             ;change default drive
  88. nochgdrv:
  89.         mov     dx,di           ;point to string
  90.         mov     ah,3bh
  91.         int     21h             ;change default directory
  92.         pop     dx
  93.         pop     ds
  94.         pop     di
  95.         jc      nxtlst          ;br if dir does not exist
  96.         mov     ah,func         ;set function
  97.         mov     al,alsave       ;restore al
  98.         pushf
  99.         call    oldint21        ;do function
  100.         cmp     al,0            ;function ok?
  101.         je      leave           ;yes
  102. nxtlst:
  103.         push    cx
  104.         push    di
  105.         push    es
  106.         push    cs
  107.         pop     es              ;es=cs
  108.         mov     di,lstptr       ;get list ptr
  109.         mov     cx,80h          ;set count
  110.         mov     al,0
  111.         repnz   scasb           ;look for null
  112.         mov     lstptr,di       ;set new list ptr
  113.         pop     es
  114.         pop     di
  115.         pop     cx
  116.         jmp     lstloop
  117. lstdone:
  118.         pop     ds
  119.         pop     di
  120.         mov     ah,func         ;put in func
  121.         mov     al,0ffh
  122. leave:
  123.         push    ax
  124.         push    dx
  125.         push    ds
  126.         push    cs
  127.         pop     ds              ;ds=cs
  128.         mov     dl,defdrv
  129.         mov     ah,0eh
  130.         int     21h             ;restore default drive
  131.         mov     dx,0
  132.         mov     ah,3bh
  133.         int     21h             ;set dir
  134.         pop     ds
  135.         pop     dx
  136.         pop     ax
  137.         iret
  138.  
  139. loaddpath:
  140.         call    srchdpath       ;dpath installed?
  141.         jnc     loaded          ;yes
  142.         mov     loadflag,1      ;set load flag
  143.         push    cs
  144.         pop     es
  145.         jmp     short procargs
  146. loaded:
  147.         mov     loadflag,0      ;reset load flag
  148.         mov     ax,es           ;get search seg
  149.         xor     dx,dx           ;clear high part
  150.         mov     cx,4
  151. shftlp:
  152.         shl     ax,1            ;shift low
  153.         rcl     dx,1            ;shift high
  154.         loop    shftlp
  155.         add     ax,di           ;add offset
  156.         adc     dx,0            ;add possible carry
  157.         sub     ax,(offset id-offset start)+102h ;sub offset
  158.         sbb     dx,0            ;sub possible borrow
  159.         mov     cx,4
  160. shftlp1:
  161.         shr     dx,1            ;shift high
  162.         rcr     ax,1            ;shift low
  163.         loop    shftlp1
  164.         mov     es,ax           ;point to old segment
  165. procargs:
  166.         push    cs
  167.         pop     ds              ;ds=cs
  168.         mov     si,81h          ;point to src
  169.         mov     di,si           ;point to dst
  170.         cld                     ;move forward
  171.         mov     byte ptr es:[di-1],1 ;make byte before 1st arg non-zero
  172. firstlp:
  173.         lodsb
  174.         cmp     al,' '          ;blank?
  175.         je      firstlp         ;yes
  176.         cmp     al,CR           ;CR?
  177.         jne     argloopst       ;no
  178.         cmp     loadflag,0      ;loaded?
  179.         je      prtdpath        ;yes
  180.         mov     dx,offset noloadmsg
  181.         mov     ah,9
  182.         int     21h             ;print msg
  183.         int     20h
  184. prtdpath:
  185.         mov     dx,offset dpathmsg
  186.         mov     ah,9
  187.         int     21h             ;print dpath msg
  188.         dec     si              ;move back
  189.         push    es
  190.         pop     ds              ;ds=es
  191.         mov     si,81h          ;point to beginning of path names
  192. prtloop:
  193.         lodsb                   ;get byte
  194.         cmp     al,0            ;null?
  195.         je      prtpathend      ;yes
  196.         mov     dl,al
  197.         mov     ah,2
  198.         int     21h             ;print char
  199.         jmp     prtloop
  200. prtpathend:
  201.         mov     dl,';'
  202.         mov     ah,2
  203.         int     21h             ;print semicolon
  204.         cmp     byte ptr [si],0 ;at end?
  205.         jne     prtloop         ;no
  206.         push    cs
  207.         pop     ds              ;ds=cs
  208.         mov     dx,offset crlfmsg
  209.         mov     ah,9
  210.         int     21h             ;print CRLF
  211.         int     20h
  212. argloopst:
  213.         dec     si              ;move back
  214. argloop:
  215.         lodsb                   ;get arg char
  216.         cmp     al,CR           ;CR?
  217.         je      docr            ;yes
  218.         cmp     al,' '          ;space?
  219.         je      argloop         ;yes, skip
  220.         cmp     al,';'          ;semicolon?
  221.         jne     notsemi         ;yes
  222.         mov     al,0            ;set null
  223. notsemi:
  224.         stosb                   ;put char in dst
  225.         jmp     argloop
  226. docr:
  227.         mov     al,0
  228.         cmp     al,byte ptr es:[di-1] ;already null at end?
  229.         je      nullatend       ;yes
  230.         stosb                   ;put in null
  231. nullatend:
  232.         stosb                   ;put in null
  233.         cmp     loadflag,0      ;load?
  234.         jne     doload          ;yes
  235.         int     20h
  236. doload:
  237.         mov     dx,offset loadmsg
  238.         mov     ah,9
  239.         int     21h
  240.         mov     id,dpathid
  241.         mov     ax,intseg
  242.         mov     ds,ax
  243.         assume  ds:intseg
  244.         mov     ax,int21+2      ;get int seg
  245.         mov     word ptr oldint21+2,ax ;save it
  246.         mov     ax,int21        ;get int offset
  247.         mov     word ptr oldint21,ax ;save it
  248.         mov     int21+2,cs      ;set new int seg
  249.         mov     int21,offset newint21 ;set new int offset
  250.         assume  ds:nothing
  251.         mov     dx,offset loaddpath
  252.         int     27h
  253.  
  254. srchdpath proc  near
  255.         xor     ax,ax           ;start at segment 0
  256.         cld
  257. blkloop:
  258.         mov     es,ax           ;set segment
  259.         mov     cx,4000h        ;set count
  260.         mov     di,0
  261.         mov     ax,dpathid
  262. loop1:
  263.         repnz   scasw           ;look for 1st word
  264.         jnz     nxtblk          ;no dpath found in this 32k block
  265.         push    cx              ;save cnt
  266.         push    di              ;save ptr
  267.         mov     si,offset id+2  ;set code offset
  268.         mov     cx,(offset loaddpath-offset id)-2
  269.         repz    cmpsb           ;see if rest is here
  270.         pop     di              ;restore ptr
  271.         pop     cx              ;restore cnt
  272.         jnz     loop1           ;search unsuccessful
  273.         clc                     ;set found flag
  274.         ret
  275. nxtblk:
  276.         mov     ax,es           ;get es
  277.         add     ax,800h         ;to next block
  278.         mov     dx,cs
  279.         cmp     ax,dx           ;done?
  280.         jb      blkloop         ;no
  281.         stc                     ;set not found flag
  282.         ret
  283. srchdpath endp
  284.  
  285. loadmsg db      'Resident part of dpath loaded',13,10,'$'
  286. noloadmsg db    'Dpath not loaded'
  287. crlfmsg db      13,10,'$'
  288. dpathmsg db     'DPATH=$'
  289. code    ends
  290.         end     start
  291.