MIKAEL@vax.psl.ku.dk (01/16/91)
I have an interesting problem. I have an IEEE488 Interface card. It uses BASIC example files, and is really designed for BASIC interface, but I would like to use Pascal instead. The interface between Basic and The IEEE488 port is via a resident driver, that BASIC calls with a "CALL" instruction. Has anybody any experience in interfacing between Turbo Pascal and BASIC It seems that they use the same calling conventions. Mikael Mortensen
bobb@vice.ICO.TEK.COM (Bob Beauchaine) (01/17/91)
In article <25512@adm.brl.mil> MIKAEL@vax.psl.ku.dk writes: > Has anybody any experience in interfacing between Turbo Pascal and BASIC >It seems that they use the same calling conventions. I have never attempted interfacing Turbo with BASIC, but I have interfaced BASIC callable object routines with C. (Remainder of discussion comes from my work with compiled BASIC, Microsoft QuickBasic. No guarantee of success with interpreted BASIC, since I have never officially tried.) Basic uses what in the 'C' world is known as the medium memory model, which is functionally equivalent to Turbo Pascal. The medium memory model allows for multiple code segments and one data segment (hence the 64k static data limit). The calling covention of BASIC is the same as Turbo Pascal (i.e, the called routine is responsible for cleaning up the stack), with one minor exception: the default calling mechanism for BASIC is by reference. Parameters are not pushed on the stack, but rather a pointer to the parameter is pushed (this can be overidden in BASIC, but I have never looked into the details since I loathe BASIC.) Strings are handled in a rather annoying manner. Rather than passing a pointer to a string, a pointer to a record is passed. The record is equivalent to: type stringrec = record length : integer; data : ^string; end; The length field contains the current length of the string, and the data field is a pointer to the actual contents. Consequently, the difference between the BASIC string and a pascal string is in the preceeding length byte for a Pascal string. However, this allows BASIC strings to be up to 32,767 (I think) bytes. The only other issue is whether or not the pre-compiled BASIC modules conform to the Turbo requirements for externally linked object files. This is not likely, though version 6 has relaxed these requirements somewhat. As an example, to call a BASIC routine that excepts two integer arguments, you would define a procedure like this {$F+} procedure BasicProceudre(var i,j : integer); external;{$F-} (version 4,5.0,5.5) or procedure BasicProcedure(var i,j : integer); external; far; (version 6) and then include a {$L objectfilename} somewhere in the same source file. I realize that this has been somewhat hazy, and I don't have my references here, (I hope I didn't make any mistakes), so feel free to continue this discussion by e-mail if you have any problems. Bob Beauchaine bobb@vice.ICO.TEK.COM