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

Last change on this file since 810 was 810, checked in by Sam Hocevar, 14 years ago
  • Renamed cucul_t into cucul_canvas_t. Eh ouais mon con.
  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: driver_vga.c 810 2006-04-18 12:59:07Z sam $
7 *
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
14/*
15 *  This file contains the libcaca VGA input and output driver
16 */
17
18#include "config.h"
19
20#if defined(USE_VGA)
21
22#include "caca.h"
23#include "caca_internals.h"
24#include "cucul.h"
25#include "cucul_internals.h"
26
27/* Address of the VGA screen */
28#define VGA_SCREEN ((char *)(intptr_t)0x000b8000)
29
30static uint8_t const vga_colors[][4] =
31{
32    /* Colour values range from 0x00 to 0x3f */
33    { 0,      0x00, 0x00, 0x00 },
34    { 1,      0x00, 0x00, 0x1f },
35    { 2,      0x00, 0x1f, 0x00 },
36    { 3,      0x00, 0x1f, 0x1f },
37    { 4,      0x1f, 0x00, 0x00 },
38    { 5,      0x1f, 0x00, 0x1f },
39    { 0x14,   0x1f, 0x1f, 0x00 },
40    { 7,      0x1f, 0x1f, 0x1f },
41
42    { 0x38,   0x0f, 0x0f, 0x0f },
43    { 0x39,   0x0f, 0x0f, 0x3f },
44    { 0x3a,   0x0f, 0x3f, 0x0f },
45    { 0x3b,   0x0f, 0x3f, 0x3f },
46    { 0x3c,   0x3f, 0x0f, 0x0f },
47    { 0x3d,   0x3f, 0x0f, 0x3f },
48    { 0x3e,   0x3f, 0x3f, 0x0f },
49    { 0x3f,   0x3f, 0x3f, 0x3f },
50};
51
52static int vga_init_graphics(caca_t *kk)
53{
54    int i;
55    uint8_t tmp;
56
57    /* Blank screen */
58    memset(VGA_SCREEN, 0, 80 * 25 * 2);
59
60    /* Fill VGA palette */
61    for(i = 0; i < 16; i++)
62    {
63        outb(vga_colors[i][0], 0x3c8);
64        outb(vga_colors[i][1], 0x3c9);
65        outb(vga_colors[i][2], 0x3c9);
66        outb(vga_colors[i][3], 0x3c9);
67    }
68
69    /* Hide cursor */
70    outb(0x0a, 0x3d4);
71    tmp = inb(0x3d5);
72    tmp |= 0x20;
73    outb(0x0a, 0x3d4);
74    outb(tmp, 0x3d5);
75
76    /* We don't have much choice */
77    _cucul_set_size(kk->c, 80, 25);
78
79    return 0;
80}
81
82static int vga_end_graphics(caca_t *kk)
83{
84    uint8_t tmp;
85
86    /* Show cursor again */
87    outb(0x0a, 0x3d4);
88    tmp = inb(0x3d5);
89    tmp &= 0xdf;
90    outb(0x0a, 0x3d4);
91    outb(tmp, 0x3d5);
92
93    return 0;
94}
95
96static int vga_set_window_title(caca_t *kk, char const *title)
97{
98    /* Unsupported, of course. */
99    return 0;
100}
101
102static unsigned int vga_get_window_width(caca_t *kk)
103{
104    /* Fallback to a 320x200 screen */
105    return 320;
106}
107
108static unsigned int vga_get_window_height(caca_t *kk)
109{
110    /* Fallback to a 320x200 screen */
111    return 200;
112}
113
114static void vga_display(caca_t *kk)
115{
116    char *screen = (char *)(intptr_t)0x000b8000;
117    uint32_t *attr = kk->c->attr;
118    uint32_t *chars = kk->c->chars;
119    int n;
120
121    for(n = kk->c->height * kk->c->width; n--; )
122    {
123        *screen++ = _cucul_utf32_to_cp437(*chars++);
124        *screen++ = _cucul_argb32_to_ansi8(*attr++);
125    }
126}
127
128static void vga_handle_resize(caca_t *kk)
129{
130    /* We know nothing about our window */
131    kk->resize.w = kk->c->width;
132    kk->resize.h = kk->c->height;
133}
134
135static int vga_get_event(caca_t *kk, caca_event-t *ev)
136{
137    /* FIXME */
138    ev->type = CACA_EVENT_NONE;
139    return 0;
140}
141
142/*
143 * Driver initialisation
144 */
145
146int vga_install(caca_t *kk)
147{
148    kk->drv.driver = CACA_DRIVER_VGA;
149
150    kk->drv.init_graphics = vga_init_graphics;
151    kk->drv.end_graphics = vga_end_graphics;
152    kk->drv.set_window_title = vga_set_window_title;
153    kk->drv.get_window_width = vga_get_window_width;
154    kk->drv.get_window_height = vga_get_window_height;
155    kk->drv.display = vga_display;
156    kk->drv.handle_resize = vga_handle_resize;
157    kk->drv.get_event = vga_get_event;
158    kk->drv.set_mouse = NULL;
159
160    return 0;
161}
162
163#endif /* USE_VGA */
164
Note: See TracBrowser for help on using the repository browser.