/uspace/trunk/console/screenbuffer.h |
---|
0,0 → 1,72 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __SCREENBUFFER_H__ |
#define __SCREENBUFFER_H__ |
#define DEFAULT_FOREGROUND_COLOR 0xffffff |
#define DEFAULT_BACKGROUND_COLOR 0x00003f |
typedef struct { |
unsigned int bg_color; /**< background color */ |
unsigned int fg_color; /**< foreground color */ |
} style_t; |
/** One field at screen. It contain one character and its attributes. */ |
typedef struct { |
char character; /**< Character itself */ |
style_t style; /**< Character`s attributes */ |
} keyfield_t; |
/** Structure for buffering state of one virtual console. |
*/ |
typedef struct { |
keyfield_t *buffer; /**< Screen content - characters and its style. Used as cyclyc buffer. */ |
unsigned int size_x, size_y; /**< Number of columns and rows */ |
unsigned int position_x, position_y; /**< Coordinates of last printed character for determining cursor position */ |
style_t style; /**< Current style */ |
unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ |
} screenbuffer_t; |
static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
{ |
return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
} |
int screenbuffer_putchar(screenbuffer_t *scr, char c); |
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y); |
void screenbuffer_clear(screenbuffer_t *scr); |
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line); |
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); |
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y); |
#endif |
/uspace/trunk/console/console.c |
---|
38,12 → 38,13 |
#include <unistd.h> |
#include <async.h> |
#include <libadt/fifo.h> |
#include <screenbuffer.h> |
static void sysput(char c) |
{ |
__SYSCALL3(SYS_IO, 1, &c, 1); |
} |
} |
//#define CONSOLE_COUNT VFB_CONNECTIONS |
#define CONSOLE_COUNT 8 |
#define MAX_KEYREQUESTS_BUFFERED 32 |
52,13 → 53,19 |
int active_console = 1; |
struct { |
int phone; /**< Framebuffer phone */ |
int rows; /**< Framebuffer rows */ |
int cols; /**< Framebuffer columns */ |
} fb_info; |
typedef struct { |
keybuffer_t keybuffer; |
FIFO_CREATE_STATIC(keyrequests, ipc_callid_t , MAX_KEYREQUESTS_BUFFERED); |
int keyrequest_counter; |
int client_phone; |
int vfb_phone; |
int used; |
screenbuffer_t screenbuffer; |
} connection_t; |
connection_t connections[CONSOLE_COUNT]; |
94,7 → 101,7 |
ipc_callid_t callid; |
ipc_call_t call; |
int retval; |
int i; |
int i, j; |
char c; |
/* Ignore parameters, the connection is alread opened */ |
115,7 → 122,19 |
/* switch to another virtual console */ |
if ((c >= KBD_KEY_F1) && (c < KBD_KEY_F1 + CONSOLE_COUNT)) { |
/*FIXME: draw another console content from buffer */ |
active_console = c - KBD_KEY_F1; |
ipc_call_async_2(fb_info.phone, FB_CLEAR, 0, 0, NULL, NULL); |
ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, 'a', 0, 0,NULL,NULL, NULL); |
for (i = 0; i < connections[active_console].screenbuffer.size_x; i++) |
for (j = 0; j < connections[active_console].screenbuffer.size_y; j++) { |
ipc_call_async_3(fb_info.phone, FB_PUTCHAR, get_field_at(&(connections[active_console].screenbuffer),\ |
i, j)->character, j, i, NULL, NULL, NULL); |
} |
break; |
} |
153,8 → 172,10 |
ipc_answer_fast(iid,ELIMIT,0,0); |
return; |
} |
connections[consnum].used = 1; |
connections[consnum].client_phone = IPC_GET_ARG3(call); |
screenbuffer_clear(&(connections[consnum].screenbuffer)); |
/* Accept the connection */ |
ipc_answer_fast(iid,0,0,0); |
167,15 → 188,28 |
ipc_answer_fast(callid, 0,0,0); |
return; |
case CONSOLE_PUTCHAR: |
if (consnum != active_console) { |
/* Send message to fb */ |
if (consnum == active_console) { |
ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, IPC_GET_ARG2(call), connections[consnum].screenbuffer.position_y, \ |
connections[consnum].screenbuffer.position_x, NULL, NULL, NULL); |
} |
/* Send message to fb */ |
ipc_call_sync_2(connections[consnum].vfb_phone, FB_PUTCHAR, IPC_GET_ARG1(call), IPC_GET_ARG2(call), NULL, NULL); |
// ipc_call_sync_2(connections[6].vfb_phone, FB_PUTCHAR, 0, IPC_GET_ARG2(call),NULL,NULL); |
screenbuffer_putchar(&(connections[consnum].screenbuffer), IPC_GET_ARG2(call)); |
break; |
case CONSOLE_CLEAR: |
/* Send message to fb */ |
if (consnum == active_console) { |
ipc_call_async_2(fb_info.phone, FB_CLEAR, 0, 0, NULL, NULL); |
} |
screenbuffer_clear(&(connections[consnum].screenbuffer)); |
break; |
case CONSOLE_GOTO: |
screenbuffer_goto(&(connections[consnum].screenbuffer), IPC_GET_ARG1(call), IPC_GET_ARG2(call)); |
break; |
case CONSOLE_GETCHAR: |
219,17 → 253,29 |
/* Connect to framebuffer driver */ |
while ((fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
usleep(10000); |
} |
ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, '1', 0, 0,NULL,NULL, NULL); |
ipc_call_sync_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols)); |
/* Init virtual consoles */ |
for (i = 0; i < CONSOLE_COUNT; i++) { |
ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, '$', 2*i, 1,NULL,NULL, NULL); |
connections[i].used = 0; |
keybuffer_init(&(connections[i].keybuffer)); |
ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, '>', 2*i+1, 1,NULL,NULL, NULL); |
/* TODO: init key_buffer */ |
while ((connections[i].vfb_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) { |
usleep(10000); |
} |
connections[i].keyrequests.head = connections[i].keyrequests.tail = 0; |
connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED; |
connections[i].keyrequest_counter = 0; |
ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, '?', 2*i+1, 1,NULL,NULL, NULL); |
if (screenbuffer_init(&(connections[i].screenbuffer), fb_info.cols, fb_info.rows ) == NULL) { |
/*FIXME: handle error */ |
return -1; |
} |
} |
if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonehash) != 0) { |
236,6 → 282,7 |
return -1; |
}; |
ipc_call_sync_3(fb_info.phone, FB_PUTCHAR, 'M', 3, 3,NULL,NULL, NULL); |
async_manager(); |
return 0; |
/uspace/trunk/console/screenbuffer.c |
---|
0,0 → 1,118 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <screenbuffer.h> |
#include <malloc.h> |
#include <unistd.h> |
/** Get field from buffer that corresponds to character at position x,y at screen |
* |
*/ |
int screenbuffer_putchar(screenbuffer_t *scr, char c) |
{ |
keyfield_t *field; |
field = get_field_at(scr, scr->position_x, scr->position_y); |
field->character = c; |
field->style = scr->style; |
scr->position_x++; |
if (scr->position_x == scr->size_x) { |
scr->position_x = 0; |
scr->position_y++; |
if (scr->position_y == scr->size_y) { |
/* scroll */ |
scr->position_y--; |
screenbuffer_clear_line(scr, scr->top_line++); |
} |
} |
return 1; |
} |
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y) |
{ |
if ((scr->buffer = (keyfield_t *)malloc(sizeof(keyfield_t) * size_x * size_y)) == NULL) { |
return NULL; |
} |
scr->size_x = size_x; |
scr->size_y = size_y; |
scr->position_y = 0; |
scr->position_x = 0; |
scr->style.fg_color = DEFAULT_FOREGROUND_COLOR; |
scr->style.bg_color = DEFAULT_BACKGROUND_COLOR; |
scr->top_line = 0; |
return scr; |
} |
void screenbuffer_clear(screenbuffer_t *scr) |
{ |
unsigned int i; |
for (i = 0; i < scr->size_x * scr->size_y; i++) { |
scr->buffer[i].character = ' '; |
scr->buffer[i].style = scr->style; |
} |
scr->top_line = 0; |
scr->position_y = 0; |
scr->position_x = 0; |
} |
/** Clear one buffer line |
* @param scr |
* @param line One buffer line (not a screen line!) |
*/ |
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line) |
{ |
unsigned int i; |
for (i = 0; i < scr->size_x; i++) { |
scr->buffer[i + line*scr->size_x].character = ' '; |
scr->buffer[i + line*scr->size_x].style = scr->style; |
} |
} |
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest) |
{ |
unsigned int i; |
for (i = 0; i < scr->size_x * scr->size_y; i++) { |
dest[i] = scr->buffer[i]; |
} |
} |
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y) |
{ |
scr->position_x = x % scr->size_x; |
scr->position_y = (y + scr->top_line) % scr->size_y; |
} |
/uspace/trunk/console/Makefile |
---|
43,6 → 43,7 |
OUTPUT = console |
GENERIC_SOURCES = \ |
console.c \ |
screenbuffer.c \ |
../kbd/generic/key_buffer.c |
ARCH_SOURCES = |