Orlando Llanes wrote:
Let's say I have a record as follows:
TYPE ToeFoo = PACKED RECORD { Is PACKED neccessary to keep it continuous? }
Yes, it is.
If you want to verify for yourself, you can try something like
var Foo: ToeFoo; begin {$x+} Writeln ( Pointer(@Foo.BarNone) - Pointer(@Foo.Bar) ) end.
(works only with non-packed records). The type casts to Pointer are there to prevent GPC from assuming another base size than 1.
Bar : Byte; BarNone : Word;
END;
The fields are not important, what is important is the following procedure:
PROCEDURE DahDahDah( VAR aFoo : ToeFoo ); BEGIN END;
I need to get a pointer to it in ASM in order to manipulate it and in order to save the value. What would I have to do? Is it safe to assume that DS = Descriptor to aFoo in procedure DahDahDah? And do VAR parameters return a 32-bit offset? I remember it coming up once before that the pointers were 32-bit offsets, but I just want to verify that I remembered correctly :}
On the x86 platform, it is. All variables (global, local and dynamic) and code are in the same segment, and pointers and references are just 32-bit offsets. (On other platforms, there may not be anything like Descriptors, or pointers may have a different size, e.g. 64 bits.)
For the curious, what I'm doing is coding a DPMI Simulate Real Mode Interrupt so I Can call RM ISRs, but especially to change the graphics mode. I'm aware of BPCompat (BTW, AWESOME collection of routines Chief et al! :), and I tried it, but although the procedure __dpmi_simulate_real_mode_interrupt() executed properly, I didn't get the desired video mode. Besides, I'm coding it myself because I want to keep it simple.
(* IMHO, it would be simpler to use existing units. *)
Instead of getting mode 3, I got mode 1 or 2 (I didn't check beyond noticing that it didn't look like Mode-13h, it was some 40x20 characters per screen, and it looked like a text mode). I honestly don't think it was something wrong in the DPMI unit, the DPMI unit links to a C routine.
Unfortunately, there is something wrong there, namely the declaration of __dpmi_regs. Instead of ShortCard (16 bit unsigned integers on the x86, and the natural translation of the "unsigned short" of dpmi.h), it uses Bytes for the 16-bit registers. Try changing it as below. (I did not check your program, however, because I'm too lazy now to boot DosEmu... ;-)
BTW: "Packed" is (I think) not necessary for this record, because all fields are aligned, anyway, i.e. 32-bit fields are preceeded only by other 32-bit fields, and so on. The original record is a "struct" in dpmi.h, and I think C's "struct"s correspond to non-packed records in Pascal. Is this right? Is there anything in C that corresponds to packed records in Pascal?
If you want to verify for yourself, you can try something like (works only with non-packed records). The type casts to Pointer are there to prevent GPC from assuming another base size than 1.
Only reason I'd need to verify really is to make sure the Beta's working right, I'll keep you posted if it doesn't :)
On the x86 platform, it is. All variables (global, local and dynamic) and code are in the same segment, and pointers and references are just 32-bit offsets. (On other platforms, there may not be anything like Descriptors, or pointers may have a different size, e.g. 64 bits.)
Cool :) Where can I Get info on the Machine specifics of Alphas? I want to know the low level details like how graphics are displayed, if sound is available, the architecture of the memory (for example: PC has segments, offsets, etc). BTW, are there plans to port DJGPP and/or GPC to the Mac platform? Are there any free tools you or anybody know of that compile on it?
Unfortunately, there is something wrong there, namely the declaration of __dpmi_regs. Instead of ShortCard (16 bit unsigned integers on the x86, and the natural translation of the "unsigned short" of dpmi.h), it uses Bytes for the 16-bit registers. Try changing it as below. (I did not check your program, however, because I'm too lazy now to boot DosEmu... ;-)
Doh! It's *always* those dang pesky minor details that are so elusive, the ones that you would never think could possibly go wrong :P One thing tho, I think I tried it using the following declarations (and I changed the sizes accordingly as well):
TYPE DWord = Cardinal(32); Word = Cardinal(16); Byte = Cardinal(8);
So what said Byte previously, I changed to Word, and what was Word previously I changed to DWord. I'll try it again, mayhaps I did something wrong :}
BTW: "Packed" is (I think) not necessary for this record, because all fields are aligned, anyway, i.e. 32-bit fields are preceeded only by other 32-bit fields, and so on. The original record is a "struct" in dpmi.h, and I think C's "struct"s correspond to non-packed records in Pascal. Is this right?
Does Packed align on a Dword boundary? Or does it lump all the fields together to ensure that they are continuous? I ask because from what I remmeber about Pascal, it's to keep them continuous (the only time in Borin... errr... Standard Pascal that I've seen Packed is for a character array).
Is there anything in C that corresponds to packed records in Pascal?
Got me on that one :( Although I am very familiar with the types, type definitions, and I haven't seen anything really about packing the records like in Pascal. I could be wrong tho, if there is something, it's one of those deep dark secrets of C :P
See ya! Orlando Llanes
"Hey, we all did the drug thing, we all did the money thing, and eventually you find out that none of that stuff fixes anything, and we have nowhere else to go except to evolve spiritually and intellectually" -- Meredith Brooks
"Look out fo' flyeeng feet" O__/ a010111t@bc.seflin.org /|____. O <__. /> / \ ____________|_________ http://ourworld.compuserve.com/homepages/Monkey414
So what said Byte previously, I changed to Word, and what was Word previously I changed to DWord. I'll try it again, mayhaps I did something wrong :}
Ok, I think I figured out what went wrong. Apparently in C, the way __dpmi_regs is defined is in a way such that the 3 sections (d, x, and h) overlap, but it doens't appear to be overlapping in Pascal. I noticed a quirk with Borland Pascal, and I was wondering if it was present in GPC, when you define a record structure as follows:
TYPE MyRec = RECORD CASE Integer OF 0 : (SomeVar : Integer; SomeVar2 : Integer); 1 : AnotherVar : ARRAY[ 1..2 ] OF Integer; END; END;
Supposedly, you want to tell the compiler to use SomeVar, or AnotherVar as if they were overlapping. An Integer is 16 bits in BP, with that in mind, BP would report 8 when you use SizeOf( MyRec ), logically it should be 4. By overlapping, I mean like a type cast. Is there a way to do this in GPC like C apparently does?
See ya! Orlando Llanes
"Hey, we all did the drug thing, we all did the money thing, and eventually you find out that none of that stuff fixes anything, and we have nowhere else to go except to evolve spiritually and intellectually" -- Meredith Brooks
"Look out fo' flyeeng feet" O__/ a010111t@bc.seflin.org /|____. O <__. /> / \ ____________|_________ http://ourworld.compuserve.com/homepages/Monkey414