Archived

This topic is now archived and is closed to further replies.

Virtual screen in 640x480 mode

This topic is 6686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I didn't work with BC 5.0, but v3.1 can't compile in 32bit PM mode, so your restricted with 64K segments and can't just allocate 327680 bytes of memory with malloc. Are you sure you allocating memory right? Or you allocating many blocks by 64K?
And what you get when you trying to send your virtual screen to video memory?

FlyFire/CodeX
http://codexorg.webjump.com

Share this post


Link to post
Share on other sites
I've discovered that malloc doesn't work but _fmalloc does.
But still problems. When I try for example to access buffer[65537] then compiler sets a value at buffer[1] (!) while the explanation says that you CAN allocate blocks >64Kb.
When sending it to the screen it just send the first block 5 times in staid of buffer[0],buffer[65536] etc.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is how i might handle it...
This will not be the cleanest code then again it is just a example so bear with me..

#include

unsigned char *vid_mem = (unsigned char *)0xA0000;

void main() {

unsigned char *back_buffer = (unsigned char *)malloc(width * height * bitdepth);

set_video(whatever);
pixel_stuff_to_back_buffer(back_buffer);
Update_vidmem_from_back_buffer(back_buffer);

set_video(back to whatever);
free(back_buffer);
}

void Update_vidmem_from_back_buffer(char *buffer) {

setpage(0);
memcpy(vid_mem,(unsigned char *)buffer,65536);
setpage(1)
memcpy(vid_mem,(unsigned char *)buffer+65536,65536);
...
...
...
}

I would never work with vid_mem directly cause there is a chance that something could screw up.. as for your memset stuff, that would most likely be used to set a backgroud color.. and you buffer[65537] is that an array? i am a bit confused on what you were trying to do...

E-mail me if ya want specific stuff, and i can help ya out more...
dieraxx@stega.smoky.org

Share this post


Link to post
Share on other sites
You can use buffers as an array in C++. For example if you put a value at buffer[1] then what you are really doing is:
Asm{
les di, buffer //getting the buffer-address
inc di, 1 //you know, from buffer[1]
mov al, value //the value to transfer
stosb //or mov [es:di], value
};

Since real dos depends a lot on 64Kb stuff you can't access buffer[65537]
(why can you allocate buffers >64Kb when it is almost impossible to access?!).

But on to the subject if you use
memcpy(screen,buffer+65536,65536)
it's just the same as:
memcpy(screen,buffer,65536)
Since the reason I wanted to learn C++ is because you can allocate blocks >64Kb I'm now going to learn DJGPP (it is just C++ with DPMI).
Anyone knows how to use asm in that compiler?
asm { code }; doesn't work (parse error)

Share this post


Link to post
Share on other sites
I have never had problems accessing large arrays or pointers...i also use Watcom C/C++
i dont know if that would really matter,

you said
"memcpy(screen,buffer+65536,65536)
it's just the same as:
memcpy(screen,buffer,65536)"

I dont understand how they are the same..

because you are setting pages in video_memory you obviously have to copy it in segments, maybe i am thinking it all wrong and missing what you are trying to say, please explain though..Talk to ya later

Share this post


Link to post
Share on other sites
You both messed up a lot here.
bosjoh: in real mode or 16bit pm mode you are restricted with 64K limit. As you write in asm example, BC generates code that uses di register (or other index) to access data. And because di is 16bit register (max 65535 value), you can't access 65537 element of an array. Of caurce, you can write your own code to use edi as index instead of di.

Other way, as Syntax says, is to use
memcpy(vid_mem,buffer+65536,65536);
it's really not the same as
memcpy(vid_mem,buffer,65536)
because in first way you copy memory beginning from 65536 offset of your buffer, and in second, from beginning.

Also, if you will go into DJGPP (i recommend Watcom, really), you can use large arrays without restrictions, because you will run in 32bit flat model. But inline asm there is really beast, but powerful thing. You gotta read about it in online help.

Syntax: if you are using a great thing like Watcom C++, why you still using banks, when you can use LFB addressing? And i don't agree with your words that working directly with video mem is dangerous. I always do so.
Also, if you interested, i'm currently developing a lot of stuff for Watcom C++, which you can find on my homepage. There is also my new VFlat library, which will allow you to use LFB addressing wihtout VESA 2.0 standart.

That's it. If you have any more questions, ask me. Just i worked for all this stuff for a long time and know a lot.

FlyFire/CodeX
http://codexorg.webjump.com

Share this post


Link to post
Share on other sites
Yep i know that what I said about memcpy wasn't really true but it sure acts the same.
Now I'm using DJGPP and the memory management works fine.
But about Watcom: is it free and if so, where can I download it then (I hope it isn't too big too download)?

I'm really interested in that LFB addressing you talked about. Maybe you can send me an URL or something like that with more info.

Share this post


Link to post
Share on other sites
Good Point FlyFire and I am using the Great Thing know only as Watcom C/C++ I will check out the site, sorry for buggin ya bosjoh i was just confused at what was going on..see ya around

Share this post


Link to post
Share on other sites
I guess I should buy Watcom then.
Maybe they're selling a cheaper copy at school (despite the fact that the other students are still working in text-mode, counting numbers or something like that. And no teacher has ever heard of the word assembler).

Share this post


Link to post
Share on other sites
I'm having problems setting up a virtual screen for 640x480 VESA mode in Borland C++ 5.0. When I allocate 327680 Kb (I use the large memory model) the memset function doesn't work right. And I can't send the screen (in blocks of 64K) to the videocard properly. Anyone has some good routines?

Share this post


Link to post
Share on other sites