Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

simple dos c program

2 views
Skip to first unread message

deus the programmer

unread,
Dec 19, 2009, 6:45:11 PM12/19/09
to
hello i am trying to write a simple dos c program to display a list of
files on a floppy disk but would not like to use dos system calls just
rom bios system calls. the code will need to decypher the fat file
system and display names of files on the disk. if you are able to help
please do.
thanks deustheprogrammer

Chris Giese

unread,
Dec 19, 2009, 7:53:14 PM12/19/09
to


#include <stdio.h>
#include <bios.h>
#define read_le16(X) *(unsigned short *)(X)
static unsigned g_drive_num = 0, g_heads = 1, g_sectors = 1;
static int read_sector(void *buf, unsigned lba) {
unsigned sector, head;

sector = (lba % g_sectors) + 1;
lba /= g_sectors;
head = lba % g_heads;
lba /= g_heads;
return biosdisk(/*_DISK_READ=*/2, g_drive_num, head,
/*cylinder=*/lba, sector, /* num_sects=*/1, buf); }

int main(void) {
unsigned first_root_sector, num_root_sectors, s;
unsigned char buf[512], *e;

/* should test for error here; and validate boot sector */
(void)read_sector(buf, 0);
g_heads = read_le16(&buf[26]); /* number of heads */
g_sectors = read_le16(&buf[24]); /* sectors per track */
first_root_sector =
read_le16(&buf[14]) + /* start of FAT(s) */
buf[16] * /* number of FATs */
read_le16(&buf[22]); /* sectors per FAT */
num_root_sectors = read_le16(&buf[17]) *
32 / /* bytes per directory entry */
512; /* bytes per sector */
for(s = 0; s < num_root_sectors; s++) {
(void)read_sector(buf, first_root_sector + s);
for(e = &buf[0]; e < &buf[512]; e += 32) {
if(e[0] == '\0' /* unused directory entry */
|| e[0] == 0xE5 /* deleted entry */
|| (e[11] & 0x08)) /* volume label or LFN */
continue;
printf("%-11.11s ", e); }}
printf("\n");
return 0; }

0 new messages