lcd-m6sp.c: remove \r
[kugel-rb.git] / apps / plugins / doom / i_video.c
blobe7f8e9014b9699995b691dfd2eddb6710e22c2d2
1 /* Emacs style mode select -*- C++ -*-
2 *-----------------------------------------------------------------------------
4 * $Id$
6 * Copyright (C) 1993-1996 by id Software, Inc.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * $Log: i_video.c,v $
19 * Revision 1.26 2006-12-13 04:44:17 kkurbjun
20 * Dehacked and BEX support for Doom - currently only supports a DEHACKED file in a WAD (not as a standalone file yet).
22 * Revision 1.25 2006-10-26 13:38:04 barrywardell
23 * Allow the Sansa e200 UI simulator to be built. Thanks to Andre Smith for the nice image of the Sansa. Lots more to be done including testing and tweaking the keymaps and modifying the plugins for the Sansa's 176x220 LCD.
25 * Revision 1.24 2006-09-05 00:23:06 barrywardell
26 * Fix not being able to exit Doom on the H10.
28 * Revision 1.23 2006-08-10 18:34:43 amiconn
29 * Correct calculation of necessary buffer size to give maximum number of shades on iPod Mini.
31 * Revision 1.22 2006-08-07 02:44:18 amiconn
32 * Use striped buffering for grayscale targets to make the buffer fit on iPod g3/g4. Also slightly faster (at least on H1x0) with the buffer in IRAM.
34 * Revision 1.21 2006-08-07 01:57:29 amiconn
35 * Fix red iPod g3 build.
37 * Revision 1.20 2006-08-07 01:46:41 amiconn
38 * Grayscale library ported to the grayscale iPods, first version. Added C reference versions of gray_update_rect() for both horizontal and vertical pixel packing. gray_update_rect() and gray_ub_gray_bitmap_part() not yet assembler optimised. Grayscale screendump doesn't work yet. * Fixed button assignments for iPod in grayscale.c
40 * Revision 1.19 2006-08-03 20:17:22 bagder
41 * Barry Wardell's keymappings for H10
43 * Revision 1.18 2006-08-02 00:21:59 amiconn
44 * Grayscale library: LCD linearisation and gamma correction.
46 * Revision 1.17 2006-04-22 03:48:15 kkurbjun
47 * Better video update, add options to startup menu, change default screensize
49 * Revision 1.16 2006-04-20 19:39:56 kkurbjun
50 * Optimizations for doom: coldfire asm drawspan routine = not much, fixed point multiply changes = not much, H300 asm lcd update = some, IRAM sound updates and simplifications = more
52 * Revision 1.15 2006-04-16 23:14:04 kkurbjun
53 * Fix run so that it stays enabled across level loads. Removed some unused code and added some back in for hopeful future use.
55 * Revision 1.14 2006-04-15 22:08:36 kkurbjun
56 * Slight code cleanups, fixed sound parameter - now it saves. Old configurations will be reset.
58 * Revision 1.13 2006-04-06 21:31:49 kkurbjun
59 * Scaling code fixed by clamping down the width to a max of SCREENWIDTH. Removed some #ifdefs for glprboom
61 * Revision 1.12 2006-04-05 06:37:37 kkurbjun
62 * Fix finale text and try and prevent some data corruption due to the scaling code. Also allows the non-standard GP32 mods to work with some bounds checking. More comments are in v_video.c
64 * Revision 1.11 2006-04-04 19:39:31 amiconn
65 * Doom on H1x0: Don't waste memory, the grayscale lib doesn't need that much, but properly tell the lib how much memory it may use.
67 * Revision 1.10 2006-04-04 12:00:53 dave
68 * iPod: Make the hold switch bring up the in-game menu.
70 * Revision 1.9 2006-04-03 20:03:02 kkurbjun
71 * Updates doom menu w/ new graphics, now requires rockdoom.wad: http://alamode.mines.edu/~kkurbjun/rockdoom.wad
73 * Revision 1.8 2006-04-03 17:11:42 kkurbjun
74 * Finishing touches
76 * Revision 1.7 2006-04-03 16:30:12 kkurbjun
77 * Fix #if
79 * Revision 1.5 2006-04-03 08:51:08 bger
80 * Patch #4864 by Jonathan Gordon: text editor plugin, with some changes by me.
81 * Also correct a var clash between the rockbox's gui api and doom plugin
83 * Revision 1.4 2006-04-02 20:45:24 kkurbjun
84 * Properly ifdef H300 video code, fix commented line handling rockbox volume
86 * Revision 1.3 2006-04-02 01:52:44 kkurbjun
87 * Update adds prboom's high resolution support, also makes the scaling for
88 * platforms w/ resolution less then 320x200 much nicer. IDoom's lookup table
89 * code has been removed. Also fixed a pallete bug. Some graphic errors are
90 * present in menu and status bar. Also updates some headers and output
91 * formatting.
93 * Revision 1.2 2006-03-28 17:20:49 christian
94 * added good (tm) button mappings for x5, and added ifdef for HAS_BUTTON_HOLD
96 * Revision 1.1 2006-03-28 15:44:01 dave
97 * Patch #2969 - Doom! Currently only working on the H300.
100 * DESCRIPTION:
101 * DOOM graphics and buttons. H300 Port by Karl Kurbjun
102 * H100 Port by Dave Chapman, Karl Kurbjun and Jens Arnold
103 * IPOD port by Dave Chapman and Paul Louden
104 * Additional work by Thom Johansen
106 *-----------------------------------------------------------------------------
109 #include "doomstat.h"
110 #include "i_system.h"
111 #include "v_video.h"
112 #include "m_argv.h"
113 #include "d_main.h"
115 #include "doomdef.h"
117 #include "rockmacros.h"
119 #ifndef HAVE_LCD_COLOR
120 #include "lib/grey.h"
121 GREY_INFO_STRUCT_IRAM
122 static unsigned char greybuffer[LCD_WIDTH] IBSS_ATTR; /* off screen buffer */
123 static unsigned char *gbuf;
124 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
125 #define GREYBUFSIZE (((LCD_WIDTH+7)/8)*LCD_HEIGHT*16+200)
126 #else
127 #define GREYBUFSIZE (LCD_WIDTH*((LCD_HEIGHT+7)/8)*16+200)
128 #endif
129 #endif
131 #if defined(CPU_COLDFIRE)
132 static char fastscreen[LCD_WIDTH*LCD_HEIGHT] IBSS_ATTR;
133 #endif
135 static fb_data palette[256] IBSS_ATTR;
136 static fb_data *paldata=NULL;
139 // I_ShutdownGraphics
141 void I_ShutdownGraphics(void)
143 #if defined(HAVE_LCD_MODES)
144 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
145 rb->lcd_set_mode(LCD_MODE_RGB565);
146 #endif
147 #endif
149 #ifndef HAVE_LCD_COLOR
150 grey_release();
151 #endif
152 noprintf=0;
156 // I_StartTic
159 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
160 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
161 //#define DOOMBUTTON_SCROLLWHEEL
162 #define DOOMBUTTON_UP BUTTON_MENU
163 #define DOOMBUTTON_WEAPON BUTTON_SELECT
164 #define DOOMBUTTON_LEFT BUTTON_LEFT
165 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
166 #define DOOMBUTTON_SHOOT BUTTON_PLAY
167 #define DOOMBUTTON_ENTER BUTTON_SELECT
168 #define DOOMBUTTON_OPEN BUTTON_MENU
169 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
170 #define DOOMBUTTON_UP BUTTON_UP
171 #define DOOMBUTTON_DOWN BUTTON_DOWN
172 #define DOOMBUTTON_LEFT BUTTON_LEFT
173 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
174 #define DOOMBUTTON_SHOOT BUTTON_SELECT
175 #define DOOMBUTTON_OPEN BUTTON_PLAY
176 #define DOOMBUTTON_ESC BUTTON_POWER
177 #define DOOMBUTTON_ENTER BUTTON_SELECT
178 #define DOOMBUTTON_WEAPON BUTTON_REC
179 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
180 #define DOOMBUTTON_UP BUTTON_SCROLL_UP
181 #define DOOMBUTTON_DOWN BUTTON_SCROLL_DOWN
182 #define DOOMBUTTON_LEFT BUTTON_LEFT
183 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
184 #define DOOMBUTTON_SHOOT BUTTON_REW
185 #define DOOMBUTTON_OPEN BUTTON_PLAY
186 #define DOOMBUTTON_ESC BUTTON_POWER
187 #define DOOMBUTTON_ENTER BUTTON_REW
188 #define DOOMBUTTON_WEAPON BUTTON_FF
189 #elif CONFIG_KEYPAD == SANSA_E200_PAD
190 #define DOOMBUTTON_SCROLLWHEEL
191 #define DOOMBUTTON_SCROLLWHEEL_CC BUTTON_SCROLL_BACK
192 #define DOOMBUTTON_SCROLLWHEEL_CW BUTTON_SCROLL_FWD
193 #define DOOMBUTTON_UP BUTTON_UP
194 #define DOOMBUTTON_DOWN BUTTON_DOWN
195 #define DOOMBUTTON_LEFT BUTTON_LEFT
196 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
197 #define DOOMBUTTON_SHOOT BUTTON_SELECT
198 #define DOOMBUTTON_OPEN BUTTON_REC
199 #define DOOMBUTTON_ESC BUTTON_POWER
200 #define DOOMBUTTON_ENTER BUTTON_SELECT
201 #define DOOMBUTTON_WEAPON DOOMBUTTON_SCROLLWHEEL_CW
202 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
203 #define DOOMBUTTON_SCROLLWHEEL
204 #define DOOMBUTTON_SCROLLWHEEL_CC BUTTON_SCROLL_BACK
205 #define DOOMBUTTON_SCROLLWHEEL_CW BUTTON_SCROLL_FWD
206 #define DOOMBUTTON_UP BUTTON_UP
207 #define DOOMBUTTON_DOWN BUTTON_DOWN
208 #define DOOMBUTTON_LEFT BUTTON_LEFT
209 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
210 #define DOOMBUTTON_SHOOT BUTTON_SELECT
211 #define DOOMBUTTON_OPEN BUTTON_POWER
212 #define DOOMBUTTON_ESC BUTTON_HOME
213 #define DOOMBUTTON_ENTER BUTTON_SELECT
214 #define DOOMBUTTON_WEAPON DOOMBUTTON_SCROLLWHEEL_CW
215 #elif CONFIG_KEYPAD == SANSA_C200_PAD
216 #define DOOMBUTTON_UP BUTTON_UP
217 #define DOOMBUTTON_DOWN BUTTON_DOWN
218 #define DOOMBUTTON_LEFT BUTTON_LEFT
219 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
220 #define DOOMBUTTON_SHOOT BUTTON_SELECT
221 #define DOOMBUTTON_OPEN BUTTON_REC
222 #define DOOMBUTTON_ESC BUTTON_POWER
223 #define DOOMBUTTON_ENTER BUTTON_SELECT
224 #define DOOMBUTTON_WEAPON BUTTON_VOL_UP
225 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
226 #define DOOMBUTTON_UP BUTTON_UP
227 #define DOOMBUTTON_DOWN BUTTON_DOWN
228 #define DOOMBUTTON_LEFT BUTTON_LEFT
229 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
230 #define DOOMBUTTON_SHOOT BUTTON_SELECT
231 #define DOOMBUTTON_OPEN BUTTON_HOME
232 #define DOOMBUTTON_ESC BUTTON_POWER
233 #define DOOMBUTTON_ENTER BUTTON_SELECT
234 #define DOOMBUTTON_WEAPON BUTTON_VOL_UP
235 #elif CONFIG_KEYPAD == GIGABEAT_PAD
236 #define DOOMBUTTON_UP BUTTON_UP
237 #define DOOMBUTTON_DOWN BUTTON_DOWN
238 #define DOOMBUTTON_LEFT BUTTON_LEFT
239 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
240 #define DOOMBUTTON_SHOOT BUTTON_A
241 #define DOOMBUTTON_OPEN BUTTON_MENU
242 #define DOOMBUTTON_ESC BUTTON_POWER
243 #define DOOMBUTTON_ENTER BUTTON_SELECT
244 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
245 #define DOOMBUTTON_MAP BUTTON_VOL_UP
246 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
247 #define DOOMBUTTON_UP BUTTON_UP
248 #define DOOMBUTTON_DOWN BUTTON_DOWN
249 #define DOOMBUTTON_LEFT BUTTON_LEFT
250 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
251 #define DOOMBUTTON_SHOOT BUTTON_PLAY
252 #define DOOMBUTTON_OPEN BUTTON_MENU
253 #define DOOMBUTTON_ESC BUTTON_POWER
254 #define DOOMBUTTON_ENTER BUTTON_SELECT
255 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
256 #define DOOMBUTTON_MAP BUTTON_VOL_UP
257 #elif CONFIG_KEYPAD == MROBE500_PAD
258 #define DOOMBUTTON_ESC BUTTON_POWER
259 #define DOOMBUTTON_UP BUTTON_RC_PLAY
260 #define DOOMBUTTON_DOWN BUTTON_RC_DOWN
261 #define DOOMBUTTON_LEFT BUTTON_RC_REW
262 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
263 #define DOOMBUTTON_OPEN BUTTON_RC_VOL_DOWN
264 #define DOOMBUTTON_SHOOT BUTTON_RC_VOL_UP
265 #define DOOMBUTTON_ENTER BUTTON_RC_MODE
266 #define DOOMBUTTON_WEAPON BUTTON_RC_HEART
267 #elif CONFIG_KEYPAD == IRIVER_H100_PAD || \
268 CONFIG_KEYPAD == IRIVER_H300_PAD
269 #define DOOMBUTTON_UP BUTTON_UP
270 #define DOOMBUTTON_DOWN BUTTON_DOWN
271 #define DOOMBUTTON_LEFT BUTTON_LEFT
272 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
273 #define DOOMBUTTON_SHOOT BUTTON_REC
274 #define DOOMBUTTON_OPEN BUTTON_MODE
275 #define DOOMBUTTON_ESC BUTTON_OFF
276 #define DOOMBUTTON_ENTER BUTTON_SELECT
277 #define DOOMBUTTON_WEAPON BUTTON_ON
278 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
279 #define DOOMBUTTON_ESC BUTTON_RC_REC
280 #define DOOMBUTTON_UP BUTTON_RC_VOL_UP
281 #define DOOMBUTTON_DOWN BUTTON_RC_VOL_DOWN
282 #define DOOMBUTTON_LEFT BUTTON_RC_REW
283 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
284 #define DOOMBUTTON_OPEN BUTTON_RC_PLAY
285 #define DOOMBUTTON_SHOOT BUTTON_RC_MODE
286 #define DOOMBUTTON_ENTER BUTTON_RC_PLAY
287 #define DOOMBUTTON_WEAPON BUTTON_RC_MENU
288 #elif CONFIG_KEYPAD == COWON_D2_PAD
289 #define DOOMBUTTON_ESC BUTTON_POWER
290 #define DOOMBUTTON_SHOOT BUTTON_PLUS
291 #define DOOMBUTTON_WEAPON BUTTON_MINUS
292 #define DOOMBUTTON_MAP BUTTON_MENU
293 #elif CONFIG_KEYPAD == MROBE100_PAD
294 #define DOOMBUTTON_UP BUTTON_UP
295 #define DOOMBUTTON_DOWN BUTTON_DOWN
296 #define DOOMBUTTON_LEFT BUTTON_LEFT
297 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
298 #define DOOMBUTTON_SHOOT BUTTON_SELECT
299 #define DOOMBUTTON_OPEN BUTTON_PLAY
300 #define DOOMBUTTON_ESC BUTTON_POWER
301 #define DOOMBUTTON_ENTER BUTTON_MENU
302 #define DOOMBUTTON_WEAPON BUTTON_DISPLAY
303 #elif CONFIG_KEYPAD == IAUDIO67_PAD
304 #define DOOMBUTTON_ESC BUTTON_POWER
305 #define DOOMBUTTON_UP BUTTON_STOP
306 #define DOOMBUTTON_DOWN BUTTON_PLAY
307 #define DOOMBUTTON_LEFT BUTTON_LEFT
308 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
309 #define DOOMBUTTON_SHOOT BUTTON_VOLUP
310 #define DOOMBUTTON_OPEN BUTTON_VOLDOWN
311 #define DOOMBUTTON_ENTER BUTTON_MENU
312 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
313 #define DOOMBUTTON_UP BUTTON_UP
314 #define DOOMBUTTON_DOWN BUTTON_DOWN
315 #define DOOMBUTTON_LEFT BUTTON_LEFT
316 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
317 #define DOOMBUTTON_SHOOT BUTTON_SELECT
318 #define DOOMBUTTON_OPEN BUTTON_PLAY
319 #define DOOMBUTTON_ESC BUTTON_BACK
320 #define DOOMBUTTON_ENTER BUTTON_PLAY
321 #define DOOMBUTTON_WEAPON BUTTON_MENU
322 #define DOOMBUTTON_MAP BUTTON_CUSTOM
323 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
324 #define DOOMBUTTON_UP BUTTON_UP
325 #define DOOMBUTTON_DOWN BUTTON_DOWN
326 #define DOOMBUTTON_LEFT BUTTON_LEFT
327 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
328 #define DOOMBUTTON_SHOOT BUTTON_PLAYLIST
329 #define DOOMBUTTON_OPEN BUTTON_MENU
330 #define DOOMBUTTON_ESC BUTTON_POWER
331 #define DOOMBUTTON_ENTER BUTTON_VIEW
332 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
333 #define DOOMBUTTON_MAP BUTTON_VOL_UP
334 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
335 #define DOOMBUTTON_UP BUTTON_UP
336 #define DOOMBUTTON_DOWN BUTTON_DOWN
337 #define DOOMBUTTON_LEFT BUTTON_PREV
338 #define DOOMBUTTON_RIGHT BUTTON_NEXT
339 #define DOOMBUTTON_SHOOT BUTTON_RIGHT
340 #define DOOMBUTTON_OPEN BUTTON_MENU
341 #define DOOMBUTTON_ESC BUTTON_POWER
342 #define DOOMBUTTON_ENTER BUTTON_LEFT
343 #define DOOMBUTTON_WEAPON BUTOTN_VOL_DOWN
344 #define DOOMBUTTON_MAP BUTTON_VOL_UP
345 #elif CONFIG_KEYPAD == ONDAVX747_PAD
346 #define DOOMBUTTON_ESC BUTTON_POWER
347 #define DOOMBUTTON_SHOOT BUTTON_VOL_UP
348 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
349 #define DOOMBUTTON_MAP BUTTON_MENU
350 #elif CONFIG_KEYPAD == ONDAVX777_PAD
351 #define DOOMBUTTON_ESC BUTTON_POWER
352 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
353 #define DOOMBUTTON_UP BUTTON_UP
354 #define DOOMBUTTON_DOWN BUTTON_DOWN
355 #define DOOMBUTTON_LEFT BUTTON_LEFT
356 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
357 #define DOOMBUTTON_SHOOT BUTTON_PLAY
358 #define DOOMBUTTON_OPEN (BUTTON_PLAY|BUTTON_LEFT)
359 #define DOOMBUTTON_ESC BUTTON_REC
360 #define DOOMBUTTON_ENTER (BUTTON_PLAY|BUTTON_RIGHT)
361 #define DOOMBUTTON_WEAPON (BUTTON_PLAY|BUTTON_UP)
362 #define DOOMBUTTON_MAP (BUTTON_PLAY|BUTTON_DOWN)
363 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
364 #define DOOMBUTTON_UP BUTTON_OK
365 #define DOOMBUTTON_DOWN BUTTON_CANCEL
366 #define DOOMBUTTON_LEFT BUTTON_PREV
367 #define DOOMBUTTON_RIGHT BUTTON_NEXT
368 #define DOOMBUTTON_SHOOT BUTTON_MENU
369 #define DOOMBUTTON_OPEN BUTTON_OK
370 #define DOOMBUTTON_ESC BUTTON_REC
371 #define DOOMBUTTON_ENTER BUTTON_POWER
372 #define DOOMBUTTON_WEAPON BUTTON_PLAY
373 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
374 #define DOOMBUTTON_UP BUTTON_PREV
375 #define DOOMBUTTON_DOWN BUTTON_NEXT
376 #define DOOMBUTTON_LEFT BUTTON_VOL_DOWN
377 #define DOOMBUTTON_RIGHT BUTTON_VOL_UP
378 #define DOOMBUTTON_SHOOT BUTTON_SELECT
379 #define DOOMBUTTON_OPEN (BUTTON_SELECT|BUTTON_PLAY)
380 #define DOOMBUTTON_ESC BUTTON_REC
381 #define DOOMBUTTON_ENTER BUTTON_PLAY
382 #define DOOMBUTTON_WEAPON (BUTTON_PLAY|BUTTON_REPEAT)
383 #else
384 #error Keymap not defined!
385 #endif
387 #ifdef HAVE_TOUCHSCREEN
388 #ifndef DOOMBUTTON_UP
389 #define DOOMBUTTON_UP BUTTON_TOPMIDDLE
390 #endif
391 #ifndef DOOMBUTTON_DOWN
392 #define DOOMBUTTON_DOWN BUTTON_BOTTOMMIDDLE
393 #endif
394 #ifndef DOOMBUTTON_LEFT
395 #define DOOMBUTTON_LEFT BUTTON_MIDLEFT
396 #endif
397 #ifndef DOOMBUTTON_RIGHT
398 #define DOOMBUTTON_RIGHT BUTTON_MIDRIGHT
399 #endif
400 #ifndef DOOMBUTTON_SHOOT
401 #define DOOMBUTTON_SHOOT BUTTON_BOTTOMRIGHT
402 #endif
403 #ifndef DOOMBUTTON_OPEN
404 #define DOOMBUTTON_OPEN BUTTON_TOPRIGHT
405 #endif
406 #ifndef DOOMBUTTON_ESC
407 #define DOOMBUTTON_ESC BUTTON_TOPLEFT
408 #endif
409 #ifndef DOOMBUTTON_ENTER
410 #define DOOMBUTTON_ENTER BUTTON_CENTER
411 #endif
412 #ifndef DOOMBUTTON_WEAPON
413 #define DOOMBUTTON_WEAPON BUTTON_BOTTOMLEFT
414 #endif
415 #endif
417 #ifdef DOOMBUTTON_SCROLLWHEEL
418 /* Scrollwheel events are posted directly and not polled by the button
419 driver - synthesize polling */
420 static inline unsigned int read_scroll_wheel(void)
422 unsigned int buttons = BUTTON_NONE;
423 unsigned int btn;
425 /* Empty out the button queue and see if any scrollwheel events were
426 posted */
429 btn = rb->button_get_w_tmo(0);
430 buttons |= btn;
432 while (btn != BUTTON_NONE);
434 return buttons & (DOOMBUTTON_SCROLLWHEEL_CC | DOOMBUTTON_SCROLLWHEEL_CW);
436 #endif
438 inline void getkey()
440 event_t event;
441 /* Same button handling as rockboy */
442 static unsigned int oldbuttonstate IDATA_ATTR = 0;
444 unsigned int released, pressed, newbuttonstate;
446 #ifdef HAS_BUTTON_HOLD
447 static unsigned int holdbutton IDATA_ATTR=0;
448 static bool hswitch IDATA_ATTR=0;
449 if (rb->button_hold()&~holdbutton)
451 if(hswitch==0)
453 event.type = ev_keydown;
454 hswitch=1;
456 else
458 event.type = ev_keyup;
459 hswitch=0;
461 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
462 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
463 /* Bring up the menu */
464 event.data1=KEY_ESCAPE;
465 #else
466 /* Enable run */
467 event.data1=KEY_CAPSLOCK;
468 #endif
469 D_PostEvent(&event);
471 holdbutton=rb->button_hold();
472 #endif
474 newbuttonstate = rb->button_status();
475 #ifdef DOOMBUTTON_SCROLLWHEEL
476 newbuttonstate |= read_scroll_wheel();
477 #endif
479 if(newbuttonstate==oldbuttonstate) /* Don't continue, nothing left to do */
480 return;
481 released = ~newbuttonstate & oldbuttonstate;
482 pressed = newbuttonstate & ~oldbuttonstate;
483 oldbuttonstate = newbuttonstate;
484 if(released)
486 event.type = ev_keyup;
487 if(released & DOOMBUTTON_LEFT)
489 event.data1=KEY_LEFTARROW;
490 D_PostEvent(&event);
492 if(released & DOOMBUTTON_RIGHT)
494 event.data1=KEY_RIGHTARROW;
495 D_PostEvent(&event);
497 #ifdef DOOMBUTTON_DOWN
498 if(released & DOOMBUTTON_DOWN)
500 event.data1=KEY_DOWNARROW;
501 D_PostEvent(&event);
503 #endif
504 if(released & DOOMBUTTON_UP)
506 event.data1=KEY_UPARROW;
507 D_PostEvent(&event);
509 if(released & DOOMBUTTON_SHOOT)
511 event.data1=KEY_RCTRL;
512 D_PostEvent(&event);
514 if(released & DOOMBUTTON_OPEN)
516 event.data1=' ';
517 D_PostEvent(&event);
519 #ifdef DOOMBUTTON_ESC
520 if(released & DOOMBUTTON_ESC)
522 event.data1=KEY_ESCAPE;
523 D_PostEvent(&event);
525 #endif
526 if(released & DOOMBUTTON_ENTER)
528 event.data1=KEY_ENTER;
529 D_PostEvent(&event);
531 #ifdef DOOMBUTTON_WEAPON
532 if(released & DOOMBUTTON_WEAPON)
534 event.data1 ='w';
535 D_PostEvent(&event);
537 #endif
538 #ifdef DOOMBUTTON_MAP
539 if(released & DOOMBUTTON_MAP)
541 event.data1 =KEY_TAB;
542 D_PostEvent(&event);
544 #endif
546 if(pressed)
548 event.type = ev_keydown;
549 if(pressed & DOOMBUTTON_LEFT)
551 event.data1=KEY_LEFTARROW;
552 D_PostEvent(&event);
554 if(pressed & DOOMBUTTON_RIGHT)
556 event.data1=KEY_RIGHTARROW;
557 D_PostEvent(&event);
559 #ifdef DOOMBUTTON_DOWN
560 if(pressed & DOOMBUTTON_DOWN)
562 event.data1=KEY_DOWNARROW;
563 D_PostEvent(&event);
565 #endif
566 if(pressed & DOOMBUTTON_UP)
568 event.data1=KEY_UPARROW;
569 D_PostEvent(&event);
571 if(pressed & DOOMBUTTON_SHOOT)
573 event.data1=KEY_RCTRL;
574 D_PostEvent(&event);
576 if(pressed & DOOMBUTTON_OPEN)
578 event.data1=' ';
579 D_PostEvent(&event);
581 #ifdef DOOMBUTTON_ESC
582 if(pressed & DOOMBUTTON_ESC)
584 event.data1=KEY_ESCAPE;
585 D_PostEvent(&event);
587 #endif
588 #ifdef DOOMBUTTON_ENTER
589 if(pressed & DOOMBUTTON_ENTER)
591 event.data1=KEY_ENTER;
592 D_PostEvent(&event);
594 #endif
595 #ifdef DOOMBUTTON_WEAPON
596 if(pressed & DOOMBUTTON_WEAPON)
598 event.data1='w';
599 D_PostEvent(&event);
601 #endif
602 #ifdef DOOMBUTTON_MAP
603 if(pressed & DOOMBUTTON_MAP)
605 event.data1 =KEY_TAB;
606 D_PostEvent(&event);
608 #endif
612 inline void I_StartTic (void)
614 getkey();
618 ///////////////////////////////////////////////////////////
619 // Palette stuff.
621 static void I_UploadNewPalette(int pal)
623 // This is used to replace the current 256 colour cmap with a new one
624 // Used by 256 colour PseudoColor modes
625 static int cachedgamma;
626 static size_t num_pals;
628 if ((paldata == NULL) || (cachedgamma != usegamma)) {
629 int lump = W_GetNumForName("PLAYPAL");
630 const byte *pall = W_CacheLumpNum(lump);
631 register const byte *const gtable = gammatable[cachedgamma = usegamma];
632 register int i;
634 num_pals = W_LumpLength(lump) / (3*256);
635 num_pals *= 256;
637 if (!paldata) {
638 // First call - allocate and prepare colour array
639 paldata = malloc(sizeof(*paldata)*num_pals);
642 // set the colormap entries
643 for (i=0 ; (size_t)i<num_pals ; i++) {
644 int r = gtable[pall[0]];
645 int g = gtable[pall[1]];
646 int b = gtable[pall[2]];
647 pall+=3;
648 #ifndef HAVE_LCD_COLOR
649 paldata[i]=(3*r+6*g+b)/10;
650 #else
651 paldata[i] = LCD_RGBPACK(r,g,b);
652 #endif
655 W_UnlockLumpNum(lump);
656 num_pals/=256;
659 #ifdef RANGECHECK
660 if ((size_t)pal >= num_pals)
661 I_Error("I_UploadNewPalette: Palette number out of range (%d>=%d)",
662 pal, num_pals);
663 #endif
665 memcpy(palette,paldata+256*pal,256*sizeof(fb_data));
667 #if defined(HAVE_LCD_MODES)
668 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
669 rb->lcd_pal256_update_pal(paldata+256*pal);
670 #endif
671 #endif
675 // I_FinishUpdate
678 void I_FinishUpdate (void)
680 int count;
681 byte *src = d_screens[0];
683 #if (CONFIG_LCD == LCD_H300) && !defined(SIMULATOR)
684 count = SCREENWIDTH*SCREENHEIGHT;
686 /* ASM screen update (drops ~300 tics) */
687 asm volatile (
688 "move.w #33, (%[LCD]) \n" /* Setup the LCD controller */
689 "nop \n"
690 "clr.w (%[LCD2]) \n"
691 "nop \n"
692 "move.w #34, (%[LCD]) \n" /* End LCD controller setup */
693 "clr.l %%d1 \n"
694 ".loop: \n"
695 "move.l (%[scrp])+, %%d0 \n"
696 "swap.w %%d0 \n"
697 "move.w %%d0, %%d1 \n"
698 "lsr.l #8,%%d1 \n"
699 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
700 "move.b %%d0,%%d1 \n"
701 "swap.w %%d0 \n"
702 "nop \n"
703 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
704 "move.w %%d0, %%d1 \n"
705 "lsr.l #8,%%d1 \n"
706 "nop \n"
707 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
708 "move.b %%d0,%%d1 \n"
709 "nop \n"
710 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
711 "subq.l #4,%[cnt] \n"
712 "bne.b .loop \n"
713 : /* outputs */
714 [scrp]"+a"(src),
715 [cnt] "+d"(count)
716 : /* inputs */
717 [pal] "a" (palette),
718 [LCD] "a" (0xf0000000),
719 [LCD2]"a" (0xf0000002)
720 : /* clobbers */
721 "d0", "d1"
723 #elif (CONFIG_LCD == LCD_X5) && !defined(SIMULATOR) \
724 && defined(CPU_COLDFIRE) /* protect from using it on e200 (sic!) */
725 count = SCREENWIDTH*SCREENHEIGHT;
727 /* ASM screen update (drops ~230 tics) */
728 asm volatile (
729 "clr.w (%[LCD]) \n" /* Setup the LCD controller */
730 "move.w #(33<<1), (%[LCD]) \n"
731 "clr.w (%[LCD2]) \n"
732 "clr.w (%[LCD2]) \n"
733 "clr.w (%[LCD]) \n" /* End LCD controller setup */
734 "move.w #(34<<1), (%[LCD]) \n"
735 "clr.l %%d1 \n"
736 ".loop: \n"
737 "move.l (%[scrp])+, %%d0 \n"
738 "swap.w %%d0 \n"
739 "move.w %%d0, %%d1 \n"
740 "lsr.l #8,%%d1 \n"
741 "move.w (%[pal], %%d1.l:2), %%d2 \n"
742 "move.l %%d2, %%d3 \n"
743 "lsr.l #7, %%d3 \n"
744 "move.w %%d3, (%[LCD2]) \n"
745 "lsl.l #1, %%d2 \n"
746 "move.w %%d2, (%[LCD2]) \n"
747 "move.b %%d0,%%d1 \n"
748 "move.w (%[pal], %%d1.l:2), %%d2 \n"
749 "move.l %%d2, %%d3 \n"
750 "lsr.l #7, %%d3 \n"
751 "move.w %%d3, (%[LCD2]) \n"
752 "lsl.l #1, %%d2 \n"
753 "move.w %%d2, (%[LCD2]) \n"
754 "swap.w %%d0 \n"
755 "move.w %%d0, %%d1 \n"
756 "lsr.l #8,%%d1 \n"
757 "move.w (%[pal], %%d1.l:2), %%d2 \n"
758 "move.l %%d2, %%d3 \n"
759 "lsr.l #7, %%d3 \n"
760 "move.w %%d3, (%[LCD2]) \n"
761 "lsl.l #1, %%d2 \n"
762 "move.w %%d2, (%[LCD2]) \n"
763 "move.b %%d0,%%d1 \n"
764 "move.w (%[pal], %%d1.l:2), %%d2 \n"
765 "move.l %%d2, %%d3 \n"
766 "lsr.l #7, %%d3 \n"
767 "move.w %%d3, (%[LCD2]) \n"
768 "lsl.l #1, %%d2 \n"
769 "move.w %%d2, (%[LCD2]) \n"
770 "subq.l #4,%[cnt] \n"
771 "bne.b .loop \n"
772 : /* outputs */
773 [scrp]"+a"(src),
774 [cnt] "+d"(count)
775 : /* inputs */
776 [pal] "a" (palette),
777 [LCD] "a" (0xf0008000),
778 [LCD2]"a" (0xf0008002)
779 : /* clobbers */
780 "d0", "d1", "d2", "d3"
782 #else
784 /* If the hardware has support for a paletted mode it takes precidence */
785 #if defined(HAVE_LCD_MODES)
786 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
787 (void) count;
788 rb->lcd_blit_pal256(src, 0, 0, 0, 0, LCD_WIDTH, LCD_HEIGHT);
789 #endif
790 #elif defined(HAVE_LCD_COLOR)
791 #if(LCD_HEIGHT>LCD_WIDTH)
792 if(rotate_screen)
794 int y;
796 for (y = 1; y <= SCREENHEIGHT; y++)
798 fb_data *dst = rb->lcd_framebuffer + LCD_WIDTH - y;
799 count = SCREENWIDTH;
803 *dst = palette[*src++];
804 dst += LCD_WIDTH;
806 while (--count);
809 else
810 #endif
812 fb_data *dst = rb->lcd_framebuffer;
813 count = SCREENWIDTH*SCREENHEIGHT;
816 *dst++ = palette[*src++];
817 while (--count);
819 rb->lcd_update();
820 #else /* !HAVE_LCD_COLOR */
822 unsigned char *dst;
823 int y;
825 for (y = 0; y < SCREENHEIGHT; y++)
827 dst = greybuffer;
828 count = SCREENWIDTH;
831 *dst++ = palette[*src++];
832 while (--count);
834 grey_ub_gray_bitmap(greybuffer, 0, y, SCREENWIDTH, 1);
836 #endif
837 #endif
841 // I_ReadScreen
843 void I_ReadScreen (byte* scr)
845 memcpy (scr, d_screens[0], LCD_WIDTH*LCD_HEIGHT);
849 // I_SetPalette
851 void I_SetPalette (int pal)
853 I_UploadNewPalette(pal);
857 // I_InitGraphics
859 void I_InitGraphics(void)
861 printf("Starting Graphics engine\n");
863 noprintf=1;
865 #if defined(HAVE_LCD_MODES)
866 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
867 rb->lcd_set_mode(LCD_MODE_PAL256);
868 #endif
869 #endif
871 /* Note: The other screens are allocated as needed */
873 #ifndef HAVE_LCD_COLOR
874 gbuf=malloc(GREYBUFSIZE);
875 grey_init(gbuf, GREYBUFSIZE, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL);
876 /* switch on greyscale overlay */
877 grey_show(true);
878 #endif
880 #ifdef CPU_COLDFIRE
881 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE);
882 d_screens[0] = fastscreen;
883 #else
884 // Don't know if this will fit in other IRAMs
885 d_screens[0] = malloc (LCD_WIDTH * LCD_HEIGHT * sizeof(unsigned char));
886 #endif