home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
dskutl
/
wd.arc
/
DISKSTUF.C
< prev
next >
Wrap
Text File
|
1987-10-02
|
9KB
|
318 lines
#include <\c_ms\include\structs.h>
#include <\c_ms\include\defs.h>
#include <\c_ms\include\scancode.h>
#include <\c_ms\include\color.h>
/* Global variables */
extern struct type_htable hd_table;
extern struct type_task_file task_file;
extern struct type_esfile ;
extern union type_scan scan_code;
extern struct type_error err_table[100];
extern char *rd_buffer, *wr_buffer, *fmt_buffer;
extern int command,err_count, errcnt,bad_count,redirection,quit;
extern char head_buf[16][buf_length];
extern unsigned char alt_value;
/*************************************/
/* */
/* init_disk() */
/* */
/* initialize hard disk */
/* */
/*************************************/
init_disk()
{ /* start of init_disk */
int temp_sdh;
at_reset(); /* reset hard drive */
while(at_ckbsy()); /* check busy bit in controler */
while(at_ckbsy()); /* wait untill drive is ready */
temp_sdh = (hd_table.max_head & 0xf) + /* bits 0-3 */
((hd_table.drv_number <<4) & 0x10) + /* bit 4 */
((hd_table.sec_size << 5) & 0x60) + /* bits 5,6 */
((hd_table.ecc << 7) & 0x80); /* bit 7 */
at_setp(temp_sdh,hd_table.max_sec); /* set parameters */
while(at_ckbsy()); /* check busy bit in controler */
while(at_ckbsy()); /* wait untill drive is ready */
load_task_file(); /* load task file */
at_rest(0); /* recal drive */
while(at_ckbsy()); /* check busy bit in controler */
while(at_ckbsy()); /* check busy bit in controler */
load_task_file(); /* load task file */
at_rest(0); /* restore drive */
while(at_ckbsy()); /* check busy bit in controler */
while(at_ckbsy()); /* check busy bit in controler */
if (at_rstat() & 0x05) /* check if error for recal */
show_error(); /* show any errors */
} /* end of init_disk */
/*************************************/
/* */
/* should_do_errors() */
/* */
/* find out from user if bad tracks */
/* should be marked bad then mark */
/* bad if was "Y" typed. */
/* */
/*************************************/
should_do_errors()
{ /* start of error junk */
int done;
unsigned char resp;
char temp_str[8];
do_errors(); /* show errors found in err_table */
printf("\n\nDo you wish to mark these blocks bad? (y/n)");
done = FALSE;
while(!done)
{
resp = get_input(redirection); /* get user responce */
resp = toupper(resp);
switch(resp)
{ /* start of switch */
case 'Y' : done = TRUE;
mark_bad_track(); /* mark bad tracks */
break;
case 'N' : err_count = 1;
done = TRUE;
break;
default : BELL;
} /* end of switch */
} /* end while */
} /* end of sould_do_errors */
/*************************************/
/* */
/* enter_bad_map() */
/* */
/* user can enter bad track map from */
/* keyboard. */
/* */
/*************************************/
enter_bad_map()
{ /* start of enter_bad_map() */
int done,in_valid;
unsigned char temp_str[8];
int temp1,temp2,temp3;
cls();
curs(1,1);
printf("\n\nYou may now enter additional blocks to be marked bad.");
printf("\n\nEnter cylinder number <CR> and head number <CR>) at ");
printf("\nthe prompt. To end entry, press ESC. at the prompt\n");
curs(8,20);printf("Enter <cylinder#> <head#>: ");
done = FALSE;
while(!done)
{ /* start of while */
do_ilt(128,0,wr_buffer); /* set bad sector mark */
in_valid = TRUE;
while((!done) AND in_valid)
{
upscroll(1,10,14,5,78,VNORMAL); /* scroll up one line */
done = get_dec2(14,31,4,&hd_table.cyl_number,ESC); /* get cyl number */
if((0 <= hd_table.cyl_number)
AND (hd_table.cyl_number <= hd_table.max_cyl))
in_valid = FALSE;
if((!done) AND in_valid) BELL;
}
if(!done)
{ /* start of if done */
in_valid = TRUE;
while((!done) AND in_valid)
{ /* start of if valid */
done = get_dec2(14,42,2,&hd_table.head_number,ESC); /* get head number */
if((0 <= hd_table.head_number)
AND (hd_table.head_number <= hd_table.max_head))
in_valid = FALSE;
if((!done) AND in_valid) BELL;
} /* end while valid */
} /* end if done */
if(!done)
{ /* start of if done */
do_ilt(128,hd_table.head_number,wr_buffer); /* set badsector mark */
load_task_file(); /* load task file */
at_fmt(); /* do format */
while(!( 0x08 & at_rstat())); /* wait for data request */
at_wrbfr(0, wr_buffer); /* write buffer */
while(at_ckbsy()); /* check busy bit in controler */
while(at_ckbsy()); /* check busy bit in controler */
} /* end if done */
} /* end of while */
} /* end enter_bad_map() */
/*************************************/
/* */
/* mark bad track */
/* */
/*************************************/
mark_bad_track()
{ /* start of mark_bad_track */
bad_count = 0;
do_ilt(128,0,wr_buffer);
for (errcnt = 1; errcnt < err_count; errcnt++)
{
hd_table.cyl_number = err_table[errcnt].cyl;
hd_table.head_number = err_table[errcnt].head;
load_task_file();
at_fmt();
while(!( 0x08 & at_rstat())); /* wait for data request */
at_wrbfr(0, wr_buffer);
while(at_ckbsy()); /* check busy bit in controler */
while(at_ckbsy()); /* check busy bit in controler */
bad_count++;
}
} /* end of mark_bad_sector */
/*************************************/
/*************************************/
/* */
/* make block mark and sector # */
/* for one track */
/* */
/*************************************/
do_ilt(block_mark,head,buff)
char block_mark;
int head;
unsigned char *buff;
{
int offset, count, ileave, maxcnt;
unsigned char temp, *p;
p = buff;
for( count=0; count < 512; count++ )
*p++ = 0xff; /* fill buffer with 0xFF */
ileave = hd_table.ileave; /* set up vars for loop */
count = 0;
if(hd_table.alt_sector) maxcnt = hd_table.max_sec-1;
else maxcnt = hd_table.max_sec;
offset = (hd_table.skew*head)%maxcnt; /* clear offset */
while ( count < maxcnt )
{
for( ; *(buff+(offset*2)) != 0xFF; offset++); /* inc offset if overlap*/
p = buff + ( offset * 2 );
*p++ = block_mark; /* block mark */
*p = 1+(count % maxcnt); /* sector number */
offset += ileave; /* inc offset by interleave */
offset = offset % maxcnt; /* loop offset */
count++;
} /* end of while */
if(hd_table.alt_sector) /* if need alt sector */
{
p = buff + (maxcnt * 2);
*p++ = block_mark; /* block mark */
*p = alt_value; /* sector number*/
}
}
/*************************************/
/* */
/* set up task file and load it */
/* */
/*************************************/
load_task_file()
{
task_file.error = hd_table.precomp;
task_file.secnt = hd_table.blk_size;
task_file.sector = hd_table.sec_number;
task_file.cyllo = (hd_table.cyl_number % 256);
task_file.cylhi = (hd_table.cyl_number / 256);
task_file.SDH = (hd_table.head_number & 0xf) + /* bits 0-3 */
((hd_table.drv_number <<4) & 0x10) + /* bit 4 */
((hd_table.sec_size << 5) & 0x60) + /* bits 5,6 */
(hd_table.ecc << 7); /* bit 7 */
at_wtskf(&task_file);
}
/*************************************/
/* */
/* display errors from reisters */
/* */
/*************************************/
show_error()
{
curs(22,1);
printf(" Error!!... Cyl. %4d Head %2d Status %2x Error %2x",
hd_table.cyl_number, hd_table.head_number,
at_rstat(), at_rderr());
}
/*************************************/
/* */
/* display errors found in error table*/
/* */
/*************************************/
do_errors()
{
cls();
curs(1,1);
printf("Errors will be marked at the following cylinder/head locations:");
printf("\n\n");
for (errcnt = 1; errcnt < err_count; errcnt++)
{
printf(" %4d/%2d", err_table[errcnt].cyl,
err_table[errcnt].head);
if ((errcnt % 5) == 0)
printf ("\n");
}
}
/*************************************/
/* */
/* dimp 5 lines of buffer to screen */
/* */
/*************************************/
dump_5lines(buffer)
char *buffer;
{
int num_bytes, count;
for (count = 0; count < 80; count++)
{
if ((count % 16) == 0)
printf("\n%04x ", count);
printf("%02x ", buffer[count]);
};
printf("\n");
}