#include #include #include #include #include #define PI 3.1415926 #include #include #include #include #include //Set up for use of near pointers #include #ifdef __DJGPP unsigned char Buffer [307200]; #else unsigned char far *Buffer; #endif typedef unsigned char colorvalue; int _crt0_startup_flags = _CRT0_FLAG_NEARPTR | _CRT0_FLAG_NONMOVE_SBRK; struct VBE_Info { long VESASignature __attribute__((packed)); unsigned short Version __attribute__((packed)); char *OEMStringPTR __attribute__((packed)); long Capabilities __attribute__((packed)); long VideoModePTR __attribute__((packed)); unsigned short TotalMemory __attribute__((packed)); char Reserved [235] __attribute__((packed)); }; struct Mode_Info { unsigned short ModeAttributes __attribute__((packed)); unsigned char WinAAttributes __attribute__((packed)); unsigned char WinBAttributes __attribute__((packed)); unsigned short WinGranularity __attribute__((packed)); unsigned short WinSize __attribute__((packed)); unsigned short WinASegment __attribute__((packed)); unsigned short WinBSegment __attribute__((packed)); void *WinFuncPtr __attribute__((packed)); unsigned short BytesPerScanLine __attribute__((packed)); unsigned short XResolution __attribute__((packed)); unsigned short YResolution __attribute__((packed)); unsigned char XCharSize __attribute__((packed)); unsigned char YCharSize __attribute__((packed)); unsigned char NumberOfPlanes __attribute__((packed)); unsigned char BitsPerPixel __attribute__((packed)); char Dummy [14] __attribute__((packed)); unsigned int PhysBasePtr __attribute__((packed)); char Reserved [212] __attribute__((packed)); }; struct VBE_Info VBEInfo; struct Mode_Info ModeInfo; unsigned char *Screen; __dpmi_regs Regs; unsigned short BytesPerScanLine; char IsVBE (); char SupportVideoMode (unsigned short Mode); void VESAGetModeInfo (unsigned short Mode); char SetVESA (); char SetText (); void VESAPutPixel (long X, long Y, unsigned char Color); unsigned char VESAGetPixel (long X, long Y); void VertSync (); void FillScreen (colorvalue color); void ClearBuffer (); void DisplayBuffer (); void BufferPixel (int x, int y, colorvalue col); unsigned char BufferGetPixel (int x, int y); void Pal (colorvalue ColorNo, colorvalue R, colorvalue G, colorvalue B); void MakeCircle(int x, int y, int radius, colorvalue col); //This function checks whether a VESA BIOS is installed char IsVBE () { //Function 0 - Initialize Regs.x.ax = 0x4F00; Regs.x.es = __tb >> 4; Regs.x.di = 0; //Call VBE __dpmi_int (0x10, &Regs); //Copy the transfer buffer into the global struct dosmemget (__tb, sizeof (VBEInfo), &VBEInfo); //Return success if AX = 4F return Regs.x.ax == 0x4F; } //This functions checks whether a specific video mode is supported char SupportVideoMode (unsigned short Mode) { unsigned short TestMode; long List; List = (VBEInfo.VideoModePTR & 0xFFFF) + ((VBEInfo.VideoModePTR & 0xFFFF0000) >> 12); do { dosmemget (List, 2, &TestMode); //If the video mode is found in the list, return success if (TestMode == Mode) { return 1; } //Move on to the next entry in the list List += 2; //Until the end is reached } while (TestMode != 0xFFFF); //Return failure return 0; } void VESAGetModeInfo (unsigned short Mode) { // Use the transfer buffer to store the results of VBE call Regs.x.ax = 0x4F01; Regs.x.cx = Mode; Regs.x.es = __tb >> 4; Regs.x.di = 0; //Call VBE __dpmi_int (0x10, &Regs); //Copy the transfer buffer into the global struct dosmemget (__tb, sizeof (ModeInfo), &ModeInfo); } char SetVESA () { unsigned int Mode = 0x101; __dpmi_meminfo info; unsigned short Counter; char Success; if (Mode < 0x100) { Regs.x.ax = 0x0003; __dpmi_int (0x10, &Regs); return; } //Get information on the graphics mode VESAGetModeInfo (Mode); BytesPerScanLine = ModeInfo.BytesPerScanLine; //Allocate memory using DPMI info.size = ModeInfo.BytesPerScanLine * ModeInfo.YResolution; info.address = ModeInfo.PhysBasePtr; if (__dpmi_physical_address_mapping (&info) == -1) return 0; //Set up linear frame buffer Screen = (unsigned char *)(info.address + __djgpp_conventional_base); Regs.x.ax = 0x4F02; Regs.x.bx = (0x4000 | Mode); __dpmi_int (0x10, &Regs); return (Regs.x.ax == 0x4F); } char SetText () { unsigned int Mode = 0x03; __dpmi_meminfo info; unsigned short Counter; char Success; if (Mode < 0x100) { Regs.x.ax = 0x0003; __dpmi_int (0x10, &Regs); return; } //Get information on the graphics mode VESAGetModeInfo (Mode); BytesPerScanLine = ModeInfo.BytesPerScanLine; //Allocate memory using DPMI info.size = ModeInfo.BytesPerScanLine * ModeInfo.YResolution; info.address = ModeInfo.PhysBasePtr; if (__dpmi_physical_address_mapping (&info) == -1) return 0; //Set up linear frame buffer Screen = (unsigned char *)(info.address + __djgpp_conventional_base); Regs.x.ax = 0x4F02; Regs.x.bx = (0x4000 | Mode); __dpmi_int (0x10, &Regs); return (Regs.x.ax == 0x4F); } void VESAPutPixel (long X, long Y, unsigned char Color) { long OffSet; //Calculate linear offset in display memory OffSet = (BytesPerScanLine * Y) + X; //Set pixel Screen [OffSet] = Color; } unsigned char VESAGetPixel (long X, long Y) { long OffSet; //Calculate linear offset in display memory OffSet = (BytesPerScanLine * Y) + X; //Set pixel return Screen [OffSet]; } //Wait for a vertical sync void VertSync () { while (inp(0x3da) & 8); while (!(inp(0x3da) & 8)); } void FillScreen (colorvalue color) { memset (Screen, color, 307200); } //Clear buffer to 0 void ClearBuffer () { #ifdef __DJGPP memset (Buffer, 0, 307200); #else _fmemset (Buffer, 0, 307200); #endif } //Displays the buffer void DisplayBuffer () { #ifdef __DJGPP memcpy (Screen, Buffer, 307200); #else _fmemcpy (Screen, Buffer, 307200); #endif } void BufferPixel (int x, int y, colorvalue col) { long Offset; //Calculate linear offset in display memory Offset = (BytesPerScanLine * y) + x; //Set pixel Buffer[Offset] = col; } unsigned char BufferGetPixel (int x, int y) { long Offset; Offset = (BytesPerScanLine * y) + x; return (Buffer[Offset]); } //Palatte shift using ports etc. void Pal (colorvalue ColorNo, colorvalue R, colorvalue G, colorvalue B) { if (R > 63) R = 63; if (G > 63) G = 63; if (B > 63) B = 63; outp (0x03C8, ColorNo); outp (0x03C9, R); outp (0x03C9, G); outp (0x03C9, B); } //Draw a circle on the screen void MakeCircle(int x, int y, int radius, colorvalue col) { float x_result, y_result; double degrees = 0; for (degrees = 0; degrees <= 360; degrees+=.005) { x_result = (float)(x + cos((degrees*PI)/180) * radius); y_result = (float)(y + sin((degrees*PI)/180) * radius); if (x_result >=0 && y_result >=0) { VESAPutPixel(x_result, y_result, col); } } }