exact copy floppy disk

C 16Bit (MS-DOS) No Comments »
#include<dos.h>
#include<stat.h>
#include<conio.h>
#include<stdio.h>
#include<fcntl.h>
#include<io.h>
void main()
{
	int in,bytes,i,n;
	char buf[512];
	clrscr();
	in=open("sect.dat",O_CREAT|O_BINARY|O_WRONLY);
	gotoxy(25,2);
	printf("Sector reader\n");
 
	for(i=1;i<=2847-1;i++)
	{
		absread(0,1,i,&buf);
 
		write(in,buf,512);
		gotoxy(15,5);
		printf("%d sectors readed",i);
	}
	close(in);
	gotoxy(15,7);
	printf("\nEnter target disk");
	wait;
	in=open("sect.dat",O_BINARY|O_RDONLY);
 
	for(i=1;i<=1439;i++)
	{
	  read(in,buf,512);
	  n=abswrite(0,1,i,&buf);
		if(n!=0)
		{
		   gotoxy(15,10);
		   printf("%3d th sector  skipped");
		}
 
	  gotoxy(15,12);
	  printf("sectors written = %3d",i);
	}
	close(in);
 
}

clear keyboard buffer – flush STDIN

C 16Bit (MS-DOS) No Comments »

I use inportb macro for keyboard port 60h to get keystrokes from the keyboard buffer directly using a loop.
for example in a loop executes and in that block i will use this function to get the scan codes of keystrokes and use it… like the following

	unsigned char key;
 
	while(1)
	{
		if((key = inportb(0x60))==1)break; // if esc is pressed
		printf("\n%d",key);
	}

i hope people know why %d is used for a char datatype. But behind this there is a contradiction among many young programmers…

here, your screen will be flooded with scan codes whether or not press any key… that’s the use of inportb…
you press a key and you can see the scan code. if you want the ascii code then you have to issue an interrupt to get both scan codes and ascii code as integer in which the first 8bits and other 8bits will give you the ascii and scan codes…

and the problem is when you press a key and before you release you are sending more than the limit of keystrokes to the the keyboard buffer and to notify this the beep sound beeps… and these extra keystrokes will appear for your next input which is not needed… it is like if you press ‘k’ and then you do some process and then your code again waits for the key strokes now you will get the remaining k’s from the keyboard buffer if it is not flushed…

so here comes the following code which will clear the keyboard buffer for every time it executes…

#include<stdio.h>
#include<dos.h>
 
void main()
{
	int i;
 
	while(1)
	{
		if(inportb(0x60)==2)break;
		printf("\n%d",inportb(0x60));
 
		_AH=0xc;
		_AL=0x2;
		asm int 21h
	}
}

whether or not a key is pressed the buffer is cleared… so from the next stroke i could assume that only one entry will be present in the keyboard buffer before it is read…

and hope people are good in registers of the processor and interrupts to understand the above code which has an inline assembly language code.

21h is for keyboard and other two are sub functions to clear buffer. maybe i should sit a little more to elaborate. déjame ver if i could… .

double click event in ms-dos

C 16Bit (MS-DOS) No Comments »

This program displays the click event of the mouse in ms dos environment using Turbo C. If you double click on the screen then you will get the message that you have double clicked else none. I wrote this function to use it in the 640×480 16 color graphics mode for a simple my computer program to which detects single click and double click on a file.

If people know about interrupts, ports, scan codes and button states then it might be useful for them if they are trying to under stand the concept of low level input and output. Using this may help them understand the windows env better…

and one more important point is i have used inline asm codes so … be ware…
here i would like to say one thing and that is about the inportb macro… using this i mimicked a multiprocessing program… which displays the time and at the same time it can detect the mouse and keyboard like in windows… i can never forget this word because i have used it very extensively.

anyway here is the code…

Interrupt 33 deals with the mouse and sub function 0 and 1 are for initialize mouse and show mouse pointer respectively… one interesting function i have made among the others… yeeeehaaawww…

#include<time.h>
#include<stdio.h>
#include<dos.h>
 
	char butt;
	clock_t start;
 
void main()
{
	void mouse();
	void click();
 
	start=clock();
 
	_AX=0;asm int 33h;
	_AX=1;asm int 33h;
 
	while(inportb(0x60)!=1)
	{
		mouse();
	    if(butt)
	    {
		click();
		while(butt)mouse();
	    }
	}
 
}
 
void click()
{
	float as;
	as=(float) start-clock();
 
	gotoxy(50,2);
 
	if(as>-6.&&as<0.)
		printf("double click");
	else
		printf("            ");
	start=clock();
}
 
void mouse()
{
	_AX=3;asm int 33h;
	butt=_BX;
}

read boot sector of floppy

C 16Bit (MS-DOS) No Comments »

This program is no longer used cause no body uses a floppy… i have to update it to a 32bit program from 16bit… and manipulating a USB will be nice instead of a floppy.

This program displays the boot sector of a floppy drive. The biosdisk function can be used to manipulate a FAT32 hard drive even now. Manipulating a FAT16 and FAT12 are straight forward using absolute disk read and absolute disk write functions provided in Borland’s Turbo C IDE.

I am trying to write a program which will help me play with FAT32 in windows… using WIN32 API…

anyway here is one silly program for the strong hearts…

#include<stdio.h>
#include<conio.h>
#include<bios.h>
 
	struct
	{
		char jump[3];
		char si[8];//system id
		int bps;// no of bytes per sector
		char spc;// no of sectors per cluster
		int res;// no of reserved area
		char cof;// no of copies of fat
		int rde;//no of root directory entries
		int tos;// total no of sectors
		char md;// media discriptor
		int spf;// no of sectors per fat
		int spt;// no of sectors per track
		int sides;// no of sides
		int hs;// no of hidden sectors
		char rest[482];
 
	}zero;
 
	void display_bootsector();
 
void main()
{
	biosdisk(2,0x81,0,0,1,1,&zero);
	display_bootsector();
 
}
 
void display_bootsector()
{
	zero.jump[3]=0;
	printf("\nJump Instruction\t\t%s",zero.jump);
	zero.si[8]=0;
	printf("\nSystem Id\t\t%s",zero.si);
	printf("\nBytes per sector\t%d",zero.bps);
	printf("\nSectors per cluster\t%d",zero.spc);
	printf("\nReserved\t\t%d",zero.res);
	printf("\nCopies of fat\t\t%d",zero.cof);
	printf("\nRoot directory entries\t%d",zero.rde);
	printf("\nTotal no of sectors\t%d",zero.tos);
	printf("\nMedia discriptor\t%0x",zero.md);
	printf("\nSectors per fat\t\t%d",zero.spf);
	printf("\nSectors per track\t%d",zero.spt);
	printf("\nNo of sides\t\t%d",zero.sides);
	printf("\nNo of hidden sectors\t%d",zero.hs);
	printf("\n");
}
Entries RSS