3 * - By John Hodge (thePowersGang)
6 * - Virtual Terminal - Input code
10 #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;
58 if( Count > Term->ScrollHeight ) Count = Term->ScrollHeight;
59 if( Count < -Term->ScrollHeight ) Count = -Term->ScrollHeight;
60 LOG("Count = %i", Count);
62 // Switch to 2D Command Stream
63 tmp = VIDEO_BUFFMT_2DSTREAM;
64 VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp);
66 // BLIT to 0,0 from 0,giVT_CharHeight
67 buf.Op = VIDEO_2DOP_BLIT;
68 buf.SrcX = 0; buf.DstX = 0;
69 // TODO: Don't assume character dimensions
70 buf.W = Term->TextWidth * giVT_CharWidth;
73 buf.SrcY = (Term->ScrollTop+Count) * giVT_CharHeight;
74 buf.DstY = Term->ScrollTop * giVT_CharHeight;
76 else // Scroll up, move text down
79 buf.SrcY = Term->ScrollTop * giVT_CharHeight;
80 buf.DstY = (Term->ScrollTop+Count) * giVT_CharHeight;
82 buf.H = (Term->ScrollHeight-Count) * giVT_CharHeight;
83 VFS_WriteAt(giVT_OutputDevHandle, 0, sizeof(buf), &buf);
85 // Restore old mode (this function is only called during text mode)
86 tmp = VIDEO_BUFFMT_TEXT;
87 VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETBUFFORMAT, &tmp);
91 void VT_int_UpdateCursor( tVTerm *Term, int bShow )
93 tVideo_IOCtl_Pos csr_pos;
95 if( Term != gpVT_CurTerm ) return ;
97 ENTER("pTerm bShow", Term, bShow);
104 else if( Term->Mode == TERM_MODE_TEXT )
106 // if( !(Term->Flags & VT_FLAG_SHOWCSR)
107 // && ( (Term->Flags & VT_FLAG_HIDECSR) || !Term->Node.ReadThreads)
109 if( !Term->Text || Term->Flags & VT_FLAG_HIDECSR )
116 const tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
117 csr_pos.x = wrpos->Col;
118 csr_pos.y = wrpos->Row - (Term->Flags & VT_FLAG_ALTBUF ? 0 : Term->ViewTopRow);
119 if( 0 > csr_pos.y || csr_pos.y >= Term->TextHeight )
120 csr_pos.y = -1, csr_pos.x = -1;
125 csr_pos.x = Term->VideoCursorX;
126 csr_pos.y = Term->VideoCursorY;
128 VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &csr_pos);
133 * \fn void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
134 * \brief Updates the video framebuffer
136 void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
138 ENTER("pTerm iUpdateAll", Term, UpdateAll);
139 // Only update if this is the current terminal
140 if( Term != gpVT_CurTerm ) {
141 LOG("Term != gpVT_CurTerm (%p)", gpVT_CurTerm);
148 case TERM_MODE_TEXT: {
149 size_t view_pos = (Term->Flags & VT_FLAG_ALTBUF) ? 0 : Term->ViewTopRow*Term->TextWidth;
150 const tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
151 const tVT_Char *buffer = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltBuf : Term->Text;
152 LOG("view_pos = %i, wrpos = %p (R%i,C%i), buffer=%p", view_pos, wrpos, wrpos->Row, wrpos->Col, buffer);
153 // Re copy the entire screen?
156 giVT_OutputDevHandle,
158 Term->TextWidth*Term->TextHeight*sizeof(tVT_Char),
162 // Only copy the current line
164 size_t ofs = wrpos->Row * Term->TextWidth;
165 LOG("ofs = %i", ofs);
167 giVT_OutputDevHandle,
168 (ofs - view_pos)*sizeof(tVT_Char),
169 Term->TextWidth*sizeof(tVT_Char),
178 VT_int_UpdateCursor(Term, 1);