home *** CD-ROM | disk | FTP | other *** search
- ;void remove_subdirectory(tree_array,position);
- ; char *tree_array;
- ; unsigned short position;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _tree_array_size:word
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _remove_subdirectory
- _remove_subdirectory proc near
- jmp short start ;jump over local data
- holder dw ? ;
- array_address dd ? ;
- start: push bp ;
- mov bp,sp ;
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;
- cmp _memory_model,2 ;data near or far?
- jb A0 ;jump if near
- les di,dword ptr[bp+4] ;
- add di,21 ;start with array element 1
- mov word ptr cs:array_address,di
- mov word ptr cs:array_address+2,es
- add bp,2 ;
- jmp short A1 ;
- A0: mov ax,[bp+4] ;
- add ax,21 ;start with array element 1
- mov word ptr cs:array_address,ax
- mov word ptr cs:array_address+2,ds
- A1: mov ax,[bp+6] ;fetch Position
- or ax,ax ;zero?
- jz A2 ;quit if so
- mov _error_code,1 ;1 = Position out of range
- mov bx,_tree_array_size ;meaningless to eliminate only element of array
- cmp bx,1 ;
- jbe A2 ;
- cmp ax,bx ;Position in range?
- jna B1 ;quit if so
- A2: jmp K1 ;
- B1: dec _error_code ;0 = no error
- push _tree_array_size ;
- dec _tree_array_size ;
- dec ax ;count records from zero
- les di,dword ptr cs:array_address ;point to array
- mov dl,21 ;bytes per record
- mul dl ;
- add di,ax ;ES:DI pts to record
- push es ;save record pointer
- push di ;
- mov bx,15 ;offsets when first below parent:
- push bx ;
- mov bx,13 ;
- cmp word ptr es:[di+17],0 ;is there a Prior?
- je C1 ;jump if not
- pop bx ;offset when not first below parent:
- mov bx,19 ;
- push bx ;
- mov bx,17 ;
- C1: mov cx,es:[di][bx] ;get Parent record number
- mov word ptr cs:holder,0 ;default value for Parent's Child field
- cmp word ptr es:[di+19],0 ;is there a Next?
- je D1 ;jump if not
- mov ax,es:[di+19] ;get Next record number
- mov cs:holder,ax ;save for Parent-Child/Prior-Next field
- lds si,dword ptr cs:array_address ;point DS:SI to Next
- mov dl,21 ;
- dec ax ;
- mul dl ;
- add si,ax ;
- mov word ptr[si+17],0 ;default: change Prior in Next to zero
- cmp bx,13 ;test whether Child case or Next case
- je D1 ;jump if child
- mov word ptr[si+17],cx ;else change Prior in Next to Prior record
- D1: mov ax,cx ;
- lds si,dword ptr cs:array_address ;point DS:SI to Parent
- mov dl,21 ;
- dec ax ;
- mul dl ;
- add si,ax ;
- mov ax,cs:holder ;set Parent/Prior child field
- pop bx ;get field offset
- mov [si][bx],ax ;
- pop di ;point ES:DI back to record
- pop es ;
- mov si,di ;point DS:SI 21 bytes higher
- mov ax,es ;
- mov ds,ax ;
- add si,21 ;
- pop ax ;fetch _tree_array_size
- mov dx,ax ;make copy
- mov bx,[bp+6] ;get Position again
- sub ax,bx ;number records to shift
- mov cl,21 ;bytes per record
- mul cl ;
- mov cx,ax ;bytes to move in CX
- jcxz E1 ;no shift if last record
- cld ;move records down
- rep movsb ;
- E1: mov cx,dx ;number records
- dec cx ;minus one removed
- lds si,dword ptr cs:array_address ;DS:SI pts to array
- mov bx,[bp+6] ;number of removed record
- F1: cmp [si+13],bx ;Parent above or equal?
- jna G1 ;jump if below
- dec word ptr[si+13] ;else decrement
- G1: cmp [si+15],bx ;Child
- jna H1 ;
- dec word ptr[si+15] ;
- H1: cmp [si+17],bx ;Prior
- jna I1 ;
- dec word ptr[si+17] ;
- I1: cmp [si+19],bx ;Next
- jna J1 ;
- dec word ptr[si+19] ;
- J1: add si,21 ;forward to next record
- loop F1 ;scan all records
- K1: pop ds ;
- pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _remove_subdirectory endp
- _TEXT ENDS
- END