Hi everybody.
Is there some CRT unit to use with GPC? Because I don't want to install the BPCompat kit, so it's unit doesn't work. Or if there is no CRT unit, is there some way to use the stdio.h header file? Specially the getchar function.
Thank you, ARIEL. --- Ariel Bendersky bender@einstein.com.ar
Hello!
According to Bendersky:
Is there some CRT unit to use with GPC? Because I don't want to install the BPCompat kit, so it's unit doesn't work.
What's wrong with the CRT in `BPcompat'?
Or if there is no CRT unit, is there some way to use the stdio.h header file? Specially the getchar function.
Which system are you running? DOS/DJGPP?
You can access each function of your system's C library from GNU Pascal; see the GPC FAQ list at http://home.pages.de/~GNU-Pascal/gpc-faq.html.
If you need a C "FILE" structure, you can use GPC's `GetFile' function to extract it from a Pascal file type (only available in recent beta/ alpha versions).
Hope this helps,
Peter
Hi,
What's wrong with the CRT in `BPcompat'?
There's nothing wrong with it. Just that I want to learn how to use GPC, and not how to write my programs in Borland Pascal and make them run in GPC. It's just that, so what I did, was to take a look to the BPcompat sources to learn how to "import" functions from the C library. I finally used the following as borland's readkey:
Function getche:char; C;
Which system are you running? DOS/DJGPP?
Yes, I'm running that system.
Thank you a lot, Ariel. --- Ariel Bendersky bender@einstein.com.ar
According to Bendersky:
What's wrong with the CRT in `BPcompat'?
There's nothing wrong with it. Just that I want to learn how to use GPC, and not how to write my programs in Borland Pascal and make them run in GPC.
:-) Welcome to the club!
It's just that, so what I did, was to take a look to the BPcompat sources to learn how to "import" functions from the C library. I finally used the following as borland's readkey:
Function getche:char; C;
Okay, that's *one* method to get this functionality.
Which system are you running? DOS/DJGPP?
Yes, I'm running that system.
Then it's probably the best method to get a `ReadKey' function to call the BIOS interrupt directly from your program.
Function KeyPressed = result: Boolean;
begin (* KeyPressed *) result:= false; asm ( 'movb $0x01, %%ah' 'int $0x16' 'setneb %0' : '=rm' ( result ) : (* no input *) : '%eax' ); end (* KeyPressed *);
Function ReadKey = result: Char;
begin (* ReadKey *) asm ( 'movb $0x00, %%ah' 'int $0x16' : '=a' ( result ) : (* no input *) : '%eax' ); end (* ReadKey *);
Remarks:
* The "= result" above is an ISO-10206 Pascal extension. It declares a variable that holds the return value of the function.
* The above only works under DOS (or DOS emulation). For UNIX (incl. Linux), use some C functions instead; I recommand to use the portable `ncurses' library. (That's the reason why I don't mind to use assembler under DOS: There is no intrinsically portable solution anyway.)
* For a GPC assembler tutorial, see ftp://agnes.dida.physik.uni-essen.de/gnu-pascal/contrib/gpcasm.zip.
In addition, have a look at the fairly portable GRX graphics library.
Have fun,
Peter