source: libcaca/trunk/caca/driver_conio.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.7 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_conio.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 DOS/conio.h input and output driver
16 */
17
18#include "config.h"
19
20#if defined(USE_CONIO)
21
22#include <dos.h>
23#include <conio.h>
24#if defined(SCREENUPDATE_IN_PC_H)
25#   include <pc.h>
26#endif
27
28#include <stdlib.h>
29
30#include "caca.h"
31#include "caca_internals.h"
32#include "cucul.h"
33#include "cucul_internals.h"
34
35struct driver_private
36{
37    struct text_info ti;
38    char *screen;
39};
40
41static int conio_init_graphics(caca_t *kk)
42{
43    kk->drv.p = malloc(sizeof(struct driver_private));
44
45    _wscroll = 0;
46    _setcursortype(_NOCURSOR);
47    clrscr();
48
49    gettextinfo(&kk->drv.p->ti);
50    kk->drv.p->screen = malloc(2 * kk->drv.p->ti.screenwidth
51                                 * kk->drv.p->ti.screenheight * sizeof(char));
52    if(kk->drv.p->screen == NULL)
53        return -1;
54#   if defined(SCREENUPDATE_IN_PC_H)
55    ScreenRetrieve(kk->drv.p->screen);
56#   else
57    /* FIXME */
58#   endif
59    _cucul_set_size(kk->c, kk->drv.p->ti.screenwidth,
60                           kk->drv.p->ti.screenheight);
61    return 0;
62}
63
64static int conio_end_graphics(caca_t *kk)
65{
66    _wscroll = 1;
67    textcolor((enum COLORS)WHITE);
68    textbackground((enum COLORS)BLACK);
69    gotoxy(kk->c->width, kk->c->height);
70    cputs("\r\n");
71    _setcursortype(_NORMALCURSOR);
72
73    free(kk->drv.p->screen);
74    free(kk->drv.p);
75
76    return 0;
77}
78
79static int conio_set_window_title(caca_t *kk, char const *title)
80{
81    return 0;
82}
83
84static unsigned int conio_get_window_width(caca_t *kk)
85{
86    /* Fallback to a 6x10 font */
87    return kk->c->width * 6;
88}
89
90static unsigned int conio_get_window_height(caca_t *kk)
91{
92    /* Fallback to a 6x10 font */
93    return kk->c->height * 10;
94}
95
96static void conio_display(caca_t *kk)
97{
98    char *screen = kk->drv.p->screen;
99    uint32_t *attr = kk->c->attr;
100    uint32_t *chars = kk->c->chars;
101    int n;
102
103    for(n = kk->c->height * kk->c->width; n--; )
104    {
105        *screen++ = _cucul_utf32_to_cp437(*chars++);
106        *screen++ = _cucul_argb32_to_ansi8(*attr++);
107    }
108#   if defined(SCREENUPDATE_IN_PC_H)
109    ScreenUpdate(kk->drv.p->screen);
110#   else
111    /* FIXME */
112#   endif
113}
114
115static void conio_handle_resize(caca_t *kk)
116{
117    /* We know nothing about our window */
118    kk->resize.w = kk->c->width;
119    kk->resize.h = kk->c->height;
120}
121
122static int conio_get_event(caca_t *kk, caca_event_t *ev)
123{
124    unsigned char ch;
125    caca_event_t release;
126
127    if(!_conio_kbhit())
128    {
129        ev->type = CACA_EVENT_NONE;
130        return 0;
131    }
132
133    ch = getch();
134
135    ev->type = CACA_EVENT_KEY_PRESS;
136    ev->data.key.ch = ch;
137    ev->data.key.ucs4 = (uint32_t)ch;
138    ev->data.key.utf8[0] = ch;
139    ev->data.key.utf8[1] = '\0';
140
141    release = *ev;
142    release.type = CACA_EVENT_KEY_RELEASE;
143    _push_event(kk, &release);
144
145    return 1;
146}
147
148/*
149 * Driver initialisation
150 */
151
152int conio_install(caca_t *kk)
153{
154    kk->drv.driver = CACA_DRIVER_CONIO;
155
156    kk->drv.init_graphics = conio_init_graphics;
157    kk->drv.end_graphics = conio_end_graphics;
158    kk->drv.set_window_title = conio_set_window_title;
159    kk->drv.get_window_width = conio_get_window_width;
160    kk->drv.get_window_height = conio_get_window_height;
161    kk->drv.display = conio_display;
162    kk->drv.handle_resize = conio_handle_resize;
163    kk->drv.get_event = conio_get_event;
164    kk->drv.set_mouse = NULL;
165
166    return 0;
167}
168
169#endif /* USE_CONIO */
170
Note: See TracBrowser for help on using the repository browser.