Accept FS#5153 - Doom Scrollwheel Patch
[kugel-rb.git] / apps / plugins / doom / i_video.c
blob7023e8f87cb47b3b9d93ba904c5bcca42dccf2a7
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_SCROLLWHEEL_CC BUTTON_SCROLL_BACK
163 #define DOOMBUTTON_SCROLLWHEEL_CW BUTTON_SCROLL_FWD
164 #define DOOMBUTTON_UP BUTTON_MENU
165 #define DOOMBUTTON_WEAPON BUTTON_SELECT
166 #define DOOMBUTTON_LEFT BUTTON_LEFT
167 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
168 #define DOOMBUTTON_SHOOT BUTTON_PLAY
169 #define DOOMBUTTON_ENTER BUTTON_SELECT
170 #define DOOMBUTTON_OPEN BUTTON_MENU
171 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
172 #define DOOMBUTTON_UP BUTTON_UP
173 #define DOOMBUTTON_DOWN BUTTON_DOWN
174 #define DOOMBUTTON_LEFT BUTTON_LEFT
175 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
176 #define DOOMBUTTON_SHOOT BUTTON_SELECT
177 #define DOOMBUTTON_OPEN BUTTON_PLAY
178 #define DOOMBUTTON_ESC BUTTON_POWER
179 #define DOOMBUTTON_ENTER BUTTON_SELECT
180 #define DOOMBUTTON_WEAPON BUTTON_REC
181 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
182 #define DOOMBUTTON_UP BUTTON_SCROLL_UP
183 #define DOOMBUTTON_DOWN BUTTON_SCROLL_DOWN
184 #define DOOMBUTTON_LEFT BUTTON_LEFT
185 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
186 #define DOOMBUTTON_SHOOT BUTTON_REW
187 #define DOOMBUTTON_OPEN BUTTON_PLAY
188 #define DOOMBUTTON_ESC BUTTON_POWER
189 #define DOOMBUTTON_ENTER BUTTON_REW
190 #define DOOMBUTTON_WEAPON BUTTON_FF
191 #elif CONFIG_KEYPAD == SANSA_E200_PAD
192 #define DOOMBUTTON_SCROLLWHEEL
193 #define DOOMBUTTON_SCROLLWHEEL_CC BUTTON_SCROLL_BACK
194 #define DOOMBUTTON_SCROLLWHEEL_CW BUTTON_SCROLL_FWD
195 #define DOOMBUTTON_UP BUTTON_UP
196 #define DOOMBUTTON_DOWN BUTTON_DOWN
197 #define DOOMBUTTON_LEFT BUTTON_LEFT
198 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
199 #define DOOMBUTTON_SHOOT BUTTON_SELECT
200 #define DOOMBUTTON_OPEN BUTTON_REC
201 #define DOOMBUTTON_ESC BUTTON_POWER
202 #define DOOMBUTTON_ENTER BUTTON_SELECT
203 #define DOOMBUTTON_WEAPON DOOMBUTTON_SCROLLWHEEL_CW
204 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
205 #define DOOMBUTTON_SCROLLWHEEL
206 #define DOOMBUTTON_SCROLLWHEEL_CC BUTTON_SCROLL_BACK
207 #define DOOMBUTTON_SCROLLWHEEL_CW BUTTON_SCROLL_FWD
208 #define DOOMBUTTON_UP BUTTON_UP
209 #define DOOMBUTTON_DOWN BUTTON_DOWN
210 #define DOOMBUTTON_LEFT BUTTON_LEFT
211 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
212 #define DOOMBUTTON_SHOOT BUTTON_SELECT
213 #define DOOMBUTTON_OPEN BUTTON_POWER
214 #define DOOMBUTTON_ESC BUTTON_HOME
215 #define DOOMBUTTON_ENTER BUTTON_SELECT
216 #define DOOMBUTTON_WEAPON DOOMBUTTON_SCROLLWHEEL_CW
217 #elif CONFIG_KEYPAD == SANSA_C200_PAD
218 #define DOOMBUTTON_UP BUTTON_UP
219 #define DOOMBUTTON_DOWN BUTTON_DOWN
220 #define DOOMBUTTON_LEFT BUTTON_LEFT
221 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
222 #define DOOMBUTTON_SHOOT BUTTON_SELECT
223 #define DOOMBUTTON_OPEN BUTTON_REC
224 #define DOOMBUTTON_ESC BUTTON_POWER
225 #define DOOMBUTTON_ENTER BUTTON_SELECT
226 #define DOOMBUTTON_WEAPON BUTTON_VOL_UP
227 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
228 #define DOOMBUTTON_UP BUTTON_UP
229 #define DOOMBUTTON_DOWN BUTTON_DOWN
230 #define DOOMBUTTON_LEFT BUTTON_LEFT
231 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
232 #define DOOMBUTTON_SHOOT BUTTON_SELECT
233 #define DOOMBUTTON_OPEN BUTTON_HOME
234 #define DOOMBUTTON_ESC BUTTON_POWER
235 #define DOOMBUTTON_ENTER BUTTON_SELECT
236 #define DOOMBUTTON_WEAPON BUTTON_VOL_UP
237 #elif CONFIG_KEYPAD == GIGABEAT_PAD
238 #define DOOMBUTTON_UP BUTTON_UP
239 #define DOOMBUTTON_DOWN BUTTON_DOWN
240 #define DOOMBUTTON_LEFT BUTTON_LEFT
241 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
242 #define DOOMBUTTON_SHOOT BUTTON_A
243 #define DOOMBUTTON_OPEN BUTTON_MENU
244 #define DOOMBUTTON_ESC BUTTON_POWER
245 #define DOOMBUTTON_ENTER BUTTON_SELECT
246 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
247 #define DOOMBUTTON_MAP BUTTON_VOL_UP
248 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
249 #define DOOMBUTTON_UP BUTTON_UP
250 #define DOOMBUTTON_DOWN BUTTON_DOWN
251 #define DOOMBUTTON_LEFT BUTTON_LEFT
252 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
253 #define DOOMBUTTON_SHOOT BUTTON_PLAY
254 #define DOOMBUTTON_OPEN BUTTON_MENU
255 #define DOOMBUTTON_ESC BUTTON_POWER
256 #define DOOMBUTTON_ENTER BUTTON_SELECT
257 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
258 #define DOOMBUTTON_MAP BUTTON_VOL_UP
259 #elif CONFIG_KEYPAD == MROBE500_PAD
260 #define DOOMBUTTON_ESC BUTTON_POWER
261 #define DOOMBUTTON_UP BUTTON_RC_PLAY
262 #define DOOMBUTTON_DOWN BUTTON_RC_DOWN
263 #define DOOMBUTTON_LEFT BUTTON_RC_REW
264 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
265 #define DOOMBUTTON_OPEN BUTTON_RC_VOL_DOWN
266 #define DOOMBUTTON_SHOOT BUTTON_RC_VOL_UP
267 #define DOOMBUTTON_ENTER BUTTON_RC_MODE
268 #define DOOMBUTTON_WEAPON BUTTON_RC_HEART
269 #elif CONFIG_KEYPAD == IRIVER_H100_PAD || \
270 CONFIG_KEYPAD == IRIVER_H300_PAD
271 #define DOOMBUTTON_UP BUTTON_UP
272 #define DOOMBUTTON_DOWN BUTTON_DOWN
273 #define DOOMBUTTON_LEFT BUTTON_LEFT
274 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
275 #define DOOMBUTTON_SHOOT BUTTON_REC
276 #define DOOMBUTTON_OPEN BUTTON_MODE
277 #define DOOMBUTTON_ESC BUTTON_OFF
278 #define DOOMBUTTON_ENTER BUTTON_SELECT
279 #define DOOMBUTTON_WEAPON BUTTON_ON
280 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
281 #define DOOMBUTTON_ESC BUTTON_RC_REC
282 #define DOOMBUTTON_UP BUTTON_RC_VOL_UP
283 #define DOOMBUTTON_DOWN BUTTON_RC_VOL_DOWN
284 #define DOOMBUTTON_LEFT BUTTON_RC_REW
285 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
286 #define DOOMBUTTON_OPEN BUTTON_RC_PLAY
287 #define DOOMBUTTON_SHOOT BUTTON_RC_MODE
288 #define DOOMBUTTON_ENTER BUTTON_RC_PLAY
289 #define DOOMBUTTON_WEAPON BUTTON_RC_MENU
290 #elif CONFIG_KEYPAD == COWON_D2_PAD
291 #define DOOMBUTTON_ESC BUTTON_POWER
292 #define DOOMBUTTON_SHOOT BUTTON_PLUS
293 #define DOOMBUTTON_WEAPON BUTTON_MINUS
294 #define DOOMBUTTON_MAP BUTTON_MENU
295 #elif CONFIG_KEYPAD == MROBE100_PAD
296 #define DOOMBUTTON_UP BUTTON_UP
297 #define DOOMBUTTON_DOWN BUTTON_DOWN
298 #define DOOMBUTTON_LEFT BUTTON_LEFT
299 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
300 #define DOOMBUTTON_SHOOT BUTTON_SELECT
301 #define DOOMBUTTON_OPEN BUTTON_PLAY
302 #define DOOMBUTTON_ESC BUTTON_POWER
303 #define DOOMBUTTON_ENTER BUTTON_MENU
304 #define DOOMBUTTON_WEAPON BUTTON_DISPLAY
305 #elif CONFIG_KEYPAD == IAUDIO67_PAD
306 #define DOOMBUTTON_ESC BUTTON_POWER
307 #define DOOMBUTTON_UP BUTTON_STOP
308 #define DOOMBUTTON_DOWN BUTTON_PLAY
309 #define DOOMBUTTON_LEFT BUTTON_LEFT
310 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
311 #define DOOMBUTTON_SHOOT BUTTON_VOLUP
312 #define DOOMBUTTON_OPEN BUTTON_VOLDOWN
313 #define DOOMBUTTON_ENTER BUTTON_MENU
314 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
315 #define DOOMBUTTON_UP BUTTON_UP
316 #define DOOMBUTTON_DOWN BUTTON_DOWN
317 #define DOOMBUTTON_LEFT BUTTON_LEFT
318 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
319 #define DOOMBUTTON_SHOOT BUTTON_SELECT
320 #define DOOMBUTTON_OPEN BUTTON_PLAY
321 #define DOOMBUTTON_ESC BUTTON_BACK
322 #define DOOMBUTTON_ENTER BUTTON_PLAY
323 #define DOOMBUTTON_WEAPON BUTTON_MENU
324 #define DOOMBUTTON_MAP BUTTON_CUSTOM
325 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
326 #define DOOMBUTTON_UP BUTTON_UP
327 #define DOOMBUTTON_DOWN BUTTON_DOWN
328 #define DOOMBUTTON_LEFT BUTTON_LEFT
329 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
330 #define DOOMBUTTON_SHOOT BUTTON_PLAYLIST
331 #define DOOMBUTTON_OPEN BUTTON_MENU
332 #define DOOMBUTTON_ESC BUTTON_POWER
333 #define DOOMBUTTON_ENTER BUTTON_VIEW
334 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
335 #define DOOMBUTTON_MAP BUTTON_VOL_UP
336 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
337 #define DOOMBUTTON_UP BUTTON_UP
338 #define DOOMBUTTON_DOWN BUTTON_DOWN
339 #define DOOMBUTTON_LEFT BUTTON_LEFT
340 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
341 #define DOOMBUTTON_SHOOT BUTTON_NEXT
342 #define DOOMBUTTON_OPEN BUTTON_MENU
343 #define DOOMBUTTON_ESC BUTTON_POWER
344 #define DOOMBUTTON_ENTER BUTTON_PLAY
345 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
346 #define DOOMBUTTON_MAP BUTTON_VOL_UP
347 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
348 #define DOOMBUTTON_UP BUTTON_UP
349 #define DOOMBUTTON_DOWN BUTTON_DOWN
350 #define DOOMBUTTON_LEFT BUTTON_PREV
351 #define DOOMBUTTON_RIGHT BUTTON_NEXT
352 #define DOOMBUTTON_SHOOT BUTTON_RIGHT
353 #define DOOMBUTTON_OPEN BUTTON_MENU
354 #define DOOMBUTTON_ESC BUTTON_POWER
355 #define DOOMBUTTON_ENTER BUTTON_LEFT
356 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
357 #define DOOMBUTTON_MAP BUTTON_VOL_UP
358 #elif CONFIG_KEYPAD == ONDAVX747_PAD
359 #define DOOMBUTTON_ESC BUTTON_POWER
360 #define DOOMBUTTON_SHOOT BUTTON_VOL_UP
361 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
362 #define DOOMBUTTON_MAP BUTTON_MENU
363 #elif CONFIG_KEYPAD == ONDAVX777_PAD
364 #define DOOMBUTTON_ESC BUTTON_POWER
365 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
366 #define DOOMBUTTON_UP BUTTON_UP
367 #define DOOMBUTTON_DOWN BUTTON_DOWN
368 #define DOOMBUTTON_LEFT BUTTON_LEFT
369 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
370 #define DOOMBUTTON_SHOOT BUTTON_PLAY
371 #define DOOMBUTTON_OPEN (BUTTON_PLAY|BUTTON_LEFT)
372 #define DOOMBUTTON_ESC BUTTON_REC
373 #define DOOMBUTTON_ENTER (BUTTON_PLAY|BUTTON_RIGHT)
374 #define DOOMBUTTON_WEAPON (BUTTON_PLAY|BUTTON_UP)
375 #define DOOMBUTTON_MAP (BUTTON_PLAY|BUTTON_DOWN)
376 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
377 #define DOOMBUTTON_UP BUTTON_OK
378 #define DOOMBUTTON_DOWN BUTTON_CANCEL
379 #define DOOMBUTTON_LEFT BUTTON_PREV
380 #define DOOMBUTTON_RIGHT BUTTON_NEXT
381 #define DOOMBUTTON_SHOOT BUTTON_MENU
382 #define DOOMBUTTON_OPEN BUTTON_OK
383 #define DOOMBUTTON_ESC BUTTON_REC
384 #define DOOMBUTTON_ENTER BUTTON_POWER
385 #define DOOMBUTTON_WEAPON BUTTON_PLAY
386 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
387 #define DOOMBUTTON_UP BUTTON_REW
388 #define DOOMBUTTON_DOWN BUTTON_FF
389 #define DOOMBUTTON_LEFT BUTTON_VOL_DOWN
390 #define DOOMBUTTON_RIGHT BUTTON_VOL_UP
391 #define DOOMBUTTON_SHOOT BUTTON_FUNC
392 #define DOOMBUTTON_OPEN (BUTTON_FUNC|BUTTON_PLAY)
393 #define DOOMBUTTON_ESC BUTTON_REC
394 #define DOOMBUTTON_ENTER BUTTON_PLAY
395 #define DOOMBUTTON_WEAPON (BUTTON_PLAY|BUTTON_REPEAT)
396 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
397 #define DOOMBUTTON_UP BUTTON_UP
398 #define DOOMBUTTON_DOWN BUTTON_DOWN
399 #define DOOMBUTTON_LEFT BUTTON_REW
400 #define DOOMBUTTON_RIGHT BUTTON_FF
401 #define DOOMBUTTON_SHOOT BUTTON_ENTER
402 #define DOOMBUTTON_OPEN BUTTON_MENU
403 #define DOOMBUTTON_ESC BUTTON_REC
404 #define DOOMBUTTON_ENTER BUTTON_PLAY
405 #define DOOMBUTTON_WEAPON (BUTTON_PLAY|BUTTON_REPEAT)
407 #else
408 #error Keymap not defined!
409 #endif
411 #ifdef HAVE_TOUCHSCREEN
412 #ifndef DOOMBUTTON_UP
413 #define DOOMBUTTON_UP BUTTON_TOPMIDDLE
414 #endif
415 #ifndef DOOMBUTTON_DOWN
416 #define DOOMBUTTON_DOWN BUTTON_BOTTOMMIDDLE
417 #endif
418 #ifndef DOOMBUTTON_LEFT
419 #define DOOMBUTTON_LEFT BUTTON_MIDLEFT
420 #endif
421 #ifndef DOOMBUTTON_RIGHT
422 #define DOOMBUTTON_RIGHT BUTTON_MIDRIGHT
423 #endif
424 #ifndef DOOMBUTTON_SHOOT
425 #define DOOMBUTTON_SHOOT BUTTON_BOTTOMRIGHT
426 #endif
427 #ifndef DOOMBUTTON_OPEN
428 #define DOOMBUTTON_OPEN BUTTON_TOPRIGHT
429 #endif
430 #ifndef DOOMBUTTON_ESC
431 #define DOOMBUTTON_ESC BUTTON_TOPLEFT
432 #endif
433 #ifndef DOOMBUTTON_ENTER
434 #define DOOMBUTTON_ENTER BUTTON_CENTER
435 #endif
436 #ifndef DOOMBUTTON_WEAPON
437 #define DOOMBUTTON_WEAPON BUTTON_BOTTOMLEFT
438 #endif
439 #endif
441 #ifdef DOOMBUTTON_SCROLLWHEEL
442 /* Scrollwheel events are posted directly and not polled by the button
443 driver - synthesize polling */
444 static inline unsigned int read_scroll_wheel(void)
446 unsigned int buttons = BUTTON_NONE;
447 unsigned int btn;
449 /* Empty out the button queue and see if any scrollwheel events were
450 posted */
453 btn = rb->button_get_w_tmo(0);
454 buttons |= btn;
456 while (btn != BUTTON_NONE);
458 return buttons & (DOOMBUTTON_SCROLLWHEEL_CC | DOOMBUTTON_SCROLLWHEEL_CW);
460 #endif
462 static inline void getkey()
464 event_t event;
465 /* Same button handling as rockboy */
466 static unsigned int oldbuttonstate IDATA_ATTR = 0;
468 unsigned int released, pressed, newbuttonstate;
470 #ifdef HAS_BUTTON_HOLD
471 static unsigned int holdbutton IDATA_ATTR=0;
472 static bool hswitch IDATA_ATTR=0;
473 if (rb->button_hold()&~holdbutton)
475 if(hswitch==0)
477 event.type = ev_keydown;
478 hswitch=1;
480 else
482 event.type = ev_keyup;
483 hswitch=0;
485 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
486 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
487 /* Bring up the menu */
488 event.data1=KEY_ESCAPE;
489 #else
490 /* Enable run */
491 event.data1=KEY_CAPSLOCK;
492 #endif
493 D_PostEvent(&event);
495 holdbutton=rb->button_hold();
496 #endif
498 #ifdef DOOMBUTTON_SCROLLWHEEL
499 /* use button_get(false) for clickwheel checks */
500 int button; /* move me */
501 button = rb->button_get(false);
502 switch(button){
503 case DOOMBUTTON_SCROLLWHEEL_CC | BUTTON_REPEAT:
504 case DOOMBUTTON_SCROLLWHEEL_CC:
505 event.type = ev_scroll;
506 event.data1=-1;
507 D_PostEvent(&event);
508 break;
509 case DOOMBUTTON_SCROLLWHEEL_CW | BUTTON_REPEAT:
510 case DOOMBUTTON_SCROLLWHEEL_CW:
511 event.type = ev_scroll;
512 //event.data1=KEY_LEFTARROW;
513 event.data1=1;
514 D_PostEvent(&event);
515 break;
517 #endif
518 newbuttonstate = rb->button_status();
519 #ifdef DOOMBUTTON_SCROLLWHEEL
520 newbuttonstate |= read_scroll_wheel();
521 #endif
523 if(newbuttonstate==oldbuttonstate) /* Don't continue, nothing left to do */
524 return;
525 released = ~newbuttonstate & oldbuttonstate;
526 pressed = newbuttonstate & ~oldbuttonstate;
527 oldbuttonstate = newbuttonstate;
528 if(released)
530 event.type = ev_keyup;
531 if(released & DOOMBUTTON_LEFT)
533 event.data1=KEY_LEFTARROW;
534 D_PostEvent(&event);
536 if(released & DOOMBUTTON_RIGHT)
538 event.data1=KEY_RIGHTARROW;
539 D_PostEvent(&event);
541 #ifdef DOOMBUTTON_DOWN
542 if(released & DOOMBUTTON_DOWN)
544 event.data1=KEY_DOWNARROW;
545 D_PostEvent(&event);
547 #endif
548 if(released & DOOMBUTTON_UP)
550 event.data1=KEY_UPARROW;
551 D_PostEvent(&event);
553 if(released & DOOMBUTTON_SHOOT)
555 event.data1=KEY_RCTRL;
556 D_PostEvent(&event);
558 if(released & DOOMBUTTON_OPEN)
560 event.data1=' ';
561 D_PostEvent(&event);
563 #ifdef DOOMBUTTON_ESC
564 if(released & DOOMBUTTON_ESC)
566 event.data1=KEY_ESCAPE;
567 D_PostEvent(&event);
569 #endif
570 if(released & DOOMBUTTON_ENTER)
572 event.data1=KEY_ENTER;
573 D_PostEvent(&event);
575 #ifdef DOOMBUTTON_WEAPON
576 if(released & DOOMBUTTON_WEAPON)
578 event.data1 ='w';
579 D_PostEvent(&event);
581 #endif
582 #ifdef DOOMBUTTON_MAP
583 if(released & DOOMBUTTON_MAP)
585 event.data1 =KEY_TAB;
586 D_PostEvent(&event);
588 #endif
590 if(pressed)
592 event.type = ev_keydown;
593 if(pressed & DOOMBUTTON_LEFT)
595 event.data1=KEY_LEFTARROW;
596 D_PostEvent(&event);
598 if(pressed & DOOMBUTTON_RIGHT)
600 event.data1=KEY_RIGHTARROW;
601 D_PostEvent(&event);
603 #ifdef DOOMBUTTON_DOWN
604 if(pressed & DOOMBUTTON_DOWN)
606 event.data1=KEY_DOWNARROW;
607 D_PostEvent(&event);
609 #endif
610 if(pressed & DOOMBUTTON_UP)
612 event.data1=KEY_UPARROW;
613 D_PostEvent(&event);
615 if(pressed & DOOMBUTTON_SHOOT)
617 event.data1=KEY_RCTRL;
618 D_PostEvent(&event);
620 if(pressed & DOOMBUTTON_OPEN)
622 event.data1=' ';
623 D_PostEvent(&event);
625 #ifdef DOOMBUTTON_ESC
626 if(pressed & DOOMBUTTON_ESC)
628 event.data1=KEY_ESCAPE;
629 D_PostEvent(&event);
631 #endif
632 #ifdef DOOMBUTTON_ENTER
633 if(pressed & DOOMBUTTON_ENTER)
635 event.data1=KEY_ENTER;
636 D_PostEvent(&event);
638 #endif
639 #ifdef DOOMBUTTON_WEAPON
640 if(pressed & DOOMBUTTON_WEAPON)
642 event.data1='w';
643 D_PostEvent(&event);
645 #endif
646 #ifdef DOOMBUTTON_MAP
647 if(pressed & DOOMBUTTON_MAP)
649 event.data1 =KEY_TAB;
650 D_PostEvent(&event);
652 #endif
656 void I_StartTic (void)
658 getkey();
662 ///////////////////////////////////////////////////////////
663 // Palette stuff.
665 static void I_UploadNewPalette(int pal)
667 // This is used to replace the current 256 colour cmap with a new one
668 // Used by 256 colour PseudoColor modes
669 static int cachedgamma;
670 static size_t num_pals;
672 if ((paldata == NULL) || (cachedgamma != usegamma)) {
673 int lump = W_GetNumForName("PLAYPAL");
674 const byte *pall = W_CacheLumpNum(lump);
675 register const byte *const gtable = gammatable[cachedgamma = usegamma];
676 register int i;
678 num_pals = W_LumpLength(lump) / (3*256);
679 num_pals *= 256;
681 if (!paldata) {
682 // First call - allocate and prepare colour array
683 paldata = malloc(sizeof(*paldata)*num_pals);
686 // set the colormap entries
687 for (i=0 ; (size_t)i<num_pals ; i++) {
688 int r = gtable[pall[0]];
689 int g = gtable[pall[1]];
690 int b = gtable[pall[2]];
691 pall+=3;
692 #ifndef HAVE_LCD_COLOR
693 paldata[i]=(3*r+6*g+b)/10;
694 #else
695 paldata[i] = LCD_RGBPACK(r,g,b);
696 #endif
699 W_UnlockLumpNum(lump);
700 num_pals/=256;
703 #ifdef RANGECHECK
704 if ((size_t)pal >= num_pals)
705 I_Error("I_UploadNewPalette: Palette number out of range (%d>=%d)",
706 pal, num_pals);
707 #endif
709 memcpy(palette,paldata+256*pal,256*sizeof(fb_data));
711 #if defined(HAVE_LCD_MODES)
712 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
713 rb->lcd_pal256_update_pal(paldata+256*pal);
714 #endif
715 #endif
719 // I_FinishUpdate
722 void I_FinishUpdate (void)
724 int count;
725 byte *src = d_screens[0];
727 #if (CONFIG_LCD == LCD_H300) && !defined(SIMULATOR)
728 count = SCREENWIDTH*SCREENHEIGHT;
730 /* ASM screen update (drops ~300 tics) */
731 asm volatile (
732 "move.w #33, (%[LCD]) \n" /* Setup the LCD controller */
733 "nop \n"
734 "clr.w (%[LCD2]) \n"
735 "nop \n"
736 "move.w #34, (%[LCD]) \n" /* End LCD controller setup */
737 "clr.l %%d1 \n"
738 ".loop: \n"
739 "move.l (%[scrp])+, %%d0 \n"
740 "swap.w %%d0 \n"
741 "move.w %%d0, %%d1 \n"
742 "lsr.l #8,%%d1 \n"
743 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
744 "move.b %%d0,%%d1 \n"
745 "swap.w %%d0 \n"
746 "nop \n"
747 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
748 "move.w %%d0, %%d1 \n"
749 "lsr.l #8,%%d1 \n"
750 "nop \n"
751 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
752 "move.b %%d0,%%d1 \n"
753 "nop \n"
754 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
755 "subq.l #4,%[cnt] \n"
756 "bne.b .loop \n"
757 : /* outputs */
758 [scrp]"+a"(src),
759 [cnt] "+d"(count)
760 : /* inputs */
761 [pal] "a" (palette),
762 [LCD] "a" (0xf0000000),
763 [LCD2]"a" (0xf0000002)
764 : /* clobbers */
765 "d0", "d1"
767 #elif (CONFIG_LCD == LCD_X5) && !defined(SIMULATOR) \
768 && defined(CPU_COLDFIRE) /* protect from using it on e200 (sic!) */
769 count = SCREENWIDTH*SCREENHEIGHT;
771 /* ASM screen update (drops ~230 tics) */
772 asm volatile (
773 "clr.w (%[LCD]) \n" /* Setup the LCD controller */
774 "move.w #(33<<1), (%[LCD]) \n"
775 "clr.w (%[LCD2]) \n"
776 "clr.w (%[LCD2]) \n"
777 "clr.w (%[LCD]) \n" /* End LCD controller setup */
778 "move.w #(34<<1), (%[LCD]) \n"
779 "clr.l %%d1 \n"
780 ".loop: \n"
781 "move.l (%[scrp])+, %%d0 \n"
782 "swap.w %%d0 \n"
783 "move.w %%d0, %%d1 \n"
784 "lsr.l #8,%%d1 \n"
785 "move.w (%[pal], %%d1.l:2), %%d2 \n"
786 "move.l %%d2, %%d3 \n"
787 "lsr.l #7, %%d3 \n"
788 "move.w %%d3, (%[LCD2]) \n"
789 "lsl.l #1, %%d2 \n"
790 "move.w %%d2, (%[LCD2]) \n"
791 "move.b %%d0,%%d1 \n"
792 "move.w (%[pal], %%d1.l:2), %%d2 \n"
793 "move.l %%d2, %%d3 \n"
794 "lsr.l #7, %%d3 \n"
795 "move.w %%d3, (%[LCD2]) \n"
796 "lsl.l #1, %%d2 \n"
797 "move.w %%d2, (%[LCD2]) \n"
798 "swap.w %%d0 \n"
799 "move.w %%d0, %%d1 \n"
800 "lsr.l #8,%%d1 \n"
801 "move.w (%[pal], %%d1.l:2), %%d2 \n"
802 "move.l %%d2, %%d3 \n"
803 "lsr.l #7, %%d3 \n"
804 "move.w %%d3, (%[LCD2]) \n"
805 "lsl.l #1, %%d2 \n"
806 "move.w %%d2, (%[LCD2]) \n"
807 "move.b %%d0,%%d1 \n"
808 "move.w (%[pal], %%d1.l:2), %%d2 \n"
809 "move.l %%d2, %%d3 \n"
810 "lsr.l #7, %%d3 \n"
811 "move.w %%d3, (%[LCD2]) \n"
812 "lsl.l #1, %%d2 \n"
813 "move.w %%d2, (%[LCD2]) \n"
814 "subq.l #4,%[cnt] \n"
815 "bne.b .loop \n"
816 : /* outputs */
817 [scrp]"+a"(src),
818 [cnt] "+d"(count)
819 : /* inputs */
820 [pal] "a" (palette),
821 [LCD] "a" (0xf0008000),
822 [LCD2]"a" (0xf0008002)
823 : /* clobbers */
824 "d0", "d1", "d2", "d3"
826 #else
828 /* If the hardware has support for a paletted mode it takes precidence */
829 #if defined(HAVE_LCD_MODES)
830 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
831 (void) count;
832 rb->lcd_blit_pal256(src, 0, 0, 0, 0, LCD_WIDTH, LCD_HEIGHT);
833 #endif
834 #elif defined(HAVE_LCD_COLOR)
835 #if(LCD_HEIGHT>LCD_WIDTH)
836 if(rotate_screen)
838 int y;
840 for (y = 1; y <= SCREENHEIGHT; y++)
842 fb_data *dst = rb->lcd_framebuffer + LCD_WIDTH - y;
843 count = SCREENWIDTH;
847 *dst = palette[*src++];
848 dst += LCD_WIDTH;
850 while (--count);
853 else
854 #endif
856 fb_data *dst = rb->lcd_framebuffer;
857 count = SCREENWIDTH*SCREENHEIGHT;
860 *dst++ = palette[*src++];
861 while (--count);
863 rb->lcd_update();
864 #else /* !HAVE_LCD_COLOR */
866 unsigned char *dst;
867 int y;
869 for (y = 0; y < SCREENHEIGHT; y++)
871 dst = greybuffer;
872 count = SCREENWIDTH;
875 *dst++ = palette[*src++];
876 while (--count);
878 grey_ub_gray_bitmap(greybuffer, 0, y, SCREENWIDTH, 1);
880 #endif
881 #endif
885 // I_ReadScreen
887 void I_ReadScreen (byte* scr)
889 memcpy (scr, d_screens[0], LCD_WIDTH*LCD_HEIGHT);
893 // I_SetPalette
895 void I_SetPalette (int pal)
897 I_UploadNewPalette(pal);
901 // I_InitGraphics
903 void I_InitGraphics(void)
905 printf("Starting Graphics engine\n");
907 noprintf=1;
909 #if defined(HAVE_LCD_MODES)
910 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
911 rb->lcd_set_mode(LCD_MODE_PAL256);
912 #endif
913 #endif
915 /* Note: The other screens are allocated as needed */
917 #ifndef HAVE_LCD_COLOR
918 gbuf=malloc(GREYBUFSIZE);
919 grey_init(gbuf, GREYBUFSIZE, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL);
920 /* switch on greyscale overlay */
921 grey_show(true);
922 #endif
924 #ifdef CPU_COLDFIRE
925 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE);
926 d_screens[0] = fastscreen;
927 #else
928 // Don't know if this will fit in other IRAMs
929 d_screens[0] = malloc (LCD_WIDTH * LCD_HEIGHT * sizeof(unsigned char));
930 #endif