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?