/*
* Acess2 Virtual Terminal Driver
*/
-#define DEBUG 1
+#define DEBUG 0
#include <acess.h>
#include <fs_devfs.h>
#include <modules.h>
#define NUM_VTS 8
#define MAX_INPUT_CHARS32 64
#define MAX_INPUT_CHARS8 (MAX_INPUT_CHARS32*4)
-#define VT_SCROLLBACK 1 // 2 Screens of text
+#define VT_SCROLLBACK 2 // 2 Screens of text
//#define DEFAULT_OUTPUT "VGA"
-#define DEFAULT_OUTPUT "BochsGA"
+//#define DEFAULT_OUTPUT "BochsGA"
+#define DEFAULT_OUTPUT "Vesa"
#define DEFAULT_INPUT "PS2Keyboard"
#define DEFAULT_WIDTH 80
#define DEFAULT_HEIGHT 25
int Flags; //!< Flags (see VT_FLAG_*)
short Width; //!< Virtual Width
short Height; //!< Virtual Height
- short RealWidth; //!< Real Width
- short RealHeight; //!< Real Height
int ViewPos; //!< View Buffer Offset (Text Only)
int WritePos; //!< Write Buffer Offset (Text Only)
Uint32 CurColour; //!< Current Text Colour
- char Name[2]; //!< Name of the terminal
int InputRead; //!< Input buffer read position
int InputWrite; //!< Input buffer write position
tVT_Char *Text;
Uint32 *Buffer;
};
+ char Name[2]; //!< Name of the terminal
tVFS_Node Node;
} tVTerm;
// === PROTOTYPES ===
int VT_Install(char **Arguments);
+void VT_InitOutput(void);
+void VT_InitInput(void);
char *VT_ReadDir(tVFS_Node *Node, int Pos);
tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name);
int VT_Root_IOCtl(tVFS_Node *Node, int Id, void *Data);
Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
int VT_Terminal_IOCtl(tVFS_Node *Node, int Id, void *Data);
+void VT_SetResolution(int IsTextMode, int Width, int Height);
void VT_SetTerminal(int ID);
void VT_KBCallBack(Uint32 Codepoint);
void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count);
// --- Terminals ---
tVTerm gVT_Terminals[NUM_VTS];
int giVT_CurrentTerminal = 0;
+tVTerm *gpVT_CurTerm = &gVT_Terminals[0];
+// --- Video State ---
+short giVT_RealWidth; //!< Real Width
+short giVT_RealHeight; //!< Real Height
// --- Driver Handles ---
char *gsVT_OutputDevice = NULL;
char *gsVT_InputDevice = NULL;
strcpy(gsVT_InputDevice, args[1]);
args ++;
break;
-
}
}
}
if(!gsVT_OutputDevice) gsVT_OutputDevice = "/Devices/"DEFAULT_OUTPUT;
if(!gsVT_InputDevice) gsVT_InputDevice = "/Devices/"DEFAULT_INPUT;
- LOG("Using '%s' as output", gsVT_OutputDevice);
- LOG("Using '%s' as input", gsVT_InputDevice);
+ Log_Log("VTerm", "Using '%s' as output", gsVT_OutputDevice);
+ Log_Log("VTerm", "Using '%s' as input", gsVT_InputDevice);
// Create Nodes
for( i = 0; i < NUM_VTS; i++ )
// Add to DevFS
DevFS_AddDevice( &gVT_DrvInfo );
+ VT_InitOutput();
+ VT_InitInput();
+
// Set kernel output to VT0
Debug_SetKTerminal("/Devices/VTerm/0");
- return MODULE_INIT_SUCCESS;
+ Log_Log("VTerm", "Returning %i", MODULE_ERR_OK);
+ return MODULE_ERR_OK;
}
/**
void VT_InitOutput()
{
giVT_OutputDevHandle = VFS_Open(gsVT_OutputDevice, VFS_OPENFLAG_WRITE);
+ if(giVT_InputDevHandle == -1) {
+ Log_Warning("VTerm", "Oh F**k, I can't open the video device '%s'", gsVT_OutputDevice);
+ return ;
+ }
VT_SetTerminal( 0 );
+ VT_SetResolution(1, 640, 400);
}
/**
{
int num;
- //ENTER("pNode sName", Node, Name);
+ ENTER("pNode sName", Node, Name);
// Open the input and output files if needed
if(giVT_OutputDevHandle == -2) VT_InitOutput();
return NULL;
}
// Return node
- //LEAVE('p', &gVT_Terminals[num].Node);
+ LEAVE('p', &gVT_Terminals[num].Node);
return &gVT_Terminals[num].Node;
}
}
break;
- case TERM_MODE_FB:
- //case TERM_MODE_:
+ //case TERM_MODE_FB:
+ default:
while(pos < Length)
{
while(term->InputRead == term->InputWrite) Threads_Yield();
{
tVTerm *term = &gVT_Terminals[ Node->Inode ];
- //ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
-
// Write
switch( term->Mode )
{
VT_int_PutString(term, Buffer, Length);
break;
case TERM_MODE_FB:
- if( term->RealWidth > term->Width || term->RealHeight > term->Height )
+ if( giVT_RealWidth > term->Width || giVT_RealHeight > term->Height )
{
#if 0
int x, y, h;
}
}
- //LEAVE('i', 0);
return 0;
}
return -1;
}
-/**
- * \fn void VT_SetTerminal(int ID)
- * \brief Set the current terminal
- */
-void VT_SetTerminal(int ID)
+void VT_SetResolution(int IsTextMode, int Width, int Height)
{
tVideo_IOCtl_Mode mode = {0};
- int modeNum;
+ int tmp;
// Create the video mode
- mode.width = gVT_Terminals[ ID ].Width;
- mode.height = gVT_Terminals[ ID ].Height;
- // - Text Mode
- if(gVT_Terminals[ ID ].Mode == TERM_MODE_TEXT) {
- mode.bpp = 12;
- mode.flags = VIDEO_FLAG_TEXT;
- }
- // - Framebuffer or 3D
- else {
- mode.bpp = 32;
- mode.flags = 0;
- }
+ mode.width = Width;
+ mode.height = Height;
+ mode.bpp = 32;
+ mode.flags = 0;
// Set video mode
VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_FINDMODE, &mode );
- modeNum = mode.id;
- gVT_Terminals[ ID ].RealWidth = mode.width;
- gVT_Terminals[ ID ].RealHeight = mode.height;
- VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_GETSETMODE, &modeNum );
+ tmp = mode.id;
+ giVT_RealWidth = mode.width;
+ giVT_RealHeight = mode.height;
+ VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_GETSETMODE, &tmp );
+ tmp = IsTextMode ? VIDEO_BUFFMT_TEXT : VIDEO_BUFFMT_FRAMEBUFFER;
+ VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp );
+}
+
+/**
+ * \fn void VT_SetTerminal(int ID)
+ * \brief Set the current terminal
+ */
+void VT_SetTerminal(int ID)
+{
// Update current terminal ID
- Log("Changed terminal from %i to %i", giVT_CurrentTerminal, ID);
+ Log_Log("VTerm", "Changed terminal from %i to %i", giVT_CurrentTerminal, ID);
giVT_CurrentTerminal = ID;
+ gpVT_CurTerm = &gVT_Terminals[ID];
+
+ // Update cursor
+ if( gpVT_CurTerm->Mode == TERM_MODE_TEXT && !(gpVT_CurTerm->Flags & VT_FLAG_HIDECSR) )
+ {
+ tVideo_IOCtl_Pos pos;
+ pos.x = gpVT_CurTerm->WritePos % gpVT_CurTerm->Width;
+ pos.y = gpVT_CurTerm->WritePos / gpVT_CurTerm->Width;
+ VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos);
+ }
+
+ if( gpVT_CurTerm->Mode == TERM_MODE_TEXT )
+ VT_SetResolution( 1, gpVT_CurTerm->Width*giVT_CharWidth, gpVT_CurTerm->Height*giVT_CharHeight );
+ else
+ VT_SetResolution( 0, gpVT_CurTerm->Width, gpVT_CurTerm->Height );
// Update the screen
VT_int_UpdateScreen( &gVT_Terminals[ ID ], 1 );
/**
* \fn void VT_KBCallBack(Uint32 Codepoint)
* \brief Called on keyboard interrupt
+ * \param Codepoint Pseudo-UTF32 character
+ *
+ * Handles a key press and sends the key code to the user's buffer.
+ * If the code creates a kernel-magic sequence, it is not passed to the
+ * user and is handled in-kernel.
*/
void VT_KBCallBack(Uint32 Codepoint)
{
case KEY_F11: VT_SetTerminal(10); return;
case KEY_F12: VT_SetTerminal(11); return;
case KEY_PGUP:
+ if( gpVT_CurTerm->ViewPos > gpVT_CurTerm->Width )
+ gpVT_CurTerm->ViewPos -= gpVT_CurTerm->Width;
+ else
+ gpVT_CurTerm->ViewPos = 0;
return;
case KEY_PGDOWN:
+ if( gpVT_CurTerm->ViewPos < gpVT_CurTerm->Width*(gpVT_CurTerm->Height*(VT_SCROLLBACK-1)) )
+ gpVT_CurTerm->ViewPos += gpVT_CurTerm->Width;
+ else
+ gpVT_CurTerm->ViewPos = gpVT_CurTerm->Width*(gpVT_CurTerm->Height*(VT_SCROLLBACK-1));
return;
}
}
}
}
-/**
- * \fn void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count)
- * \brief Print a string to the Virtual Terminal
- */
-void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count)
-{
- Uint32 val;
- int i;
- for( i = 0; i < Count; i++ )
- {
- if( Buffer[i] == 0x1B ) // Escape Sequence
- {
- i ++;
- i += VT_int_ParseEscape(Term, (char*)&Buffer[i]);
- continue;
- }
-
- if( Buffer[i] < 128 ) // Plain ASCII
- VT_int_PutChar(Term, Buffer[i]);
- else { // UTF-8
- i += ReadUTF8(&Buffer[i], &val);
- VT_int_PutChar(Term, val);
- }
- }
-
- // Update cursor
- if( !(Term->Flags & VT_FLAG_HIDECSR) )
- {
- tVideo_IOCtl_Pos pos;
- pos.x = Term->WritePos % Term->Width;
- pos.y = Term->WritePos / Term->Width;
- VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos);
- }
-}
-
/**
* \fn void VT_int_ClearLine(tVTerm *Term, int Num)
* \brief Clears a line in a virtual terminal
return j + 1;
}
+/**
+ * \fn void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count)
+ * \brief Print a string to the Virtual Terminal
+ */
+void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count)
+{
+ Uint32 val;
+ int i;
+ for( i = 0; i < Count; i++ )
+ {
+ if( Buffer[i] == 0x1B ) // Escape Sequence
+ {
+ i ++;
+ i += VT_int_ParseEscape(Term, (char*)&Buffer[i]);
+ continue;
+ }
+
+ if( Buffer[i] < 128 ) // Plain ASCII
+ VT_int_PutChar(Term, Buffer[i]);
+ else { // UTF-8
+ i += ReadUTF8(&Buffer[i], &val);
+ VT_int_PutChar(Term, val);
+ }
+ }
+ // Update Screen
+ VT_int_UpdateScreen( Term, 0 );
+
+ // Update cursor
+ if( Term == gpVT_CurTerm && !(Term->Flags & VT_FLAG_HIDECSR) )
+ {
+ tVideo_IOCtl_Pos pos;
+ pos.x = Term->WritePos % Term->Width;
+ pos.y = Term->WritePos / Term->Width;
+ VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos);
+ }
+}
+
/**
* \fn void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
* \brief Write a single character to a VTerm
{
case '\0': return; // Ignore NULL byte
case '\n':
+ VT_int_UpdateScreen( Term, 0 ); // Update the line before newlining
Term->WritePos += Term->Width;
case '\r':
Term->WritePos -= Term->WritePos % Term->Width;
memcpy(
Term->Text,
&Term->Text[Term->Width],
- Term->Width*(Term->Height-1)*VT_SCROLLBACK*sizeof(tVT_Char)
+ (Term->Width*Term->Height*VT_SCROLLBACK-Term->Width)*sizeof(tVT_Char)
);
// Clear last row
Term->Text[ base + i ].Colour = Term->CurColour;
}
+ //LOG("Scrolled buffer");
VT_int_UpdateScreen( Term, 1 );
}
else if(Term->WritePos > Term->Width*Term->Height+Term->ViewPos)
{
Term->ViewPos += Term->Width;
+ //LOG("Scrolled screen");
VT_int_UpdateScreen( Term, 1 );
}
- else
- VT_int_UpdateScreen( Term, 0 );
//LEAVE('-');
}
if( Term->Mode == TERM_MODE_TEXT )
{
if(UpdateAll) {
+ //LOG("UpdateAll = 1");
+ //LOG("VFS_WriteAt(0x%x, 0, %i*sizeof(tVT_Char), &Term->Text[%i])",
+ // giVT_OutputDevHandle, Term->Width*Term->Height, Term->ViewPos);
VFS_WriteAt(
giVT_OutputDevHandle,
0,
);
} else {
int pos = Term->WritePos - Term->WritePos % Term->Width;
+ //LOG("UpdateAll = 0");
+ //LOG("VFS_WriteAt(0x%x, %i*sizeof(tVT_Char), %i*sizeof(tVT_Char), &Term->Text[%i])",
+ // giVT_OutputDevHandle, (pos - Term->ViewPos), Term->Width, pos);
VFS_WriteAt(
giVT_OutputDevHandle,
(pos - Term->ViewPos)*sizeof(tVT_Char),
Uint8 *VT_Font_GetChar(Uint32 Codepoint);
// === GLOBALS ===
-int giVT_CharWidth = FONT_WIDTH+1;
+int giVT_CharWidth = FONT_WIDTH;
int giVT_CharHeight = FONT_HEIGHT;
// === CODE ===