Solved

Pixel Plotting Problem

Posted on 1998-06-17
10
327 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
10 Comments
 
LVL 2

Accepted Solution

by:
kinkajou earned 100 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 opening and reading files in the C programming language.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now