source: libcaca/trunk/caca/driver_conio.c @ 549

Last change on this file since 549 was 549, checked in by Sam Hocevar, 15 years ago
  • Cleaned up useless header includes.
  • Property svn:keywords set to Id
File size: 3.3 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_conio.c
13 *  \version \$Id: driver_conio.c 549 2006-03-08 09:51:53Z sam $
14 *  \author Sam Hocevar <sam@zoy.org>
15 *  \brief DOS/conio.h driver
16 *
17 *  This file contains the libcaca DOS/conio.h input and output driver
18 */
19
20#include "config.h"
21
22#if defined(USE_CONIO)
23
24#include <dos.h>
25#include <conio.h>
26#if defined(SCREENUPDATE_IN_PC_H)
27#   include <pc.h>
28#endif
29
30#include "caca.h"
31#include "caca_internals.h"
32#include "cucul.h"
33#include "cucul_internals.h"
34
35static int conio_init_graphics(caca_t *kk)
36{
37    _wscroll = 0;
38    _setcursortype(_NOCURSOR);
39    clrscr();
40
41    gettextinfo(&kk->conio.ti);
42    kk->conio.screen = malloc(2 * kk->conio.ti.screenwidth
43                                * kk->conio.ti.screenheight * sizeof(char));
44    if(kk->conio.screen == NULL)
45        return -1;
46#   if defined(SCREENUPDATE_IN_PC_H)
47    ScreenRetrieve(kk->conio.screen);
48#   else
49    /* FIXME */
50#   endif
51    cucul_set_size(kk->qq, kk->conio.ti.screenwidth,
52                           kk->conio.ti.screenheight);
53    return 0;
54}
55
56static int conio_end_graphics(caca_t *kk)
57{
58    _wscroll = 1;
59    textcolor((enum COLORS)WHITE);
60    textbackground((enum COLORS)BLACK);
61    gotoxy(kk->qq->width, kk->qq->height);
62    cputs("\r\n");
63    _setcursortype(_NORMALCURSOR);
64
65    free(kk->conio.screen);
66
67    return 0;
68}
69
70static int conio_set_window_title(caca_t *kk, char const *title)
71{
72    return 0;
73}
74
75static unsigned int conio_get_window_width(caca_t *kk)
76{
77    /* Fallback to a 6x10 font */
78    return kk->qq->width * 6;
79}
80
81static unsigned int conio_get_window_height(caca_t *kk)
82{
83    /* Fallback to a 6x10 font */
84    return kk->qq->height * 10;
85}
86
87static void conio_display(caca_t *kk)
88{
89    int n;
90    char *screen = kk->conio.screen;
91    uint8_t *attr = kk->qq->attr;
92    uint32_t *chars = kk->qq->chars;
93    for(n = kk->qq->height * kk->qq->width; n--; )
94    {
95        *screen++ = *chars++ & 0x7f;
96        *screen++ = *attr++;
97    }
98#   if defined(SCREENUPDATE_IN_PC_H)
99    ScreenUpdate(kk->conio.screen);
100#   else
101    /* FIXME */
102#   endif
103}
104
105static void conio_handle_resize(caca_t *kk, unsigned int *new_width,
106                                            unsigned int *new_height)
107{
108    *new_width = kk->qq->width;
109    *new_height = kk->qq->height;
110}
111
112static unsigned int conio_get_event(caca_t *kk)
113{
114    unsigned int event;
115
116    if(!_conio_kbhit())
117        return CACA_EVENT_NONE;
118
119    event = getch();
120    _push_event(kk, CACA_EVENT_KEY_RELEASE | event);
121    return CACA_EVENT_KEY_PRESS | event;
122}
123
124/*
125 * Driver initialisation
126 */
127
128void conio_init_driver(caca_t *kk)
129{
130    kk->driver.driver = CACA_DRIVER_CONIO;
131
132    kk->driver.init_graphics = conio_init_graphics;
133    kk->driver.end_graphics = conio_end_graphics;
134    kk->driver.set_window_title = conio_set_window_title;
135    kk->driver.get_window_width = conio_get_window_width;
136    kk->driver.get_window_height = conio_get_window_height;
137    kk->driver.display = conio_display;
138    kk->driver.handle_resize = conio_handle_resize;
139    kk->driver.get_event = conio_get_event;
140}
141
142#endif /* USE_CONIO */
143
Note: See TracBrowser for help on using the repository browser.