3 * - By John Hodge (thePowersGang)
13 #include <acess/sys.h>
14 #include <acess/devices/pty.h>
15 #include <acess/devices/pty_cmds.h>
16 #include "resources/cursor.h"
21 CVideo::CVideo(const CConfigVideo& config):
25 m_bufferFormat(PTYBUFFMT_TEXT)
29 if( _SysIOCtl(m_fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL )
30 throw AxWin::InitFailure("stdin isn't a terminal");
32 if( _SysIOCtl(m_fd, PTY_IOCTL_GETDIMS, &dims) == -1 )
33 throw AxWin::InitFailure("Failed to get dimensions from stdin");
36 if( m_width == 0 || m_height == 0 )
37 throw AxWin::InitFailure("Terminal not capable of graphics");
40 _SysDebug("m_width=%i, m_height=%i", m_width, m_height);
43 SetCursorPos( m_width/2, m_height/2 );
45 SetBufFormat(PTYBUFFMT_FB);
46 uint32_t data[m_width];
47 for( unsigned int i = 0; i < m_height; i ++ )
48 BlitLine(data, i, 0, m_width);
51 void CVideo::GetDims(unsigned int& w, unsigned int& h)
57 void CVideo::BlitLine(const uint32_t* src, unsigned int dst_y, unsigned int dst_x, unsigned int width)
59 //_SysDebug("CVideo::BlitLine (%p, %i, %i, %i)", src, dst_y, dst_x, width);
60 //_SysDebugHex("CVideo::BlitLine", src, width*4);
61 size_t cmdlen = (sizeof(struct ptycmd_senddata) + width*4)/4;
62 //_SysDebug(" - Offset = %i, cmdlen = %i", (dst_y * m_width + dst_x) * 4, cmdlen);
63 struct ptycmd_senddata cmd = {
64 {PTY2D_CMD_SEND, uint8_t(cmdlen & 0xFF), uint16_t(cmdlen>>8)},
65 (dst_y * m_width + dst_x)
67 SetBufFormat(PTYBUFFMT_2DCMD);
68 _SysWrite(m_fd, &cmd, sizeof(cmd));
69 _SysWrite(m_fd, src, width*4);
74 // TODO: Write to a local copy of the framebuffer in BlitLine, and then flush out in this function
77 void CVideo::SetBufFormat(unsigned int FormatID)
79 if( m_bufferFormat != FormatID )
82 struct ptymode mode = {.OutputMode = FormatID, .InputMode = 0};
83 int rv = _SysIOCtl( m_fd, PTY_IOCTL_SETMODE, &mode );
85 throw ::AxWin::InitFailure("Can't set PTY to framebuffer mode");
88 m_bufferFormat = FormatID;
92 void CVideo::SetCursorBitmap()
94 // Set cursor position and bitmap
95 struct ptycmd_header hdr = {PTY2D_CMD_SETCURSORBMP,0,0};
96 size_t size = sizeof(hdr) + sizeof(cCursorBitmap) + cCursorBitmap.W*cCursorBitmap.H*4;
97 hdr.len_low = size / 4;
98 hdr.len_hi = size / (256*4);
100 SetBufFormat(PTYBUFFMT_2DCMD);
101 _SysWrite(m_fd, &hdr, sizeof(hdr));
102 _SysDebug("SetCursorBitmap - size = %i (%04x:%02x * 4)", size, hdr.len_hi, hdr.len_low);
103 _SysWrite(m_fd, &cCursorBitmap, size-sizeof(hdr));
106 void CVideo::SetCursorPos(int X, int Y)
108 struct ptycmd_setcursorpos cmd;
109 cmd.hdr.cmd = PTY2D_CMD_SETCURSORPOS;
110 cmd.hdr.len_low = sizeof(cmd)/4;
115 SetBufFormat(PTYBUFFMT_2DCMD);
116 _SysWrite(m_fd, &cmd, sizeof(cmd));
119 }; // namespace AxWin