[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

Pixel Plotting Problem

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
BOINGED
Asked:
BOINGED
1 Solution
 
kinkajouCommented:
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
 
imladrisCommented:
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
 
BOINGEDAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kinkajouCommented:
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
 
kellyjjCommented:
Have you considered using assembler?  would be easier to implement, and you intergrate it into your C program.
0
 
BOINGEDAuthor Commented:
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
 
kinkajouCommented:
"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
 
TheMadManiacCommented:
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
 
BOINGEDAuthor Commented:
Aaargh!
Nothing seems to work. How difficult can it be to plot a single pixel on the screen :)
0
 
kinkajouCommented:
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

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now