320X200 resolution works but 640X480 does not ???
Posted: Sun Feb 22, 2009 11:59 pm
hi ! first of all thank you to all the people on this forum, for guiding me previously on switching to VGA graphics mode, even when it was asked zillionth time.
I am stuck again and not able to move ahead ... I have the following code:
#include <kernel.h>
//define the ports , taken from //http://files.osdev.org/mirrors/geezer/o ... cs/modes.c
#define VGA_AC_INDEX 0x3C0
#define VGA_AC_WRITE 0x3C0
#define VGA_AC_READ 0x3C1
#define VGA_MISC_WRITE 0x3C2
#define VGA_SEQ_INDEX 0x3C4
#define VGA_SEQ_DATA 0x3C5
#define VGA_DAC_READ_INDEX 0x3C7
#define VGA_DAC_WRITE_INDEX 0x3C8
#define VGA_DAC_DATA 0x3C9
#define VGA_MISC_READ 0x3CC
#define VGA_GC_INDEX 0x3CE
#define VGA_GC_DATA 0x3CF
#define VGA_CRTC_INDEX 0x3D4 /* 0x3B4 */
#define VGA_CRTC_DATA 0x3D5 /* 0x3B5 */
#define VGA_INSTAT_READ 0x3DA
#define VGA_NUM_SEQ_REGS 5
#define VGA_NUM_CRTC_REGS 25
#define VGA_NUM_GC_REGS 9
#define VGA_NUM_AC_REGS 21
#define VGA_NUM_REGS (1+VGA_NUM_SEQ_REGS+VGA_NUM_CRTC_REGS+VGA_NUM_GC_REGS+VGA_NUM_AC_REGS)
//the vga identifiers
unsigned int VGA_width;
unsigned int VGA_height;
unsigned int VGA_bpp;
unsigned char *VGA_address;
void VGA_init(int width, int height, int bpp);
void write_registers(unsigned char *regs);
void VGA_clear_screen();
void vga_mode()
{
VGA_init(640,480,16);
}
/**
* CREATE THE REGISTER ARRAY TAKEN FROM http://wiki.osdev.org/VGA_Hardware
*/
unsigned char g_640x480x16[] =
{
/* MISC */
0xE3,
/* SEQ */
0x03, 0x01, 0x08, 0x00, 0x06,
/* CRTC */
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E,
0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3,
0xFF,
/* GC */
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0F,
0xFF,
/* AC */
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00
};
void write_registers(unsigned char *regs){
unsigned i;
/* write MISCELLANEOUS reg */
outportb(VGA_MISC_WRITE, *regs);
regs++;
/* write SEQUENCER regs */
for(i = 0; i < VGA_NUM_SEQ_REGS; i++)
{
outportb(VGA_SEQ_INDEX, i);
outportb(VGA_SEQ_DATA, *regs);
regs++;
}
/* unlock CRTC registers */
outportb(VGA_CRTC_INDEX, 0x03);
outportb(VGA_CRTC_DATA, inportb(VGA_CRTC_DATA) | 0x80);
outportb(VGA_CRTC_INDEX, 0x11);
outportb(VGA_CRTC_DATA, inportb(VGA_CRTC_DATA) & ~0x80);
/* make sure they remain unlocked */
regs[0x03] |= 0x80;
regs[0x11] &= ~0x80;
/* write CRTC regs */
for(i = 0; i < VGA_NUM_CRTC_REGS; i++)
{
outportb(VGA_CRTC_INDEX, i);
outportb(VGA_CRTC_DATA, *regs);
regs++;
}
/* write GRAPHICS CONTROLLER regs */
for(i = 0; i < VGA_NUM_GC_REGS; i++)
{
outportb(VGA_GC_INDEX, i);
outportb(VGA_GC_DATA, *regs);
regs++;
}
/* write ATTRIBUTE CONTROLLER regs */
for(i = 0; i < VGA_NUM_AC_REGS; i++)
{
(void)inportb(VGA_INSTAT_READ);
outportb(VGA_AC_INDEX, i);
outportb(VGA_AC_WRITE, *regs);
regs++;
}
/* lock 16-color palette and unblank display */
(void)inportb(VGA_INSTAT_READ);
outportb(VGA_AC_INDEX, 0x20);
outportb(0x3c8,0x00);
outportb(0x3c9,0x3f);
outportb(0x3c9,0x3f);
outportb(0x3c9,0x3f);
}
/**
* Clears the VGA screen
*/
void VGA_clear_screen(){
unsigned int x=0;
unsigned int y=0;
for(y=0; y<VGA_height; y++){
for(x=0; x<VGA_width; x++){
// Address 0xA0000 is (0,0)
VGA_address[VGA_width*y+x]=0x0f; // 8 bit/pixel
}
}
}
/**
* Note here the vga struct must have the width 320 and height of 200
* color mode is 256
*/
void VGA_init(int width, int height, int bpp){
//setup the vga struct
VGA_width=(unsigned int)width;
VGA_height=(unsigned int)height;
VGA_bpp=bpp; // Bit per pixel 8 bits to color 1 pixel.
VGA_address=0xA0000;
write_registers(g_640x480x16);
//clears the screen
VGA_clear_screen();
}
which i found through this forum itself. I am trying to switch to graphics mode in Protected mode with 640X480X16 resolution. It does switch to graphics mode but the VGA_clear_screen() is not able to clear the screen, the screen is still blurred, it has all junk appearance. It does not color the whole screen to one color as desired. It works when I pass an array with 320X200X256 register values, but not with 640X480X16. Am I still missing something in the code above.
I have read the documentation VGA_hardware and the Register properties in Wiki VGA_Resources but as a beginner I am not able to figure out the bug.
Please guide me on the error and how to rectify it.
I am stuck again and not able to move ahead ... I have the following code:
#include <kernel.h>
//define the ports , taken from //http://files.osdev.org/mirrors/geezer/o ... cs/modes.c
#define VGA_AC_INDEX 0x3C0
#define VGA_AC_WRITE 0x3C0
#define VGA_AC_READ 0x3C1
#define VGA_MISC_WRITE 0x3C2
#define VGA_SEQ_INDEX 0x3C4
#define VGA_SEQ_DATA 0x3C5
#define VGA_DAC_READ_INDEX 0x3C7
#define VGA_DAC_WRITE_INDEX 0x3C8
#define VGA_DAC_DATA 0x3C9
#define VGA_MISC_READ 0x3CC
#define VGA_GC_INDEX 0x3CE
#define VGA_GC_DATA 0x3CF
#define VGA_CRTC_INDEX 0x3D4 /* 0x3B4 */
#define VGA_CRTC_DATA 0x3D5 /* 0x3B5 */
#define VGA_INSTAT_READ 0x3DA
#define VGA_NUM_SEQ_REGS 5
#define VGA_NUM_CRTC_REGS 25
#define VGA_NUM_GC_REGS 9
#define VGA_NUM_AC_REGS 21
#define VGA_NUM_REGS (1+VGA_NUM_SEQ_REGS+VGA_NUM_CRTC_REGS+VGA_NUM_GC_REGS+VGA_NUM_AC_REGS)
//the vga identifiers
unsigned int VGA_width;
unsigned int VGA_height;
unsigned int VGA_bpp;
unsigned char *VGA_address;
void VGA_init(int width, int height, int bpp);
void write_registers(unsigned char *regs);
void VGA_clear_screen();
void vga_mode()
{
VGA_init(640,480,16);
}
/**
* CREATE THE REGISTER ARRAY TAKEN FROM http://wiki.osdev.org/VGA_Hardware
*/
unsigned char g_640x480x16[] =
{
/* MISC */
0xE3,
/* SEQ */
0x03, 0x01, 0x08, 0x00, 0x06,
/* CRTC */
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E,
0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3,
0xFF,
/* GC */
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0F,
0xFF,
/* AC */
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x01, 0x00, 0x0F, 0x00, 0x00
};
void write_registers(unsigned char *regs){
unsigned i;
/* write MISCELLANEOUS reg */
outportb(VGA_MISC_WRITE, *regs);
regs++;
/* write SEQUENCER regs */
for(i = 0; i < VGA_NUM_SEQ_REGS; i++)
{
outportb(VGA_SEQ_INDEX, i);
outportb(VGA_SEQ_DATA, *regs);
regs++;
}
/* unlock CRTC registers */
outportb(VGA_CRTC_INDEX, 0x03);
outportb(VGA_CRTC_DATA, inportb(VGA_CRTC_DATA) | 0x80);
outportb(VGA_CRTC_INDEX, 0x11);
outportb(VGA_CRTC_DATA, inportb(VGA_CRTC_DATA) & ~0x80);
/* make sure they remain unlocked */
regs[0x03] |= 0x80;
regs[0x11] &= ~0x80;
/* write CRTC regs */
for(i = 0; i < VGA_NUM_CRTC_REGS; i++)
{
outportb(VGA_CRTC_INDEX, i);
outportb(VGA_CRTC_DATA, *regs);
regs++;
}
/* write GRAPHICS CONTROLLER regs */
for(i = 0; i < VGA_NUM_GC_REGS; i++)
{
outportb(VGA_GC_INDEX, i);
outportb(VGA_GC_DATA, *regs);
regs++;
}
/* write ATTRIBUTE CONTROLLER regs */
for(i = 0; i < VGA_NUM_AC_REGS; i++)
{
(void)inportb(VGA_INSTAT_READ);
outportb(VGA_AC_INDEX, i);
outportb(VGA_AC_WRITE, *regs);
regs++;
}
/* lock 16-color palette and unblank display */
(void)inportb(VGA_INSTAT_READ);
outportb(VGA_AC_INDEX, 0x20);
outportb(0x3c8,0x00);
outportb(0x3c9,0x3f);
outportb(0x3c9,0x3f);
outportb(0x3c9,0x3f);
}
/**
* Clears the VGA screen
*/
void VGA_clear_screen(){
unsigned int x=0;
unsigned int y=0;
for(y=0; y<VGA_height; y++){
for(x=0; x<VGA_width; x++){
// Address 0xA0000 is (0,0)
VGA_address[VGA_width*y+x]=0x0f; // 8 bit/pixel
}
}
}
/**
* Note here the vga struct must have the width 320 and height of 200
* color mode is 256
*/
void VGA_init(int width, int height, int bpp){
//setup the vga struct
VGA_width=(unsigned int)width;
VGA_height=(unsigned int)height;
VGA_bpp=bpp; // Bit per pixel 8 bits to color 1 pixel.
VGA_address=0xA0000;
write_registers(g_640x480x16);
//clears the screen
VGA_clear_screen();
}
which i found through this forum itself. I am trying to switch to graphics mode in Protected mode with 640X480X16 resolution. It does switch to graphics mode but the VGA_clear_screen() is not able to clear the screen, the screen is still blurred, it has all junk appearance. It does not color the whole screen to one color as desired. It works when I pass an array with 320X200X256 register values, but not with 640X480X16. Am I still missing something in the code above.
I have read the documentation VGA_hardware and the Register properties in Wiki VGA_Resources but as a beginner I am not able to figure out the bug.
Please guide me on the error and how to rectify it.