Import backup from 2003-11-11

This commit is contained in:
Josh Holtrop 2003-11-11 22:00:00 -05:00
parent 57980293e6
commit 294b4b0e27
5 changed files with 89 additions and 101 deletions

View File

@ -4,9 +4,6 @@
//Version: 0.1.2
//Modified: 10/30/03
#define VXR video_mode.XResolution
#define VYR video_mode.YResolution
#include "k_defines.h" //#DEFINE's for kernel
#include "lib/string.h" //library string functions
@ -36,6 +33,7 @@ extern dword read_cr3();
#include "video.c"
dword timer = 0;
dword *videoMode;
//Main kernel initialization method
void k_init()
@ -46,7 +44,9 @@ void k_init()
remap_pics(0x20, 0x28);
init_timer();
mm_init();
video_init((ModeInfoBlock *) 0x90306);
videoMode = (dword *)0x90002;
if (*videoMode)
video_init((ModeInfoBlock *) 0x90306);
vmm_init();
mouse_init();
vmm_enable_paging();
@ -57,6 +57,7 @@ void k_init()
printf("HOS 0.1.2 - Kernel Size: %d kb\n", kernel_size()/1024);
printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem);
printf("Freem memory: %d bytes\n", mm_freemem());
dword key = 0;
for (;;)

View File

@ -14,6 +14,9 @@ void mouse_init()
outportb(0x64, 0xD4); //send command to mouse, not kbd
outportb(0x60, 0xF4); //enable data reporting
mouse_x = video_mode.XResolution >> 1;
mouse_y = video_mode.YResolution >> 1;
//outportb(0x64, 0xD4);
//outportb(0x60, 0xE7); //scaling 2:1
@ -39,14 +42,15 @@ void isr_mouse()
mouse_y -= adjy; //-= because screen y coordinates are opposite mouse y coordinates
if (mouse_inbuffer[0] & 0x01) //left button
{
video_pset(VXR/2+mouse_x, VYR/2+mouse_y, 0x00FFFFFF);
video_pset(mouse_x, mouse_y, 0x00FFFFFF);
printf("X: %d, Y: %d\n", mouse_x, mouse_y);
}
else
{
video_pset(VXR/2+mouse_x, VYR/2+mouse_y, 0x00000000);
video_pset(mouse_x, mouse_y, 0x00000000);
printf("X: %d, Y: %d\n", mouse_x, mouse_y);
}
video_copyBuffer();
}
}

View File

@ -3,8 +3,8 @@
// Author: Josh Holtrop
int mouse_x = 0;
int mouse_y = 0;
int mouse_x;
int mouse_y;
int mouse_bytesRead = 0;
byte mouse_inbuffer[16];

160
video.c
View File

