Subversion Repositories HelenOS

Rev

Rev 4348 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4348 Rev 4691
Line 47... Line 47...
47
#include <ipc/fb.h>
47
#include <ipc/fb.h>
48
#include <ipc/ipc.h>
48
#include <ipc/ipc.h>
49
#include <ipc/ns.h>
49
#include <ipc/ns.h>
50
#include <ipc/services.h>
50
#include <ipc/services.h>
51
#include <libarch/ddi.h>
51
#include <libarch/ddi.h>
52
#include <console/style.h>
52
#include <io/style.h>
53
#include <console/color.h>
53
#include <io/color.h>
54
#include <sys/types.h>
54
#include <sys/types.h>
55
 
55
 
56
#include "ega.h"
56
#include "ega.h"
57
#include "../console/screenbuffer.h"
57
#include "../console/screenbuffer.h"
58
#include "main.h"
58
#include "main.h"
Line 68... Line 68...
68
#define EGA_IO_SIZE 2
68
#define EGA_IO_SIZE 2
69
 
69
 
70
int ega_normal_color = 0x0f;
70
int ega_normal_color = 0x0f;
71
int ega_inverted_color = 0xf0;
71
int ega_inverted_color = 0xf0;
72
 
72
 
73
#define NORMAL_COLOR        ega_normal_color       
73
#define NORMAL_COLOR        ega_normal_color
74
#define INVERTED_COLOR      ega_inverted_color
74
#define INVERTED_COLOR      ega_inverted_color
75
 
75
 
76
/* Allow only 1 connection */
76
/* Allow only 1 connection */
77
static int client_connected = 0;
77
static int client_connected = 0;
78
 
78
 
Line 85... Line 85...
85
static unsigned attr_to_ega_style(const attrs_t *a);
85
static unsigned attr_to_ega_style(const attrs_t *a);
86
static uint8_t ega_glyph(wchar_t ch);
86
static uint8_t ega_glyph(wchar_t ch);
87
 
87
 
88
static void clrscr(void)
88
static void clrscr(void)
89
{
89
{
90
    int i;
90
    unsigned i;
91
   
91
   
92
    for (i = 0; i < scr_width * scr_height; i++) {
92
    for (i = 0; i < scr_width * scr_height; i++) {
93
        scr_addr[i * 2] = ' ';
93
        scr_addr[i * 2] = ' ';
94
        scr_addr[i * 2 + 1] = style;
94
        scr_addr[i * 2 + 1] = style;
95
    }
95
    }
96
}
96
}
97
 
97
 
98
static void cursor_goto(unsigned int row, unsigned int col)
98
static void cursor_goto(unsigned int col, unsigned int row)
99
{
99
{
100
    int ega_cursor;
100
    int ega_cursor;
101
 
101
 
102
    ega_cursor = col + scr_width * row;
102
    ega_cursor = col + scr_width * row;
103
   
103
   
Line 127... Line 127...
127
    pio_write_8(EGA_IO_BASE + 1, stat & (~(1 << 5)));
127
    pio_write_8(EGA_IO_BASE + 1, stat & (~(1 << 5)));
128
}
128
}
129
 
129
 
