🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Virtual screen in 640x480 mode

Started by
12 comments, last by bosjoh 24 years, 9 months ago
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

Advertisement
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.
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

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)

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

-Lucas
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

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.

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
-Lucas
Thanks a lot guys. I'm now searching for watcom and LFB (linear frame buffer).
bosjoh:
Watcom isn't free and it's very huge. I have full CD version of Watcom 11.0B, and it takes full 650MB. (but i also have ripped v10.0 which installation package takes approx 30-40 mb, don't remember).
You can read about it at www.sybase.com

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

This topic is closed to new replies.

Advertisement