Changeset 258 in xtideuniversalbios for trunk/Serial_Server/library/Image.cpp


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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.