Vous êtes sur la page 1sur 14

1) Boot sector parameters of a floppy disk #include<stdio.h> #include<dos.

h> struct mbrrecord { int jumpinstruction; int nop; char oem[8]; int bytespersector; int sectorpercluster; int numfat; int rootdirectory; int numsector; int mediatype ; int numheads; int sectorpertrack; long nonhiddensector; long numsectorhuge; char driveno; char reserve; char signature; long volumeid; long volumelabel[11]; char filesystype[8]; char rec[449]; }mbr; main() { int i; clrscr(); printf("\n ENTER THE DISK AND PRESS ANY KEY : "); getch(); if(absread(0,1,0,&mbr)!=0) { printf("\n ERROR......."); getch(); exit(0); } printf("\n jumpinstruction : %d",mbr.jumpinstruction); printf("\n nop : %d",mbr.nop); printf("\n oem : %s",mbr.oem); printf("\n bytespersector : %d ",mbr.bytespersector); printf("\n sectorpercluster: %d ",mbr.sectorpercluster); printf("\n no of FAT: %d ",mbr.numfat); printf("\n rootdirectory : %d",mbr.rootdirectory); printf("\n numsector : %d",mbr.numsector); printf("\n media type : %d",mbr.mediatype); printf("\n numheads : %d",mbr.numheads); printf("\n sectors per track : %d",mbr.sectorpertrack); printf("\n non hiddensectors : %lu",mbr.nonhiddensector); printf("\n numsectorhuge : %lu",mbr.numsectorhuge); printf("\n drivenumber : %c",mbr.driveno); printf("\n reserve : %c",mbr.reserve); printf("\n signature : %c ",mbr.signature); printf("\n volumeid : %lu",mbr.volumeid); printf("\n volumelabel :"); for(i=0;i<11;i++) printf("%lu",mbr.volumelabel[i]); return 0; }

2) Partition table parameters #include<stdio.h> #include<bios.h> #include<conio.h> #include<dos.h> #define HI(x)(x&0xf0)>>8 #define LO(x)(x&0x0f) struct partitiontableentry { char partitionstate; char starthead; int startcylindersector; char partitiontype; char endhead; int endcylindersector; long lba; long sectorcount; }; struct partitiontable { char pgm[446]; struct partitiontableentry partition[4]; short sign; }; void main() { struct partitiontable part; int sector,cylinder,i; clrscr(); biosdisk(2,0x00,0,0,1,1,&part); for(i=0;i<4;i++) { printf("\n\n DETAILS OF PARTION TABLE ENTRY : %d",i);

printf("\n ACTIVE PARTITION : %x",part.partition[i].partitionstate); sector=part.partition[i].startcylindersector&0x3f; cylinder=HI(part.partition[i].startcylindersector)|(LO(part.partition[i].startcylindersector)&0x0f<<2); printf("\n START SECTOR : %d",sector); printf("\n START CYLINDER: %d",cylinder); printf("\n PARTITION TYPE : %x ",part.partition[i].partitiontype); sector=part.partition[i].endcylindersector&0x3f; cylinder=(HI(part.partition[i].endcylindersector)&0x0f<<2); printf("\n ENDSECTOR: %d",sector); printf("\n ENDCYLINDER: %d",cylinder); printf("\n NUMBER OF SECTORS BETWEEN MBR AND FIRST SECTOR %d",part.partition[i].lba); printf("\n NUMBER OF SECTORS IN PARTITION:%d",part.partition[i].sectorcount); } printf("\n\n BOOT SIGNATURE :%x",part.sign); getch(); }

OF

PARTITION

3) Read from and write to a floppy disk #include<stdio.h> #include<bios.h> #include<conio.h> int main() { int count,ans,choice;

