- Changed Video Mode setting routines to directly modify VGA registers instead on relying on Int 0x10 services.

- Removed unused code.

svn path=/trunk/; revision=8531
This commit is contained in:
Filip Navara 2004-03-04 18:49:58 +00:00
parent 1849adaa6b
commit eab00ba2a1
4 changed files with 122 additions and 237 deletions

View file

@ -1,129 +1,119 @@
#include <ntddk.h>
#include <rosrtl/string.h>
#include "vgavideo.h"
#define NDEBUG
#include <debug.h>
void outxay(PUSHORT ad, UCHAR x, UCHAR y)
static VGA_REGISTERS Mode12Regs =
{
USHORT xy = (x << 8) + y;
VideoPortWritePortUshort(ad, xy);
}
void setMode(VideoMode mode)
{
unsigned char x;
VideoPortWritePortUchar((PUCHAR)MISC, mode.Misc);
VideoPortWritePortUchar((PUCHAR)STATUS, 0);
VideoPortWritePortUchar((PUCHAR)FEATURE, mode.Feature);
for(x=0; x<5; x++)
{
outxay((PUSHORT)SEQ, mode.Seq[x], x);
}
VideoPortWritePortUshort((PUSHORT)CRTC, 0x11);
VideoPortWritePortUshort((PUSHORT)CRTC, (mode.Crtc[0x11] & 0x7f));
for(x=0; x<25; x++)
{
outxay((PUSHORT)CRTC, mode.Crtc[x], x);
}
for(x=0; x<9; x++)
{
outxay((PUSHORT)GRAPHICS, mode.Gfx[x], x);
}
x=VideoPortReadPortUchar((PUCHAR)FEATURE);
for(x=0; x<21; x++)
{
VideoPortWritePortUchar((PUCHAR)ATTRIB, x);
VideoPortWritePortUchar((PUCHAR)ATTRIB, mode.Attrib[x]);
}
x=VideoPortReadPortUchar((PUCHAR)STATUS);
VideoPortWritePortUchar((PUCHAR)ATTRIB, 0x20);
}
VideoMode Mode12 = {
0xa000, 0xe3, 0x00,
{0x03, 0x01, 0x0f, 0x00, 0x06 },
{0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x59, 0xea, 0x8c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3,
0xff},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff},
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f, 0x81, 0x00, 0x0f, 0x00, 0x00}
/* CRT Controller Registers */
{0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x59, 0xEA, 0x8C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3},
/* Attribute Controller Registers */
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F, 0x81, 0x00, 0x0F, 0x00, 0x00},
/* Graphics Controller Registers */
{0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x0F, 0xFF},
/* Sequencer Registers */
{0x03, 0x01, 0x0F, 0x00, 0x06},
/* Misc Output Register */
0xE3
};
void InitVGAMode()
VGA_REGISTERS TextModeRegs;
STATIC VOID FASTCALL
vgaSaveRegisters(PVGA_REGISTERS Registers)
{
int i;
VIDEO_X86_BIOS_ARGUMENTS vxba;
VP_STATUS vps;
// FIXME: Use Vidport to map the memory properly
vidmem = (char *)(0xd0000000 + 0xa0000);
memset(&vxba, 0, sizeof(vxba));
vxba.Eax = 0x0012;
vps = VideoPortInt10(NULL, &vxba);
int i;
// Get VGA registers into the correct state (mainly for setting up the palette registers correctly)
setMode(Mode12);
for (i = 0; i < sizeof(Registers->CRT); i++)
{
VideoPortWritePortUchar(CRTC, i);
Registers->CRT[i] = VideoPortReadPortUchar(CRTCDATA);
}
// Get the VGA into the mode we want to work with
WRITE_PORT_UCHAR((PUCHAR)GRA_I,0x08); // Set
WRITE_PORT_UCHAR((PUCHAR)GRA_D,0); // the MASK
WRITE_PORT_USHORT((PUSHORT)GRA_I,0x0205); // write mode = 2 (bits 0,1) read mode = 0 (bit 3)
i = READ_REGISTER_UCHAR(vidmem); // Update bit buffer
WRITE_REGISTER_UCHAR(vidmem, 0); // Write the pixel
WRITE_PORT_UCHAR((PUCHAR)GRA_I,0x08);
WRITE_PORT_UCHAR((PUCHAR)GRA_D,0xff);
for (i = 0; i < sizeof(Registers->Attribute); i++)
{
VideoPortReadPortUchar(STATUS);
VideoPortWritePortUchar(ATTRIB, i);
Registers->Attribute[i] = VideoPortReadPortUchar(ATTRIBREAD);
}
// Zero out video memory (clear a possibly trashed screen)
RtlZeroMemory(vidmem, 64000);
for (i = 0; i < sizeof(Registers->Graphics); i++)
{
VideoPortWritePortUchar(GRAPHICS, i);
Registers->Graphics[i] = VideoPortReadPortUchar(GRAPHICSDATA);
}
vgaPreCalc();
for (i = 0; i < sizeof(Registers->Sequencer); i++)
{
VideoPortWritePortUchar(SEQ, i);
Registers->Sequencer[i] = VideoPortReadPortUchar(SEQDATA);
}
Registers->Misc = VideoPortReadPortUchar(MISC);
}
VOID VGAResetDevice(OUT PSTATUS_BLOCK StatusBlock)
STATIC VOID FASTCALL
vgaSetRegisters(PVGA_REGISTERS Registers)
{
HANDLE Event;
OBJECT_ATTRIBUTES Attr;
UNICODE_STRING Name = ROS_STRING_INITIALIZER(L"\\TextConsoleRefreshEvent");
NTSTATUS Status;
VIDEO_X86_BIOS_ARGUMENTS vxba;
VP_STATUS vps;
ULONG ThreadRelease = 1;
CHECKPOINT;
Event = 0;
int i;
memset(&vxba, 0, sizeof(vxba));
vxba.Eax = 0x0003;
vps = VideoPortInt10(NULL, &vxba);
memset(&vxba, 0, sizeof(vxba));
vxba.Eax = 0x1112;
vps = VideoPortInt10(NULL, &vxba);
InitializeObjectAttributes( &Attr, &Name, 0, 0, 0 );
Status = ZwOpenEvent( &Event, STANDARD_RIGHTS_ALL, &Attr );
if( !NT_SUCCESS( Status ) )
DbgPrint( "VGA: Failed to open refresh event\n" );
else {
ZwSetEvent( Event, &ThreadRelease );
ZwClose( Event );
}
/* Update misc output register */
VideoPortWritePortUchar(MISC, Registers->Misc);
/* Synchronous reset on */
VideoPortWritePortUchar(SEQ, 0x00);
VideoPortWritePortUchar(SEQDATA, 0x01);
/* Write sequencer registers */
for (i = 1; i < sizeof(Registers->Sequencer); i++)
{
VideoPortWritePortUchar(SEQ, i);
VideoPortWritePortUchar(SEQDATA, Registers->Sequencer[i]);
}
/* Synchronous reset off */
VideoPortWritePortUchar(SEQ, 0x00);
VideoPortWritePortUchar(SEQDATA, 0x03);
/* Deprotect CRT registers 0-7 */
VideoPortWritePortUchar(CRTC, 0x11);
VideoPortWritePortUchar(CRTCDATA, Registers->CRT[0x11] & 0x7f);
/* Write CRT registers */
for (i = 0; i < sizeof(Registers->CRT); i++)
{
VideoPortWritePortUchar(CRTC, i);
VideoPortWritePortUchar(CRTCDATA, Registers->CRT[i]);
}
/* Write graphics controller registers */
for (i = 0; i < sizeof(Registers->Graphics); i++)
{
VideoPortWritePortUchar(GRAPHICS, i);
VideoPortWritePortUchar(GRAPHICSDATA, Registers->Graphics[i]);
}
/* Write attribute controller registers */
for (i = 0; i < sizeof(Registers->Attribute); i++)
{
VideoPortReadPortUchar(STATUS);
VideoPortWritePortUchar(ATTRIB, i);
VideoPortWritePortUchar(ATTRIB, Registers->Attribute[i]);
}
}
VOID
InitVGAMode()
{
vgaSaveRegisters(&TextModeRegs);
vgaSetRegisters(&Mode12Regs);
}
VOID
VGAResetDevice(OUT PSTATUS_BLOCK StatusBlock)
{
vgaSetRegisters(&TextModeRegs);
}

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.1 2004/01/10 14:39:21 navaraf Exp $
# $Id: makefile,v 1.2 2004/03/04 18:49:58 navaraf Exp $
PATH_TO_TOP = ../../../..
@ -12,8 +12,7 @@ TARGET_CFLAGS = -Werror -Wall
TARGET_OBJECTS = \
initvga.o \
vgamp.o \
vgavideo.o
vgamp.o
include $(PATH_TO_TOP)/rules.mak

