+CVideo::CVideo(const CConfigVideo& config):
+ m_fd(1),
+ m_width(0),
+ m_height(0),
+ m_bufferFormat(PTYBUFFMT_TEXT)
+{
+ // Obtain dimensions
+ {
+ if( _SysIOCtl(m_fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL )
+ throw AxWin::InitFailure("stdin isn't a terminal");
+ struct ptydims dims;
+ if( _SysIOCtl(m_fd, PTY_IOCTL_GETDIMS, &dims) == -1 )
+ throw AxWin::InitFailure("Failed to get dimensions from stdin");
+ m_width = dims.PW;
+ m_height = dims.PH;
+ if( m_width == 0 || m_height == 0 )
+ throw AxWin::InitFailure("Terminal not capable of graphics");
+ }
+
+ _SysDebug("m_width=%i, m_height=%i", m_width, m_height);
+ SetCursorBitmap();
+
+ SetCursorPos( m_width/2, m_height/2 );
+
+ SetBufFormat(PTYBUFFMT_FB);
+ uint32_t data[m_width];
+ for( unsigned int i = 0; i < m_height; i ++ )
+ BlitLine(data, i, 0, m_width);
+}
+
+void CVideo::GetDims(unsigned int& w, unsigned int& h)
+{
+ w = m_width;
+ h = m_height;
+}
+
+void CVideo::BlitLine(const uint32_t* src, unsigned int dst_y, unsigned int dst_x, unsigned int width)
+{
+ //_SysDebug("CVideo::BlitLine (%p, %i, %i, %i)", src, dst_y, dst_x, width);
+ //_SysDebugHex("CVideo::BlitLine", src, width*4);
+ size_t cmdlen = (sizeof(struct ptycmd_senddata) + width*4)/4;
+ //_SysDebug(" - Offset = %i, cmdlen = %i", (dst_y * m_width + dst_x) * 4, cmdlen);
+ struct ptycmd_senddata cmd = {
+ {PTY2D_CMD_SEND, uint8_t(cmdlen & 0xFF), uint16_t(cmdlen>>8)},
+ (dst_y * m_width + dst_x)
+ };
+ SetBufFormat(PTYBUFFMT_2DCMD);
+ _SysWrite(m_fd, &cmd, sizeof(cmd));
+ _SysWrite(m_fd, src, width*4);
+}