Skip to content

Commit

Permalink
Fix issue #62 DPMI function 0x800 cannot map more than 8Mb, that's wh…
Browse files Browse the repository at this point in the history
…y it crashes on cards with 16Mb or more. Fixes VESA crash on multiple video cards. Also related to #185
  • Loading branch information
viti95 committed Apr 3, 2024
1 parent faed325 commit abff702
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
39 changes: 15 additions & 24 deletions FASTDOOM/i_vesa.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ static void *LastPhysicalMapping = NULL;
static union REGS regs;
static struct SREGS sregs;

/*
* Some informations 'bout the last mode which was set
* These informations are required to compensate some differencies
* between the normal and direct PM calling methods
*/

static signed short vbelastbank = -1;
static unsigned long BytesPerScanline;
static unsigned char BitsPerPixel;

/*
* This function pointers will be initialized after you called
* VBE_Init. It'll be set to the realmode or protected mode call
Expand Down Expand Up @@ -138,17 +128,23 @@ void DPMI_UNMAP_PHYSICAL(void *p)
int386x(0x31, &regs, &regs, &sregs);
}

#define MEMORY_LIMIT (128*64*1024)

void *DPMI_MAP_PHYSICAL(void *p, unsigned long size)
{
// Limit memory to 8Mb, mapping 16Mb crashes
if (size > MEMORY_LIMIT)
size = MEMORY_LIMIT;

/* DPMI call 800h map physical memory*/
PrepareRegisters();
regs.w.ax = 0x0800;
regs.w.bx = (unsigned short)(((unsigned long)p) >> 16);
regs.w.cx = (unsigned short)(((unsigned long)p) & 0xffff);
regs.w.si = (unsigned short)(((unsigned long)size) >> 16);
regs.w.di = (unsigned short)(((unsigned long)size) & 0xffff);
regs.w.si = (unsigned short)(size >> 16);
regs.w.di = (unsigned short)(size & 0xffff);
int386x(0x31, &regs, &regs, &sregs);
return (void *)((regs.w.bx << 16) + regs.w.cx);
return (void *)(((unsigned long)regs.w.bx << 16) | regs.w.cx);
}

void VBE_Controller_Information(struct VBE_VbeInfoBlock *a)
Expand All @@ -174,12 +170,9 @@ int VBE_IsModeLinear(short Mode)
{
return 1;
}
#ifdef DISABLE_LFB
return 0;
#else

VBE_Mode_Information(Mode, &a);
return ((a.ModeAttributes & 128) == 128);
#endif
}

void VBE_SetDisplayStart(short x, short y)
Expand Down Expand Up @@ -243,8 +236,6 @@ void VBE_SetMode(short Mode, int linear, int clear)

// get the current mode-info block and set some parameters...
VBE_Mode_Information(Mode, &a);
BytesPerScanline = a.BytesPerScanline;
BitsPerPixel = a.BitsPerPixel;
}

char *VBE_GetVideoPtr(short mode)
Expand All @@ -261,7 +252,7 @@ char *VBE_GetVideoPtr(short mode)
LastPhysicalMapping = NULL;
}
LastPhysicalMapping = DPMI_MAP_PHYSICAL((void *)ModeInfo.PhysBasePtr,
(long)(VBE_Controller_Info_Pointer->TotalMemory) * 64 * 1024);
((unsigned long)VBE_Controller_Info_Pointer->TotalMemory) * 64 * 1024);
return (char *)LastPhysicalMapping;
}

Expand Down Expand Up @@ -315,7 +306,7 @@ static struct VBE_VbeInfoBlock vbeinfo;
static struct VBE_ModeInfoBlock vbemode;
unsigned short vesavideomode = 0xFFFF;
int vesalinear = -1;
int vesamemory = -1;
unsigned long vesamemory = -1;
char *vesavideoptr;

void VBE2_InitGraphics(void)
Expand All @@ -326,7 +317,7 @@ void VBE2_InitGraphics(void)

// Get VBE info
VBE_Controller_Information(&vbeinfo);
vesamemory = vbeinfo.TotalMemory * 64;
vesamemory = ((unsigned long)vbeinfo.TotalMemory) * 64;
// Get VBE modes
for (mode = 0; vbeinfo.VideoModePtr[mode] != 0xffff; mode++)
{
Expand All @@ -353,10 +344,10 @@ void VBE2_InitGraphics(void)
}
}
#if defined(MODE_VBE2_DIRECT)
// CHeck for available offscreen memory for tripple buffering + border on fourth vram buffer
// Check for available offscreen memory for tripple buffering + border on fourth vram buffer
if (vesamemory < SCREENWIDTH * SCREENHEIGHT * 4 / 1024)
{
I_Error("Not enough VRAM for triple buffering! (%i KB required, have %i KB)", SCREENWIDTH * SCREENHEIGHT * 4 / 1024, vesamemory);
I_Error("Not enough VRAM for triple buffering! (%i KB required, have %lu KB)", SCREENWIDTH * SCREENHEIGHT * 4 / 1024, vesamemory);
}
#endif
VBE_SetMode(vesavideomode, vesalinear, 1);
Expand Down
3 changes: 0 additions & 3 deletions FASTDOOM/i_vesa.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
/* Disables the Proteted Mode Extensions (buggy on some cards (e.g. matrox)) */
#define DISABLE_PM_EXTENSIONS

/* Disables the Linar Frame Buffer */
// #define DISABLE_LFB

/* Enables Debugging Option */
//#define DEBUG_VESA

Expand Down

0 comments on commit abff702

Please sign in to comment.