video.c:
Code: Select all
/* Includes */
#include <hardware.h>
#include <memory.h>
#include <video.h>
/* Variables */
TVideoConsole videoConsoles[9];
int currentConsole;
/**
* Description:
* Initializes the virtual consoles.
*
* Parameters:
*
* Result:
*
*/
void VideoInitialize()
{
int index;
for(index = 0; index < 9; index++)
{
videoConsoles[index].color = 0x07;
videoConsoles[index].memory = (unsigned char *)0xB8000;
videoConsoles[index].x = 0;
videoConsoles[index].y = 0;
ClearScreen(' ', 0x07, index);
}
currentConsole = 0;
}
/**
* Description:
* Changes virtual consoles.
*
* Parameters:
* console - ID of the new virtual console to switch to.
*
* Result:
*
*/
void SwitchConsoles(int console)
{
unsigned char *where;
int index;
currentConsole = console;
MemorySet(
videoConsoles[console].memory,
videoConsoles[console].data,
4160
);
/*MemoryCopy(
videoConsoles[console].data,
videoConsoles[console].memory,
sizeof(videoConsoles[console].data)
);*/
VideoUpdateCursor(console);
}
/**
* Description:
* Changes the color for new characters printed to console.
*
* Parameters:
* color - New color value.
* console - Console that will be modified.
*
* Result:
*
*/
void SetVideoColor(unsigned char color, int console)
{
videoConsoles[console].color = color;
}
/**
* Description:
* Clears the screen of all data.
*
* Parameters:
* character - Character to clear the screen with.
* color - Color to print the character in.
* console - Console to clear.
*
* Result:
*
*/
void ClearScreen(unsigned char character, unsigned char color, int console)
{
unsigned char oldColor;
int index;
oldColor = videoConsoles[console].color;
SetVideoColor(color, console);
for(
index = 0;
(videoConsoles[console].x != 80) && (videoConsoles[console].y != 25);
index++
)
PrintChr(character, console);
SetVideoColor(oldColor, console);
videoConsoles[console].x = 0;
videoConsoles[console].y = 0;
return;
}
/**
* Description:
* Prints a character to the screen.
*
* Parameters:
* character - Character to print.
* console - Console to output to.
*
* Result:
*
*/
void PrintChr(const unsigned char character, int console)
{
unsigned char *where = (unsigned char *)(0xB8000 + (
videoConsoles[console].y *
80 +
videoConsoles[console].x
) * 2
);
*videoConsoles[console].data++ = character;
*videoConsoles[console].data++ = videoConsoles[console].color;
/*videoConsoles[console].data[(
videoConsoles[console].y *
80 +
videoConsoles[console].x
) * 2
] = character;
videoConsoles[console].data[(
videoConsoles[console].y *
80 +
videoConsoles[console].x + 1
) * 2
] = videoConsoles[console].color;*/
//if(console != currentConsole)
//{
// return;
//}
if(character >= ' ')
{
*where++ = character;
*where++ = videoConsoles[console].color;
videoConsoles[console].x++;
if(videoConsoles[console].x == 80)
{
videoConsoles[console].y++;
videoConsoles[console].x = 0;
}
}
else
{
switch(character)
{
case('\n'):
{
videoConsoles[console].x = 0;
videoConsoles[console].y++;
}
break;
case('\r'):
{
videoConsoles[console].x = 0;
}
break;
case('\t'):
{
videoConsoles[console].x = videoConsoles[console].y + 8;
}
break;
case(0x08):
{
if(videoConsoles[console].x != 0)
videoConsoles[console].x--;
}
break;
}
}
//VideoScroll(console);
VideoUpdateCursor(console);
}
/**
* Description:
* Prints a string to the screen.
*
* Parameters:
* string - String to print.
* console - Console to print to.
*
* Result:
*
*/
void PrintStr(char *string, int console)
{
for(; *string != '\0'; string++)
PrintChr(*string, console);
}
/**
* Description:
* Updates the hardware cursor.
*
* Parameters:
* console - Console to update.
*
* Result:
*
*/
void VideoUpdateCursor(int console)
{
unsigned where;
where = videoConsoles[console].y * 80 + videoConsoles[console].x;
HwWriteByte(0x3D4, 14);
HwWriteByte(0x3D5, where >> 8);
HwWriteByte(0x3D4, 15);
HwWriteByte(0x3D5, where);
}
/**
* Description:
* Scrolls the screen down to fit all of the text.
*
* Parameters:
*
* Result:
*
*/
void VideoScroll()
{
//
}
Code: Select all
/* Inclusion guard */
#ifndef __VIDEO_H__
#define __VIDEO_H__
/* Structures */
typedef struct
{
unsigned char color, *data, *memory;
unsigned x, y;
} TVideoConsole, *PVideoConsole;
/* Variables */
extern TVideoConsole videoConsoles[9];
extern int currentConsole;
/* Routines */
extern void VideoInitialize();
extern void SwitchConsoles(int console);
extern void SetVideoColor(unsigned char color, int console);
extern void ClearScreen(
unsigned char character,
unsigned char color,
int console
);
extern void PrintChr(const unsigned char character, int console);
extern void PrintStr(char *string, int console);
extern void VideoUpdateCursor(int console);
extern void VideoScroll();
#endif /* __VIDEO_H__ */
Thanks!
- Jeremiah
P.S.: I'm not aiming for POSIX compatibility, or compatibility with any other OS. That is why I've strayed so far from traditional function names (e.g. putc).