Kamikaze!
07-29-2002, 07:39 PM
I've been screwing around with mode 13h (dos graphics mode) in DJGPP, mainly because it's the only compilers I've found that would actually let into mode 13h without errors (I've tried Watcom, MSVC++, Borland and Dev-C++).
Anyway, compiling my code works perfectly in C but for some reason I get a strange error when I try to compile it in C++ and I have no idea what it means:
h:/djgpp/tmp/ccexr92a.o<.eh_frame+0x11>:vga.cpp: undefined reference to '___gxx_personality_v0'
collect2: ld returned 1 exit status
Does anybody have a clue what the problem is?
Strike
07-30-2002, 12:31 AM
Well, first of all, there's a reason they won't let you into that mode (I believe it requires not running in protected mode, but I'm not sure). If you want to do graphics, do it with a library for the actual OS you are using and not the OS that it sits on top of ;)
Secondly, without the code ... no way of telling what the problem is.
Kamikaze!
07-30-2002, 07:43 AM
Oops, sorry. As far as I know I haven't used anything C specific.
/***************
MODE 13h
****************/
#include <stdio.h>
#include <dpmi.h> // for dpmi functions
#include <go32.h> // _dos_ds
#include <sys/farptr.h> // far pointer support
#include <sys/movedata.h> //dosmemput
#include <conio.h> // getch()
#include <pc.h> // for outportb
/************
DEFINES
*************/
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 200
#define PALETTE_MASK 0x3C6
#define PALETTE_READ 0x3C7
#define PALETTE_WRITE 0x3C8
#define PALETTE_DATA 0x3C9
/*************
TYPEDEFS
**************/
typedef unsigned char byte;
/***************
STRUCTURES
****************/
// An RGB color structure
// Note: MCGA only supports 64 rgb values (0-63).
struct rgb_color
{
byte r,g,b;
};
// A 256 color palette structure
struct palette
{
struct rgb_color index[255];
} pal;
void set_mode(int);
void put_pixel(int, int, byte);
void set_palette_color(byte, struct rgb_color);
struct rgb_color get_palette_color(byte);
void draw_line(int, int, int, int, byte);
void fill_screen(byte*);
void draw_circle(int, int, int, byte);
// PALETTE FUNCTIONS
void vsync(void);
void load_pal(char*);
void apply_pal(void);
/*****************************************
MAIN
******************************************/
int main()
{
set_mode(0x13);
printf("Dit is een string.");
//put_pixel(100,100,2);
draw_line(25,25,66,66,2);
draw_circle(100,100,20,2);
getch();
fill_screen(0);
getch();
set_mode(0x3);
return 0;
}
/******************************************
Set video mode
0x12 = VGA graphics mode 640x480x16
0x13 = MCGA graphics mode 320x200x256
0x3 = text mode
*******************************************/
void set_mode(int mode)
{
__dpmi_regs r;
r.x.ax = mode;
__dpmi_int(0x10, &r);
}
/*****************************************
Put a pixel on the screen
color = palette index
******************************************/
void put_pixel(int x, int y, byte color)
{
_farpokeb(_dos_ds, 0xA0000+y*320+x, color);
}
/*****************************************
Set palette color
index = color index ranging from 0-255
red {
green { rgb value ranging from 0-63
blue {
******************************************/
void set_palette_color( byte index, struct rgb_color rgb)
{
vsync(); // sync with monitor
outportb(PALETTE_WRITE, index);
outportb(PALETTE_DATA, rgb.r);
outportb(PALETTE_DATA, rgb.g);
outportb(PALETTE_DATA, rgb.b);
}
/*****************************
GET PALETTE INDEX COLOR
******************************/
struct rgb_color get_palette_color (byte index)
{
struct rgb_color rgb;
outportb(PALETTE_READ, index);
outportb(PALETTE_DATA, rgb.r);
outportb(PALETTE_DATA, rgb.g);
outportb(PALETTE_DATA, rgb.b);
return rgb;
}
/*************************************
Vsync
Call before set_palette_color
**************************************/
void vsync()
{
/* wait until any previous retrace has ended */
do
{
} while (inportb(0x3DA) & 8);
/* wait until a new retrace has just begun */
do
{
} while (!(inportb(0x3DA) & 8));
}
/*********
LINE
**WILL BE CHANGED**
**********/
void draw_line(int x1,int y1,int x2,int y2, byte color)
{
int x,y,dx,dy,a;
// deltay deltax
dx = x2-x1;
dy = y2-y1;
a = dy/dx;
y = y1;
// decision int
//d = (dy << 2) - dx;
_farsetsel(_dos_ds);
for (x = x1; x < x2; x++) //INcrement x
{
y = (a*x) + y1; // y = ax + b
// draw the pixel
_farnspokeb(0xA0000+y*SCREEN_WIDTH+x, color);
}
}
/************
CIRCLE
(x,y) is the center of the circle
*************/
void draw_circle(int x, int y, int radius, byte color)
{
int d, x1,y1;
// initialize
d = 3 - (2 * radius);
x1 = 0;
y1 = radius;
for(x1=0;x1<=y1;x1++)
{
//draw 8 pixels
put_pixel(x + x1, y + y1, color);
put_pixel(x + x1, y - y1, color);
put_pixel(x - x1, y + y1, color);
put_pixel(x - x1, y - y1, color);
put_pixel(x + y1, y + x1, color);
put_pixel(x + y1, y - x1, color);
put_pixel(x - y1, y + x1, color);
put_pixel(x - y1, y - x1, color);
if(d < 0)
d += (x1 << 2) + 6;
else
{
d += ((x1 - y1) << 2) + 10;
y1--;
}
} //for
}
/**************************
FILL THE SCREEN
with color [index]
**DOESNT WORK YET**
***************************/
void fill_screen(byte* index)
{
/*int x,y;
vsync();
for(x=0;x<320;x++)
{
for(y=0;y<200;y++)
{
put_pixel(x,y,index);
}
}*/
byte screen_buffer[255];
dosmemput(screen_buffer,64000,0xA0000);
//_dosmemputb((int*)index,64000,0xA0000);
}
/*****************
LOAD PALETTE
palette size = 256 * 3 bytes
******************/
void load_pal(char* palfile)
{
byte i; //struct palette pal;
FILE* file = fopen(palfile,"rb");
fseek(file,0,SEEK_SET); // set pointer at start ofthe file
for(i=0;i<=255;i++) // loop through 256 palette entries
{
pal.index[i].r = fgetc(file); // get next 3 bytes and put them in the palette index.
pal.index[i].g = fgetc(file);
pal.index[i].b = fgetc(file);
}
}
/*******************
APPLY PALETTE
********************/
void apply_pal()
{
byte i;
vsync(); // sync with monitor to prevent flickering
for (i=0;i<=255;i++)
{
if(pal.index[i].r > 63) // if >63 dont apply palette color
{
outportb(0x3C8, i); //index
outportb(0x3C9, pal.index[i].r); //red
outportb(0x3C9, pal.index[i].g); //green
outportb(0x3C9, pal.index[i].b); //blue
}
}
}
DJGPP is only compiler that has the REGS union (or struct or whatever) in dos.h, and even then it's a different REGS :\
thought the C standard library was the same or almost the same everywhere (seeing as it is a STANDARD). Oh well.
Yeah, it has to do with protected mode and real mode.
Kamikaze!
08-03-2002, 11:58 AM
Well, thanks to your help I've figured it out myself. I didn't know you had to use gxx to compile C++ programs instead of gcc :rolleyes:
Edit: Unfortunately, gxx produces huge executables of over 1 mb and I get a bunch of crap when I try to optimize :( Why????
Edit 2: I forgot the -s compiler switch :\
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.