char ch; int len; unsigned char buffer[512],write[10]; clrscr(); do { printf("\n ENTER THE CHOICE \n 1.READ \n 2.WRITE \n"); scanf("%d",&choice); switch(choice) { case 1: { ans=biosdisk(2,0,0,0,3,1,buffer); printf("\n RETURN :%x",ans); printf("\n"); for(count=0;count<=len;count++) {printf("%c",buffer[count]); } printf("\n FINISHED READING \n"); break; } case 2: { printf("\n ENTER THE STRING : "); scanf("%s",buffer); len=strlen(buffer); ans=biosdisk(3,0,0,0,3,1,buffer); printf("\n WRITING OVER"); break; } default : { printf("\n INVALID"); break; } } printf("\n DO YOU WANT TO CONTINUE Y/N : "); scanf("%c",&ch); scanf("%c",&ch); }while(ch=='y'||ch=='Y'); getch(); return ans; }

4) Key Toggling #include<conio.h> #include<stdio.h> #include<string.h> void main() { char *text,c; int val; char ch; char check[10]; char far* ptr; clrscr(); ptr=(char far*)0x417; do { printf("Key toggle\n"); printf("\n 1.Caps Lock\n 2. Num lock\n 3. Scroll \n 4.Exit \nEnter a choice:"); scanf("%d",&val);

switch(val) { case 1: if((*ptr)&0x40) { printf("Caps lock is on \n Changing Caps lock to off\n"); } else {printf("Caps lock is off \n Setting caps lock to on\n"); printf("Enter any string "); gets(check); gets(check); } _fmemset(ptr,(*ptr)^0x40,2); printf("Enter any string "); gets(check); gets(check); break; case 2: if((*ptr)&0x20) { printf("\n Num lock is on \n Changing Num lock to Off"); } else { printf("Num Lock is off \n Setting Num Lock to On\n"); } _fmemset(ptr,(*ptr)^0x20,2); break; case 3: if((*ptr)&0x10) { printf("\n Scroll lock is on \n Changing Scroll lock to Off\n"); } else { printf("Scroll Lock is off \n Setting Scroll Lock to On\n"); } _fmemset(ptr,(*ptr)^0x10,2); break; case 4:exit(0);break; } printf("\nDo you want to continue?? y/n "); scanf("%c",&ch); scanf("%c",&ch); }while(ch=='y'||ch=='Y'); getch(); }

5) Scan code and ASCII code #include<stdio.h> #include<conio.h> #include<dos.h> void main() { int scan,ascii; char ch; union REGS in,out; clrscr(); printf("\n ENTER ANY KEY : "); int86(0x16,&in,&out); ascii=out.h.al;

scan=out.h.ah; printf("\n ENTERED CHARACTER IS : %c",ascii); printf("\n\n SCAN CODE: %d,ASCII CODE :%d",scan,ascii); getch(); }

6) Get and set file attributes #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> #include<dos.h> void main() { union REGS inregs,outregs; int ch,value,choice; char * fname =malloc(sizeof(char)*50); clrscr(); printf("Enter the path of a file"); scanf("%s",fname); inregs.x.dx =(unsigned int) fname; inregs.h.ah= 0x43; do { printf("\n\n\nMENU:"); printf("\n1.Get attributes of file"); printf("\n2.Set attributes of file"); printf("\n3.Quit"); printf("\nEnter your choice(1/2):"); scanf("%d",&ch); printf("\n"); switch(ch) { case 1: { inregs.h.al= 0x00; int86(0x21,&inregs,&outregs); printf("\nThe attributes of file %s",fname); if(!(outregs.x.cx & 0x01)) printf("\nFile is not read only"); else printf("\nFile is read only"); if(!(outregs.x.cx& 0x02)) printf("\nNot hidden"); else printf("\nHidden"); if(!(outregs.x.cx & 0x20)) printf("\n Not archived"); else printf("\nFile is archived"); break; } case 2:{ inregs.h.al=0x01; printf("\nEnter choice 1.Read only 2.Hidden 3.Archive"); scanf("%d",&choice); if(choice==1) {printf("%x",inregs.x.cx); inregs.x.cx=inregs.x.cx^0x01; } else if(choice==2) inregs.x.cx=inregs.x.cx^0x02;

