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

  1. ;unsigned short  connecting_line(array_position,level,tree_array);
  2. ;  char  *tree_array;
  3. ;  unsigned short  array_position,level;
  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 _connecting_line
  12. _connecting_line proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;
  15.     push di            ;
  16.     cmp  _memory_model,0    ;near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bp            ;else add 2 to BP
  19.     inc  bp            ;
  20. begin:    mov  _error_code,0    ;default value
  21.     mov  dx,1        ;let dx count levels
  22.     mov  ax,[bp+4]        ;get array position
  23.     or   ax,ax        ;test for zero
  24.     jz   L2            ;quit if zero
  25.     cmp  ax,_tree_array_size ;in range?
  26.     jna  L2            ;jump ahead if OK
  27.     inc  _error_code    ;
  28.     jmp  short L9        ;jump ahead and quit
  29. L2:    call FigureOffset    ;figure offset of element in array
  30.     add  di,13        ;point to parent field    
  31.     mov  bx,es:[di]        ;fetch parent pointer
  32.     or   bx,bx        ;test if pts to root dir
  33.     jz   L3            ;jump if no higher levels
  34.     inc  dx            ;else increment level counter
  35.     mov  ax,bx        ;new offset
  36.     jmp  short L2        ;go check parent element
  37. L3:    mov  bx,[bp+6]        ;level to check for in BX
  38.     cmp  bx,dx        ;compare to level of subdir
  39.     ja   L8            ;quit if level is greater than
  40.     sub  dx,bx        ;number levels higher must seek
  41.     or   dx,dx        ;does Level match level of subdir?
  42.     jnz  L5            ;jump ahead if not
  43.     mov  ax,[bp+4]        ;element position in array
  44.     call FigureOffset    ;figure offset
  45.     add  di,19        ;point to Next field
  46.     test word ptr es:[di],0FFFFh ;is it zero?
  47.     jz   L4            ;jump if so
  48.     mov  ax,1        ;use straight char
  49.     jmp  short L0        ;quit
  50. L4:    mov  ax,2        ;use corner char
  51.     jmp  short L0        ;quit
  52. L5:    mov  ax,[bp+4]        ;array position
  53. L6:    call FigureOffset    ;will climb up to specified level
  54.     or   dx,dx        ;search finished?
  55.     jz   L7            ;jump if so
  56.     dec  dx            ;dec level counter
  57.     add  di,13        ;point to parent field    
  58.     mov  ax,es:[di]        ;fetch parent pointer
  59.     jmp  short L6        ;loop up to next level
  60. L7:    test  word ptr es:[di+19],0FFFFh ;test for zero
  61.     jz    L9        ;jump if zero
  62.     mov   ax,1        ;1 = straight segment
  63.     jmp   short L0        ;quit
  64. L8:    mov  _error_code,2    ;2 = level > subdir level
  65. L9:    sub  ax,ax        ;return 0
  66. L0:    pop  di            ;
  67.     pop  bp            ;
  68.     cmp  _memory_model,0    ;quit
  69.     jle  quit        ;
  70.     db   0CBh        ;RET far
  71. quit:    ret            ;RET near
  72. _connecting_line  endp
  73. figureoffset PROC
  74.     cmp  _memory_model,2    ;data near or far?
  75.     jb   A1            ;    
  76.     les  di,dword ptr[bp+8] ;ES:DI pts to array
  77.     add  di,21        ;start with array element 1
  78.     jmp  short A2        ;
  79. A1:    push ds            ;near case
  80.     pop  es            ;
  81.     mov  di,[bp+8]        ;
  82.     add  di,21        ;start with array element 1
  83. A2:    dec  ax            ;count from zero to get offset
  84.     mov  cl,21        ;byte per element
  85.     mul  cl            ;calculate offset
  86.     add  di,ax        ;now ES:DI pts to element
  87.     ret            ;
  88. figureoffset endp
  89. _TEXT    ENDS
  90.     END
  91.