Changeset 46 in xtideuniversalbios for trunk/Assembly_Library/Src/Util/Sort.asm


Ignore:
Timestamp:
Oct 4, 2010, 7:38:36 AM (14 years ago)
Author:
aitotat
google:author:
aitotat
Message:

Changes to Assembly Library:
Sorting now works (pivot item is copied for comparison and index comparisons are now signed instead of unsigned).
Menu shadow now looks better on black and white modes.
Sorting is now implemented for File Fialog: directories are displayed before files.
File Dialog now displays directories with upper case letters and files with lower case letters.
Line splitter now removes all empty lines from the end.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Assembly_Library/Src/Util/Sort.asm

    r45 r46  
    22; Project name  :   Assembly Library
    33; Created date  :   28.9.2010
    4 ; Last update   :   29.9.2010
     4; Last update   :   1.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Sorting algorithms
     
    99
    1010struc QSORT_PARAMS
    11     .lpItems        resb    4
    12     .tempStruct:
     11    .lpItems            resb    4
     12    .tempAndPivotItems:
    1313endstruc
    1414
     
    1616; Prototype for comparator callback function
    1717;   Parameters:
    18 ;       DS:SI:  Offset to first item to compare
    19 ;       ES:DI:  Offset to second item to compare
     18;       CX:     Item size in bytes
     19;       DS:SI:  Ptr to first item to compare
     20;       ES:DI:  Ptr to second item to compare
    2021;   Returns:
    2122;       FLAGS:  Signed comparition between first and second item
     
    2930
    3031;--------------------------------------------------------------------
    31 ; DialogFile_GetFileNameWithIoInDSSI
    32 ;   Parameters:
    33 ;       DS:SI:  Ptr to FILE_DIALOG_IO
    34 ;       SS:BP:  Ptr to parent MENU
     32; Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
     33;   Parameters:
     34;       CX:     Item size in bytes
     35;       DX:     Number of items to sort (signed)
     36;       CS:BX:  Comparator function
     37;       DS:SI:  Ptr to array of items to sort
    3538;   Returns:
    3639;       Nothing
     
    4245    push    es
    4346    push    di
     47    mov     di, cx
     48    shl     cx, 1                       ; Reserve temp and pivot items
    4449    add     cx, BYTE QSORT_PARAMS_size
    4550    eENTER_STRUCT cx
     51    push    cx
    4652
    4753    cld
    48     sub     cx, BYTE QSORT_PARAMS_size  ; Restore CX to item size
    49     xor     ax, ax                      ; Zero for starting index
     54    mov     cx, di                      ; Restore item size to CX
     55    xor     ax, ax                      ; Zero starting index
    5056    dec     dx                          ; Count to index of last item
    5157    mov     [bp+QSORT_PARAMS.lpItems], si
     
    5460
    5561    lds     si, [bp+QSORT_PARAMS.lpItems]
    56     add     cx, BYTE QSORT_PARAMS_size
    57     eLEAVE_STRUCT cx
     62    pop     ax
     63    eLEAVE_STRUCT ax
    5864    pop     di
    5965    pop     es
     
    8692    ; Does left partition need more sorting
    8793    cmp     si, dx          ; if (first index < Index of rightmost unsorted item)
    88     jae     SHORT .CheckIfRightPartitionNeedsMoreSorting
     94    jge     SHORT .CheckIfRightPartitionNeedsMoreSorting
    8995    xchg    ax, si          ; AX = first index, SI = Index of leftmost unsorted item
    9096    call    QuicksortItemsInRangeFromAXtoDXwithQsortParamsInSSBP
     
    9399.CheckIfRightPartitionNeedsMoreSorting:
    94100    cmp     ax, di          ; if (Index of leftmost unsorted item < last index)
    95     jae     SHORT .SortCompleted
     101    jge     SHORT .SortCompleted
    96102    mov     dx, di          ; DI = Index of leftmost unsorted item
    97103    call    QuicksortItemsInRangeFromAXtoDXwithQsortParamsInSSBP
     
    133139.GetPivotPointerToESDI:
    134140    push    ax
     141
    135142    add     ax, dx
    136     shr     ax, 1
     143    shr     ax, 1           ; AX = Middle index in partition
    137144    call    GetItemPointerToDSSIfromIndexInAX
     145    call    GetPointerToTemporaryItemToESDI
     146    add     di, cx          ; Pivot is after temporary item
     147    call    CopyItemFromDSSItoESDI
     148    sub     di, cx          ; Restore DI
     149
    138150    pop     ax
    139     jmp     Memory_ExchangeDSSIwithESDI
     151    ret
    140152
    141153
     
    158170ArrangeItemsInRangeAXtoDXtoBothSidesOfPivotInESDI:
    159171    cmp     ax, dx  ; while (left <= right)
    160     ja      SHORT .BreakLoopSinceAllItemsExamined
     172    jg      SHORT .BreakLoopSinceAllItemsExamined
    161173
    162174    call    GetItemPointerToDSSIfromIndexInAX
     
    167179
    168180    cmp     ax, dx  ; If (left <= right)
    169     ja      SHORT ArrangeItemsInRangeAXtoDXtoBothSidesOfPivotInESDI
     181    jg      SHORT ArrangeItemsInRangeAXtoDXtoBothSidesOfPivotInESDI
    170182    call    SwapItemsFromIndexesAXandDX
    171183    inc     ax
     
    213225
    214226    ; Item AX to stack
    215     call    .GetPtrToTemporaryStructToESDI
     227    call    GetPointerToTemporaryItemToESDI
    216228    call    GetItemPointerToDSSIfromIndexInAX
    217     call    .CopyItemFromDSSItoESDI
     229    call    CopyItemFromDSSItoESDI
    218230
    219231    ; Item DX to Item AX
    220232    call    Memory_ExchangeDSSIwithESDI
    221233    call    GetItemPointerToDSSIfromIndexInDX
    222     call    .CopyItemFromDSSItoESDI
     234    call    CopyItemFromDSSItoESDI
    223235
    224236    ; Stack to Item DX
    225     call    .GetPtrToTemporaryStructToESDI
     237    call    GetPointerToTemporaryItemToESDI
    226238    call    Memory_ExchangeDSSIwithESDI
    227     call    .CopyItemFromDSSItoESDI
     239    call    CopyItemFromDSSItoESDI
    228240
    229241    pop     di
     
    231243    ret
    232244
    233 ALIGN JUMP_ALIGN
    234 .GetPtrToTemporaryStructToESDI:
    235     lea     di, [bp+QSORT_PARAMS.tempStruct]
     245
     246;--------------------------------------------------------------------
     247; GetPointerToTemporaryItemToESDI
     248;   Parameters:
     249;       SS:BP:  Ptr to QSORT_PARAMS
     250;   Returns:
     251;       ES:DI:  Ptr to temporary item
     252;   Corrupts registers:
     253;       Nothing
     254;--------------------------------------------------------------------
     255ALIGN JUMP_ALIGN
     256GetPointerToTemporaryItemToESDI:
     257    lea     di, [bp+QSORT_PARAMS.tempAndPivotItems]
    236258    push    ss
    237259    pop     es
    238     ret
    239 
    240 ALIGN JUMP_ALIGN
    241 .CopyItemFromDSSItoESDI:
    242     push    si
    243     push    cx
    244 
    245     shr     cx, 1           ; We want to copy WORDs for performance
    246     jcxz    .CopyLastByte
    247     rep     movsw
    248 .CopyLastByte:
    249     jnc     SHORT .CopyComplete
    250     movsb
    251 .CopyComplete:
    252     pop     cx
    253     pop     si
    254260    ret
    255261
     
    286292    pop     dx
    287293    ret
     294
     295
     296;--------------------------------------------------------------------
     297; CopyItemFromDSSItoESDI
     298;   Parameters:
     299;       CX:     Item size in bytes
     300;       DS:SI:  Ptr to source item
     301;       ES:DI:  Ptr to destination buffer
     302;   Returns:
     303;       Nothing
     304;   Corrupts registers:
     305;       DI
     306;--------------------------------------------------------------------
     307ALIGN JUMP_ALIGN
     308CopyItemFromDSSItoESDI:
     309    call    Memory_CopyCXbytesFromDSSItoESDI
     310    sub     si, cx          ; Restore SI
     311    ret
Note: See TracChangeset for help on using the changeset viewer.