home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd2.bin
/
dosutils
/
partprog
/
pdisk.arc
/
FDINTINS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-01-12
|
9KB
|
320 lines
/* fdintins: Install the FDINTTBL program for various systems. See assembly
* source code for fdtblint at the bottom of this file.
*
* Copyright (C) 1986, Scott E. Garfinkle. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
typedef unsigned char byte;
typedef unsigned int word;
typedef unsigned long dword;
#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <io.h>
#include <dos.h>
#include <errno.h>
#include <ctype.h>
#pragma pack(1)
typedef struct { /* BIOS-maintained fixed disk parameter table entry.
* INT 0x41 (or 46 for drive 2) points to a descriptor
* table for the current fixed drive. See BIOS listing
*/
word fd_ncyls; /* number of cylinders on drive */
char fd_heads; /* number of heads on drive */
word fd_current; /* starting cyl for reduced write current (XT only) */
word fd_write_precomp; /* starting cylinder for write pre-compensation
* or -1 if no write precompensation needed.
*/
byte fd_ecc_burst, /* max ecc data burst length (XT only) */
fd_control, /* see below */
fd_std_time, /* standard time out value (XT only) */
fd_format_time, /* time out for format drive (XT only) */
fd_check_time; /* time out for check drive (XT only) */
word fd_lz; /* landing zone */
char fd_sec_per_track; /* # of sectors per track */
char fd_reserved; /* reserved for future use */
} DISK_TABLE, far *FDPTR;
struct program {
word init_jump;
DISK_TABLE fdtbld;
byte unused0[4];
word intr_no;
byte unused1[7];
word intr_off;
byte unsused2[3];
word intr_seg;
byte unsed3[8];
byte diskno;
byte unused4[11];
} *data;
#define p_ncyls fdtbld.fd_ncyls
#define p_heads fdtbld.fd_heads
#define p_current fdtbld.fd_current
#define p_precomp fdtbld.fd_write_precomp
#define p_burst fdtbld.fd_ecc_burst
#define p_control fdtbld.fd_control
#define p_stdtime fdtbld.fd_std_time
#define p_fmttime fdtbld.fd_format_time
#define p_chktime fdtbld.fd_check_time
#define p_lz fdtbld.fd_lz
#define p_sec_per_track fdtbld.fd_sec_per_track
#define p_reserved fdtbld.fd_reserved
byte data_tbl[] = {
0xEB, 0x10,
0x00, 0x04, 0x04, 0x00, 0x00, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x11, 0x00,
0xBE, 0x02, 0x01, 0xBF,
0x90, 0x01,
0x33, 0xC9, 0x8E, 0xC1, 0x26, 0x89, 0x3E,
0x04, 0x01,
0x26, 0x89, 0x0E,
0x06, 0x01,
0xB9, 0x08, 0x00, 0xF3, 0xA5, 0xB4, 0x09, 0xB2,
0x80,
0xCD, 0x13, 0xB4, 0x00, 0xCD, 0x13, 0xB8, 0x00, 0x4C, 0xCD, 0x21
};
#define DISK_NO1 0x80
#define DISK_NO2 0x81
#define DISK_NO1_LOC 0x41*4
#define DISK_NO2_LOC 0x46*4
#define DFLT_INTR 0x64
char *prgname = "tblint .com";
main()
{
int i, fd, line_no=4, num_disks;
union REGS regs;
data = (struct program *)data_tbl;
regs.h.ah = 8;
regs.h.dl = 0x80;
int86(0x13, ®s, ®s);
num_disks = regs.h.dl;
scr_smode(scr_gmode()); /* clear screen */
scr_pos(22,0);
printf("Custom Fixed Disk Installation, Copyright(C) 1986, 1988 S. E. Garfinkle.");
scr_pos(23,0);
printf("All rights reserved.");
i = get_scr_val(line_no++,10,"Disk number 1 or 2?",1,1,2);
if (num_disks >= i)
data->fdtbld = *(FDPTR) _dos_getvect(i==1 ? 0x41 : 0x46);
prgname[6] = i+'0';
if (i == 1) {
data->diskno = DISK_NO1;
data->intr_off = DISK_NO1_LOC;
data->intr_seg = DISK_NO1_LOC+2;
i = DFLT_INTR;
}
else {
data->diskno = DISK_NO2;
data->intr_off = DISK_NO2_LOC;
data->intr_seg = DISK_NO2_LOC+2;
i = DFLT_INTR+4;
}
data->intr_no = 4 * get_scr_val(line_no++,16,"Use which base interrupt (base 16)? ",i,0x60,0x6c);
data->p_heads = get_scr_val(line_no++,10,"Number of heads on the disk?",data->p_heads,0,72);
data->fdtbld.fd_ncyls = get_scr_val(line_no++,10,"Number of cylinders (max 1024)?",data->fdtbld.fd_ncyls,20,1024);
data->p_control = get_scr_val(line_no++,16,"Control byte value (base 16)?",0,0,0xff);
i = get_scr_val(line_no++,10,"Are you using an AT (0) or XT (1) compatible?",0,0,1);
data->p_precomp = get_scr_val(line_no++,10,
"Cylinder on which to start write precompensation?", i-1,-1,data->p_ncyls-1);
if(i) {
data->p_current = get_scr_val(line_no++,10,"Cylinder on which to start write reduced write current?",
data->p_precomp,0,data->p_ncyls-1);
data->p_burst = get_scr_val(line_no++,10,"ECC Burst length?", 0x0b,0,0xff);
data->p_stdtime = get_scr_val(line_no++,10,"Standard timeout value?",0x0c,0,0xff);
data->p_fmttime = get_scr_val(line_no++,10,"Timeout value for formatting?",0xb4,0,0xff);
data->p_chktime = get_scr_val(line_no++,10,"Timeout value for checks?",0x28,0,0xff);
}
else {
data->p_lz = get_scr_val(line_no++,10,"Cylinder for landing zone?",data->p_ncyls,0,2048);
data->fdtbld.fd_sec_per_track = get_scr_val(line_no++,10,"Number of sector per track?",data->fdtbld.fd_sec_per_track,1,40);
}
if((fd=open(prgname,O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,S_IREAD|S_IWRITE)) < 0) {
fprintf(stderr,"\nCouldn't open file: '%s' ",prgname);
fputs(errno==EACCES ? "exists and is read-only or is a directory\n" :
". Couldn't open any more files (check config.sys)\n",
stderr);
exit(1);
}
write(fd,data_tbl,sizeof(struct program));
close(fd);
exit(0);
}
#define ESC 27
#define BACKSPACE 8
int
get_scr_val(start, base, m_str, def_val, low_lim, high_lim)
int start; /* what line this goes on */
char *m_str; /* what to say on that line */
int def_val, /* default value */
low_lim, /* least acceptable value */
high_lim; /* highest acceptable value */
{
int val, len, len1, len2, len3;
word pos, row, col, col2;
char buf[8];
len1 = strlen(itoa(def_val, buf, base));
len2 = strlen(itoa(low_lim, buf, base));
len3 = strlen(itoa(high_lim, buf, base));
len = max(max(len1,len2),len3);
scr_pos(start,0);
printf("%s [%*s]",m_str,len," ");
fflush(stdout);
pos = scr_rpos(); /* read scr_pos position */
row = pos >> 8;
col2 = (pos & 0xff) - 2;
col = col2-len+1;
#ifdef DEBUG
scr_pos(24,0); printf("len %d, row %d, col2 %d",len,row,col2);
fflush(stdout);
#endif
do {
int c;
val = 0;
do {
scr_pos(row, col);
printf(base==10 ? "%*d" : "%*x",
len,val ? val : def_val);
fflush(stdout);
scr_pos(row, col2);
c=getch();
if(isupper(c))
c = tolower(c);
#ifdef DEBUG
scr_pos(18,0);printf("!! val %d, c %d\n",val,c);fflush(stdout);
#endif
switch (c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if((val = val*base + c - '0') > high_lim) {
scr_pos(row+2,0);
printf(base==10 ? "Maximum value is %d.":
"Maximum value is %x.",high_lim);
sleep(1000L);
erase_eol(row+2);
val = 0;
}
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
if(base==16 &&
(val = val*base + c - 'a'+10) > high_lim) {
scr_pos(row+2,0);
printf("Maximum value is %x.",high_lim);
sleep(1000L);
erase_eol(row+2);
val = 0;
}
break;
case BACKSPACE:
if(val)
val /= base;
break;
case EOF:
exit(1); /* assume we need an immediate abort */
/* NOTREACHED */
/* default: ignore the character. */
} /* end of switch */
} while (c != '\r' && c != '\n' && c != ESC);
if(!val)
val = def_val;
else if (val<low_lim) {
scr_pos(row+2,0);
printf(base==10 ? "Minimum value is %d.":
"Minimum value is %x.", low_lim);
sleep(1000L);
erase_eol(row+2);
}
} while(val<low_lim);
return(val);
}
erase_eol(from) /* erase line "from" and stay there */
word from;
{
word scr_gac();
scr_scroll(from, 0, from, 79, 0, 7);
scr_pos(from,0);
}
/*
; FDTBLINT: Create fixed disk table to use instead of default DOS ones.
; This version should normally only be used if you plan to use the IBM
; diagnostic routines -- these routines screw up the memory management and
; overwrite the table of FDTBL. See accompanying program FDTBL, otherwise.
;
.RADIX 16
INTR EQU (41H*4)
DISKNO EQU 80H
INTR64 EQU (64H*4) ; use reserved for users intrs 64 to 67 to store table
CSEG SEGMENT
ORG 100H
ASSUME CS:CSEG,DS:CSEG
BEGIN: JMP SHORT START
DATA LABEL BYTE
DW 1024 ; number of cylinders
DB 4 ; number of heads
DW -1 ; starting reduced write current cylinder (XT only)
DW -1 ; starting write precompensation cylinder
DB 0 ; max ECC data burst length (XT only)
DB 0 ; control byte
DB 0 ; standard time out value (XT only)
DB 0 ; format time out value (XT only)
DB 0 ; check drive time out value (XT only)
DW 1024 ; landing zone cyl (usually same as number of cyl)
DB 17 ; number of sectors per track (don't change)
DB 0 ; reserved
START: MOV SI,OFFSET DATA ; whence (offset part. segment part set in DS)
MOV DI,INTR64 ; whither (offset part)
XOR CX,CX ; whither (segment part)
MOV ES,CX
MOV ES:[INTR],DI ; update pointer to table (offset part)
MOV ES:[INTR+2],CX ; (segment part)
MOV CX,8 ; length (in words) of table)
REP MOVSW ; move it in
MOV AH,9 ; "initialize characteristics"
MOV DL,DISKNO
INT 13H
MOV AH,0 ; "reset disk"
INT 13H
MOV AX,4C00H ; terminate
INT 21H
CSEG ENDS
END BEGIN
*/