Changeset 258 in xtideuniversalbios for trunk


Ignore:
Timestamp:
Feb 22, 2012, 7:01:53 PM (13 years ago)
Author:
gregli@…
google:author:
gregli@hotmail.com
Message:

Added floppy drive emulation over the serial connection (MODULE_SERIAL_FLOPPY). Along the way, various optimizations were made to stay within the 8K ROM size target. Also, serial code now returns the number of sectors transferred.

Location:
trunk
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • trunk/Assembly_Library/Inc/Macros.inc

    r119 r258  
    5252; when stack usage is undesirable (ie speed is critical).
    5353;
     54; The PRESERVE_FLAGS version will zero the register with a MOV instead
     55; of an XOR, thus preserving the flags.  It is one byte larger on
     56; non-186 or higher systems.
     57;
    5458; LOAD_BDA_SEGMENT_TO
     59; LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO
    5560;   Parameters:
    5661;       %1:     Destination Segment Register
     
    6873%elifidn %3, !
    6974    xor     %2, %2
     75    mov     %1, %2
     76%else
     77    push    BYTE 0
     78    pop     %1
     79%endif
     80%endmacro
     81
     82%macro LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO 2-3
     83%ifndef USE_186
     84    mov     %2, 0
     85    mov     %1, %2
     86%elifidn %3, !
     87    mov     %2, 0
    7088    mov     %1, %2
    7189%else
  • trunk/Serial_Server/library/Image.cpp

    r233 r258  
    1212#include <stdio.h>
    1313
     14struct floppyInfo {
     15    unsigned long size;
     16    unsigned char type;
     17    unsigned char cylinders;
     18    unsigned char heads;
     19    unsigned char sectors;
     20} floppyInfos[] =
     21{
     22{ 2949120 / 512, 6, 80, 2, 36 },   // 2.88MB 3.5"
     23{ 1474560 / 512, 4, 80, 2, 18 },        // 1.44MB 3.5"
     24{ 1228800 / 512, 2, 80, 2, 15 },     // 1.2MB 5.25"
     25{ 737280 / 512, 3, 80, 1, 18 },    // 720KB 3.5"
     26{ 368640 / 512, 1, 40, 2, 9 }, // 360KB 5.25"
     27{ 327680 / 512, 0, 40, 2, 8 }, // 320KB 5.25"
     28{ 184320 / 512, 0, 40, 1, 9 }, // 180KB 5.25" single sided
     29{ 163840 / 512, 0, 40, 1, 8 }, // 160KB 5.25" single sided
     30{ 0, 0, 0, 0, 0 }
     31};
     32
    1433Image::Image( char *name, int p_readOnly, int p_drive )
    1534{
     
    2746{
    2847    double sizef;
     48    char sizeChar;
     49    struct floppyInfo *f;
    2950
    3051    for( char *c = shortFileName = name; *c; c++ )
     
    4667    if( totallba == 0 )
    4768        log( -1, "'%s', Image size zero?" );
     69
     70    floppy = 0;
     71    for( f = floppyInfos; f->size && f->size != totallba; f++ ) ;
     72    if( f->size )
     73    {
     74        floppy = 1;
     75        floppyType = f->type;
     76        p_useCHS = 1;
     77        p_cyl = f->cylinders;
     78        p_head = f->heads;
     79        p_sect = f->sectors;
     80    }
    4881
    4982    if( p_useCHS )
     
    82115
    83116    sizef = totallba/2048.0;
     117    sizeChar = 'M';
     118    if( sizef < 1 )
     119    {
     120        sizef *= 1024;
     121        sizeChar = 'K';
     122    }
    84123    if( useCHS )
    85         log( 0, "Opening '%s', CHS geometry %u:%u:%u, total LBA %lu, total size %.1lf MB", name, cyl, sect, head, totallba, sizef );
    86     else
    87         log( 0, "Opening '%s', total LBA %lu, total size %.1lf MB", name, totallba, sizef );
     124        log( 0, "%s: %s with CHS geometry %u:%u:%u, size %.2lf %cB",
     125             name, (floppy ? "Floppy Disk" : "Hard Disk"), cyl, head, sect, sizef, sizeChar );
     126    else
     127        log( 0, "%s: %s with total sectors %lu, size %.2lf %cB",
     128             name, (floppy ? "Floppy Disk" : "Hard Disk"), totallba, sizef, sizeChar );
    88129}
    89130
     
    137178#define ATA_dwLBACnt 60
    138179
    139 #define ATA_wVendor 159
    140 
     180// Words carved out of the vendor specific area for our use
     181//
     182#define ATA_wSerialFloppyFlagAndType 158
     183#define ATA_wSerialPortAndBaud 159
     184
     185// Defines used in the words above
     186//
    141187#define ATA_wCaps_LBA 0x200
    142188
    143189#define ATA_wGenCfg_FIXED 0x40
     190
     191#define ATA_wSerialFloppyFlagAndType_Flag 0x10
     192#define ATA_wSerialFloppyFlagAndType_TypePosition 5
    144193
    145194struct comPorts {
     
    207256    }
    208257
     258    if( floppy )
     259        buff[ ATA_wSerialFloppyFlagAndType ] = ATA_wSerialFloppyFlagAndType_Flag | (floppyType << ATA_wSerialFloppyFlagAndType_TypePosition);
     260
     261    // we always set this, so that the bulk of the BIOS will consider this disk as a hard disk
     262    //
    209263    buff[ ATA_wGenCfg ] = ATA_wGenCfg_FIXED;
    210     //                  buff[ ATA_VendorSpecific_ReturnPortBaud ] = retWord;
    211 }
     264}
  • trunk/Serial_Server/library/Library.h

    r233 r258  
    3232
    3333    unsigned long cyl, sect, head;
     34    unsigned char floppy, floppyType;
    3435    int useCHS;
    3536
  • trunk/Serial_Server/library/Process.cpp

    r233 r258  
    9999    lastScan = 0;
    100100
     101    //
     102    // Floppy disks must come after any hard disks
     103    //
     104    if( (image0 && image0->floppy) && (image1 && !image1->floppy) )
     105    {
     106        img = image0;
     107        image0 = image1;
     108        image1 = img;
     109    }
     110
    101111    lasttick = GetTime();
    102112
  • trunk/Serial_Server/win32/Win32.cpp

    r233 r258  
    3030        "  -n [megabytes]      Create new disk with given size or use -g geometry",
    3131        "                      Maximum size is " USAGE_MAXSECTORS,
    32         "                      (default is a 32 MB disk, with CHS geometry 65:63:16)",
    33         "",
    34         "  -p                  Named Pipe mode for emulators (pipe is \"" PIPENAME "\")",
    35         "",
    36         "  -c COMPortNumber    COM Port to use (default is first found)",
     32        "                      (default is a 32 MB disk, with CHS geometry 65:16:63)",
     33        "",
     34        "  -p [pipename]       Named Pipe mode for emulators",
     35        "                      (must begin with \"\\\\\", default is \"" PIPENAME "\")",
     36        "",
     37        "  -c COMPortNumber    COM Port to use (default is first found)",
     38        "                      Available COM ports on this system are:",
     39     "COM                          ",
    3740        "",
    3841        "  -b BaudRate         Baud rate to use on the COM port, with client machine",
     
    5356        "with xtidecfg.com.  Or one can hold down the ALT key at the end of the normal",
    5457        "IDE hard disk scan and the XTIDE Universal BIOS will scan COM1-7, at each of",
    55         "the four speeds given above for BaudRate.  Note that hardware rate multipliers",
     58        "the six speeds given above for BaudRate.  Note that hardware rate multipliers",
    5659        "must be taken into account on the server end, but are invisible on the client.",
     60        "",
     61        "Floppy images may also be used.  Image size must be exactly the same size",
     62        "as a 2.88MB, 1.44MB, 1.2MB, 720KB, 360KB, 320KB, 180KB, or 160KB disk.",
     63        "Floppy images must be the last disks discovered by the BIOS, and only",
     64        "two floppy drives are supported by the BIOS at a time.",
    5765        NULL };
    5866
    5967    for( int t = 0; usageStrings[t]; t++ )
    60         fprintf( stderr, "%s\n", usageStrings[t] );
     68    {
     69        if( !strncmp( usageStrings[t], "COM", 3 ) )
     70        {
     71            char logbuff[ 1024 ];
     72
     73            SerialAccess::EnumerateCOMPorts( logbuff, 1024 );
     74            fprintf( stderr, "%s%s\n", usageStrings[t]+3, logbuff );
     75        }
     76        else
     77            fprintf( stderr, "%s\n", usageStrings[t] );
     78    }
    6179
    6280    exit( 1 );
     
    120138                break;
    121139            case 'p': case 'P':
    122                 ComPort = "PIPE";
     140                if( argv[t+1][0] == '\\' && argv[t+1][1] == '\\' )
     141                    ComPort = argv[++t];
     142                else
     143                    ComPort = PIPENAME;
    123144                if( !baudRate )
    124145                    baudRate = baudRateMatchString( "115200" );
  • trunk/Serial_Server/win32/Win32Serial.h

    r233 r258  
    3535        }
    3636
    37         if( !strcmp( name, "PIPE" ) )
     37        if( name[0] == '\\' && name[1] == '\\' )
    3838        {
    39             log( 0, "Opening named pipe %s (simulating %s baud)", PIPENAME, baudRate->display );
     39            log( 0, "Opening named pipe %s (simulating %s baud)", name, baudRate->display );
    4040       
    41             pipe = CreateNamedPipeA( PIPENAME, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_REJECT_REMOTE_CLIENTS, 2, 1024, 1024, 0, NULL );
     41            pipe = CreateNamedPipeA( name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_REJECT_REMOTE_CLIENTS, 2, 1024, 1024, 0, NULL );
    4242            if( pipe == INVALID_HANDLE_VALUE )
    4343                log( -1, "Could not CreateNamedPipe " PIPENAME );
     
    5959                DCB dcb;
    6060
    61                 log( 0, "Opening %s (%lu baud)", name, baudRate->rate );
     61                log( 0, "Opening %s (%s baud)", name, baudRate->display );
    6262           
    6363                pipe = CreateFileA( name, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
     
    7474                dcb.Parity = NOPARITY;
    7575                if( !SetCommState( pipe, &dcb ) )
    76                     log( -1, "Could not SetCommState" );
     76                {
     77                    char *msg = "";
     78                    COMMPROP comProp;
     79
     80                    if( GetCommProperties( pipe, &comProp ) )
     81                    {
     82                        if( comProp.dwMaxBaud != BAUD_USER )
     83                            msg = "\n    On this COM port, baud rate is limited to 115.2K";
     84                    }
     85                    log( -1, "Could not SetCommState: baud rate selected may not be availabele%s", msg );
     86                }
    7787
    7888                if( !SetCommTimeouts( pipe, &timeouts ) )
     
    8292            {
    8393                char logbuff[ 1024 ];
    84                 int found = 0;
    8594
    86                 sprintf( logbuff, "serial port '%s' not found, detected COM ports:", name );
    87 
    88                 for( int t = 1; t <= 40; t++ )
    89                 {
    90                     sprintf( buff1, "COM%d", t );
    91                     if( QueryDosDeviceA( buff1, buff2, sizeof(buff2) ) )
    92                     {
    93                         strcat( logbuff, "\n    " );
    94                         strcat( logbuff, buff1 );
    95                         found = 1;
    96                     }
    97                 }
    98                 if( !found )
    99                     strcat( logbuff, "\n    (none)" );
     95                EnumerateCOMPorts( logbuff, 1024 );
    10096               
    101                 log( -1, logbuff );
     97                log( -1, "Serial port '%s' not found, detected COM ports: %s", name, logbuff );
    10298            }
    10399        }
     100    }
     101
     102    static void EnumerateCOMPorts( char *logbuff, int logbuffLen )
     103    {
     104        int found = 0;
     105        char buff1[20], buff2[1024];
     106
     107        logbuff[0] = 0;
     108
     109        for( int t = 1; t <= 40 && strlen(logbuff) < (logbuffLen - 40); t++ )
     110        {
     111            sprintf( buff1, "COM%d", t );
     112            if( QueryDosDeviceA( buff1, buff2, sizeof(buff2) ) )
     113            {
     114                if( found )
     115                    strcat( logbuff, ", " );
     116                strcat( logbuff, buff1 );
     117                found = 1;
     118            }
     119        }
     120
     121        if( !found )
     122            strcat( logbuff, "(none)" );
    104123    }
    105124
  • trunk/XTIDE_Universal_BIOS/Inc/ATA_ID.inc

    r233 r258  
    254254    .wRMSN      resw 1  ; 127F, Removable Media Status Notification feature set support
    255255    .wSecurity  resw 1  ; 128FV, Security Status
    256                 resw 159-129    ; 129...158X, Vendor Specific
    257     .wVendor    resw 1  ; 159X, Vendor Specific - picking one word for use by the Serial Port code
     256                resw 158-129    ; 129...157X, Vendor Specific
     257    .wSerialFloppyFlagAndType:
     258    .wVendor1   resw 1  ; 158x, Vendor specific - word for use by the serial port code
     259    .wSerialPortAndBaud:
     260    .wVendor2   resw 1  ; 159X, Vendor Specific - word for use by the Serial Port code
    258261    .wCFAPower  resw 1  ; 160FV, CFA Power Mode 1
    259262                resw 176-161    ; 161...175R, Reserved for assignment by the CompactFlash Association
  • trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc

    r238 r258  
    6868MASKH_DPT_RESET                 EQU 0F0h
    6969
     70FLGH_DPT_SERIAL_FLOPPY                      EQU (1<<4)
     71FLGH_DPT_SERIAL_FLOPPY_TYPE_MASK            EQU 0e0h
     72FLGH_DPT_SERIAL_FLOPPY_TYPE_FIELD_POSITION  EQU 5
     73
    7074; Addressing modes for DPT.wFlags
    7175ADDRESSING_MODE_FIELD_POSITION  EQU     5
  • trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc

    r248 r258  
    1111struc XLATEVARS
    1212    .wFDandHDswap:
    13     .bFDSwap        resb    1   ; Floppy Drive to swap to 00h and vice versa
    14     .bHDSwap        resb    1   ; Hard Drive to swap to 80h and vice versa
    15     .bXlatedDrv     resb    1   ; Drive number after translation
    16                     resb    1   ; alignment
     13    .bFDSwap            resb    1   ; Floppy Drive to swap to 00h and vice versa
     14    .bHDSwap            resb    1   ; Hard Drive to swap to 80h and vice versa
     15    .bXlatedDrv         resb    1   ; Drive number after translation
     16%ifdef MODULE_SERIAL_FLOPPY
     17    .bFlopCreateCnt:
     18    .bFlopCntAndFirst   resb    1   ; Normally, packed starting floppy drive number (high order 7 bits)
     19                                    ; and number of drives (low order bit, max 2 drives supported).
     20                                    ; During initialization, until the end of DetectDrives_FromAllIDEControllers,
     21                                    ; this byte contains the raw number of floppy drives seen (using .bFlopCreateCnt)
     22%else
     23                        resb    1   ; alignment
     24%endif
    1725endstruc
    1826
     
    2735
    2836    .wDrvCntAndFirst:
     37    .bFirstDrv          resb    1   ; Number of first drive for this BIOS
    2938    .bDrvCnt            resb    1   ; Number of drives handled by this BIOS
    30     .bFirstDrv          resb    1   ; Number of first drive for this BIOS
    3139
    3240    ; Variables for drive number translation
  • trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenu.asm

    r248 r258  
    3737;               Clear: There is no selected menu item, DL is not valid
    3838;   Corrupts registers:
    39 ;       CX, DI
     39;       AX, DI
    4040;--------------------------------------------------------------------
    4141ALIGN JUMP_ALIGN
     
    5050
    5151    mov     dl, cl                          ; Copy menuitem index to DX
    52     call    FloppyDrive_GetCountToCX
    53     cmp     dl, cl                          ; Floppy drive?
     52    call    FloppyDrive_GetCountToAX
     53    cmp     dl, al                          ; Floppy drive?
    5454    jb      SHORT .ReturnFloppyDriveInDX    ; Set CF if branch taken
    55     or      cl, 80h                         ; Or 80h into CL before the sub
     55    or      al, 80h                         ; Or 80h into AL before the sub
    5656                                            ; to cause CF to be set after
    5757                                            ; and result has high order bit set
    58     sub     dl, cl                          ; Remove floppy drives from index
     58    sub     dl, al                          ; Remove floppy drives from index
    5959
    6060.ReturnFloppyDriveInDX:
     
    9494ALIGN JUMP_ALIGN
    9595BootMenu_GetMenuitemCountToAX:
    96     call    RamVars_GetHardDiskCountFromBDAtoCX
     96    call    RamVars_GetHardDiskCountFromBDAtoAX
    9797    xchg    ax, cx
    98     call    FloppyDrive_GetCountToCX
     98    call    FloppyDrive_GetCountToAX
    9999    add     ax, cx
    100100    ret
     
    136136BootMenu_GetMenuitemToAXforAsciiHotkeyInAL:
    137137    call    Char_ALtoUpperCaseLetter
    138     call    BootMenu_GetLetterForFirstHardDiskToCL
    139138    xor     ah, ah
    140     cmp     al, cl                      ; Letter is for Hard Disk?
     139    xchg    ax, cx
     140    call    BootMenu_GetLetterForFirstHardDiskToAL
     141    cmp     cl, al                      ; Letter is for Hard Disk?
    141142    jae     SHORT .StartFromHardDiskLetter
     143    xchg    ax, cx
    142144    sub     al, 'A'                     ; Letter to Floppy Drive menuitem
    143145    ret
    144146ALIGN JUMP_ALIGN
    145147.StartFromHardDiskLetter:
    146     sub     al, cl                      ; Hard Disk index
    147     call    FloppyDrive_GetCountToCX
     148    sub     cl, al                      ; Hard Disk index
     149    call    FloppyDrive_GetCountToAX
    148150    add     ax, cx                      ; Menuitem index
     151                                        ; Note: no need to xchg ax, cx as above, since adding with result to ax
    149152    ret
    150153
     
    160163;       CL:     Upper case letter for first hard disk
    161164;   Corrupts registers:
    162 ;       CH
    163 ;--------------------------------------------------------------------
    164 ALIGN JUMP_ALIGN
    165 BootMenu_GetLetterForFirstHardDiskToCL:
    166     call    FloppyDrive_GetCountToCX
    167     add     cl, 'A'
    168     cmp     cl, 'C'
     165;       AX
     166;--------------------------------------------------------------------
     167ALIGN JUMP_ALIGN
     168BootMenu_GetLetterForFirstHardDiskToAL:
     169    call    FloppyDrive_GetCountToAX
     170    add     al, 'A'
     171    cmp     al, 'C'
    169172    ja      .Return
    170     mov     cl, 'C'
     173    mov     al, 'C'
    171174ALIGN JUMP_ALIGN, ret
    172175.Return:
     
    181184;       DX:     Menuitem index (assuming drive is available)
    182185;   Corrupts registers:
    183 ;       Nothing
     186;       AX
    184187;--------------------------------------------------------------------
    185188ALIGN JUMP_ALIGN
     
    188191    test    dl, dl
    189192    jns     SHORT .ReturnItemIndexInDX  ; Return if floppy drive (HD bit not set)
    190     call    FloppyDrive_GetCountToCX
     193    call    FloppyDrive_GetCountToAX
    191194    and     dl, ~80h                    ; Clear HD bit
    192     add     dx, cx
     195    add     dx, ax
    193196.ReturnItemIndexInDX:
    194197    ret
     
    212215    test    dl, dl                              ; Floppy drive?
    213216    jns     SHORT .IsFloppyDriveInSystem
    214     call    RamVars_GetHardDiskCountFromBDAtoCX ; Hard Disk count to CX
    215     or      cl, 80h                             ; Set Hard Disk bit to CX
     217    call    RamVars_GetHardDiskCountFromBDAtoAX ; Hard Disk count to AX
     218    or      al, 80h                             ; Set Hard Disk bit to AX
    216219    jmp     SHORT .CompareDriveNumberToDriveCount
    217220.IsFloppyDriveInSystem:
    218     call    FloppyDrive_GetCountToCX
     221    call    FloppyDrive_GetCountToAX
    219222.CompareDriveNumberToDriveCount:
    220     cmp     dl, cl                              ; Set CF when DL is smaller
    221     ret
     223    cmp     dl, al                              ; Set CF when DL is smaller
     224    ret
  • trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuEvent.asm

    r248 r258  
    2121%ifdef MENUEVENT_INLINE_OFFSETS
    2222
    23     add     bx, BootMenuEvent_Handler
     23    add     bx, BootMenuEvent_Handler.FirstEvent
    2424    jmp     bx
    2525
    26 MENUEVENT_InitializeMenuinitFromDSSI equ  (BootMenuEvent_Handler.InitializeMenuinitFromDSSI - BootMenuEvent_Handler)
    27 MENUEVENT_ExitMenu equ  (BootMenuEvent_EventCompleted - BootMenuEvent_Handler)
    28 MENUEVENT_ItemHighlightedFromCX equ (BootMenuEvent_Handler.ItemHighlightedFromCX - BootMenuEvent_Handler)
    29 MENUEVENT_ItemSelectedFromCX equ (BootMenuEvent_Handler.ItemSelectedFromCX - BootMenuEvent_Handler)
    30 MENUEVENT_KeyStrokeInAX equ (BootMenuEvent_Handler.KeyStrokeInAX - BootMenuEvent_Handler)
    31 MENUEVENT_RefreshTitle equ (BootMenuPrint_TitleStrings - BootMenuEvent_Handler)
    32 MENUEVENT_RefreshInformation equ (BootMenuPrint_RefreshInformation - BootMenuEvent_Handler)
    33 MENUEVENT_RefreshItemFromCX equ (BootMenuPrint_RefreshItem - BootMenuEvent_Handler)
     26MENUEVENT_InitializeMenuinitFromDSSI equ  (BootMenuEvent_Handler.InitializeMenuinitFromDSSI - BootMenuEvent_Handler.FirstEvent)
     27MENUEVENT_ExitMenu equ  (BootMenuEvent_EventCompleted - BootMenuEvent_Handler.FirstEvent)
     28MENUEVENT_ItemHighlightedFromCX equ (BootMenuEvent_Handler.ItemHighlightedFromCX - BootMenuEvent_Handler.FirstEvent)
     29MENUEVENT_ItemSelectedFromCX equ (BootMenuEvent_Handler.ItemSelectedFromCX - BootMenuEvent_Handler.FirstEvent)
     30MENUEVENT_KeyStrokeInAX equ (BootMenuEvent_Handler.KeyStrokeInAX - BootMenuEvent_Handler.FirstEvent)
     31MENUEVENT_RefreshTitle equ (BootMenuPrint_TitleStrings - BootMenuEvent_Handler.FirstEvent)
     32MENUEVENT_RefreshInformation equ (BootMenuPrint_RefreshInformation - BootMenuEvent_Handler.FirstEvent)
     33MENUEVENT_RefreshItemFromCX equ (BootMenuPrint_RefreshItem - BootMenuEvent_Handler.FirstEvent)
    3434;
    3535; Note that there is no entry for MENUEVENT_IdleProcessing.  If MENUEVENT_IDLEPROCESSING_ENABLE is not %defined,
     
    6767;   DS:SI:      Ptr to initialized MENUINIT struct
    6868ALIGN JUMP_ALIGN
     69.FirstEvent:   
    6970.InitializeMenuinitFromDSSI:
    7071    push    ds
  • trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrint.asm

    r255 r258  
    2424
    2525    call    RamVars_IsDriveHandledByThisBIOS               
    26     jnc     .notOurs
     26    jc      .notOurs
    2727
    2828    call    FindDPT_ForDriveNumber                  ; if it is one of ours, print the string in bootnfo
     
    4747    push    ax                                      ; the hard disks don't ever use it, but it does no harm)
    4848       
    49     jmp     short BootMenuPrint_FormatCSSIfromParamsInSSBP
     49    jmp     short BootMenuPrint_RefreshInformation.FormatRelay
    5050
    5151;--------------------------------------------------------------------
     
    8787    push    bp
    8888    mov     bp,sp
    89     jmp     short BootMenuPrint_FormatCSSIfromParamsInSSBP
     89    jmp     short BootMenuPrint_RefreshInformation.FormatRelay
    9090
    9191       
     
    110110    mov     bp, sp
    111111
     112    mov     si, g_szCapacity                            ; Setup print string now, carries through to print call
     113
     114    xor     di, di
     115    call    RamVars_IsDriveHandledByThisBIOS
     116    jc      SHORT .notours
     117    call    FindDPT_ForDriveNumber                      ; DS:DI to point DPT
     118.notours:       
     119       
    112120    test    dl, dl                                      ; are we a hard disk?
    113121    js      BootMenuPrint_HardDiskRefreshInformation       
    114        
     122
     123    test    di,di
     124    jnz     .ours
    115125    call    FloppyDrive_GetType                         ; Get Floppy Drive type to BX
     126    jmp     .around
     127.ours:
     128    call    AH8h_GetDriveParameters
     129.around:               
    116130
    117131    mov     ax, g_szFddSizeOr                           ; .PrintXTFloppyType
    118     test    bx, bx                                      ; Two possibilities? (FLOPPY_TYPE_525_OR_35_DD)     
     132    test    bl, bl                                      ; Two possibilities? (FLOPPY_TYPE_525_OR_35_DD)     
    119133    jz      SHORT .PushAXAndOutput
    120134
     
    158172
    159173    mov     al,FloppyTypes.rgbCapacityMultiplier
     174    mov     bh, 0
    160175    mul     byte [cs:bx+FloppyTypes.rgbCapacity - 1]    ; -1 since 0 is handled above and not in the table
    161176
     
    163178    push    ax
    164179
    165     jmp     short BootMenuPrint_HardDiskRefreshInformation.output
     180.FormatRelay:
     181    jmp     short BootMenuPrint_FormatCSSIfromParamsInSSBP
    166182
    167183
     
    180196ALIGN JUMP_ALIGN
    181197BootMenuPrint_HardDiskRefreshInformation:       
    182     call    RamVars_IsDriveHandledByThisBIOS
    183     jnc     SHORT .HardDiskMenuitemInfoForForeignDrive
    184     call    FindDPT_ForDriveNumber                      ; DS:DI to point DPT
    185     ; Fall to .HardDiskMenuitemInfoForOurDrive
    186 
    187 ;--------------------------------------------------------------------
    188 ; .HardDiskMenuitemInfoForOurDrive
    189 ;   Parameters:
    190 ;       DL:     Untranslated Hard Disk number
    191 ;       DS:DI:  Ptr to DPT
    192 ;   Returns:
    193 ;       Nothing
    194 ;   Corrupts registers:
    195 ;       AX, BX, CX, DX, SI, DI, ES
    196 ;--------------------------------------------------------------------
     198    test    di,di
     199    jz      .HardDiskMenuitemInfoForForeignDrive       
     200
    197201.HardDiskMenuitemInfoForOurDrive:
    198202    ePUSH_T ax, g_szInformation
     
    200204    ; Get and push total LBA size
    201205    call    BootMenuInfo_GetTotalSectorCount
    202     call    ConvertSectorCountInBXDXAXtoSizeAndPushForFormat       
    203     jmp     BootMenuPrintCfg_ForOurDrive
    204 
    205 ;--------------------------------------------------------------------
    206 ; .HardDiskMenuitemInfoForForeignDrive
    207 ;   Parameters:
    208 ;       DL:     Untranslated Hard Disk number
    209 ;       DS:     RAMVARS segment
    210 ;   Returns:
    211 ;       CF:     Set since menu event was handled successfully
    212 ;   Corrupts registers:
    213 ;       AX, BX, CX, DX, SI, DI
    214 ;--------------------------------------------------------------------
    215 ALIGN JUMP_ALIGN
     206    jmp     .ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
     207       
    216208.HardDiskMenuitemInfoForForeignDrive:
    217209    call    DriveXlate_ToOrBack
    218210    call    AH15h_GetSectorCountFromForeignDriveToDXAX
    219     call    ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
    220 
    221 ALIGN JUMP_ALIGN       
    222 .output:
    223     mov     si, g_szCapacity
    224 ;;; fall-through
     211
     212.ConvertSectorCountInBXDXAXtoSizeAndPushForFormat:
     213    ePUSH_T cx, g_szCapacityNum     ; Push format substring
     214    call    Size_ConvertSectorCountInBXDXAXtoKiB
     215    mov     cx, BYTE_MULTIPLES.kiB
     216    call    Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
     217    push    ax                      ; Size in magnitude
     218    push    cx                      ; Tenths
     219    push    dx                      ; Magnitude character       
     220               
     221    test    di,di
     222    jz      short BootMenuPrint_FormatCSSIfromParamsInSSBP
     223
     224%include "BootMenuPrintCfg.asm"         ; inline of code to fill out remainder of information string
     225
     226;;; fall-through to BootMenuPrint_FormatCSSIfromParamsInSSBP
     227
    225228
    226229;--------------------------------------------------------------------
     
    273276ALIGN JUMP_ALIGN
    274277BootMenuPrint_TheBottomOfScreen:
    275     call    FloppyDrive_GetCountToCX
    276     mov     bl, cl                  ; Floppy Drive count to BL
    277     call    RamVars_GetHardDiskCountFromBDAtoCX
    278     mov     bh, cl                  ; Hard Disk count to BH
     278    call    FloppyDrive_GetCountToAX
     279    xchg    bx, ax                  ; Floppy Drive count to BL
     280    call    RamVars_GetHardDiskCountFromBDAtoAX
     281    mov     bh, al                  ; Hard Disk count to BH
    279282    ; Fall to .MoveCursorToHotkeyStrings
    280283
     
    321324    test    bh, bh      ; Any Hard Drives?
    322325    jz      SHORT .SkipHardDriveHotkeys
    323     xchg    ax, cx      ; Store Key Attribute
    324     call    BootMenu_GetLetterForFirstHardDiskToCL
    325     mov     ch, ANGLE_QUOTE_RIGHT
    326     xchg    ax, cx
     326    call    BootMenu_GetLetterForFirstHardDiskToAL
     327    mov     ah, ANGLE_QUOTE_RIGHT
    327328    mov     si, g_szHDD
    328329    call    PushHotkeyParamsAndFormat
     
    390391    CALL_DISPLAY_LIBRARY InitializeDisplayContext
    391392    ret
    392 
    393 
    394 ;--------------------------------------------------------------------
    395 ; ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
    396 ;   Parameters:
    397 ;       BX:DX:AX:   Sector count
    398 ;   Returns:
    399 ;       Size in stack
    400 ;   Corrupts registers:
    401 ;       AX, BX, CX, DX, SI
    402 ;--------------------------------------------------------------------
    403 ALIGN JUMP_ALIGN
    404 ConvertSectorCountInBXDXAXtoSizeAndPushForFormat:
    405     pop     si                      ; Pop return address
    406     ePUSH_T cx, g_szCapacityNum     ; Push format substring
    407     call    Size_ConvertSectorCountInBXDXAXtoKiB
    408     mov     cx, BYTE_MULTIPLES.kiB
    409     call    Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
    410     push    ax                      ; Size in magnitude
    411     push    cx                      ; Tenths
    412     push    dx                      ; Magnitude character
    413     jmp     si
    414393
    415394
  • trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrintCfg.asm

    r241 r258  
    22; Description   :   Functions for printing drive configuration
    33;                   information on Boot Menu.
    4 
     4;
     5; Included by BootMenuPrint.asm, this routine is to be inserted into
     6; BootMenuPrint_HardDiskRefreshInformation.
     7;
    58; Section containing code
    69SECTION .text
     10
     11;;; fall-into from BootMenuPrint_HardDiskRefreshInformation.
    712
    813;--------------------------------------------------------------------
     
    1621;       Nothing
    1722;   Corrupts registers:
    18 ;       AX, BX, CX, DX, SI, DI
     23;       AX, BX, CX, DX
    1924;--------------------------------------------------------------------
    20 ALIGN JUMP_ALIGN
    21 BootMenuPrintCfg_ForOurDrive:
     25.BootMenuPrintCfg_ForOurDrive:
    2226    eMOVZX  ax, BYTE [di+DPT.bIdevarsOffset]
    23     xchg    si, ax                      ; CS:SI now points to IDEVARS
     27    xchg    bx, ax                      ; CS:BX now points to IDEVARS
    2428    ; Fall to .PushAndFormatCfgString
    2529
     
    2832;   Parameters:
    2933;       DS:DI:  Ptr to DPT
    30 ;       CS:SI:  Ptr to IDEVARS
     34;       CS:BX:  Ptr to IDEVARS
    3135;   Returns:
    3236;       Nothing (jumps to next push below)
    3337;   Corrupts registers:
    34 ;       AX, BX
     38;       AX, CX
    3539;--------------------------------------------------------------------
    3640.PushAddressingMode:
     
    4145    ;; with AL clear, and so we exchange AL and AH after the multiply for the final result.
    4246    ;;
    43     mov     bl,(1<<(8-ADDRESSING_MODE_FIELD_POSITION)) * g_szAddressingModes_Displacement
    44     mul     bl
     47    mov     cl,(1<<(8-ADDRESSING_MODE_FIELD_POSITION)) * g_szAddressingModes_Displacement
     48    mul     cl
    4549    xchg    al,ah
    4650    add     ax,g_szAddressingModes
     
    5155;   Parameters:
    5256;       DS:DI:  Ptr to DPT
    53 ;       CS:SI:  Ptr to IDEVARS
     57;       CS:BX:  Ptr to IDEVARS
    5458;   Returns:
    5559;       Nothing (falls to next push below)
     
    6973;   Parameters:
    7074;       DS:DI:  Ptr to DPT
    71 ;       CS:SI:  Ptr to IDEVARS
     75;       CS:BX:  Ptr to IDEVARS
    7276;   Returns:
    7377;       Nothing (jumps to next push below)
     
    7781.PushBusType:
    7882    mov     al,g_szBusTypeValues_Displacement
    79     mul     BYTE [cs:si+IDEVARS.bDevice]
     83    mul     BYTE [cs:bx+IDEVARS.bDevice]
    8084       
    8185    shr     ax,1            ; divide by 2 since IDEVARS.bDevice is multiplied by 2
     
    8892;   Parameters:
    8993;       DS:DI:  Ptr to DPT
    90 ;       CS:SI:  Ptr to IDEVARS
     94;       CS:BX:  Ptr to IDEVARS
    9195;   Returns:
    9296;       Nothing (falls to next push below)
     
    9599;--------------------------------------------------------------------
    96100.PushIRQ:
    97     mov     al, BYTE [cs:si+IDEVARS.bIRQ]
     101    mov     al, BYTE [cs:bx+IDEVARS.bIRQ]
    98102    cbw
    99103    push    ax
     
    103107;   Parameters:
    104108;       DS:DI:  Ptr to DPT
    105 ;       CS:SI:  Ptr to IDEVARS
     109;       CS:BX:  Ptr to IDEVARS
    106110;   Returns:
    107111;       Nothing (falls to next push below)
     
    114118    push    ax
    115119
    116 ;--------------------------------------------------------------------
    117 ; PrintValuesFromStack
    118 ;   Parameters:
    119 ;       Stack:  All formatting parameters
    120 ;   Returns:
    121 ;       Nothing
    122 ;   Corrupts registers:
    123 ;       AX, SI, DI
    124 ;--------------------------------------------------------------------
    125 .PrintValuesFromStack:
    126     jmp     BootMenuPrint_HardDiskRefreshInformation.output
    127 
     120;;; fall-out to BootMenuPrint_HardDiskRefreshInformation.
  • trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm

    r249 r258  
    3737%ifdef MODULE_SERIAL
    3838Device_FinalizeDPT:
    39     TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE .FinalizeDptForSerialPortDevice
     39    ; needs to check IDEVARS vs. checking the DPT as the serial bit in the DPT is set in the Finalize routine
     40    CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .FinalizeDptForSerialPortDevice
    4041    jmp     IdeDPT_Finalize
    41 .FinalizeDptForSerialPortDevice:
     42.FinalizeDptForSerialPortDevice: 
    4243    jmp     SerialDPT_Finalize
    4344
  • trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm

    r242 r258  
    1212;       CS:BP:  Ptr to IDEVARS for the controller
    1313;   Returns:
    14 ;       Nothing
     14;       CF:     Clear, IDE interface only supports hard disks
    1515;   Corrupts registers:
    1616;       AX
     
    4242;       CS:BP:  Ptr to IDEVARS for the controller
    4343;   Returns:
    44 ;       Nothing
     44;       CF:     Always clear, we don't support floppies on the IDE inteface
    4545;   Corrupts registers:
    4646;       Nothing
     
    5252
    5353.EndDPT:
     54    clc
    5455    ret
  • trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm

    r242 r258  
    5656;   Returns:
    5757;       AH:     INT 13h Error Code
     58;       CX:     Number of successfully transferred sectors (for transfer commands)
    5859;       CF:     Cleared if success, Set if error
    5960;   Corrupts registers:
     
    309310        dec     al              ; decrement sector count
    310311        push    ax              ; save
    311         jz      SerialCommand_OutputWithParameters_ReturnCodeInALCF    ; CF=0 from "cmp ax,bp" returning Zero above
     312        jz      SerialCommand_OutputWithParameters_ReturnCodeInAL
    312313
    313314        cli                     ; interrupts back off for ACK byte to host
     
    409410
    410411.clearBufferComplete:
    411         stc
    412         mov     al,1
    413 
    414 ALIGN JUMP_ALIGN
    415 SerialCommand_OutputWithParameters_ReturnCodeInALCF:
     412        mov     al, 3           ;  error return code and CF (low order bit)
     413
     414ALIGN JUMP_ALIGN
     415SerialCommand_OutputWithParameters_ReturnCodeInAL:
    416416%if 0
    417417        sti                     ;  all paths here will already have interrupts turned back on
    418418%endif
    419         mov     ah,al
    420 
    421         pop     bp              ;  recover ax (command and count) from stack, throw away
     419        mov     ah, al          ;  for success, AL will already be zero
     420
     421        pop     bx              ;  recover "ax" (command and count) from stack
    422422
    423423        pop     bp
    424424        pop     di
    425425        pop     si
     426
     427        mov     ch, 0
     428        mov     cl,[bp+IDEPACK.bSectorCount]
     429        sub     cl, bl          ; subtract off the number of sectors that remained
     430       
     431        shr     ah, 1           ; shift down return code and CF
    426432
    427433        ret
     
    632638        call    FindDPT_ToDSDIforSerialDevice
    633639        pop     si
     640%ifdef MODULE_SERIAL_FLOPPY
     641        jc      .founddpt
     642;
     643; If not found above with FindDPT_ToDSDIforSerialDevice, DI will point to the DPT after the last hard disk DPT
     644;
     645        cmp     byte [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], 0
     646        jz      .notfounddpt
     647.founddpt:
     648%else
    634649        jnc     .notfounddpt
     650%endif
    635651        mov     ax, [di+DPT_SERIAL.wSerialPortAndBaud]
    636652.notfounddpt:
     
    678694; which is read by FinalizeDPT and DetectDrives
    679695;
    680         mov     [es:si+ATA6.wVendor],dx
     696        mov     [es:si+ATA6.wSerialPortAndBaud],dx
    681697
    682698.notFound:
  • trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialDPT.asm

    r242 r258  
    1111;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    1212;   Returns:
    13 ;       Nothing
     13;       CF:     Set, indicates that this is a floppy disk
     14;               Clear, indicates that this is a hard disk
    1415;   Corrupts registers:
    1516;       AX
    1617;--------------------------------------------------------------------
    1718SerialDPT_Finalize:
    18         or      byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
    19         mov     ax, [es:si+ATA6.wVendor]
     19        mov     ax, [es:si+ATA6.wSerialPortAndBaud]
    2020        mov     [di+DPT_SERIAL.wSerialPortAndBaud], ax
     21
     22;
     23; Note that this section is not under %ifdef MODULE_SERIAL_FLOPPY.  It is important to
     24; detect floppy disks presented by the server and not treat them like hard disks, even
     25; if the floppy support is disabled.
     26;
     27        mov     al, [es:si+ATA6.wSerialFloppyFlagAndType]
     28        or      al, FLGH_DPT_SERIAL_DEVICE
     29        or      byte [di+DPT.bFlagsHigh], al
     30
     31        test    al, FLGH_DPT_SERIAL_FLOPPY           ; clears CF
     32        jz      .notfloppy
     33        stc     
     34.notfloppy:     
     35       
    2136        ret
    2237
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm

    r249 r258  
    2929    mov     [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
    3030    call    RamVars_IsFunctionHandledByThisBIOS
    31     jnc     SHORT Int13h_DirectCallToAnotherBios
     31    jc      SHORT Int13h_DirectCallToAnotherBios
     32
    3233    call    FindDPT_ForDriveNumber      ; DS:DI now points to DPT
    3334
     
    139140ALIGN JUMP_ALIGN
    140141Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
     142%ifdef MODULE_SERIAL_FLOPPY
     143    mov     al, [bp+IDEPACK.intpack+INTPACK.dl]
     144Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:   
     145    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
     146%else
    141147    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
     148%endif
    142149Int13h_ReturnFromHandlerWithoutStoringErrorCode:
    143150    or      WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF   ; Return with interrupts enabled
     
    154161;   Returns:
    155162;       Depends on function
     163;       NOTE: ES:DI needs to be returned from the previous interrupt
     164;             handler, for floppy DPT in function 08h
    156165;   Corrupts registers:
    157 ;       BX, DI, ES
     166;       None
    158167;--------------------------------------------------------------------
    159168ALIGN JUMP_ALIGN
    160169Int13h_CallPreviousInt13hHandler:
    161     push    di
    162170    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
    163171    int     BIOS_DISK_INTERRUPT_13h
    164     call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
    165     pop     di
    166     ret
    167 
     172;;;  fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler
    168173
    169174;--------------------------------------------------------------------
     
    174179;       Nothing
    175180;   Corrupts registers:
    176 ;       DI
     181;       Nothing
     182;       Note: Flags are preserved
    177183;--------------------------------------------------------------------
    178184ALIGN JUMP_ALIGN
    179185ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
    180186    push    es
    181     LOAD_BDA_SEGMENT_TO es, di
    182     mov     di, [RAMVARS.fpOldI13h]
     187    push    si
     188    LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO  es, si
     189    mov     si, [RAMVARS.fpOldI13h]
    183190    cli
    184     xchg    di, [es:BIOS_DISK_INTERRUPT_13h*4]
    185     mov     [RAMVARS.fpOldI13h], di
    186     mov     di, [RAMVARS.fpOldI13h+2]
    187     xchg    di, [es:BIOS_DISK_INTERRUPT_13h*4+2]
     191    xchg    si, [es:BIOS_DISK_INTERRUPT_13h*4]
     192    mov     [RAMVARS.fpOldI13h], si
     193    mov     si, [RAMVARS.fpOldI13h+2]
     194    xchg    si, [es:BIOS_DISK_INTERRUPT_13h*4+2]
    188195    sti
    189     mov     [RAMVARS.fpOldI13h+2], di
     196    mov     [RAMVARS.fpOldI13h+2], si
     197    pop     si
    190198    pop     es
    191199    ret
     
    204212;--------------------------------------------------------------------
    205213ALIGN JUMP_ALIGN
     214%ifdef MODULE_SERIAL_FLOPPY
     215Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
     216    ; Store error code to BDA
     217    mov     bx, BDA.bHDLastSt
     218    test    al, al
     219    js      .HardDisk
     220    mov     bl, BDA.bFDRetST & 0xff
     221.HardDisk:
     222    LOAD_BDA_SEGMENT_TO ds, di
     223    mov     [bx], ah       
     224%else
    206225Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
    207226    ; Store error code to BDA
    208     LOAD_BDA_SEGMENT_TO ds, di
     227    LOAD_BDA_SEGMENT_TO ds, di     
    209228    mov     [BDA.bHDLastSt], ah
     229%endif
    210230
    211231    ; Store error code to INTPACK
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm

    r152 r258  
    2222    eMOVZX  bx, dl                      ; Copy requested drive to BL, zero BH to assume no errors
    2323    call    ResetFloppyDrivesWithInt40h
    24     test    bl, bl
    25     jns     SHORT .SkipHardDiskReset
    2624    call    ResetForeignHardDisks
    2725    call    AH0h_ResetHardDisksHandledByOurBIOS
     
    6462    xor     ah, ah                      ; Disk Controller Reset
    6563    call    Int13h_CallPreviousInt13hHandler
    66     jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
    67 
     64;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
     65
     66
     67;--------------------------------------------------------------------
     68; BackupErrorCodeFromTheRequestedDriveToBH
     69;   Parameters:
     70;       AH:     Error code from the last resetted drive
     71;       DL:     Drive last resetted
     72;       BL:     Requested drive (DL when entering AH=00h)
     73;   Returns:
     74;       BH:     Backuped error code
     75;   Corrupts registers:
     76;       Nothing
     77;--------------------------------------------------------------------
     78ALIGN JUMP_ALIGN
     79BackupErrorCodeFromTheRequestedDriveToBH:
     80    cmp     dl, bl              ; Requested drive?
     81    eCMOVE  bh, ah
     82    ret
     83       
    6884
    6985;--------------------------------------------------------------------
     
    8298    mov     dl, bl
    8399    call    RamVars_IsDriveHandledByThisBIOS
    84     jnc     SHORT .Return               ; Return what was in BL unmodified
     100    jc      SHORT .Return               ; Return what was in BL unmodified
    85101    mov     dl, 80h
    86102.Return:
     
    101117ALIGN JUMP_ALIGN
    102118AH0h_ResetHardDisksHandledByOurBIOS:
    103     mov     dh, [RAMVARS.bDrvCnt]       ; Load drive count to DH
     119    mov     dx, [RAMVARS.wDrvCntAndFirst]   ; DL = drive number, DH = drive count
    104120    test    dh, dh
    105121    jz      SHORT .AllDrivesReset       ; Return if no drives
    106     mov     dl, [RAMVARS.bFirstDrv]     ; Load number of our first drive
    107122    add     dh, dl                      ; DH = one past last drive to reset
    108123ALIGN JUMP_ALIGN
     
    114129    jb      SHORT .DriveResetLoop       ;  If not, reset next drive
    115130.AllDrivesReset:
    116     ret
    117 
     131%ifdef MODULE_SERIAL_FLOPPY
     132;
     133; "Reset" emulatd serial floppy drives, if any.  There is nothing to actually do for this reset,
     134; but record the proper error return code if one of these floppy drives is the drive requested.
     135;
     136    call    RamVars_UnpackFlopCntAndFirstToAL
     137
     138    cbw                                                 ; Clears AH (there are flop drives) or ffh (there are not)
     139                                                        ; Either AH has success code (flop drives are present)
     140                                                        ; or it doesn't matter because we won't match drive ffh
     141
     142    cwd                                                 ; clears DX (there are flop drives) or ffffh (there are not)
     143
     144    adc     dl, al                                      ; second drive (CF set) if present
     145                                                        ; If no drive is present, this will result in ffh which
     146                                                        ; won't match a drive
     147    call    BackupErrorCodeFromTheRequestedDriveToBH
     148    mov     dl, al                                      ; We may end up doing the first drive twice (if there is
     149    jmp     BackupErrorCodeFromTheRequestedDriveToBH    ; only one drive), but doing it again is not harmful.
     150%else
     151    ret
     152%endif
     153       
    118154;--------------------------------------------------------------------
    119155; .BackupErrorCodeFromMasterOrSlaveToBH
     
    144180    ret
    145181
     182       
    146183;--------------------------------------------------------------------
    147184; GetBasePortToCX
     
    167204
    168205
    169 ;--------------------------------------------------------------------
    170 ; BackupErrorCodeFromTheRequestedDriveToBH
    171 ;   Parameters:
    172 ;       AH:     Error code from the last resetted drive
    173 ;       DL:     Drive last resetted
    174 ;       BL:     Requested drive (DL when entering AH=00h)
    175 ;   Returns:
    176 ;       BH:     Backuped error code
    177 ;   Corrupts registers:
    178 ;       Nothing
    179 ;--------------------------------------------------------------------
    180 ALIGN JUMP_ALIGN
    181 BackupErrorCodeFromTheRequestedDriveToBH:
    182     cmp     dl, bl              ; Requested drive?
    183     eCMOVE  bh, ah
    184     ret
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH15h_HSize.asm

    r257 r258  
    1515;   Returns with INTPACK:
    1616;       If succesfull:
    17 ;           AH:     3 (Hard disk accessible)
     17;           AH:     Hard Disk: 3 (Hard disk accessible)
     18;                   Floppy:    1 (Floppy disk, without change detection)
    1819;           CX:DX:  Total number of sectors
    1920;           CF:     0
     
    2526ALIGN JUMP_ALIGN
    2627AH15h_HandlerForReadDiskDriveSize:
     28%ifdef MODULE_SERIAL_FLOPPY
     29    mov     cl, 1                                       ; 1 = floppy disk, no change detection
     30               
     31    test    dl,dl                                       ; DO NOT store the sector count if this is a
     32    jns     .FloppyDrive                                ; floppy disk, some OS's depend on this not
     33                                                        ; happening for floppies in order to boot.
     34%endif
     35       
    2736    call    AH15h_GetSectorCountToBXDXAX
    28     mov     [bp+IDEPACK.intpack+INTPACK.cx], dx ; HIWORD to CX
    29     mov     [bp+IDEPACK.intpack+INTPACK.dx], ax ; LOWORD to DX
     37    mov     [bp+IDEPACK.intpack+INTPACK.cx], dx         ; HIWORD to CX
     38    xchg    [bp+IDEPACK.intpack+INTPACK.dx], ax         ; LOWORD to DX, AL gets drive number
    3039
    31     xor     ah, ah
    32     call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH    ; Store success to BDA and CF
    33     mov     BYTE [bp+IDEPACK.intpack+INTPACK.ah], 3             ; Type code = Hard disk
     40    xor     ah, ah     
     41%ifdef MODULE_SERIAL_FLOPPY             
     42    mov     cl, 3                                       ; 3 = Hard Disk Accessible
     43.FloppyDrive:
     44       
     45    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber   ; Store success to BDA and CF       
     46    mov     BYTE [bp+IDEPACK.intpack+INTPACK.ah], cl
     47%else
     48    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH    ; Store success to BDA and CF       
     49    mov     BYTE [bp+IDEPACK.intpack+INTPACK.ah], 3
     50%endif     
     51       
    3452    jmp     Int13h_ReturnFromHandlerWithoutStoringErrorCode
    3553
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1h_HStatus.asm

    r150 r258  
    2020AH1h_HandlerForReadDiskStatus:
    2121    LOAD_BDA_SEGMENT_TO ds, ax, !
     22
     23%ifdef MODULE_SERIAL_FLOPPY
     24    test    dl, dl
     25    jns     .HardDisk
     26    mov     ah, [BDA.bFDRetST]      ; Unlike for hard disks below, floppy version does not clear the status
     27    jmp     .done
     28.HardDisk: 
     29%endif
     30       
    2231    xchg    ah, [BDA.bHDLastSt]     ; Load and clear last error
     32                                    ; Note that AH is cleared with the LOAD_BDA_SEGMENT above
     33               
     34.done:
    2335    call    Int13h_SetErrorCodeToIntpackInSSBPfromAH
    2436    jmp     Int13h_ReturnFromHandlerWithoutStoringErrorCode
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm

    r249 r258  
    4040    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
    4141%endif
     42
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm

    r227 r258  
    1414;       SS:BP:  Ptr to IDEPACK
    1515;   Returns with INTPACK:
     16;       BL:     Drive Type (for floppies only)
    1617;       CH:     Maximum cylinder number, bits 7...0
    1718;       CL:     Bits 7...6: Cylinder number bits 9...8
     
    1920;       DH:     Maximum head number (0...255)
    2021;       DL:     Number of drives
     22;       ES:DI:  Floppy DPT (for floppies only)
    2123;       AH:     Int 13h/40h floppy return status
    2224;       CF:     0 if successfull, 1 if error
    2325;--------------------------------------------------------------------
    2426AH8h_HandlerForReadDiskDriveParameters:
     27
    2528    call    RamVars_IsDriveHandledByThisBIOS
    26     jnc     SHORT .GetDriveParametersForForeignHardDiskInDL
     29    jnc     SHORT .OurDrive
     30
     31    call    Int13h_CallPreviousInt13hHandler
     32    jnc     SHORT .MidGame
     33    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
     34       
     35.OurDrive:     
    2736    call    AH8h_GetDriveParameters
    28     jmp     SHORT .ReturnAfterStoringValuesToIntpack
    2937
    30 .GetDriveParametersForForeignHardDiskInDL:
    31     call    Int13h_CallPreviousInt13hHandler
    32     jc      SHORT .ReturnErrorFromPreviousInt13hHandler
    33     call    RamVars_GetCountOfKnownDrivesToDL
    34 .ReturnAfterStoringValuesToIntpack:
     38%ifdef MODULE_SERIAL_FLOPPY
     39    push    cs                          ; setup registers if we are a floppy drive, in all cases
     40    pop     es                          ; if it is not a floppy drive, these values will not be put in INTPACK
     41    mov     di, AH8h_FloppyDPT
     42%endif
     43    ;; fall-through
     44       
     45.MidGame:       
     46    call    RamVars_GetCountOfKnownDrivesToAX       ; assume hard disk for now, will discard if for floppies
     47
     48    test    byte [bp+IDEPACK.intpack+INTPACK.dl], 080h
     49    jnz     .Done
     50       
     51    mov     [bp+IDEPACK.intpack+INTPACK.bl], bl
     52
     53    mov     [bp+IDEPACK.intpack+INTPACK.es], es
     54    mov     [bp+IDEPACK.intpack+INTPACK.di], di     
     55
     56    call    FloppyDrive_GetCountToAX
     57
     58.Done: 
     59    mov     ah, dh
     60       
    3561    mov     [bp+IDEPACK.intpack+INTPACK.cx], cx
    36     mov     [bp+IDEPACK.intpack+INTPACK.dx], dx
     62    xchg    [bp+IDEPACK.intpack+INTPACK.dx], ax     ; recover DL for BDA last status byte determination
     63
    3764    xor     ah, ah
    38 .ReturnErrorFromPreviousInt13hHandler:
     65%ifdef MODULE_SERIAL_FLOPPY
     66    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber           
     67%else
    3968    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
     69%endif
    4070
    4171
     
    5181;               Bits 5...0: Maximum sector number (1...63)
    5282;       DH:     Maximum head number (0...255)
    53 ;       DL:     Number of drives
    5483;   Corrupts registers:
    5584;       AX, BX
     
    73102;               Bits 5...0: Maximum sector number (1...63)
    74103;       DH:     Maximum head number (0...255)
    75 ;       DL:     Number of drives
    76104;   Corrupts registers:
    77105;       AX, BX
     
    85113    or      cl, bh                  ; CL bits 0...5 = Sectors per track
    86114    mov     dh, bl                  ; DH = Maximum head number
    87     jmp     RamVars_GetCountOfKnownDrivesToDL
     115       
     116%ifdef MODULE_SERIAL_FLOPPY
     117    mov     bl,[di+DPT.bFlagsHigh]
     118    eSHR_IM bl,FLGH_DPT_SERIAL_FLOPPY_TYPE_FIELD_POSITION
     119%endif     
     120    ret
     121
     122%ifdef MODULE_SERIAL_FLOPPY
     123;
     124; Floppy Disk Parameter Table.  There is no way to specify more than one of these
     125; for any given system, so no way to make this drive or media specific.
     126; So we return fixed values out of the ROM for callers might be expecting this information.
     127;
     128; On AT systems, we return the information for a 1.44 MB disk,
     129; and on XT systems, we return the information for a 360 KB disk.
     130;
     131AH8h_FloppyDPT:
     132%ifdef USE_AT
     133    db      0ah << 4 | 0fh          ; Offset 0: Drive timings, 1.44MB values
     134%else
     135    db      0dh << 4 | 0fh          ; Offset 0: Drive timings, 360KB values
     136%endif
     137
     138    db      1h << 1 | 0             ; Offset 1: Typical values of 1 for head load time
     139                                    ;           DMA used (although it actually is not, but is more restrctive)
     140    db      25h                     ; Offset 2: Inactiviy motor turn-off delay,
     141                                    ;           Typical value of 25h for 2 second delay
     142    db      02h                     ; Offset 3: Sector size, always 512
     143
     144%ifdef USE_AT
     145    db      12h                     ; Offset 4: Sectors per track, 1.44MB value
     146    db      1bh                     ; Offset 5: Sector gap, 1.44MB value
     147%else
     148    db      09h                     ; Offset 4: Sectors per track, 360KB value
     149    db      2ah                     ; Offset 5: Sector gap, 360KB value
     150%endif
     151
     152    db      0ffh                    ; Offset 6: Data length
     153
     154%ifdef USE_AT
     155    db      6ch                     ; Offset 7: Format gap length, 1.44MB value
     156%else
     157    db      50h                     ; Offset 7: Format gap length, 360KB value
     158%endif
     159
     160    db      0f6h                    ; Offset 8: Fill byte for format
     161    db      0fh                     ; Offset 9: Head setting time
     162    db      08h                     ; Offset A: Wait for motor startpu time
     163
     164%ifdef USE_AT
     165    db      79                      ; Offset B: Maximum track number, 1.44MB value
     166    db      0                       ; Offset C: Data transfer rate, 1.44MB value
     167    db      4                       ; Offset D: Diskette CMOS drive type, 1.44MB value
     168%else
     169    db      39                      ; Offset B: Maximum track number, 360KB value
     170    db      80h                     ; Offset C: Data transfer rate, 360KB value
     171    db      1                       ; Offset D: Diskette CMOS drive type, 360KB value
     172%endif
     173%endif
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm

    r227 r258  
    4343    push    cx
    4444
     45%ifdef MODULE_SERIAL
     46    ;
     47    ; no need to do this for serial deveices, and we use the DPT_RESET flag bits
     48    ; to store the drive type for serial floppy drives (MODULE_SERIAL_FLOPPY)
     49    ;
     50    xor     ah, ah
     51    test    byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE    ; Clears CF
     52    jnz     .ReturnNotSuccessfull
     53%endif
     54       
    4555    ; Try to select drive and wait until ready
    4656    or      BYTE [di+DPT.bFlagsHigh], MASKH_DPT_RESET       ; Everything uninitialized
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm

    r250 r258  
    3131    ; Install INT 19h handler for proper reboot
    3232    LOAD_BDA_SEGMENT_TO es, ax
    33     mov     bx, BIOS_BOOT_LOADER_INTERRUPT_19h  ; INT 19h interrupt vector offset
     33    mov     al, BIOS_BOOT_LOADER_INTERRUPT_19h  ; INT 19h interrupt vector offset
    3434    mov     si, Int19h_ResetHandler             ; INT 19h handler to reboot the system
    35     call    Interrupts_InstallHandlerToVectorInBXFromCSSI
     35    call    Interrupts_InstallHandlerToVectorInALFromCSSI
    3636    call    Initialize_AndDetectDrives          ; Installs new boot menu loader
    3737    ; Fall to .PrepareStackAndSelectDriveFromBootMenu
  • trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm

    r254 r258  
    4343
    4444%ifdef MODULE_SERIAL
     45;----------------------------------------------------------------------
    4546;
    4647; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
     
    5758%endif
    5859
    59 .done:
     60.done: 
     61%ifdef MODULE_SERIAL_FLOPPY
     62;----------------------------------------------------------------------
     63;
     64; Add in any emulated serial floppy drives.
     65;
     66    mov     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
     67    dec     al
     68    mov     cl, al
     69    js      .NoFloppies                     ; if no drives are present, we store 0ffh
     70
     71    call    FloppyDrive_GetCountFromBIOS_or_BDA
     72
     73    push    ax
     74
     75    add     al, cl                          ; Add our drives to existing drive count
     76    cmp     al, 3                           ; For BDA, max out at 4 drives (ours is zero based)
     77    jl      .MaxBDAFloppiesExceeded
     78    mov     al, 3                           
     79.MaxBDAFloppiesExceeded:
     80    eROR_IM al, 2                           ; move to bits 6-7
     81    inc     ax                              ; low order bit, indicating floppy drive exists
     82
     83    mov     ah, [es:BDA.wEquipment]         ; Load Equipment WORD low byte 
     84    and     ah, 03eh                        ; Mask off drive number and drives present bit
     85    or      al, ah                          ; Or in new values
     86    mov     [es:BDA.wEquipment], al         ; and store
     87
     88    mov     al, 1eh                         ; BDA pointer to Floppy DPT
     89    mov     si, AH8h_FloppyDPT
     90    call    Interrupts_InstallHandlerToVectorInALFromCSSI
     91
     92    pop     ax
     93
     94    shr     cl, 1                           ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
     95    rcl     al, 1                           ; starting drive number in upper 7 bits, number of drives in low bit
     96.NoFloppies:   
     97    mov     [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
     98%endif
     99       
    60100    ret
    61101
  • trunk/XTIDE_Universal_BIOS/Src/Initialization/FloppyDrive.asm

    r181 r258  
    120120; Returns number of Floppy Drives in system.
    121121;
    122 ; FloppyDrive_GetCountToCX
    123 ;   Parameters:
    124 ;       Nothing
    125 ;   Returns:
    126 ;       CX:     Number of Floppy Drives
    127 ;   Corrupts registers:
    128 ;       Nothing
    129 ;--------------------------------------------------------------------
    130 ALIGN JUMP_ALIGN
    131 FloppyDrive_GetCountToCX:
     122; FloppyDrive_GetCountToAX
     123;   Parameters:
     124;       DS:     RAMVARS Segment
     125;   Returns:
     126;       AX:     Number of Floppy Drives
     127;--------------------------------------------------------------------
     128ALIGN JUMP_ALIGN
     129FloppyDrive_GetCountToAX:       
     130%ifdef MODULE_SERIAL_FLOPPY
     131    call    RamVars_UnpackFlopCntAndFirstToAL
     132    adc     al,1                        ; adds in the drive count bit, and adds 1 for count vs. 0-index,
     133                                        ; but still won't impact SF
     134    jns     .UseInternalNumber          ; need to clear CH on the way out, and add in additional drive numbers
     135
     136%endif
     137    call    FloppyDrive_GetCountFromBIOS_or_BDA
     138       
     139.UseInternalNumber:
     140    mov     ah, [cs:ROMVARS.bMinFddCnt]
     141    MAX_U   al, ah
     142    cbw
     143       
     144    ret
     145
     146ALIGN JUMP_ALIGN       
     147FloppyDrive_GetCountFromBIOS_or_BDA:
    132148    push    es
    133 %ifdef USE_AT
    134     call    GetCountFromBIOS
    135 %else
    136     call    GetCountFromBDA
    137 %endif
    138     mov     ch, [cs:ROMVARS.bMinFddCnt]
    139     MAX_U   cl, ch
    140     pop     es
    141     xor     ch, ch
    142     ret
    143 
    144149
    145150;--------------------------------------------------------------------
     
    160165%ifdef USE_AT
    161166ALIGN JUMP_ALIGN
    162 GetCountFromBIOS:
     167.GetCountFromBIOS:
    163168    push    di
    164169    push    dx
    165170    push    bx
    166     push    ax
    167171
    168172    mov     ah, 08h                 ; Get Drive Parameters
    169173    cwd                             ; Floppy Drive 00h
    170174    int     BIOS_DISKETTE_INTERRUPT_40h
    171     mov     cl, dl                  ; Number of Floppy Drives to CL
    172 
    173     pop     ax
     175    mov     al, dl                  ; Number of Floppy Drives to AL
     176
    174177    pop     bx
    175178    pop     dx
    176179    pop     di
    177     ret
    178 %endif
    179 
     180%endif
    180181
    181182;--------------------------------------------------------------------
     
    193194%ifndef USE_AT
    194195ALIGN JUMP_ALIGN
    195 GetCountFromBDA:
    196     LOAD_BDA_SEGMENT_TO es, cx
    197     mov     cl, [es:BDA.wEquipment]         ; Load Equipment WORD low byte
    198     mov     ch, cl                          ; Copy it to CH
    199     and     cx, 0C001h                      ; Leave bits 15..14 and 0
    200     eROL_IM ch, 2                           ; EW low byte bits 7..6 to 1..0
    201     add     cl, ch                          ; CL = Floppy Drive count
    202     ret
    203 %endif
     196.GetCountFromBDA:
     197    LOAD_BDA_SEGMENT_TO es, ax
     198    mov     al, [es:BDA.wEquipment]         ; Load Equipment WORD low byte
     199    mov     ah, al                          ; Copy it to CH
     200    and     ax, 0C001h                      ; Leave bits 15..14 and 0
     201    eROL_IM ah, 2                           ; EW low byte bits 7..6 to 1..0
     202    add     al, ah                          ; CL = Floppy Drive count
     203%endif
     204
     205    pop     es
     206    ret
     207       
  • trunk/XTIDE_Universal_BIOS/Src/Initialization/Initialize.asm

    r243 r258  
    2929
    3030    ; Install INT 19h handler (boot loader) where drives are detected
    31     mov     bx, BIOS_BOOT_LOADER_INTERRUPT_19h
     31    mov     al, BIOS_BOOT_LOADER_INTERRUPT_19h
    3232    mov     si, Int19h_BootLoaderHandler
    33     call    Interrupts_InstallHandlerToVectorInBXFromCSSI
     33    call    Interrupts_InstallHandlerToVectorInALFromCSSI
    3434
    3535.SkipRomInitialization:
     
    7373    mov     dl, 80h
    7474    call    RamVars_IsDriveHandledByThisBIOS
    75     jnc     SHORT .FindForDrive81h  ; Store nothing if not our drive
     75    jc      SHORT .FindForDrive81h  ; Store nothing if not our drive
    7676    call    FindDPT_ForDriveNumber  ; DPT to DS:DI
    7777    mov     [es:HD0_DPT_POINTER_41h*4], di
     
    8080    inc     dx
    8181    call    RamVars_IsDriveHandledByThisBIOS
    82     jnc     SHORT .ResetDetectedDrives
     82    jc      SHORT .ResetDetectedDrives
    8383    call    FindDPT_ForDriveNumber
    8484    mov     [es:HD1_DPT_POINTER_46h*4], di
  • trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm

    r243 r258  
    3434    mov     ax, [es:BIOS_DISK_INTERRUPT_13h*4]  ; Load old INT 13h offset
    3535    mov     [RAMVARS.fpOldI13h], ax             ; Store old INT 13h offset
    36 
    37     mov     bx, BIOS_DISK_INTERRUPT_13h         ; INT 13h interrupt vector offset
    38     mov     si, Int13h_DiskFunctionsHandler     ; Interrupt handler offset
    39     call    Interrupts_InstallHandlerToVectorInBXFromCSSI
    4036
    4137    ; Only store INT 13h handler to 40h if 40h is not already installed.
     
    4743    mov     [es:BIOS_DISKETTE_INTERRUPT_40h*4+2], dx    ; Store old INT 13h segment
    4844.Int40hAlreadyInstalled:
     45
     46    mov     al, BIOS_DISK_INTERRUPT_13h         ; INT 13h interrupt vector offset
     47    mov     si, Int13h_DiskFunctionsHandler     ; Interrupt handler offset
     48    call    Interrupts_InstallHandlerToVectorInALFromCSSI
    4949    ; Fall to .InitializeHardwareIrqHandlers
    5050
     
    5656;       Nothing
    5757;   Corrupts registers:
    58 ;       BX, CX, DX, SI, DI
     58;       BX, CX, DX, SI, DI, AX
    5959;--------------------------------------------------------------------
    6060.InitializeHardwareIrqHandlers:
     
    6262    mov     di, ROMVARS.ideVars0            ; CS:SI points to first IDEVARS
    6363.IdeControllerLoop:
    64     eMOVZX  bx, BYTE [cs:di+IDEVARS.bIRQ]
     64    mov     al, BYTE [cs:di+IDEVARS.bIRQ]
    6565    add     di, BYTE IDEVARS_size           ; Increment to next controller
    6666    call    .InstallLowOrHighIrqHandler
     
    7272; .InstallLowOrHighIrqHandler
    7373;   Parameters:
    74 ;       BX:     IRQ number, 0 if IRQ disabled
     74;       AL:     IRQ number, 0 if IRQ disabled
    7575;       ES:     BDA and Interrupt Vector segment (zero)
    7676;   Returns:
     
    8080;--------------------------------------------------------------------
    8181.InstallLowOrHighIrqHandler:
    82     test    bl, bl
     82    test    al, al
    8383    jz      SHORT .Return   ; IRQ not used
    84     cmp     bl, 8
     84    cmp     al, 8
    8585    jb      SHORT .InstallLowIrqHandler
    8686    ; Fall to .InstallHighIrqHandler
     
    9494;       Nothing
    9595;   Corrupts registers:
    96 ;       BX, SI
     96;       AL, BX, SI
    9797;--------------------------------------------------------------------
    9898.InstallHighIrqHandler:
    99     add     bx, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8   ; Interrupt vector number
     99    add     al, BYTE HARDWARE_IRQ_8_INTERRUPT_70h - 8   ; Interrupt vector number
    100100    mov     si, IdeIrq_InterruptServiceRoutineForIrqs8to15
    101     jmp     SHORT Interrupts_InstallHandlerToVectorInBXFromCSSI
     101    jmp     SHORT Interrupts_InstallHandlerToVectorInALFromCSSI
    102102
    103103;--------------------------------------------------------------------
    104104; .InstallLowIrqHandler
    105105;   Parameters:
    106 ;       BX:     IRQ number (0...7)
    107 ;       ES:     BDA and Interrupt Vector segment (zero)
    108 ;   Returns:
    109 ;       Nothing
    110 ;   Corrupts registers:
    111 ;       BX, SI
     106;       AL:     IRQ number (0...7)
     107;       ES:     BDA and Interrupt Vector segment (zero)
     108;   Returns:
     109;       Nothing
     110;   Corrupts registers:
     111;       AL, BX, SI
    112112;--------------------------------------------------------------------
    113113.InstallLowIrqHandler:
    114     add     bx, BYTE HARDWARE_IRQ_0_INTERRUPT_08h       ; Interrupt vector number
     114    add     al, BYTE HARDWARE_IRQ_0_INTERRUPT_08h       ; Interrupt vector number
    115115    mov     si, IdeIrq_InterruptServiceRoutineForIrqs2to7
    116     ; Fall to Interrupts_InstallHandlerToVectorInBXFromCSSI
    117 
    118 
    119 ;--------------------------------------------------------------------
    120 ; Interrupts_InstallHandlerToVectorInBXFromCSSI
    121 ;   Parameters:
    122 ;       BX:     Interrupt vector number (for example 13h)
     116    ; Fall to Interrupts_InstallHandlerToVectorInALFromCSSI
     117
     118
     119;--------------------------------------------------------------------
     120; Interrupts_InstallHandlerToVectorInALFromCSSI
     121;   Parameters:
     122;       AL:     Interrupt vector number (for example 13h)
    123123;       ES:     BDA and Interrupt Vector segment (zero)
    124124;       CS:SI:  Ptr to interrupt handler
     
    126126;       Nothing
    127127;   Corrupts registers:
    128 ;       BX
    129 ;--------------------------------------------------------------------
    130 Interrupts_InstallHandlerToVectorInBXFromCSSI:
    131     eSHL_IM bx, 2                   ; Shift for DWORD offset
     128;       AX, BX
     129;--------------------------------------------------------------------
     130Interrupts_InstallHandlerToVectorInALFromCSSI:
     131    mov     bl, 4                   ; Shift for DWORD offset, MUL smaller than other alternatives
     132    mul     bl
     133    xchg    ax, bx
    132134    mov     [es:bx], si             ; Store offset
    133135    mov     [es:bx+2], cs           ; Store segment
  • trunk/XTIDE_Universal_BIOS/Src/Main.asm

    r254 r258  
    176176    %include "BootMenuEvent.asm"    ; For menu library event handling
    177177                                    ; NOTE: BootMenuPrint needs to come immediately after BootMenuEvent
    178     %include "BootMenuPrint.asm"    ; For printing Boot Menu strings
     178                                    ;       so that jump table entries in BootMenuEvent stay within 8-bits
     179    %include "BootMenuPrint.asm"    ; For printing Boot Menu strings, also includes "BootMenuPrintCfg.asm"
    179180    %include "BootPrint.asm"        ; For printing boot information
    180     %include "BootMenuPrintCfg.asm" ; For printing hard disk configuration
    181181    %include "FloppyDrive.asm"      ; Floppy Drive related functions
    182182    %include "BootSector.asm"       ; For loading boot sector
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm

    r227 r258  
    6363.StoreFlags:
    6464    mov     [di+DPT.wFlags], ax
    65 
    66 %ifdef MODULE_SERIAL
    67     cmp     byte [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
    68     jnz     .StoreAddressing
    69     or      byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
    70 %endif
    7165    ; Fall to .StoreAddressing
    7266
     
    205199.StoreDeviceSpecificParameters:
    206200    call    Device_FinalizeDPT
     201
     202%ifdef MODULE_SERIAL_FLOPPY
     203;
     204; These two instructions serve two purposes:
     205; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
     206; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
     207;    effectively discarded.  This is more of a safety check then code that should ever normally be hit (see below).
     208;    Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
     209;    this was necessary.  Now, this situation shouldn't happen in normal operation, for a couple of reasons:
     210;       A. xtidecfg always puts configured serial ports at the end fo the IDEVARS list
     211;       B. the auto serial code is always executed last
     212;       C. the serial server always returns floppy drives last
     213;
     214    adc     byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
     215    jnz     .AllDone   
     216%else
     217;
     218; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
     219; could lead to unpredictable results since no MBR will be present, etc.  The server doesn't know that
     220; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
     221;
     222    jc      .AllDone
     223%endif
     224
    207225    ; Fall to .StoreDriveNumberAndUpdateDriveCount
    208226
     
    230248    ja      SHORT .AllDone              ;  If so, return
    231249    mov     [RAMVARS.bFirstDrv], dl     ; Store first drive number
     250
     251.AllDone:
    232252    clc
    233 .AllDone:
    234253    ret
     254
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm

    r233 r258  
    1414;       DS:DI:  Ptr to first unused DPT
    1515;   Corrupts registers:
    16 ;       DL
     16;       DX
    1717;--------------------------------------------------------------------
    1818ALIGN JUMP_ALIGN
    1919FindDPT_ForNewDriveToDSDI:
    20     mov     dl, [RAMVARS.bFirstDrv]
    21     add     dl, [RAMVARS.bDrvCnt]
     20    mov     ax, [RAMVARS.wDrvCntAndFirst]
     21    add     al, ah
     22%ifdef MODULE_SERIAL_FLOPPY
     23    add     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
     24%endif
     25    xchg    ax, dx     
    2226    ; Fall to FindDPT_ForDriveNumber
    2327
     
    4145    xchg    di, ax  ; Save the contents of AX in DI
    4246
     47%ifdef MODULE_SERIAL_FLOPPY
     48    mov     ax, [RAMVARS.wDrvCntAndFirst]
     49       
     50    test    dl, dl
     51    js      .harddisk
     52
     53    call    RamVars_UnpackFlopCntAndFirstToAL
     54    add     dl, ah                      ; add in end of hard disk DPT list, floppies start immediately after
     55.harddisk:
     56    sub     dl, al                      ; subtract off beginning of either hard disk or floppy list (as appropriate)
     57%else
     58    sub     dl, [RAMVARS.bFirstDrv]     ; subtract off beginning of hard disk list
     59%endif
     60       
    4361    mov     al, LARGEST_DPT_SIZE
    44     sub     dl, [RAMVARS.bFirstDrv]
     62       
    4563    mul     dl
    4664    add     ax, BYTE RAMVARS_size
    4765
    48     xchg    di, ax  ; Restore AX and put result in DI
     66    xchg    di, ax                      ; Restore AX and put result in DI
    4967    pop     dx
    5068    ret
     
    89107; IterateToMasterAtPortCallback
    90108;   Parameters:
    91 ;       CH:     Drive number
    92109;       DX:     IDE Base Port address
    93110;       DS:DI:  Ptr to DPT to examine
    94111;   Returns:
    95 ;       DL:     Drive number if correct DPT
    96112;       CF:     Set if wanted DPT found
    97113;               Cleared if wrong DPT
     
    116132    pop     bx
    117133    jne     SHORT ReturnWrongDPT
    118     mov     dl, ch                              ; Return drive number in DL
    119134
    120135ReturnRightDPT:
     
    187202;   Returns:
    188203;       DS:DI:      Ptr to wanted DPT (if found)
     204;                   If not found, points to first empty DPT
    189205;       CF:         Set if wanted DPT found
    190206;                   Cleared if DPT not found, or no DPTs present
     
    195211IterateAllDPTs:
    196212    push    cx
    197     mov     cx, [RAMVARS.wDrvCntAndFirst]
     213
     214    mov     cl, [RAMVARS.bDrvCnt]       
     215    mov     ch, 0
     216       
     217    mov     di, RAMVARS_size            ; Point DS:DI to first DPT
     218       
    198219    jcxz    .NotFound                   ; Return if no drives
    199     mov     di, RAMVARS_size            ; Point DS:DI to first DPT
     220       
    200221ALIGN JUMP_ALIGN
    201222.LoopWhileDPTsLeft:
    202223    call    si                          ; Is wanted DPT?
    203224    jc      SHORT .AllDptsIterated      ;  If so, return
    204     inc     ch                          ; Increment drive number
    205225    add     di, BYTE LARGEST_DPT_SIZE   ; Point to next DPT
    206     dec     cl                          ; Decrement drives left
    207     jnz     SHORT .LoopWhileDPTsLeft
     226    loop    .LoopWhileDPTsLeft
     227       
    208228.NotFound:     
    209229    clc                                 ; Clear CF since DPT not found
     230       
    210231ALIGN JUMP_ALIGN
    211232.AllDptsIterated:
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm

    r241 r258  
    123123;       DS:     RAMVARS segment
    124124;   Returns:
    125 ;       CF:     Set if function is handled by this BIOS
    126 ;               Cleared if function belongs to some other BIOS
     125;       CF:     Cleared if function is handled by this BIOS
     126;               Set if function belongs to some other BIOS
    127127;   Corrupts registers:
    128128;       Nothing
     
    131131RamVars_IsFunctionHandledByThisBIOS:
    132132    test    ah, ah          ; Reset for all floppy and hard disk drives?
    133     jz      SHORT .FunctionIsHandledByOurBIOS
    134     cmp     ah, 08h         ; Read Disk Drive Parameters?
    135     jne     SHORT RamVars_IsDriveHandledByThisBIOS
    136     test    dl, dl          ; We do not handle floppy drives
    137     jns     SHORT .FunctionIsNotHandledByOurBIOS
    138 ALIGN JUMP_ALIGN
    139 .FunctionIsHandledByOurBIOS:
    140     stc
    141 .FunctionIsNotHandledByOurBIOS:
    142     ret
    143 
     133    jz      SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS
     134    cmp     ah, 08h
     135%ifdef MODULE_SERIAL_FLOPPY
     136; we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts
     137    je      SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS
     138%else
     139; we handle all *hard disk* traffic for function 08h, as we need to wrap the hard disk drive count
     140    je      SHORT RamVars_IsDriveHandledByThisBIOS.IsDriveAHardDisk
     141%endif
     142;;; fall-through           
     143       
    144144;--------------------------------------------------------------------
    145145; Checks if drive is handled by this BIOS.
     
    150150;       DS:     RAMVARS segment
    151151;   Returns:
    152 ;       CF:     Set if drive is handled by this BIOS
    153 ;               Cleared if drive belongs to some other BIOS
     152;       CF:     Cleared if drive is handled by this BIOS
     153;               Set if drive belongs to some other BIOS
    154154;   Corrupts registers:
    155155;       Nothing
     
    158158RamVars_IsDriveHandledByThisBIOS:
    159159    push    ax
    160     mov     ax, [RAMVARS.wDrvCntAndFirst]       ; Drive count to AL, First number to AH
    161     add     al, ah                              ; One past last drive to AL
    162     cmp     dl, al                              ; Above last supported?
    163     jae     SHORT .DriveNotHandledByThisBIOS
    164     cmp     ah, dl                              ; Below first supported?
    165     ja      SHORT .DriveNotHandledByThisBIOS
    166     stc
    167 .DriveNotHandledByThisBIOS:
     160
     161    mov     ax, [RAMVARS.wDrvCntAndFirst]       ; Drive count to AH, First number to AL
     162    add     ah, al                              ; One past last drive to AH
     163    cmp     dl, ah                              ; Above last supported?
     164    jae     SHORT .HardDiskIsNotHandledByThisBIOS
     165.TestLowLimit:
     166    cmp     dl, al                              ; Below first supported?
     167    jae     SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX  ; note that CF is clear if the branch is taken
     168
     169.HardDiskIsNotHandledByThisBIOS:
     170%ifdef MODULE_SERIAL_FLOPPY
     171    call    RamVars_UnpackFlopCntAndFirstToAL
     172    cbw                                         ; normally 0h, could be ffh if no drives present
     173    adc     ah, al                              ; if no drives present, still ffh (ffh + ffh + 1 = ffh)
     174    js      SHORT .DiskIsNotHandledByThisBIOS
     175    cmp     ah, dl
     176    jz      SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX
     177    cmp     al, dl
     178    jz      SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX
     179.DiskIsNotHandledByThisBIOS:           
     180%endif
     181
     182    stc                                         ; Is not supported by our BIOS
     183       
     184.CFAlreadyClear_IsHandledByOurBIOS_PopAX:               
    168185    pop     ax
    169     ret
    170 
    171 
    172 ;--------------------------------------------------------------------
    173 ; RamVars_GetHardDiskCountFromBDAtoCX
    174 ;   Parameters:
    175 ;       DS:     RAMVARS segment
    176 ;   Returns:
    177 ;       CX:     Total hard disk count
    178 ;   Corrupts registers:
    179 ;       Nothing
    180 ;--------------------------------------------------------------------
    181 ALIGN JUMP_ALIGN
    182 RamVars_GetHardDiskCountFromBDAtoCX:
     186.CFAlreadyClear_IsHandledByOurBIOS:
     187    ret
     188
     189%ifndef MODULE_SERIAL_FLOPPY       
     190;
     191; Note that we could have just checked for the high order bit in dl, but with the needed STC and jumps,
     192; leveraging the code above resulted in space savings.
     193;
     194.IsDriveAHardDisk:     
     195    push    ax                                  ; match stack at the top of routine
     196    mov     al, 80h                             ; to catch all hard disks, lower limit is 80h vs. bFirstDrv
     197    jmp     .TestLowLimit                       ; and there is no need to test a high limit
     198%endif
     199
     200;--------------------------------------------------------------------
     201; RamVars_GetHardDiskCountFromBDAtoAX
     202;   Parameters:
     203;       DS:     RAMVARS segment
     204;   Returns:
     205;       AX:     Total hard disk count
     206;   Corrupts registers:
     207;       CX
     208;--------------------------------------------------------------------
     209ALIGN JUMP_ALIGN
     210RamVars_GetHardDiskCountFromBDAtoAX:
    183211    push    es
    184     push    dx
    185 
    186     LOAD_BDA_SEGMENT_TO es, cx, !       ; Zero CX
    187     call    RamVars_GetCountOfKnownDrivesToDL
     212
     213    LOAD_BDA_SEGMENT_TO es, ax
     214    call    RamVars_GetCountOfKnownDrivesToAX
    188215    mov     cl, [es:BDA.bHDCount]
    189     MAX_U   cl, dl
    190 
    191     pop     dx
     216    MAX_U   al, cl
     217       
    192218    pop     es
    193219    ret
    194220
    195221;--------------------------------------------------------------------
    196 ; RamVars_GetCountOfKnownDrivesToDL
    197 ;   Parameters:
    198 ;       DS:     RAMVARS segment
    199 ;   Returns:
    200 ;       DL:     Total hard disk count
    201 ;   Corrupts registers:
    202 ;       Nothing
    203 ;--------------------------------------------------------------------
    204 ALIGN JUMP_ALIGN
    205 RamVars_GetCountOfKnownDrivesToDL:
    206     mov     dl, [RAMVARS.bFirstDrv]     ; Number for our first drive
    207     add     dl, [RAMVARS.bDrvCnt]       ; Our drives
    208     and     dl, 7Fh                     ; Clear HD bit for drive count
    209     ret
    210 
    211 
     222; RamVars_GetCountOfKnownDrivesToAX
     223;   Parameters:
     224;       DS:     RAMVARS segment
     225;   Returns:
     226;       AX:     Total hard disk count
     227;   Corrupts registers:
     228;       None
     229;--------------------------------------------------------------------
     230ALIGN JUMP_ALIGN
     231RamVars_GetCountOfKnownDrivesToAX:
     232    mov     ax, [RAMVARS.wDrvCntAndFirst]
     233    add     al, ah
     234    and     al, 7fh
     235    cbw
     236    ret
     237   
    212238;--------------------------------------------------------------------
    213239; RamVars_GetIdeControllerCountToCX
     
    219245;       Nothing
    220246;--------------------------------------------------------------------
     247ALIGN JUMP_ALIGN
    221248RamVars_GetIdeControllerCountToCX:
    222249    eMOVZX  cx, BYTE [cs:ROMVARS.bIdeCnt]
    223250    ret
     251
     252%ifdef MODULE_SERIAL_FLOPPY
     253;--------------------------------------------------------------------
     254; RamVars_UnpackFlopCntAndFirstToAL
     255;   Parameters:
     256;       Nothing
     257;   Returns:
     258;       AL:     First floppy drive number supported
     259;       CF:     Number of floppy drives supported (clear = 1, set = 2)
     260;   Corrupts registers:
     261;       Nothing
     262;--------------------------------------------------------------------       
     263ALIGN JUMP_ALIGN
     264RamVars_UnpackFlopCntAndFirstToAL:
     265    mov     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst]
     266    sar     al, 1       
     267    ret
     268%endif
  • trunk/XTIDE_Universal_BIOS/makefile

    r252 r258  
    6666# Assembler preprocessor defines.                               #
    6767#################################################################
    68 DEFINES = INCLUDE_MENU_LIBRARY EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS MODULE_EBIOS MODULE_SERIAL MODULE_STRINGS_COMPRESSED
     68DEFINES = INCLUDE_MENU_LIBRARY EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS MODULE_EBIOS MODULE_SERIAL MODULE_STRINGS_COMPRESSED MODULE_SERIAL_FLOPPY
    6969DEFINES_XT = ELIMINATE_CGA_SNOW
    7070DEFINES_XTPLUS = ELIMINATE_CGA_SNOW USE_186
  • trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/ConfigurationMenu.asm

    r206 r258  
    276276    CALL_MENU_LIBRARY RefreshItemFromAX
    277277    pop     es
    278     ret
     278    ; Fall to ConfigurationMenu_CheckAndMoveSerialDrivesToBottom
     279
     280;----------------------------------------------------------------------
     281; ConfigurationMenu_CheckAndMoveSerialDrivesToBottom
     282;
     283; Checks to ensure that serial adapters are at the end of the
     284; IDEVARS structures list, as serial floppies (if present) need to be
     285; the last drives detected by the BIOS.  If there are other controllers
     286; after a serial controller, the other controllers are moved up on the list
     287; and the serial controller is placed at the end of the list.
     288;
     289;   Parameters:
     290;       SS:BP:  Menu handle
     291;   Returns:
     292;       Nothing
     293;   Corrupts registers:
     294;       All
     295;----------------------------------------------------------------------     
     296ConfigurationMenu_CheckAndMoveSerialDrivesToBottom:     
     297    push    es
     298    push    ds
     299    push    di
     300    push    si
     301
     302    call    Buffers_GetIdeControllerCountToCX   ; will also set ES:DI to point to file buffer
     303    push    es
     304    pop     ds
     305    mov     ch, 0                       ; clearing high order of CX and notification flag
     306    mov     dx, cx                      ; (probably unncessary, CX should be less than 127, but just to be sure)
     307    jcxz    .done                       ; probably unnecessary, but make sure there is at least one controller     
     308
     309    add     di, ROMVARS.ideVars0        ; add in offset of first idevars
     310    mov     bx, di
     311
     312.outerLoop:
     313    mov     di, bx                      ; start of idevars
     314    xor     si, si                      ; first serial found
     315    xor     ax, ax                      ; first non-serial found
     316    mov     cl, dl                      ; idevars count
     317    mov     ch, 0
     318
     319.loop:
     320    cmp     byte [di+IDEVARS.bDevice], DEVICE_SERIAL_PORT
     321    jnz     .notSerial
     322
     323    test    si, si                      ; record the first serial controllert that we find
     324    jnz     .next   
     325    mov     si, di
     326    jmp     .next
     327
     328.notSerial:
     329    mov     ax, di                      ; record the *last* non-serial controller that we find
     330
     331.next: 
     332    add     di, IDEVARS_size
     333    loop    .loop
     334
     335    test    si,si                       ; no serial drives, nothing to do
     336    jz      .done
     337    cmp     si,ax                       ; serial port is already later on the list than any other controllers
     338    ja      .done                       ; (also takes care of the case where ther are no other controllers)
     339
     340;
     341; move serial to end of list, others up
     342;
     343    cld
     344
     345    mov     ax, di                      ; save end pointer of list after scan
     346
     347    sub     sp, IDEVARS_size            ; copy serial to temporary space on stack
     348
     349    mov     di, sp
     350
     351    mov     cx, IDEVARS_size
     352    push    ss
     353    pop     es
     354
     355    rep movsb
     356
     357    mov     di, si                      ; move up all the idevars below the serial, by one slot
     358    sub     di, IDEVARS_size
     359
     360    mov     cx, ax                      ; restore end pointer of list, subtract off end of serial idevars
     361    sub     cx, si
     362
     363    push    ds
     364    pop     es
     365
     366    rep movsb
     367
     368    mov     si, sp                      ; place serial (currently on the stack) at bottom of list
     369    push    ss
     370    pop     ds
     371    mov     cx, IDEVARS_size
     372    ; di is already at last IDEVARS position
     373   
     374    rep movsb
     375
     376    add     sp, IDEVARS_size           
     377
     378    push    es
     379    pop     ds
     380
     381    mov     dh, 1                       ; set flag that we have done a relocation
     382   
     383    jmp     .outerLoop
     384
     385.done:
     386    pop     si
     387    pop     di
     388    pop     ds
     389    pop     es
     390
     391    test    dh, dh
     392    jz      .noWorkDone
     393       
     394    mov     dx, g_szSerialMoved
     395    call    Dialogs_DisplayNotificationFromCSDX
     396
     397.noWorkDone:       
     398    ret
  • trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm

    r242 r258  
    9797g_szNfoCfgIdeCnt:       db  "Number of IDE controllers to manage.",NULL
    9898
     99g_szSerialMoved:        db  "A Serial Controller has been moved to the end of the Controller list. No further action is required. Serial Controllers must be placed at the end of the list.",NULL
     100
    99101g_szHelpCfgFullMode:    incbin  "Configuration_FullMode.txt"
    100102                        db  NULL
    101103g_szHelpCfgStealSize:   incbin  "Configuration_StealSize.txt"
    102104                        db  NULL
    103 
    104105
    105106; Strings for IDE Controller menu
Note: See TracChangeset for help on using the changeset viewer.