delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/23/13:55:11

From: "Billy Johnson" <icekool AT erols DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: beginner mode13 question
Date: Wed, 23 Dec 1998 13:49:26 -0500
Lines: 98
Message-ID: <75re3i$hj2$1@winter.news.rcn.net>
References: <dMOe2.122$14 DOT 362 AT newsr2 DOT u-net DOT net>
X-Trace: atO5rUQOh4bM836il1JVT4pjnc7YTpSr8pAJ7gO+F9E=
X-Complaints-To: abuse AT rcn DOT com
NNTP-Posting-Date: 23 Dec 1998 18:51:30 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Max Erhard wrote in message ...
>I am having trouble getting mode13 programs to work. Plotting pixels using
>bios interupts works OK. But as soon as I try to directly address the video
>memory, I start to get horrible GPFs. I have tried A000, A0000 and A0000000
>as the address for video memory but no luck. I have read about special
>commands for near pointers or something but they need <sys/nearptr.h> and I
>do not have this file in my /include/sys folder, only farptr.h. Also is
>there a memory model setting for gcc that I need to know about.
>
>Errors look like this:-
>
>General Protection Fault at eip=211
>eax=00000001 ebx=00051d00 ecx=000a0141 edx=000a0141 esi=00000000
>edi=00000000
>ebp=00051d50 esp=00051d4c cs=bf ds=b7 es=b7 fs=b7 gs=b7 ss=c7 cr2=00001fec
>Call frame traceback EIPs:
>  0x00000211
>  0x00000285
>
>My code is:- (which should make a rainbow of all of the 256 colours on
>screen.)
>
>#include <stdio.h>
>#include <bios.h>
>#include <dos.h>
>
>int a;
>int dx;
>int dy;
>unsigned char *VGA=(unsigned char *)0xA0000L;
>
>void set_mode13()
>{
> union REGS regs;
> regs.h.ah = 0x00;
> regs.h.al = 0x13;
> int86(0x10,&regs,&regs);
>}
>
>void set_textmode()
>{
> union REGS regs;
> regs.h.ah = 0x00;
> regs.h.al = 0x03;
> int86(0x10,&regs,&regs);
>}
>
>void plot_pixel(int x, int y, int colour)
>{
> VGA[y*320+x]=colour;
>}
>
>void main ()
>{
> set_mode13();
> for(a=0;a<=256;a+1)
> {
>  for(dx=1;dx<=320;dx++)
>  {
>   for(dy=1;dy<=200;dy++)
>   {
>    plot_pixel(dx,dy,a);
>   }
>  }
> }
> set_textmode();
>}

Ok, all you need to do is make one "setmode" function. Here is a nice
example:

void setmode(int mode)
   {
       __dpmi_regs r;
       r.x.ax = mode;
       __dpmi_int(0x10, &r);
    }

That will take care of the set mode function. Just pass
0x13 for VGA256 and 0x3 for TEXT mode. Now for the put pixel function.

    All we have to do here is use some of the functions in the header file
<sys/farptr.h>. Here is a function that will take care of the put pixel
function.

void putpixel(int x, int y, int color)
   {
       _farpokeb(_dos_ds, ((y<<8) + (y<<6)) + x,          color);
    }

That should help. If you don't understand how it works, just e-mail me back
and I can explain what is happening.

                Later,
                Billy Johnson


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019