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

Last change on this file since 643 was 643, checked in by Sam Hocevar, 14 years ago
  • Factorised some charset handling code into a new cucul/charset.c file.
  • Property svn:keywords set to Id
File size: 3.6 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 643 2006-03-17 13:32:58Z 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    /* Colour values range from 0x00 to 0x3f */
35    { 0,      0x00, 0x00, 0x00 },
36    { 1,      0x00, 0x00, 0x1f },
37    { 2,      0x00, 0x1f, 0x00 },
38    { 3,      0x00, 0x1f, 0x1f },
39    { 4,      0x1f, 0x00, 0x00 },
40    { 5,      0x1f, 0x00, 0x1f },
41    { 0x14,   0x1f, 0x1f, 0x00 },
42    { 7,      0x1f, 0x1f, 0x1f },
43
44    { 0x38,   0x0f, 0x0f, 0x0f },
45    { 0x39,   0x0f, 0x0f, 0x3f },
46    { 0x3a,   0x0f, 0x3f, 0x0f },
47    { 0x3b,   0x0f, 0x3f, 0x3f },
48    { 0x3c,   0x3f, 0x0f, 0x0f },
49    { 0x3d,   0x3f, 0x0f, 0x3f },
50    { 0x3e,   0x3f, 0x3f, 0x0f },
51    { 0x3f,   0x3f, 0x3f, 0x3f },
52};
53
54static int vga_init_graphics(caca_t *kk)
55{
56    int i;
57    uint8_t tmp;
58
59    /* Blank screen */
60    memset(VGA_SCREEN, 0, 80 * 25 * 2);
61
62    /* Fill VGA palette */
63    for(i = 0; i < 16; i++)
64    {
65        outb(vga_colors[i][0], 0x3c8);
66        outb(vga_colors[i][1], 0x3c9);
67        outb(vga_colors[i][2], 0x3c9);
68        outb(vga_colors[i][3], 0x3c9);
69    }
70
71    /* Hide cursor */
72    outb(0x0a, 0x3d4);
73    tmp = inb(0x3d5);
74    tmp |= 0x20;
75    outb(0x0a, 0x3d4);
76    outb(tmp, 0x3d5);
77
78    /* We don't have much choice */
79    _cucul_set_size(kk->qq, 80, 25);
80
81    return 0;
82}
83
84static int vga_end_graphics(caca_t *kk)
85{
86    uint8_t tmp;
87
88    /* Show cursor again */
89    outb(0x0a, 0x3d4);
90    tmp = inb(0x3d5);
91    tmp &= 0xdf;
92    outb(0x0a, 0x3d4);
93    outb(tmp, 0x3d5);
94
95    return 0;
96}
97
98static int vga_set_window_title(caca_t *kk, char const *title)
99{
100    /* Unsupported, of course. */
101    return 0;
102}
103
104static unsigned int vga_get_window_width(caca_t *kk)
105{
106    /* Fallback to a 320x200 screen */
107    return 320;
108}
109
110static unsigned int vga_get_window_height(caca_t *kk)
111{
112    /* Fallback to a 320x200 screen */
113    return 200;
114}
115
116static void vga_display(caca_t *kk)
117{
118    char *screen = (char *)(intptr_t)0x000b8000;
119    uint8_t *attr = kk->qq->attr;
120    uint32_t *chars = kk->qq->chars;
121    int n;
122
123    for(n = kk->qq->height * kk->qq->width; n--; )
124    {
125        *screen++ = _cucul_utf32_to_cp437(*chars++);
126        *screen++ = *attr++;
127    }
128}
129
130static void vga_handle_resize(caca_t *kk)
131{
132    /* We know nothing about our window */
133    kk->resize.w = kk->qq->width;
134    kk->resize.h = kk->qq->height;
135}
136
137static unsigned int vga_get_event(caca_t *kk)
138{
139    /* FIXME */
140    return CACA_EVENT_NONE;
141}
142
143/*
144 * Driver initialisation
145 */
146
147void vga_init_driver(caca_t *kk)
148{
149    kk->drv.driver = CACA_DRIVER_VGA;
150
151    kk->drv.init_graphics = vga_init_graphics;
152    kk->drv.end_graphics = vga_end_graphics;
153    kk->drv.set_window_title = vga_set_window_title;
154    kk->drv.get_window_width = vga_get_window_width;
155    kk->drv.get_window_height = vga_get_window_height;
156    kk->drv.display = vga_display;
157    kk->drv.handle_resize = vga_handle_resize;
158    kk->drv.get_event = vga_get_event;
159}
160
161#endif /* USE_VGA */
162
Note: See TracBrowser for help on using the repository browser.