{@@@@@@@@@@@ copyright (C) 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@@@@
The purchaser of these procedures and functions may include them in COMPILED
programs freely, but may not sell or give away the source text.

    This is a handy application that internally resets the switches
    that tell your PC how many diskette drives it has.  Certain RAM
    DISK programs require switch settings to be set to the number
    of physical drives PLUS the number of RAM disks you will want.
    Others require that the switches show ONLY the physical drives.
    NUMDISKS lets you keep your switches set for the physical drives
    and reset them WITHOUT opening the PC box if need be.

    NUMDISKS works ONLY in COMPILED form.  There may be a problem if
    it is activated any time except immediately after a system reset.

    You can enter "NUMDISKS <number>", where <number> is 1..4.  If you
    want to skip the "press a key to reboot", add an N (or n) to your
    parameter line (e.g., NUMDISKS 3n)
}
{$I regpack.typ}
{$I equipmnt.lib}
{$I reboot.lib}
{$I parametr.lib}
var
  Equip_word : integer absolute $0040:$0010;
  StrNumber  : string[3];
  OldNumber, NewNumber, error  : integer;
  Mask, BitChanges : integer;
  Wait             : boolean;
begin
  StrNumber := GetParameters;
  Wait      := true;
  OldNumber := equipment('D');
  GotoXY(1,5);
  WriteLn('Switches currently set for ',OldNumber,' disk drives.');
  if pos('N',StrNumber) <> 0 then
    begin
      delete(StrNumber,pos('N',StrNumber),1);
      Wait := false;
    end;
  if pos('n',StrNumber) <> 0 then
    begin
      delete(StrNumber,pos('n',StrNumber),1);
      Wait := false;
    end;
  while pos(' ',StrNumber) <> 0 do
    delete(StrNumber,pos(' ',StrNumber),1);
  val(StrNumber, NewNumber, error);
  if error <> 0 then NewNumber := 5;
  if not (NewNumber in [1..4]) then
    begin
      WriteLn('Enter new number of diskette drives (1..4)');
      repeat
        read(NewNumber);
      until newNumber in [0..4];
      WriteLn;
    end;
  if NewNumber = 0 then
    begin
      Mask     := $FF3E; { In binary, $FF3E is 1111111100111110.  When we
                          AND this mask onto the Equipment flag, it
                          turns OFF the bottom byte (byte #0) and bytes
                          # 6 and 7.  Byte # 0 indicates whether there
                          are ANY disk drives, and #6,7 say HOW many.}
      BitChanges := 0
    end
  else
    begin
      Mask := $FF3F;  { ANDing $FF3F onto the Equipment Flag turns OFF
                        bits # 6 and 7, the old value for number of
                        disk drives.  Then we OR BitChanges onto it to
                        turn ON the correct bits for the new value}
      BitChanges := (((NewNumber-1) shl 6) +1);
    end;
  if OldNumber <> NewNumber then
    begin
      Equip_word := (Equip_word and Mask ) or BitChanges;
      WriteLn('Changed equipment information to indicate ',NewNumber:1,' drives');
      if wait then
        begin
          WriteLn('Press a key to reboot and activate new information.');
          repeat until keypressed;
        end
      else
        begin
          write(chr(7));
          WriteLn('Rebooting now.');
        end;
      reboot;
    end
  else
    WriteLn('No change required.');
end.

