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

Last change on this file since 548 was 548, checked in by Sam Hocevar, 15 years ago
  • Split event.c into the appropriate driver_*.c files.
  • Property svn:keywords set to Id
File size: 3.5 KB
RevLine 
[35]1/*
[268]2 *  libcaca       ASCII-Art library
[527]3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
[268]4 *                All Rights Reserved
[35]5 *
[268]6 *  This library is free software; you can redistribute it and/or
[522]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.
[35]10 */
[17]11
[540]12/** \file driver_conio.c
[268]13 *  \version \$Id: driver_conio.c 548 2006-03-08 09:28:41Z sam $
14 *  \author Sam Hocevar <sam@zoy.org>
[540]15 *  \brief DOS/conio.h driver
[205]16 *
[540]17 *  This file contains the libcaca DOS/conio.h input and output driver
[205]18 */
19
[63]20#include "config.h"
21
[539]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
[147]30#include <string.h>
[17]31#include <stdlib.h>
[344]32#if defined(HAVE_UNISTD_H)
33#   include <unistd.h>
34#endif
[181]35#include <stdarg.h>
[17]36
[348]37#if defined(HAVE_SYS_IOCTL_H)
38#   include <sys/ioctl.h>
39#endif
40
[185]41#include "caca.h"
42#include "caca_internals.h"
[524]43#include "cucul.h"
44#include "cucul_internals.h"
[17]45
[540]46static int conio_init_graphics(caca_t *kk)
[227]47{
[539]48    _wscroll = 0;
49    _setcursortype(_NOCURSOR);
50    clrscr();
[348]51
[539]52    gettextinfo(&kk->conio.ti);
53    kk->conio.screen = malloc(2 * kk->conio.ti.screenwidth
[527]54                                * kk->conio.ti.screenheight * sizeof(char));
[539]55    if(kk->conio.screen == NULL)
56        return -1;
[227]57#   if defined(SCREENUPDATE_IN_PC_H)
[539]58    ScreenRetrieve(kk->conio.screen);
[227]59#   else
[539]60    /* FIXME */
[227]61#   endif
[539]62    cucul_set_size(kk->qq, kk->conio.ti.screenwidth,
63                           kk->conio.ti.screenheight);
[227]64    return 0;
65}
66
[540]67static int conio_end_graphics(caca_t *kk)
[251]68{
[539]69    _wscroll = 1;
70    textcolor((enum COLORS)WHITE);
71    textbackground((enum COLORS)BLACK);
[543]72    gotoxy(kk->qq->width, kk->qq->height);
[539]73    cputs("\r\n");
74    _setcursortype(_NORMALCURSOR);
[300]75
[539]76    free(kk->conio.screen);
77
[251]78    return 0;
79}
80
[540]81static int conio_set_window_title(caca_t *kk, char const *title)
[343]82{
83    return 0;
84}
85
[540]86static unsigned int conio_get_window_width(caca_t *kk)
[352]87{
88    /* Fallback to a 6x10 font */
[524]89    return kk->qq->width * 6;
[352]90}
91
[540]92static unsigned int conio_get_window_height(caca_t *kk)
[352]93{
94    /* Fallback to a 6x10 font */
[524]95    return kk->qq->height * 10;
[352]96}
97
[540]98static void conio_display(caca_t *kk)
[227]99{
[539]100    int n;
101    char *screen = kk->conio.screen;
102    uint8_t *attr = kk->qq->attr;
103    uint32_t *chars = kk->qq->chars;
104    for(n = kk->qq->height * kk->qq->width; n--; )
[265]105    {
[539]106        *screen++ = *chars++ & 0x7f;
107        *screen++ = *attr++;
[265]108    }
[227]109#   if defined(SCREENUPDATE_IN_PC_H)
[539]110    ScreenUpdate(kk->conio.screen);
[227]111#   else
[539]112    /* FIXME */
[227]113#   endif
[539]114}
[261]115
[540]116static void conio_handle_resize(caca_t *kk, unsigned int *new_width,
117                                            unsigned int *new_height)
[539]118{
[540]119    *new_width = kk->qq->width;
120    *new_height = kk->qq->height;
[227]121}
122
[548]123static unsigned int conio_get_event(caca_t *kk)
124{
125    unsigned int event;
126
127    if(!_conio_kbhit())
128        return CACA_EVENT_NONE;
129
130    event = getch();
131    _push_event(kk, CACA_EVENT_KEY_RELEASE | event);
132    return CACA_EVENT_KEY_PRESS | event;
133}
134
[347]135/*
[539]136 * Driver initialisation
[347]137 */
[524]138
[539]139void conio_init_driver(caca_t *kk)
[347]140{
[539]141    kk->driver.driver = CACA_DRIVER_CONIO;
[347]142
[539]143    kk->driver.init_graphics = conio_init_graphics;
144    kk->driver.end_graphics = conio_end_graphics;
145    kk->driver.set_window_title = conio_set_window_title;
146    kk->driver.get_window_width = conio_get_window_width;
147    kk->driver.get_window_height = conio_get_window_height;
148    kk->driver.display = conio_display;
149    kk->driver.handle_resize = conio_handle_resize;
[548]150    kk->driver.get_event = conio_get_event;
[347]151}
152
[539]153#endif /* USE_CONIO */
[281]154
Note: See TracBrowser for help on using the repository browser.