floppy disk programming

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ncsu121978

floppy disk programming

Post by ncsu121978 »

does anyone have some code (very simple) that i can look at for programming the floppy disk ? Something as simple as calling floppy_init();
and like floppy_write_sector(sector_num, char* buf);
floppy_read_sector(sector_num, char* buf);

some simple functions like that ?
Paul

Re:floppy disk programming

Post by Paul »

You can find a sample floppy driver here:

http://www.execpc.com/~geezer/os/fdc.zip

But I must tell you... It isn't as simple as just calling an INIT function and then calling a READ SECTOR or WRITE SECTOR function. You will need to integrate this code with your operating system. More specifically, it will rely on your timer interrupt to turn the floppy motor off after a certain amount of time. Also, you will need to create a handler for IRQ 6 (the floppy interrupt.) All this interrupt is going to have to do is set a flag so that the driver knows an operation has been completed. (Sounds kind of stupid, doesn't it? Why make it interrupt driven if you are going to poll anyway for the interrupt to flag that the operation is complete!! But, you must do it that way. I don't know of a way to poll to see if a floppy operation is complete -- and, obviously, neither did the author of this program.)

Once you have set those couple of things up, THEN all you have to do is calling a readsector() function or writesector() function, passing them a block number and buffer. :)

Paul
ncsu121978

Re:floppy disk programming

Post by ncsu121978 »

i cant really get that code into my system Paul because it is making some dos sytem calls it looks like.
like this bit of code he uses

Code: Select all

/* 
 * this allocates a buffer in the < 1M range, maps it and returns the linear
 * address, also setting the physical in the integer pointed at
 */
long alloc_dma_buffer(int size)
{
   _go32_dpmi_seginfo seginfo;
   long begin,end;

   /* loop until allocated mem does not cross a 64K boundary */
   do {
      seginfo.size = (size + 15) / 16;  /* translate to paragraphs */
      assert(_go32_dpmi_allocate_dos_memory(&seginfo) == 0);
      begin = seginfo.rm_segment << 4;
      end = begin + seginfo.size;
   } while((end & 0xffff) < (begin & 0xffff));
   
   return begin;
}
he uses stuff like that in other areas as well
Tim

Re:floppy disk programming

Post by Tim »

So you need to understand what those DOS calls achieve and replace them with calls to your own kernel. All this function is doing is allocating memory below 1MB and making sure that the block allocated doesn't span a 64KB boundary.
Post Reply