Changeset 46 in xtideuniversalbios


Ignore:
Timestamp:
Oct 4, 2010, 7:38:36 AM (13 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.

Location:
trunk/Assembly_Library/Src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Assembly_Library/Src/LibraryTests.asm

    r45 r46  
    3333    CALL_DISPLAY_LIBRARY ClearScreen
    3434
    35     call    LibraryTests_Sort
     35    ;call   LibraryTests_Sort
    3636    ;call   LibraryTests_ForDisplayLibrary
    3737    ;call   LibraryTests_ForKeyboardLibrary
    38     ;call   LibraryTests_ForMenuLibrary
     38    call    LibraryTests_ForMenuLibrary
    3939
    4040    ; Exit to DOS
     
    571571    push    ax
    572572    mov     ax, [si]
    573     ;DISPLAY_DEBUG_CHARACTER 'I'
    574     ;DISPLAY_DEBUG_WORD_AND_WAIT_ANY_KEY ax, 10
    575     ;DISPLAY_DEBUG_CHARACTER ','
    576     ;DISPLAY_DEBUG_WORD_AND_WAIT_ANY_KEY [es:di], 10
    577     ;DISPLAY_DEBUG_CHARACTER ' '
     573    DISPLAY_DEBUG_CHARACTER 'I'
     574    DISPLAY_DEBUG_WORD_AND_WAIT_ANY_KEY ax, 16
     575    DISPLAY_DEBUG_CHARACTER ','
     576    DISPLAY_DEBUG_WORD_AND_WAIT_ANY_KEY [es:di], 16
     577    DISPLAY_DEBUG_CHARACTER ' '
    578578    cmp     ax, [es:di]
    579579    pop     ax
     
    586586    pop     ds
    587587    mov     si, .rgwItems
    588     mov     bx, 10
     588    mov     bx, 16
    589589.Loop:
    590590    lodsw
     
    596596
    597597.rgwItems:
    598     dw      435
    599     dw      -31551
    600     dw      345
    601     dw      0
    602     dw      -18
    603     dw      23
    604     dw      435
     598    dw      '['
     599    dw      'n'
     600    dw      '5'
     601    dw      '.'
     602    dw      ']'
     603    dw      'a'
     604    dw      'A'
    605605
    606606
  • trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm

    r44 r46  
    22; Project name  :   Assembly Library
    33; Created date  :   6.8.2010
    4 ; Last update   :   27.9.2010
     4; Last update   :   1.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Common functions for many dialogs.
     
    2828    eENTER_STRUCT DIALOG_size
    2929
    30     mov     cx, DIALOG_size / 2
    31     call    Memory_ZeroSSBPbyWordsInCX
     30    mov     cx, DIALOG_size
     31    call    Memory_ZeroSSBPwithSizeInCX
    3232    mov     [bp+DIALOG.fpDialogIO], si
    3333    mov     [bp+DIALOG.fpDialogIO+2], ds
  • trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm

    r45 r46  
    22; Project name  :   Assembly Library
    33; Created date  :   6.9.2010
    4 ; Last update   :   28.9.2010
     4; Last update   :   4.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Displays file dialog.
     
    112112    call    LoadItemStringBufferToESDI
    113113    call    CreateStringFromCurrentDirectoryContentsToESDI
     114    call    LoadItemStringBufferToESDI
     115    call    SortDirectoryContentsStringFromESDIwithCountInCX
    114116    push    ss
    115117    pop     ds
     
    120122    CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
    121123    mov     [bp+MENUINIT.bHeight], ah               ; Always max height
    122     mov     WORD [bp+MENU.wHighlightedItem], 0
     124    xor     ax, ax
     125    mov     [bp+MENU.wHighlightedItem], ax
     126    mov     [bp+MENU.wFirstVisibleItem], ax
    123127    ret
    124128
     
    146150;       SS:BP:  Ptr to DIALOG
    147151;   Returns:
    148 ;       Nothing
    149 ;   Corrupts registers:
    150 ;       AX, CX, DX, SI, DI, DS, ES
     152;       CX:     Number of files or directories found
     153;   Corrupts registers:
     154;       AX, DX, SI, DI, DS, ES
    151155;--------------------------------------------------------------------
    152156ALIGN JUMP_ALIGN
     
    160164    call    Directory_GetDiskTransferAreaAddressToDSSI
    161165    rcl     cx, 1           ; Restore CF
     166    xor     cx, cx          ; Clear file/directory count
    162167    ; Fall to .FindMatchingFilesAndWriteThemToESDI
    163168
     
    165170; .FindMatchingFilesAndWriteThemToESDI
    166171;   Parameters:
     172;       CX:     Initial directory count
    167173;       DL:     Zero if root directory selected
    168174;       DS:SI:  Ptr to DTA with first matching file
    169175;       ES:DI:  Ptr to destination string buffer
    170176;   Returns:
    171 ;       Nothing
    172 ;   Corrupts registers:
    173 ;       AX, CX, DX, DI
     177;       CX:     Incremented by number of files/directories found
     178;   Corrupts registers:
     179;       AX, DX, DI
    174180;--------------------------------------------------------------------
    175181;ALIGN JUMP_ALIGN
    176182.FindMatchingFilesAndWriteThemToESDI:
    177     jc      SHORT RemoveLastLFandTerminateESDIwithNull
     183    jc      SHORT TerminateESDIwithNull
    178184    call    AppendFileToBufferInESDIfromDtaInDSSI
    179185    call    Directory_UpdateDTAForNextMatchUsingPreviousParameters
     
    200206    ret
    201207
    202 ;--------------------------------------------------------------------
    203 ; RemoveLastLFandTerminateESDIwithNull
     208
     209;--------------------------------------------------------------------
     210; TerminateESDIwithNull
    204211;   Parameters:
    205212;       ES:DI:  Ptr to destination string buffer
     
    210217;--------------------------------------------------------------------
    211218ALIGN JUMP_ALIGN
    212 RemoveLastLFandTerminateESDIwithNull:
     219TerminateESDIwithNull:
    213220    xor     ax, ax
    214     dec     di              ; Remove last LF
    215221    stosb
    216222    ret
    217223
     224
    218225;--------------------------------------------------------------------
    219226; AppendFileToBufferInESDIfromDtaInDSSI
    220227;   Parameters:
     228;       CX:     Files/directores found
    221229;       DL:     Zero if root directory selected
    222230;       DS:SI:  Ptr to DTA containing file information
    223231;       ES:DI:  Ptr to destination string buffer
    224232;   Returns:
     233;       CX:     Incremented by number of files/directories found
    225234;       DI:     Updated for next file
    226235;   Corrupts registers:
    227 ;       AX, BX, CX, DX
     236;       AX, BX, DX
    228237;--------------------------------------------------------------------
    229238ALIGN JUMP_ALIGN
     
    231240    call    .FilterCurrentDirectory         ; We never want "."
    232241    call    .FilterUpDirectoryWhenInRoot    ; No ".." when in root directory
     242    inc     cx                              ; Nothing filtered so increment files/directories
    233243    ; Fall to .PrepareBufferFormattingAndFormatFromDTAinDSSI
    234244
     
    241251;       DI:     Updated for next file
    242252;   Corrupts registers:
    243 ;       AX, BX, CX, DX
     253;       AX, BX, DX
    244254;--------------------------------------------------------------------
    245255;ALIGN JUMP_ALIGN
     
    247257    push    bp
    248258    push    si
    249     mov     cx, di
     259    push    cx
     260    mov     bx, di
    250261    CALL_DISPLAY_LIBRARY PushDisplayContext
    251262
     263    xchg    ax, bx
    252264    mov     bx, es
    253     xchg    ax, cx
    254265    CALL_DISPLAY_LIBRARY SetCharacterPointerFromBXAX
    255266    mov     bl, ATTRIBUTES_NOT_USED
     
    261272    CALL_DISPLAY_LIBRARY GetCharacterPointerToBXAX
    262273    mov     es, bx
    263     xchg    cx, ax
     274    xchg    bx, ax
    264275    CALL_DISPLAY_LIBRARY PopDisplayContext
    265     mov     di, cx
     276    mov     di, bx
     277    pop     cx
    266278    pop     si
    267279    pop     bp
     
    281293    mov     bp, sp
    282294    lea     ax, [si+DTA.szFile]
    283     push    ax
    284     push    ds
    285295
    286296    test    BYTE [si+DTA.bFileAttributes], FLG_FILEATTR_DIRECTORY
    287297    jnz     SHORT .FormatDirectory
    288 
     298    ; Fall to .FormatFile
     299
     300;--------------------------------------------------------------------
     301; .FormatFile
     302;   Parameters:
     303;       BP:     SP before pushing formatting parameters
     304;       DS:AX:  Far pointer to file name
     305;       DS:SI:  Ptr to DTA containing file information
     306;   Returns:
     307;       Nothing
     308;   Corrupts registers:
     309;       AX, BX, CX, DX, SI, DI, BP
     310;--------------------------------------------------------------------
     311.FormatFile:
     312    ; Push parameters for file name
     313    xchg    si, ax
     314    call    String_ConvertDSSItoLowerCase
     315    xchg    ax, si
     316    push    ax              ; Push directory name offset
     317    push    ds              ; Push directory name segment
     318
     319    ; Push parameters for file size
    289320    mov     ax, [si+DTA.dwFileSize]
    290321    mov     dx, [si+DTA.dwFileSize+2]
     
    298329    push    dx
    299330    push    cx
     331
     332    ; Format to buffer
    300333    mov     si, g_szFileFormat
    301334    jmp     SHORT .FormatStringInCSSIandReturn
    302335
     336;--------------------------------------------------------------------
     337; .FormatDirectory
     338;   Parameters:
     339;       BP:     SP before pushing formatting parameters
     340;       DS:AX:  Far pointer to directory name
     341;       DS:SI:  Ptr to DTA containing file information
     342;   Returns:
     343;       Nothing
     344;   Corrupts registers:
     345;       AX, BX, CX, DX, SI, DI, BP
     346;--------------------------------------------------------------------
    303347ALIGN JUMP_ALIGN
    304348.FormatDirectory:
     349    push    ax              ; Push directory name offset
     350    push    ds              ; Push directory name segment
    305351    mov     ax, g_szSub
    306352    cmp     WORD [si+DTA.szFile], UPDIR_CHARACTERS
     
    345391
    346392;--------------------------------------------------------------------
     393; SortDirectoryContentsStringFromESDIwithCountInCX
     394;   Parameters:
     395;       CX:     Number of files and directories
     396;       ES:DI:  Buffer containing directory contents string
     397;       SS:BP:  Ptr to DIALOG
     398;   Returns:
     399;       Nothing
     400;   Corrupts registers:
     401;       AX, BX, CX, DX, SI, DI, DS, ES
     402;--------------------------------------------------------------------
     403ALIGN JUMP_ALIGN
     404SortDirectoryContentsStringFromESDIwithCountInCX:
     405    call    Memory_ExchangeDSSIwithESDI
     406    mov     bx, .FileStringComparator
     407    xchg    dx, cx
     408    mov     cx, FILE_STRING_LENGTH
     409    jmp     Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
     410
     411;--------------------------------------------------------------------
     412; .FileStringComparator
     413;   Parameters:
     414;       CX:     Item size in bytes
     415;       DS:SI:  Ptr to first item to compare
     416;       ES:DI:  Ptr to second item to compare
     417;   Returns:
     418;       FLAGS:  Signed comparition between first and second item
     419;   Corrupts registers:
     420;       Nothing
     421;--------------------------------------------------------------------
     422ALIGN JUMP_ALIGN
     423.FileStringComparator:
     424    push    di
     425    push    si
     426    push    cx
     427    push    bx
     428
     429    mov     bx, FILE_STRING_LENGTH-2            ; Zero BH
     430    cmp     WORD [si], UPDIR_CHARACTERS
     431    je      SHORT .ForceValueFromDSSItoBeLess
     432    mov     bl, [si+bx]
     433    cmp     bl, [es:di+FILE_STRING_LENGTH-2]    ; 'B' for files, 'R' for directories
     434    jne     SHORT .ForceValueFromDSSItoBeMoreOrLess
     435    repe cmpsb                                  ; Two directories or two files
     436
     437ALIGN JUMP_ALIGN
     438.ReturnFromComparison:
     439    pop     bx
     440    pop     cx
     441    pop     si
     442    pop     di
     443    ret
     444ALIGN JUMP_ALIGN
     445.ForceValueFromDSSItoBeMoreOrLess:
     446    ja      SHORT .ForceValueFromDSSItoBeLess   ; Directory in SI, file in DI
     447    xchg    bl, bh
     448    ; Fall to ForceValueFromDSSItoBeLess
     449ALIGN JUMP_ALIGN
     450.ForceValueFromDSSItoBeLess:
     451    cmp     bh, bl
     452    jmp     SHORT .ReturnFromComparison
     453
     454
     455;--------------------------------------------------------------------
    347456; GetInfoLinesToCXandDialogFlagsToAX
    348457;   Parameters:
     
    388497ALIGN JUMP_ALIGN
    389498ParseSelectionFromItemLineInDSSI:
    390     cmp     BYTE [si], '['
    391     je      SHORT .ChangeToSubdirInDSSI
    392     ; Fall to .SelectFileFromDSSI
    393 
    394 ;--------------------------------------------------------------------
    395 ; .SelectFileFromDSSI
    396 ;   Parameters:
    397 ;       DS:SI:  Ptr to char buffer containing file name to be selected
     499    mov     ax, [si]
     500    cmp     ax, UPDIR_CHARACTERS
     501    je      SHORT .ChangeToUpdir
     502    call    Char_IsUpperCaseLetterInAL
     503    jc      SHORT .ParseAndChangeToSubdirInDSSI
     504    ; Fall to .ParseAndSelectFileFromDSSI
     505
     506;--------------------------------------------------------------------
     507; .ParseAndSelectFileFromDSSI
     508;   Parameters:
     509;       DS:SI:  NULL terminated string selected from dialog
    398510;       SS:BP:  Ptr to DIALOG
    399511;   Returns:
     
    402514;       All, except BP
    403515;--------------------------------------------------------------------
    404 ;ALIGN JUMP_ALIGN
    405 .SelectFileFromDSSI:
     516.ParseAndSelectFileFromDSSI:
    406517    les     di, [bp+DIALOG.fpDialogIO]
    407518    add     di, BYTE FILE_DIALOG_IO.szFile
     
    414525
    415526;--------------------------------------------------------------------
    416 ; ChangeToSubdirInDSSI
    417 ;   Parameters:
    418 ;       DS:SI:  NULL terminated string containing new subdir in []
    419 ;       SS:BP:  Ptr to DIALOG
    420 ;   Returns:
    421 ;       Nothing
    422 ;   Corrupts registers:
    423 ;       All, except BP
    424 ;--------------------------------------------------------------------
    425 ALIGN JUMP_ALIGN
    426 .ChangeToSubdirInDSSI:
    427     inc     si                  ; Skip '['
    428     mov     BYTE [si+12], NULL  ; Replace ']' with NULL
    429     cmp     WORD [si], UPDIR_CHARACTERS
    430     eCMOVE  si, g_szUpdir       ; Real DOS do not accept spaces after ".."
     527; .ChangeToUpdir
     528;   Parameters:
     529;       SS:BP:  Ptr to DIALOG
     530;   Returns:
     531;       Nothing
     532;   Corrupts registers:
     533;       All, except BP
     534;--------------------------------------------------------------------
     535ALIGN JUMP_ALIGN
     536.ChangeToUpdir:
     537    mov     si, g_szUpdir
     538    jmp     SHORT .ChangeDirectoryToDSSI
     539
     540;--------------------------------------------------------------------
     541; .ParseAndChangeToSubdirInDSSI
     542;   Parameters:
     543;       DS:SI:  NULL terminated string selected from dialog
     544;       SS:BP:  Ptr to DIALOG
     545;   Returns:
     546;       Nothing
     547;   Corrupts registers:
     548;       All, except BP
     549;--------------------------------------------------------------------
     550ALIGN JUMP_ALIGN
     551.ParseAndChangeToSubdirInDSSI:
     552    mov     BYTE [si+12], NULL  ; Terminate with NULL (unnecessary spaces do not matter)
     553.ChangeDirectoryToDSSI:
    431554    call    Directory_ChangeToPathFromDSSI
    432555    ; Fall to RefreshFilesToDisplay
     
    624747    or      bx, cx
    625748    jnz     SHORT .BitShiftLoop
    626     jmp     RemoveLastLFandTerminateESDIwithNull
     749    jmp     TerminateESDIwithNull
    627750
    628751;--------------------------------------------------------------------
  • trunk/Assembly_Library/Src/Menu/Dialog/LineSplitter.asm

    r41 r46  
    22; Project name  :   Assembly Library
    33; Created date  :   8.8.2010
    4 ; Last update   :   15.9.2010
     4; Last update   :   1.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Splits long strings to multiple lines.
     
    131131.ProcessControlCharacter:
    132132    cmp     al, NULL            ; End of string?
    133     je      SHORT .EndOfString
     133    je      SHORT .RemoveEmptyLinesAtTheEndIfAnyExists
    134134    cmp     al, LF              ; Line feed?
    135135    je      SHORT .NewlineCharacter
     
    142142ALIGN JUMP_ALIGN
    143143.NewlineCharacter:
    144     mov     BYTE [si-1], SOH                    ; SOH marks previous newline character
     144    mov     BYTE [si-1], SOH    ; SOH marks previous newline character
    145145    mov     [bp+LINE_SPLITTER.pLastWord], si
    146146    jmp     SHORT .StartNewLine
    147147
    148148ALIGN JUMP_ALIGN
    149 .EndOfString:
    150     ret
     149.RemoveEmptyLinesAtTheEndIfAnyExists:
     150    mov     al, [si-2]          ; Load character before NULL
     151    cmp     al, SOH
     152    je      SHORT .RemoveEmptyLineAtTheEndOfString
     153    cmp     al, LF
     154    je      SHORT .RemoveEmptyLineAtTheEndOfString
     155    ret
     156ALIGN JUMP_ALIGN
     157.RemoveEmptyLineAtTheEndOfString:
     158    dec     si
     159    dec     WORD [bp+LINE_SPLITTER.wLines]
     160    mov     BYTE [si-1], NULL
     161    jmp     SHORT .RemoveEmptyLinesAtTheEndIfAnyExists
    151162
    152163
  • trunk/Assembly_Library/Src/Menu/Dialog/StringsForDialogs.asm

    r44 r46  
    22; Project name  :   Assembly Library
    33; Created date  :   14.9.2010
    4 ; Last update   :   27.9.2010
     4; Last update   :   1.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Strings used by dialogs.
     
    2222    db      "Enter name for new file or directory.",NULL
    2323
     24FILE_STRING_LENGTH      EQU     (24+1)  ; +1 = LF in directory contents string
    2425g_szFileFormat:
    25     db      "%14S  %4-u %c%cB",LF,NULL
     26    db      "%16S%4-u %c%cB",LF,NULL
    2627g_szDirectoryFormat:
    27     db      "[%12S]  %s-DIR",LF,NULL
     28    db      "%16S%s-DIR",LF,NULL
    2829g_szSub:
    2930    db      ANGLE_QUOTE_RIGHT,"SUB",NULL
    3031g_szUp:
    31     db      ANGLE_QUOTE_LEFT,"UP",NULL
     32    db      ANGLE_QUOTE_LEFT," UP",NULL
    3233
    3334g_szSingleItem:         ; Used by Dialog.asm for single item line
  • trunk/Assembly_Library/Src/Menu/MenuAttributes.asm

    r41 r46  
    9494istruc ATTRIBUTE_CHARS
    9595    at  ATTRIBUTE_CHARS.cBordersAndBackground,  db  COLOR_ATTRIBUTE(COLOR_BRIGHT_WHITE, COLOR_BLACK)
    96     at  ATTRIBUTE_CHARS.cShadow,                db  COLOR_ATTRIBUTE(COLOR_GRAY, COLOR_WHITE)
     96    at  ATTRIBUTE_CHARS.cShadow,                db  COLOR_ATTRIBUTE(COLOR_GRAY, COLOR_BLACK)
    9797    at  ATTRIBUTE_CHARS.cTitle,                 db  COLOR_ATTRIBUTE(COLOR_BRIGHT_WHITE, COLOR_BLACK)
    9898    at  ATTRIBUTE_CHARS.cItem,                  db  COLOR_ATTRIBUTE(COLOR_WHITE, COLOR_BLACK)
  • trunk/Assembly_Library/Src/Menu/MenuInit.asm

    r41 r46  
    22; Project name  :   Assembly Library
    33; Created date  :   13.7.2010
    4 ; Last update   :   16.9.2010
     4; Last update   :   1.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Functions for initializing menu system.
     
    2727    eENTER_STRUCT MENU_size
    2828
    29     mov     cx, MENU_size / 2
    30     call    Memory_ZeroSSBPbyWordsInCX
     29    mov     cx, MENU_size
     30    call    Memory_ZeroSSBPwithSizeInCX
    3131    call    MenuInit_EnterMenuWithHandlerInBXandUserDataInDXAX
    3232    mov     ax, [bp+MENU.wHighlightedItem]
  • trunk/Assembly_Library/Src/String/String.asm

    r41 r46  
    22; Project name  :   Assembly Library
    33; Created date  :   12.7.2010
    4 ; Last update   :   6.9.2010
     4; Last update   :   1.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Functions for handling characters.
     
    7676    pop     ax
    7777    ret
     78
     79
     80;--------------------------------------------------------------------
     81; String_ConvertDSSItoLowerCase
     82;   Parameters:
     83;       DS:SI:  Ptr to NULL terminated string to convert
     84;   Returns:
     85;       Nothing
     86;   Corrupts registers:
     87;       Nothing
     88;--------------------------------------------------------------------
     89ALIGN JUMP_ALIGN
     90String_ConvertDSSItoLowerCase:
     91    push    si
     92    push    ax
     93
     94ALIGN JUMP_ALIGN
     95.ConvertNextCharacter:
     96    lodsb
     97    test    al, al              ; NULL to end string?
     98    jz      SHORT .EndOfString
     99    call    Char_ALtoLowerCaseLetter
     100    mov     [si-1], al
     101    jmp     SHORT .ConvertNextCharacter
     102
     103ALIGN JUMP_ALIGN
     104.EndOfString:
     105    pop     ax
     106    pop     si
     107    ret
  • trunk/Assembly_Library/Src/Util/Memory.asm

    r41 r46  
    22; Project name  :   Assembly Library
    33; Created date  :   14.7.2010
    4 ; Last update   :   15.9.2010
     4; Last update   :   1.10.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Functions for memory access.
     
    1010
    1111;--------------------------------------------------------------------
    12 ; Memory_ZeroDSSIbyWordsInCX
     12; OPTIMIZE_STRING_OPERATION
    1313;   Parameters
    14 ;       CX:     Number of words to zero
    15 ;       DS:SI:  Ptr to buffer to zero
     14;       %1:     Repeat instruction
     15;       %2:     String instruction without size (for example MOVS and not MOVSB or MOVSW)
     16;       CX:     Number of BYTEs to operate
     17;       DS:SI:  Ptr to source data
     18;       ES:DI:  Ptr to destination
    1619;   Returns:
     20;       SI, DI: Updated by number of bytes operated
     21;   Corrupts registers:
    1722;       Nothing
     23;--------------------------------------------------------------------
     24%macro OPTIMIZE_STRING_OPERATION 2
     25    push    cx
     26
     27    shr     cx, 1           ; Operate with WORDs for performance
     28    jcxz    %%HandleRemainingByte
     29    %1      %2w
     30%%HandleRemainingByte:
     31    jnc     SHORT %%OperationCompleted
     32    %2b
     33
     34ALIGN JUMP_ALIGN
     35%%OperationCompleted:
     36    pop     cx
     37%endmacro
     38
     39
     40;--------------------------------------------------------------------
     41; Memory_CopyCXbytesFromDSSItoESDI
     42;   Parameters
     43;       CX:     Number of bytes to copy
     44;       DS:SI:  Ptr to source data
     45;       ES:DI:  Ptr to destination buffer
     46;   Returns:
     47;       SI, DI: Updated by number of bytes copied
    1848;   Corrupts registers:
    19 ;       AX
     49;       Nothing
    2050;--------------------------------------------------------------------
    2151ALIGN JUMP_ALIGN
    22 Memory_ZeroDSSIbyWordsInCX:
    23     call    Memory_ExchangeDSSIwithESDI
    24     call    Memory_ZeroESDIbyWordsInCX
    25     jmp     SHORT Memory_ExchangeDSSIwithESDI
     52Memory_CopyCXbytesFromDSSItoESDI:
     53    OPTIMIZE_STRING_OPERATION rep, movs
     54    ret
     55
    2656
    2757;--------------------------------------------------------------------
    28 ; Memory_ZeroSSBPbyWordsInCX
     58; Memory_ZeroSSBPwithSizeInCX
    2959;   Parameters
    30 ;       CX:     Number of words to zero
     60;       CX:     Number of bytes to zero
    3161;       SS:BP:  Ptr to buffer to zero
    3262;   Returns:
     
    3666;--------------------------------------------------------------------
    3767ALIGN JUMP_ALIGN
    38 Memory_ZeroSSBPbyWordsInCX:
    39     push    es
    40     push    di
     68Memory_ZeroSSBPwithSizeInCX:
    4169    push    ax
    4270
    43     push    ss
    44     pop     es
    45     mov     di, bp
    46     call    Memory_ZeroESDIbyWordsInCX
     71    call    Memory_ExchangeSSBPwithESDI
     72    call    Memory_ZeroESDIwithSizeInCX
     73    call    Memory_ExchangeSSBPwithESDI
    4774
    4875    pop     ax
    49     pop     di
    50     pop     es
    5176    ret
    5277
    5378;--------------------------------------------------------------------
    54 ; Memory_ZeroESDIbyWordsInCX
     79; Memory_ZeroESDIwithSizeInCX
    5580;   Parameters
    56 ;       CX:     Number of words to zero
    57 ;       ES:DI:  Ptr to buffer to zero
     81;       CX:     Number of bytes to zero
     82;       ES:DI:  Ptr to destination buffer
    5883;   Returns:
    5984;       Nothing
     
    6287;--------------------------------------------------------------------
    6388ALIGN JUMP_ALIGN
    64 Memory_ZeroESDIbyWordsInCX:
     89Memory_ZeroESDIwithSizeInCX:
    6590    xor     ax, ax
    66     ; Fall to Memory_FillESDIwithAXbyCXtimes
     91    ; Fall to Memory_StoreCXbytesFromAccumToESDI
    6792
    6893;--------------------------------------------------------------------
    69 ; Memory_FillESDIwithAXbyCXtimes
     94; Memory_StoreCXbytesFromAccumToESDI
    7095;   Parameters
    7196;       AX:     Word to use to fill buffer
    72 ;       CX:     Number of words to fill
    73 ;       ES:DI:  Ptr to buffer to fill
     97;       CX:     Number of BYTEs to store
     98;       ES:DI:  Ptr to destination buffer
    7499;   Returns:
    75100;       Nothing
     
    78103;--------------------------------------------------------------------
    79104ALIGN JUMP_ALIGN
    80 Memory_FillESDIwithAXbyCXtimes:
    81     cld
    82     push    di
    83     push    cx
    84     rep stosw
    85     pop     cx
    86     pop     di
     105Memory_StoreCXbytesFromAccumToESDI:
     106    OPTIMIZE_STRING_OPERATION rep, stos
     107    sub     di, cx
    87108    ret
    88109
    89110
    90111;--------------------------------------------------------------------
     112; Memory_ExchangeSSBPwithESDI
    91113; Memory_ExchangeDSSIwithESDI
    92114;   Parameters
    93115;       Nothing
    94116;   Returns:
    95 ;       DS:SI and ES:DI are exchanged.
     117;       SS:BP/DS:SI and ES:DI are exchanged.
    96118;   Corrupts registers:
    97119;       Nothing
    98120;--------------------------------------------------------------------
     121ALIGN JUMP_ALIGN
     122Memory_ExchangeSSBPwithESDI:
     123    xchg    bp, di
     124    push    ss
     125    push    es
     126    pop     ss
     127    pop     es
     128    ret
     129
    99130ALIGN JUMP_ALIGN
    100131Memory_ExchangeDSSIwithESDI:
     
    108139
    109140;--------------------------------------------------------------------
    110 ; Memory_CopySSBPtoDSSI
    111141; Memory_CopySSBPtoESDI
    112142;   Parameters
    113143;       Nothing
    114144;   Returns:
    115 ;       DS:SI:      Same as SS:BP
     145;       ES:DI:      Same as SS:BP
    116146;   Corrupts registers:
    117147;       Nothing
    118148;--------------------------------------------------------------------
    119 ALIGN JUMP_ALIGN
    120 Memory_CopySSBPtoDSSI:
    121     push    ss
    122     pop     ds
    123     mov     si, bp
    124     ret
    125 
    126149ALIGN JUMP_ALIGN
    127150Memory_CopySSBPtoESDI:
  • 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.