# 设计(28) 《FDISK硬盘分区模拟软件》设计

《FDISK硬盘分区软件模拟软件》

FDISKS设计

FDISKS不对硬盘发生实际影响，只是对虚拟的硬盘数据进行改变。本软件是作为“上海市计算机应用能力中级”上机考试使用软件之一，自2000年开发成功至今，已被上海电视大学，等单位大量免费使用。

由于实际的Fdisk硬盘分区软件操作不当有使盘上数据丢失危险，不能随便拿来供不熟悉该软件操作的学生当作练习进行试验，为此我除了开发一个供考试用的模拟软件之外，还另外开发了一个供考练习用的模拟软件。它预先假设硬盘有多少大（当时我假设为400M），要求学生按要求分成几个区，完毕后能指示结果是否正确。以下为其全部源程序(但不包含CCMSGIO一个被调用的中文输入输出单元，当时BP的CRT单元有200号错误，我在本软件中编程实现了CRT单元的全部功能)：

USES DOS{,CRTU},graph,CCMSGIO;
type
tpage=array [1..25] of string[80];
const
{ title1=
'  Partition Status   Type    Volume Label  Mbytes   System   Usage';
examp1=
'   C: 1        A    PRI DOS                 1020   FAT16       16%';
}
title2=
'  Drv Volume Label  Mbytes  System  Usage';
examp2=
'  D:  SOFTWARE       2047  FAT16      38%';