130
static void scroll(int rows)
130
static void scroll(int rows)
131
{
131
{
132
    int i;
132
    unsigned i;
-
 
133
 
133
    if (rows > 0) {
134
    if (rows > 0) {
134
        memmove(scr_addr, ((char *) scr_addr) + rows * scr_width * 2,
135
        memmove(scr_addr, ((char *) scr_addr) + rows * scr_width * 2,
135
            scr_width * scr_height * 2 - rows * scr_width * 2);
136
            scr_width * scr_height * 2 - rows * scr_width * 2);
136
        for (i = 0; i < rows * scr_width; i++)
137
        for (i = 0; i < rows * scr_width; i++)
137
            (((short *) scr_addr) + scr_width * scr_height - rows *
138
            (((short *) scr_addr) + scr_width * scr_height - rows *
Line 142... Line 143...
142
        for (i = 0; i < -rows * scr_width; i++)
143
        for (i = 0; i < -rows * scr_width; i++)
143
            ((short *)scr_addr)[i] = ((style << 8 ) + ' ');
144
            ((short *)scr_addr)[i] = ((style << 8 ) + ' ');
144
    }
145
    }
145
}
146
}
146
 
147
 
147
static void printchar(wchar_t c, unsigned int row, unsigned int col)
148
static void printchar(wchar_t c, unsigned int col, unsigned int row)
148
{
149
{
149
    scr_addr[(row * scr_width + col) * 2] = ega_glyph(c);
150
    scr_addr[(row * scr_width + col) * 2] = ega_glyph(c);
150
    scr_addr[(row * scr_width + col) * 2 + 1] = style;
151
    scr_addr[(row * scr_width + col) * 2 + 1] = style;
151
   
152
   
152
    cursor_goto(row, col + 1);
153
    cursor_goto(col + 1, row);
153
}
154
}
154
 
155
 
155
/** Draw text data to viewport.
156
/** Draw text data to viewport.
156
 *
157
 *
157
 * @param vport Viewport id
158
 * @param vport Viewport id
Line 239... Line 240...
239
}
240
}
240
 
241
 
241
static unsigned attr_to_ega_style(const attrs_t *a)
242
static unsigned attr_to_ega_style(const attrs_t *a)
242
{
243
{
243
    switch (a->t) {
244
    switch (a->t) {
-
 
245
    case at_style:
244
    case at_style: return style_to_ega_style(a->a.s.style);
246
        return style_to_ega_style(a->a.s.style);
-
 
247
    case at_rgb:
245
    case at_rgb: return rgb_to_ega_style(a->a.r.fg_color, a->a.r.bg_color);
248
        return rgb_to_ega_style(a->a.r.fg_color, a->a.r.bg_color);
-
 
249
    case at_idx:
246
    case at_idx: return color_to_ega_style(a->a.i.fg_color,
250
        return color_to_ega_style(a->a.i.fg_color,
247
        a->a.i.bg_color, a->a.i.flags);
251
            a->a.i.bg_color, a->a.i.flags);
-
 
252
    default:
248
    default: return INVERTED_COLOR;
253
        return INVERTED_COLOR;
249
    }
254
    }
250
}
255
}
251
 
256
 
252
static uint8_t ega_glyph(wchar_t ch)
257
static uint8_t ega_glyph(wchar_t ch)
253
{
258
{
Line 310... Line 315...
310
            }
315
            }
311
            draw_text_data(interbuf, col, row, w, h);
316
            draw_text_data(interbuf, col, row, w, h);
312
            retval = 0;
317
            retval = 0;
313
            break;
318
            break;
314
        case FB_GET_CSIZE:
319
        case FB_GET_CSIZE:
315
            ipc_answer_2(callid, EOK, scr_height, scr_width);
320
            ipc_answer_2(callid, EOK, scr_width, scr_height);
-
 
321
            continue;
-
 
322
        case FB_GET_COLOR_CAP:
-
 
323
            ipc_answer_1(callid, EOK, FB_CCAP_INDEXED);
316
            continue;
324
            continue;
317
        case FB_CLEAR:
325
        case FB_CLEAR:
318
            clrscr();
326
            clrscr();
319
            retval = 0;
327
            retval = 0;
320
            break;
328
            break;
321
        case FB_PUTCHAR:
329
        case FB_PUTCHAR:
322
            c = IPC_GET_ARG1(call);
330
            c = IPC_GET_ARG1(call);
323
            row = IPC_GET_ARG2(call);
331
            col = IPC_GET_ARG2(call);
324
            col = IPC_GET_ARG3(call);
332
            row = IPC_GET_ARG3(call);
325
            if (col >= scr_width || row >= scr_height) {
333
            if (col >= scr_width || row >= scr_height) {
326
                retval = EINVAL;
334
                retval = EINVAL;
327
                break;
335
                break;
328
            }
336
            }
329
            printchar(c, row, col);
337
            printchar(c, col, row);
330
            retval = 0;
338
            retval = 0;
331
            break;
339
            break;
332
        case FB_CURSOR_GOTO:
340
        case FB_CURSOR_GOTO:
333
            row = IPC_GET_ARG1(call);
341
            col = IPC_GET_ARG1(call);
334
            col = IPC_GET_ARG2(call);
342
            row = IPC_GET_ARG2(call);
335
            if (row >= scr_height || col >= scr_width) {
343
            if (row >= scr_height || col >= scr_width) {
336
                retval = EINVAL;
344
                retval = EINVAL;
337
                break;
345
                break;
338
            }
346
            }
339
            cursor_goto(row, col);
347
            cursor_goto(col, row);
340
            retval = 0;
348
            retval = 0;
341
            break;
349
            break;
342
        case FB_SCROLL:
350
        case FB_SCROLL:
343
            i = IPC_GET_ARG1(call);
351
            i = IPC_GET_ARG1(call);
344
            if (i > scr_height || i < -((int) scr_height)) {
352
            if (i > (int) scr_height || i < -((int) scr_height)) {
345
                retval = EINVAL;
353
                retval = EINVAL;
346
                break;
354
                break;
347
            }
355
            }
348
            scroll(i);
356
            scroll(i);
349
            retval = 0;
357
            retval = 0;