?
Solved

Pixel Plotting Problem

Posted on 1998-06-17
10
Medium Priority
?
337 Views
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:

      ptr[320*y+x]=colour;

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.
0
Comment
Question by:BOINGED
[X]
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
10 Comments
 
LVL 2

Accepted Solution

by:
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 *.
0
 
LVL 16

Expert Comment

by:imladris
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.

0
 

Author Comment

by:BOINGED
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:kinkajou
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.
0
 
LVL 2

Expert Comment

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

Author Comment

by:BOINGED
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?
0
 
LVL 2

Expert Comment

by:kinkajou
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

MODEL MEDIUM
CODE
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
ret

Plot_Pixel ENDP

END

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.
0
 
LVL 1

Expert Comment

by:TheMadManiac
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;

greetz,

 FlorizzzZz

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

Author Comment

by:BOINGED
ID: 1251273
Aaargh!
Nothing seems to work. How difficult can it be to plot a single pixel on the screen :)
0
 
LVL 2

Expert Comment

by:kinkajou
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.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

801 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