[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Pixel Plotting Problem

Posted on 1998-06-17
Medium Priority
Last Modified: 2008-02-01
I'm having problems with a book that shows you how to write games in C. To plot a pixel on the screen vga mode 13h must be entered which I can do. Then a pointer is created pointing to the video address:

      char * far ptr=(char * far) 0xA0000000L;

and a pixel is plotted with:


Well 'far' fails the compile and not using it causes the program to crash, so how do I solve this? The solution must be as fast and compact ideally. Thanks.
Question by:BOINGED
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

kinkajou earned 200 total points
ID: 1251265
This may solve your problem, I always use: "unsigned char far * video_ptr = (char far *) 0xA0000000L;"

In other words, switch the far and the *.
LVL 16

Expert Comment

ID: 1251266
I have a very similar construct in a program which works (using MSC version 6.00). Perhaps it would be relevant to know what compiler you are using, what environment (something on a PC (from the video address); DOS? Windows? 95?), and exactly what error the compiler emits for the pointer assignment attempt.


Author Comment

ID: 1251267
I tried kinkajous' solution and got the following error messages upon compiling:

syntax error before * (on line unsigned char * far etc)
video_ptr undeclared  (on next line, i.e. because of above error)

I'm using the djgpp200 compiler (a DOS port of GNU) in a DOS window in Windows 95.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1251268
I also had to change up the syntax of the code snip I used earlier. The compiler complains that we are trying to assign a long address to a char pointer. I changed the syntax and compiled successfully using: "unsigned char far * video_ptr = (unsigned char far *) 0xA0000000;". Notice that the type cast has been changed from "char far *" to "unsigned char far *" and the address being assigned is devoid of the "L" indicating that it is a long address. Please let us know if this solves your problems.

Expert Comment

ID: 1251269
Have you considered using assembler?  would be easier to implement, and you intergrate it into your C program.

Author Comment

ID: 1251270
I tried kinkajou's second solution but still got the error - I think the problem is with a 'far' pointer are they part of ANSI C?
If assembler is as quick then I'll use that, I take it I can write this inline? What do I do then?

Expert Comment

ID: 1251271
"far" is not ANSI C. The intent of "far" is to provide a 32 bit pointer that can be placed in remote segments without declaring a memory model that utililzes 32 bit far pointers.

An Assembler routine would look like:

video_address EQU 0A000h

PUBLIC Plot_Pixel
Plot_Pixel PROC FAR C color:WORD

mov AX, video_address       ; Set ES:DI to screen memory
mov ES, AX
xor  DI,DI                           ; Zero DI

mov CX, 1                          ; Number of WORDS to display
mov AL, BYTE PTR color    ; Move the color into AH and al
mov AH,AL
rep  stowsw                       ; Write the color CX number of times using STRING
                                        ; WORD call

Plot_Pixel ENDP


But before doing any Assembler, I would suggest looking into your compiler options to change the memory model to MEDIUM or greater and type cast the video_ptr to an "unsigned long int". You might want to look up "far pointers" to see how your compiler suggests using them.

Expert Comment

ID: 1251272
FAR pointers are only needed when you are making a 16 bit DOS program (or something else 16 bit).
the syntax:

 char far *video=(char far *)(0xa0000000);

works ok for borland under dos, don't know about others.
for watcom, this would also work (provided compiling 16 bit), but then you wouldn't need 16:16 pointers anyway.

if your memory model is large or something similair, you don't have to use the far keyword, since all pointers are far by default.

now for relevant stuff :)

just a hunch, but DJGPP is a 32 bit compiler. thus, the video address would be 0xa0000 and the FAR is not needed, and not wanted either. FAR as said earlier isn't a ANSI c thing, and it's quite possible djgpp doesn't know it. if so, the construct becomes:

char *video=(char *)0xa0000;



PS: although i like assembler and use it frequently, i do not think it is needed here :)

Author Comment

ID: 1251273
Nothing seems to work. How difficult can it be to plot a single pixel on the screen :)

Expert Comment

ID: 1251274
So what is your status? Still getting errors? Correct me if I'm wrong, but aren't you using the DOS video memory address? That would indicated that you need to use a DOS executable and run it in MSDos. I'm not sure of the reliability of using the DOS video memory address under windows, even in a DOS box, when windows uses GDI to display to the screen. Let us know what is working and not for you. It may be a djgpp200 compiler issue.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question