[comp.sys.ibm.pc.misc] Direct address access via C

rg@msel.unh.edu (Roger Gonzalez) (01/29/91)

I'd like to directly manipulate the text video area via Turbo C.  I gather
that it is located at B something or 8 something, depending on your adaptor.
How do you do the memory access, though?  On a VMEbus based machine, all 
you have to do is coerce a pointer to be the address, and then you can do
stuff like overlay structures on the memory map.  I'm new to this aspect
of PC programming, since I'm mainly a Unix programmer.

Is there any speed gain in doing C->addr manipulations rather than using
Turbo's (a little too restrictive) routines, or do I have to learn Intel's
assembler to really get anything out of it?

-Roger

-- 
"The question of whether a computer can think is no more interesting
 than the question of whether a submarine can swim" - Edsgar W. Dijkstra 
rg@[msel|unhd].unh.edu        |  UNH Marine Systems Engineering Laboratory
r_gonzalez@unhh.bitnet        |  Durham, NH  03824-3525

stanley@phoenix.com (John Stanley) (01/29/91)

rg@msel.unh.edu (Roger Gonzalez) writes:

> I'd like to directly manipulate the text video area via Turbo C.  I gather
> that it is located at B something or 8 something, depending on your adaptor.
> How do you do the memory access, though?  On a VMEbus based machine, all 
> you have to do is coerce a pointer to be the address, and then you can do
> stuff like overlay structures on the memory map.  

  Well, for TurboC, all you need to do is coerce a pointer to be the 
address, and then you can do stuff like overlay structures on the memory
map.

  Look in the manual under MK_FP. You will need to be in at least large
model (I think) to do this. 

> Is there any speed gain in doing C->addr manipulations rather than using
> Turbo's (a little too restrictive) routines, or do I have to learn Intel's
> assembler to really get anything out of it?

   You should be able to increase the speed a little. As always, if you 
want top speed, and can afford to invest the time, use assembler. 

> "The question of whether a computer can think is no more interesting
>  than the question of whether a submarine can swim" - Edsgar W. Dijkstra 

   But even more interesting, can computers swim and submarines think?
Yeth, thomtimeth they DO think. 

py@meadow.uucp (Peter Yeung) (01/30/91)

In article <1991Jan28.202900.11946@unhd.unh.edu> rg@msel.unh.edu (Roger Gonzalez) writes:
>I'd like to directly manipulate the text video area via Turbo C.  I gather
>that it is located at B something or 8 something, depending on your adaptor.
>How do you do the memory access, though?  On a VMEbus based machine, all 
>you have to do is coerce a pointer to be the address, and then you can do
>stuff like overlay structures on the memory map.  I'm new to this aspect
>of PC programming, since I'm mainly a Unix programmer.
>

Use the macro MK_FP(seg,off) to create a far * <seg>:<off>.

>Is there any speed gain in doing C->addr manipulations rather than using
>Turbo's (a little too restrictive) routines, or do I have to learn Intel's
>assembler to really get anything out of it?
>

On a plain 8088 type machine, writing directly to video ram is considerably 
faster than going through the BIOS/DOS (depending which calls you are using). 
I am not sure about the speed gain on faster machines, especially those
386's with BIOS shadow ram.

However, it makes life more complicated since you have to handle video 
attributes, scrolling etc. Scrolling is slightly more complex when using a 
true blue CGA card due to its poor design.

You should be able to do almost anything in Turbo C without resorting
to assembly language. However, you have to know about low level hardware
stuff (e.g. check for vertical trace to avoid snow on IBM CGA card).

There are a few PD/shareware type packages doing fast video I/O which
by-pass the BIOS.. Typically they are part of "windowing" packages.

>-Roger
>
>-- 
>"The question of whether a computer can think is no more interesting
> than the question of whether a submarine can swim" - Edsgar W. Dijkstra 
>rg@[msel|unhd].unh.edu        |  UNH Marine Systems Engineering Laboratory
>r_gonzalez@unhh.bitnet        |  Durham, NH  03824-3525


-- 
Peter Yeung     Amdahl Canada Ltd., Software Development Center
                2000 Argentia Road, Plaza 2, Suite 300
                Mississauga, Ont.   L5N 1V8
                Phone: (416) 542-6300    Fax: (416) 858-2233