View file

@ -1,94 +0,0 @@
#include "vgavideo.h"
div_t div(int num, int denom)
{
div_t r;
if (num > 0 && denom < 0) {
num = -num;
denom = -denom;
}
r.quot = num / denom;
r.rem = num % denom;
if (num < 0 && denom > 0)
{
if (r.rem > 0)
{
r.quot++;
r.rem -= denom;
}
}
return r;
}
int mod(int num, int denom)
{
div_t dvt = div(num, denom);
return dvt.rem;
}
VOID vgaPreCalc()
{
ULONG j;
startmasks[1] = 127;
startmasks[2] = 63;
startmasks[3] = 31;
startmasks[4] = 15;
startmasks[5] = 7;
startmasks[6] = 3;
startmasks[7] = 1;
startmasks[8] = 255;
endmasks[0] = 128;
endmasks[1] = 192;
endmasks[2] = 224;
endmasks[3] = 240;
endmasks[4] = 248;
endmasks[5] = 252;
endmasks[6] = 254;
endmasks[7] = 255;
endmasks[8] = 255;
for(j=0; j<80; j++)
{
maskbit[j*8] = 128;
maskbit[j*8+1] = 64;
maskbit[j*8+2] = 32;
maskbit[j*8+3] = 16;
maskbit[j*8+4] = 8;
maskbit[j*8+5] = 4;
maskbit[j*8+6] = 2;
maskbit[j*8+7] = 1;
bit8[j*8] = 7;
bit8[j*8+1] = 6;
bit8[j*8+2] = 5;
bit8[j*8+3] = 4;
bit8[j*8+4] = 3;
bit8[j*8+5] = 2;
bit8[j*8+6] = 1;
bit8[j*8+7] = 0;
}
for(j=0; j<480; j++)
{
y80[j] = j*80;
}
for(j=0; j<640; j++)
{
xconv[j] = j >> 3;
}
}
void vgaSetWriteMode(char mode)
{
VideoPortWritePortUchar((PUCHAR)GRA_I, 0x03);
VideoPortWritePortUchar((PUCHAR)GRA_D, mode);
}
void vgaSetColor(int cindex, int red, int green, int blue)
{
VideoPortWritePortUchar((PUCHAR)0x03c8, cindex);
VideoPortWritePortUchar((PUCHAR)0x03c9, red);
VideoPortWritePortUchar((PUCHAR)0x03c9, green);
VideoPortWritePortUchar((PUCHAR)0x03c9, blue);
}

