- VT_int_UpdateScreen( Term, 0 );
- if( Term->Flags & VT_FLAG_ALTBUF )
- Term->AltWritePos += Term->TextWidth;
- else
- Term->WritePos += Term->TextWidth;
- }
- }
- else
- {
- Count = -Count;
- if(Count > Term->ScrollHeight) Count = Term->ScrollHeight;
-
- len = Term->TextWidth*(Term->ScrollHeight - Count);
-
- // Scroll terminal cache
- memcpy(
- &buf[Term->TextWidth*(Term->ScrollTop+Count)],
- &buf[Term->TextWidth*Term->ScrollTop],
- len*sizeof(tVT_Char)
- );
- // Clear preceding rows
- for( i = 0; i < Term->TextWidth*Count; i ++ )
- {
- Term->AltBuf[ i ].Ch = 0;
- Term->AltBuf[ i ].Colour = Term->CurColour;
- }
-
- VT_int_ScrollFramebuffer( Term, -Count );
- if( Term->Flags & VT_FLAG_ALTBUF )
- Term->AltWritePos = Term->TextWidth*Term->ScrollTop;
- else
- Term->WritePos = Term->ViewPos + Term->TextWidth*Term->ScrollTop;
- 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;
- }
- }
-
- if( Term->Flags & VT_FLAG_ALTBUF )
- Term->AltWritePos = init_write_pos;
- else
- Term->WritePos = init_write_pos;
-}
-
-/**
- * \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, int Count )
-{
- int tmp;
- struct {
- Uint8 Op;
- Uint16 DstX, DstY;
- Uint16 SrcX, SrcY;
- Uint16 W, H;
- } PACKED buf;
-
- // 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 to 0,0 from 0,giVT_CharHeight
- buf.Op = VIDEO_2DOP_BLIT;
- buf.SrcX = 0; buf.DstX = 0;
- // TODO: Don't assume character dimensions
- buf.W = Term->TextWidth * giVT_CharWidth;
- 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)
- tmp = VIDEO_BUFFMT_TEXT;
- VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp);
-}
-
-/**
- * \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),
- &buffer[view_pos]
- );
- }
- // Only copy the current line
- else {
- int ofs = write_pos - write_pos % Term->TextWidth;
- VFS_WriteAt(
- giVT_OutputDevHandle,
- (ofs - view_pos)*sizeof(tVT_Char),
- Term->TextWidth*sizeof(tVT_Char),
- &buffer[ofs]
- );
- }
- break;
- case TERM_MODE_FB:
- VFS_WriteAt(
- giVT_OutputDevHandle,
- 0,
- Term->Width*Term->Height*sizeof(Uint32),
- Term->Buffer
- );
- break;
- }
-}
-
-/**
- * \brief Update the screen mode
- * \param Term Terminal to update
- * \param NewMode New mode to set
- * \param NewWidth New framebuffer width
- * \param NewHeight New framebuffer height
- */
-void VT_int_ChangeMode(tVTerm *Term, int NewMode, int NewWidth, int NewHeight)
-{
-
- // TODO: Increase RealWidth/RealHeight when this happens
- if(NewWidth > giVT_RealWidth) NewWidth = giVT_RealWidth;
- if(NewHeight > giVT_RealHeight) NewHeight = giVT_RealHeight;
-
- Term->Mode = NewMode;
-
- 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)
- );