else if(choice==3) inregs.x.cx=inregs.x.cx^0x20; else {printf("\nInvalid choice!"); exit(0); } int86(0x21,&inregs,&outregs); printf("Attributes have been changed!"); break; } } }while(ch!=3); getch(); }

7) Create, rename and delete files #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<dos.h> void main() { union REGS inregs,outregs; int ch; char *file1,*file2; clrscr(); do { printf("\n\t MENU \n 1.CREATE A FILE \n 2.RENAME A FILE \n 3.DELETE A FILE\n 4.EXIT\n ENTER YOUR CHOICE "); scanf("%d",&ch); switch(ch) { case 1: { printf("\n ENTER THE PATH OF THE FILE TO BE CREATED"); scanf("%s",file1); inregs.x.dx=(unsigned int)file1; inregs.h.ah=0x5b; inregs.x.cx=0x00; int86(0x21,&inregs,&outregs); printf("\n THE FILE NAMED %s has been created \n",file1); break; } case 2: { printf("\n ENTER THE PATH OF TH FILE TO BE RENAMED"); scanf("%s",file1); printf("ENTER NEW PATH FOR THE FILE %s : ",file1); scanf("%s",file2); inregs.x.dx=(unsigned int)file1; inregs.x.di=(unsigned int)file2; inregs.h.ah=0x56; int86(0x21,&inregs,&outregs); printf("\nTHE NAME OF THE FILE HAS BEEN CHANGED to %s \n",file2); break; } case 3: { printf("\n ENTER THE PATH OF THE FILE TO BE DELETED"); scanf("%s",file1);

inregs.x.dx=(unsigned int)file1; inregs.h.ah=0x41; int86(0x21,&inregs,&outregs); printf("\n THE FILE NAMED %s HAS BEEN DELETED \n\n",file1); break; } case 4: { printf("\nEXITING"); break; } default: { printf("\n WRONG CHOICE"); break; } } }while(ch!=4); fclose(file1); fclose(file2); getch(); }

8) Create, rename and delete subdirectory #include<stdio.h> #include<conio.h> #include<dos.h> #include<stdlib.h> void main() { union REGS inregs,outregs; int ch; char *sub1,*sub2; clrscr(); do { printf("\t\n MENU\n 1.CREATE \n 2.RENAME \n3.DELETE \n4.EXIT \nENTER YOUR CHOICE"); scanf("%d",&ch); switch(ch) { case 1: { printf("\nENTER THE PATH OF THE SUBDIRECTORY TO BE CREATED"); scanf("%s",sub1); inregs.x.dx=(unsigned int)sub1; inregs.h.ah=0x39; inregs.x.cx=0x00; int86(0x21,&inregs,&outregs); printf("\nTHE SUBDIRECTORY NAMED %s HAS BEN CREATED",sub1); break; } case 2: { printf("\nENTER THE PATH OF THE SUBDIRECTORY TO BE RENAMED :"); scanf("%s",sub1); printf("\nENTER NEW PATH OF SUBDIRECTORY %s",sub1); scanf("%s",sub2); inregs.x.dx=(unsigned int)sub1; inregs.x.di=(unsigned int)sub2; inregs.h.ah=0x56;

int86(0x21,&inregs,&outregs); if(outregs.x.cflag==0x0000) printf("\n THE NAME OF THE SUBDIRECTORY HAS BEEN CHANGED TO %s",sub2); else printf("\n error"); break; } case 3: { printf("\n Enter the path of the subdirectory to be deleted "); scanf("%s",sub1); inregs.x.dx=(unsigned int)sub1; inregs.h.ah=0x3a; int86(0x21,&inregs,&outregs); printf("\n the subdirectory named %s has been deleted\n",sub1); break; } case 4: { printf("\n exiting\n"); break; } default: { printf("wrong choice"); break; } } }while(ch !=4); getch(); }