View file

@ -6,36 +6,26 @@
#define VGA_OR 16
#define VGA_XOR 24
//This is in mingw standard headers
//typedef struct { int quot, rem; } div_t;
#define MISC (PUCHAR)0x3c2
#define SEQ (PUCHAR)0x3c4
#define SEQDATA (PUCHAR)0x3c5
#define CRTC (PUCHAR)0x3d4
#define CRTCDATA (PUCHAR)0x3d5
#define GRAPHICS (PUCHAR)0x3ce
#define GRAPHICSDATA (PUCHAR)0x3cf
#define ATTRIB (PUCHAR)0x3c0
#define ATTRIBREAD (PUCHAR)0x3c1
#define STATUS (PUCHAR)0x3da
#define PELMASK (PUCHAR)0x3c6
#define PELINDEX (PUCHAR)0x3c8
#define PELDATA (PUCHAR)0x3c9
#define FEATURE (PUCHAR)0x3da
int maskbit[640], y80[480], xconv[640], bit8[640], startmasks[8], endmasks[8];
char* vidmem;
#define MISC 0x3c2
#define SEQ 0x3c4
#define CRTC 0x3d4
#define GRAPHICS 0x3ce
#define FEATURE 0x3da
#define ATTRIB 0x3c0
#define STATUS 0x3da
#define SEQ_I 0x3C4 /* Sequencer Index */
#define SEQ_D 0x3C5 /* Sequencer Data Register */
#define GRA_I 0x3CE /* Graphics Controller Index */
#define GRA_D 0x3CF /* Graphics Controller Data Register */
typedef struct _VideoMode {
unsigned short VidSeg;
unsigned char Misc;
unsigned char Feature;
unsigned short Seq[6];
unsigned short Crtc[25];
unsigned short Gfx[9];
unsigned char Attrib[21];
} VideoMode;
VOID vgaPreCalc();
typedef struct _VGA_REGISTERS
{
UCHAR CRT[24];
UCHAR Attribute[21];
UCHAR Graphics[9];
UCHAR Sequencer[5];
UCHAR Misc;
} VGA_REGISTERS, *PVGA_REGISTERS;