127 lines
2.6 KiB
C
127 lines
2.6 KiB
C
// display.c
|
|
// Author: Josh Holtrop
|
|
// Date: 08/07/04
|
|
// Modified: 03/19/05
|
|
|
|
#include "fs/devices.h"
|
|
#include "char/vconsole.h"
|
|
#include "display.h"
|
|
#include "lang/lang.h"
|
|
#include "kernel.h"
|
|
#include "display/vesafb.h"
|
|
|
|
extern real_mode_param_t rm_params; // check if a video mode is activated
|
|
int display_activeConsole = -1; // start with no active console
|
|
display_t myDisplays[12]; // f1-f12 change displays
|
|
|
|
// initialization routine for display subsystem
|
|
int display_init()
|
|
{
|
|
minor_t vc;
|
|
int width = 80;
|
|
int height = 25;
|
|
int displayType = DISPLAY_CONSOLE;
|
|
if (rm_params.vid_addr) // framebuffer mode
|
|
{
|
|
vesafb_init(rm_params.width, rm_params.height, rm_params.bpp);
|
|
width = vesafb_getWidth();
|
|
height = vesafb_getHeight();
|
|
displayType = DISPLAY_FB;
|
|
}
|
|
if (( vc = vconsole_new(width, height) ))
|
|
{
|
|
myDisplays[11].type = displayType;
|
|
myDisplays[11].id = vc;
|
|
display_activeConsole = vc;
|
|
}
|
|
else
|
|
return -1;
|
|
int i;
|
|
for (i = 0; i < 6; i++)
|
|
{
|
|
if ((vc = vconsole_new(width, height)))
|
|
{
|
|
myDisplays[i].type = displayType;
|
|
myDisplays[i].id = vc;
|
|
}
|
|
else
|
|
return -2 - i;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
// activate the given display
|
|
int display_activate(u32_t id)
|
|
{
|
|
if (id > 11)
|
|
return -1;
|
|
switch (myDisplays[id].type)
|
|
{
|
|
case DISPLAY_CONSOLE:
|
|
case DISPLAY_FB:
|
|
display_activeConsole = myDisplays[id].id;
|
|
return vconsole_draw(display_activeConsole);
|
|
case DISPLAY_GRAPHICAL:
|
|
default:
|
|
return -2;
|
|
}
|
|
}
|
|
|
|
// routine to refresh a console window
|
|
int display_console_draw(minor_t id, int cursorPosition, u16_t *buffer, int buff_len)
|
|
{
|
|
if (id == display_activeConsole)
|
|
{
|
|
int i;
|
|
for (i = 0; i < 12; i++)
|
|
{
|
|
if (myDisplays[i].id == id)
|
|
{
|
|
if (myDisplays[i].type == DISPLAY_CONSOLE)
|
|
{
|
|
memcpyw((void *)CONSOLE_MEMORY, buffer, buff_len);
|
|
writeCursorPosition(cursorPosition);
|
|
return 0;
|
|
}
|
|
else if (myDisplays[i].type == DISPLAY_FB)
|
|
return vesafb_draw(buffer, buff_len, cursorPosition);
|
|
return -2;
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
// write a character to the screen
|
|
int display_console_put_char(minor_t id, u16_t c, int position)
|
|
{
|
|
if (id == display_activeConsole)
|
|
{
|
|
if (myDisplays[id].type == DISPLAY_CONSOLE)
|
|
*(u16_t *)(CONSOLE_MEMORY + (position << 1)) = c;
|
|
else if (myDisplays[id].type == DISPLAY_FB)
|
|
vesafb_draw_char(position, c);
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
// move the cursor on the screen
|
|
int display_console_update_cursor(minor_t id, int cursorPosition)
|
|
{
|
|
if (id == display_activeConsole)
|
|
{
|
|
if (myDisplays[id].type == DISPLAY_CONSOLE)
|
|
writeCursorPosition(cursorPosition);
|
|
else if (myDisplays[id].type == DISPLAY_FB)
|
|
vesafb_update_cursor(cursorPosition);
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|