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

Last change on this file since 1063 was 1006, checked in by Sam Hocevar, 14 years ago
  • Fixed libcaca prototypes so that all functions use the errno mechanism and return a value.
  • Property svn:keywords set to Id
File size: 3.8 KB
RevLine 
[35]1/*
[672]2 *  libcaca       Colour ASCII-Art library
[527]3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
[268]4 *                All Rights Reserved
[35]5 *
[769]6 *  $Id: driver_conio.c 1006 2006-08-02 13:12:43Z sam $
7 *
[268]8 *  This library is free software; you can redistribute it and/or
[522]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.
[35]12 */
[17]13
[769]14/*
[540]15 *  This file contains the libcaca DOS/conio.h input and output driver
[205]16 */
17
[63]18#include "config.h"
[859]19#include "common.h"
[63]20
[539]21#if defined(USE_CONIO)
22
23#include <dos.h>
24#include <conio.h>
25#if defined(SCREENUPDATE_IN_PC_H)
26#   include <pc.h>
27#endif
28
[550]29#include <stdlib.h>
30
[185]31#include "caca.h"
32#include "caca_internals.h"
[524]33#include "cucul.h"
34#include "cucul_internals.h"
[17]35
[550]36struct driver_private
37{
38    struct text_info ti;
39    char *screen;
40};
41
[811]42static int conio_init_graphics(caca_display_t *dp)
[227]43{
[811]44    dp->drv.p = malloc(sizeof(struct driver_private));
[550]45
[539]46    _wscroll = 0;
47    _setcursortype(_NOCURSOR);
48    clrscr();
[348]49
[811]50    gettextinfo(&dp->drv.p->ti);
51    dp->drv.p->screen = malloc(2 * dp->drv.p->ti.screenwidth
52                                 * dp->drv.p->ti.screenheight * sizeof(char));
53    if(dp->drv.p->screen == NULL)
[539]54        return -1;
[227]55#   if defined(SCREENUPDATE_IN_PC_H)
[811]56    ScreenRetrieve(dp->drv.p->screen);
[227]57#   else
[539]58    /* FIXME */
[227]59#   endif
[813]60    _cucul_set_canvas_size(dp->cv, dp->drv.p->ti.screenwidth,
61                                   dp->drv.p->ti.screenheight);
[227]62    return 0;
63}
64
[811]65static int conio_end_graphics(caca_display_t *dp)
[251]66{
[539]67    _wscroll = 1;
68    textcolor((enum COLORS)WHITE);
69    textbackground((enum COLORS)BLACK);
[811]70    gotoxy(dp->cv->width, dp->cv->height);
[539]71    cputs("\r\n");
72    _setcursortype(_NORMALCURSOR);
[300]73
[811]74    free(dp->drv.p->screen);
75    free(dp->drv.p);
[539]76
[251]77    return 0;
78}
79
[819]80static int conio_set_display_title(caca_display_t *dp, char const *title)
[343]81{
[1006]82    return -1;
[343]83}
84
[819]85static unsigned int conio_get_display_width(caca_display_t *dp)
[352]86{
87    /* Fallback to a 6x10 font */
[811]88    return dp->cv->width * 6;
[352]89}
90
[819]91static unsigned int conio_get_display_height(caca_display_t *dp)
[352]92{
93    /* Fallback to a 6x10 font */
[811]94    return dp->cv->height * 10;
[352]95}
96
[811]97static void conio_display(caca_display_t *dp)
[227]98{
[811]99    char *screen = dp->drv.p->screen;
100    uint32_t *attr = dp->cv->attr;
101    uint32_t *chars = dp->cv->chars;
[567]102    int n;
103
[811]104    for(n = dp->cv->height * dp->cv->width; n--; )
[265]105    {
[979]106        *screen++ = cucul_utf32_to_cp437(*chars++);
[728]107        *screen++ = _cucul_argb32_to_ansi8(*attr++);
[265]108    }
[227]109#   if defined(SCREENUPDATE_IN_PC_H)
[811]110    ScreenUpdate(dp->drv.p->screen);
[227]111#   else
[539]112    /* FIXME */
[227]113#   endif
[539]114}
[261]115
[811]116static void conio_handle_resize(caca_display_t *dp)
[539]117{
[553]118    /* We know nothing about our window */
[811]119    dp->resize.w = dp->cv->width;
120    dp->resize.h = dp->cv->height;
[227]121}
122
[811]123static int conio_get_event(caca_display_t *dp, caca_event_t *ev)
[548]124{
[681]125    unsigned char ch;
[777]126    caca_event_t release;
[548]127
128    if(!_conio_kbhit())
[681]129    {
130        ev->type = CACA_EVENT_NONE;
131        return 0;
132    }
[548]133
[681]134    ch = getch();
135
136    ev->type = CACA_EVENT_KEY_PRESS;
[810]137    ev->data.key.ch = ch;
[969]138    ev->data.key.utf32 = (uint32_t)ch;
[681]139    ev->data.key.utf8[0] = ch;
140    ev->data.key.utf8[1] = '\0';
141
142    release = *ev;
143    release.type = CACA_EVENT_KEY_RELEASE;
[811]144    _push_event(dp, &release);
[681]145
146    return 1;
[548]147}
148
[347]149/*
[539]150 * Driver initialisation
[347]151 */
[524]152
[811]153int conio_install(caca_display_t *dp)
[347]154{
[811]155    dp->drv.driver = CACA_DRIVER_CONIO;
[347]156
[811]157    dp->drv.init_graphics = conio_init_graphics;
158    dp->drv.end_graphics = conio_end_graphics;
[819]159    dp->drv.set_display_title = conio_set_display_title;
160    dp->drv.get_display_width = conio_get_display_width;
161    dp->drv.get_display_height = conio_get_display_height;
[811]162    dp->drv.display = conio_display;
163    dp->drv.handle_resize = conio_handle_resize;
164    dp->drv.get_event = conio_get_event;
165    dp->drv.set_mouse = NULL;
[684]166
167    return 0;
[347]168}
169
[539]170#endif /* USE_CONIO */
[281]171
Note: See TracBrowser for help on using the repository browser.