delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/14/02:22:55

From: peter AT agnes DOT dida DOT physik DOT uni-essen DOT de (Peter Gerwinski)
Newsgroups: comp.os.msdos.djgpp,comp.lang.pascal.misc
Subject: Re: GNU Pascal: var p : ^void; How do I access the memory!
Followup-To: comp.os.msdos.djgpp,comp.lang.pascal.misc
Date: 13 Jan 1997 19:07:30 GMT
Organization: Universitaet Essen, Germany
Lines: 126
Message-ID: <5be15i$97m@sun3.uni-essen.de>
References: <5b42d3$kid AT acs1 DOT star DOT net>
Reply-To: peter DOT gerwinski AT uni-essen DOT de
NNTP-Posting-Host: agnes.dida.physik.uni-essen.de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

You are trying to do direct memory access, this is not so trivial
in protected mode.  Jan-Jaap van der Heijden wrote the following to
the GNU Pascal mailing list:

8< -- v Jan-Jaap v ---------------------------------------------------------

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;

8< -- ^ Jan-Jaap ^ ---------------------------------------------------------

> If anyone knows of any documentation or books, that would also be very
> helpful!

There is on-line documentation, the FAQ, and the GNU Pascal mailing list
- and these NewsGroups.  For details see the GNU Pascal home page,

    http://home.pages.de/~GNU-Pascal/

Hope this helps,

    Peter

      e-mail:  peter DOT gerwinski AT uni-essen DOT de
home address:  D\"usseldorfer Str. 35, 45145 Essen, Germany
         WWW:  http://agnes.dida.physik.uni-essen.de/~peter/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019