9) Mouse Pointer #include<stdio.h> #include<dos.h> union REGS in,out; void mouseposition(int *xp,int *yp,int *click) { in.x.ax=3; int86(0X33,&in,&out); *click=out.x.bx; *xp=out.x.cx; *yp=out.x.dx; } int main() { int x,y,c,x1,y1,c1; do { mouseposition(&x,&y,&c); if((x!=x1)||(y!=y1)||(c!=c1)) { clrscr(); printf("\n mouse coordinates"); printf("\n x \t :\t%d\n y\t:\t%d",x,y); printf("\n"); switch(c) { case 0: printf(" no"); break;

case 1: printf(" left"); break; case 2: printf(" right"); break; case 3: printf(" both"); break; } printf(" button pressed"); printf("\n press any key to exit"); } x1=x; y1=y; c1=c; }while(!kbhit()); return 1; }

10) Restrict mouse pointer within rectangle #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void main() { union REGS i,o; int gd=DETECT,gm; int button,poly[8]; initgraph(&gd,&gm,"C:\\TC\\BGI"); i.x.ax=0; int86(0x33,&i,&o); if(o.x.ax==0) { restorecrtmode(); printf("No mouse"); exit(0); } rectangle(99,100,501,151); i.x.ax=1; int86(0x33,&i,&o); i.x.ax=7; i.x.cx=100; i.x.dx=500; int86(0x33,&i,&o); i.x.ax=8; i.x.cx=100; i.x.dx=150; int86(0x33,&i,&o); i.x.ax=1; int86(0x33,&i,&o); gotoxy(25,23); printf("\n Press any key to exit"); poly[0]=100; poly[1]=100; poly[2]=500; poly[3]=100; poly[4]=500; poly[5]=150; poly[6]=100; poly[7]=150;

while(!kbhit()) { i.x.ax=3; int86(0x33,&i,&o); gotoxy(2,2); printf("X:%d\t Y:%d",o.x.cx,o.x.dx); button=o.x.bx&7; gotoxy(23,11); switch(button) { case 1:printf("Left button pressed"); setfillstyle(SOLID_FILL,6); fillpoly(4,poly); break; case 2:printf("Right button pressed"); setfillstyle(SOLID_FILL,0); fillpoly(4,poly); break; } } i.x.ax=0; int86(0x33,&i,&o); getch(); }

11) Port Address #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void main() { union REGS i,o; int gd=DETECT,gm; int button,poly[8]; initgraph(&gd,&gm,"C:\\TC\\BGI"); i.x.ax=0; int86(0x33,&i,&o); if(o.x.ax==0) { restorecrtmode(); printf("No mouse"); exit(0); } rectangle(99,100,501,151); i.x.ax=1; int86(0x33,&i,&o); i.x.ax=7; i.x.cx=100; i.x.dx=500; int86(0x33,&i,&o); i.x.ax=8; i.x.cx=100; i.x.dx=150; int86(0x33,&i,&o); i.x.ax=1; int86(0x33,&i,&o); gotoxy(25,23); printf("\n Press any key to exit"); poly[0]=100; poly[1]=100; poly[2]=500;

poly[3]=100; poly[4]=500; poly[5]=150; poly[6]=100; poly[7]=150; while(!kbhit()) { i.x.ax=3; int86(0x33,&i,&o); gotoxy(2,2); printf("X:%d\t Y:%d",o.x.cx,o.x.dx); button=o.x.bx&7; gotoxy(23,11); switch(button) { case 1:printf("Left button pressed"); setfillstyle(SOLID_FILL,6); fillpoly(4,poly); break; case 2:printf("Right button pressed"); setfillstyle(SOLID_FILL,0); fillpoly(4,poly); break; } } i.x.ax=0; int86(0x33,&i,&o); getch(); }

