delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/11/13:01:38

From: "Alex Barsamian" <bigalex AT worldnet DOT att DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Mode13h help...
Date: Thu, 11 Dec 1997 10:48:01 -0700
Organization: AT&T WorldNet Services
Lines: 101
Message-ID: <66p96i$rl3@bgtnsc03.worldnet.att.net>
References: <348F6F25 DOT 564D AT alpha DOT delta DOT edu>
NNTP-Posting-Host: 12.65.166.2
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Matt Kris wrote in message <348F6F25 DOT 564D AT alpha DOT delta DOT edu>...
>Howdy...
>
>This code is suppose to just plot a pixel. It will compile with DJGPP
>but will not run.  Please look through it and see what you's can come up
>with. Thanks
>
>/** *******************************************************************
>* fast.c                                                              *
>* written by Matt Kris                                                *
>**********************************************************************/
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <dos.h>
>
>#define VIDEO               0x10      /* the BIOS video interrupt. */
>#define SET_MODE            0x00      /* BIOS func  set video mode. */
>#define VGA_256_COLOR_MODE  0x13      /* use to set 256-color mode. */
>#define TEXT_MODE           0x03      /* use to set 80x25 text mode. */
>
>char *video_buffer=(char *)0xA0000000L;
>char color;
>int x, y;
>
>/*- set mode-------------------------------------------------------*/
>
>void set_mode(unsigned char mode)
>{
>  union REGS regs;
>
>  regs.h.ah = SET_MODE;
>  regs.h.al = mode;
>  int86(VIDEO, &regs, &regs);
>}
>
>/*- Plot_Pixel_Fast ------------*/
>
>void Plot_Pixel_Fast(int x, int y, char color)
>{
>  video_buffer[((y<<8) + (y<<6)) + x] = color;
>}
>
>/*- Main -----------------------*/
>
>int main(void)
>{
>  color = 8;
>  x = 50;
>  y = 50;
>
>  set_mode(VGA_256_COLOR_MODE);       /* set the video mode. */
>
>  Plot_Pixel_Fast(x,y,color);
>
>  while(!kbhit()){}         /* Waits for a key to be hit */
>
>  set_mode(TEXT_MODE);      /* Cuts back to text mode */
>
>  return 0;
>}

Use this code for your putpixel:

/* needed to use near pointers
   the usual word of caution applies here!
    with nearpointers enabled, memory protection is disabled, and you
    could quickly find yourself overwriting memory you *really* shouldn't
    have :-)
    */

#include <sys/nearptr.h>

void putpixel(int x, int y, int c) {

    /* need to recalculate screen address because it moves around.
        also, __djgpp_conventional_base is a macro, not a function
        call (somebody had it as __djgpp_conventional_base( );  )  */

    char *destination = 0xA0000 + __djgpp_conventional_base;

    /* plot the pixel */

    *(destination + x + (y<<8 + y <<6) = c;
}

That's it, and this should work as expected.  Before calling this, you must
call __djgpp_nearptr_enable() and afterwards, call
__djgpp_nearptr_disable().  These two are slow, so try to do all your
drawing at once (via linked list, etc) and call them as rarely as possible.

Thanks to Brennan Underwood for the entire idea of using nearpointers to
write to the screen.  I had been using
_dosmemput*(...) until just recently!

Alex




- Raw text -


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