+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
+ memmove(
+ &buf[Term->TextWidth*scroll_top],
+ &buf[Term->TextWidth*(scroll_top+Count)],
+ len*sizeof(tVT_Char)
+ );
+ // Clear last rows
+ for( i = 0; i < Term->TextWidth*Count; i ++ )
+ {
+ buf[ base + i ].Ch = 0;
+ buf[ base + i ].Colour = Term->CurColour;
+ }
+
+ // 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;
+ }
+ }
+ else
+ {
+ Count = -Count;
+ if(Count > scroll_height) Count = scroll_height;
+
+ len = Term->TextWidth*(scroll_height - Count);
+
+ // 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;
+ }
+ }
+
+ 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);
+}
+
+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);
+}
+