Pascal DMA and Floppy

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Pascal DMA and Floppy

Post by System123 »

HI

So far I have programmed my floppy controller from scratch in pascal with the help of some C code and a bunch of Floppy Controller Documents. The problem is now how do I set up a read and write procedure.

I have read a lot of DMA tutorials and I am fine with understanding then the problem is I am trying to convert this section from C code but I don't know how to do the one section in Pascal.

Here is the C code. I got it from http://forum.osdev.org/viewtopic.php?t=13538

Code: Select all

#define floppy_dmalen 0x4800
static const char floppy_dmabuf[floppy_dmalen]
                  __attribute__((aligned(0x8000)));

static void floppy_dma_init(floppy_dir dir) {

    union {
        unsigned char b[4]; // 4 bytes
        unsigned long l;    // 1 long = 32-bit
    } a, c; // address and count
The problem is when I create a buffer array I get a compiler error saying the size is too large. How else can I perform these tasks? And is a 'union' in C the same as a record in Pascal?

Thanks
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Laksen
Member
Member
Posts: 140
Joined: Fri Nov 09, 2007 3:30 am
Location: Aalborg, Denmark

Re: Pascal DMA and Floppy

Post by Laksen »

You probably have to allocate the dma buffer yourself as static alignment in pascal is a little dodgy. I've heard rumors that it's possible on i386 but I haven't found a surefire way to do it

Edit: yeah, I fucked this up :P

Code: Select all

procedure floppy_dma_init(dir: floppy_dir);
var a,c: packed record
    case integer of
     0: (b: array[0..3] of byte);
     1: (l: longword);
    end;
begin

end;
Last edited by Laksen on Mon Dec 01, 2008 5:07 pm, edited 1 time in total.
http://j-software.dk | JPasKernel - My Object Pascal kernel
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Pascal DMA and Floppy

Post by Craze Frog »

System123 wrote:And is a 'union' in C the same as a record in Pascal?
No, to use a union in pascal you need a case statement inside a record block (called a variant part).

Copied from Delphi help:

Code: Select all

A record type can have a variant part, which looks like a case statement. The variant part must follow the other fields in the record declaration.
To declare a record type with a variant part, use the following syntax.

type recordTypeName = record

  fieldList1: type1;
  ...
  fieldListn: typen;
case tag: ordinalType of
  constantList1: (variant1);
  ...
  constantListn: (variantn);
end;

The first part of the declaration—up to the reserved word case—is the same as that of a standard record type. The remainder of the declaration—from case to the optional final semicolon—is called the variant part. In the variant part,

tag is optional and can be any valid identifier. If you omit tag, omit the colon (:) after it as well.
	ordinalType denotes an ordinal type.
	Each constantList is a constant denoting a value of type ordinalType, or a comma-delimited list of such constants. No value can be represented more than once in the combined constantLists.
	Each variant is a comma-delimited list of declarations resembling the fieldList: type constructions in the main part of the record type. That is, a variant has the form

fieldList1: type1;

 ...
fieldListn: typen;

where each fieldList is a valid identifier or comma-delimited list of identifiers, each type denotes a type, and the final semicolon is optional. The types must not be long strings, dynamic arrays, variants (that is, Variant types), or interfaces, nor can they be structured types that contain long strings, dynamic arrays, variants, or interfaces; but they can be pointers to these types.

Records with variant parts are complicated syntactically but deceptively simple semantically. The variant part of a record contains several variants which share the same space in memory. You can read or write to any field of any variant at any time; but if you write to a field in one variant and then to a field in another variant, you may be overwriting your own data. The tag, if there is one, functions as an extra field (of type ordinalType) in the non-variant part of the record.

Variant parts have two purposes. First, suppose you want to create a record type that has fields for different kinds of data, but you know that you will never need to use all of the fields in a single record instance. For example,

type

  TEmployee = record
  FirstName, LastName: string[40];
  BirthDate: TDate;
  case Salaried: Boolean of
    True: (AnnualSalary: Currency);
    False: (HourlyWage: Currency);
end;

The idea here is that every employee has either a salary or an hourly wage, but not both. So when you create an instance of TEmployee, there is no reason to allocate enough memory for both fields. In this case, the only difference between the variants is in the field names, but the fields could just as easily have been of different types. Consider some more complicated examples:

type

  TPerson = record
  FirstName, LastName: string[40];
  BirthDate: TDate;
  case Citizen: Boolean of
    True: (Birthplace: string[40]);
    False: (Country: string[20];
            EntryPort: string[20];
            EntryDate, ExitDate: TDate);
  end;

type

  TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other);
  TFigure = record
    case TShapeList of
      Rectangle: (Height, Width: Real);
      Triangle: (Side1, Side2, Angle: Real);
      Circle: (Radius: Real);
      Ellipse, Other: ();
  end;

