Mail Archives: djgpp/1999/02/17/08:19:19
This is a multi-part message in MIME format.
--------------70D370026CF6
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
You have to include the "globals.h" in your files to de able to
use the global selector video_ds.
HTH
Ludvig Larsson
ps. Don't know if graphics_off() and graphics_on() works as they
should. But the initial call to init_graphics() (You must call
this function to get the video_ds right) witt (if possible)
put the mode inte graphics and init the selector(video_ds).
--------------70D370026CF6
Content-Type: text/plain; charset=us-ascii; name="globals.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="globals.h"
/***** Globals: *****/
/* include "globals.h to get access to video_ds !!! */
/* Graphics */
#define max_nr_of_sprites 2000
#define max_nr_of_bmps 300
short *double_buffer;
int *y_screen_start; /* lookup for plots */
int video_ds; /* lfb-start */
short *bmp[max_nr_of_bmps];
int nr_of_bmps;
typedef struct
{
int x,y,height;
int image;
}sprite_struct;
sprite_struct sprite[max_nr_of_sprites]; /* Is this okay? */
/* Mouse */
int mouse_x,mouse_y;
int mouse_x1,mouse_y1,mouse_x2,mouse_y2;
int mouse_on;
/* Maps & Levels */
short *compressed_map;
/* Div */
//void goto_error(char*);
--------------70D370026CF6
Content-Type: text/plain; charset=us-ascii; name="vesa.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="vesa.c"
#include <stdio.h>
#include <stdlib.h>
#include <pc.h>
#include <dpmi.h>
#include <go32.h>
#include <dos.h>
#include <sys/farptr.h>
#include <fcntl.h>
#include <share.h>
#include <sys/stat.h>
#include <sys/movedata.h>
#include <conio.h>
#include <float.h>
#include <string.h>
#include "globals.h"
#define BYTE unsigned char
void graphics_off(void)
{
__dpmi_regs reg;
reg.x.ax = 0x0003;
__dpmi_int(0x10,®);
/* Must maybe Free the descriptor? */
}
void goto_error(char *error_string)
{
graphics_off();
printf("%s\n",error_string);
getch();
exit(1);
}
typedef struct {
unsigned ModeAttributes;
unsigned granularity,startseg,farfunc;
short bscanline;
short XResolution;
short YResolution;
short charpixels;
unsigned bogus1,bogus2,bogus3,bogus4;
unsigned PhysBasePtr;
char bogus[228];
} ModeInfoBlock;
unsigned int ADDR;
int width,height;
ModeInfoBlock *get_mode_info(int mode)
{
static ModeInfoBlock info;
__dpmi_regs r;
/* Use the transfer buffer to store the results of VBE call */
r.x.ax = 0x4F01;
r.x.cx = mode;
r.x.es = __tb / 16;
r.x.di = 0;
__dpmi_int(0x10, &r);
if(r.h.ah) return 0;
dosmemget(__tb, sizeof(ModeInfoBlock), &info);
return &info;
}
void init_lfb_graphics(void)
{
__dpmi_meminfo info;
__dpmi_regs reg;
ModeInfoBlock *mb;
mb=get_mode_info(0x111);
if (!mb) {
printf("Get VESA mode info failed.\n");
exit(1);
}
if (!(mb->ModeAttributes & 0x80)) {
printf("Linear frame buffer not supported for VESA mode.\n");
exit(1);
}
width=mb->XResolution;
height=mb->YResolution;
info.size=width*height;
info.address=mb->PhysBasePtr;
if(__dpmi_physical_address_mapping(&info) == -1) {
printf("Physical mapping of address 0x%x failed!\n",mb->PhysBasePtr);
exit(2);
}
ADDR=info.address; /* Updated by above call */
printf("Vesa mode 0x111: %d x %d, linear frame: 0x%x\n",width,height,ADDR);
//delay(5500);
reg.x.ax=0x4f02;
reg.x.bx=0x4111; /* mode plus linear enable bit */
__dpmi_int(0x10,®); /* set the mode */
if(reg.h.al != 0x4f || reg.h.ah) {
printf("Mode set failed!\n");
exit(3);
}
}
int lfb_main(void)
{
int i;
printf("Checks mode 0x111(640x480x16bits) VBE 2.0 linear buffer support\n");
delay(3000);
init_lfb_graphics();
/* Note: Video mode probably doesn't support text writes at this point */
video_ds = __dpmi_allocate_ldt_descriptors(1);
__dpmi_set_segment_base_address(video_ds,ADDR);
ADDR = 0; /* basis now zero from selector */
__dpmi_set_segment_limit(video_ds,(width*height*2)|0xfff); /* *2(16bits) ? */
// _farpokew(video_ds,0,65535); /* put a pixel at top corner */
return(0);
}
void graphics_on(void) /* Does this work? */
{
lfb_main();
}
plot16(int x,int y,int color)
{
//if((x>=0)&&(x<640)&&(y>=0)&&(y<480)) /* Safety Check */
_farpokew(video_ds,x*2+y*1280,color);
}
void clear_screen(void)
{
int x,y;
// for(i=0;i<640*240;i+=4)
// _farpokel(video_ds,i,0);
for(y=0;y<480;y++)
for(x=0;x<640;x++)
plot16(x,y,0);
}
int init_graphics()
{
int i;
lfb_main();
y_screen_start=malloc(1024*4);
for(i=0;i<480;i++)
y_screen_start[i]=1280*i;
}
--------------70D370026CF6--
- Raw text -