也就是对 0xa0000-0xaffff这段内存地址中 写入颜色所对应的数值
bootpack.c中新增的代码
① 对所有颜色的宏定义
#define COL8_BLACK 0
#define COL8_BigRed 1
#define COL8_BigGreen 2
#define COL8_BigYellow 3
#define COL8_BigBlue 4
#define COL8_BigPurple 5
#define COL8_LightBrilliantBlue 6
#define COL8_WHITE 7
#define COL8_BigGrey 8
#define COL8_DarkRed 9
#define COL8_DarkGreen 10
#define COL8_DarkYellow 11
#define COL8_DarkCyan 12
#define COL8_DarkPurple 13
#define COL8_LightDarkBlue 14
#define COL8_DarkGrey 15
②新增加的 函数 用来画一个矩形
void DrawBoxFillColor8(unsigned char *pAdd, int nLineLen,
unsigned char Clolor8, int nX0, int nY0, int nX1, int nY1);
void DrawBoxFillColor8(unsigned char *pAdd, int nLineLen,
unsigned char Clolor8, int nX0, int nY0, int nX1, int nY1)
{
int x , y;
for(y = nY0; y <= nY1; y++)
{
for(x = nX0; x <= nX1; x++)
{
pAdd[y*nLineLen+x] = Clolor8;
}
}
return ;
}
DrawBoxFillColor8(pAdd, 320, COL8_BigGreen, 50, 50, 100,100);
bootpack.c 中所有代码
void io_hlt(void);//允许中断
void io_cli(void);//关中断
void io_out8(int nPort, int nData);//向端口 写入RGB
int io_load_eflags(void);//获取标志寄存器
void io_store_eflags(int nEflags);//恢复标志寄存器
#define COL8_BLACK 0
#define COL8_BigRed 1
#define COL8_BigGreen 2
#define COL8_BigYellow 3
#define COL8_BigBlue 4
#define COL8_BigPurple 5
#define COL8_LightBrilliantBlue 6
#define COL8_WHITE 7
#define COL8_BigGrey 8
#define COL8_DarkRed 9
#define COL8_DarkGreen 10
#define COL8_DarkYellow 11
#define COL8_DarkCyan 12
#define COL8_DarkPurple 13
#define COL8_LightDarkBlue 14
#define COL8_DarkGrey 15
void init_palette(void);//初始化调色板
void set_palette(int nStart, int nEnd, unsigned char * pRGB);
void DrawBoxFillColor8(unsigned char *pAdd, int nLineLen,
unsigned char Clolor8, int nX0, int nY0, int nX1, int nY1);
//320*200
void HariMain(void)
{
int i;
unsigned char *pAdd = (unsigned char *)0xa0000;
init_palette(); //设定调色板
/*for (i = 0; i <= 0xffff; i++)
{
*(pAdd+i) = i & 0x0f;
}*/
DrawBoxFillColor8(pAdd, 320, COL8_BigGreen, 50, 50, 100,100);
for (;;)
{
io_hlt();
}
}
void DrawBoxFillColor8(unsigned char *pAdd, int nLineLen,
unsigned char Clolor8, int nX0, int nY0, int nX1, int nY1)
{
int x , y;
for(y = nY0; y <= nY1; y++)
{
for(x = nX0; x <= nX1; x++)
{
pAdd[y*nLineLen+x] = Clolor8;
}
}
return ;
}
void init_palette(void)
{
static unsigned char Table_Rgb[16*3] =
{
0x00, 0x00, 0x00, /* 0:黑色 */
0xff, 0x00, 0x00, /* 1:亮红 */
0x00, 0xff, 0x00, /* 2:亮绿 */
0xff, 0xff, 0x00, /* 3:亮黄 */
0x00, 0x00, 0xff, /* 4:亮蓝 */
0xff, 0x00, 0xff, /* 5:亮紫 */
0x00, 0xff, 0xff, /* 6:浅亮蓝 */
0xff, 0xff, 0xff, /* 7:白 */
0xc6, 0xc6, 0xc6, /* 8:亮灰 */
0x84, 0x00, 0x00, /* 9:暗红 */
0x00, 0x84, 0x00, /* 10:暗绿 */
0x84, 0x84, 0x00, /* 11:暗黄 */
0x00, 0x00, 0x84, /* 12:暗青 */
0x84, 0x00, 0x84, /* 13:暗紫 */
0x00, 0x84, 0x84, /* 14:浅暗蓝 */
0x84, 0x84, 0x84 /* 15:暗灰 */
};
set_palette(0, 15, Table_Rgb);
return;
}
void set_palette(int nStart, int nEnd, unsigned char * pRGB)
{
int i , eflags;
eflags = io_load_eflags(); //记录中断许可标志的值
io_cli();//将中断许可标志位置0 不允许 产生中断
io_out8(0x03c8, nStart);//将想要设定的调色板号码 写入0X03c8
for(i = nStart; i <= nEnd; i++) //按照R G B 的顺序进行写入
{
io_out8(0x03c9, pRGB[0] / 4);
io_out8(0x03c9, pRGB[1] / 4);
io_out8(0x03c9, pRGB[2] / 4);
pRGB += 3;
}
io_store_eflags(eflags);//恢复 中断许可标志
return;
}

博客主要讲述向 0xa0000 - 0xaffff 内存地址写入颜色对应数值,还提及 bootpack.c 中新增代码,包括对所有颜色的宏定义和用于画矩形的新函数,最后给出 bootpack.c 所有代码。

1565

被折叠的 条评论
为什么被折叠?