@ -1,39 +1,37 @@
//video.c
// 08/13/03 Josh Holtrop
// Modified: 11/12/03
//Initialized the video mode information block video_mode and allocated double-buffer memory for graphics display
void video_init(ModeInfoBlock *mib)
{
video_mode = *mib;
switch(video_mode.BitsPerPixel)
{
case 16:
vid_ptr16 = (word *) video_mode.PhysBasePtr;
break;
case 24:
vid_ptr24 = (byte *) video_mode.PhysBasePtr;
break;
case 32:
vid_ptr32 = (dword *) video_mode.PhysBasePtr;
}
//Get a buffer region in memory for double-buffering video memory in 32bpp
vid_Buffer = mm_palloc((4*video_mode.XResolution*video_mode.YResolution)/4096+1, PID_KERNEL);
if ((dword)vid_Buffer == 0)
{
printf("ERROR - COULD NOT ALLOCATE MEMORY FOR VIDEO DOUBLE-BUFFER!!\n");
halt();
}
dword tot = ((video_mode.XResolution) * (video_mode.YResolution));
int a;
for (a = 0; a < tot; a++)
{
if (a < (tot / 4))
video_psetp(a, 0x00FF0000);
else if (a < (tot / 2))
video_psetp(a, 0x0000FF00);
vid_Buffer[a] = 0x00FF0000;
else if (a < (tot / 2))
vid_Buffer[a] = 0x0000FF00;
else if (a < ((tot * 3) / 4))
video_psetp(a, 0x000000FF);
vid_Buffer[a] = 0x000000FF;
else
video_psetp(a, 0x00FFFFFF);
vid_Buffer[a] = 0x00FFFFFF;
}
int VXR = video_mode.XResolution;
int VYR = video_mode.YResolution;
video_rectf(VXR*3/11, 0, VXR*4/11, VYR-1, 0x00000088); //test rectangles, draws "HOS"
video_rectf(VXR*7/11, 0, VXR*8/11, VYR-1, 0x00000088);
video_rectf(VXR/11, 0, VXR*2/11, VYR*2/5, 0x00000088);
@ -42,13 +40,6 @@ void video_init(ModeInfoBlock *mib)
video_rectf(VXR*9/11, VYR/5, VXR-1, VYR*2/5, 0x00000088);
video_rectf(VXR*8/11, VYR*3/5, VXR*10/11, VYR*4/5, 0x00000088);
video_vert(10, 10, 16, 0x00ffff00); //should be yellow 'H'
video_horiz(13, 10, 14, 0x00ffff00);
video_vert(14, 10, 16, 0x00ffff00);
video_horiz(10, 17, 21, 0x00ffff00);
video_vert(19, 10, 16, 0x00ffff00);
video_horiz(16, 17, 21, 0x00ffff00);
int b;
for (a = 0; a < 256; a++)
@ -65,118 +56,115 @@ void video_init(ModeInfoBlock *mib)
}
}
video_copyBuffer();
}
//Draws a horizontal line
void video_horiz(int y, int x1, int x2, dword color)
{
checkBoundsy(y);
checkBoundsx(x1);
checkBoundsx(x2);
if (x1 > x2)
{
int tmp = x2;
x2 = x1;
x1 = tmp;
x1 = tmp; //x2 >= x1 now
}
if (x2 < 0)
return;
if (x1 > video_mode.XResolution)
return;
if (x1 < 0)
x1 = 0;
if (x2 > video_mode.XResolution)
x2 = video_mode.XResolution;
int pixel = y*video_mode.XResolution+x1;
int a;
for (a = 0; a <= (x2-x1); a++)
for (; x1 <= x2; x1++)
{
video_psetp(pixel, color);
pixel++;
vid_Buffer[pixel++] = color;
}
}
//Draws a vertical line
void video_vert(int x, int y1, int y2, dword color)
{
checkBoundsx(x);
checkBoundsy(y1);
checkBoundsy(y2);
if (y1 > y2)
{
int tmp = y2;
y2 = y1;
y1 = tmp;
y1 = tmp; //y2 >= y1 now
}
if (y2 < 0)
return;
if (y1 > video_mode.YResolution)
return;
if (y1 < 0)
y1 = 0;
if (y2 > video_mode.YResolution)
y2 = video_mode.YResolution;
int pixel = y1*video_mode.XResolution+x;
int a;
for (a = 0; a <= (y2-y1); a++)
for (; y1 <= y2; y1++)
{
video_psetp(pixel, color);
vid_Buffer[pixel] = color;
pixel+=video_mode.XResolution;
}
}
//Draws a rectangle
void video_rect(int x1, int y1, int x2, int y2, dword color)
{
checkBoundsx(x1);
checkBoundsx(x2);
checkBoundsy(y1);
checkBoundsy(y2);
if (x2 < x1)
{
int tmp = x2;
x2 = x1;
x1 = tmp;
}
if (y2 < y1)
{
int tmp = y2;
y2 = y1;
y1 = tmp;
}
video_horiz(y1, x1, x2, color);
video_horiz(y2, x1, x2, color);
video_vert(x1, y1, y2, color);
video_vert(x2, y1, y2, color);
}
//Draws a filled rectangle
void video_rectf(int x1, int y1, int x2, int y2, dword color)
{
checkBoundsx(x1);
checkBoundsx(x2);
checkBoundsy(y1);
checkBoundsy(y2);
if (x2 < x1)
{
int tmp = x2;
x2 = x1;
x1 = tmp;
}
if (y2 < y1)
{
int tmp = y2;
y2 = y1;
y1 = tmp;
}
int a;
for (a = 0; a <= (y2-y1); a++)
video_horiz(y1+a, x1, x2, color);
for (; y1 <= y2; y1++)
video_horiz(y1, x1, x2, color);
}
//Draws a single pixel
inline void video_pset(int x, int y, dword color)
{
video_psetp(y*video_mode.XResolution+x, color);
if ((x < 0) || (x > video_mode.XResolution) || (y < 0) || (y > video_mode.YResolution))
return;
vid_Buffer[y*video_mode.XResolution+x] = color;
}
void video_psetp(int pixel, dword color)
//Copies double-buffer to VESA Linear Frame Buffer
void video_copyBuffer()
{
switch(video_mode.BitsPerPixel)
{
case 16:
vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<5) | ((((color>>16)&0xFF)>>3)<<11);
//vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>3)<<5) | ((((color>>16)&0xFF)>>3)<<10);
break;
case 24:
vid_ptr24[pixel*3] = color & 0xFF;
vid_ptr24[pixel*3+1] = (color>>8) & 0xFF;
vid_ptr24[pixel*3+2] = (color>>16) & 0xFF;
break;
case 32:
vid_ptr32[pixel] = color;
}
int pixel;
dword color;
for (pixel = 0; pixel < video_mode.XResolution*video_mode.YResolution; pixel++)
{
switch(video_mode.BitsPerPixel)
{
case 16:
color = vid_Buffer[pixel];
((word *)video_mode.PhysBasePtr)[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<5) | ((((color>>16)&0xFF)>>3)<<11);
//vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>3)<<5) | ((((color>>16)&0xFF)>>3)<<10); //15 bit mode?
break;
case 24:
color = vid_Buffer[pixel];
((byte *)video_mode.PhysBasePtr)[pixel*3] = color & 0xFF;
((byte *)video_mode.PhysBasePtr)[pixel*3+1] = (color>>8) & 0xFF;
((byte *)video_mode.PhysBasePtr)[pixel*3+2] = (color>>16) & 0xFF;
break;
case 32:
color = vid_Buffer[pixel];
((dword *)video_mode.PhysBasePtr)[pixel] = color;
}
}
}

View File

@ -1,6 +1,6 @@
//video.h
// 08/18/03 Josh Holtrop
// Modified: 11/12/03
void video_init();
void video_horiz(int y, int x1, int x2, dword color);
@ -9,11 +9,9 @@ void video_rect(int x1, int y1, int x2, int y2, dword color);
void video_rectf(int x1, int y1, int x2, int y2, dword color);
inline void video_pset(int x, int y, dword color);
void video_psetp(int pixel, dword color);
void video_copyBuffer();
#define checkBoundsx(x) (x<0 ? x=0 : (x>=video_mode.XResolution ? x=video_mode.XResolution-1 : 0))
#define checkBoundsy(x) (x<0 ? x=0 : (x>=video_mode.YResolution ? x=video_mode.YResolution-1 : 0))
typedef struct{
word ModeAttributes;
byte WinAAttributes;
@ -54,9 +52,6 @@ typedef struct{
} ModeInfoBlock;
ModeInfoBlock video_mode;
byte *vid_ptr24;
word *vid_ptr16;
dword *vid_ptr32;
dword *vid_Buffer;