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

Last change on this file since 565 was 565, checked in by Sam Hocevar, 17 years ago
  • Pure VGA output driver.
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1/*
2 *  libcaca       ASCII-Art library
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  This library is free software; you can redistribute it and/or
7 *  modify it under the terms of the Do What The Fuck You Want To
8 *  Public License, Version 2, as published by Sam Hocevar. See
9 *  http://sam.zoy.org/wtfpl/COPYING for more details.
10 */
11
12/** \file driver_vga.c
13 *  \version \$Id: driver_vga.c 565 2006-03-09 12:41:02Z sam $
14 *  \author Sam Hocevar <sam@zoy.org>
15 *  \brief VGA driver
16 *
17 *  This file contains the libcaca VGA input and output driver
18 */
19
20#include "config.h"
21
22#if defined(USE_VGA)
23
24#include "caca.h"
25#include "caca_internals.h"
26#include "cucul.h"
27#include "cucul_internals.h"
28
29/* Address of the VGA screen */
30#define VGA_SCREEN ((char *)(intptr_t)0x000b8000)
31
32static uint8_t const vga_colors[][4] =
33{
34    { 0,      0x20, 0x20, 0x20 },
35    { 1,      0x20, 0x20, 0x7f },
36    { 2,      0x20, 0x7f, 0x20 },
37    { 3,      0x20, 0x7f, 0x7f },
38    { 4,      0x7f, 0x20, 0x20 },
39    { 5,      0x7f, 0x20, 0x7f },
40    { 0x14,   0x7f, 0x7f, 0x20 },
41    { 7,      0x7f, 0x7f, 0x7f },
42
43    { 0x38,   0x40, 0x40, 0x40 },
44    { 0x39,   0x40, 0x40, 0xff },
45    { 0x3a,   0x40, 0xff, 0x40 },
46    { 0x3b,   0x40, 0xff, 0xff },
47    { 0x3c,   0xff, 0x40, 0x40 },
48    { 0x3d,   0xff, 0x40, 0xff },
49    { 0x3e,   0xff, 0xff, 0x40 },
50    { 0x3f,   0xff, 0xff, 0xff }
51};
52
53static int vga_init_graphics(caca_t *kk)
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
77    return 0;
78}
79
80static int vga_end_graphics(caca_t *kk)
81{
82    uint8_t tmp;
83
84    /* Show cursor again */
85    outb(0x0a, 0x3d4);
86    tmp = inb(0x3d5);
87    tmp &= 0xdf;
88    outb(0x0a, 0x3d4);
89    outb(tmp, 0x3d5);
90
91    return 0;
92}
93
94static int vga_set_window_title(caca_t *kk, char const *title)
95{
96    /* Unsupported, of course. */
97    return 0;
98}
99
100static unsigned int vga_get_window_width(caca_t *kk)
101{
102    /* Fallback to a 6x10 font */
103    return kk->qq->width * 6;
104}
105
106static unsigned int vga_get_window_height(caca_t *kk)
107{
108    /* Fallback to a 6x10 font */
109    return kk->qq->height * 10;
110}
111
112static void vga_display(caca_t *kk)
113{
114    char *screen = (char *)(intptr_t)0x000b8000;
115    uint8_t *attr = kk->qq->attr;
116    uint32_t *chars = kk->qq->chars;
117    int n;
118
119    for(n = kk->qq->height * kk->qq->width; n--; )
120    {
121        uint32_t c = *chars++;
122
123        if(c > 0x00000020 && c < 0x00000080)
124            *screen++ = (char)c;
125        else
126            *screen++ = ' ';
127
128        *screen++ = *attr++;
129    }
130}
131
132static void vga_handle_resize(caca_t *kk)
133{
134    /* We know nothing about our window */
135    kk->resize.w = kk->qq->width;
136    kk->resize.h = kk->qq->height;
137}
138
139static unsigned int vga_get_event(caca_t *kk)
140{
141    /* FIXME */
142    return CACA_EVENT_NONE;
143}
144
145/*
146 * Driver initialisation
147 */
148
149void vga_init_driver(caca_t *kk)
150{
151    kk->drv.driver = CACA_DRIVER_VGA;
152
153    kk->drv.init_graphics = vga_init_graphics;
154    kk->drv.end_graphics = vga_end_graphics;
155    kk->drv.set_window_title = vga_set_window_title;
156    kk->drv.get_window_width = vga_get_window_width;
157    kk->drv.get_window_height = vga_get_window_height;
158    kk->drv.display = vga_display;
159    kk->drv.handle_resize = vga_handle_resize;
160    kk->drv.get_event = vga_get_event;
161}
162
163#endif /* USE_VGA */
164
Note: See TracBrowser for help on using the repository browser.