Mail Archives: djgpp/1997/10/18/16:02:26
At 12:16 10/17/1997 GMT, waage wrote:
>I am having problems copying info from a virtual screen allocated with
>malloc and copying it to the VGA 0xa000. The code looks like this,
>when compiled it says no errors but when I try to write to the virtual
>screen with my put_pixel it crashes.
>
>This is the function that allocates the virtual screen and (I hope)
>returns the address in memory where its located.
>
>unsigned long set_virtual(int w, int h) {
> unsigned long v_size = w * h;
> unsigned long vir_scr;
> (void *)vir_scr = malloc(v_size);
>
> if(vir_scr != NULL) {
> printf("Allocated memory for virtual screen.\n");
> return vir_scr;
> }
> else {
> printf("Unable to allocate %U bytes for virtual screen.\n",
>v_size);
> return 0;
> }
>}
>
>This is my put_pixel function, where is the address in memory that it
>wants to write to.
>
>void put_pixel(int where, int x, int y, unsigned char *col) {
> _farpokeb(_dos_ds, where*16+(x+(y*320)), col);
> }
>
>This does not work with the virtual screen. Can anyone tell me if it
>is because the virtual screen has a different selector than the a000
>(the info said that _dos_de has a limit of 1MB)? Does malloc(...) use
>memory above 1mb and do I need to use a different selector? I thought
>of this and came up with this:
That's it exactly. All your program's code and data is addressed relative to
the _my_ds() selector. You don't need to use farptr functions to access it.
>
>short get_virtual_discriptor(unsigned long vir_scr) {
> return(__dpmi_segment_to_descriptor(vir_scr));
> }
>
>void put_vir_pixel(short sel, unsigned long where, int x, int y,
>unsigned char col) {
> _farpokeb(sel, where*16+(x+(y*320)), col);
> }
Do this to put_pixel your vir_scr:
*(unsigned char *)vir_scr+x+(y*32) = col;
Nate Eldredge
eldredge AT ap DOT net
- Raw text -