Category : Files from Magazines
Archive   : DDJ9407C.ZIP
Filename : RAYSVGA.CPP
/*** (C) Copyright A.MANGEN 1994 ***/
/***********************************************************************/
/*** PROJECT : RAY TRACING PROGRAM ***/
/*** PROGRAM NAME: RAYSVGA.CPP ***/
/*** VERSION : 1.1 ***/
/***-----------------------------------------------------------------***/
/*** DESCRIPTION : VESA SVGA Interface Routines ***/
/***********************************************************************/
#include
#include
#include
#include "raysvga.h"
int VESA_CurrentBank=0;
int VESA_GetMaxX=0;
int VESA_GetMaxY=0;
unsigned char far *VESA_Screen = (unsigned char *) MK_FP(0xA000,0);
struct { char R,G,B; } VESA_Palette[256];
int VESA_SetMode(int Mode,int GetMaxX,int GetMaxY)
{ union REGS inregs,outregs;
inregs.x.ax=0x4F02; // Set SVGA Mode
inregs.x.bx=Mode; // Mode
int86(0x10,&inregs,&outregs);
VESA_CurrentBank=0; // Initialize variables
VESA_GetMaxX=GetMaxX;
VESA_GetMaxY=GetMaxY;
memset(&VESA_Palette,0,sizeof(VESA_Palette));
return(outregs.x.ax==VESA_OK);
}
int VESA_Close()
{ union REGS inregs,outregs;
inregs.x.ax=0x4F02; // Set SVGA Mode
inregs.x.bx=3; // Mode
int86(0x10,&inregs,&outregs);
VESA_CurrentBank=VESA_GetMaxX=VESA_GetMaxY=0;
return(outregs.x.ax==VESA_OK);
}
int VESA_GetMode()
{ union REGS inregs,outregs;
inregs.x.ax=0x4F03; // Get SVGA Mode
int86(0x10,&inregs,&outregs);
return(outregs.x.ax==VESA_OK?outregs.x.bx:FALSE);
}
int VESA_SetBank(int N)
{ union REGS inregs,outregs;
inregs.x.ax=0x4F05; // Video Memory Window Control
inregs.x.bx=0x0; // Select window / Window 0
inregs.x.dx=VESA_CurrentBank=N;
int86(0x10,&inregs,&outregs);
return(outregs.x.ax==VESA_OK);
}
void VESA_PutPixel(int x,int y,int color)
{ long ofs,B;
ofs=(long) VESA_GetMaxX * (long) y + (long) x;
if((B=ofs>>16)!=VESA_CurrentBank)
VESA_SetBank((int) B); // Set SVGA Memory Bank
VESA_Screen[(int) (ofs & 0xFFFFL)]=color; // Direct Memory Addressing
}
void VESA_WritePixel(int x,int y,int n,char *color)
{ long ofs,B;
ofs=(long) VESA_GetMaxX * (long) y + (long) x;
if((B=ofs>>16)!=VESA_CurrentBank)
VESA_SetBank((int) B); // Set SVGA Memory Bank
ofs&=0xFFFFL;
if(ofs+n<=0x10000L)
_fmemcpy(VESA_Screen+ofs,color,n); // Direct Memory Addressing
else
{ _fmemcpy(VESA_Screen+ofs,color,0x10000L-ofs);
VESA_SetBank((int) B+1);
_fmemcpy(VESA_Screen,color+0x10000L-ofs,ofs+n-0x10000L);
}
}
void VESA_ShowPalette() // Display active palette
{ for(int y=0;y<256;y++)
for(int x=0;x
(void) getchar();
}
void VESA_LoadBlackPalette() // Black palette
{ memset(&VESA_Palette,0,sizeof(VESA_Palette));
}
void VESA_LoadBWPalette() // Grey scale palette
{ memset(&VESA_Palette,0,sizeof(VESA_Palette));
for(int i=0;i<256;i++)
VESA_Palette[i].R=VESA_Palette[i].G=VESA_Palette[i].B=i/4;
}
void VESA_LoadColor(int i,int R,int G,int B) // Load a color in palette
{ VESA_Palette[i].R=R;
VESA_Palette[i].G=G;
VESA_Palette[i].B=B;
}
void VESA_ActivatePalette() // Transfer in-memory palette
{ union REGS inregs,outregs; // to VGA video palette
struct SREGS segregs;
inregs.x.ax=0x1012; // Set Palette
inregs.x.bx=0; // Start of colormap
inregs.x.cx=256; // Number of colors
inregs.x.dx=FP_OFF(VESA_Palette);
segregs.es=FP_SEG(VESA_Palette);
int86x(0x10,&inregs,&outregs,&segregs);
}
void Beep() // Sound speaker
{ sound(440); delay(50); nosound();
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/