home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / SORT01.ASM < prev    next >
Assembly Source File  |  1994-11-03  |  2KB  |  79 lines

  1. ;***************************** SORT01.ASM ***********************************
  2.  
  3. LIBSEG           segment byte public "LIB"
  4.         assume cs:LIBSEG , ds:nothing
  5.  
  6. ;----------------------------------------------------------------------------
  7. .xlist
  8.     include  mac.inc
  9.     include  common.inc
  10.     extrn     dos_mem_allocate:far
  11.     extrn     dos_mem_release:far
  12.  
  13.     extrn    make_index:near
  14.     extrn    order_buffer:near
  15.  
  16.     extrn    sort_engine:word
  17.     extrn    sort_field_len:byte
  18.     extrn    sort_column:word
  19.     extrn    last_sort_column:word
  20.     extrn    buffer_off:word
  21.     
  22. .list
  23. comment 
  24. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  SORT   )
  25. ; buffer sort, allocate memory for index.
  26. ;  inputs:  es:di = pointer to buffer, or asciiz if file
  27. ;              cx = buffer length, or zero if file
  28. ;              bx = record length if fixed length, else zero if variable len.
  29. ;              al = record terminator for variable lenght records. else zero
  30. ;   output: carry set if insufficient memory
  31. ;           no carry - cx = partial record size
  32. ;
  33. ;* * * * * * * * * * * * * *
  34. 
  35. index_seg    dw    0
  36. bs_buf_off    dw    0
  37.  
  38.     public    buffer_sort
  39. buffer_sort    proc    near
  40.     apush    ax,es
  41.     mov    dx,0
  42.     mov    ax,0f000h        ;allocate 61k bytes for index
  43.     call    dos_mem_allocate    ;retruns es: = memory seg
  44.     jc    no_memory1        ;jmp if error
  45.     mov    cs:index_seg,es        ;save index
  46.     push    es
  47.     pop    ds            ;index buf seg now in -ds-
  48.     apop    es,ax            ;restore data buf seg
  49.  
  50.     call    make_index        ;build index buffer
  51.     push    cx            ;save partial record size
  52.     
  53.     mov    cl,cs:sort_field_len    ;get length of sort field
  54.     mov    ch,0            ;just incase
  55.     mov    dx,cs:sort_column    ;get starting byte posn
  56.     mov    cs:last_sort_column,dx
  57.     add    cs:last_sort_column,cx
  58.     mov    ax,cs:buffer_off    ;get buffer start    
  59.     call    sort_engine        ;near call
  60.  
  61.     push    es
  62.     pop    ds            ;ds=buffer seg
  63.     mov    si,cs:bs_buf_off
  64.     mov    dx,cs:index_seg
  65.     call    order_buffer        ;move all records to correct location
  66.     jc    no_memory2
  67.         
  68.     mov    es,cs:index_seg
  69.     call    dos_mem_release        ;release index
  70.     clc        
  71. no_memory2:    
  72.     pop    cx
  73. no_memory1:
  74.     ret
  75. buffer_sort    endp
  76.  
  77. LIBSEG    ENDS
  78.     end
  79.