home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / cexpress / files / rmsubdir.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  3.8 KB  |  135 lines

  1. ;void  remove_subdirectory(tree_array,position);
  2. ;  char  *tree_array;
  3. ;  unsigned short  position;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _tree_array_size:word
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _remove_subdirectory
  12. _remove_subdirectory proc near
  13.     jmp  short start    ;jump over local data
  14. holder  dw   ?            ;
  15. array_address dd ?        ;
  16. start:    push bp            ;
  17.     mov  bp,sp        ;
  18.     push di            ;
  19.     push si            ;
  20.     cmp  _memory_model,0    ;near or far?
  21.     jle  begin        ;jump if near
  22.     inc  bp            ;else add 2 to BP
  23.     inc  bp            ;
  24. begin:    push ds            ;
  25.     cmp  _memory_model,2    ;data near or far?
  26.     jb   A0            ;jump if near
  27.     les  di,dword ptr[bp+4]    ;
  28.     add  di,21        ;start with array element 1
  29.     mov  word ptr cs:array_address,di 
  30.     mov  word ptr cs:array_address+2,es
  31.     add  bp,2        ;
  32.     jmp  short A1        ;
  33. A0:    mov  ax,[bp+4]        ;
  34.     add  ax,21        ;start with array element 1
  35.     mov  word ptr cs:array_address,ax
  36.     mov  word ptr cs:array_address+2,ds
  37. A1:    mov  ax,[bp+6]        ;fetch Position
  38.     or   ax,ax        ;zero?
  39.     jz   A2            ;quit if so
  40.     mov  _error_code,1    ;1 = Position out of range
  41.     mov  bx,_tree_array_size ;meaningless to eliminate only element of array
  42.     cmp  bx,1        ;
  43.     jbe  A2            ;
  44.     cmp  ax,bx        ;Position in range?
  45.     jna  B1            ;quit if so
  46. A2:    jmp  K1            ;
  47. B1:    dec  _error_code    ;0 = no error
  48.     push _tree_array_size    ;
  49.     dec  _tree_array_size    ;
  50.     dec  ax            ;count records from zero
  51.     les  di,dword ptr cs:array_address  ;point to array
  52.     mov  dl,21        ;bytes per record
  53.     mul  dl            ;
  54.     add  di,ax        ;ES:DI pts to record
  55.     push es            ;save record pointer
  56.     push di            ;
  57.     mov  bx,15        ;offsets when first below parent:
  58.     push bx            ;
  59.     mov  bx,13        ;
  60.     cmp  word ptr es:[di+17],0 ;is there a Prior?
  61.     je   C1            ;jump if not
  62.     pop  bx            ;offset when not first below parent:
  63.     mov  bx,19        ;
  64.     push bx            ;
  65.     mov  bx,17        ;
  66. C1:    mov  cx,es:[di][bx]    ;get Parent record number
  67.     mov  word ptr cs:holder,0 ;default value for Parent's Child field
  68.     cmp  word ptr es:[di+19],0  ;is there a Next?
  69.     je   D1            ;jump if not
  70.     mov  ax,es:[di+19]    ;get Next record number
  71.     mov  cs:holder,ax    ;save for Parent-Child/Prior-Next field
  72.     lds  si,dword ptr cs:array_address ;point DS:SI to Next
  73.     mov  dl,21        ;
  74.     dec  ax            ;
  75.     mul  dl            ;
  76.     add  si,ax        ;
  77.     mov  word ptr[si+17],0    ;default: change Prior in Next to zero
  78.     cmp  bx,13        ;test whether Child case or Next case
  79.     je   D1            ;jump if child
  80.     mov  word ptr[si+17],cx ;else change Prior in Next to Prior record
  81. D1:    mov  ax,cx        ;
  82.     lds  si,dword ptr cs:array_address ;point DS:SI to Parent
  83.     mov  dl,21        ;
  84.     dec  ax            ;
  85.     mul  dl            ;
  86.     add  si,ax        ;
  87.     mov  ax,cs:holder    ;set Parent/Prior child field
  88.     pop  bx            ;get field offset
  89.     mov  [si][bx],ax    ;
  90.     pop  di            ;point ES:DI back to record
  91.     pop  es            ;
  92.     mov  si,di        ;point DS:SI 21 bytes higher
  93.     mov  ax,es        ;
  94.     mov  ds,ax        ;
  95.     add  si,21        ;
  96.     pop  ax            ;fetch _tree_array_size        
  97.     mov  dx,ax        ;make copy
  98.     mov  bx,[bp+6]        ;get Position again
  99.     sub  ax,bx        ;number records to shift
  100.     mov  cl,21        ;bytes per record
  101.     mul  cl            ;
  102.     mov  cx,ax        ;bytes to move in CX
  103.     jcxz E1            ;no shift if last record
  104.     cld            ;move records down
  105.     rep  movsb        ;
  106. E1:    mov  cx,dx        ;number records
  107.     dec  cx            ;minus one removed
  108.     lds  si,dword ptr cs:array_address  ;DS:SI pts to array
  109.     mov  bx,[bp+6]        ;number of removed record
  110. F1:    cmp [si+13],bx        ;Parent above or equal?
  111.     jna G1            ;jump if below
  112.     dec word ptr[si+13]    ;else decrement
  113. G1:    cmp [si+15],bx        ;Child
  114.     jna H1            ;
  115.     dec word ptr[si+15]    ;
  116. H1:    cmp [si+17],bx        ;Prior
  117.     jna I1            ;
  118.     dec word ptr[si+17]    ;
  119. I1:    cmp [si+19],bx        ;Next
  120.     jna J1            ;
  121.     dec word ptr[si+19]    ;
  122. J1:    add  si,21        ;forward to next record
  123.     loop F1            ;scan all records
  124. K1:    pop  ds            ;
  125.     pop  si            ;
  126.     pop  di            ;
  127.     pop  bp            ;
  128.     cmp  _memory_model,0    ;quit
  129.     jle  quit        ;
  130.     db   0CBh        ;RET far
  131. quit:    ret            ;RET near
  132. _remove_subdirectory  endp
  133. _TEXT    ENDS
  134.     END
  135.