For each record instance, the compiler allocates enough memory to hold all the fields in the largest variant. The optional tag and the constantLists (like Rectangle, Triangle, and so forth in the last example above) play no role in the way the compiler manages the fields; they are there only for the convenience of the programmer.
The second reason for variant parts is that they let you treat the same data as belonging to different types, even in cases where the compiler would not allow a typecast. For example, if you have a 64-bit Real as the first field in one variant and a 32-bit Integer as the first field in another, you can assign a value to the Real field and then read back the first 32 bits of it as the value of the Integer field (passing it, say, to a function that requires integer parameters).
leledumbo
Member
Member
Posts: 103
Joined: Wed Apr 23, 2008 8:46 pm

Re: Pascal DMA and Floppy

Post by leledumbo »

The problem is when I create a buffer array I get a compiler error saying the size is too large
0x4800 isn't very large, except if you're still using the old Turbo Pascal. Use Free Pascal!
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: Pascal DMA and Floppy

Post by System123 »

Thanks Craze Frog for clearing that up for me.

I am using Free Pascal. You try declare an array of byte with the length of $4800. Pascal cannot compile it as it says its too large. 0x4800 = 18432 decimal.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
leledumbo
Member
Member
Posts: 103
Joined: Wed Apr 23, 2008 8:46 pm

Re: Pascal DMA and Floppy

Post by leledumbo »

What's your version? 18432 is just too far from the limit FPC can handle. This program even compiles fine to me:

Code: Select all

program test;

var
  a: array [0..$7FFFFFFE] of Byte; // 2 GB, just as stated in the manual
begin

end.
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: Pascal DMA and Floppy

Post by System123 »

Its the latest version. 2.0.2 I think.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Pascal DMA and Floppy

Post by jal »

System123 wrote:I get a compiler error saying the size is too large
Could you please (and from now on always) give the exact error message the compiler gives? This could help trace the error.


JAL
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: Pascal DMA and Floppy

Post by System123 »

I sorted the problem with the compiler out. It works now and so does my floppy driver. Well almost. It reads the floppy perfectly but when I try write to the floppy it doesn't write and then it finishes the boot. But if i press any key it triple faults. I will post my code if it is needed.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
leledumbo
Member
Member
Posts: 103
Joined: Wed Apr 23, 2008 8:46 pm

Re: Pascal DMA and Floppy

Post by leledumbo »

Its the latest version. 2.0.2 I think.
The latest (release) version is 2.2.2, I'm using the daily snapshots (2.3.1). You're quite (if not very :mrgreen:) far behind.
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: Pascal DMA and Floppy

Post by System123 »

NO I got the version number wrong its 2.2.0 not 2.0.2. I can't afford to download a new version everyday or month. In my country we still have internet caps of on average a huge 1Gb
Gizmic OS
Currently - Busy with FAT12 driver and VFS
OrOS
Member
Member
Posts: 143
Joined: Sat Sep 08, 2007 11:26 pm
Location: Canada

Re: Pascal DMA and Floppy

Post by OrOS »

Damn, where do you live? I use just under 1TB a month between me and my servers.
Laksen
Member
Member
Posts: 140
Joined: Fri Nov 09, 2007 3:30 am
Location: Aalborg, Denmark

Re: Pascal DMA and Floppy

Post by Laksen »

Which platform and os are you on system123?
http://j-software.dk | JPasKernel - My Object Pascal kernel
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: Pascal DMA and Floppy

Post by System123 »

It's a little place called South Africa. Its somewhere in Mexico :mrgreen:

I'm on Windows Vista, or Ubuntu Linux, depending on my mood. 32 bit PC
Gizmic OS
Currently - Busy with FAT12 driver and VFS
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: Pascal DMA and Floppy

Post by eddyb »

System123 wrote:It's a little place called South Africa. Its somewhere in Mexico :mrgreen:
South Africa is in Mexico?! :mrgreen: :D South Africa is in the south part of Africa :lol: .
Post Reply