3 * - By John Hodge (thePowersGang)
6 * - Virtual Terminal - Input code
9 #include <api_drv_video.h>
14 * \fn void VT_InitOutput()
15 * \brief Initialise Video Output
19 giVT_OutputDevHandle = VFS_Open(gsVT_OutputDevice, VFS_OPENFLAG_WRITE);
20 if(giVT_OutputDevHandle == -1) {
21 Log_Warning("VTerm", "Oh F**k, I can't open the video device '%s'", gsVT_OutputDevice);
24 VT_SetResolution( giVT_RealWidth, giVT_RealHeight );
26 VT_SetMode( VIDEO_BUFFMT_TEXT );
27 LOG("VTerm output initialised");
31 * \brief Set video output buffer mode
33 void VT_SetMode(int Mode)
35 VFS_IOCtl( giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &Mode );
39 * \fn void VT_int_ScrollFramebuffer( tVTerm *Term, int Count )
40 * \note Scrolls the framebuffer down by \a Count text lines
42 void VT_int_ScrollFramebuffer( tVTerm *Term, int Count )
52 // Only update if this is the current terminal
53 if( Term != gpVT_CurTerm ) return;
55 if( Count > Term->ScrollHeight ) Count = Term->ScrollHeight;
56 if( Count < -Term->ScrollHeight ) Count = -Term->ScrollHeight;
58 // Switch to 2D Command Stream
59 tmp = VIDEO_BUFFMT_2DSTREAM;
60 VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp);
62 // BLIT to 0,0 from 0,giVT_CharHeight
63 buf.Op = VIDEO_2DOP_BLIT;
64 buf.SrcX = 0; buf.DstX = 0;
65 // TODO: Don't assume character dimensions
66 buf.W = Term->TextWidth * giVT_CharWidth;
69 buf.SrcY = (Term->ScrollTop+Count) * giVT_CharHeight;
70 buf.DstY = Term->ScrollTop * giVT_CharHeight;
72 else // Scroll up, move text down
75 buf.SrcY = Term->ScrollTop * giVT_CharHeight;
76 buf.DstY = (Term->ScrollTop+Count) * giVT_CharHeight;
78 buf.H = (Term->ScrollHeight-Count) * giVT_CharHeight;
79 VFS_WriteAt(giVT_OutputDevHandle, 0, sizeof(buf), &buf);
81 // Restore old mode (this function is only called during text mode)
82 tmp = VIDEO_BUFFMT_TEXT;
83 VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp);
86 void VT_int_UpdateCursor( tVTerm *Term, int bShow )
88 tVideo_IOCtl_Pos csr_pos;
90 if( Term != gpVT_CurTerm ) return ;
97 else if( Term->Mode == TERM_MODE_TEXT )
99 // if( !(Term->Flags & VT_FLAG_SHOWCSR)
100 // && ( (Term->Flags & VT_FLAG_HIDECSR) || !Term->Node.ReadThreads)
102 if( !Term->Text || Term->Flags & VT_FLAG_HIDECSR )
109 const tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
110 csr_pos.x = wrpos->Col;
111 csr_pos.y = wrpos->Row - (Term->Flags & VT_FLAG_ALTBUF ? 0 : Term->ViewTopRow);
112 if( 0 > csr_pos.y || csr_pos.y >= Term->TextHeight )
113 csr_pos.y = -1, csr_pos.x = -1;
118 csr_pos.x = Term->VideoCursorX;
119 csr_pos.y = Term->VideoCursorY;
121 VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &csr_pos);
125 * \fn void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
126 * \brief Updates the video framebuffer
128 void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
130 // Only update if this is the current terminal
131 if( Term != gpVT_CurTerm ) return;
135 case TERM_MODE_TEXT: {
136 size_t view_pos = (Term->Flags & VT_FLAG_ALTBUF) ? 0 : Term->ViewTopRow*Term->TextWidth;
137 const tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
138 const tVT_Char *buffer = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltBuf : Term->Text;
139 // Re copy the entire screen?
142 giVT_OutputDevHandle,
144 Term->TextWidth*Term->TextHeight*sizeof(tVT_Char),
148 // Only copy the current line
150 size_t ofs = wrpos->Row * Term->TextWidth;
152 giVT_OutputDevHandle,
153 (ofs - view_pos)*sizeof(tVT_Char),
154 Term->TextWidth*sizeof(tVT_Char),
163 VT_int_UpdateCursor(Term, 1);