/* * QEMU graphical console * * Copyright (c) 2004 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "vl.h" #define DEFAULT_BACKSCROLL 512 #define MAX_CONSOLES 12 #define RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) #define RGB(r, g, b) RGBA(r, g, b, 0xff) typedef struct TextCell { uint8_t ch; uint8_t bgcol:4; uint8_t fgcol:4; } TextCell; #define MAX_ESC_PARAMS 3 enum TTYState { TTY_STATE_NORM, TTY_STATE_ESC, TTY_STATE_CSI, }; struct TextConsole { int text_console; /* true if text console */ DisplayState *ds; int g_width, g_height; int width; int height; int total_height; int backscroll_height; int fgcol; int bgcol; int x, y; int y_displayed; int y_base; TextCell *cells; enum TTYState state; int esc_params[MAX_ESC_PARAMS]; int nb_esc_params; /* kbd read handler */ IOReadHandler *fd_read; void *fd_opaque; }; static TextConsole *active_console; static TextConsole *consoles[MAX_CONSOLES]; static int nb_consoles = 0; /* convert a RGBA color to a color index usable in graphic primitives */ static unsigned int vga_get_color(DisplayState *ds, unsigned int rgba) { unsigned int r, g, b, color; switch(ds->depth) { #if 0 case 8: r = (rgba >> 16) & 0xff; g = (rgba >> 8) & 0xff; b = (rgba) & 0xff; color = (rgb_to_index[r] * 6 * 6) + (rgb_to_index[g] * 6) + (rgb_to_index[b]); break; #endif case 15: r = (rgba >> 16) & 0xff; g = (rgba >> 8) & 0xff; b = (rgba) & 0xff; color = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3); break; case 16: r = (rgba >> 16) & 0xff; g = (rgba >> 8) & 0xff; b = (rgba) & 0xff; color = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); break; case 32: default: color = rgba; break; } return color; } static void vga_fill_rect (DisplayState *ds, int posx, int posy, int width, int height, uint32_t color) { uint8_t *d, *d1; int x, y, bpp; bpp = (ds->depth + 7) >> 3; d1 = ds->data + ds->linesize * posy + bpp * posx; for (y = 0; y < height; y++) { d = d1; switch(bpp) { case 1: for (x = 0; x < width; x++) { *((uint8_t *)d) = color; d++; } break; case 2: for (x = 0; x < width; x++) { *((uint16_t *)d) = color; d += 2; } break; case 4: for (x = 0; x < width; x++) { *((uint32_t *)d) = color; d += 4; } break; } d1 += ds->linesize; } } /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */ static void vga_bitblt(DisplayState *ds, int xs, int ys, int xd, int yd, int w, int h) { const uint8_t *s; uint8_t *d; int wb, y, bpp; bpp = (ds->depth + 7) >> 3; wb = w * bpp; if (yd <= ys) { s = ds->data + ds->linesize * ys + bpp * xs; d = ds->data + ds->linesize * yd + bpp * xd; for (y = 0; y < h; y++) { memmove(d, s, wb); d += ds->linesize; s += ds->linesize; } } else { s = ds->data + ds->linesize * (ys + h - 1) + bpp * xs; d = ds->data + ds->linesize * (yd + h - 1) + bpp * xd; for (y = 0; y < h; y++) { memmove(d, s, wb); d -= ds->linesize; s -= ds->linesize; } } } /***********************************************************/ /* basic char display */ #define FONT_HEIGHT 16 #define FONT_WIDTH 8 #include "vgafont.h" #define cbswap_32(__x) \ ((uint32_t)( \ (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )) #ifdef WORDS_BIGENDIAN #define PAT(x) x #else #define PAT(x) cbswap_32(x) #endif static const uint32_t dmask16[16] = { PAT(0x00000000), PAT(0x000000ff), PAT(0x0000ff00), PAT(0x0000ffff), PAT(0x00ff0000), PAT(0x00ff00ff), PAT(0x00ffff00), PAT(0x00ffffff), PAT(0xff000000), PAT(0xff0000ff), PAT(0xff00ff00), PAT(0xff00ffff), PAT(0xffff0000), PAT(0xffff00ff), PAT(0xffffff00), PAT(0xffffffff), }; static const uint32_t dmask4[4] = { PAT(0x00000000), PAT(0x0000ffff), PAT(0xffff0000), PAT(0xffffffff), }; static uint32_t color_table[8]; static const uint32_t color_table_rgb[8] = { RGB(0x00, 0x00, 0x00), RGB(0xff, 0x00, 0x00), RGB(0x00, 0xff, 0x00), RGB(0xff, 0xff, 0x00), RGB(0x00, 0x00, 0xff), RGB(0x
/*
LUFA Library
Copyright (C) Dean Camera, 2010.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
#include "SideshowCommon.h"
uint16_t SideShow_Read_Unicode_String(void* const UnicodeString,
const uint16_t MaxBytes)
{
Unicode_String_t* const UnicodeStruct = (Unicode_String_t*)UnicodeString;
uint32_t UnicodeCharsToRead;
Endpoint_Read_Stream_LE(&UnicodeCharsToRead, sizeof(uint32_t));
int UnicodeData[UnicodeCharsToRead];
UnicodeStruct->LengthInBytes = (UnicodeCharsToRead << 1);
Endpoint_Read_Stream_LE(&UnicodeData, UnicodeStruct->LengthInBytes);
if (UnicodeStruct->LengthInBytes > MaxBytes)
UnicodeStruct->LengthInBytes = MaxBytes;
memcpy(&UnicodeStruct->UnicodeString, &UnicodeData, UnicodeStruct->LengthInBytes);
return ((UnicodeCharsToRead << 1) + sizeof(uint32_t));
}
void SideShow_Write_Unicode_String(void* const UnicodeString)
{
Unicode_String_t* const UnicodeStruct = (Unicode_String_t*)UnicodeString;
uint32_t StringSizeInCharacters = (UnicodeStruct->LengthInBytes >> 1);
Endpoint_Write_Stream_LE(&StringSizeInCharacters, sizeof(uint32_t));
Endpoint_Write_Stream_LE(&UnicodeStruct->UnicodeString, UnicodeStruct->LengthInBytes);
}
void SideShow_Discard_Byte_Stream(void)
{
uint32_t StreamSize;
Endpoint_Read_Stream_LE(&StreamSize, sizeof(uint32_t));
Endpoint_Discard_Stream(StreamSize);
}