Sweden-Number/console/generic.c

186 lines
5.1 KiB
C
Raw Normal View History

1998-12-02 20:58:08 +01:00
/* generic.c */
/* Copyright 1999 - Joseph Pranevich */
1998-12-02 20:58:08 +01:00
/* This is a driver to implement, when possible, "high-level"
routines using only low level calls. This is to make it possible
to have accelerated functions for the individual drivers...
or to simply not bother with them. */
/* When creating new drivers, you need to assign all the functions that
that driver supports into the driver struct. If it is a supplementary
driver, it should make sure to perserve the old values. */
#include <stdio.h>
1998-12-02 20:58:08 +01:00
#include "console.h"
#include "config.h"
#include "debug.h"
DEFAULT_DEBUG_CHANNEL(console)
1999-01-03 17:15:12 +01:00
static void GENERIC_MoveLine(char row1, char row2, char col1, char col2);
static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
int attribute);
1998-12-02 20:58:08 +01:00
void GENERIC_Start()
{
/* Here, we only want to add a driver if there is not one already
defined. */
TRACE(console, "GENERIC_Start\n");
if (!driver.clearWindow)
driver.clearWindow = GENERIC_ClearWindow;
if (!driver.scrollUpWindow)
driver.scrollUpWindow = GENERIC_ScrollUpWindow;
if (!driver.scrollDownWindow)
driver.scrollDownWindow = GENERIC_ScrollDownWindow;
if (!driver.getCharacter)
driver.getCharacter = GENERIC_GetCharacter;
}
void GENERIC_ClearWindow(char row1, char col1, char row2, char col2,
int bg_color, int attribute)
{
1999-01-03 17:15:12 +01:00
char trow, tcol, x;
1998-12-02 20:58:08 +01:00
int old_refresh;
/* Abort if we have only partial functionality */
if (!(driver.getCursorPosition && driver.moveCursor && driver.write))
return;
old_refresh = CONSOLE_GetRefresh();
CONSOLE_SetRefresh(FALSE);
CONSOLE_GetCursorPosition(&trow, &tcol);
1999-01-03 17:15:12 +01:00
for (x = row1; x <= row2; x++)
GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
1998-12-02 20:58:08 +01:00
CONSOLE_MoveCursor(trow, tcol);
CONSOLE_SetRefresh(old_refresh);
}
void GENERIC_ScrollUpWindow(char row1, char col1, char row2, char col2,
char lines, int bg_color, int attribute)
{
1999-01-03 17:15:12 +01:00
/* Scroll Up Window: Characters go down */
1998-12-02 20:58:08 +01:00
char trow, tcol;
1999-01-03 17:15:12 +01:00
int old_refresh, x;
1998-12-02 20:58:08 +01:00
1999-01-03 17:15:12 +01:00
TRACE(console, "Scroll Up %d lines from %d to %d.\n", lines, row1,
row2);
1998-12-02 20:58:08 +01:00
/* Abort if we have only partial functionality */
if (!(driver.getCursorPosition && driver.moveCursor && driver.write
&& driver.getCharacterAtCursor && driver.clearWindow))
return;
1999-01-03 17:15:12 +01:00
/* Save initial state... */
1998-12-02 20:58:08 +01:00
old_refresh = CONSOLE_GetRefresh();
CONSOLE_SetRefresh(FALSE);
CONSOLE_GetCursorPosition(&trow, &tcol);
1999-01-03 17:15:12 +01:00
for (x = row1 + lines; x <= row2; x++)
1998-12-02 20:58:08 +01:00
{
1999-01-03 17:15:12 +01:00
GENERIC_MoveLine(x, x - lines, col1, col2);
GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
}
1998-12-02 20:58:08 +01:00
1999-01-03 17:15:12 +01:00
/* Restore State */
CONSOLE_MoveCursor(trow, tcol);
1998-12-02 20:58:08 +01:00
CONSOLE_SetRefresh(old_refresh);
}
void GENERIC_ScrollDownWindow(char row1, char col1, char row2, char col2,
char lines, int bg_color, int attribute)
{
1999-01-03 17:15:12 +01:00
/* Scroll Down Window: Characters go up */
1998-12-02 20:58:08 +01:00
1999-01-03 17:15:12 +01:00
char trow, tcol;
int old_refresh, x;
1998-12-02 20:58:08 +01:00
/* Abort if we have only partial functionality */
if (!(driver.getCursorPosition && driver.moveCursor && driver.write
&& driver.getCharacterAtCursor && driver.clearWindow))
return;
1999-01-03 17:15:12 +01:00
/* Save initial state... */
1998-12-02 20:58:08 +01:00
old_refresh = CONSOLE_GetRefresh();
CONSOLE_SetRefresh(FALSE);
CONSOLE_GetCursorPosition(&trow, &tcol);
1999-01-03 17:15:12 +01:00
for (x = row2; x >= row1 + lines; x--)
1998-12-02 20:58:08 +01:00
{
1999-01-03 17:15:12 +01:00
GENERIC_MoveLine(x, x + lines, col1, col2);
GENERIC_ClearLine(x, col1, col1, bg_color, attribute);
}
1998-12-02 20:58:08 +01:00
1999-01-03 17:15:12 +01:00
/* Restore State */
CONSOLE_MoveCursor(trow, tcol);
1998-12-02 20:58:08 +01:00
CONSOLE_SetRefresh(old_refresh);
}
char GENERIC_GetCharacter()
{
/* Keep getting keys until we get one with a char value */
char ch = (char) 0, scan;
while (!ch)
{
CONSOLE_GetKeystroke(&scan, &ch);
1998-12-02 20:58:08 +01:00
}
return ch;
}
1999-01-03 17:15:12 +01:00
static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
int attribute)
{
/* This function is here to simplify the logic of the scroll and clear
functions but may be useful elsewhere. If it can be used from
outside here, it should be made non-static */
int x;
TRACE(console, "Clear Line: %d from %d to %d.\n", row, col1, col2);
for (x = col1; x <= col2; x++)
{
CONSOLE_MoveCursor(row, x);
CONSOLE_Write(' ', 0, 0, 0);
}
/* Assume that the calling function will make sure that the cursor is
repositioned properly. If this becomes non-static, that will need to be
changed. */
}
static void GENERIC_MoveLine(char row1, char row2, char col1, char col2)
{
/* This function is here to simplify the logic of the scroll and clear
functions but may be useful elsewhere. If it can be used from
outside here, it should be made non-static */
int x;
int bg_color, fg_color, attribute;
char ch;
TRACE(console, "Move Line: Move %d to %d.\n", row1, row2);
for (x = col1; x <= col2; x++)
{
CONSOLE_MoveCursor(row1, x);
CONSOLE_GetCharacterAtCursor(&ch, &fg_color, &bg_color, &attribute);
CONSOLE_MoveCursor(row2, x);
CONSOLE_Write(ch, fg_color, bg_color, attribute);
}
/* Assume that the calling function will make sure that the cursor is
repositioned properly. If this becomes non-static, that will need to be
changed. */
}