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 graphics.c |
---|
13 | * \version \$Id: driver_conio.c 539 2006-03-06 23:01:59Z sam $ |
---|
14 | * \author Sam Hocevar <sam@zoy.org> |
---|
15 | * \brief Character drawing |
---|
16 | * |
---|
17 | * This file contains character and string drawing functions. |
---|
18 | */ |
---|
19 | |
---|
20 | #include "config.h" |
---|
21 | |
---|
22 | #if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) |
---|
23 | # include <inttypes.h> |
---|
24 | #else |
---|
25 | typedef unsigned int uint32_t; |
---|
26 | typedef unsigned char uint8_t; |
---|
27 | #endif |
---|
28 | |
---|
29 | #if defined(USE_CONIO) |
---|
30 | |
---|
31 | #include <dos.h> |
---|
32 | #include <conio.h> |
---|
33 | #if defined(SCREENUPDATE_IN_PC_H) |
---|
34 | # include <pc.h> |
---|
35 | #endif |
---|
36 | |
---|
37 | #include <string.h> |
---|
38 | #include <stdlib.h> |
---|
39 | #if defined(HAVE_UNISTD_H) |
---|
40 | # include <unistd.h> |
---|
41 | #endif |
---|
42 | #include <stdarg.h> |
---|
43 | |
---|
44 | #if defined(HAVE_SYS_IOCTL_H) |
---|
45 | # include <sys/ioctl.h> |
---|
46 | #endif |
---|
47 | |
---|
48 | #include "caca.h" |
---|
49 | #include "caca_internals.h" |
---|
50 | #include "cucul.h" |
---|
51 | #include "cucul_internals.h" |
---|
52 | |
---|
53 | #if !defined(_DOXYGEN_SKIP_ME) |
---|
54 | int conio_init_graphics(caca_t *kk) |
---|
55 | { |
---|
56 | _wscroll = 0; |
---|
57 | _setcursortype(_NOCURSOR); |
---|
58 | clrscr(); |
---|
59 | |
---|
60 | gettextinfo(&kk->conio.ti); |
---|
61 | kk->conio.screen = malloc(2 * kk->conio.ti.screenwidth |
---|
62 | * kk->conio.ti.screenheight * sizeof(char)); |
---|
63 | if(kk->conio.screen == NULL) |
---|
64 | return -1; |
---|
65 | # if defined(SCREENUPDATE_IN_PC_H) |
---|
66 | ScreenRetrieve(kk->conio.screen); |
---|
67 | # else |
---|
68 | /* FIXME */ |
---|
69 | # endif |
---|
70 | cucul_set_size(kk->qq, kk->conio.ti.screenwidth, |
---|
71 | kk->conio.ti.screenheight); |
---|
72 | return 0; |
---|
73 | } |
---|
74 | |
---|
75 | int conio_end_graphics(caca_t *kk) |
---|
76 | { |
---|
77 | _wscroll = 1; |
---|
78 | textcolor((enum COLORS)WHITE); |
---|
79 | textbackground((enum COLORS)BLACK); |
---|
80 | gotoxy(_caca_width, _caca_height); |
---|
81 | cputs("\r\n"); |
---|
82 | _setcursortype(_NORMALCURSOR); |
---|
83 | |
---|
84 | free(kk->conio.screen); |
---|
85 | |
---|
86 | return 0; |
---|
87 | } |
---|
88 | #endif /* _DOXYGEN_SKIP_ME */ |
---|
89 | |
---|
90 | int conio_set_window_title(caca_t *kk, char const *title) |
---|
91 | { |
---|
92 | return 0; |
---|
93 | } |
---|
94 | |
---|
95 | unsigned int conio_get_window_width(caca_t *kk) |
---|
96 | { |
---|
97 | /* Fallback to a 6x10 font */ |
---|
98 | return kk->qq->width * 6; |
---|
99 | } |
---|
100 | |
---|
101 | unsigned int conio_get_window_height(caca_t *kk) |
---|
102 | { |
---|
103 | /* Fallback to a 6x10 font */ |
---|
104 | return kk->qq->height * 10; |
---|
105 | } |
---|
106 | |
---|
107 | void conio_display(caca_t *kk) |
---|
108 | { |
---|
109 | int n; |
---|
110 | char *screen = kk->conio.screen; |
---|
111 | uint8_t *attr = kk->qq->attr; |
---|
112 | uint32_t *chars = kk->qq->chars; |
---|
113 | for(n = kk->qq->height * kk->qq->width; n--; ) |
---|
114 | { |
---|
115 | *screen++ = *chars++ & 0x7f; |
---|
116 | *screen++ = *attr++; |
---|
117 | } |
---|
118 | # if defined(SCREENUPDATE_IN_PC_H) |
---|
119 | ScreenUpdate(kk->conio.screen); |
---|
120 | # else |
---|
121 | /* FIXME */ |
---|
122 | # endif |
---|
123 | } |
---|
124 | |
---|
125 | void conio_handle_resize(caca_t *kk) |
---|
126 | { |
---|
127 | return; |
---|
128 | } |
---|
129 | |
---|
130 | /* |
---|
131 | * Driver initialisation |
---|
132 | */ |
---|
133 | |
---|
134 | void conio_init_driver(caca_t *kk) |
---|
135 | { |
---|
136 | kk->driver.driver = CACA_DRIVER_CONIO; |
---|
137 | |
---|
138 | kk->driver.init_graphics = conio_init_graphics; |
---|
139 | kk->driver.end_graphics = conio_end_graphics; |
---|
140 | kk->driver.set_window_title = conio_set_window_title; |
---|
141 | kk->driver.get_window_width = conio_get_window_width; |
---|
142 | kk->driver.get_window_height = conio_get_window_height; |
---|
143 | kk->driver.display = conio_display; |
---|
144 | kk->driver.handle_resize = conio_handle_resize; |
---|
145 | } |
---|
146 | |
---|
147 | #endif /* USE_CONIO */ |
---|
148 | |
---|