[ Charset ISO-8859-1 unsupported, converting... ]
Hi there,
It looks like it's not possible to declare a pointer to char and initialise it to the video memory, e.g.
type VideoMemory: ^char;
var VideoMemory := 0x80000;
Excuse the syntax if its wrong, I'm new to Pascal. :-)
The following shows how to store a character at address 0x80000:
program VideoMemory; type VideoMemory = ^char;
var VideoMemoryVar : VideoMemory value VideoMemory($80000); begin VideoMemoryVar^ := 'a'; end .
Note that it depends on your OS what will be at the address 0x80000. If you try to access video memory after entering protected mode, but before you initialize memory management your OS will crash.
Also variables and pointer types used to access hardware should be marked `volatile', but I just noticed that currently GPC does not allow this...
I'd like to know if it's not possible to get a pointer to the video memory region on PCs will I need to modify the compiler to allow it? Or would it be easier to just write a helper routine in C or assembler and link to it instead? Also what is the calling convention used and what does the procedure activation record look like?
You can use inline asm -- typically things which are impossible to do in Pascal (or another HLL) reduce to a small number of instructions.
In general GPC uses the same calling convention as C. However, Pascal has much more possibilities for parameter passing then C (variable parameters, conformal arrays) and extra types. Also, GPC adds some extensions to standard Pascal. Things which are not present in C are mapped to C-like constructs -- for example variable parameters are implemented by passing pointers (addreses of the parameters).
Is it fairly easy to use an alternative standalone runtime library with GNU Pascal? I'd like to use GCC's -fstandalone and -nostdinc -nostdlib (IIRC) options to link to my own standalone runtime so I can use Pascal for low level system programming.
It is fairly easy to link-in alternative runtime library (or no runtime library at all), just use gcc as a linker. OTOH GPC assumes presence of runtime support and generates calls to support routines when needed. So you have to provide support routines for all constructs that you use. As first approximation operations on strings, sets and files and memory (de)allocation are implemented by runtime calls.
Note that most of GPC runtime is written in Pascal -- if you avoid some high-level constructs you can use no runtime at all.