2 // nazghul - an old-school RPG engine
3 // Copyright (C) 2002, 2003 Gordon McNutt
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 2 of the License, or (at your option)
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 // You should have received a copy of the GNU General Public License along with
16 // this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17 // Suite 330, Boston, MA 02111-1307 USA
20 // gmcnutt@users.sourceforge.net
27 #include "dimensions.h"
29 #include <SDL_image.h>
36 /* To see the function names in backtraces, you need to ask gcc to
37 * add them to the binary with the -rdynamic linker (LDFLAGS) option
38 * and disable the static keyword for objects which static functions
39 * you'd like to see, either with -Dstatic= compiler option or just
40 * using in those sources following: */
44 #define MAX_STACK_DEPTH 16
45 static void backtrace2stderr(void)
48 void *bt[MAX_STACK_DEPTH];
49 depth = backtrace(bt, MAX_STACK_DEPTH);
51 /* skip this fuction and C++ main, show rest */
52 backtrace_symbols_fd(bt+1, depth-2, 2);
58 #define ASCII_DEF_CLR White /* default printing color is white */
59 #define ASCII_CLR_STK_SZ 32
61 /* State machine states for embedded control sequences. */
62 enum ascii_ctrl_states {
69 /* This is a default character image set in XPM format. For emergency use
71 static const char * charset_xpm[] = {
117 ".+@##@+.$%%&*&%$=-;-=-;-=-;-=-;-...;>......;-......;>....+@##@+............->>.....->>.............->>..........,-''''-,........",
118 ".+@##@+.$%%&*&%$=-;-=-;-=-;-=-;-...;>......;-......;>....+@##@+............->>.....->>.............->>..........,-''''-,........",
119 ".@#)!#@.%~{{{{~%;.;;;;.;;;;;;;;;..;;->.....;-.....;;->...@#)!#@...];;]....-^^^>...-^^^>......->>..->^->.////////-......-..$&&$..",
120 ".@#)!#@.%~{{{{~%;.;;;;.;;;;;;;;;..;;->.....;-.....;;->...@#)!#@...];;]....-^^^>...-^^^>......->>..->^->.////////-......-..$&&$..",
121 ".@#.+#@.&~(__(~&;-=-;-=-;-=-;-=-.;;-->>....;-....;;-->>..........^:'=:^..-.->>^>.-.-->^>....^^->.^->^->.<<<<<<<<'......'.%*//*%.",
122 ".@#.+#@.&~(__(~&;-=-;-=-;-=-;-=-.;;-->>....;-....;;-->>..........^:'=:^..-.->>^>.-.-->^>....^^->.^->^->.<<<<<<<<'......'.%*//*%.",
123 ".+@##@+.*~[__[~*;;;;;;;;;;;;;;;;...;;......;-......;;....+@##@+.}|'>>'|}^-^-^.^>^-^->^^>..->>-^>.^^->>..11111111'......'2&341/&2",
124 ".+@##@+.*~[__[~*;;;;;;;;;;;;;;;;...;;......;-......;;....+@##@+.}|'>>'|}^-^-^.^>^-^->^^>..->>-^>.^^->>..11111111'......'2&341/&2",
125 "+@####@+&~(__(~&=-;-=-;-=-;-=-;=...;-......;-......;-...........}|--''|}^-^->>^>^-^-^>^>.->^->^...^^>...////////'......'2&55/3&2",
126 "+@####@+&~(__(~&=-;-=-;-=-;-=-;=...;-......;-......;-...........}|--''|}^-^->>^>^-^-^>^>.->^->^...^^>...////////'......'2&55/3&2",
127 "..+@#+..%~6__6~%;;;;;;;;;;;;;;;;.;;-->>..;;-->>....;-.....+@#+...^:--:^.^^-^^.>.^^-^^.>.^->^->.....->>..********'......'.%*55*%.",
128 "..+@#+..%~6__6~%;;;;;;;;;;;;;;;;.;;-->>..;;-->>....;-.....+@#+...^:--:^.^^-^^.>.^^-^^.>.^->^->.....->>..********'......'.%*55*%.",
129 "..+@#+..2%~66~%2;.=-;-.-;-=-;-=-..;;->....;;->.....;-.....+@#+....];;]...^^-->...^^-->..^^->>.....^^-...%%%%%%%%-......-..$&&$..",
130 "..+@#+..2%~66~%2;.=-;-.-;-=-;-=-..;;->....;;->.....;-.....+@#+....];;]...^^-->...^^-->..^^->>.....^^-...%%%%%%%%-......-..$&&$..",
131 "..+@#+...2%~~%2.;;;;;;;;;;;;;;;;...;>......;>......;-.....+@#+............^^^.....^^^....^^^.......^............,-''''-,........",
132 "..+@#+...2%~~%2.;;;;;;;;;;;;;;;;...;>......;>......;-.....+@#+............^^^.....^^^....^^^.......^............,-''''-,........",
133 "..................................;78.....|^8.....|,7.....|,|.....7,|.....8^|.....87;.....888....2%%&&$..%*55*$..%5/5$2..222$$2.",
134 "..................................;78.....|^8.....|,7.....|,|.....7,|.....8^|.....87;.....888....2%%&&$..%*55*$..%5/5$2..222$$2.",
135 "/*%..........%*/.................,9778...,>978...,>0,7...,>a>,...7,>b,...879>,...8779,...87778..2$2$$%*%$*%%%*5%$5*&*5%22%**%2$2",
136 "/*%..........%*/.................,9778...,>978...,>0,7...,>a>,...7,>b,...879>,...8779,...87778..2$2$$%*%$*%%%*5%$5*&*5%22%**%2$2",
137 "<5*$........$*5c................;'77778.;>b^778.;>>>b97.|>00a0|.79b>b>;.877^b>;.87777';.8777778.$2&53&%*&%&3/**5***/%/*2$5//5&2%",
138 "<5*$........$*5c................;'77778.;>b^778.;>>>b97.|>00a0|.79b>b>;.877^b>;.87777';.8777778.$2&53&%*&%&3/**5***/%/*2$5//5&2%",
139 "135%........%531................,=77778.,>a9778.,>bbd;7.,>>>0b,.7;eded-.8779a>,.87777=,.8777778.$%5**3%5&$3**/&/5%/*%/*25*%%*5$%",
140 "135%........%531................,=77778.,>a9778.,>bbd;7.,>>>0b,.7;eded-.8779a>,.87777=,.8777778.$%5**3%5&$3**/&/5%/*%/*25*%%*5$%",
141 "//5%........%5//................;'77778.;>e^778.;>d>097.|>b>ad|.79b>>>;.877^b>;.87777';.8777778.2*/%*/%5%$5*%%*55%3**5%$/&/**3$&",
142 "//5%........%5//................;'77778.;>e^778.;>d>097.|>b>ad|.79b>>>;.877^b>;.87777';.8777778.2*/%*/%5%$5*%%*55%3**5%$/&/**3$&",
143 "**%$........$%**........->.->.->.,9778...,>978...,>b,7...,>>0,...7,b>,...879>,...8779,...87778..2*/%/***%2&5//5$*%&35&2$5**/3&%&",
144 "**%$........$%**........->.->.->.,9778...,>978...,>b,7...,>>0,...7,b>,...879>,...8779,...87778..2*/%/***%2&5//5$*%&35&2$5**/3&%&",
145 "%%$..........$%%........->^->^->..;78.....|^8.....|,7.....|,|.....7,|.....8^|.....87;.....888...2%5*&*5$2$2%**%2%*%$$2$2%5*%%%*$",
146 "%%$..........$%%........->^->^->..;78.....|^8.....|,7.....|,|.....7,|.....8^|.....87;.....888...2%5*&*5$2$2%**%2%*%$$2$2%5*%%%*$",
147 "........................^.^^.^^..................................................................2$5/5%..2$$222..$&&%%2..$*55*%.",
148 "........................^.^^.^^..................................................................2$5/5%..2$$222..$&&%%2..$*55*%.",
149 "...........->.....->.->.............>..............->>....->........->....->..................................................->",
150 "...........->.....->.->.............>..............->>....->........->....->..................................................->",
151 "..........^->....^->^->...->.->...->>>>..->...->..->^->..^->.......->....^^->.....->.->....->................................->.",
152 "..........^->....^->^->...->.->...->>>>..->...->..->^->..^->.......->....^^->.....->.->....->................................->.",
153 "..........^->....^->^->..->>>>>>.->^>^..^->..->..^^->>...->.......->......^^->...^^->>....^->...............................->..",
154 "..........^->....^->^->..->>>>>>.->^>^..^->..->..^^->>...->.......->......^^->...^^->>....^->...............................->..",
155 "..........^->....^^.^^..^^->^->.^^->>>>.^^..->....->>...^^.......^->.......^->...->>>>>>.->>>>>..........->>>>.............->...",
156 "..........^->....^^.^^..^^->^->.^^->>>>.^^..->....->>...^^.......^->.......^->...->>>>>>.->>>>>..........->>>>.............->...",
157 "..........^->............->>>>>>.^^^>^->...->....->^->->.........^->.......^->..^^^->>^.^^^->...........^^^^^.............->....",
158 "..........^->............->>>>>>.^^^>^->...->....->^->->.........^->.......^->..^^^->>^.^^^->...........^^^^^.............->....",
159 "..........^^............^^->^->...->>>>...->..->^->.^->..........^^->......->.....->^->...^->......->..............->....->.....",
160 "..........^^............^^->^->...->>>>...->..->^->.^->..........^^->......->.....->^->...^->......->..............->....->.....",
161 "...........->............^^.^^...^^^>....->..^->^^->>>............^^->....->.....^^.^^....^^......^->.............^->...->......",
162 "...........->............^^.^^...^^^>....->..^->^^->>>............^^->....->.....^^.^^....^^......^->.............^->...->......",
163 "..........^^.......................^....^^...^^..^^^^..............^^....^^.......................->..............^^....^.......",
164 "..........^^.......................^....^^...^^..^^^^..............^^....^^.......................->..............^^....^.......",
165 "...->>.....->.....->>>....->>>...->.^->..->>>>>....->>...->>>>>...->>>....->>>......................->............->......->>>..",
166 "...->>.....->.....->>>....->>>...->.^->..->>>>>....->>...->>>>>...->>>....->>>......................->............->......->>>..",
167 "..->^->...->>....->^^->..->^^->.^->.^->.^->^^^....->^...^^^^^->..->^^->..->^^->....................->............^^->....->^^->.",
168 "..->^->...->>....->^^->..->^^->.^->.^->.^->^^^....->^...^^^^^->..->^^->..->^^->....................->............^^->....->^^->.",
169 ".->.^->..^^->...^^..^->.^^..^->.^->.^->.^->>>>...->.........->..^->.^->.^->.^->....->......->.....->.....->>>>....^^->..^^..^->.",
170 ".->.^->..^^->...^^..^->.^^..^->.^->.^->.^->>>>...->.........->..^->.^->.^->.^->....->......->.....->.....->>>>....^^->..^^..^->.",
171 "^->.^->...^->......->>.....->>..^->>>>>.^^^^^->.^->>>>.....^->..^^->>>..^^->>>>...^->.....^->....->.....^^^^^......^^->.....->..",
172 "^->.^->...^->......->>.....->>..^->>>>>.^^^^^->.^->>>>.....^->..^^->>>..^^->>>>...^->.....^->....->.....^^^^^......^^->.....->..",
173 "^->.^->...^->.....->^.....^^^->.^^^^^->.....^->.^->^^->....->....->^^->..^^^^->...^^......^^....^^->................->.....->...",
174 "^->.^->...^->.....->^.....^^^->.^^^^^->.....^->.^->^^->....->....->^^->..^^^^->...^^......^^....^^->................->.....->...",
175 "^->.^->...^->....->......->.^->.....^->..->.^->.^->.^->...^->...^->.^->.....->.....->......->....^^->....->>>>.....->.....^^....",
176 "^->.^->...^->....->......->.^->.....^->..->.^->.^->.^->...^->...^->.^->.....->.....->......->....^^->....->>>>.....->.....^^....",
177 "^^->>>....->>>..^->>>>>.^^->>>......^->.^^->>>..^^->>>....^->...^^->>>....->>.....^->.....^->.....^^->..^^^^^.....->.......->...",
178 "^^->>>....->>>..^->>>>>.^^->>>......^->.^^->>>..^^->>>....^->...^^->>>....->>.....^->.....^->.....^^->..^^^^^.....->.......->...",
179 ".^^^^....^^^^...^^^^^^...^^^^.......^^...^^^^....^^^^.....^^.....^^^^....^^^......^^......->.......^^............^^.......^^....",
180 ".^^^^....^^^^...^^^^^^...^^^^.......^^...^^^^....^^^^.....^^.....^^^^....^^^......^^......->.......^^............^^.......^^....",
181 "..->>>.....->....->>>>....->>>...->>>>...->>>>>..->>>>>...->>>...->..->...->>>.....->>>..->..->..->......->...->.->..->...->>>..",
182 "..->>>.....->....->>>>....->>>...->>>>...->>>>>..->>>>>...->>>...->..->...->>>.....->>>..->..->..->......->...->.->..->...->>>..",
183 ".->^^->...->>>..^->^^->..->^^->.^->^^->.^->^^^..^->^^^...->^^->.^->.^->..^^->.....^^^->.^->.^->.^->.....^->>.->>^->>^->..->^^->.",
184 ".->^^->...->>>..^->^^->..->^^->.^->^^->.^->^^^..^->^^^...->^^->.^->.^->..^^->.....^^^->.^->.^->.^->.....^->>.->>^->>^->..->^^->.",
185 "^->.->>..->^^->.^->.^->.^->.^^..^->.^->.^->.....^->.....^->.^^..^->.^->...^->.......^->.^->.->..^->.....^->>>>>>^->->->.^->.^->.",
186 "^->.->>..->^^->.^->.^->.^->.^^..^->.^->.^->.....^->.....^->.^^..^->.^->...^->.......^->.^->.->..^->.....^->>>>>>^->->->.^->.^->.",
187 "^->^-^>.^->.^->.^->>>>..^->.....^->.^->.^->>>...^->>>...^->.->>.^->>>>>...^->.......^->.^->>>...^->.....^->^>^->^->^->>.^->.^->.",
188 "^->^-^>.^->.^->.^->>>>..^->.....^->.^->.^->>>...^->>>...^->.->>.^->>>>>...^->.......^->.^->>>...^->.....^->^>^->^->^->>.^->.^->.",
189 "^->^->>.^->>>>>.^->^^->.^->.....^->.^->.^->^....^->^....^->^^->.^->^^->...^->....->.^->.^->^->..^->.....^->^.^->^->^^->.^->.^->.",
190 "^->^->>.^->>>>>.^->^^->.^->.....^->.^->.^->^....^->^....^->^^->.^->^^->...^->....->.^->.^->^->..^->.....^->^.^->^->^^->.^->.^->.",
191 "^->^^^..^->.^->.^->.^->.^->..->.^->.^->.^->.....^->.....^->..->.^->.^->...^->...^->.^->.^->^^->.^->.....^->..^->^->.^->.^->.^->.",
192 "^->^^^..^->.^->.^->.^->.^->..->.^->.^->.^->.....^->.....^->..->.^->.^->...^->...^->.^->.^->^^->.^->.....^->..^->^->.^->.^->.^->.",
193 "^^->>>..^->.^->.^->>>>..^^->>>..^->>>>..^->>>>>.^->.....^^->>>..^->.^->...->>>..^^->>>..^->.^->.^->>>>>.^->..^->^->.^->.^^->>>..",
194 "^^->>>..^->.^->.^->>>>..^^->>>..^->>>>..^->>>>>.^->.....^^->>>..^->.^->...->>>..^^->>>..^->.^->.^->>>>>.^->..^->^->.^->.^^->>>..",
195 ".^^^^...^^..^^..^^^^^....^^^^...^^^^^...^^^^^^..^^.......^^^^...^^..^^...^^^^....^^^^...^^..^^..^^^^^^..^^...^^.^^..^^...^^^^...",
196 ".^^^^...^^..^^..^^^^^....^^^^...^^^^^...^^^^^^..^^.......^^^^...^^..^^...^^^^....^^^^...^^..^^..^^^^^^..^^...^^.^^..^^...^^^^...",
197 ".->>>>....->>>...->>>>....->>>...->>>>>..->..->..->..->..->...->.->..->..->..->..->>>>>..^>-....^>.......^->.......^............",
198 ".->>>>....->>>...->>>>....->>>...->>>>>..->..->..->..->..->...->.->..->..->..->..->>>>>..^>-....^>.......^->.......^............",
199 "^->^^->..->^^->.^->^^->..->^^->.^^^->...^->.^->.^->.^->.^->..^->^->.^->.^->.^->.^^^^^->..^>......^>........>......^->...........",
200 "^->^^->..->^^->.^->^^->..->^^->.^^^->...^->.^->.^->.^->.^->..^->^->.^->.^->.^->.^^^^^->..^>......^>........>......^->...........",
201 "^->.^->.^->.^->.^->.^->.^->.^^....^->...^->.^->.^->.^->.^->..^->^^->->..^->.^->.....->...^>.......^>.......>.....^-.^>..........",
202 "^->.^->.^->.^->.^->.^->.^->.^^....^->...^->.^->.^->.^->.^->..^->^^->->..^->.^->.....->...^>.......^>.......>.....^-.^>..........",
203 "^->>>>..^->.^->.^->>>>..^^->>>....^->...^->.^->.^->.^->.^->.>^->.^^->...^^->>>.....->....^>........^>......>....^-...^>.........",
204 "^->>>>..^->.^->.^->>>>..^^->>>....^->...^->.^->.^->.^->.^->.>^->.^^->...^^->>>.....->....^>........^>......>....^-...^>.........",
205 "^->^^...^->.^->.^->.^->..^^^^->...^->...^->.^->.^->.^->.^->>>>->..->->...^^->.....->.....^>.........^-.....>....................",
206 "^->^^...^->.^->.^->.^->..^^^^->...^->...^->.^->.^->.^->.^->>>>->..->->...^^->.....->.....^>.........^-.....>....................",
207 "^->.....^->.>>>.^->.^->..->.^->...^->...^->.^->.^^->>>..^->>^->>.->^^->...^->....->......^>..........^-....>....................",
208 "^->.....^->.>>>.^->.^->..->.^->...^->...^->.^->.^^->>>..^->>^->>.->^^->...^->....->......^>..........^-....>....................",
209 "^->.....^^->->..^->.^->.^^->>>....^->...^^->>>...^^->...^->.^^->^->.^->...^->...^->>>>>..^>-..........^..^->....................",
210 "^->.....^^->->..^->.^->.^^->>>....^->...^^->>>...^^->...^->.^^->^->.^->...^->...^->>>>>..^>-..........^..^->....................",
211 "^^.......^^^^->.^^..^^...^^^^.....^^.....^^^^.....^^....^^...^^.^^..^^....^^....^^^^^^..................................>>>>>>>>",
212 "^^.......^^^^->.^^..^^...^^^^.....^^.....^^^^.....^^....^^...^^.^^..^^....^^....^^^^^^..................................>>>>>>>>",
213 ".^>..............->..................->............->>...........->........->........->..->.......->>...........................",
214 ".^>..............->..................->............->>...........->........->........->..->.......->>...........................",
215 ".^>^............^->.................^->...........->^->.........^->.......^^........^^..^->......^^->...........................",
216 ".^>^............^->.................^->...........->^->.........^->.......^^........^^..^->......^^->...........................",
217 "..^-......->>>..^->.......->>>......^->...->>>...^->^^....->>>>.^->.......->>.......->>.^->..->...^->....->>.>>..->>>>....->>>..",
218 "..^-......->>>..^->.......->>>......^->...->>>...^->^^....->>>>.^->.......->>.......->>.^->..->...^->....->>.>>..->>>>....->>>..",
219 ".........^^^^->.^->>>>...->^^->...->>>>..->^^->..->>>....->^^->.^->>>>...^^->......^^->.^->.->....^->...^->>>>>>^->^^->..->^^->.",
220 ".........^^^^->.^->>>>...->^^->...->>>>..->^^->..->>>....->^^->.^->>>>...^^->......^^->.^->.->....^->...^->>>>>>^->^^->..->^^->.",
221 "..........->>>>.^->^^->.^->.^^...->^^->.^->>>>>.^^->....^->.^->.^->^^->...^->.......^->.^->>>.....^->...^->^>^->^->.^->.^->.^->.",
222 "..........->>>>.^->^^->.^->.^^...->^^->.^->>>>>.^^->....^->.^->.^->^^->...^->.......^->.^->>>.....^->...^->^>^->^->.^->.^->.^->.",
223 ".........->^^->.^->.^->.^->..->.^->.^->.^->^^^...^->....^^->>>>.^->.^->...^->....->.^->.^->^->....^->...^->^.^->^->.^->.^->.^->.",
224 ".........->^^->.^->.^->.^->..->.^->.^->.^->^^^...^->....^^->>>>.^->.^->...^->....->.^->.^->^->....^->...^->^.^->^->.^->.^->.^->.",
225 "........^^->>>>.^->>>>..^^->>>..^^->>>>.^^->>>...^->.....^^^^->.^->.^->...->>>..^->.^->.^->^^->...->>>..^->..^->^->.^->.^^->>>..",
226 "........^^->>>>.^->>>>..^^->>>..^^->>>>.^^->>>...^->.....^^^^->.^->.^->...->>>..^->.^->.^->^^->...->>>..^->..^->^->.^->.^^->>>..",
227 ".........^^^^^..^^^^^....^^^^....^^^^^...^^^^....^^.......->>>..^^..^^...^^^^...^^->>>..^^..^^...^^^^...^^...^^.^^..^^...^^^^...",
228 ".........^^^^^..^^^^^....^^^^....^^^^^...^^^^....^^.......->>>..^^..^^...^^^^...^^->>>..^^..^^...^^^^...^^...^^.^^..^^...^^^^...",
229 "..................................->........................................................->.....->.....->......->>.->........",
230 "..................................->........................................................->.....->.....->......->>.->........",
231 ".................................^->.......................................................->.....^->....^^->....->^->>....^>...",
232 ".................................^->.......................................................->.....^->....^^->....->^->>....^>...",
233 ".->>>>....->>>>..->>>>....->>>...->>>....->..->..->..->..->...->.->..->..->..->..->>>>>....->.....^->.....^->...^^.^^^....^-->..",
234 ".->>>>....->>>>..->>>>....->>>...->>>....->..->..->..->..->...->.->..->..->..->..->>>>>....->.....^->.....^->...^^.^^^....^-->..",
235 "^->^^->..->^^->.^->^^->..->^^...^^->....^->.^->.^->.^->.^->.>^->^^->->..^->.^->.^^^^->....->......^^......^^->...........^->^->.",
236 "^->^^->..->^^->.^->^^->..->^^...^^->....^->.^->.^->.^->.^->.>^->^^->->..^->.^->.^^^^->....->......^^......^^->...........^->^->.",
237 "^->.^->.^->.^->.^->.^^..^^->>>...^->....^->.^->.^->.^->.^->>>>->.^^->...^->.^->....->....^^->......->......->...........^->..^->",
238 "^->.^->.^->.^->.^->.^^..^^->>>...^->....^->.^->.^->.^->.^->>>>->.^^->...^->.^->....->....^^->......->......->...........^->..^->",
239 "^->>>>..^^->>>>.^->......^^^^->..^->.->.^->.^->.^^->>>..^->>^->>..->->..^^->>>>...->......^->.....^->.....^->...........^->..^->",
240 "^->>>>..^^->>>>.^->......^^^^->..^->.->.^->.^->.^^->>>..^->>^->>..->->..^^->>>>...->......^->.....^->.....^->...........^->..^->",
241 "^->^^....^^^^->.^->.......->>>...^^->>..^^->>>>..^^->...^->.^^->.->^^->..^^^^->..->>>>>...^^->....^->.....->............^------>",
242 "^->^^....^^^^->.^->.......->>>...^^->>..^^->>>>..^^->...^->.^^->.->^^->..^^^^->..->>>>>...^^->....^->.....->............^------>",
243 "^->.........^->.^^.......^^^^.....^^^....^^^^^....^^....^^...^^.^^..^^....->>>..^^^^^^.....^^.....^^.....^^.....................",
244 "^->.........^->.^^.......^^^^.....^^^....^^^^^....^^....^^...^^.^^..^^....->>>..^^^^^^.....^^.....^^.....^^.....................",
260 "................ "};
262 static struct ascii {
263 struct images *images;
265 ascii_ctrl_states state;
266 Uint32 color_stack[ASCII_CLR_STK_SZ];
267 int i_color; /* index onto stack */
268 Uint32 color; /* active color */
271 static Uint32 asciiDecodeColor(char clr)
274 case 'w': return White;
275 case 'B': return Black;
276 case 'r': return TextRed;
277 case 'g': return TextGreen;
278 case 'b': return TextBlue;
279 case 'y': return TextYellow;
280 case 'c': return TextCyan;
281 case 'm': return TextMagenta;
282 case 'G': return Gray;
284 warn("Color '%c' unknown\n", clr);
285 return ASCII_DEF_CLR;
289 static void asciiPushColor()
291 /* Check for overrun. */
292 if (array_sz(Ascii.color_stack) == Ascii.i_color) {
293 warn("Ascii color stack overrun\n");
297 /* Push the new color. */
298 Ascii.color_stack[Ascii.i_color] = Ascii.color;
302 static void asciiPopColor()
304 /* Check for underrun. */
305 if (0 == Ascii.i_color) {
306 warn("Ascii color stack already at bottom\n");
311 Ascii.color = Ascii.color_stack[Ascii.i_color];
315 static void asciiSetColor(char clr)
317 /* Check for a pop. */
326 /* current color, nop */
329 Ascii.color = asciiDecodeColor(clr);
334 static void asciiBlitColored16(SDL_Surface *src, SDL_Rect *srcrect,
335 SDL_Surface *dst, SDL_Rect *dstrect,
339 Uint16 *srcpix, *dstpix;
342 assert(dst->format->BitsPerPixel==16);
344 for (y=0; y<dstrect->h; y++) {
346 srcpix = (Uint16*)src->pixels
347 + (srcrect->y+y)*src->w
349 dstpix = (Uint16*)dst->pixels
350 + (dstrect->y+y)*dst->w
353 for (x=0; x<dstrect->w; x++) {
354 *dstpix = *srcpix&mask;
361 static void asciiBlitColored32(SDL_Surface *src, SDL_Rect *srcrect,
362 SDL_Surface *dst, SDL_Rect *dstrect,
366 Uint32 *srcpix, *dstpix;
369 assert(dst->format->BitsPerPixel==32);
371 for (y=0; y<dstrect->h; y++) {
373 srcpix = (Uint32*)src->pixels
374 + (srcrect->y+y)*src->w
376 dstpix = (Uint32*)dst->pixels
377 + (dstrect->y+y)*dst->w
380 for (x=0; x<dstrect->w; x++) {
381 *dstpix = *srcpix&mask;
388 static void asciiBlitColored(SDL_Surface *src, SDL_Rect *srcrect,
389 SDL_Surface *dst, SDL_Rect *dstrect,
393 if (src->format->BitsPerPixel!=dst->format->BitsPerPixel) {
395 "ERROR: %dx%d@%d surface not in destination format!\n",
396 src->w, src->h, src->format->BytesPerPixel);
401 assert(src->format->BitsPerPixel==dst->format->BitsPerPixel);
403 assert(dstrect->w==srcrect->w);
404 assert(dstrect->h==srcrect->h);
406 switch (dst->format->BitsPerPixel) {
408 asciiBlitColored16(src, srcrect, dst, dstrect, color);
411 asciiBlitColored32(src, srcrect, dst, dstrect, color);
414 err("asciiBlitColored: unsupported BitsPerPixel: %d\n",
415 dst->format->BitsPerPixel);
420 static void asciiPaintColored(unsigned char c, int x, int y,
421 SDL_Surface *surf, Uint32 color)
428 assert(Ascii.images);
440 /* fixme -- put these calcs in a table or something. Don't need to do
442 col = c % Ascii.images->cols;
443 row = c / Ascii.images->cols;
445 src.x = (col * ASCII_W) + Ascii.images->offx;
446 src.y = (row * ASCII_H) + Ascii.images->offy;
455 asciiBlitColored(Ascii.images->images, &src,
460 static void asciiPaintDefault(unsigned char c, int x, int y,
468 assert(Ascii.images);
473 /* fixme -- put these calcs in a table or something. Don't need to do
475 col = c % Ascii.images->cols;
476 row = c / Ascii.images->cols;
478 src.x = (col * ASCII_W) + Ascii.images->offx;
479 src.y = (row * ASCII_H) + Ascii.images->offy;
488 SDL_BlitSurface(Ascii.images->images, &src, surf, &dest);
492 * Load the emergency ASCII image set from XPM.
494 * @returns The images struct ready for use, our 0 if there was some kind of
495 * error in loading it.
497 static struct images *ascii_load_fixed_charset(void)
499 struct images *images;
501 images = new struct images;
503 memset(images, 0, sizeof(*images));
512 images->images = IMG_ReadXPMFromArray((char**)charset_xpm);
513 if (!images->images) {
514 err("IMG_ReadXPMFromArray() failed: '%s'\n", SDL_GetError() );
518 if (!images_convert2display(images)) {
527 char *fname = cfg_get("ascii-image-filename");
529 /* This lib might be unitialized twice: once early in startup so that
530 * error messages can be displayed, and again later after the
531 * configuration file has been found and parsed. */
533 images_del(Ascii.images);
538 Ascii.images = images_new(0, 8, 16, 9, 16, 0, 0, fname);
540 Ascii.images = ascii_load_fixed_charset();
542 assert(Ascii.images);
544 Ascii.state = ASCII_STATE_DEF;
546 Ascii.color = ASCII_DEF_CLR;
550 int asciiPaint(char c, int x, int y, SDL_Surface * surf)
554 switch (Ascii.state) {
556 case ASCII_STATE_CLR:
558 Ascii.state = ('+'==c?ASCII_STATE_CLRPUSH:ASCII_STATE_DEF);
561 case ASCII_STATE_CLRPUSH:
563 Ascii.state = ASCII_STATE_DEF;
566 case ASCII_STATE_ESC:
568 Ascii.state = ASCII_STATE_CLR;
572 case ASCII_STATE_DEF:
575 Ascii.state = ASCII_STATE_ESC;
577 if (ASCII_DEF_CLR==Ascii.color) {
578 asciiPaintDefault(c, x, y, surf);
580 asciiPaintColored(c, x, y, surf, Ascii.color);
589 int asciiStrlen(char *s)
591 /* Start with the current state. */
592 enum ascii_ctrl_states state = Ascii.state;
598 case ASCII_STATE_CLR:
599 state = ('+'==c?ASCII_STATE_CLRPUSH:ASCII_STATE_DEF);
602 case ASCII_STATE_CLRPUSH:
603 state = ASCII_STATE_DEF;
606 case ASCII_STATE_ESC:
608 state = ASCII_STATE_CLR;
612 case ASCII_STATE_DEF:
615 state = ASCII_STATE_ESC;