var
disks:integer; {numbers of disk}
disk:integer;  {current disk #}
tsiz,          {total size of disk[i]}
psiz,
esiz,
remainder,
drive:         {total drives in disk[i]}
array [1..2] of integer;
dsiz:          {size of drive in disk[i]}
array[1..2,0..10] of integer;
act:integer;
active:char;
FAT32,         {true when disk[i] > 512M}
PRICreated,      {true when PRI Partition exist}
EXTCreated:      {true when EXT partition exist}
boolean;

sizstr:string;

const
{----------}
page:array[1..14] of string[80]=
('Your computer has a disk larger than 512 MB. This version of Windows',
'includes improved support for large disks, resulting in more efficient',
'use of disk space on large drives, and allowing disks over 2 GB to be',
'formatted as a single drive.',
'',
'INPORTANT: If you enable large disk support and create any new drives on this',
'disk, you will not be able to access the new drive(s) using other operating',
'systems, including some versions of Windows 95 and Windows NT, as well as',
'earlier versions of Windows and MS-DOS. In addition, disk utilities that',
'were not designed explicitly for the FAT32 file system will not be able',
'to work with this disk. If you need to access this disk with other operating',
'systems or older disk utilities, do not enable large drive support.',
'',
'Do you wish to enable large disk support (Y/N)...........? [Y]');
{-------------}
page0:tpage=
('                           Microsoft Windows 95',
'                         Fixed Disk Setup Program',
'                 (C)Copyright Microsoft Corp. 1983 - 1997',
'',
'                              FDISK Options',
'',
'Current fixed disk drive: 1',
'',
'Choose one of the following:',
'',
'1. Create DOS partition or Logical DOS Drive',
'2. Set active partition',
'3. Delete partition or Logical DOS Drive',
'4. Display partition information',
'5. Change current fixed disk drive',
'',
'',
'Enter choice: [1]',
'',
'',
'',
'',
'',
'',
'Press Esc to exit FDISK');
{-------------}
page1:tpage=
(
'','','','',
'                Create DOS Partition or Logical DOS Drive',
'',
'Current fixed disk drive: 1',
'',
'Choose one of the following:' ,
'',
'1. Create Primary DOS Partition',
'2. Create Extended DOS Partition',
'3. Create Logical DOS Drive(s) in the Extended DOS Partition',
'','','','',
'Enter choice: [1]',
'','','','','','',
'Press Esc to return to FDISK Options'
);

{-------------}
page11:tpage=
(
'','','','',
'                      Create Preimary DOS Partition',
'',
'Current fixed disk drive: 1',
'',
'Partition Status   Type    Volume Label  Mbytes   System   Usage',
'','',
'','','','','','','','','','','',
'Primary DOS Partition already exists.',
'',
'Press Esc to continue'
);

page12:tpage=
(
'','','','',
'                      Create Extended DOS Partition',
'',
'Current fixed disk drive: 1',
'',
'Partition Status   Type    Volume Label  Mbytes   System   Usage',
'','','','','','','','','','','','','',
'Extended DOS Partition already exists.',
'',
'Press Esc to continue'
);

page13:tpage=
('',
'           Create Logical DOS Drive(s) in the Extended DOS Partition',
'',
'Drv Volume Label  Mbytes  System  Usage',
'','','','','','','','',
'','','','','',
'','','','','',
'All available space in the Extended DOS Partition',
'is assigned to logical drives.',
'Press Esc to continue');

page2:tpage=
(
'','','','',
'                          Set Active Partition',
'',
'Current fixed disk drive: 1',
'',
'Partition Status   Type    Volume Label  Mbytes   System   Usage',
'','','','','','','','','','','','',
'The only startable partition on Drive 1 is already set active.',
'','',
'Press Esc to continue'
);

page3:tpage=
(
'','','','',
'                Delete DOS Partition or Logical DOS Drive',
'',
'Current fixed disk drive: 1',
'',
'Choose one of the following:' ,
'',
'1. Delete Primary DOS Partition',
'2. Delete Extended DOS Partition',
'3. Delete Logical DOS Drive(s) in the Extended DOS Partition',
'4. Delete Non-DOS Partition',
'','','',
'Enter choice: [ ]',
'','','','','','',
'Press Esc to return to FDISK Options'
);

page31:tpage=
(
'','','','',
'                      Delete Primary DOS Partition',
'',
'Current fixed disk drive: 1',
'',
'Partition Status   Type    Volume Label  Mbytes   System   Usage',
'','','','','',
'Total disk space is  6479 Mbytes (1 Mbyte = 1048576 bytes)',
'','','','','','','',
'Cannot delete Primary DOS partition on drive 1',
'when an Extended DOS Partition exists.',
'Press Esc to continue'
);

page32:tpage=
(
'','','','',
'                      Delete Extended DOS Partition',
'',
'Current fixed disk drive: 1',
'',
'Partition Status   Type    Volume Label  Mbytes   System   Usage',
'','','','','',
'Total disk space is  6479 Mbytes (1 Mbyte = 1048576 bytes)',
'','','','','','','',
'Cannot delete Extended DOS partition while logical drives exist.',
'',
'Press Esc to continue'
);

page33:tpage=
('',
'           Delete Logical DOS Drive(s) in the Extended DOS Partition',
'',
'Drv Volume Label  Mbytes  System  Usage',
'','','','','','','','',
'','','','','',
'Total Extended DOS Partition size is  5452 Mbytes (1 Mbyte = 1048576 bytes)',
'',
'WARNING! Data in a deleted Logical DOS Drive will be lost.',
'What drive do you want to delete............................?[ ]',
'','','',
'Press Esc to return to FDISK Options');

page4:tpage=
('','','','',
'                      Display Partition Information',
'',
'Current fixed disk drive: 1',
'',
'Partition Status   Type    Volume Label  Mbytes   System   Usage',
'','','','','',
'Total disk space is  6479 Mbytes (1 Mbyte = 1048576 bytes)',
'','',
'The Extended DOS Partition contains Logical DOS Drives.',
'Do you want to display the logical drive information (Y/N)......?[Y]',
'','','','','',
'Press Esc to return to FDISK Options');

page41:tpage=
('',
'                      Display Logical DOS Drive Information',
'',
'Drv Volume Label  Mbytes  System  Usage',
'','','','','','','','',
'','','','','',
'Total Extended DOS Partition size is  5452 Mbytes (1 Mbyte = 1048576 bytes)',
'','','',
'','','',
'Press Esc to continue');

{CRTU -----------------------------------------------------------}
var i,j,c:integer; ch,cmd:char;

var  cb,cf,xo,yo,curx,cury:byte;
xm,ym:byte;

var bbb:byte;

function ra(R:real;w1,w2:integer):string;
var s:string;
begin
str(r:w1:w2,s);
ra:=s;
end;

function wherex:byte;
begin
wherex:=curx
end;

function wherey:byte;
begin
wherey:=cury
end;

procedure setcusr(x,y:integer);
var r:registers;
tt:word;
pg:byte;
begin
pg:=0;
r.ah:=2;
r.bh:=pg;
r.dl:=x;
r.dh:=y;
intr($10,r); end; procedure clrscr; var x,y:integer; begin for y:=yo to ym do for x:=xo to xm do begin mem[$b800:(y-1)*160+2*(x-1)]:=32;
mem[$b800:(y-1)*160+2*(x-1)+1]:=cb shl 4+cf; end end; procedure tdelline(y:integer); function readkey:char; var aaa:byte; begin asm mov ah,0 int 16h mov aaa,al mov bbb,ah end; readkey:=chr(aaa); end; var x:integer; begin for x:=xo to xm do begin mem[$b800:(y-1)*160+2*(x-1)]:=32;
mem[$b800:(y-1)*160+2*(x-1)+1]:=1 shl 4+cf; end; readkey; end; procedure delline(y:integer); var x:integer; begin for x:=xo to xm do begin mem[$b800:(y-1)*160+2*(x-1)]:=32;
mem[$b800:(y-1)*160+2*(x-1)+1]:=cb shl 4+cf; end end; procedure gotoxy(x,y:byte); begin curx:=x; cury:=y; setcusr(x-1,y-1); end; procedure window(x1,y1,x2,y2:byte); begin xo:=x1; yo:=y1; xm:=x2; ym:=y2; end; procedure ggotoxy(x,y:byte); begin asm mov ah,02h mov dh,x mov dl,y int 10h end; end; procedure hidecursor; begin asm mov bh,0 mov dh,25 mov dl,0 mov ah,2 int 10h end end; procedure showcursor; begin asm mov bh,0 mov dh,0 mov dl,0 mov ah,2 int 10h end end; procedure textcolor(c:byte); begin cf:=c; mem[$0000:$0466]:=c end; procedure textbackground(c:byte); begin cb:=c end; function Csec:word; var hh,mm,ss,dd:word; begin gettime(hh,mm,ss,dd); Csec:=(((hh*60)+mm)*60+ss)*100+dd; end; procedure delay(ms:word); var t1,t2:word; begin t1:=Csec; repeat t2:=Csec; until t2-t1>=ms div 10; end; function kkeypressed:boolean; var aaa,bbb:byte; begin asm lahf mov aaa,ah end; if aaa and 64=0 then kkeypressed:=true else kkeypressed:=false end; function rreadkey:char; var aaa:byte; begin asm mov ah,0 int 16h mov aaa,al mov bbb,ah end; rreadkey:=chr(aaa); end; function rreadkey2:char; begin rreadkey2:=chr(bbb); end; function keypressed:boolean; var eee,bbb:byte; begin keypressed:=true; bbb:=mem[$0040:$001a]; eee:=mem[$0040:$001c]; if (bbb=eee) then keypressed:=false; end; function readkey2:char; begin readkey2:=chr(bbb); end; function readkey:char; var aaa:byte; begin asm mov ah,0 int 16h mov aaa,al mov bbb,ah end; readkey:=chr(aaa); end; procedure sound(hz:word); begin end; procedure nosound; begin end; procedure _write(s:string); var i:integer; begin if yo+cury>ym+1 then exit; for i:=1 to length(s) do begin if xo+curx>xm+1 then exit; mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2]:=ord(s[i]);
mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2+1]:=cb*16+cf; curx:=curx+1; end; end; procedure swrite(s:string); var i:integer; begin if yo+cury>ym+1 then exit; for i:=1 to length(s) do begin if xo+curx>xm+1 then exit; mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2]:=ord(s[i]);
mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2+1]:=cb*16+cf; curx:=curx+1; end; end; procedure Wwrite(s:string; w:integer); var x,y,i:integer; begin x:=curx; y:=cury; for i:=1 to length(s) do write(' '); for I:=1 to w-length(s) do curx:=curx+1; if yo+cury>ym+1 then exit; for i:=1 to length(s) do begin if xo+curx>xm+1 then exit; mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2]:=ord(s[i]);
mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2+1]:=cb*16+cf; curx:=curx+1; end; end; procedure wln; begin cury:=cury+1; curx:=1; end; procedure initialize; begin xo:=1; yo:=1; xm:=80; ym:=25; cf:=7; cb:=0; end; {END of CRTU -----------------------------------------------------} procedure Fwrite(s:string; w:integer); begin write(s:w); end; procedure wr(ch:char); {? color } begin textcolor(c); write(ch); end; procedure wrcxy(x,y,c:integer; s:string); var i:integer; begin for i:=1 to length(s) do begin mem[$b800:(yo+y-2)*160+(xo+x-2)*2]:=ord(s[i]);
mem[$b800:(yo+y-2)*160+(xo+x-2)*2+1]:=cb*16+c; x:=x+1; end; end; procedure getstr(var s:string); {graph mode} var len:integer; c:char; begin len:=0; repeat len:=len+1; c:=readkey; if c in ['0'..'9'] then outtext(c); s[len]:=c; until c=#13; s[0]:=chr(len); end; procedure getint(x,y,w:integer; var i:integer); var ch:char; maxi,v,k,n,j,err:integer; p,s:string; start:boolean; label loop; begin maxi:=i; gotoxy(x,y); write(i); str(i,p); n:=length(p); x:=x+length(p)-1; loop: start:=false; gotoxy(x,y); v:=0; k:=0; s:=''; repeat gotoxy(x,y); if keypressed then begin ch:=readkey; if start=false then begin gotoxy(x-w+1,y); for j:=1 to w do swrite(' '); gotoxy(x,y); end; case ch of #8:if k>0 then begin delline(22); s:=copy(s,1,length(s)-1); gotoxy(x-k+1,y); k:=k-1; swrite(' '+s); gotoxy(x,y); end; #13: if k>0 then begin val(s,v,n); i:=v; if i<=maxi then begin clrscr; exit; end else begin gotoxy(1,22); textcolor(15); swrite('Invalid range of numerical value.'); ch:=#255; k:=0; s:=''; i:=0; gotoxy(x,y); goto loop; end; end; '0'..'9': begin delline(22); if start=false then begin gotoxy(x-w+1,y); for j:=1 to w do swrite(' '); gotoxy(x,y); start:=true; end; if (k<w) and (i<=maxi) then begin s:=s+ch; gotoxy(x-k,y); k:=k+1; swrite(s); ch:=#255; gotoxy(x,y); end else begin gotoxy(1,22); textcolor(15); swrite('Invalid range of numerical value.'); ch:=#255; k:=0; s:=''; gotoxy(x,y); end; end else begin gotoxy(1,22); textcolor(15); swrite('Invalid numerical value.'); end; end; end; until ch in [#27,#13]; end; function showpage(n:integer; p:tpage):char; procedure wr(s:string); var i:integer; begin if yo+cury>ym+1 then exit; for i:=1 to length(s) do begin if xo+curx>xm+1 then exit; mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2]:=ord(s[i]);
mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2+1]:=cb*16+cf; curx:=curx+1; end; end; procedure wr0(ch:char); begin textcolor(c); write(ch); end; var i,j:integer; ch,chlast:char; begin cf:=7; clrscr; curx:=1; cury:=1; for i:=1 to 25 do begin wr(' '); for j:=1 to length(p[i]) do begin ch:=p[i][j]; if ch<>'' then wr(ch) else begin if cf=15 then cf:=7 else cf:=15; end; end; if i<25 then begin curx:=1; cury:=cury+1 end; end; { repeat gotoxy(18,18); chlast:=readkey; if chlast<>#13 then ch:=chlast; write(ch); gotoxy(18,18); until chlast=#13; showpage:=upcase(ch); if ch=#13 then showpage:='Y'; } end; procedure w(s:string); var j:integer; ch:char; begin for j:=1 to length(s) do begin ch:=s[j]; if ch<>'' then wr(ch) else begin if c=15 then c:=7 else c:=15; end; end; end; function showpage_(pn:integer):char; procedure wr(s:string); var i:integer; begin if yo+cury>ym+1 then exit; for i:=1 to length(s) do begin if xo+curx>xm+1 then exit; mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2]:=ord(s[i]);
mem[$b800:(yo+cury-2)*160+(xo+curx-2)*2+1]:=cb*16+cf; curx:=curx+1; end; end; procedure wr0(ch:char); begin textcolor(c); write(ch); end; var i,j:integer; ch,chlast:char; p:tpage; begin case pn of 1:p:=page1; 2:P:=page2; end; cf:=7; clrscr; curx:=1; cury:=1; for i:=1 to 25 do begin wr(' '); for j:=1 to length(p[i]) do begin ch:=p[i][j]; if ch<>'' then wr(ch) else begin if cf=15 then cf:=7 else cf:=15; end; end; if i<25 then begin curx:=1; cury:=cury+1 end; end; { repeat gotoxy(18,18); chlast:=readkey; if chlast<>#13 then ch:=chlast; write(ch); gotoxy(18,18); until chlast=#13; showpage:=upcase(ch); if ch=#13 then showpage:='Y'; } end; function sshowpage_(pn:integer):char; procedure wrbad(ch:char); var i:integer; begin mem[$b800:(cury-1)*160+(curx-1)*2]:=ord(ch);
mem[$b800:(cury-1)*160+(curx-1)*2+1]:=cb*16+cf; end; var i,j:integer; ch:char; p:tpage; begin case pn of 1: p:=page1; 2: p:=page2; 3: p:=page3; 4: p:=page4; end; c:=7; clrscr; for i:=1 to 25 do begin write(' '); for j:=1 to length(p[i]) do begin ch:=p[i][j]; if ch<>'' then wr(ch) else begin if c=15 then c:=7 else c:=15; end; end; if i<25 then writeln; end; case pn of 1: begin gotoxy(18,18); ch:=readkey; if ch=#13 then sshowpage_:='1' else sshowpage_:=upcase(ch); end; 2: gotoxy(24,25); 3: begin repeat gotoxy(18,18); ch:=readkey; {gotoxy(18,18);} if not (ch in ['1'..'4']) then begin gotoxy(1,24); w(' Invalid entry, please enter 1-4.'); end else sshowpage_:=upcase(ch); until ch in ['1'..'4']; end; 4: begin gotoxy(69,19); ch:=readkey; if ch=#13 then sshowpage_:='Y' else sshowpage_:=upcase(ch); end; end; { readln(ch);} end; { writeln; c:=7; for i:=1 to 25 do begin for j:=1 to length(crtdoslog[i]) do begin ch:=crtdoslog[i][j]; if ch<>'' then wr(ch) else begin if c=15 then c:=7 else c:=15; end; end; if i<25 then writeln; end; } { test3.dat: DISKS=1 DRIVES=0 SIZE=4300 test5.dat: DISKS=2 DRIVES=3 SIZE=6400M C=2000M A D=2000M E=1500M DRIVES=1 SIZE=1040M C=500M A } procedure showpartition(d:integer); var dr,i,SizExt:integer; begin textcolor(7); ch:='B'; i:=1; delline(10); delline(11); gotoxy(1,10); if pricreated then begin wwrite(chr(ord(ch)+i)+':',5); wwrite('1',2); wwrite('A',9); wwrite('PRI DOS',11); wwrite(' ',15); wwrite(' '+ia(dsiz[d,1]),6); wwrite('FAT16',8); wwrite(ra(100.0*dsiz[d,1]/tsiz[d],9,0)+'%',9); SizExt:=0; end; if EXTcreated then begin gotoxy(1,11); wwrite(' ',5); wwrite('2',2); textcolor(12); { if active[dr]=ch then wwrite('A',9) else wwrite(' ',9);} textcolor(7); wwrite('EXT DOS',11); wwrite(' ',15); wwrite(' '+ia(dsiz[d,dr]),6); wwrite('FAT16',8); wwrite(ra(100.0*dsiz[d,dr]/tsiz[d],9,0)+'%',9); end; { if (drive[d]>0) then begin { wwrite(chr(ord(ch)+i)+':',5); wwrite('1',2); wwrite('A',9); wwrite('PRI DOS',11); wwrite(' ',15); wwrite(' '+ia(dsiz[d,1]),6); wwrite('FAT16',8); wwrite(ra(100.0*dsiz[d,1]/tsiz[d],9,0)+'%',9);} SizExt:=0; if drive[d]>1 then begin for dr:=2 to drive[d] do begin SizExt:=SizExt+Dsiz[d,dr]; end; end; { gotoxy(1,11); wwrite(' ',5); wwrite('2',2); textcolor(12); if active[dr]=ch then wwrite('A',9) else wwrite(' ',9); textcolor(7); wwrite('EXT DOS',11); wwrite(' ',15); wwrite(' '+ia(dsiz[d,dr]),6); wwrite('FAT16',8); wwrite(ra(100.0*dsiz[d,dr]/tsiz[d],9,0)+'%',9); end; } end; procedure getxy(x,y:integer); var ch,ch2:char; begin gotoxy(1,1); swrite(' '); textcolor(11); gotoxy(1,1); swrite(ia(x)+','+ia(y)); gotoxy(x,y); repeat if keypressed then begin ch:=readkey; if ch=#0 then begin ch2:=readkey2; if ch2='M' then x:=x+1; if ch2='K' then x:=x-1; if ch2='P' then y:=y+1; if ch2='H' then y:=y-1 end; textcolor(11); gotoxy(1,1); swrite(ia(x)+','+ia(y)); gotoxy(x,y); end; until ch=#27; end; procedure showlogicdrive(d:integer); var i,dr:integer; dbg:boolean; begin dbg:=false; delline(5); delline(6); delline(7); if dbg then begin writeln('Drv Volume Label Mbytes System Usage'); writeln('D: SOFTWARE 2047 FAT16 38%'); writeln('E: FTP 2047 FAT16 38%'); writeln('F: USER 1357 FAT16 25%'); writeln; end; i:=0; if d=1 then ch:='B' else ch:=chr(67+drive[1]); if drive[d]>0 {not original} then for dr:=2 to drive[d] do begin gotoxy(2,4+dr-1); i:=i+1; textcolor(7); wwrite(chr(ord(ch)+dr)+':',3); wwrite(' ',14); gotoxy(21,5); wwrite(ia(dsiz[d,dr]),5); gotoxy(27,5); if fat32 then wwrite('UNKNOWN',7) else wwrite('FAT16 ',7); gotoxy(38,5); wwrite(ra(100.0*dsiz[d,dr]/tsiz[d],3,0)+'%',3); end; getxy(40,10); end; procedure showpgfile(n:string); var i,j:integer; f:file; fnm:string; begin fnm:='SCREEN'+n+'.DAT'; assign(f,fnm); reset(f,1); for i:=0 to 24 do for j:=0 to 159 do blockread(f,mem[$b800:i*160+j],1);
close(f);
end;

{procedure GETCFG(n:string);
var i,j:integer;
f:file;  fnm:string;
begin
fnm:='PROBLEM'+n+'.DAT';
assign(f,fnm);
reset(f,1);
for i:=0 to 24 do
for j:=0 to 159 do
blockread(f,mem[$b800:i*160+j],1); close(f); end; } procedure SHOWPRMTS; var i,x,y:integer; begin clrscr; x:=20; y:=9; gotoxy(x+1,y+1); write('DISKs=',disks); for i:=1 to disks do begin write(' TSIZ[',i,']=',tsiz[i]); gotoxy(x,y+2); write(' PSIZ[',i,']=',psiz[i]); gotoxy(x,y+3); write(' ESIZ[',i,']=',esiz[i]); gotoxy(x,y+4); write(' DRV[',i,']=',drive[i]); gotoxy(1,y+5); for J:=1 to drive[i] do begin gotoxy(x+(j-1)*10,y+5); write(' D[',j,']=',dsiz[i,j]); end; gotoxy(x,y+6); write(' SREM[',i,']=',remainder[i]); end; end; procedure GETPRMTS(ns:string); var i,j,k,n,p1,p2:integer; f:text; s,s1,fnm:string; lastletter,letter:char; dbg:boolean; begin dbg:=true; fnm:='TEST'+ns+'.DAT'; assign(f,fnm); reset(f); readln(f,s); val(copy(s,length(s),1),disks,n); if dbg then writeln('disks=',disks); letter:='B'; for i:=1 to disks do begin readln(f,s); val(copy(s,length(s),1),drive[i],n); if dbg then writeln(' drives[',i,']=',drive[i]); readln(f,s); p1:=pos('=',s); p2:=pos('M',s); s1:=copy(s,p1+1,p2-p1-1); val(s1,tsiz[i],n); if dbg then writeln(' tsize[',i,']=',tsiz[i]); readln(f,s); p1:=pos('=',s); p2:=pos('M',s); s1:=copy(s,p1+1,p2-p1-1); val(s1,psiz[i],n); if dbg then writeln(' psize[',i,']=',psiz[i]); readln(f,s); p1:=pos('=',s); p2:=pos('M',s); s1:=copy(s,p1+1,p2-p1-1); val(s1,esiz[i],n); if dbg then writeln(' esize[',i,']=',esiz[i]); if drive[i]=0 then begin remainder[i]:=tsiz[i]; { clrscr; gotoxy(1,22); textcolor(15); swrite('No Partitions Defined.');} end else begin remainder[i]:=tsiz[i]; for J:=1 to drive[i] do begin readln(f,s); if s[length(s)]='A' then act:=1; p1:=pos('=',s); p2:=pos('M',s); val(copy(s,p1+1,p2-p1-1),dsiz[i,j],n); remainder[i]:=remainder[i]-dsiz[i,j]; case i of 1:begin letter:=chr(ord(letter)+1); if (disks=2) and (j=2) then letter:=chr(ord(letter)+1); if dbg then writeln( letter,' dsize[',i,',',j,']=',dsiz[i,j]); lastletter:=letter; end; 2:begin if j=1 then letter:='D' else if j=2 then letter:=chr(ord(lastletter)+1) else letter:=chr(ord(letter)+1); if dbg then writeln( letter,' dsize[',i,',',j,']=',dsiz[i,j]); end; end; { if i=1 then if dbg then writeln('ActiveDrive=',active[i]);} end; end; end; close(f); readkey; end; procedure wrxy(x,y:integer; S:string); begin moveto(x*8,y*20); outctextc2(11,11,0,s); end; procedure wrxyc(x,y,c,e:integer; S:string); begin moveto(x*8,y*20); outctextc2(c,e,0,s); end; procedure bar1(x1,x2,y,b,c:integer); var X:integer; ofs:word; begin for x:=x1 to x2 do begin ofs:=(y-1)*160+(x-1)*2; mem[$B800:ofs+1]:=
128 or (b shl 4 or c);
{mem[$B800:ofs+1] and$0f) or c;}
end
end;

var x0,x,y,i:integer; ch:char;
begin
s:='';
x:=curx;
x0:=curx;
gotoxy(curx,cury);
_write('_');
x:=curx;
x:=xo+curx-2;
Y:=yo+cury-1;
bar1(x,x,y,0,15);
repeat
if (ch=#8) then
begin
if (x>24+xo) then
begin
s:=copy(s,1,length(s)-1);
gotoxy(curx-1,cury);
_write(' ');
x:=xo+curx-2;
Y:=yo+cury-1;
gotoxy(curx-2,cury);
_write('_');
x:=xo+curx-2;
Y:=yo+cury-1;
bar1(x,x,y,0,15);
end
end
else
if (ch<>#13) and (ch in ['0'..'9','A'..'Z','a'..'z']) then
begin
s:=s+ch;
gotoxy(curx-1,cury);
_write(ch+'_');
x:=xo+curx-2;
Y:=yo+cury-1;
bar1(x,x,y,0,15);
end;
{ mem[$b800:(yo+cury-2)*160+2*(xo+curx-2)+1]:= mem[$b800:(yo+cury-2)*160+2*(xo+curx-2)+1] + 128;}
until ch=#13;
end;

type chset=set of char;
var chlast,c:char; x,y:integer;
begin
x:=wherex; y:=whereY;
repeat
gotoxy(x,y);
if chlast<>#13 then ch:=chlast;
if ch in s then
write(ch);
{  case ch of
#27:
begin
clrscr;
exit;
end;
'1'..'5':
begin
textcolor(15);
write(ch);
gotoxy(1,24);
textcolor(15);
write('                                           ');
end;
'6'..'9','0':
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  ',ch,' is not a choice. Please enter 1-5.');
end;
else
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  Invalid entry, please enter 1-5.      ');
end;
end;}
gotoxy(18,18);
until (chlast=#13) and (ch in s);
end;

procedure verify;
var i:integer; ch:char;
begin
{  clrscr;
showpgfile('1');}
gotoxy(2,21);
textcolor(7);
write('   Verify Drive Integrity,       completed.');
hidecursor;
for i:=1 to 20 do
begin
gotoxy(30,21);
textcolor(15);
wrcxy(30,21,15,ia(i)+'%');
delay(5);
end;
delline(21);
showcursor;
{   gotoxy(64,10);
ch:='Y';
end;

procedure verifyatline(n:integer);
var i:integer; ch:char;
begin
{  clrscr;
showpgfile('1');}
gotoxy(2,n);
textcolor(7);
write('   Verify Drive Integrity,       completed.');
hidecursor;
for i:=1 to 100 do
begin
gotoxy(30,n);
textcolor(15);
wrcxy(30,n,15,ia(i)+'%');
delay(10);
end;
delline(n);
showcursor;
{   gotoxy(64,10);
ch:='Y';
end;

function sigmadsiz:integer; {total size of from 'D' to current Drive}
var i,t:integer;
begin
t:=0;
for i:=2 to drive[disk] do
t:=t+dsiz[disk,i];
end;

procedure showdrives(disk:integer);
var i:integer; chtmp:char;
begin
for i:=5 to 10 do delline(i);
for i:=2 to drive[disk]-1 do
begin
delline(6+i);
gotoxy(3,6+i);
chtmp:=chr(65+i);
write(chtmp+':');  {ok}
gotoxy(21,6+i);
wwrite(ia(dsiz[disk,i]),5);
gotoxy(28,6+i);
if fat32 then
wwrite('UNKNOWN',7)
else
wwrite(' FAT16 ',7);
gotoxy(39,6+i);
swrite(ra(100.0*dsiz[disk,i]/tsiz[disk],2,0)+'%');
end;
end;

procedure savedata;
var disk,i:integer; fo:text; nm:string; d0,d:char;
begin
{ clrscr;
gotoxy(20,11);
write('File to Save [*.DAT] = ');
nm:='LOG.DAT';
assign(fo,nm);
rewrite(fo);
writeln(fo,'DISKS=',disks);
for disk:=1 to disks do
begin
writeln(fo,' DRIVES=',drive[disk]);
writeln(fo,'  TSIZE=',tsiz[disk],'M');
writeln(fo,'  PSIZE=',psiz[disk],'M');
writeln(fo,'  ESIZE=',esiz[disk],'M');
{   if disks=1 then d0:='B' else d0:=chr}
for i:=1 to drive[disk] do
begin
d:=chr(ord('B')+i);
if (i=1) and (act=1) then
writeln(fo,'  ',d,':=',ia(dsiz[disk,i])+'M A')
else
writeln(fo,'  ',d,':=',ia(dsiz[disk,i])+'M');
{ if fat32 then
write(fo,'UNKNOWN':15)
else
write(fo,' FAT16 ':5);}
end;
end;
close(fo);
end;

procedure message;
begin
exit;
gotoxy(1,24); write('Esiz[disk]=',esiz[disk],'  rest=',remainder[disk]);
end;

var buf:array[0..5,0..159] of byte;

procedure movetobuf(fr,t:integer);
var i,j,k:integer;
begin
for i:=fr to t do
begin
for j:=0 to 159 do
begin
buf[i-fr,j]:=mem[$b800:(i-1)*160+j]; end; delline(i); end; end; procedure movetoscr(fr,count:integer); var i,j:integer; begin for i:=0 to count-1 do for j:=0 to 159 do mem[$b800:(i+fr-1)*160+j]:=buf[i,j];
end;

procedure getesc;
var ch:char;
begin
repeat
until ch=#27;
end;

procedure rect3d(x1,y1,x2,y2:integer);
begin
setcolor(8);
rectangle(x1,y1,x2,y2);
setcolor(15);
line(x1,y2,x2,y2);
line(x2,y1,x2,y2);
end;

{********************************MAIN*********************************}
var total,sz,extsize:real;
size:array['C'..'Z'] of real;
percent:array['C'..'Z'] of integer;
md,chlast,ch1,ch2,ch3,ch34,chtmp:char;
fi:text; x,y,gd,gm:integer;
s,sss:string;
type disktype=record
drive:char;
mbytes:integer;
system:string;
usage:integer;
end;

var

dellogt:array [1..2] of integer;
logt:array [1..2] of integer;
dellog:array[1..4] of char;
log:array[1..4] of char;
dl:char;lf:char;ll:char;dd:integer;
logdisk:array[1..2,1..4] of disktype;
extdisk:array[1..2] of disktype;
pridisk:array[1..2] of disktype;
j1,j2:integer;
lab:string;
snmb:string;

label loop,loop2,loopdl,loopdp,last;

begin
gd:=detect;
initgraph(gd,gm,'');

x:=26; y:=8;
setfillstyle(1,1);
bar(0,0,639,479);
setfillstyle(1,8);
bar(110,110,550,389);
setfillstyle(1,7);

bar(100,100,540,379);
rect3d(110,110,530,369);
setcolor(1);
moveto(x*8,y*20-30);
outctextc2(0,0,0,'        请选择硬盘类型');
wrxyc(x,y+0,0,0,' 0 ---- 与本机容量相同的空盘 ');
wrxyc(x,y+1,0,0,' 1 ---- 420M, 已作过分区的盘');
wrxyc(x,y+2,0,0,' 2 ---- 4.3G, 未作分区的空盘');
wrxyc(x,y+3,0,0,' 3 ---- 6.4G, 已作过分区的盘');
wrxyc(x,y+4,0,0,' 4 ---- 13.0G,未作分区的空盘');
wrxyc(x,y+5,0,0,' 5 ---- 双硬盘，均已作过分区 ');
wrxyc(x,y+6,0,0,' Esc -- 退出FDISK仿真程序。');
setfillstyle(1,7);
bar(400-24,358,470-24,375);
wrxy(x-3,y+10,'请先输入学号（考试证号）');
setcolor(0);
moveto(400-25+5,358+6);
getstr(snmb);

setfillstyle(1,1);
bar(100,358,547,375);
setfillstyle(1,7);
bar(400-14,358,470-24,375);
wrxy(x-3,y+10,'请选择硬盘假设类型[0..5]');
setcolor(0);
moveto(400-25+15,358+6);
getstr(lab);

{ repeat
until ch in ['1'..'5',#27];}
ch:=lab[1];
closegraph;
case ch of
#27:begin
clrscr;
halt;
end;
'0':begin

end;
else
begin
getprmts(ch);
end;
end;
{ act:=0;}
{showprmts;
initialize;
disk:=1;
fat32:=false;
{  closegraph;
clrscr;
GETCFG('1');
assign(fi,'PROBLEM'+ch+'.DAT');
reset(fi);
if ioresult<>0 then
begin
gotoxy(10,12);
halt;
end;
if upcase(s[1])='O' then original:=true else original:=false;
if not original then
begin
maxdrive:=chr(ord('C')+drives-1);
for i:=1 to drives do
begin
end;
end;
close(fi);
clrscr;
}

{
for i:=1 to disks do
begin
showpartition(i);
writeln;
showlogicdrive(i);
end;
}
{get real disk parametters:
i:=2;
total:=0;
extsize:=0;
repeat
i:=i+1;
sz:=disksize(i);
size[chr(64+i)]:=sz;
total:=total+sz;
if i>3 then extsize:=extsize+sz;
if sz>0 then writeln(chr(64+i),' ',sz/1024/1024:0:0);
until sz<0;
writeln('total=',round(total/1024/1024));
i:=i-1;
md:=chr(64+i);
writeln('SIZE:');
for ch:='C' to md do
begin
percent[ch]:=round(1.0*size[ch]/total*100);
writeln(ch,':',percent[ch],'%');
end;
writeln('PRISIZE=',size['C']/1024/1024:0:0);
writeln('EXTSIZE=',extsize/1024/1024
:0:0);
showpage4;}

{0}

if tsiz[1]>512 then {show INPORTANT notation}
begin
for i:=1 to 5 do writeln;
c:=7;
for i:=1 to 14 do
begin
write('  ');
for j:=1 to length(page[i]) do
begin
ch:=page[i][j];
if ch<>'' then wr(ch)
else
begin
if c=15 then c:=7
else c:=15;
end;
end;
writeln;
end;
for i:=1 to 5 do writeln;
{hidecursor;
cb:=0;
sss:=''; }
gotoxy(63,19);
end;

{1}
loop:
ch:='1';
REPEAT
showpage(0,page0);
gotoxy(29,7);
textcolor(7);
swrite(ia(disk));
if disks=1 then
delline(15);
repeat
repeat
gotoxy(18,18);
if chlast<>#13 then ch:=chlast;
case ch of
#27:
begin
clrscr;
savedata;
textcolor(7);
gotoxy(1,1);
getdir(0,s);
swrite(s+'>');
exit;
end;
'1'..'5':
begin
textcolor(15);
write(ch);
gotoxy(1,24);
textcolor(15);
write('                                           ');
end;
'6'..'9','0':
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  ',ch,' is not a choice. Please enter 1-5.');
end;
else
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  Invalid entry, please enter 1-5.      ');
end;
end;
gotoxy(18,18);
until (chlast=#13) and (ch in ['1'..'5']);
{  gotoxy(20,18);
case ch of
'1':
{Create DOS Partition ----------------------------------------}
begin
ch1:='1';
showpage(1,page1);
gotoxy(29,7);
textcolor(11);
swrite(ia(disk));
repeat
gotoxy(18,18);
if chlast<>#13 then ch1:=chlast;
case ch1 of
#27:goto loop;
'1'..'3':
begin
textcolor(15);
write(ch1);
gotoxy(1,24);
textcolor(15);
write('                                           ');
end;
'4'..'9','0':
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  ',ch1,' is not a choice. Please enter 1-5.');
end;
else
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  Invalid entry, please enter 1-5.      ');
end;
end;
gotoxy(18,18);
until (chlast=#13) and (ch1 in ['1'..'3']);
case ch1 of
'1':  {create pri partition}
if PRIcreated then
begin
showpgfile('29');
gotoxy(47,10);
swrite(' '+ia(dsiz[disk,1]));
gotoxy(64,10);
swrite(ra(100.0*dsiz[disk,1]/tsiz[disk],5,0));
gotoxy(27,25);
getesc;
goto loop;
end
else
begin
if act=1 then
begin
showpage(11,page11);
gotoxy(29,7);
textcolor(11);
swrite(ia(disk));
showpartition(disk);
end
else
begin
clrscr;
showpgfile('1');
delline(9);
delline(10);
gotoxy(2,21);
textcolor(7);
write('   Verify Drive Integrity,       completed.');
hidecursor;
for i:=1 to 20 do
begin
gotoxy(30,21);
textcolor(15);
wrcxy(30,21,15,ia(i)+'%');
delay(10);
end;
delline(21);
showpgfile('1');
showcursor;
gotoxy(64,10);
ch:='Y';
if upcase(ch)='Y' then
begin       {Full size for PRI DOS Partition}
verify;
clrscr;
showpgfile('3');             {}
gotoxy(18,10); swrite(' ');
gotoxy(47,10); wwrite(ia(tsiz[disk]),5);
gotoxy(65,10); wwrite('100%',5);
gotoxy(26,25);
{modify:}
getesc;
showpgfile('20');
gotoxy(28,25);
repeat
until ch=#27;
savedata;
clrscr;
halt;
end
else     {to specify the size for PRI DOS partition}
begin
showpgfile('2');
for i:=15 to 15 do delline(i);
textcolor(15);
gotoxy(46,16);
swrite(' '+ia(tsiz[disk]));
for i:=16 to 20 do
delline(i);
verify;
showpgfile('2');
textcolor(15);
gotoxy(25,15);
swrite(' '+ia(tsiz[disk]));
textcolor(15);
gotoxy(46,16);
swrite(' '+ia(tsiz[disk]));
J:=remainder[disk];
getint(72,20,5,j);
dsiz[disk,1]:=j;
psiz[disk]:=j;
remainder[disk]:=tsiz[disk]-j;
PRIcreated:=true;
showpgfile('3'); {show 'PRI DOS created'}
gotoxy(47,10);
swrite(' '+ia(dsiz[disk,1]));
gotoxy(64,10);
swrite(ra(100.0*dsiz[disk,1]/tsiz[disk],5,0));
gotoxy(27,25);
getesc;
end;
goto loop;
end;
repeat
until ch34=#27;
goto loop;
end;
'2':   {to create EXT DOS partition:}
if not PRIcreated then
begin
showpgfile('21');
gotoxy(26,25);
getesc;
goto loop;
end
else
begin
showpgfile('23');
gotoxy(47,10);
swrite(' '+ia(dsiz[disk,1]));
gotoxy(66,10);
j:=remainder[disk];
swrite(' '+ra(1.0*dsiz[disk,1]*100/tsiz[disk],0,0));
delline(15);
delline(16);
delline(19);
delline(20);
gotoxy(2,21);
textcolor(7);
write('   Verify Drive Integrity,       completed.');
hidecursor;
for i:=1 to 10 do
begin
gotoxy(30,21);
textcolor(15);
wrcxy(30,21,15,ia(i)+'%');
delay(10);
end;
{re-display:}
showpgfile('23');
gotoxy(47,10);
swrite(' '+ia(dsiz[disk,1]));
gotoxy(66,10);
j:=remainder[disk];
swrite(' '+ra(1.0*dsiz[disk,1]*100/tsiz[disk],0,0));
gotoxy(25,15);
swrite(' '+ia(tsiz[disk]));
gotoxy(46,16);
swrite(' '+ia(remainder[disk]));
gotoxy(70,20);
swrite(' '+ia(remainder[disk]));
gotoxy(60,16);
swrite(' '+ra(100.0*(remainder[disk]/tsiz[disk]),0,0));
j:=remainder[disk];

getint(71,20,5,j);
Esiz[disk]:=j;
EXTcreated:=true;
remainder[disk]:=j;
showpgfile('7'); {show 'EXT DOS Created'}
gotoxy(47,10);
swrite(' '+ia(psiz[disk]));
gotoxy(66,10);
swrite(' '+ra(1.0*psiz[disk]*100/tsiz[disk],0,0));
gotoxy(47,11);
swrite(' '+ia(esiz[disk]));
gotoxy(66,11);
swrite(' '+ra(1.0*esiz[disk]*100/tsiz[disk],0,0));
gotoxy(19,10); swrite(' ');
gotoxy(26,25);
drive[disk]:=1;
getesc;
goto loop2;
end;
'3':                           {Create Logical dirves}
if not EXTcreated then
begin                      {show EXT DOS not create}
showpgfile('24');
gotoxy(26,25);
getesc;
goto loop;
end
else
begin
loop2:
begin
showpage(13,page13);   {all available EXT .. to logi..}
showdrives(disk);
goto loop;
end
else
repeat
if dsiz[disk,2]=0 then
begin
showpgfile('8');         {for create 1st logdrive}
gotoxy(42,18);
wwrite(ia(esiz[disk]),5);
gotoxy(50,19);
wwrite(ia(remainder[disk]),5);
gotoxy(64,19);
wwrite(ra(100.0*remainder[disk]/esiz[disk],2,0)+'%',4);
gotoxy(72,21);
wwrite(ia(remainder[disk]),5);
{message;}
{J:=remainder[disk];
gotoxy(72,21); swrite('   ');
getint(73,21,5,j);
drive[disk]:=drive[disk]+1;
dsiz[disk,drive[disk]]:=j;
remainder[disk]:=remainder[disk]-j;
end
else
begin
showpgfile('9');         {create other logdrive, or'1'}
for i:=5 to 8 do
delline(i);
{gotoxy(1,2);
swrite(title2);
gotoxy(1,3);
swrite(examp2); }
for i:=2 to drive[disk] do
begin
gotoxy(2,3+i);
ch3:=chr(66+i);
write(ch3,':',' ':15,dsiz[disk,i]:5);
write('FAT16':8);
write(ra(100.0*dsiz[disk,i]/esiz[disk],2,0)+'%':7);
end;
movetobuf(18,21);
verifyatline(22);
movetoscr(18,4);
gotoxy(42,18);
wwrite(ia(esiz[disk]),5);
gotoxy(50,19);
wwrite(ia(remainder[disk]),5);
gotoxy(65,19);
wwrite(ra(100.0*remainder[disk]/esiz[disk],2,0)+'%',4);
gotoxy(72,21);
wwrite(ia(remainder[disk]),5);
end;
J:=remainder[disk];
gotoxy(72,21); swrite('   ');
getint(73,21,5,j);
drive[disk]:=drive[disk]+1;
dsiz[disk,drive[disk]]:=j;
remainder[disk]:=remainder[disk]-j;
if remainder[disk]=0 then
begin
gotoxy(3,24);
showpgfile('10');
for i:=2 to drive[disk] do
begin
gotoxy(1,3+i);
ch3:=chr(66+i);
write(ch3,':',' ':16,dsiz[disk,i]:5);
write('FAT16':8);
write(ra(100.0*dsiz[disk,i]/esiz[disk],2,0)+'%':8);
end;
getesc;
end;
until (remainder[disk]=0) {or (ch=#27)};
{show all EXT size assigned to logdrv?}
{ gotoxy(29,7);
textcolor(11);
swrite(ia(disk));
{showlogicdrive(disk);}
{showpartition(1);}
{ repeat
until ch34=#27;}
goto loop;
end;
end;
end;

'2': {Set active partition ------------------------------------------- }
begin
{ disk:=1;}
pridisk[disk].system:='UNKNOWN';
extdisk[disk].system:='UNKNOWN';
if psiz[disk]>0  then
begin
pridisk[disk].drive:='X';
pridisk[disk].mbytes:=psiz[disk];
pridisk[disk].usage:=round(100.0*psiz[disk]/tsiz[disk]);
end
else pridisk[disk].drive:='$'; if esiz[disk]>0 then begin extdisk[disk].drive:='X'; extdisk[disk].mbytes:=esiz[disk]; extdisk[disk].usage:=round(100.0*esiz[disk]/tsiz[disk]); end else extdisk[disk].drive:='$';
logt[disk]:=drive[disk]-1;
for i:=1 to logt[disk] do
with logdisk[disk][i] do
begin
drive:=chr(67+i);
mbytes:=dsiz[disk,i+1];
usage:=round(100.0*dsiz[disk,i+1]/esiz[disk]);
end;
logdisk[disk][i+1].drive:='$'; dellogt[disk]:=0; if act=1 then active:='A' else active:=' '; {--------------------------} if pridisk[disk].drive='$' then
begin
showpgfile('30');
repeat
until ch34=#27;
goto loop;
end
else
begin
if act=1 then
begin
showpage_(2);
gotoxy(1,10);
with pridisk[disk] do
write('   C: 1        A    PRI DOS                ',mbytes:5,'  ',system,'      ',usage:2,'%');
if extdisk[disk].drive='X' then
begin
gotoxy(1,11);
with extdisk[disk] do
write('      2             EXT DOS                ',mbytes:5,'  ',system,'      ',usage:2,'%');
end
else
begin
gotoxy(1,11);
with extdisk[disk] do
write('                                                                      ');
end;
repeat
until ch34=#27;
goto loop;
end
else   {act=1}
begin
showpgfile('4');
gotoxy(76,17);
write(' ');
repeat
begin
gotoxy(76,17);
if chlast<>#13 then ch1:=upcase(chlast);
case ch1 of
#27:goto loop;
'1':
begin
gotoxy(1,24);
write('                                           ');
gotoxy(76,17);
write(ch1);
end;
'2'..'9','0':
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('      ',ch1,' is not a choice. Please enter 1-1.');
end;
else
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('      Invalid entry, please enter 1-1.      ');
gotoxy(54,18);
end;
end; {case  ch1}
end;
until (chlast=#13) and (ch1 in ['1']);
case ch1 of
'1':begin
act:=1;
active:='A';
{ show('5'); }
textcolor(7);
gotoxy(19,10);
write('A');
gotoxy(1,17);
write('                                                                                 ');
textcolor(15);
gotoxy(1,22);
gotoxy(1,25);
write('    Press Esc to continue                    ');
repeat
until ch34=#27;
goto loop;
end;
end;
end;
end;
end;

'3': {Delete Partition -----------------------------------------------}
begin
{+++++++++++++++++++++}
{  disk:=1;}
pridisk[disk].system:='UNKNOWN';
extdisk[disk].system:='UNKNOWN';
if psiz[disk]>0  then
begin
pridisk[disk].drive:='X';
pridisk[disk].mbytes:=psiz[disk];
pridisk[disk].usage:=round(100.0*psiz[disk]/tsiz[disk]);
end
else pridisk[disk].drive:='$'; if esiz[disk]>0 then begin extdisk[disk].drive:='X'; extdisk[disk].mbytes:=esiz[disk]; extdisk[disk].usage:=round(100.0*esiz[disk]/tsiz[disk]); end else extdisk[disk].drive:='$';
logt[disk]:=drive[disk]-1;
for i:=1 to logt[disk] do
with logdisk[disk][i] do
begin
drive:=chr(67+i);
mbytes:=dsiz[disk,i+1];
usage:=round(100.0*dsiz[disk,i+1]/esiz[disk]);
end;
logdisk[disk][i+1].drive:='$'; dellogt[disk]:=0; if act=1 then active:='A' else active:=' '; {--------------------------} if pridisk[disk].drive='$' then
begin
showpgfile('22');
repeat
until ch34=#27;
goto last;
end
else
begin
showpage(3,page3);
repeat
gotoxy(18,18);
if chlast<>#13 then ch3:=chlast;
case ch3 of
#27:
begin
goto last;
end;
'1'..'4':
begin
textcolor(15);
write(ch3);
gotoxy(1,24);
textcolor(15);
write('                                           ');
end;
'5'..'9','0':
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  ',ch3,' is not a choice. Please enter 1-4.');
end;
else
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  Invalid entry, please enter 1-4.      ');
end;
end;
gotoxy(18,18);
until (chlast=#13) and (ch3 in ['1'..'4']);

case ch3 of
'1':
begin
ch1:='N';
if extdisk[disk].drive='X' then
begin
showpage(31,page31);
gotoxy(1,10);
with pridisk[disk] do
write('   C: 1        ',active,'    PRI DOS                ',mbytes:5,'  ',system,'      ',usage:2,'%');
gotoxy(1,11);
with extdisk[disk] do
write('      2             EXT DOS                ',mbytes:5,'  ',system,'      ',usage:2,'%');
textcolor(15);
gotoxy(23,15);
write(tsiz[disk]:5);

repeat
until ch34=#27;
goto last;
end
else     {extdisk.drive='X'}
begin
showpgfile('18');
gotoxy(1,10);
with pridisk[disk] do
write('      C: 1        ',active,'    PRI DOS                ',mbytes:5,'  ',system,'      ',usage:2,'%');
textcolor(15);
gotoxy(25,15);
write(tsiz[disk]:5);

ch1:='1';
repeat
begin
gotoxy(54,21);
if chlast<>#13 then ch1:=upcase(chlast);
case ch1 of
#27:goto last;
'1':
begin
gotoxy(1,24);
write('                                           ');
gotoxy(54,21);
write(ch1);
end;
'2'..'9','0':
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('    ',ch1,' is not a choice. Please enter 1-1.');
end;
else
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('    Invalid entry, please enter 1-1.      ');
gotoxy(54,18);
end;
end; {case  ch1}
end;
until (chlast=#13) and (ch1 in ['1']);
case ch1 of
'1':begin
gotoxy(1,22);
write('    Enter Volume Label..............................?');
textcolor(15);
gotoxy(55,22);
write('[           ]');
gotoxy(56,22);

i:=0;
repeat
if i<12 then
case ch34 of
#27:goto last;
'0'..'9','A'..'Z':
if i<11 then
begin
i:=i+1;
gotoxy(55+i,22);
write(ch34);
lab[i]:=ch34;
gotoxy(56+i,22);
end;
#8:
if i>0 then
begin
i:=i-1;
gotoxy(56+i,22);
write(' ');
gotoxy(56+i,22);
end;
end;       {case ch34}
until ch34=#13;
if i<>0 then
begin
gotoxy(1,23);
write('    Volume label does not match.');
gotoxy(1,25);
write('    Press Esc to continue                ');
repeat
until ch34=#27;
goto last;
end
else
begin
gotoxy(1,23);
write('    Are you sure (Y/N)..............................?');
textcolor(15);
gotoxy(55,23);
write('[N]');
end;
ch1:='N';
repeat
gotoxy(56,23);
if chlast<>#13 then ch1:=upcase(chlast);
case ch1 of
#27:goto last;
'Y','N':
begin
gotoxy(1,24);
write('                                           ');
gotoxy(56,23);
write(ch1);
end;
else
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('    Invalid entry, please enter Y-N.      ');
gotoxy(54,23);
end;
end; {ch1}
until (chlast=#13) and (ch1 in ['Y','N']);
case ch1 of
'N': begin
gotoxy(1,22);
write('                                                                   ');
gotoxy(1,23);
write('                                                                   ');
gotoxy(65,21);
write(' ');
goto last;
end;
'Y': begin
pridisk[disk].drive:='$'; act:=0;active:=' '; showpgfile('19'); textcolor(15); gotoxy(25,15); write(tsiz[disk]:5); repeat ch34:=readkey; until ch34=#27; goto last; end; end; {ch1} end; end; end; end; '2': begin ch1:='N'; if extdisk[disk].drive='$' then
begin
gotoxy(1,22);
textcolor(15);
write('  No Extended DOS Partition to delete.');
gotoxy(1,18);
write('                                         ');
repeat
until ch34=#27;
goto last;
end
else  {extdisk.drive='$'} begin if logt[disk]<>0 then begin {!!!!!!!} showpage(32,page32); gotoxy(1,10); with pridisk[disk] do write(' C: 1 ',active,' PRI DOS ',mbytes:5,' ',system,' ',usage:2,'%'); gotoxy(1,11); with extdisk[disk] do write(' 2 EXT DOS ',mbytes:5,' ',system,' ',usage:2,'%'); textcolor(15); gotoxy(23,15); write(tsiz[disk]:5); repeat ch34:=readkey; until ch34=#27; goto last; end else {log=0} begin showpgfile('15'); gotoxy(1,10); with pridisk[disk] do write(' C: 1 ',active,' PRI DOS ',mbytes:5,' ',system,' ',usage:2,'%'); gotoxy(1,11); with extdisk[disk] do write(' 2 EXT DOS ',mbytes:5,' ',system,' ',usage:2,'%'); textcolor(15); gotoxy(25,15); write(tsiz[disk]:5); repeat begin gotoxy(54,18); chlast:=readkey; if chlast<>#13 then ch1:=upcase(chlast); case ch1 of #27:goto last; 'Y','N': begin gotoxy(1,24); write(' '); gotoxy(54,18); write(ch1); end; else begin write(' '); gotoxy(1,24); textcolor(15); write(' Invalid entry, please enter Y-N. '); gotoxy(54,18); end; end; {case ch1} end; until (chlast=#13) and (ch1 in ['Y','N']); case ch1 of 'Y':begin extdisk[disk].drive:='$';
showpgfile('17');
gotoxy(1,10);
with pridisk[disk] do
write('      C: 1        ',active,'    PRI DOS                ',mbytes:5,'  ',system,'      ',usage:2,'%');
gotoxy(25,15);
write(tsiz[disk]:5);
repeat
until ch34=#27;
goto last;
end;
'N':begin
goto last;
end;
end;
end;    {else log<>0}
end;     {else extdisk.drive='$'} end; '3': begin if logt[disk]=0 then begin gotoxy(1,18); write(' '); gotoxy(1,23); textcolor(15); write(' No Logical DOS Drive(s) to delete.'); repeat ch34:=readkey; until ch34=#27; goto last; end; ch1:='$';
dellogt[disk]:=0;
lf:=logdisk[disk][1].drive;
ll:=logdisk[disk][logt[disk]].drive;
showpage(33,page33);
for i:=1 to logt[disk] do
begin
gotoxy(1,4+i);
with logdisk[disk][i] do
write('  ',drive,':                 ',mbytes,'             ',usage,'%');
end;
textcolor(15);
gotoxy(40,18);
write(esiz[disk]:5);
loopdl:  ch1:='1';
repeat
gotoxy(65,21);
if chlast<>#13 then ch1:=upcase(chlast);
if (ord(ch1)>=ord(lf)) and (ord(ch1)<=ord(ll)) then
begin
textcolor(15);
write(upcase(ch1));
dellog[dellogt[disk]+1]:=ch1;
dl:=ch1;
gotoxy(1,23);
write('                                        ');
gotoxy(1,24);
textcolor(15);
write('                                     ');
end
else
case ch1 of
#27: begin
if dellogt[disk]=0 then goto last
else
begin
begin
j1:=0;j2:=1;
for i:=1 to logt[disk]+dellogt[disk] do
begin
if logdisk[disk][i].drive<>'$' then begin j1:=j1+1; j2:=j2+1; end else {logdisk[i].drive<>'$'}
begin
j2:=j2+1;
if logdisk[disk][j2].drive<>'$' then begin with logdisk[disk][j1+1] do begin drive:=chr(68+j1); mbytes:=logdisk[disk][j2].mbytes; usage:=logdisk[disk][j2].usage; end; logdisk[disk][j2].drive:='$';
j1:=j1+1;
end;     { logdisk[j2].drive<>'$' } end; {for} end; for i:=1 to logt[disk] do begin gotoxy(1,4+i); with logdisk[disk][i] do write(' ',drive,': ',mbytes,' ',usage,'%'); end; for i:=logt[disk]+1 to 8 do begin gotoxy(1,4+i); write(' '); end; gotoxy(1,5+i); write(' '); gotoxy(1,18); write(' '); gotoxy(1,19); write(' Drive letters have been changed or deleted'); gotoxy(1,20); write(' '); gotoxy(1,21); write(' '); gotoxy(1,24); write(' '); gotoxy(1,25); write(' Press Esc to continue '); end; end; repeat ch1:=readkey; until ch1=#27; goto last; end; {#27} 'A'..'Z','a'..'z': begin write(' '); gotoxy(1,23); write(' '); gotoxy(1,24); textcolor(15); write(' ',upcase(ch1),' is not a choice. Please enter ',lf,'-',ll); end; else begin textcolor(15); write(' '); gotoxy(1,23); write(' '); gotoxy(1,24); textcolor(15); write(' Invalid entry, please enter ',lf,'-',ll,' '); end; end; until (chlast=#13) and (ord(upcase(ch1))>=ord(lf)) and (ord(upcase(ch1))<=ord(ll)); dd:=1; for i:=1 to dellogt[disk] do if dl=dellog[i] then dd:=0; if dd=0 then begin gotoxy(65,21); write(' '); gotoxy(1,23); write(' Drive ',dl,': already deleted. '); goto loopdl; end; gotoxy(1,22); write(' Enter Volume Label..............................?'); textcolor(15); gotoxy(53,22); write('[ ]'); gotoxy(54,22); i:=0; repeat ch34:=upcase(readkey); if i<12 then case ch34 of #27:goto last; '0'..'9','A'..'Z': if i<11 then begin i:=i+1; gotoxy(53+i,22); write(ch34); lab[i]:=ch34; gotoxy(54+i,22); end; #8: if i>0 then begin i:=i-1; gotoxy(54+i,22); write(' '); gotoxy(54+i,22); end; end; {case ch34} until ch34=#13; if i<>0 then begin gotoxy(1,22); write(' '); gotoxy(1,23); write(' Volume label does not match.'); gotoxy(65,21); write(' '); gotoxy(65,21); goto loopdl; end else begin gotoxy(1,23); write(' Are you sure (Y/N)..............................?'); textcolor(15); gotoxy(53,23); write('[N]'); end; ch1:='N'; repeat gotoxy(54,23); chlast:=readkey; if chlast<>#13 then ch1:=upcase(chlast); case ch1 of #27:goto last; 'Y','N': begin gotoxy(1,24); write(' '); gotoxy(54,23); write(ch1); end; else begin write(' '); gotoxy(1,24); textcolor(15); write(' Invalid entry, please enter Y-N. '); gotoxy(54,23); end; end; {ch1} until (chlast=#13) and (ch1 in ['Y','N']); case ch1 of 'N': begin gotoxy(1,22); write(' '); gotoxy(1,23); write(' '); gotoxy(65,21); write(' '); goto loopdl; end; 'Y': begin dellogt[disk]:=dellogt[disk]+1; logt[disk]:=logt[disk]-1; logdisk[disk][ord(dl)-67].drive:='$';
gotoxy(1,5+ord(dl)-ord(lf));
write('  '+dl+':  Drive deleted                             ');
gotoxy(1,22);
write('                                                                   ');
gotoxy(1,23);
write('                                                                   ');
if logt[disk]=0 then
begin
for i:=18 to 23 do
begin
gotoxy(1,i);
write('                                                                               ');
end;
write('  All logical drives deleted in the Extended DOS Partition.                      ');
gotoxy(1,24);
write('                                                                               ');
repeat
until ch34=#27;
showpgfile('14');
repeat
until ch34=#27;
goto last;
end;
gotoxy(65,21);
write(' ');
dellog[dellogt[disk]]:=dl;
goto loopdl;
end;

end; {ch1}
end;            {---------------------}

'4':{if nondosexist then}
begin
gotoxy(1,18);
write('                              ');
gotoxy(1,23);
textcolor(15);
write('  No Non-DOS Partition to delete.');
gotoxy(1,25);
textcolor(7);
write('  Press     to continue                ');
gotoxy(9,25);
textcolor(15);
write('Esc');
gotoxy(24,25);
repeat
until ch34=#27;
goto last;
end;
end;
end;
end;

'4':  {Display Partition --------------------------------------------- }
for disk:=1 to disks do
begin
if (drive[disk]>0) then
begin
showpage(4,page4);
gotoxy(1,10);
write('   C: 1        A    PRI DOS                 1020   FAT16       16%');
gotoxy(1,11);
write('      2             EXT DOS                 1020   FAT16       16%');
gotoxy(23,15);
wwrite(ia(tsiz[disk]),5);
gotoxy(44,10);
swrite(' '+ia(psiz[disk]));
gotoxy(63,10);
swrite(' '+ra(1.0*psiz[disk]*100/tsiz[disk],0,0));
gotoxy(44,11);
swrite(' '+ia(esiz[disk]));
gotoxy(63,11);
swrite(' '+ra(1.0*esiz[disk]*100/tsiz[disk],0,0));
gotoxy(19,10); swrite(' ');
gotoxy(26,25);
{  drive[disk]:=1;}

gotoxy(29,7);
textcolor(11);
swrite(ia(disk));
end;
{  showdrives(disk);

{  if drive[disk]>0 then
showpartition(disk);}
ch1:='Y';
repeat
gotoxy(69,19);
if chlast<>#13 then ch1:=upcase(chlast);
case ch1 of
#27:goto loop;
'Y','N':
begin
gotoxy(1,24);
write('                                           ');
gotoxy(69,19);
write(ch1);
end;
else
begin
write(' ');
gotoxy(1,24);
textcolor(15);
write('  Invalid entry, please enter Y-N.      ');
gotoxy(70,19);
end;
end; {ch1}
until (chlast=#13) and (ch1 in ['Y','N']);
case ch1 of
'N': goto loop;
'Y': begin
showpage(41,page41);
gotoxy(29,7);
textcolor(11);
swrite(ia(disk));
showlogicdrive(disk);
repeat
gotoxy(24,25);
until ch34=#27;
goto loop;
end;
end; {ch1}
end; {case '4'}
'5':if disks>1 then
begin {change DISK ----------------------------------------------}
showpgfile('0');
gotoxy(64,22);
ch:='1';
disk:=ord(ch)-48;
goto loop;
end;
#27:
begin
savedata;
clrscr;
gotoxy(1,1);
getdir(0,s);
writeln(s,'>');
halt;
end;
end; {ch}
{  if cmd=#27 then
begin
savedata;
clrscr;
gotoxy(1,1);
getdir(0,s);
writeln(s,'>');
halt;
end; }
until false; {(cmd in ['1'..'5',#27]);}
clrscr;
until cmd=#27;
write('>');
last:
for i:=1 to disks do
begin
if pridisk[i].drive='$' then begin psiz[i]:=0; drive[i]:=0; pricreated:=false; remainder[i]:=tsiz[i]; end else if extdisk[i].drive='$' then
begin
esiz[i]:=0; drive[i]:=1;
extcreated:=false; remainder[i]:=tsiz[i]-psiz[i];
end
else
begin
drive[i]:=logt[i]+1;
remainder[i]:=esiz[i];
for j:=2 to drive[i] do
begin
dsiz[i,j]:=logdisk[i,j].mbytes;
remainder[i]:=remainder[i]-dsiz[i,j];
end;
end;
end;
goto loop;
end.