Changeset 258 in xtideuniversalbios for trunk/Serial_Server


Ignore:
Timestamp:
Feb 22, 2012, 7:01:53 PM (12 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/Serial_Server
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.