reading floppy disk sector

This is a discussion on reading floppy disk sector within the C++ Programming forums, part of the General Programming Boards category; Hello! I've trying to read and write sectors using the Win32 API. However, I am having some difficulties on finding ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    2

    reading floppy disk sector

    Hello!

    I've trying to read and write sectors using the Win32 API. However, I am having some difficulties on finding out the sector number in a floppy disk.

    For example, I created an assembly program wherein I write a 512 bytes on Track 1, Sector Number 1 and Head Number 1. When I use the Windows.h function, I can't seem to locate that 512 byte file.

    From what I understand, windows uses flat adressing. So the sectors numbers are actually from 0 to 2879. I've created an equation that calculates the sector given the track number, head number and the sector number. However, I can't seem to make it work.

    My prototype equation goes as:
    iSector = (HeadNum * SECTORS_PER_TRACK * TRACKS_PER_SIDE ) + (TrackNum * SECTORS_PER_TRACK+ aSectorNum) -1;

    SECTORS_PER_TRACK = 18
    TRACKS_PER_SIDE = 80
    NUMBER OF SIDES for a floppy diskkete = 2

    Hope somebody can give me an idea about the windows flat addressing. Maybe that's where my problem lies.

    Thanks.

  2. #2
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    why on EARTH would you be using assembly to write to a floppy.

    technology HAS progressed, after all.
    Hmm

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    2
    Actually, I'm using assembly create the small com files that I place in the floppy sectors. From there, I will use my C++ code to see if the sector I am reading is correct.

    The reason why I do not use windows to also write in floppy is because I need to know how to compute the sector number given the head, cylinder and sector number.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    >> why on EARTH would you be using assembly to write to a floppy
    Fun is a good enough reason for me

    Code:
    #include <iostream> 
    using namespace std; 
    
    #define NUM_SIDES         2
    #define TRACKS_PER_SIDE   80
    #define SECTORS_PER_TRACK 18
    #define SECTORS_PER_SIDE  (TRACKS_PER_SIDE * SECTORS_PER_TRACK)
    
    size_t LogicalFloppySector(size_t side, size_t track, size_t track_sec)
    {
        // do some range checking on params here
    
        // params are 1 based values - calculations need 0 based values
        side--;
        track--;
        track_sec--;
    
        return (side * SECTORS_PER_SIDE) +   // get to right side
               (track * SECTORS_PER_TRACK) + // get to right track
               track_sec;                    // get to right sector on track
    }//LogicalFloppySector
    
    int main() 
    {
        size_t side, track, track_sec;
        for (side = 1; side <= NUM_SIDES; side++)
            for (track = 1; track <= TRACKS_PER_SIDE; track++)
                for (track_sec = 1; track_sec <= SECTORS_PER_TRACK; track_sec++)
                    cout << LogicalFloppySector(side, track, track_sec) << ", ";
    
        return 0; 
    }//main
    Output: 0, 1, ... , 2879

    Google("reading floppy disk sector win32")
    Reading/Writing Disk Sectors (Absolute Disk Read/Write)

    gg
    Last edited by Codeplug; 12-02-2004 at 10:37 PM.

  5. #5
    Registered User cfrost's Avatar
    Join Date
    Apr 2004
    Posts
    119
    you can download a prebuilt class for this form
    here ...
    Software is like sex it is good when it is free

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get floppy disk information ?!!
    By Masterx in forum C Programming
    Replies: 51
    Last Post: 11-28-2007, 12:33 PM
  2. read write from hard disk
    By bojan in forum C Programming
    Replies: 3
    Last Post: 05-17-2006, 01:15 AM
  3. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 06:25 AM
  4. Floppy Disk
    By Sentral in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2005, 09:00 PM
  5. formatting a floppy in C
    By McMullet in forum C Programming
    Replies: 2
    Last Post: 10-10-2004, 05:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21