12) Restrict mouse pointer within circle #include<stdio.h> #include<dos.h> #include<stdlib.h> #include<conio.h> void main() { int far *p1=0x400; int far *p2=0x402; int far *p3=0x40a; clrscr(); printf("\nPort addresses:"); printf("\nCOM1:0x%x",*(p1)); printf("\nCOM2:0x%x",*(p2)); printf("\nLPT1:0x%x",*(p3)); getch(); } 13) Mouse movement using arrow keys #include<stdio.h> #include<dos.h> #include<graphics.h> #include<conio.h> #include<math.h> void main() { union REGS i,o; int gd=DETECT,gm,centx=200,centy=200,curr_x,curr_y; int radius=100,px=200,py=200; float dist; clrscr();

initgraph(&gd,&gm,"C:\\TC\\BGI"); circle(centx,centy,radius); i.x.ax=0; int86(51,&i,&o); i.x.ax=4; i.x.cx=centx; i.x.dx=centy; int86(51,&i,&o); i.x.ax=1; int86(51,&i,&o); while(!kbhit()) { i.x.ax=3; int86(51,&i,&o); curr_x=o.x.cx; curr_y=o.x.dx; dist=sqrt(abs((curr_x-centx)*(curr_x-centx))+abs((curr_y-centy)*(curr_y-centy))); if(dist>radius) { i.x.ax=4; i.x.cx=px; i.x.dx=py; int86(51,&i,&o); } else { px=curr_x; py=curr_y; } } getch(); }

14) Copying a file #include<stdio.h> #include<dos.h> #include<stdlib.h> #include<conio.h> #include<graphics.h> #define LEFT 75 #define RIGHT 77 #define DOWN 80 #define UP 72 #define STOP 1 void main() { union REGS i,o; int gd=DETECT,gm; int x,y; initgraph(&gd,&gm,"C:\\TC\\BGI"); i.x.ax=0; int86(51,&i,&o); i.x.ax=4; i.x.cx=getmaxx()/2; i.x.dx=getmaxy()/2; int86(51,&i,&o); i.x.ax=1; int86(51,&i,&o); while(1) { i.x.ax=3; int86(51,&i,&o);

x=o.x.cx; y=o.x.dx; i.h.ah=0x00; int86(0x16,&i,&o); switch(o.h.ah) { case LEFT:x--; break; case RIGHT:x++; break; case UP:y--; break; case DOWN:y++; break; case STOP:exit(0); } if(x<1) x=1; if(x>getmaxx()-2) x=getmaxx()-2; if(y<1) y=1; if(y>getmaxy()-2) y=getmaxy()-2; i.x.ax=4; i.x.cx=x; i.x.dx=y; int86(51,&i,&o); } } 15) #include<dos.h> #include<stdio.h> #include<math.h> #include <conio.h> void main() { char *name1; char *name2; char data; int size=0; int fp,fp1; union REGS i,o,i1,o1; clrscr(); printf("\nPath of source file:"); scanf("%s",name1); printf("\nPath of destination file:"); scanf("%s",name2); //open file1 i.h.al=0x02; i.h.ah=0x3d; i.x.dx=(unsigned int)name1; int86(0x21,&i,&o); //open file2 i1.h.al=0x02; i1.h.ah=0x3d; i1.x.dx=(unsigned int)name2; int86(0x21,&i1,&o1); if(o.x.cflag) { printf("Error opening..."); getch();

exit(0); } if(o1.x.cflag) { i1.h.ah=0x5b; i1.x.cx=0x00; i1.x.dx=(unsigned int)name2; int86(0x21,&i1,&o1); i1.h.al=0x02; i1.h.ah=0x3d; i1.x.dx=(unsigned int)name2; int86(0x21,&i1,&o1); } //transfer fp=o.x.ax; fp1=o1.x.ax; printf("\nTransferring data..."); while(1) { i.h.ah=0x3f; i.x.bx=fp; i.x.cx=1; i.x.dx=(unsigned int)&data; int86(0x21,&i,&o); if(o.x.ax==0) break; size++; i1.h.ah=0x40; i1.x.bx=fp1; i1.x.cx=1; i1.x.dx=(unsigned int)&data; int86(0x21,&i1,&o1); } printf("\nTransferring complete..."); printf("\nTransferred %d bytes of data...",size); getch(); }

Vous aimerez peut-être aussi