82 lines
1.3 KiB
C
82 lines
1.3 KiB
C
// console.c
|
|
// Author: Josh Holtrop
|
|
// Date: 08/07/04
|
|
|
|
#include "fs/devices.h"
|
|
#include "char/vconsole.h"
|
|
#include "console.h"
|
|
#include "lang/asmfuncs.h"
|
|
|
|
int activeConsole;
|
|
int numConsoles;
|
|
|
|
// initialization routine for console subsystem
|
|
int console_init(int num)
|
|
{
|
|
int i;
|
|
activeConsole = 0;
|
|
for (i = 0; i < num; i++)
|
|
{
|
|
minor_t vc = vconsole_new(80, 25);
|
|
if (vc)
|
|
{
|
|
numConsoles++;
|
|
if (!activeConsole)
|
|
activeConsole = vc;
|
|
}
|
|
}
|
|
if (numConsoles)
|
|
return 0;
|
|
return -1;
|
|
}
|
|
|
|
|
|
// activate a virtual console
|
|
int console_activate(minor_t id)
|
|
{
|
|
if (id > 0 && id <= numConsoles)
|
|
{
|
|
activeConsole = id;
|
|
return vconsole_draw(id);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
// routine to refresh a console window
|
|
int console_draw(minor_t id, int cursorPosition, u16_t *buffer)
|
|
{
|
|
if (id == activeConsole)
|
|
{
|
|
memcpyw((void *)CONSOLE_MEMORY, buffer, 2000);
|
|
writeCursorPosition(cursorPosition);
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
// write a character to the screen
|
|
int console_put_char(minor_t id, u16_t c, int position)
|
|
{
|
|
if (id == activeConsole)
|
|
{
|
|
*(u16_t *)(CONSOLE_MEMORY + (position << 1)) = c;
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
// move the cursor on the screen
|
|
int console_update_cursor(minor_t id, int cursorPosition)
|
|
{
|
|
if (id == activeConsole)
|
|
{
|
|
writeCursorPosition(cursorPosition);
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|