www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/02/14:58:43

From: mjiinas AT ix DOT netcom DOT com (Max)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Programming Graphics - colorrot.c [1/1]
Date: 2 Feb 1997 18:49:29 GMT
Organization: UN Spacy
Lines: 293
Message-ID: <5d2njp$gbt@sjx-ixn2.ix.netcom.com>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970202110034 DOT 23888W-100000 AT is>
NNTP-Posting-Host: atl-ga15-12.ix.netcom.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

--*- Boundary RALxMe_ZRHLIBVcyn_4s
Content-Type: Text/Plain; charset=US-ASCII

In article <Pine DOT SUN DOT 3 DOT 91 DOT 970202110034 DOT 23888W-100000 AT is>, eliz AT is DOT elta DOT co DOT il 
says...
>
>
>On 1 Feb 1997, Max wrote:
>
>
>These are all DOSisms.  Use `inp' and `outp' instead of `_inp' and 
>`_outp', and convert `_fmemset' to `memset'.
>
>Also, in the future make sure to tell what are the error messages that GCC
>prints.  It is not always easy to guess the nature of your problems if you
>don't post these details. 

	Okay...  here goes.  I have the code attached.  (Dunno if I did that 
properly since I'm also new to Newsgroups)  Also, compiling through rhide, 
these are the errors I get when trying to run the program that rhide reports to 
me.

Call frame traceback:
in function memset+31
colorrot.c(188) in function H_Line
colorrot.c(221) in function main
in function __crt1_startup+138

	The program compiles...  It just won't run.
--*- Boundary RALxMe_ZRHLIBVcyn_4s
Content-Type: Text/Plain; charset=US-ASCII


// I N C L U D E S ///////////////////////////////////////////////////////////

#include <io.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <bios.h>
#include <fcntl.h>
#include <memory.h>
#include <math.h>
#include <string.h>
#include <pc.h>

// D E F I N E S  ////////////////////////////////////////////////////////////

#define VGA256            0x13
#define TEXT_MODE         0x03

#define PALETTE_MASK        0x3c6
#define PALETTE_REGISTER_RD 0x3c7
#define PALETTE_REGISTER_WR 0x3c8
#define PALETTE_DATA        0x3c9

#define SCREEN_WIDTH      (unsigned int)320
#define SCREEN_HEIGHT     (unsigned int)200

// S T R U C T U R E S ///////////////////////////////////////////////////////

// this structure holds a RGB triple in three bytes

typedef struct RGB_color_typ
        {

        unsigned char red;    // red   component of color 0-63
        unsigned char green;  // green component of color 0-63
        unsigned char blue;   // blue  component of color 0-63

        } RGB_color, *RGB_color_ptr;


// P R O T O T Y P E S ///////////////////////////////////////////////////////

void Set_Palette_Register(int index, RGB_color_ptr color);

void Get_Palette_Register(int index, RGB_color_ptr color);

void Create_Cool_Palette(void);

void H_Line(int x1,int x2,int y,unsigned int color);

// G L O B A L S  ////////////////////////////////////////////////////////////

unsigned char *video_buffer = (char *)0xA0000000L; // vram byte ptr

// F U N C T I O N S /////////////////////////////////////////////////////////

void Set_Palette_Register(int index, RGB_color_ptr color)
{

// this function sets a single color look up table value indexed by index
// with the value in the color structure

// tell VGA card we are going to update a pallete register

outp(PALETTE_MASK,0xff);

// tell vga card which register we will be updating

outp(PALETTE_REGISTER_WR, index);

// now update the RGB triple, note the same port is used each time

outp(PALETTE_DATA,color->red);
outp(PALETTE_DATA,color->green);
outp(PALETTE_DATA,color->blue);

} // end Set_Palette_Color

///////////////////////////////////////////////////////////////////////////////

void Get_Palette_Register(int index, RGB_color_ptr color)
{

// this function gets the data out of a color lookup regsiter and places it
// into color

// set the palette mask register

outp(PALETTE_MASK,0xff);

// tell vga card which register we will be reading

outp(PALETTE_REGISTER_RD, index);

// now extract the data

color->red   = inp(PALETTE_DATA);
color->green = inp(PALETTE_DATA);
color->blue  = inp(PALETTE_DATA);

} // end Get_Palette_Color

///////////////////////////////////////////////////////////////////////////////

void Create_Cool_Palette(void)
{
// this function creates a cool palette. 64 shades of gray, 64 of red,
// 64 of green and finally 64 of blue.

RGB_color color;

int index;

// swip thru the color registers and create 4 banks of 64 colors

for (index=0; index < 64; index++)
    {

    // grays

    color.red   = index;
    color.green = index;
    color.blue  = index;

    Set_Palette_Register(index, (RGB_color_ptr)&color);

    // reds

    color.red   = index;
    color.green = 0;
    color.blue  = 0;

    Set_Palette_Register(index+64, (RGB_color_ptr)&color);

    // greens

    color.red   = 0;
    color.green = index;
    color.blue  = 0;

    Set_Palette_Register(index+128, (RGB_color_ptr)&color);

    // blues

    color.red   = 0;
    color.green = 0;
    color.blue  = index;

    Set_Palette_Register(index+192, (RGB_color_ptr)&color);

    } // end index

// make color 0 black

color.red   = 0;
color.green = 0;
color.blue  = 0;

Set_Palette_Register(0, (RGB_color_ptr)&color);

} // end Create_Cool_Palette

//////////////////////////////////////////////////////////////////////////////

void Set_Video_Mode(int mode)
{

// use the video interrupt 10h to set the video mode to the sent value

union REGS inregs,outregs;

inregs.h.ah = 0;                    // set video mode sub-function
inregs.h.al = (unsigned char)mode;  // video mode to change to

_int86(0x10, &inregs, &outregs);

} // end Set_Video_Mode

//////////////////////////////////////////////////////////////////////////////

void H_Line(int x1,int x2,int y,unsigned int color)
{
// draw a horizontal line useing the memset function
// note x2 > x1

memset((char *)(video_buffer + ((y<<8) + (y<<6)) + x1),color,x2-x1+1);

} // end H_Line

//M A I N /////////////////////////////////////////////////////////////////////

void main(void)
{

int index,           // loop var
    x1=150,          // x1 & x2 are the edges of the current piece of the road
    x2=170,
    y=0,             // y is the current y position of the piece of road
    curr_color=1;    // the current color being drawn

RGB_color color,color_1;

// set video mode to 320x200 256 color mode

Set_Video_Mode(VGA256);

// create the color palette

Create_Cool_Palette();

printf("Press any key to exit.");

// draw a road to nowhere

for (y=80; y<200; y++)
    {
    // draw next horizontal piece of road

    H_Line(x1,x2,y,curr_color);

    // make the road wider

    if (--x1 < 0)
       x1=0;

    if (++x2 > 319)
       x2=319;

    // next color please

    if (++curr_color>255)
       curr_color=1;

    } // end for

// wait for user to hit a key

while(!kbhit())
     {
     Get_Palette_Register(1,(RGB_color_ptr)&color_1);

     for (index=1; index<=254; index++)
         {
         Get_Palette_Register(index+1,(RGB_color_ptr)&color);
         Set_Palette_Register(index,(RGB_color_ptr)&color);

         } // end for

         Set_Palette_Register(255,(RGB_color_ptr)&color_1);

     } // end while

// go back to text mode

Set_Video_Mode(TEXT_MODE);

} // end main
--*- Boundary RALxMe_ZRHLIBVcyn_4s--

- Raw text -


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