[df688cd] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[df688cd] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
[ce5bcb4] | 28 |
|
---|
| 29 | /** @defgroup egafb EGA framebuffer
|
---|
[9f1362d4] | 30 | * @brief HelenOS EGA framebuffer.
|
---|
[ce5bcb4] | 31 | * @ingroup fbs
|
---|
| 32 | * @{
|
---|
[9f1362d4] | 33 | */
|
---|
[ce5bcb4] | 34 | /** @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[1160f8d] | 37 | #include <stdlib.h>
|
---|
| 38 | #include <unistd.h>
|
---|
[df688cd] | 39 | #include <align.h>
|
---|
| 40 | #include <async.h>
|
---|
| 41 | #include <errno.h>
|
---|
| 42 | #include <stdio.h>
|
---|
| 43 | #include <ddi.h>
|
---|
| 44 | #include <sysinfo.h>
|
---|
| 45 | #include <as.h>
|
---|
| 46 | #include <ipc/fb.h>
|
---|
| 47 | #include <ipc/ns.h>
|
---|
| 48 | #include <ipc/services.h>
|
---|
[15039b67] | 49 | #include <libarch/ddi.h>
|
---|
[8dc12ac] | 50 | #include <io/style.h>
|
---|
| 51 | #include <io/color.h>
|
---|
[369a5f8] | 52 | #include <io/screenbuffer.h>
|
---|
[9cd98796] | 53 | #include <sys/types.h>
|
---|
[df688cd] | 54 |
|
---|
| 55 | #include "ega.h"
|
---|
[0bf84cc] | 56 | #include "main.h"
|
---|
[df688cd] | 57 |
|
---|
[9f1362d4] | 58 | #define MAX_SAVED_SCREENS 256
|
---|
| 59 |
|
---|
[1160f8d] | 60 | typedef struct saved_screen {
|
---|
| 61 | short *data;
|
---|
| 62 | } saved_screen;
|
---|
| 63 |
|
---|
| 64 | saved_screen saved_screens[MAX_SAVED_SCREENS];
|
---|
| 65 |
|
---|
[9f1362d4] | 66 | #define EGA_IO_BASE ((ioport8_t *) 0x3d4)
|
---|
| 67 | #define EGA_IO_SIZE 2
|
---|
[d3f2cad] | 68 |
|
---|
[df688cd] | 69 | /* Allow only 1 connection */
|
---|
| 70 | static int client_connected = 0;
|
---|
| 71 |
|
---|
[9f1362d4] | 72 | static sysarg_t scr_width;
|
---|
| 73 | static sysarg_t scr_height;
|
---|
[dc033a1] | 74 | static uint8_t *scr_addr;
|
---|
[df688cd] | 75 |
|
---|
[9f1362d4] | 76 | static uint8_t style_normal = 0xf0;
|
---|
| 77 | static uint8_t style_inverted = 0x0f;
|
---|
| 78 | static uint8_t style;
|
---|
| 79 |
|
---|
| 80 | static uint8_t style_to_ega_style(uint8_t style)
|
---|
| 81 | {
|
---|
| 82 | switch (style) {
|
---|
| 83 | case STYLE_EMPHASIS:
|
---|
| 84 | return (style_normal | 0x04);
|
---|
| 85 | case STYLE_SELECTED:
|
---|
| 86 | return (style_inverted | 0x40);
|
---|
| 87 | case STYLE_INVERTED:
|
---|
| 88 | return style_inverted;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | return style_normal;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | static uint8_t color_to_ega_style(uint8_t fg_color, uint8_t bg_color,
|
---|
| 95 | uint8_t attr)
|
---|
| 96 | {
|
---|
| 97 | uint8_t style = (fg_color & 7) | ((bg_color & 7) << 4);
|
---|
| 98 |
|
---|
| 99 | if (attr & CATTR_BRIGHT)
|
---|
| 100 | style |= 0x08;
|
---|
| 101 |
|
---|
| 102 | return style;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | static uint8_t rgb_to_ega_style(uint32_t fg, uint32_t bg)
|
---|
| 106 | {
|
---|
| 107 | return (fg > bg) ? style_inverted : style_normal;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | static uint8_t attr_to_ega_style(const attrs_t *attr)
|
---|
| 111 | {
|
---|
| 112 | switch (attr->t) {
|
---|
| 113 | case at_style:
|
---|
| 114 | return style_to_ega_style(attr->a.s.style);
|
---|
| 115 | case at_idx:
|
---|
| 116 | return color_to_ega_style(attr->a.i.fg_color,
|
---|
| 117 | attr->a.i.bg_color, attr->a.i.flags);
|
---|
| 118 | case at_rgb:
|
---|
| 119 | return rgb_to_ega_style(attr->a.r.fg_color, attr->a.r.bg_color);
|
---|
| 120 | default:
|
---|
| 121 | return style_normal;
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
[0bf84cc] | 124 |
|
---|
[9f1362d4] | 125 | static uint8_t ega_glyph(wchar_t ch)
|
---|
| 126 | {
|
---|
| 127 | if (ch >= 0 && ch < 128)
|
---|
| 128 | return ch;
|
---|
| 129 |
|
---|
| 130 | return '?';
|
---|
| 131 | }
|
---|
[198a9ef] | 132 |
|
---|
[df688cd] | 133 | static void clrscr(void)
|
---|
| 134 | {
|
---|
[0471786] | 135 | unsigned i;
|
---|
[df688cd] | 136 |
|
---|
[b74959bd] | 137 | for (i = 0; i < scr_width * scr_height; i++) {
|
---|
[00bb6965] | 138 | scr_addr[i * 2] = ' ';
|
---|
| 139 | scr_addr[i * 2 + 1] = style;
|
---|
[0bf84cc] | 140 | }
|
---|
[df688cd] | 141 | }
|
---|
| 142 |
|
---|
[9f1362d4] | 143 | static void cursor_goto(sysarg_t col, sysarg_t row)
|
---|
[dc5a0fe1] | 144 | {
|
---|
[9f1362d4] | 145 | sysarg_t cursor = col + scr_width * row;
|
---|
[dc5a0fe1] | 146 |
|
---|
[9cd98796] | 147 | pio_write_8(EGA_IO_BASE, 0xe);
|
---|
[9f1362d4] | 148 | pio_write_8(EGA_IO_BASE + 1, (cursor >> 8) & 0xff);
|
---|
[9cd98796] | 149 | pio_write_8(EGA_IO_BASE, 0xf);
|
---|
[9f1362d4] | 150 | pio_write_8(EGA_IO_BASE + 1, cursor & 0xff);
|
---|
[dc5a0fe1] | 151 | }
|
---|
| 152 |
|
---|
[1160f8d] | 153 | static void cursor_disable(void)
|
---|
[dc5a0fe1] | 154 | {
|
---|
[9cd98796] | 155 | pio_write_8(EGA_IO_BASE, 0xa);
|
---|
[9f1362d4] | 156 |
|
---|
| 157 | uint8_t stat = pio_read_8(EGA_IO_BASE + 1);
|
---|
| 158 |
|
---|
[9cd98796] | 159 | pio_write_8(EGA_IO_BASE, 0xa);
|
---|
| 160 | pio_write_8(EGA_IO_BASE + 1, stat | (1 << 5));
|
---|
[dc5a0fe1] | 161 | }
|
---|
| 162 |
|
---|
[1160f8d] | 163 | static void cursor_enable(void)
|
---|
[dc5a0fe1] | 164 | {
|
---|
[9cd98796] | 165 | pio_write_8(EGA_IO_BASE, 0xa);
|
---|
[9f1362d4] | 166 |
|
---|
| 167 | uint8_t stat = pio_read_8(EGA_IO_BASE + 1);
|
---|
| 168 |
|
---|
[9cd98796] | 169 | pio_write_8(EGA_IO_BASE, 0xa);
|
---|
| 170 | pio_write_8(EGA_IO_BASE + 1, stat & (~(1 << 5)));
|
---|
[dc5a0fe1] | 171 | }
|
---|
| 172 |
|
---|
[9f1362d4] | 173 | static void scroll(ssize_t rows)
|
---|
[1160f8d] | 174 | {
|
---|
[9f1362d4] | 175 | size_t i;
|
---|
| 176 |
|
---|
[1160f8d] | 177 | if (rows > 0) {
|
---|
[8b74af07] | 178 | memmove(scr_addr, ((char *) scr_addr) + rows * scr_width * 2,
|
---|
[b74959bd] | 179 | scr_width * scr_height * 2 - rows * scr_width * 2);
|
---|
[00bb6965] | 180 | for (i = 0; i < rows * scr_width; i++)
|
---|
| 181 | (((short *) scr_addr) + scr_width * scr_height - rows *
|
---|
[b74959bd] | 182 | scr_width)[i] = ((style << 8) + ' ');
|
---|
[1160f8d] | 183 | } else if (rows < 0) {
|
---|
[8b74af07] | 184 | memmove(((char *)scr_addr) - rows * scr_width * 2, scr_addr,
|
---|
[b74959bd] | 185 | scr_width * scr_height * 2 + rows * scr_width * 2);
|
---|
[00bb6965] | 186 | for (i = 0; i < -rows * scr_width; i++)
|
---|
[9f1362d4] | 187 | ((short *) scr_addr)[i] = ((style << 8 ) + ' ');
|
---|
[1160f8d] | 188 | }
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[9f1362d4] | 191 | static void printchar(wchar_t c, sysarg_t col, sysarg_t row)
|
---|
[df688cd] | 192 | {
|
---|
[b27eb71] | 193 | scr_addr[(row * scr_width + col) * 2] = ega_glyph(c);
|
---|
[00bb6965] | 194 | scr_addr[(row * scr_width + col) * 2 + 1] = style;
|
---|
[dc5a0fe1] | 195 |
|
---|
[ba2a055] | 196 | cursor_goto(col + 1, row);
|
---|
[0bf84cc] | 197 | }
|
---|
| 198 |
|
---|
[dc033a1] | 199 | /** Draw text data to viewport.
|
---|
| 200 | *
|
---|
| 201 | * @param vport Viewport id
|
---|
| 202 | * @param data Text data.
|
---|
[9f1362d4] | 203 | * @param x Leftmost column of the area.
|
---|
| 204 | * @param y Topmost row of the area.
|
---|
| 205 | * @param w Number of rows.
|
---|
| 206 | * @param h Number of columns.
|
---|
| 207 | *
|
---|
[dc033a1] | 208 | */
|
---|
[9f1362d4] | 209 | static void draw_text_data(keyfield_t *data, sysarg_t x, sysarg_t y,
|
---|
| 210 | sysarg_t w, sysarg_t h)
|
---|
[0bf84cc] | 211 | {
|
---|
[9f1362d4] | 212 | sysarg_t i;
|
---|
| 213 | sysarg_t j;
|
---|
[dc033a1] | 214 | keyfield_t *field;
|
---|
| 215 | uint8_t *dp;
|
---|
[9f1362d4] | 216 |
|
---|
[dc033a1] | 217 | for (j = 0; j < h; j++) {
|
---|
| 218 | for (i = 0; i < w; i++) {
|
---|
| 219 | field = &data[j * w + i];
|
---|
| 220 | dp = &scr_addr[2 * ((y + j) * scr_width + (x + i))];
|
---|
[9f1362d4] | 221 |
|
---|
[b27eb71] | 222 | dp[0] = ega_glyph(field->character);
|
---|
[dc033a1] | 223 | dp[1] = attr_to_ega_style(&field->attrs);
|
---|
| 224 | }
|
---|
[0bf84cc] | 225 | }
|
---|
[df688cd] | 226 | }
|
---|
| 227 |
|
---|
[1160f8d] | 228 | static int save_screen(void)
|
---|
| 229 | {
|
---|
[96b02eb9] | 230 | sysarg_t i;
|
---|
[9f1362d4] | 231 |
|
---|
| 232 | /* Find empty screen */
|
---|
| 233 | for (i = 0; (i < MAX_SAVED_SCREENS) && (saved_screens[i].data); i++);
|
---|
| 234 |
|
---|
| 235 | if (i == MAX_SAVED_SCREENS)
|
---|
[759c376] | 236 | return EINVAL;
|
---|
[9f1362d4] | 237 |
|
---|
| 238 | if (!(saved_screens[i].data = malloc(2 * scr_width * scr_height)))
|
---|
[759c376] | 239 | return ENOMEM;
|
---|
[9f1362d4] | 240 |
|
---|
[153a209] | 241 | memcpy(saved_screens[i].data, scr_addr, 2 * scr_width * scr_height);
|
---|
[9f1362d4] | 242 | return (int) i;
|
---|
[1160f8d] | 243 | }
|
---|
| 244 |
|
---|
[96b02eb9] | 245 | static int print_screen(sysarg_t i)
|
---|
[1160f8d] | 246 | {
|
---|
[9f1362d4] | 247 | if ((i >= MAX_SAVED_SCREENS) || (saved_screens[i].data))
|
---|
[00bb6965] | 248 | memcpy(scr_addr, saved_screens[i].data, 2 * scr_width *
|
---|
[b74959bd] | 249 | scr_height);
|
---|
[00bb6965] | 250 | else
|
---|
| 251 | return EINVAL;
|
---|
[9f1362d4] | 252 |
|
---|
| 253 | return (int) i;
|
---|
[b27eb71] | 254 | }
|
---|
| 255 |
|
---|
[df688cd] | 256 | static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 257 | {
|
---|
[0bf84cc] | 258 | size_t intersize = 0;
|
---|
[9f1362d4] | 259 | keyfield_t *interbuf = NULL;
|
---|
[369a5f8] | 260 |
|
---|
[df688cd] | 261 | if (client_connected) {
|
---|
[ffa2c8ef] | 262 | async_answer_0(iid, ELIMIT);
|
---|
[df688cd] | 263 | return;
|
---|
| 264 | }
|
---|
[9f1362d4] | 265 |
|
---|
| 266 | /* Accept connection */
|
---|
[df688cd] | 267 | client_connected = 1;
|
---|
[ffa2c8ef] | 268 | async_answer_0(iid, EOK);
|
---|
[9f1362d4] | 269 |
|
---|
| 270 | while (true) {
|
---|
| 271 | ipc_call_t call;
|
---|
| 272 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 273 |
|
---|
| 274 | wchar_t c;
|
---|
| 275 |
|
---|
[96b02eb9] | 276 | sysarg_t col;
|
---|
| 277 | sysarg_t row;
|
---|
| 278 | sysarg_t w;
|
---|
| 279 | sysarg_t h;
|
---|
[9f1362d4] | 280 |
|
---|
| 281 | ssize_t rows;
|
---|
| 282 |
|
---|
| 283 | uint8_t bg_color;
|
---|
| 284 | uint8_t fg_color;
|
---|
| 285 | uint8_t attr;
|
---|
| 286 |
|
---|
| 287 | uint32_t fg_rgb;
|
---|
| 288 | uint32_t bg_rgb;
|
---|
| 289 |
|
---|
[96b02eb9] | 290 | sysarg_t scr;
|
---|
[9f1362d4] | 291 | int retval;
|
---|
| 292 |
|
---|
[228e490] | 293 | switch (IPC_GET_IMETHOD(call)) {
|
---|
[df688cd] | 294 | case IPC_M_PHONE_HUNGUP:
|
---|
| 295 | client_connected = 0;
|
---|
[ffa2c8ef] | 296 | async_answer_0(callid, EOK);
|
---|
[9f1362d4] | 297 |
|
---|
| 298 | /* Exit thread */
|
---|
| 299 | return;
|
---|
[27d293a] | 300 | case IPC_M_SHARE_OUT:
|
---|
[0bf84cc] | 301 | /* We accept one area for data interchange */
|
---|
| 302 | intersize = IPC_GET_ARG2(call);
|
---|
[00bb6965] | 303 | if (intersize >= scr_width * scr_height *
|
---|
[b74959bd] | 304 | sizeof(*interbuf)) {
|
---|
| 305 | receive_comm_area(callid, &call,
|
---|
| 306 | (void *) &interbuf);
|
---|
[0bf84cc] | 307 | continue;
|
---|
| 308 | }
|
---|
[9f1362d4] | 309 |
|
---|
[0bf84cc] | 310 | retval = EINVAL;
|
---|
| 311 | break;
|
---|
| 312 | case FB_DRAW_TEXT_DATA:
|
---|
| 313 | if (!interbuf) {
|
---|
| 314 | retval = EINVAL;
|
---|
| 315 | break;
|
---|
| 316 | }
|
---|
[9f1362d4] | 317 |
|
---|
| 318 | col = IPC_GET_ARG1(call);
|
---|
| 319 | row = IPC_GET_ARG2(call);
|
---|
| 320 | w = IPC_GET_ARG3(call);
|
---|
| 321 | h = IPC_GET_ARG4(call);
|
---|
| 322 |
|
---|
| 323 | if ((col + w > scr_width) || (row + h > scr_height)) {
|
---|
[dc033a1] | 324 | retval = EINVAL;
|
---|
| 325 | break;
|
---|
| 326 | }
|
---|
[9f1362d4] | 327 |
|
---|
[dc033a1] | 328 | draw_text_data(interbuf, col, row, w, h);
|
---|
[0bf84cc] | 329 | retval = 0;
|
---|
| 330 | break;
|
---|
[df688cd] | 331 | case FB_GET_CSIZE:
|
---|
[ffa2c8ef] | 332 | async_answer_2(callid, EOK, scr_width, scr_height);
|
---|
[df688cd] | 333 | continue;
|
---|
[50cfa6c] | 334 | case FB_GET_COLOR_CAP:
|
---|
[ffa2c8ef] | 335 | async_answer_1(callid, EOK, FB_CCAP_INDEXED);
|
---|
[50cfa6c] | 336 | continue;
|
---|
[df688cd] | 337 | case FB_CLEAR:
|
---|
| 338 | clrscr();
|
---|
| 339 | retval = 0;
|
---|
| 340 | break;
|
---|
| 341 | case FB_PUTCHAR:
|
---|
| 342 | c = IPC_GET_ARG1(call);
|
---|
[8dc12ac] | 343 | col = IPC_GET_ARG2(call);
|
---|
| 344 | row = IPC_GET_ARG3(call);
|
---|
[9f1362d4] | 345 |
|
---|
| 346 | if ((col >= scr_width) || (row >= scr_height)) {
|
---|
[df688cd] | 347 | retval = EINVAL;
|
---|
| 348 | break;
|
---|
| 349 | }
|
---|
[9f1362d4] | 350 |
|
---|
[8dc12ac] | 351 | printchar(c, col, row);
|
---|
[df688cd] | 352 | retval = 0;
|
---|
| 353 | break;
|
---|
[9f1362d4] | 354 | case FB_CURSOR_GOTO:
|
---|
| 355 | col = IPC_GET_ARG1(call);
|
---|
[8dc12ac] | 356 | row = IPC_GET_ARG2(call);
|
---|
[9f1362d4] | 357 |
|
---|
| 358 | if ((row >= scr_height) || (col >= scr_width)) {
|
---|
[dc5a0fe1] | 359 | retval = EINVAL;
|
---|
| 360 | break;
|
---|
| 361 | }
|
---|
[9f1362d4] | 362 |
|
---|
[8dc12ac] | 363 | cursor_goto(col, row);
|
---|
[9f1362d4] | 364 | retval = 0;
|
---|
| 365 | break;
|
---|
[1160f8d] | 366 | case FB_SCROLL:
|
---|
[9f1362d4] | 367 | rows = IPC_GET_ARG1(call);
|
---|
| 368 |
|
---|
| 369 | if (rows >= 0) {
|
---|
[96b02eb9] | 370 | if ((sysarg_t) rows > scr_height) {
|
---|
[9f1362d4] | 371 | retval = EINVAL;
|
---|
| 372 | break;
|
---|
| 373 | }
|
---|
| 374 | } else {
|
---|
[96b02eb9] | 375 | if ((sysarg_t) (-rows) > scr_height) {
|
---|
[9f1362d4] | 376 | retval = EINVAL;
|
---|
| 377 | break;
|
---|
| 378 | }
|
---|
[1160f8d] | 379 | }
|
---|
[9f1362d4] | 380 |
|
---|
| 381 | scroll(rows);
|
---|
[1160f8d] | 382 | retval = 0;
|
---|
| 383 | break;
|
---|
[dc5a0fe1] | 384 | case FB_CURSOR_VISIBILITY:
|
---|
[13ec8055] | 385 | if (IPC_GET_ARG1(call))
|
---|
[dc5a0fe1] | 386 | cursor_enable();
|
---|
| 387 | else
|
---|
| 388 | cursor_disable();
|
---|
[9f1362d4] | 389 |
|
---|
[dc5a0fe1] | 390 | retval = 0;
|
---|
| 391 | break;
|
---|
[0bf84cc] | 392 | case FB_SET_STYLE:
|
---|
[198a9ef] | 393 | style = style_to_ega_style(IPC_GET_ARG1(call));
|
---|
[9805cde] | 394 | retval = 0;
|
---|
| 395 | break;
|
---|
| 396 | case FB_SET_COLOR:
|
---|
[198a9ef] | 397 | fg_color = IPC_GET_ARG1(call);
|
---|
| 398 | bg_color = IPC_GET_ARG2(call);
|
---|
| 399 | attr = IPC_GET_ARG3(call);
|
---|
[9f1362d4] | 400 |
|
---|
[198a9ef] | 401 | style = color_to_ega_style(fg_color, bg_color, attr);
|
---|
[9805cde] | 402 | retval = 0;
|
---|
| 403 | break;
|
---|
| 404 | case FB_SET_RGB_COLOR:
|
---|
[198a9ef] | 405 | fg_rgb = IPC_GET_ARG1(call);
|
---|
| 406 | bg_rgb = IPC_GET_ARG2(call);
|
---|
[9f1362d4] | 407 |
|
---|
[198a9ef] | 408 | style = rgb_to_ega_style(fg_rgb, bg_rgb);
|
---|
[153a209] | 409 | retval = 0;
|
---|
[ec9623d] | 410 | break;
|
---|
[1160f8d] | 411 | case FB_VP_DRAW_PIXMAP:
|
---|
[9f1362d4] | 412 | scr = IPC_GET_ARG2(call);
|
---|
| 413 | retval = print_screen(scr);
|
---|
[1160f8d] | 414 | break;
|
---|
| 415 | case FB_VP2PIXMAP:
|
---|
| 416 | retval = save_screen();
|
---|
| 417 | break;
|
---|
| 418 | case FB_DROP_PIXMAP:
|
---|
[9f1362d4] | 419 | scr = IPC_GET_ARG1(call);
|
---|
| 420 |
|
---|
| 421 | if (scr >= MAX_SAVED_SCREENS) {
|
---|
[1160f8d] | 422 | retval = EINVAL;
|
---|
| 423 | break;
|
---|
| 424 | }
|
---|
[9f1362d4] | 425 |
|
---|
| 426 | if (saved_screens[scr].data) {
|
---|
| 427 | free(saved_screens[scr].data);
|
---|
| 428 | saved_screens[scr].data = NULL;
|
---|
[1160f8d] | 429 | }
|
---|
[9f1362d4] | 430 |
|
---|
[153a209] | 431 | retval = 0;
|
---|
[1160f8d] | 432 | break;
|
---|
[ebfabf6] | 433 | case FB_SCREEN_YIELD:
|
---|
| 434 | case FB_SCREEN_RECLAIM:
|
---|
[10270a8] | 435 | retval = EOK;
|
---|
| 436 | break;
|
---|
[df688cd] | 437 | default:
|
---|
[d2cc7e1] | 438 | retval = EINVAL;
|
---|
[df688cd] | 439 | }
|
---|
[ffa2c8ef] | 440 | async_answer_0(callid, retval);
|
---|
[df688cd] | 441 | }
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | int ega_init(void)
|
---|
| 445 | {
|
---|
[d9fae235] | 446 | sysarg_t paddr;
|
---|
| 447 | if (sysinfo_get_value("fb.address.physical", &paddr) != EOK)
|
---|
| 448 | return -1;
|
---|
| 449 |
|
---|
[9f1362d4] | 450 | if (sysinfo_get_value("fb.width", &scr_width) != EOK)
|
---|
[d9fae235] | 451 | return -1;
|
---|
| 452 |
|
---|
[9f1362d4] | 453 | if (sysinfo_get_value("fb.height", &scr_height) != EOK)
|
---|
[d9fae235] | 454 | return -1;
|
---|
| 455 |
|
---|
| 456 | sysarg_t blinking;
|
---|
| 457 | if (sysinfo_get_value("fb.blinking", &blinking) != EOK)
|
---|
| 458 | blinking = false;
|
---|
| 459 |
|
---|
[9f1362d4] | 460 | void *ega_ph_addr = (void *) paddr;
|
---|
[d9fae235] | 461 | if (blinking) {
|
---|
[9f1362d4] | 462 | style_normal &= 0x77;
|
---|
| 463 | style_inverted &= 0x77;
|
---|
[323a5aaf] | 464 | }
|
---|
[d9fae235] | 465 |
|
---|
[9f1362d4] | 466 | style = style_normal;
|
---|
[d9fae235] | 467 |
|
---|
[9cd98796] | 468 | iospace_enable(task_get_id(), (void *) EGA_IO_BASE, 2);
|
---|
[d9fae235] | 469 |
|
---|
[9f1362d4] | 470 | size_t sz = scr_width * scr_height * 2;
|
---|
[2057572] | 471 | scr_addr = as_get_mappable_page(sz);
|
---|
[d9fae235] | 472 |
|
---|
[ae318d3] | 473 | if (physmem_map(ega_ph_addr, scr_addr, ALIGN_UP(sz, PAGE_SIZE) >>
|
---|
| 474 | PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
|
---|
| 475 | return -1;
|
---|
[9f1362d4] | 476 |
|
---|
[df688cd] | 477 | async_set_client_connection(ega_client_connection);
|
---|
[9f1362d4] | 478 |
|
---|
[df688cd] | 479 | return 0;
|
---|
| 480 | }
|
---|
[dc5a0fe1] | 481 |
|
---|
[13ec8055] | 482 | /**
|
---|
[ce5bcb4] | 483 | * @}
|
---|
| 484 | */
|
---|