Page 2 of 2

Posted: Sun Oct 29, 2006 3:13 am
by Cheery
hckr83 wrote:yea C code can look really bad... just look at the linux 0.0.1 code, they went for the "quick to type" option rather than "readable" option like in a lot of thier code they have functions with just things like "fm" how could anyone know what that means!?

actually I love C though so no one be like "quit bashing C, it can do stuff pascal cant"
C sucks, in many other languages (there are both low level and high level and both level languages which apply) you can write both quick to type and readable at the same time. It is the syntax nonsense fillers which makes C so bloat that one needs to go for only an another choice!

Posted: Sun Oct 29, 2006 4:08 am
by inflater
hckr83 wrote:have you checked anywhere!? their is fat stuff all over http://www.osdev.org/osfaq2/index.php/FAT12%20document that gives a fairly good description over fat12 also you may want to search code.google.com for some pascal stuff
I dont see on code.google.com any pascal FAT12 functions. Maybe I'm blind but I don't see any function(s) that runs or modifies files on FAT12 and in Pascal.

inflater

Posted: Sun Oct 29, 2006 10:28 am
by Dex
Because turbo pascal could use dos function, and you can not use dos functions, you are going to after write your own.
To help you you need to read how fat12 works and put it togeather with code like this

Code: Select all

uses dos;

Type
  TBootSector = Record
    nJump     : Array [1..3] of Byte;
    OEM       : Array [1..8] of Char;
    SectSize  : Word;
    ClustSize : Byte;
    ResSecs   : Word;
    FATCount  : Byte;
    RootSize  : Word;
    TotalSecs : Word;
    Media     : Byte;
    FATSize   : Word;
    TrackSize : Word;
    HeadCount : Word;
    HiddenSecs: Word;
    HiHidnSecs: Word;
    BTotalSecs: LongInt;
    DriveNo   : Byte;
    Res       : Byte;
    ExtBootSig: Byte;
    SerNo     : LongInt;
    VolLabel  : Array [1..11] of Char;
    FileSysID : Array [1..8] of Char;
    BootCode  : Array [1..450] of Byte
  End;

var
  b : TBootSector;
  f : file;
  r : registers;
  s, try : word;
  ds : string;

function upstr (s : string) : string;
var i : integer;
begin
  if length(s) > 0 then
    for i := 1 to length(s) do
      s[i] := upcase(s[i]);
  upstr := s
end;

label l1, l2;

begin
  if paramcount <> 2 then begin
    writeln ('Usage: GETBOOTF.EXE <source_disk:> <boot_sector_file> <ÄÙ');
    exit;
  end;
  ds := upstr(paramstr(1));
  if (ds <> 'A:') and (ds <> 'B:') then begin
    writeln ('Invalid source disk. It must be either A: or B:.');
    exit
  end;

                          (* READING BOOT SECTOR *)

  writeln ('Reading original boot sector...');
  try := 0;
l1:
  r.ax := $201; { read fn, 1 sector }
  r.cx := 1;    { track/cyl=0, sector=1 }
  r.dh := 0;    { head=0 }
  r.dl := ord(ds[1])-ord('A'); { disk }
  r.es := seg (b);
  r.bx := ofs (b);
  intr ($13, r);
  inc (try);
  if r.flags and fcarry = fcarry then begin
    writeln ('  An error occured. Error code: ', r.ah);
    if try = 1 then begin
      writeln ('    trying again...');
      r.ah := 0;
      r.dl := 0;
      intr ($13, r);
      goto l1;
    end
    else begin
      writeln ('  Failed.');
      exit
    end;
  end;
  writeln ('  OK.');

                            (* SAVING BOOT FILE *)

  writeln ('Saving a boot sector file...');
  assign (f, paramstr(2));
  {$i-} rewrite (f, 1); {$i+}
  if ioresult <> 0 then begin
    writeln ('  Couldn''t create a file.');
    exit;
  end;
  blockwrite (f, b, 512, s);
  close (f);
  if s <> 512 then begin
    writeln ('  An error occured.');
    exit
  end;
  writeln ('  OK.');
end.
Some of the above code you can use eg: "READING BOOT SECTOR", but some you can not eg: SAVING BOOT FILE".

Posted: Sun Oct 29, 2006 12:19 pm
by inflater
Thanx Dex and all of you ;) but how can I find the head, cluster and sector number for program e.g. GUI.BIN without using an "Disk Investigator" or other stuff? I mean like a finding file by name and executing it.

I looked to your MiniDOS - a cool make of DOS in pure ASM.
But - my code freezes when trying to print contents of diskette / running files. I think that ES is the faulty one - but PUSH ES didn't work...

inflater

Posted: Sun Oct 29, 2006 1:05 pm
by Dex
One you have filled in the above record, you need to use the info to load and scan through the rootdir, once you have load root dir into memory, you compare the name of file you want to load, with the what at the rootdir start +32, if its a 00 you print error "Can not find file", if it a differant name you add 32 to the offset and try the next name, once you find the name, you add o 0x1A to the offset and use that along with the FAT (that also needs loading) to load the file.
Problem is, i know only how to do it with ASM and you do not know much ASM and i have forgot most of what i new about pascal :cry: