* drv/vterm.c
* - Virtual Terminal - Initialisation and VFS Interface
*/
-#define DEBUG 0
+#define DEBUG 1
#include "vterm.h"
#include <fs_devfs.h>
#include <modules.h>
#define NUM_VTS 8
//#define DEFAULT_OUTPUT "BochsGA"
#define DEFAULT_OUTPUT "Vesa"
-#define FALLBACK_OUTPUT "x86_VGAText"
#define DEFAULT_INPUT "Keyboard"
#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
data[ val - arg ] = '\0';
val ++;
}
- Log_Debug("VTerm", "Argument '%s'", arg);
+ Log_Debug("VTerm", "Argument '%s'='%s'", opt, val);
if( strcmp(opt, "Video") == 0 ) {
if( !gsVT_OutputDevice )
// Apply Defaults
if(!gsVT_OutputDevice) gsVT_OutputDevice = (char*)DEFAULT_OUTPUT;
else if( Module_EnsureLoaded( gsVT_OutputDevice ) ) gsVT_OutputDevice = (char*)DEFAULT_OUTPUT;
- if( Module_EnsureLoaded( gsVT_OutputDevice ) ) gsVT_OutputDevice = (char*)FALLBACK_OUTPUT;
+ //if( Module_EnsureLoaded( gsVT_OutputDevice ) ) gsVT_OutputDevice = (char*)FALLBACK_OUTPUT;
if( Module_EnsureLoaded( gsVT_OutputDevice ) ) {
- Log_Error("VTerm", "Fallback video '%s' is not avaliable, giving up", FALLBACK_OUTPUT);
+ Log_Error("VTerm", "Video device '%s' is not avaliable, giving up", gsVT_OutputDevice);
return MODULE_ERR_MISC;
}
Log_Debug("VTerm", "Initialising nodes (and creating buffers)");
for( i = 0; i < NUM_VTS; i++ )
{
- gVT_Terminals[i].Mode = TERM_MODE_TEXT;
- gVT_Terminals[i].Flags = 0;
// gVT_Terminals[i].Flags = VT_FLAG_HIDECSR; //HACK - Stop all those memcpy calls
gVT_Terminals[i].CurColour = DEFAULT_COLOUR;
- gVT_Terminals[i].WritePos = 0;
- gVT_Terminals[i].AltWritePos = 0;
- gVT_Terminals[i].ViewPos = 0;
- gVT_Terminals[i].ScrollHeight = 0;
+ gVT_Terminals[i].Mode = PTYBUFFMT_TEXT;
// Initialise
VT_int_Resize( &gVT_Terminals[i], giVT_RealWidth, giVT_RealHeight );
- gVT_Terminals[i].Mode = PTYBUFFMT_TEXT;
char name[] = {'v','t','0'+i,'\0'};
- gVT_Terminals[i].PTY = PTY_Create(name, &gVT_Terminals[i],
- VT_PTYOutput, VT_PTYResize, VT_PTYModeset);
+ struct ptydims dims = {
+ .W = giVT_RealWidth / giVT_CharWidth,
+ .H = giVT_RealHeight / giVT_CharHeight,
+ .PW = giVT_RealWidth,
+ .PH = giVT_RealHeight
+ };
struct ptymode mode = {
.OutputMode = PTYBUFFMT_TEXT,
.InputMode = PTYIMODE_CANON|PTYIMODE_ECHO
};
- PTY_SetAttrib(gVT_Terminals[i].PTY, NULL, &mode, 0);
+ gVT_Terminals[i].PTY = PTY_Create(name, &gVT_Terminals[i],
+ VT_PTYOutput, VT_PTYResize, VT_PTYModeset,
+ &dims, &mode);
}
// Add to DevFS
// Set kernel output to VT0
Log_Debug("VTerm", "Setting kernel output to VT#0");
- Debug_SetKTerminal("/Devices/pts/vt0c");
+ Debug_SetKTerminal("/Devices/pts/vt0");
return MODULE_ERR_OK;
}
{
size_t maxlen = Term->Width * Term->Height * 4;
- if( Offset >= maxlen )
+ ENTER("pTerm xOffset xLength pBuffer", Term, Offset, Length, Buffer);
+
+ if( Offset >= maxlen ) {
+ LEAVE('-');
return ;
+ }
+ LOG("maxlen = 0x%x", maxlen);
Length = MIN(Length, maxlen - Offset);
// If the terminal is currently shown, write directly to the screen
if( Term == gpVT_CurTerm )
{
// Center the terminal vertically
- if( giVT_RealHeight > Term->Height )
+ if( giVT_RealHeight > Term->Height ) {
Offset += (giVT_RealHeight - Term->Height) / 2 * Term->Width * 4;
+ LOG("Altered offset 0x%x", Offset);
+ }
// If the terminal is not native width, center it horizontally
if( giVT_RealWidth > Term->Width )
// TODO: Fix to handle the final line correctly?
x = Offset/4; y = x / Term->Width; x %= Term->Width;
w = Length/4+x; h = w / Term->Width; w %= Term->Width;
-
+
+ LOG("(%i,%i) %ix%i", x, y, w, h);
+
// Center
x += (giVT_RealWidth - Term->Width) / 2;
dst_ofs = (x + y * giVT_RealWidth) * 4;
{
if( !Term->Buffer )
Term->Buffer = malloc( Term->Width * Term->Height * 4 );
+ LOG("Direct to cache");
// Copy to the local cache
memcpy( (char*)Term->Buffer + Offset, Buffer, Length );
}
+ LEAVE('-');
}
void VT_PTYOutput(void *Handle, size_t Length, const void *Data)
break;
case PTYBUFFMT_2DCMD:
// TODO: Impliment 2D commands
+ VT_int_Handle2DCmd(term, Length, Data);
break;
case PTYBUFFMT_3DCMD:
// TODO: Impliment 3D commands
{
tVTerm *term = Handle;
term->Mode = (Mode->OutputMode & PTYOMODE_BUFFMT);
+
+ memset(&term->Cmd2D, 0, sizeof(term->Cmd2D));
+
+ if( term == gpVT_CurTerm ) {
+ switch(term->Mode)
+ {
+ case PTYBUFFMT_TEXT:
+ VT_SetMode(VIDEO_BUFFMT_TEXT);
+ break;
+ default:
+ VT_SetMode(VIDEO_BUFFMT_FRAMEBUFFER);
+ break;
+ }
+ }
+
return 0;
}
LOG("Attempting VT_SetMode");
- if( gpVT_CurTerm->Mode == TERM_MODE_TEXT )
+ if( gpVT_CurTerm->Mode == PTYBUFFMT_TEXT )
{
VT_SetMode( VIDEO_BUFFMT_TEXT );
}