|
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <bios.h>
#include <stdio.h>
#include <dos.h>
table();
main()
{
long count;
int result,action,drive,heads,tracks,sectors,head,track,sector,nsector;
char buffer[512],restart;
randomize();
textmode(C80);
textattr(10);;
drive=0;
window(1,1,80,25);
clrscr();
begin:
printf("Checking drive >>>>>");
//подсчитываем
количество головок, дорожек, секторов...
result = biosdisk(4,drive,0,0,1,1,buffer);
//есть-ли диск в
дисководе?
if (result%2!=0||result==128)
//если нет, то заново
{
printf("Not Ready\n\r");
delay(2000);
goto begin;
}
if (result%2==0)
//если есь, то начинаем
тестирование
{
printf("Ready\n\r");
count=0;
cprintf("Test drive?");
restart=getche();
if (restart=='y'||restart=='\r')
{
cprintf("\r\nTesting drive >>>>>\r\n");
result=2;
heads=0;
do {
result = biosdisk(4,drive,heads,0,1,1,buffer);
if (result==0) heads++;
} while (result==0);
//подсчитываем головки
cprintf("Heads:%d\r\n",heads);
result=2;
tracks=0;
do {
result = biosdisk(4,drive,0,tracks,1,1,buffer);
if (result==0) tracks++;
} while (result==0);
//подсчитываем дорожки
cprintf("Tracks:%d\r\n",tracks);
result=2;
sectors=1;
do {
result = biosdisk(4,drive,0,0,sectors,1,buffer);
if (result==0)
sectors++;
} while (result==0);
//подсчитываем сектора
cprintf("Sectors:%d\r\n",sectors);
}
else
{
heads=0;
tracks=0;
sectors=0;
}
}
delay(1500);
clrscr();
table();
cprintf("action:\r\ndrive:\r\nhead:\r\ntrack:\r\nsector:\r\nnsects:\r\n");
window(8,1,39,8);
cscanf("%d",&action);cprintf("\r\n\a");
//спрашивам у
пользователя что будем делать дальше
window(30,1,80,25);
clrscr();
cprintf("drive:%d\r\nheads:%d\r\ntracks:%d\r\nsectors:%d",drive,heads,tracks,sectors);
window(1,9,80,25);
clrscr();
window(8,2,39,8);
if (action==100)
//проверить другой диск и переключится на него
{
check:
window(1,1,80,25);
clrscr();
cprintf("Which drive do you want to
use?\r\nFDD (1)\r\nHDD-1 (2)\r\nHDD-2 (3)\r\nPress 1, 2 or 3 >>>>");
getch();
restart=getche();
switch (restart)
{
case
'!':
case
'1': drive=0;
break;
case
'@':
case
'2': drive=0x80;
break;
case
'3':
case
'#': drive=0x81;
break;
case 27: action=4;
goto
begin;
default: cprintf("\r\nWrong entery!!!");
delay(2000);
goto check;
}
goto begin;
}
if (action==2571)
//испортить произвольные
сектора на диске
{
code:
window(1,1,80,25);
clrscr();
cprintf("WARNING!!!\r\nYou have entered a
secret code,\r\nif you are not sure what you are doing press
ESC\r\n\aCONTINUE?");
getch();
restart=getche();
if (restart=='y'||restart=='\r')
{
cprintf("\r\nWhich drive do you want to
use?\r\nFDD (1)\r\nHDD-1 (2)\r\nHDD-2 (3)\r\nPress 1, 2 or 3 >>>>");
}
restart=getche();
switch (restart)
{
case
'!':
case '1': drive=0;
break;
case
'@':
case
'2': drive=0x80;
break;
case
'3':
case
'#': drive=0x81;
break;
case
27: action=4;
goto begin;
default: cprintf("\r\nWrong entery!!!");
delay(2000);
goto code;
}
cprintf("\r\nYou have entered %c!!!
OK?",restart);
restart=getche();
if (restart=='y'||restart=='\r')
{
cprintf("\r\nEnter your data into
buffer>>>>> ");
cscanf("%s",
buffer);
nsector=1;
clrscr();
cprintf("Function activated!!!>>>>");
window(26,1,80,25);
count=0;
while (bioskey(1) ==
0)
{
cprintf(" \r%d",count);
head=random(heads);
track=random(tracks);
sector=random(sectors);
result=biosdisk(3,drive,head,track,sector,nsector,buffer);
if (result==0x00)
count++;
}
window (1,1,80,25);
delay(3000);
}
else {goto code;}
cprintf("\r\n\arestart?");
restart=getche();
if (restart=='y'||restart=='\r')
{
goto begin;
}
}
cscanf("%d",&drive);cprintf("\r\n\a");
cscanf("%d",&head);cprintf("\r\n\a");
cscanf("%d",&track);cprintf("\r\n\a");
cscanf("%d",§or);cprintf("\r\n\a");
cscanf("%d",&nsector);window(1,7,39,8);cprintf("\aPrompt
buffer?");
getch();
restart=getche();
if (restart=='y'||restart=='\r')
{
cprintf("\r\n\aBuffer: ");
cscanf("%s",
buffer);
}
biosdisk(action,drive,head,track,sector,nsector,buffer);
//производим операции с секторами
cprintf("\r\n\aShow buffer?");
window(1,1,80,25);
clrscr();
cprintf("Buffer:");
cprintf("%s",
buffer);
cprintf("\r\n\arestart?");
restart=getche();
if (restart=='y'||restart=='\r')
{
clrscr();
goto begin;
}
return 1;
}
table()
//посторении таблицы о
всех действиях которые могут произведины над диском
{
window(30,1,80,25);
cprintf("0 -Resets disk system, forcing the drive controller to do a
hard reset; ignore all other parameters\r\n1 -Returns the status of the
last disk operation; ignores all other parameters\r\n2 -Reads one or
more disk sectors into memory\r\n3 -Writes one or more disk sectors from
memory\r\n4 -Verifies one or more sectors\r\n5 -Formats a track");
window(1,9,80,25);
cprintf("6 -Formats a track and sets bad sector flags\r\n7 -Formats the
drive beginning at a specific track\r\n8 -Returns the current drive
parameters, in buffer's first 4 bytes\r\n9 -Initializes drive-pair
characteristics\r\n10 -Does a long read (512 plus 4 extra bytes per
sector)\r\n11 -Does a long write (512 plus 4 extra bytes per
sector)\r\n12 -Does a disk seek\r\n13 -Alternates disk reset\r\n14
-Reads sector buffer\r\n15 -Writes sector buffer\r\n16 -Tests whether
the named drive is ready\r\n17 -Recalibrates the drive\r\n18 -Controller
RAM diagnostic\r\n19 -Drive diagnostic\r\n20 -Controller internal
diagnostic\r\n 100- change drive and restart");
window(1,1,80,25);
return 1;
} |