; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;  Description: Serial IO interface library. Linux part.
;
;  Target OS: Win32
;
;  Dependencies:
;
;  Notes:
;_________________________________________________________________________________________


proc SerSetParams, .hSerial, .Baudrate, .Parity, .Flow, .Timeout
.dcb smallDCB
.cto COMMTIMEOUTS
begin
        pushad

        lea     esi, [.dcb]
        mov     [esi+DCB.DCBlength], sizeof.DCB
        invoke  GetCommState, [.hSerial], esi
        test    eax, eax
        jz      .error

        mov     eax, [.Baudrate]
        mov     ecx, [.Parity]
        mov     [.dcb.BaudRate], eax
        mov     [.dcb.Parity], cl       ; the constants are defined to be the same.
;        mov     [.dcb.StopBits], 0
        mov     [.dcb.ByteSize], 8

;        mov     ecx, [.Flow]
;        mov     [.dcb.fOutxCtsFlow], ecx
;        mov     [.dcb.fOutxDsrFlow], ecx

;        xor     ecx, ecx
;        mov     [.dcb.fOutX], ecx         ; no xon/xoff
;        mov     [.dcb.fInX], ecx          ;
;        mov     [.dcb.fAbortOnError], ecx ; no abort on error

        invoke  SetCommState, [.hSerial], esi
        test    eax, eax
        jz      .error

        mov     eax, [.Timeout]
        mov     [.cto.ReadIntervalTimeout], eax
        mov     [.cto.ReadTotalTimeoutMultiplier], eax
        mov     [.cto.ReadTotalTimeoutConstant], eax
        mov     [.cto.WriteTotalTimeoutMultiplier], eax
        mov     [.cto.WriteTotalTimeoutConstant], eax
        lea     eax, [.cto]
        invoke  SetCommTimeouts, [.hSerial], eax
        test    eax, eax
        jz      .error

        clc
        popad
        return

.error:
        stc
        popad
        return
endp