source: libcaca/trunk/caca/driver_vga.c @ 1048

Last change on this file since 1048 was 1048, checked in by Jean-Yves Lamoureux, 14 years ago
  • Updated kernel 'driver', still not working, but most of the work is done
  • Property svn:keywords set to Id
File size: 3.7 KB
RevLine 
[565]1/*
[672]2 *  libcaca       Colour ASCII-Art library
[565]3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
[769]6 *  $Id: driver_vga.c 1048 2006-09-17 12:44:18Z jylam $
7 *
[565]8 *  This library is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
[769]14/*
[565]15 *  This file contains the libcaca VGA input and output driver
16 */
17
18#include "config.h"
[859]19#include "common.h"
[565]20
21#if defined(USE_VGA)
22
23#include "caca.h"
24#include "caca_internals.h"
25#include "cucul.h"
26#include "cucul_internals.h"
27
28/* Address of the VGA screen */
29#define VGA_SCREEN ((char *)(intptr_t)0x000b8000)
30
31static uint8_t const vga_colors[][4] =
32{
[574]33    /* Colour values range from 0x00 to 0x3f */
34    { 0,      0x00, 0x00, 0x00 },
35    { 1,      0x00, 0x00, 0x1f },
36    { 2,      0x00, 0x1f, 0x00 },
37    { 3,      0x00, 0x1f, 0x1f },
38    { 4,      0x1f, 0x00, 0x00 },
39    { 5,      0x1f, 0x00, 0x1f },
40    { 0x14,   0x1f, 0x1f, 0x00 },
41    { 7,      0x1f, 0x1f, 0x1f },
[565]42
[574]43    { 0x38,   0x0f, 0x0f, 0x0f },
44    { 0x39,   0x0f, 0x0f, 0x3f },
45    { 0x3a,   0x0f, 0x3f, 0x0f },
46    { 0x3b,   0x0f, 0x3f, 0x3f },
47    { 0x3c,   0x3f, 0x0f, 0x0f },
48    { 0x3d,   0x3f, 0x0f, 0x3f },
49    { 0x3e,   0x3f, 0x3f, 0x0f },
50    { 0x3f,   0x3f, 0x3f, 0x3f },
[565]51};
52
[811]53static int vga_init_graphics(caca_display_t *dp)
[565]54{
55    int i;
56    uint8_t tmp;
57
58    /* Blank screen */
59    memset(VGA_SCREEN, 0, 80 * 25 * 2);
60
61    /* Fill VGA palette */
62    for(i = 0; i < 16; i++)
63    {
64        outb(vga_colors[i][0], 0x3c8);
65        outb(vga_colors[i][1], 0x3c9);
66        outb(vga_colors[i][2], 0x3c9);
67        outb(vga_colors[i][3], 0x3c9);
68    }
69
70    /* Hide cursor */
71    outb(0x0a, 0x3d4);
72    tmp = inb(0x3d5);
73    tmp |= 0x20;
74    outb(0x0a, 0x3d4);
75    outb(tmp, 0x3d5);
76
[580]77    /* We don't have much choice */
[813]78    _cucul_set_canvas_size(dp->cv, 80, 25);
[580]79
[565]80    return 0;
81}
82
[811]83static int vga_end_graphics(caca_display_t *dp)
[565]84{
85    uint8_t tmp;
86
87    /* Show cursor again */
88    outb(0x0a, 0x3d4);
89    tmp = inb(0x3d5);
90    tmp &= 0xdf;
91    outb(0x0a, 0x3d4);
92    outb(tmp, 0x3d5);
93
94    return 0;
95}
96
[819]97static int vga_set_display_title(caca_display_t *dp, char const *title)
[565]98{
99    /* Unsupported, of course. */
[1006]100    return -1;
[565]101}
102
[819]103static unsigned int vga_get_display_width(caca_display_t *dp)
[565]104{
[580]105    /* Fallback to a 320x200 screen */
106    return 320;
[565]107}
108
[819]109static unsigned int vga_get_display_height(caca_display_t *dp)
[565]110{
[580]111    /* Fallback to a 320x200 screen */
112    return 200;
[565]113}
114
[811]115static void vga_display(caca_display_t *dp)
[565]116{
117    char *screen = (char *)(intptr_t)0x000b8000;
[811]118    uint32_t *attr = dp->cv->attr;
119    uint32_t *chars = dp->cv->chars;
[565]120    int n;
121
[811]122    for(n = dp->cv->height * dp->cv->width; n--; )
[565]123    {
[643]124        *screen++ = _cucul_utf32_to_cp437(*chars++);
[728]125        *screen++ = _cucul_argb32_to_ansi8(*attr++);
[565]126    }
127}
128
[811]129static void vga_handle_resize(caca_display_t *dp)
[565]130{
131    /* We know nothing about our window */
[811]132    dp->resize.w = dp->cv->width;
133    dp->resize.h = dp->cv->height;
[565]134}
135
[1048]136static int vga_get_event(caca_display_t *dp, caca_event_t *ev)
[565]137{
138    /* FIXME */
[681]139    ev->type = CACA_EVENT_NONE;
140    return 0;
[565]141}
142
143/*
144 * Driver initialisation
145 */
146
[811]147int vga_install(caca_display_t *dp)
[565]148{
[811]149    dp->drv.driver = CACA_DRIVER_VGA;
[565]150
[811]151    dp->drv.init_graphics = vga_init_graphics;
152    dp->drv.end_graphics = vga_end_graphics;
[819]153    dp->drv.set_display_title = vga_set_display_title;
154    dp->drv.get_display_width = vga_get_display_width;
155    dp->drv.get_display_height = vga_get_display_height;
[811]156    dp->drv.display = vga_display;
157    dp->drv.handle_resize = vga_handle_resize;
158    dp->drv.get_event = vga_get_event;
159    dp->drv.set_mouse = NULL;
[684]160
161    return 0;
[565]162}
163
164#endif /* USE_VGA */
165
Note: See TracBrowser for help on using the repository browser.