comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nickroberts@callnetuk.com>
Subject: Re: VIDEO MEMORY ACCESS WITH POINTERS
Date: 1999/11/29
Date: 1999-11-29T00:00:00+00:00	[thread overview]
Message-ID: <3841FA9B.31E9D1F4@callnetuk.com> (raw)
In-Reply-To: 38409762.0@news.pacifier.com

DuckE wrote:
> 
> with system.storage_elements;
> 
> procedure video_memory_example is
> 
>   max_video_memory : constant := 16#2000#;
> 
>   type video_cell is mod 2**16;
> 
>   type video_memory_type is
>     array( 1 .. max_video_memory ) of video_cell;
> 
>   video_memory : video_memory_type;
>   for video_memory'address use
> system.storage_elements.to_address( 16#b8000000# );
>   pragma volatile( video_memory );
> 
> begin
>   video_memory( 1 ) := 16#4141#;
> end video_memory_example;

Strictly, this solution needs two extra declarations:

   for video_cell'Size use 16;

   for video_memory_type'Component_Size use 16;

These declarations will ensure that the types video_cell and
video_memory_type both have the correct size and format. Each should be
inserted just after the declaration of the type itself.

It would probably (but not necessarily) be more convenient for the array
index range to be 0..max_video_memory-1. It may be more convenient to
declare the array as a two-dimensional array, but (interestingly) the
Ada standard provides no way to specify or interrogate whether an array
is stored in row-major or column-major order, so you can't do this if
you need portability. (Row-major order is recommended in the RM95, but
you should check what your compiler does.)

In addition, I think it's worth pointing out that the type video_cell
could be broken down into its component parts (by making it a record or
array type), and also that, in a big program, it will likely be worth
encapsulating all accesses to bare video memory (by putting it all into
a separate package, with an appropriate interface - e.g. procedures for
drawing lines, or text, or whatever).

-- 
Nick Roberts
http://www.adapower.com/lab/adaos
Always call for the professionals. (If they don't help, call for me ;-)






  reply	other threads:[~1999-11-29  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-27  0:00 VIDEO MEMORY ACCESS WITH POINTERS ???
1999-11-27  0:00 ` DuckE
1999-11-29  0:00   ` Nick Roberts [this message]
1999-11-29  0:00     ` Niklas Holsti
1999-12-01  0:00       ` Robert Dewar
1999-11-27  0:00 ` David C. Hoos, Sr.
1999-11-28  0:00 ` Vladimir Olensky
1999-11-30  0:00 ` Gautier
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox