At 05:30 PM 1/1/97 -0500, you wrote:
Hello everyone, Happy New Year.
Greetings and best wishes from me too.
I realize this is a very stupid question and that it should
be painfully obvious, but I cannot seem to find the answer. Basically, I recently started programming in the DJGPP enviornment and have been able to do alot the of the basic stuff, I am very familiar with Turbo Pascal. Unfortunentally, I am not familiar with the other languages that the comipler is based on (ansi, enhanced etc.) and was wondering if there are any good books/docs etc on the subject.
Also, I have been trying to find out about how to write, say a byte, directly to memory or to read a byte directly from memory.
ie
var P : ^void;
begin GetMem(P, The_Space_I_Need); . . . end.
Now how do I read the and write to the memory I have allocated. In Turbo Pascal, i could use the mem[segment:offset] array, but that is not available in GNU Pascal...
Ah -- you probably mean physical memory access. This is not easy to accomplish, because of the DPMI trickery required to do such things. That's not GPC's fault, it's just as hard to do in djgpp. Give me some time to hack some code together.
I also wish to be able to read and write to ports, of the material I have found, I know that the port[] array that was in Turbo Pascal is also no longer available. What can I do in its place (ie writing to SB registers and to the Palette registers)
A port[] array would meaningless outside the PC world, so it's not part of the ANSI standards and GPC. But djgpp's C library provides simular functionality with the inportb() and outportb() functions. These (and more) are defined in <pc.h>
Consider this little program which accesses the PC's realtime clock via port $70 and $71.
============================================================================
program RTC;
type byte = __byte__ integer; short = __short__ integer; ushort = __unsigned__ short;
const RTCAdrPort = $70; RTCDtaPort = $71;
Seconds = $00; Minutes = $02; Hours = $04; Day = $07; Month = $08; Year = $09; HundredYear = $32; StatusA = $0A; StatusB = $0B; StatusC = $0C; StatusD = $0D; Diagnose = $0E;
{ Declared in djgpp's C library, see <pc.h> } function inportb(port: ushort): byte; external; C; procedure outportb(port: ushort; data: ushort); external; C;
{ Read a value from an RTC register } function RTCRead(address: ushort): byte; begin outportb(RTCAdrPort, address); { pass RTC address } RTCRead := inportb(RTCDtaPort); { read value } end;
{ Write a value to an RTC register } procedure RTCWrite(address: ushort; content: byte); begin outportb(RTCAdrPort, address); { pass RTC address } outportb(RTCDtaPort, content); { write new value } end;
{ Read a BCD date/time memory location from RTC and convert it to binary } function RTCDT(address: ushort): byte; var value: byte; begin if (RTCRead(StatusB) and 2 = 0) { BCD or binary mode ? } then RTCDT := RTCRead(address) else begin value := RTCRead(address); RTCDT := ((value shr 4) and $0F) * 10 + (value and $0F); end; end;
begin writeln('Information from the battery operated realtime clock'); writeln('----------------------------------------------------');
if RTCRead(Diagnose) and 128 = 0 then begin writeln('The clock is in ', ((RTCRead(StatusB) and 2)*6+12):2, ' hour mode'); writeln('Current time: ', RTCDT(Hours):2, ':', RTCDT(Minutes):2, ':', RTCDT(Seconds):2); writeln('Today is: ', RTCDT(Day):2, '/', RTCDT(Month):2, '/', RTCDT(HundredYear):2, RTCDT(Year):2); end else writeln(' CMOS battery dead!'); end.
============================================================================
In Turbo Pascal, RTCRead() would have been:
function RTCRead(address: ushort): byte; begin Port[RTCAdrPort] := address; RTCRead := Port[RTCDtaPort]; end;
Any help on any of the above problems would be of a huge help!
If you want to do sound programming, you may want to get the Allegro library for djgpp. Then, rewrite Allegro's C header file for GPC and you're done. That way, you don't have to program the hardware directly.
JanJaap -- "Nothing shocks me, I'm a scientist", Indiana Jones