Article View: comp.lang.modula2
Article #4048Re: Recursion & Types
From: Alex Bewley
Date: Thu, 11 Feb 1988 22:50
Date: Thu, 11 Feb 1988 22:50
36 lines
1865 bytes
1865 bytes
Pointers are extremely useful. They can be used for type conversion (but
we, being good programmers :-), don't do this). They can also be used to
'fix' data structures to certain locations in memory. For example consider the
video screen of a PC. It is composed of 4000 bytes. The colour screen memory
is located at B800H:0000H, and the monochrome screen memory is located at
B000H:0000H. A small procedure could determine which type of video card is
being used and set an array to point to the appropriate memory location. Thus,
every time you use a data structure (usually a two dimensional array, in this
case) it will change the screen display.
Some code is included below.
For this screen exercise you could use the absolute variable declaration, but
that would mean defining an array for each screen.
Alex
-----
TYPE
ScreenType = POINTER TO ARRAY [0..25-1],[0..80-1] OF RECORD
Char, Attr : CHAR;
END;
VAR
Screen : ScreenType;
BEGIN
(* determine video card type *)
...
IF ColourMonitor THEN
Screen := 0B800H:0000H;
ELSE
Screen := 0B000H:0000H;
END;
...
Screen[0][0].Char := "A"; (* put an 'A' in the top left corner of the *)
END; (* screen *)
Technical Details
Message-ID:
<INFO-M2%88021200183659@UCF1VM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!rochester!bbn!uwmcsd1!ig!agate!ucbvax!UOGUELPH.BITNET!BOTCHAIRReferences:
<markh@csd4.milw.wisc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!rochester!bbn!uwmcsd1!ig!agate!ucbvax!UOGUELPH.BITNET!BOTCHAIR From: BOTCHAIR@UOGUELPH.BITNET (Alex Bewley) Newsgroups: comp.lang.modula2 Subject: Re: Recursion & Types Message-ID: <INFO-M2%88021200183659@UCF1VM> Date: 11 Feb 88 22:50:03 GMT References: <markh@csd4.milw.wisc.edu> Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Info-Modula2 Distribution List <INFO-M2%UCF1VM.bitnet@jade.berkeley.edu> Organization: The Internet Lines: 36