#include <acess.h>
#include <fs_devfs.h>
#include <modules.h>
-#include <tpl_drv_video.h>
-#include <tpl_drv_keyboard.h>
-#include <tpl_drv_terminal.h>
+#include <api_drv_video.h>
+#include <api_drv_keyboard.h>
+#include <api_drv_terminal.h>
#include <errno.h>
-
-#define USE_CTRL_ALT 0
+#include <semaphore.h>
// === CONSTANTS ===
#define VERSION ((0<<8)|(50))
#define MAX_INPUT_CHARS8 (MAX_INPUT_CHARS32*4)
//#define DEFAULT_OUTPUT "BochsGA"
#define DEFAULT_OUTPUT "Vesa"
+#define FALLBACK_OUTPUT "x86_VGAText"
#define DEFAULT_INPUT "PS2Keyboard"
#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
#define DEFAULT_SCROLLBACK 2 // 2 Screens of text + current screen
+//#define DEFAULT_SCROLLBACK 0
#define DEFAULT_COLOUR (VT_COL_BLACK|(0xAAA<<16))
#define VT_FLAG_HIDECSR 0x01
+#define VT_FLAG_ALTBUF 0x02 //!< Alternate screen buffer
+#define VT_FLAG_RAWIN 0x04 //!< Don't handle ^Z/^C/^V
#define VT_FLAG_HASFB 0x10 //!< Set if the VTerm has requested the Framebuffer
+#define VT_FLAG_SHOWCSR 0x20 //!< Always show the text cursor
enum eVT_InModes {
VT_INMODE_TEXT8, // UTF-8 Text Mode (VT100/xterm Emulation)
short TextWidth; //!< Text Virtual Width
short TextHeight; //!< Text Virtual Height
+ Uint32 CurColour; //!< Current Text Colour
+
int ViewPos; //!< View Buffer Offset (Text Only)
int WritePos; //!< Write Buffer Offset (Text Only)
- Uint32 CurColour; //!< Current Text Colour
+ tVT_Char *Text;
+
+ tVT_Char *AltBuf; //!< Alternate Screen Buffer
+ int AltWritePos; //!< Alternate write position
+ short ScrollTop; //!< Top of scrolling region (smallest)
+ short ScrollHeight; //!< Length of scrolling region
+
+ int VideoCursorX;
+ int VideoCursorY;
tMutex ReadingLock; //!< Lock the VTerm when a process is reading from it
tTID ReadingThread; //!< Owner of the lock
int InputRead; //!< Input buffer read position
int InputWrite; //!< Input buffer write position
char InputBuffer[MAX_INPUT_CHARS8];
+// tSemaphore InputSemaphore;
- tVT_Char *Text;
Uint32 *Buffer;
+
+ // TODO: Do I need to keep this about?
+ // When should it be deallocated? on move to text mode, or some other time
+ // Call set again, it's freed, and if NULL it doesn't get reallocated.
+ tVideo_IOCtl_Bitmap *VideoCursor;
char Name[2]; //!< Name of the terminal
tVFS_Node Node;
void VT_int_ClearLine(tVTerm *Term, int Num);
int VT_int_ParseEscape(tVTerm *Term, char *Buffer);
void VT_int_PutChar(tVTerm *Term, Uint32 Ch);
-void VT_int_ScrollFramebuffer( tVTerm *Term );
+void VT_int_ScrollText(tVTerm *Term, int Count);
+void VT_int_ScrollFramebuffer( tVTerm *Term, int Count );
+void VT_int_UpdateCursor( tVTerm *Term, int bShow );
void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll );
void VT_int_ChangeMode(tVTerm *Term, int NewMode, int NewWidth, int NewHeight);
+void VT_int_ToggleAltBuffer(tVTerm *Term, int Enabled);
// === CONSTANTS ===
const Uint16 caVT100Colours[] = {
};
// === GLOBALS ===
-MODULE_DEFINE(0, VERSION, VTerm, VT_Install, NULL, DEFAULT_OUTPUT, DEFAULT_INPUT, NULL);
+MODULE_DEFINE(0, VERSION, VTerm, VT_Install, NULL, DEFAULT_INPUT, NULL);
tDevFS_Driver gVT_DrvInfo = {
NULL, "VTerm",
{
Log_Debug("VTerm", "Argument '%s'", arg);
if( strcmp(opt, "Video") == 0 ) {
- gsVT_OutputDevice = strdup(val);
+ if( !gsVT_OutputDevice )
+ gsVT_OutputDevice = strdup(val);
}
else if( strcmp(opt, "Input") == 0 ) {
- gsVT_InputDevice = strdup(val);
+ if( !gsVT_InputDevice )
+ gsVT_InputDevice = strdup(val);
}
else if( strcmp(opt, "Width") == 0 ) {
giVT_RealWidth = atoi( val );
}
}
- if(gsVT_OutputDevice) Modules_InitialiseBuiltin( gsVT_OutputDevice );
- if(gsVT_InputDevice) Modules_InitialiseBuiltin( gsVT_InputDevice );
-
// Apply Defaults
- if(!gsVT_OutputDevice) gsVT_OutputDevice = strdup(DEFAULT_OUTPUT);
- if(!gsVT_InputDevice) gsVT_InputDevice = strdup(DEFAULT_INPUT);
+ 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 ) ) {
+ Log_Error("VTerm", "Fallback video '%s' is not avaliable, giving up", FALLBACK_OUTPUT);
+ return MODULE_ERR_MISC;
+ }
- // Create paths
+ if(!gsVT_InputDevice) gsVT_InputDevice = (char*)DEFAULT_INPUT;
+ else if( Module_EnsureLoaded( gsVT_InputDevice ) ) gsVT_InputDevice = (char*)DEFAULT_INPUT;
+
+ // Create device paths
{
char *tmp;
tmp = malloc( 9 + strlen(gsVT_OutputDevice) + 1 );
strcpy(tmp, "/Devices/");
strcpy(&tmp[9], gsVT_OutputDevice);
gsVT_OutputDevice = tmp;
+
tmp = malloc( 9 + strlen(gsVT_InputDevice) + 1 );
strcpy(tmp, "/Devices/");
strcpy(&tmp[9], gsVT_InputDevice);
Log_Log("VTerm", "Using '%s' as output", gsVT_OutputDevice);
Log_Log("VTerm", "Using '%s' as input", gsVT_InputDevice);
+ VT_InitOutput();
+ VT_InitInput();
+
// Create Nodes
for( i = 0; i < NUM_VTS; i++ )
{
gVT_Terminals[i].Flags = 0;
gVT_Terminals[i].CurColour = DEFAULT_COLOUR;
gVT_Terminals[i].WritePos = 0;
+ gVT_Terminals[i].AltWritePos = 0;
gVT_Terminals[i].ViewPos = 0;
gVT_Terminals[i].ReadingThread = -1;
+ gVT_Terminals[i].ScrollHeight = 0;
// Initialise
VT_int_ChangeMode( &gVT_Terminals[i],
gVT_Terminals[i].Node.Read = VT_Read;
gVT_Terminals[i].Node.Write = VT_Write;
gVT_Terminals[i].Node.IOCtl = VT_Terminal_IOCtl;
+// Semaphore_Init(&gVT_Terminals[i].InputSemaphore, 0, MAX_INPUT_CHARS8, "VTerm", gVT_Terminals[i].Name);
}
// Add to DevFS
DevFS_AddDevice( &gVT_DrvInfo );
- VT_InitOutput();
- VT_InitInput();
-
// Set kernel output to VT0
Debug_SetKTerminal("/Devices/VTerm/0");
- Log_Log("VTerm", "Returning %i", MODULE_ERR_OK);
return MODULE_ERR_OK;
}
VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_GETSETMODE, &tmp );
// Resize text terminals if needed
- if( giVT_RealWidth != mode.width || giVT_RealHeight != mode.height )
+ if( gVT_Terminals[0].Text && (giVT_RealWidth != mode.width || giVT_RealHeight != mode.height) )
{
int newBufSize = (giVT_RealWidth/giVT_CharWidth)
*(giVT_RealHeight/giVT_CharHeight)
// Resize the text terminals
giVT_RealWidth = mode.width;
giVT_RealHeight = mode.height;
+ Log_Debug("VTerm", "Resizing terminals to %ix%i",
+ giVT_RealWidth/giVT_CharWidth, giVT_RealHeight/giVT_CharHeight);
for( i = 0; i < NUM_VTS; i ++ )
{
if( gVT_Terminals[i].Mode != TERM_MODE_TEXT ) continue;
+ gVT_Terminals[i].TextWidth = giVT_RealWidth/giVT_CharWidth;
+ gVT_Terminals[i].TextHeight = giVT_RealHeight/giVT_CharHeight;
+ gVT_Terminals[i].ScrollHeight = gVT_Terminals[i].TextHeight;
+
gVT_Terminals[i].Text = realloc(
gVT_Terminals[i].Text,
newBufSize*sizeof(tVT_Char)
}
/**
- * \fn Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
* \brief Read from a virtual terminal
*/
Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
{
int pos = 0;
+ int avail;
tVTerm *term = &gVT_Terminals[ Node->Inode ];
+ Uint32 *codepoint_buf = Buffer;
+ Uint32 *codepoint_in;
Mutex_Acquire( &term->ReadingLock );
- term->ReadingThread = Threads_GetTID();
+
+ // Update cursor
+ VT_int_UpdateCursor(term, 1);
// Check current mode
switch(term->Mode)
{
// Text Mode (UTF-8)
case TERM_MODE_TEXT:
- while(pos < Length)
+ VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "VT_Read (UTF-8)");
+
+ avail = term->InputWrite - term->InputRead;
+ if(avail < 0)
+ avail += MAX_INPUT_CHARS8;
+ if(avail > Length - pos)
+ avail = Length - pos;
+
+ while( avail -- )
{
- //TODO: Sleep instead
- while(term->InputRead == term->InputWrite) Threads_Sleep();
-
((char*)Buffer)[pos] = term->InputBuffer[term->InputRead];
pos ++;
term->InputRead ++;
- term->InputRead %= MAX_INPUT_CHARS8;
+ while(term->InputRead > MAX_INPUT_CHARS8)
+ term->InputRead -= MAX_INPUT_CHARS8;
}
break;
//case TERM_MODE_FB:
// Other - UCS-4
default:
- while(pos < Length)
+ VFS_SelectNode(Node, VFS_SELECT_READ, NULL, "VT_Read (UCS-4)");
+
+ avail = term->InputWrite - term->InputRead;
+ if(avail < 0)
+ avail += MAX_INPUT_CHARS32;
+ if(avail > Length - pos)
+ avail = Length/4 - pos;
+
+ codepoint_in = (void*)term->InputBuffer;
+ codepoint_buf = Buffer;
+
+ while( avail -- )
{
- while(term->InputRead == term->InputWrite) Threads_Sleep();
- ((Uint32*)Buffer)[pos] = ((Uint32*)term->InputBuffer)[term->InputRead];
+ codepoint_buf[pos] = codepoint_in[term->InputRead];
pos ++;
term->InputRead ++;
- term->InputRead %= MAX_INPUT_CHARS32;
+ while(term->InputRead > MAX_INPUT_CHARS32)
+ term->InputRead -= MAX_INPUT_CHARS32;
}
+ pos *= 4;
break;
}
+ // Mark none avaliable if buffer empty
+ if( term->InputRead == term->InputWrite )
+ VFS_MarkAvaliable(&term->Node, 0);
+
term->ReadingThread = -1;
+
+// VT_int_UpdateCursor(term, term->Mode == TERM_MODE_TEXT);
+
Mutex_Release( &term->ReadingLock );
- return 0;
+ return pos;
}
/**
Log_Log("VTerm", "VTerm %i mode set to %i", (int)Node->Inode, *iData);
// Update mode if needed
- if( term->Mode != *iData
- || term->NewWidth
- || term->NewHeight)
+ if( term->Mode != *iData || term->NewWidth || term->NewHeight)
{
// Adjust for text mode
if( *iData == TERM_MODE_TEXT ) {
VT_SetTerminal( Node->Inode );
LEAVE('i', 1);
return 1;
+
+ case TERM_IOCTL_GETSETCURSOR:
+ if(Data != NULL)
+ {
+ tVideo_IOCtl_Pos *pos = Data;
+ if( !CheckMem(Data, sizeof(*pos)) ) {
+ errno = -EINVAL;
+ LEAVE('i', -1);
+ return -1;
+ }
+
+ if( term->Mode == TERM_MODE_TEXT )
+ {
+ if(term->Flags & VT_FLAG_ALTBUF)
+ term->AltWritePos = pos->x + pos->y * term->TextWidth;
+ else
+ term->WritePos = pos->x + pos->y * term->TextWidth + term->ViewPos;
+ VT_int_UpdateCursor(term, 0);
+ }
+ else
+ {
+ term->VideoCursorX = pos->x;
+ term->VideoCursorY = pos->y;
+ VT_int_UpdateCursor(term, 1);
+ }
+ }
+ ret = (term->Flags & VT_FLAG_ALTBUF) ? term->AltWritePos : term->WritePos-term->ViewPos;
+ LEAVE('i', ret);
+ return ret;
+
+ case TERM_IOCTL_SETCURSORBITMAP: {
+ tVideo_IOCtl_Bitmap *bmp = Data;
+ if( Data == NULL )
+ {
+ free( term->VideoCursor );
+ term->VideoCursor = NULL;
+ LEAVE('i', 0);
+ return 0;
+ }
+
+ // Sanity check bitmap
+ if( !CheckMem(bmp, sizeof(tVideo_IOCtl_Bitmap)) ) {
+ Log_Notice("VTerm", "%p in TERM_IOCTL_SETCURSORBITMAP invalid", bmp);
+ errno = -EINVAL;
+ LEAVE_RET('i', -1);
+ }
+ if( !CheckMem(bmp->Data, bmp->W*bmp->H*sizeof(Uint32)) ) {
+ Log_Notice("VTerm", "%p in TERM_IOCTL_SETCURSORBITMAP invalid", bmp);
+ errno = -EINVAL;
+ LEAVE_RET('i', -1);
+ }
+
+ // Reallocate if needed
+ if(term->VideoCursor)
+ {
+ if(bmp->W * bmp->H != term->VideoCursor->W * term->VideoCursor->H) {
+ free(term->VideoCursor);
+ term->VideoCursor = NULL;
+ }
+ }
+ if(!term->VideoCursor) {
+ term->VideoCursor = malloc(sizeof(tVideo_IOCtl_Pos) + bmp->W*bmp->H*sizeof(Uint32));
+ if(!term->VideoCursor) {
+ Log_Error("VTerm", "Unable to allocate memory for cursor");
+ errno = -ENOMEM;
+ LEAVE_RET('i', -1);
+ }
+ }
+
+ memcpy(term->VideoCursor, bmp, sizeof(tVideo_IOCtl_Pos) + bmp->W*bmp->H*sizeof(Uint32));
+
+ Log_Debug("VTerm", "Set VT%i's cursor to %p %ix%i",
+ (int)term->Node.Inode, bmp, bmp->W, bmp->H);
+
+ if(gpVT_CurTerm == term)
+ VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSORBITMAP, term->VideoCursor);
+
+ LEAVE('i', 0);
+ return 0; }
}
LEAVE('i', -1);
return -1;
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->ViewPos) % gpVT_CurTerm->TextWidth;
- pos.y = (gpVT_CurTerm->WritePos - gpVT_CurTerm->ViewPos) / gpVT_CurTerm->TextWidth;
- if( pos.x < gpVT_CurTerm->TextHeight )
- VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos);
- }
if( gpVT_CurTerm->Mode == TERM_MODE_TEXT )
+ {
VT_SetMode( VIDEO_BUFFMT_TEXT );
+ }
else
+ {
+ // Update the cursor image
+ if(gpVT_CurTerm->VideoCursor)
+ VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSORBITMAP, gpVT_CurTerm->VideoCursor);
VT_SetMode( VIDEO_BUFFMT_FRAMEBUFFER );
+ }
+
+ VT_int_UpdateCursor(gpVT_CurTerm, 1);
// Update the screen
- VT_int_UpdateScreen( &gVT_Terminals[ ID ], 1 );
+ VT_int_UpdateScreen( gpVT_CurTerm, 1 );
}
/**
Codepoint &= 0x7FFFFFFF;
switch(Codepoint)
{
- #if !USE_CTRL_ALT
- case KEY_RSHIFT: gbVT_CtrlDown = 0; break;
- case KEY_LSHIFT: gbVT_AltDown = 0; break;
- #else
case KEY_LALT: gbVT_AltDown &= ~1; break;
case KEY_RALT: gbVT_AltDown &= ~2; break;
- case KEY_LCTRL: gbVT_CtrlDown &= ~1 break;
+ case KEY_LCTRL: gbVT_CtrlDown &= ~1; break;
case KEY_RCTRL: gbVT_CtrlDown &= ~2; break;
- #endif
}
return;
}
switch(Codepoint)
{
- #if !USE_CTRL_ALT // HACK: Use both shifts instead of Ctrl-Alt
- case KEY_RSHIFT: gbVT_CtrlDown = 1; break;
- case KEY_LSHIFT: gbVT_AltDown = 1; break;
- #else
case KEY_LALT: gbVT_AltDown |= 1; break;
case KEY_RALT: gbVT_AltDown |= 2; break;
case KEY_LCTRL: gbVT_CtrlDown |= 1; break;
case KEY_RCTRL: gbVT_CtrlDown |= 2; break;
- #endif
default:
if(!gbVT_AltDown || !gbVT_CtrlDown)
case KEY_F12: VT_SetTerminal(11); return;
// Scrolling
case KEY_PGUP:
+ if( gpVT_CurTerm->Flags & VT_FLAG_ALTBUF )
+ return ;
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*(giVT_Scrollback-1) )
+ if( gpVT_CurTerm->Flags & VT_FLAG_ALTBUF )
+ return ;
+ if( gpVT_CurTerm->ViewPos < gpVT_CurTerm->Width*gpVT_CurTerm->Height*(giVT_Scrollback) )
gpVT_CurTerm->ViewPos += gpVT_CurTerm->Width;
else
- gpVT_CurTerm->ViewPos = gpVT_CurTerm->Width*gpVT_CurTerm->Height*(giVT_Scrollback-1);
+ gpVT_CurTerm->ViewPos = gpVT_CurTerm->Width*gpVT_CurTerm->Height*(giVT_Scrollback);
return;
}
}
break;
case KEY_PGUP:
- buf[0] = '\x1B'; buf[1] = '['; buf[2] = '5'; // Some overline also
+ //buf[0] = '\x1B'; buf[1] = '['; buf[2] = '5'; // Some overline also
//len = 4; // Commented out until I'm sure
+ len = 0;
break;
case KEY_PGDOWN:
len = 0;
// Unprintable / Don't Pass
return;
}
+
+#if 0
+ // Handle meta characters
+ if( !(term->Flags & VT_FLAG_RAWIN) )
+ {
+ switch(buf[0])
+ {
+ case '\3': // ^C
+
+ break;
+ }
+ }
+#endif
// Write
if( MAX_INPUT_CHARS8 - term->InputWrite >= len )
term->InputRead = term->InputWrite + 1;
term->InputRead %= MAX_INPUT_CHARS8;
}
-
}
else
{
// Encode the raw UTF-32 Key
- ((Uint32*)term->InputBuffer)[ term->InputWrite ] = Codepoint;
+ Uint32 *raw_in = (void*)term->InputBuffer;
+ raw_in[ term->InputWrite ] = Codepoint;
term->InputWrite ++;
term->InputWrite %= MAX_INPUT_CHARS32;
if(term->InputRead == term->InputWrite) {
}
}
- // Wake up the thread waiting on us
- if( term->ReadingThread >= 0 ) {
- Threads_WakeTID(term->ReadingThread);
- }
+ VFS_MarkAvaliable(&term->Node, 1);
}
/**
void VT_int_ClearLine(tVTerm *Term, int Num)
{
int i;
- tVT_Char *cell = &Term->Text[ Num*Term->TextWidth ];
+ tVT_Char *cell;
+
if( Num < 0 || Num >= Term->TextHeight * (giVT_Scrollback + 1) ) return ;
- //ENTER("pTerm iNum", Term, Num);
+
+ cell = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltBuf : Term->Text;
+ cell = &cell[ Num*Term->TextWidth ];
+
for( i = Term->TextWidth; i--; )
{
cell[ i ].Ch = 0;
cell[ i ].Colour = Term->CurColour;
}
- //LEAVE('-');
}
/**
int argc = 0, j = 1;
int tmp;
int args[6] = {0,0,0,0};
+ int bQuestionMark = 0;
switch(Buffer[0])
{
case '[':
// Get Arguments
c = Buffer[j++];
+ if(c == '?') {
+ bQuestionMark = 1;
+ c = Buffer[j++];
+ }
if( '0' <= c && c <= '9' )
{
do {
}
// Get Command
- if( ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
+ if( ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
{
- switch(c)
+ if( bQuestionMark )
{
- // Left
- case 'D':
- if(argc == 1) tmp = args[0];
- else tmp = 1;
-
- if( Term->WritePos-(tmp-1) % Term->TextWidth == 0 )
- Term->WritePos -= Term->WritePos % Term->TextWidth;
- else
- Term->WritePos -= tmp;
- break;
-
- // Right
- case 'C':
- if(argc == 1) tmp = args[0];
- else tmp = 1;
- if( (Term->WritePos + tmp) % Term->TextWidth == 0 ) {
- Term->WritePos -= Term->WritePos % Term->TextWidth;
- Term->WritePos += Term->TextWidth - 1;
- } else
- Term->WritePos += tmp;
- break;
-
- // Clear By Line
- case 'J':
- // Clear Screen
- switch(args[0])
+ switch(c)
{
- case 2:
+ // DEC Private Mode Set
+ case 'h':
+ if(argc != 1) break;
+ switch(args[0])
+ {
+ case 1047:
+ VT_int_ToggleAltBuffer(Term, 1);
+ break;
+ }
+ break;
+ case 'l':
+ if(argc != 1) break;
+ switch(args[0])
{
- int i = Term->TextHeight * (giVT_Scrollback + 1);
- while( i-- ) VT_int_ClearLine(Term, i);
- Term->WritePos = 0;
- Term->ViewPos = 0;
- VT_int_UpdateScreen(Term, 1);
+ case 1047:
+ VT_int_ToggleAltBuffer(Term, 0);
+ break;
}
break;
+ default:
+ Log_Warning("VTerm", "Unknown control sequence '\\x1B[?%c'", c);
+ break;
}
- break;
- // Set cursor position
- case 'h':
- Term->WritePos = args[0] + args[1]*Term->TextWidth;
- Log_Debug("VTerm", "args = {%i, %i}", args[0], args[1]);
- break;
- // Set Font flags
- case 'm':
- for( ; argc--; )
+ }
+ else
+ {
+ tmp = 1;
+ switch(c)
{
- // Flags
- if( 0 <= args[argc] && args[argc] <= 8)
+ // Left
+ case 'D':
+ tmp = -1;
+ // Right
+ case 'C':
+ if(argc == 1) tmp *= args[0];
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ if( (Term->AltWritePos + tmp) % Term->TextWidth == 0 ) {
+ Term->AltWritePos -= Term->AltWritePos % Term->TextWidth;
+ Term->AltWritePos += Term->TextWidth - 1;
+ }
+ else
+ Term->AltWritePos += tmp;
+ }
+ else
{
- switch(args[argc])
+ if( (Term->WritePos + tmp) % Term->TextWidth == 0 ) {
+ Term->WritePos -= Term->WritePos % Term->TextWidth;
+ Term->WritePos += Term->TextWidth - 1;
+ }
+ else
+ Term->WritePos += tmp;
+ }
+ break;
+
+ // Erase
+ case 'J':
+ switch(args[0])
+ {
+ case 0: // Erase below
+ break;
+ case 1: // Erase above
+ break;
+ case 2: // Erase all
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ int i = Term->TextHeight;
+ while( i-- ) VT_int_ClearLine(Term, i);
+ Term->AltWritePos = 0;
+ VT_int_UpdateScreen(Term, 1);
+ }
+ else
{
- case 0: Term->CurColour = DEFAULT_COLOUR; break; // Reset
- case 1: Term->CurColour |= 0x80000000; break; // Bright
- case 2: Term->CurColour &= ~0x80000000; break; // Dim
+ int i = Term->TextHeight * (giVT_Scrollback + 1);
+ while( i-- ) VT_int_ClearLine(Term, i);
+ Term->WritePos = 0;
+ Term->ViewPos = 0;
+ VT_int_UpdateScreen(Term, 1);
}
+ break;
}
- // Foreground Colour
- else if(30 <= args[argc] && args[argc] <= 37) {
- Term->CurColour &= 0xF000FFFF;
- Term->CurColour |= (Uint32)caVT100Colours[ args[argc]-30+(Term->CurColour>>28) ] << 16;
+ break;
+
+ // Erase in line
+ case 'K':
+ switch(args[0])
+ {
+ case 0: // Erase to right
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ int i, max;
+ max = Term->Width - Term->AltWritePos % Term->Width;
+ for( i = 0; i < max; i ++ )
+ Term->AltBuf[Term->AltWritePos+i].Ch = 0;
+ }
+ else
+ {
+ int i, max;
+ max = Term->Width - Term->WritePos % Term->Width;
+ for( i = 0; i < max; i ++ )
+ Term->Text[Term->WritePos+i].Ch = 0;
+ }
+ VT_int_UpdateScreen(Term, 0);
+ break;
+ case 1: // Erase to left
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ int i = Term->AltWritePos % Term->Width;
+ while( i -- )
+ Term->AltBuf[Term->AltWritePos++].Ch = 0;
+ }
+ else
+ {
+ int i = Term->WritePos % Term->Width;
+ while( i -- )
+ Term->Text[Term->WritePos++].Ch = 0;
+ }
+ VT_int_UpdateScreen(Term, 0);
+ break;
+ case 2: // Erase all
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ VT_int_ClearLine(Term, Term->AltWritePos / Term->Width);
+ }
+ else
+ {
+ VT_int_ClearLine(Term, Term->WritePos / Term->Width);
+ }
+ VT_int_UpdateScreen(Term, 0);
+ break;
}
- // Background Colour
- else if(40 <= args[argc] && args[argc] <= 47) {
- Term->CurColour &= 0xFFFF8000;
- Term->CurColour |= caVT100Colours[ args[argc]-40+((Term->CurColour>>12)&15) ];
+ break;
+
+ // Set cursor position
+ case 'H':
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ Term->AltWritePos = args[0] + args[1]*Term->TextWidth;
+ else
+ Term->WritePos = args[0] + args[1]*Term->TextWidth;
+ //Log_Debug("VTerm", "args = {%i, %i}", args[0], args[1]);
+ break;
+
+ // Scroll up `n` lines
+ case 'S':
+ tmp = -1;
+ // Scroll down `n` lines
+ case 'T':
+ if(argc == 1) tmp *= args[0];
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ VT_int_ScrollText(Term, tmp);
+ else
+ {
+ if(Term->ViewPos/Term->TextWidth + tmp < 0)
+ break;
+ if(Term->ViewPos/Term->TextWidth + tmp > Term->TextHeight * (giVT_Scrollback + 1))
+ break;
+
+ Term->ViewPos += Term->TextWidth*tmp;
}
+ break;
+
+ // Set Font flags
+ case 'm':
+ for( ; argc--; )
+ {
+ // Flags
+ if( 0 <= args[argc] && args[argc] <= 8)
+ {
+ switch(args[argc])
+ {
+ case 0: Term->CurColour = DEFAULT_COLOUR; break; // Reset
+ case 1: Term->CurColour |= 0x80000000; break; // Bright
+ case 2: Term->CurColour &= ~0x80000000; break; // Dim
+ }
+ }
+ // Foreground Colour
+ else if(30 <= args[argc] && args[argc] <= 37) {
+ Term->CurColour &= 0xF000FFFF;
+ Term->CurColour |= (Uint32)caVT100Colours[ args[argc]-30+(Term->CurColour>>28) ] << 16;
+ }
+ // Background Colour
+ else if(40 <= args[argc] && args[argc] <= 47) {
+ Term->CurColour &= 0xFFFF8000;
+ Term->CurColour |= caVT100Colours[ args[argc]-40+((Term->CurColour>>12)&15) ];
+ }
+ }
+ break;
+
+ // Set scrolling region
+ case 'r':
+ if( argc != 2 ) break;
+ Term->ScrollTop = args[0];
+ Term->ScrollHeight = args[1] - args[0];
+ break;
+
+ default:
+ Log_Warning("VTerm", "Unknown control sequence '\\x1B[%c'", c);
+ break;
}
- break;
- default:
- Log_Warning("VTerm", "Unknown control sequence");
- break;
}
}
break;
}
// 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->ViewPos) % Term->TextWidth;
- pos.y = (Term->WritePos - Term->ViewPos) / Term->TextWidth;
- VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos);
- }
}
/**
void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
{
int i;
+ tVT_Char *buffer;
+ int write_pos;
+
+ if(Term->Flags & VT_FLAG_ALTBUF) {
+ buffer = Term->AltBuf;
+ write_pos = Term->AltWritePos;
+ }
+ else {
+ buffer = Term->Text;
+ write_pos = Term->WritePos;
+ }
switch(Ch)
{
case '\0': return; // Ignore NULL byte
case '\n':
VT_int_UpdateScreen( Term, 0 ); // Update the line before newlining
- Term->WritePos += Term->TextWidth;
+ write_pos += Term->TextWidth;
case '\r':
- Term->WritePos -= Term->WritePos % Term->TextWidth;
+ write_pos -= write_pos % Term->TextWidth;
break;
- case '\t':
+ case '\t': { int tmp = write_pos / Term->TextWidth;
+ write_pos %= Term->TextWidth;
do {
- Term->Text[ Term->WritePos ].Ch = '\0';
- Term->Text[ Term->WritePos ].Colour = Term->CurColour;
- Term->WritePos ++;
- } while(Term->WritePos & 7);
- break;
+ buffer[ write_pos ].Ch = '\0';
+ buffer[ write_pos ].Colour = Term->CurColour;
+ write_pos ++;
+ } while(write_pos & 7);
+ write_pos += tmp * Term->TextWidth;
+ break; }
case '\b':
// Backspace is invalid at Offset 0
- if(Term->WritePos == 0) break;
+ if(write_pos == 0) break;
- Term->WritePos --;
+ write_pos --;
// Singe Character
- if(Term->Text[ Term->WritePos ].Ch != '\0') {
- Term->Text[ Term->WritePos ].Ch = 0;
- Term->Text[ Term->WritePos ].Colour = Term->CurColour;
+ if(buffer[ write_pos ].Ch != '\0') {
+ buffer[ write_pos ].Ch = 0;
+ buffer[ write_pos ].Colour = Term->CurColour;
break;
}
// Tab
i = 7; // Limit it to 8
do {
- Term->Text[ Term->WritePos ].Ch = 0;
- Term->Text[ Term->WritePos ].Colour = Term->CurColour;
- Term->WritePos --;
- } while(Term->WritePos && i-- && Term->Text[ Term->WritePos ].Ch == '\0');
- if(Term->Text[ Term->WritePos ].Ch != '\0')
- Term->WritePos ++;
+ buffer[ write_pos ].Ch = 0;
+ buffer[ write_pos ].Colour = Term->CurColour;
+ write_pos --;
+ } while(write_pos && i-- && buffer[ write_pos ].Ch == '\0');
+ if(buffer[ write_pos ].Ch != '\0')
+ write_pos ++;
break;
default:
- Term->Text[ Term->WritePos ].Ch = Ch;
- Term->Text[ Term->WritePos ].Colour = Term->CurColour;
- Term->WritePos ++;
+ buffer[ write_pos ].Ch = Ch;
+ buffer[ write_pos ].Colour = Term->CurColour;
+ // Update the line before wrapping
+ if( (write_pos + 1) % Term->TextWidth == 0 )
+ VT_int_UpdateScreen( Term, 0 );
+ write_pos ++;
break;
}
- // Move Screen
- // - Check if we need to scroll the entire scrollback buffer
- if(Term->WritePos >= Term->TextWidth*Term->TextHeight*(giVT_Scrollback+1))
+ if(Term->Flags & VT_FLAG_ALTBUF)
{
- int base;
+ Term->AltBuf = buffer;
+ Term->AltWritePos = write_pos;
- // Move back by one
- Term->WritePos -= Term->TextWidth;
- // Update the scren
- VT_int_UpdateScreen( Term, 0 );
+ if(Term->AltWritePos >= Term->TextWidth*Term->TextHeight)
+ {
+ Term->AltWritePos -= Term->TextWidth;
+ VT_int_ScrollText(Term, 1);
+ }
- // Update view position
- base = Term->TextWidth*Term->TextHeight*(giVT_Scrollback);
- if(Term->ViewPos < base)
- Term->ViewPos += Term->Width;
- if(Term->ViewPos > base)
- Term->ViewPos = base;
+ }
+ else
+ {
+ Term->Text = buffer;
+ Term->WritePos = write_pos;
+ // Move Screen
+ // - Check if we need to scroll the entire scrollback buffer
+ if(Term->WritePos >= Term->TextWidth*Term->TextHeight*(giVT_Scrollback+1))
+ {
+ int base;
+
+ // Update previous line
+ Term->WritePos -= Term->TextWidth;
+ VT_int_UpdateScreen( Term, 0 );
+
+ // Update view position
+ base = Term->TextWidth*Term->TextHeight*(giVT_Scrollback);
+ if(Term->ViewPos < base)
+ Term->ViewPos += Term->Width;
+ if(Term->ViewPos > base)
+ Term->ViewPos = base;
+
+ VT_int_ScrollText(Term, 1);
+ }
+ // Ok, so we only need to scroll the screen
+ else if(Term->WritePos >= Term->ViewPos + Term->TextWidth*Term->TextHeight)
+ {
+ // Update the last line
+ Term->WritePos -= Term->TextWidth;
+ VT_int_UpdateScreen( Term, 0 );
+ Term->WritePos += Term->TextWidth;
+
+ VT_int_ScrollText(Term, 1);
+
+ Term->ViewPos += Term->TextWidth;
+ }
+ }
+
+ //LEAVE('-');
+}
+
+void VT_int_ScrollText(tVTerm *Term, int Count)
+{
+ tVT_Char *buf;
+ int height, init_write_pos;
+ int len, i;
+ int scroll_top, scroll_height;
+
+ // Get buffer pointer and attributes
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ buf = Term->AltBuf;
+ height = Term->TextHeight;
+ init_write_pos = Term->AltWritePos;
+ scroll_top = Term->ScrollTop;
+ scroll_height = Term->ScrollHeight;
+ }
+ else
+ {
+ buf = Term->Text;
+ height = Term->TextHeight*(giVT_Scrollback+1);
+ init_write_pos = Term->WritePos;
+ scroll_top = 0;
+ scroll_height = height;
+ }
+
+ // Scroll text downwards
+ if( Count > 0 )
+ {
+ int base;
+
+ // Set up
+ if(Count > scroll_height) Count = scroll_height;
+ base = Term->TextWidth*(scroll_top + scroll_height - Count);
+ len = Term->TextWidth*(scroll_height - Count);
// Scroll terminal cache
- base = Term->TextWidth*(Term->TextHeight*(giVT_Scrollback+1)-1);
- memcpy(
- Term->Text,
- &Term->Text[Term->TextWidth],
- base*sizeof(tVT_Char)
+ memmove(
+ &buf[Term->TextWidth*scroll_top],
+ &buf[Term->TextWidth*(scroll_top+Count)],
+ len*sizeof(tVT_Char)
);
-
- // Clear last row
- for( i = 0; i < Term->TextWidth; i ++ )
+ // Clear last rows
+ for( i = 0; i < Term->TextWidth*Count; i ++ )
{
- Term->Text[ base + i ].Ch = 0;
- Term->Text[ base + i ].Colour = Term->CurColour;
+ buf[ base + i ].Ch = 0;
+ buf[ base + i ].Colour = Term->CurColour;
}
- VT_int_ScrollFramebuffer( Term );
- VT_int_UpdateScreen( Term, 0 );
+ // Update Screen
+ VT_int_ScrollFramebuffer( Term, Count );
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ Term->AltWritePos = base;
+ else
+ Term->WritePos = Term->ViewPos + Term->TextWidth*(Term->TextHeight - Count);
+ for( i = 0; i < Count; i ++ )
+ {
+ VT_int_UpdateScreen( Term, 0 );
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ Term->AltWritePos += Term->TextWidth;
+ else
+ Term->WritePos += Term->TextWidth;
+ }
}
- // Ok, so we only need to scroll the screen
- else if(Term->WritePos >= Term->ViewPos + Term->TextWidth*Term->TextHeight)
+ else
{
- //Debug("Term->WritePos (%i) >= %i",
- // Term->WritePos,
- // Term->ViewPos + Term->Width*Term->Height
- // );
- //Debug("Scrolling screen only");
+ Count = -Count;
+ if(Count > scroll_height) Count = scroll_height;
- // Update the last line
- Term->WritePos -= Term->TextWidth;
- VT_int_UpdateScreen( Term, 0 );
- Term->WritePos += Term->TextWidth;
- VT_int_ClearLine(Term, Term->WritePos / Term->TextWidth);
+ len = Term->TextWidth*(scroll_height - Count);
- // Scroll
- Term->ViewPos += Term->TextWidth;
- //Debug("Term->ViewPos = %i", Term->ViewPos);
- VT_int_ScrollFramebuffer( Term );
- VT_int_UpdateScreen( Term, 0 );
+ // Scroll terminal cache
+ memmove(
+ &buf[Term->TextWidth*(scroll_top+Count)],
+ &buf[Term->TextWidth*scroll_top],
+ len*sizeof(tVT_Char)
+ );
+ // Clear preceding rows
+ for( i = 0; i < Term->TextWidth*Count; i ++ )
+ {
+ buf[ i ].Ch = 0;
+ buf[ i ].Colour = Term->CurColour;
+ }
+
+ VT_int_ScrollFramebuffer( Term, -Count );
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ Term->AltWritePos = Term->TextWidth*scroll_top;
+ else
+ Term->WritePos = Term->ViewPos;
+ for( i = 0; i < Count; i ++ )
+ {
+ VT_int_UpdateScreen( Term, 0 );
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ Term->AltWritePos += Term->TextWidth;
+ else
+ Term->WritePos += Term->TextWidth;
+ }
}
- //LEAVE('-');
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ Term->AltWritePos = init_write_pos;
+ else
+ Term->WritePos = init_write_pos;
}
/**
- * \fn void VT_int_ScrollFramebuffer( tVTerm *Term )
- * \note Scrolls the framebuffer by 1 text line
+ * \fn void VT_int_ScrollFramebuffer( tVTerm *Term, int Count )
+ * \note Scrolls the framebuffer down by \a Count text lines
*/
-void VT_int_ScrollFramebuffer( tVTerm *Term )
+void VT_int_ScrollFramebuffer( tVTerm *Term, int Count )
{
int tmp;
struct {
// Only update if this is the current terminal
if( Term != gpVT_CurTerm ) return;
+ if( Count > Term->ScrollHeight ) Count = Term->ScrollHeight;
+ if( Count < -Term->ScrollHeight ) Count = -Term->ScrollHeight;
+
// Switch to 2D Command Stream
tmp = VIDEO_BUFFMT_2DSTREAM;
VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp);
- // BLIT from 0,0 to 0,giVT_CharHeight
+ // BLIT to 0,0 from 0,giVT_CharHeight
buf.Op = VIDEO_2DOP_BLIT;
- buf.DstX = 0; buf.DstY = 0;
- buf.SrcX = 0; buf.SrcY = giVT_CharHeight;
+ buf.SrcX = 0; buf.DstX = 0;
+ // TODO: Don't assume character dimensions
buf.W = Term->TextWidth * giVT_CharWidth;
- buf.H = (Term->TextHeight-1) * giVT_CharHeight;
+ if( Count > 0 )
+ {
+ buf.SrcY = (Term->ScrollTop+Count) * giVT_CharHeight;
+ buf.DstY = Term->ScrollTop * giVT_CharHeight;
+ }
+ else // Scroll up, move text down
+ {
+ Count = -Count;
+ buf.SrcY = Term->ScrollTop * giVT_CharHeight;
+ buf.DstY = (Term->ScrollTop+Count) * giVT_CharHeight;
+ }
+ buf.H = (Term->ScrollHeight-Count) * giVT_CharHeight;
VFS_WriteAt(giVT_OutputDevHandle, 0, sizeof(buf), &buf);
// Restore old mode (this function is only called during text mode)
VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp);
}
+void VT_int_UpdateCursor( tVTerm *Term, int bShow )
+{
+ tVideo_IOCtl_Pos csr_pos;
+
+ if( Term != gpVT_CurTerm ) return ;
+
+ if( !bShow )
+ {
+ csr_pos.x = -1;
+ csr_pos.y = -1;
+ }
+ else if( Term->Mode == TERM_MODE_TEXT )
+ {
+ int offset;
+
+// if( !(Term->Flags & VT_FLAG_SHOWCSR)
+// && ( (Term->Flags & VT_FLAG_HIDECSR) || !Term->Node.ReadThreads)
+// )
+ if( !Term->Text || Term->Flags & VT_FLAG_HIDECSR )
+ {
+ csr_pos.x = -1;
+ csr_pos.y = -1;
+ }
+ else
+ {
+ if(Term->Flags & VT_FLAG_ALTBUF)
+ offset = Term->AltWritePos;
+ else
+ offset = Term->WritePos - Term->ViewPos;
+
+ csr_pos.x = offset % Term->TextWidth;
+ csr_pos.y = offset / Term->TextWidth;
+ if( 0 > csr_pos.y || csr_pos.y >= Term->TextHeight )
+ csr_pos.y = -1, csr_pos.x = -1;
+ }
+ }
+ else
+ {
+ csr_pos.x = Term->VideoCursorX;
+ csr_pos.y = Term->VideoCursorY;
+ }
+ VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &csr_pos);
+}
+
/**
* \fn void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
* \brief Updates the video framebuffer
*/
void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
{
+ tVT_Char *buffer;
+ int view_pos, write_pos;
// Only update if this is the current terminal
if( Term != gpVT_CurTerm ) return;
switch( Term->Mode )
{
case TERM_MODE_TEXT:
+ view_pos = (Term->Flags & VT_FLAG_ALTBUF) ? 0 : Term->ViewPos;
+ write_pos = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltWritePos : Term->WritePos;
+ buffer = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltBuf : Term->Text;
// Re copy the entire screen?
if(UpdateAll) {
VFS_WriteAt(
giVT_OutputDevHandle,
0,
Term->TextWidth*Term->TextHeight*sizeof(tVT_Char),
- &Term->Text[Term->ViewPos]
+ &buffer[view_pos]
);
}
// Only copy the current line
else {
- int pos = Term->WritePos - Term->WritePos % Term->TextWidth;
+ int ofs = write_pos - write_pos % Term->TextWidth;
VFS_WriteAt(
giVT_OutputDevHandle,
- (pos - Term->ViewPos)*sizeof(tVT_Char),
+ (ofs - view_pos)*sizeof(tVT_Char),
Term->TextWidth*sizeof(tVT_Char),
- &Term->Text[pos]
+ &buffer[ofs]
);
}
break;
);
break;
}
+
+ VT_int_UpdateCursor(Term, 1);
}
/**
*/
void VT_int_ChangeMode(tVTerm *Term, int NewMode, int NewWidth, int NewHeight)
{
- int oldW = Term->Width;
- int oldTW = oldW / giVT_CharWidth;
- int oldH = Term->Height;
- int oldTH = oldH / giVT_CharWidth;
- tVT_Char *oldTBuf = Term->Text;
- Uint32 *oldFB = Term->Buffer;
- int w, h, i;
-
// TODO: Increase RealWidth/RealHeight when this happens
if(NewWidth > giVT_RealWidth) NewWidth = giVT_RealWidth;
if(NewHeight > giVT_RealHeight) NewHeight = giVT_RealHeight;
- // Calculate new dimensions
- Term->TextWidth = NewWidth / giVT_CharWidth;
- Term->TextHeight = NewHeight / giVT_CharHeight;
- Term->Width = NewWidth;
- Term->Height = NewHeight;
Term->Mode = NewMode;
-
- // Allocate new buffers
- // - Text
- Term->Text = calloc(
- Term->TextWidth * Term->TextHeight * (giVT_Scrollback+1),
- sizeof(tVT_Char)
- );
- if(oldTBuf) {
- // Copy old buffer
- w = oldTW;
- if( w > Term->TextWidth ) w = Term->TextWidth;
- h = oldTH;
- if( h > Term->TextHeight ) h = Term->TextHeight;
- h *= giVT_Scrollback + 1;
- for( i = 0; i < h; i ++ )
- {
- memcpy(
- &Term->Text[i*Term->TextWidth],
- &oldTBuf[i*oldTW],
- w*sizeof(tVT_Char)
- );
-
+
+ if(NewWidth != Term->Width || NewHeight != Term->Height)
+ {
+ int oldW = Term->Width;
+ int oldTW = Term->TextWidth;
+ int oldH = Term->Height;
+ int oldTH = Term->TextHeight;
+ tVT_Char *oldTBuf = Term->Text;
+ Uint32 *oldFB = Term->Buffer;
+ int w, h, i;
+ // Calculate new dimensions
+ Term->Width = NewWidth;
+ Term->Height = NewHeight;
+ Term->TextWidth = NewWidth / giVT_CharWidth;
+ Term->TextHeight = NewHeight / giVT_CharHeight;
+ Term->ScrollHeight = Term->TextHeight - (oldTH - Term->ScrollHeight) - Term->ScrollTop;
+
+ // Allocate new buffers
+ // - Text
+ Term->Text = calloc(
+ Term->TextWidth * Term->TextHeight * (giVT_Scrollback+1),
+ sizeof(tVT_Char)
+ );
+ if(oldTBuf) {
+ // Copy old buffer
+ w = (oldTW > Term->TextWidth) ? Term->TextWidth : oldTW;
+ h = (oldTH > Term->TextHeight) ? Term->TextHeight : oldTH;
+ h *= giVT_Scrollback + 1;
+ for( i = 0; i < h; i ++ )
+ {
+ memcpy(
+ &Term->Text[i*Term->TextWidth],
+ &oldTBuf[i*oldTW],
+ w*sizeof(tVT_Char)
+ );
+ }
+ free(oldTBuf);
}
- }
-
- // - Framebuffer
- Term->Buffer = calloc( Term->Width * Term->Height, sizeof(Uint32) );
- if(oldFB) {
- // Copy old buffer
- w = oldW;
- if( w > Term->Width ) w = Term->Width;
- h = oldH;
- if( h > Term->Height ) h = Term->Height;
- for( i = 0; i < h; i ++ )
+
+ // - Alternate Text
+ Term->AltBuf = realloc(
+ Term->AltBuf,
+ Term->TextWidth * Term->TextHeight * sizeof(tVT_Char)
+ );
+
+ // - Framebuffer
+ Term->Buffer = calloc( Term->Width * Term->Height, sizeof(Uint32) );
+ if(oldFB) {
+ // Copy old buffer
+ w = (oldW > Term->Width) ? Term->Width : oldW;
+ h = (oldH > Term->Height) ? Term->Height : oldH;
+ for( i = 0; i < h; i ++ )
+ {
+ memcpy(
+ &Term->Buffer[i*Term->Width],
+ &oldFB[i*oldW],
+ w*sizeof(Uint32)
+ );
+ }
+ free(oldFB);
+ }
+
+ // Debug
+ switch(NewMode)
{
- memcpy(
- &Term->Buffer[i*Term->Width],
- &oldFB[i*oldW],
- w*sizeof(Uint32)
- );
+ case TERM_MODE_TEXT:
+ Log_Log("VTerm", "Set VT %p to text mode (%ix%i)",
+ Term, Term->TextWidth, Term->TextHeight);
+ break;
+ case TERM_MODE_FB:
+ Log_Log("VTerm", "Set VT %p to framebuffer mode (%ix%i)",
+ Term, Term->Width, Term->Height);
+ break;
+ //case TERM_MODE_2DACCEL:
+ //case TERM_MODE_3DACCEL:
+ // return;
}
}
-
- // Debug
- switch(NewMode)
- {
- case TERM_MODE_TEXT:
- Log_Log("VTerm", "Set VT %p to text mode (%ix%i)",
- Term, Term->TextWidth, Term->TextHeight);
- break;
- case TERM_MODE_FB:
- Log_Log("VTerm", "Set VT %p to framebuffer mode (%ix%i)",
- Term, Term->Width, Term->Height);
- break;
- //case TERM_MODE_2DACCEL:
- //case TERM_MODE_3DACCEL:
- // return;
- }
+}
+
+
+void VT_int_ToggleAltBuffer(tVTerm *Term, int Enabled)
+{
+ if(Enabled)
+ Term->Flags |= VT_FLAG_ALTBUF;
+ else
+ Term->Flags &= ~VT_FLAG_ALTBUF;
+ VT_int_UpdateScreen(Term, 1);
}
// ---
// Fast returns
if( Depth == 24 ) return VT_Colour12to24(Col12);
if( Depth == 15 ) return VT_Colour12to15(Col12);
+ // - 32 is a special case, it's usually 24-bit colour with an unused byte
+ if( Depth == 32 ) return VT_Colour12to24(Col12);
// Bounds checks
if( Depth < 8 ) return 0;