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 )
101 // if( !(Term->Flags & VT_FLAG_SHOWCSR)
102 // && ( (Term->Flags & VT_FLAG_HIDECSR) || !Term->Node.ReadThreads)
104 if( !Term->Text || Term->Flags & VT_FLAG_HIDECSR )
111 if(Term->Flags & VT_FLAG_ALTBUF)
112 offset = Term->AltWritePos;
114 offset = Term->WritePos - Term->ViewPos;
116 csr_pos.x = offset % Term->TextWidth;
117 csr_pos.y = offset / Term->TextWidth;
118 if( 0 > csr_pos.y || csr_pos.y >= Term->TextHeight )
119 csr_pos.y = -1, csr_pos.x = -1;
124 csr_pos.x = Term->VideoCursorX;
125 csr_pos.y = Term->VideoCursorY;
127 VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &csr_pos);
131 * \fn void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
132 * \brief Updates the video framebuffer
134 void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
137 int view_pos, write_pos;
138 // Only update if this is the current terminal
139 if( Term != gpVT_CurTerm ) return;
144 view_pos = (Term->Flags & VT_FLAG_ALTBUF) ? 0 : Term->ViewPos;
145 write_pos = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltWritePos : Term->WritePos;
146 buffer = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltBuf : Term->Text;
147 // Re copy the entire screen?
150 giVT_OutputDevHandle,
152 Term->TextWidth*Term->TextHeight*sizeof(tVT_Char),
156 // Only copy the current line
158 int ofs = write_pos - write_pos % Term->TextWidth;
160 giVT_OutputDevHandle,
161 (ofs - view_pos)*sizeof(tVT_Char),
162 Term->TextWidth*sizeof(tVT_Char),
171 VT_int_UpdateCursor(Term, 1);