Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3581 → Rev 3582

/branches/sparc/uspace/srv/fb/sgcn.c
44,13 → 44,12
#include <stdio.h>
#include <ddi.h>
 
#include "serial_console.h"
#include "sgcn.h"
 
#define WIDTH 80
#define HEIGHT 24
 
#define MAX_CONTROL 20
 
/**
* Virtual address mapped to SRAM.
*/
73,19 → 72,7
char magic[4];
/** we don't need this */
char unused[8];
/** offset within the SGCN buffer of the input buffer start */
uint32_t in_begin;
/** offset within the SGCN buffer of the input buffer end */
uint32_t in_end;
/** offset within the SGCN buffer of the input buffer read pointer */
uint32_t in_rdptr;
/** offset within the SGCN buffer of the input buffer write pointer */
uint32_t in_wrptr;
char unused[24];
 
/** offset within the SGCN buffer of the output buffer start */
uint32_t out_begin;
100,8 → 87,6
uint32_t out_wrptr;
} __attribute__ ((packed)) sgcn_buffer_header_t;
 
// TODO it is suggested to extract the common parts of this file and the msim.c file
// into a separate file and place that file to the genarch directory
 
/*
* Returns a pointer to the object of a given type which is placed at the given
132,57 → 117,6
*out_wrptr_ptr = new_wrptr;
}
 
static void sgcn_puts(char *str)
{
while (*str)
sgcn_putc(*(str++));
}
 
static void sgcn_goto(const unsigned int row, const unsigned int col)
{
if ((row > HEIGHT) || (col > WIDTH))
return;
char control[20];
snprintf(control, 20, "\033[%u;%uf", row + 1, col + 1);
sgcn_puts(control);
}
 
static void sgcn_clrscr(void)
{
sgcn_puts("\033[2J");
}
 
static void sgcn_scroll(int i)
{
if (i > 0) {
sgcn_goto(HEIGHT - 1, 0);
while (i--)
sgcn_puts("\033D");
} else if (i < 0) {
sgcn_goto(0, 0);
while (i++)
sgcn_puts("\033M");
}
}
 
static void sgcn_set_style(const unsigned int mode)
{
char control[MAX_CONTROL];
snprintf(control, MAX_CONTROL, "\033[%um", mode);
sgcn_puts(control);
}
 
static void sgcn_cursor_disable(void)
{
sgcn_puts("\033[?25l");
}
 
static void sgcn_cursor_enable(void)
{
sgcn_puts("\033[?25h");
}
 
static void sgcn_client_connection(ipc_callid_t iid, ipc_call_t *icall)
{
int retval;
207,9 → 141,9
/* Clear the terminal, set scrolling region
to 0 - 24 lines */
sgcn_clrscr();
sgcn_goto(0, 0);
sgcn_puts("\033[0;24r");
serial_clrscr();
serial_goto(0, 0);
serial_puts("\033[0;24r");
while (true) {
callid = async_get_call(&call);
223,7 → 157,7
newrow = IPC_GET_ARG2(call);
newcol = IPC_GET_ARG3(call);
if ((lastcol != newcol) || (lastrow != newrow))
sgcn_goto(newrow, newcol);
serial_goto(newrow, newcol);
lastcol = newcol + 1;
lastrow = newrow;
sgcn_putc(c);
232,7 → 166,7
case FB_CURSOR_GOTO:
newrow = IPC_GET_ARG1(call);
newcol = IPC_GET_ARG2(call);
sgcn_goto(newrow, newcol);
serial_goto(newrow, newcol);
lastrow = newrow;
lastcol = newcol;
retval = 0;
241,7 → 175,7
ipc_answer_2(callid, EOK, HEIGHT, WIDTH);
continue;
case FB_CLEAR:
sgcn_clrscr();
serial_clrscr();
retval = 0;
break;
case FB_SET_STYLE:
248,9 → 182,9
fgcolor = IPC_GET_ARG1(call);
bgcolor = IPC_GET_ARG2(call);
if (fgcolor < bgcolor)
sgcn_set_style(0);
serial_set_style(0);
else
sgcn_set_style(7);
serial_set_style(7);
retval = 0;
break;
case FB_SCROLL:
259,15 → 193,15
retval = EINVAL;
break;
}
sgcn_scroll(i);
sgcn_goto(lastrow, lastcol);
serial_scroll(i);
serial_goto(lastrow, lastcol);
retval = 0;
break;
case FB_CURSOR_VISIBILITY:
if(IPC_GET_ARG1(call))
sgcn_cursor_enable();
serial_cursor_enable();
else
sgcn_cursor_disable();
serial_cursor_disable();
retval = 0;
break;
default:
291,6 → 225,8
result);
}
serial_console_init(sgcn_putc, WIDTH, HEIGHT);
sram_buffer_offset = sysinfo_value("sram.buffer.offset");
async_set_client_connection(sgcn_client_connection);