Correct beast manual install instructions in Windows.
[kugel-rb.git] / apps / plugins / doom / i_video.c
blob84b003be51099a827bd9998838e8b8dd39814c55
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 == GIGABEAT_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_A
231 #define DOOMBUTTON_OPEN BUTTON_MENU
232 #define DOOMBUTTON_ESC BUTTON_POWER
233 #define DOOMBUTTON_ENTER BUTTON_SELECT
234 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
235 #define DOOMBUTTON_MAP BUTTON_VOL_UP
236 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
237 #define DOOMBUTTON_UP BUTTON_UP
238 #define DOOMBUTTON_DOWN BUTTON_DOWN
239 #define DOOMBUTTON_LEFT BUTTON_LEFT
240 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
241 #define DOOMBUTTON_SHOOT BUTTON_PLAY
242 #define DOOMBUTTON_OPEN BUTTON_MENU
243 #define DOOMBUTTON_ESC BUTTON_POWER
244 #define DOOMBUTTON_ENTER BUTTON_SELECT
245 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
246 #define DOOMBUTTON_MAP BUTTON_VOL_UP
247 #elif CONFIG_KEYPAD == MROBE500_PAD
248 #define DOOMBUTTON_ESC BUTTON_POWER
249 #define DOOMBUTTON_UP BUTTON_RC_PLAY
250 #define DOOMBUTTON_DOWN BUTTON_RC_DOWN
251 #define DOOMBUTTON_LEFT BUTTON_RC_REW
252 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
253 #define DOOMBUTTON_OPEN BUTTON_RC_VOL_DOWN
254 #define DOOMBUTTON_SHOOT BUTTON_RC_VOL_UP
255 #define DOOMBUTTON_ENTER BUTTON_RC_MODE
256 #define DOOMBUTTON_WEAPON BUTTON_RC_HEART
257 #elif CONFIG_KEYPAD == IRIVER_H100_PAD || \
258 CONFIG_KEYPAD == IRIVER_H300_PAD
259 #define DOOMBUTTON_UP BUTTON_UP
260 #define DOOMBUTTON_DOWN BUTTON_DOWN
261 #define DOOMBUTTON_LEFT BUTTON_LEFT
262 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
263 #define DOOMBUTTON_SHOOT BUTTON_REC
264 #define DOOMBUTTON_OPEN BUTTON_MODE
265 #define DOOMBUTTON_ESC BUTTON_OFF
266 #define DOOMBUTTON_ENTER BUTTON_SELECT
267 #define DOOMBUTTON_WEAPON BUTTON_ON
268 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
269 #define DOOMBUTTON_ESC BUTTON_RC_REC
270 #define DOOMBUTTON_UP BUTTON_RC_VOL_UP
271 #define DOOMBUTTON_DOWN BUTTON_RC_VOL_DOWN
272 #define DOOMBUTTON_LEFT BUTTON_RC_REW
273 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
274 #define DOOMBUTTON_OPEN BUTTON_RC_PLAY
275 #define DOOMBUTTON_SHOOT BUTTON_RC_MODE
276 #define DOOMBUTTON_ENTER BUTTON_RC_PLAY
277 #define DOOMBUTTON_WEAPON BUTTON_RC_MENU
278 #elif CONFIG_KEYPAD == COWOND2_PAD
279 #define DOOMBUTTON_ESC BUTTON_POWER
280 #define DOOMBUTTON_SHOOT BUTTON_PLUS
281 #define DOOMBUTTON_WEAPON BUTTON_MINUS
282 #define DOOMBUTTON_MAP BUTTON_MENU
283 #elif CONFIG_KEYPAD == MROBE100_PAD
284 #define DOOMBUTTON_UP BUTTON_UP
285 #define DOOMBUTTON_DOWN BUTTON_DOWN
286 #define DOOMBUTTON_LEFT BUTTON_LEFT
287 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
288 #define DOOMBUTTON_SHOOT BUTTON_SELECT
289 #define DOOMBUTTON_OPEN BUTTON_PLAY
290 #define DOOMBUTTON_ESC BUTTON_POWER
291 #define DOOMBUTTON_ENTER BUTTON_MENU
292 #define DOOMBUTTON_WEAPON BUTTON_DISPLAY
293 #elif CONFIG_KEYPAD == IAUDIO67_PAD
294 #define DOOMBUTTON_ESC BUTTON_POWER
295 #define DOOMBUTTON_UP BUTTON_STOP
296 #define DOOMBUTTON_DOWN BUTTON_PLAY
297 #define DOOMBUTTON_LEFT BUTTON_LEFT
298 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
299 #define DOOMBUTTON_SHOOT BUTTON_VOLUP
300 #define DOOMBUTTON_OPEN BUTTON_VOLDOWN
301 #define DOOMBUTTON_ENTER BUTTON_MENU
302 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
303 #define DOOMBUTTON_UP BUTTON_UP
304 #define DOOMBUTTON_DOWN BUTTON_DOWN
305 #define DOOMBUTTON_LEFT BUTTON_LEFT
306 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
307 #define DOOMBUTTON_SHOOT BUTTON_SELECT
308 #define DOOMBUTTON_OPEN BUTTON_PLAY
309 #define DOOMBUTTON_ESC BUTTON_BACK
310 #define DOOMBUTTON_ENTER BUTTON_PLAY
311 #define DOOMBUTTON_WEAPON BUTTON_MENU
312 #define DOOMBUTTON_MAP BUTTON_CUSTOM
313 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
314 #define DOOMBUTTON_UP BUTTON_UP
315 #define DOOMBUTTON_DOWN BUTTON_DOWN
316 #define DOOMBUTTON_LEFT BUTTON_LEFT
317 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
318 #define DOOMBUTTON_SHOOT BUTTON_PLAYLIST
319 #define DOOMBUTTON_OPEN BUTTON_MENU
320 #define DOOMBUTTON_ESC BUTTON_POWER
321 #define DOOMBUTTON_ENTER BUTTON_VIEW
322 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
323 #define DOOMBUTTON_MAP BUTTON_VOL_UP
324 #elif CONFIG_KEYPAD == ONDAVX747_PAD
325 #define DOOMBUTTON_ESC BUTTON_POWER
326 #define DOOMBUTTON_SHOOT BUTTON_VOL_UP
327 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
328 #define DOOMBUTTON_MAP BUTTON_MENU
329 #elif CONFIG_KEYPAD == ONDAVX777_PAD
330 #define DOOMBUTTON_ESC BUTTON_POWER
331 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
332 #define DOOMBUTTON_UP BUTTON_UP
333 #define DOOMBUTTON_DOWN BUTTON_DOWN
334 #define DOOMBUTTON_LEFT BUTTON_LEFT
335 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
336 #define DOOMBUTTON_SHOOT BUTTON_PLAY
337 #define DOOMBUTTON_OPEN (BUTTON_PLAY|BUTTON_LEFT)
338 #define DOOMBUTTON_ESC BUTTON_REC
339 #define DOOMBUTTON_ENTER (BUTTON_PLAY|BUTTON_RIGHT)
340 #define DOOMBUTTON_WEAPON (BUTTON_PLAY|BUTTON_UP)
341 #define DOOMBUTTON_MAP (BUTTON_PLAY|BUTTON_DOWN)
342 #else
343 #error Keymap not defined!
344 #endif
346 #ifdef HAVE_TOUCHSCREEN
347 #ifndef DOOMBUTTON_UP
348 #define DOOMBUTTON_UP BUTTON_TOPMIDDLE
349 #endif
350 #ifndef DOOMBUTTON_DOWN
351 #define DOOMBUTTON_DOWN BUTTON_BOTTOMMIDDLE
352 #endif
353 #ifndef DOOMBUTTON_LEFT
354 #define DOOMBUTTON_LEFT BUTTON_MIDLEFT
355 #endif
356 #ifndef DOOMBUTTON_RIGHT
357 #define DOOMBUTTON_RIGHT BUTTON_MIDRIGHT
358 #endif
359 #ifndef DOOMBUTTON_SHOOT
360 #define DOOMBUTTON_SHOOT BUTTON_BOTTOMRIGHT
361 #endif
362 #ifndef DOOMBUTTON_OPEN
363 #define DOOMBUTTON_OPEN BUTTON_TOPRIGHT
364 #endif
365 #ifndef DOOMBUTTON_ESC
366 #define DOOMBUTTON_ESC BUTTON_TOPLEFT
367 #endif
368 #ifndef DOOMBUTTON_ENTER
369 #define DOOMBUTTON_ENTER BUTTON_CENTER
370 #endif
371 #ifndef DOOMBUTTON_WEAPON
372 #define DOOMBUTTON_WEAPON BUTTON_BOTTOMLEFT
373 #endif
374 #endif
376 #ifdef DOOMBUTTON_SCROLLWHEEL
377 /* Scrollwheel events are posted directly and not polled by the button
378 driver - synthesize polling */
379 static inline unsigned int read_scroll_wheel(void)
381 unsigned int buttons = BUTTON_NONE;
382 unsigned int btn;
384 /* Empty out the button queue and see if any scrollwheel events were
385 posted */
388 btn = rb->button_get_w_tmo(0);
389 buttons |= btn;
391 while (btn != BUTTON_NONE);
393 return buttons & (DOOMBUTTON_SCROLLWHEEL_CC | DOOMBUTTON_SCROLLWHEEL_CW);
395 #endif
397 inline void getkey()
399 event_t event;
400 /* Same button handling as rockboy */
401 static unsigned int oldbuttonstate IDATA_ATTR = 0;
403 unsigned int released, pressed, newbuttonstate;
405 #ifdef HAS_BUTTON_HOLD
406 static unsigned int holdbutton IDATA_ATTR=0;
407 static bool hswitch IDATA_ATTR=0;
408 if (rb->button_hold()&~holdbutton)
410 if(hswitch==0)
412 event.type = ev_keydown;
413 hswitch=1;
415 else
417 event.type = ev_keyup;
418 hswitch=0;
420 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
421 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
422 /* Bring up the menu */
423 event.data1=KEY_ESCAPE;
424 #else
425 /* Enable run */
426 event.data1=KEY_CAPSLOCK;
427 #endif
428 D_PostEvent(&event);
430 holdbutton=rb->button_hold();
431 #endif
433 newbuttonstate = rb->button_status();
434 #ifdef DOOMBUTTON_SCROLLWHEEL
435 newbuttonstate |= read_scroll_wheel();
436 #endif
438 if(newbuttonstate==oldbuttonstate) /* Don't continue, nothing left to do */
439 return;
440 released = ~newbuttonstate & oldbuttonstate;
441 pressed = newbuttonstate & ~oldbuttonstate;
442 oldbuttonstate = newbuttonstate;
443 if(released)
445 event.type = ev_keyup;
446 if(released & DOOMBUTTON_LEFT)
448 event.data1=KEY_LEFTARROW;
449 D_PostEvent(&event);
451 if(released & DOOMBUTTON_RIGHT)
453 event.data1=KEY_RIGHTARROW;
454 D_PostEvent(&event);
456 #ifdef DOOMBUTTON_DOWN
457 if(released & DOOMBUTTON_DOWN)
459 event.data1=KEY_DOWNARROW;
460 D_PostEvent(&event);
462 #endif
463 if(released & DOOMBUTTON_UP)
465 event.data1=KEY_UPARROW;
466 D_PostEvent(&event);
468 if(released & DOOMBUTTON_SHOOT)
470 event.data1=KEY_RCTRL;
471 D_PostEvent(&event);
473 if(released & DOOMBUTTON_OPEN)
475 event.data1=' ';
476 D_PostEvent(&event);
478 #ifdef DOOMBUTTON_ESC
479 if(released & DOOMBUTTON_ESC)
481 event.data1=KEY_ESCAPE;
482 D_PostEvent(&event);
484 #endif
485 if(released & DOOMBUTTON_ENTER)
487 event.data1=KEY_ENTER;
488 D_PostEvent(&event);
490 #ifdef DOOMBUTTON_WEAPON
491 if(released & DOOMBUTTON_WEAPON)
493 event.data1 ='w';
494 D_PostEvent(&event);
496 #endif
497 #ifdef DOOMBUTTON_MAP
498 if(released & DOOMBUTTON_MAP)
500 event.data1 =KEY_TAB;
501 D_PostEvent(&event);
503 #endif
505 if(pressed)
507 event.type = ev_keydown;
508 if(pressed & DOOMBUTTON_LEFT)
510 event.data1=KEY_LEFTARROW;
511 D_PostEvent(&event);
513 if(pressed & DOOMBUTTON_RIGHT)
515 event.data1=KEY_RIGHTARROW;
516 D_PostEvent(&event);
518 #ifdef DOOMBUTTON_DOWN
519 if(pressed & DOOMBUTTON_DOWN)
521 event.data1=KEY_DOWNARROW;
522 D_PostEvent(&event);
524 #endif
525 if(pressed & DOOMBUTTON_UP)
527 event.data1=KEY_UPARROW;
528 D_PostEvent(&event);
530 if(pressed & DOOMBUTTON_SHOOT)
532 event.data1=KEY_RCTRL;
533 D_PostEvent(&event);
535 if(pressed & DOOMBUTTON_OPEN)
537 event.data1=' ';
538 D_PostEvent(&event);
540 #ifdef DOOMBUTTON_ESC
541 if(pressed & DOOMBUTTON_ESC)
543 event.data1=KEY_ESCAPE;
544 D_PostEvent(&event);
546 #endif
547 #ifdef DOOMBUTTON_ENTER
548 if(pressed & DOOMBUTTON_ENTER)
550 event.data1=KEY_ENTER;
551 D_PostEvent(&event);
553 #endif
554 #ifdef DOOMBUTTON_WEAPON
555 if(pressed & DOOMBUTTON_WEAPON)
557 event.data1='w';
558 D_PostEvent(&event);
560 #endif
561 #ifdef DOOMBUTTON_MAP
562 if(pressed & DOOMBUTTON_MAP)
564 event.data1 =KEY_TAB;
565 D_PostEvent(&event);
567 #endif
571 inline void I_StartTic (void)
573 getkey();
577 ///////////////////////////////////////////////////////////
578 // Palette stuff.
580 static void I_UploadNewPalette(int pal)
582 // This is used to replace the current 256 colour cmap with a new one
583 // Used by 256 colour PseudoColor modes
584 static int cachedgamma;
585 static size_t num_pals;
587 if ((paldata == NULL) || (cachedgamma != usegamma)) {
588 int lump = W_GetNumForName("PLAYPAL");
589 const byte *pall = W_CacheLumpNum(lump);
590 register const byte *const gtable = gammatable[cachedgamma = usegamma];
591 register int i;
593 num_pals = W_LumpLength(lump) / (3*256);
594 num_pals *= 256;
596 if (!paldata) {
597 // First call - allocate and prepare colour array
598 paldata = malloc(sizeof(*paldata)*num_pals);
601 // set the colormap entries
602 for (i=0 ; (size_t)i<num_pals ; i++) {
603 int r = gtable[pall[0]];
604 int g = gtable[pall[1]];
605 int b = gtable[pall[2]];
606 pall+=3;
607 #ifndef HAVE_LCD_COLOR
608 paldata[i]=(3*r+6*g+b)/10;
609 #else
610 paldata[i] = LCD_RGBPACK(r,g,b);
611 #endif
614 W_UnlockLumpNum(lump);
615 num_pals/=256;
618 #ifdef RANGECHECK
619 if ((size_t)pal >= num_pals)
620 I_Error("I_UploadNewPalette: Palette number out of range (%d>=%d)",
621 pal, num_pals);
622 #endif
624 memcpy(palette,paldata+256*pal,256*sizeof(fb_data));
626 #if defined(HAVE_LCD_MODES)
627 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
628 rb->lcd_pal256_update_pal(paldata+256*pal);
629 #endif
630 #endif
634 // I_FinishUpdate
637 void I_FinishUpdate (void)
639 int count;
640 byte *src = d_screens[0];
642 #if (CONFIG_LCD == LCD_H300) && !defined(SIMULATOR)
643 count = SCREENWIDTH*SCREENHEIGHT;
645 /* ASM screen update (drops ~300 tics) */
646 asm volatile (
647 "move.w #33, (%[LCD]) \n" /* Setup the LCD controller */
648 "nop \n"
649 "clr.w (%[LCD2]) \n"
650 "nop \n"
651 "move.w #34, (%[LCD]) \n" /* End LCD controller setup */
652 "clr.l %%d1 \n"
653 ".loop: \n"
654 "move.l (%[scrp])+, %%d0 \n"
655 "swap.w %%d0 \n"
656 "move.w %%d0, %%d1 \n"
657 "lsr.l #8,%%d1 \n"
658 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
659 "move.b %%d0,%%d1 \n"
660 "swap.w %%d0 \n"
661 "nop \n"
662 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
663 "move.w %%d0, %%d1 \n"
664 "lsr.l #8,%%d1 \n"
665 "nop \n"
666 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
667 "move.b %%d0,%%d1 \n"
668 "nop \n"
669 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
670 "subq.l #4,%[cnt] \n"
671 "bne.b .loop \n"
672 : /* outputs */
673 [scrp]"+a"(src),
674 [cnt] "+d"(count)
675 : /* inputs */
676 [pal] "a" (palette),
677 [LCD] "a" (0xf0000000),
678 [LCD2]"a" (0xf0000002)
679 : /* clobbers */
680 "d0", "d1"
682 #elif (CONFIG_LCD == LCD_X5) && !defined(SIMULATOR) \
683 && defined(CPU_COLDFIRE) /* protect from using it on e200 (sic!) */
684 count = SCREENWIDTH*SCREENHEIGHT;
686 /* ASM screen update (drops ~230 tics) */
687 asm volatile (
688 "clr.w (%[LCD]) \n" /* Setup the LCD controller */
689 "move.w #(33<<1), (%[LCD]) \n"
690 "clr.w (%[LCD2]) \n"
691 "clr.w (%[LCD2]) \n"
692 "clr.w (%[LCD]) \n" /* End LCD controller setup */
693 "move.w #(34<<1), (%[LCD]) \n"
694 "clr.l %%d1 \n"
695 ".loop: \n"
696 "move.l (%[scrp])+, %%d0 \n"
697 "swap.w %%d0 \n"
698 "move.w %%d0, %%d1 \n"
699 "lsr.l #8,%%d1 \n"
700 "move.w (%[pal], %%d1.l:2), %%d2 \n"
701 "move.l %%d2, %%d3 \n"
702 "lsr.l #7, %%d3 \n"
703 "move.w %%d3, (%[LCD2]) \n"
704 "lsl.l #1, %%d2 \n"
705 "move.w %%d2, (%[LCD2]) \n"
706 "move.b %%d0,%%d1 \n"
707 "move.w (%[pal], %%d1.l:2), %%d2 \n"
708 "move.l %%d2, %%d3 \n"
709 "lsr.l #7, %%d3 \n"
710 "move.w %%d3, (%[LCD2]) \n"
711 "lsl.l #1, %%d2 \n"
712 "move.w %%d2, (%[LCD2]) \n"
713 "swap.w %%d0 \n"
714 "move.w %%d0, %%d1 \n"
715 "lsr.l #8,%%d1 \n"
716 "move.w (%[pal], %%d1.l:2), %%d2 \n"
717 "move.l %%d2, %%d3 \n"
718 "lsr.l #7, %%d3 \n"
719 "move.w %%d3, (%[LCD2]) \n"
720 "lsl.l #1, %%d2 \n"
721 "move.w %%d2, (%[LCD2]) \n"
722 "move.b %%d0,%%d1 \n"
723 "move.w (%[pal], %%d1.l:2), %%d2 \n"
724 "move.l %%d2, %%d3 \n"
725 "lsr.l #7, %%d3 \n"
726 "move.w %%d3, (%[LCD2]) \n"
727 "lsl.l #1, %%d2 \n"
728 "move.w %%d2, (%[LCD2]) \n"
729 "subq.l #4,%[cnt] \n"
730 "bne.b .loop \n"
731 : /* outputs */
732 [scrp]"+a"(src),
733 [cnt] "+d"(count)
734 : /* inputs */
735 [pal] "a" (palette),
736 [LCD] "a" (0xf0008000),
737 [LCD2]"a" (0xf0008002)
738 : /* clobbers */
739 "d0", "d1", "d2", "d3"
741 #else
743 /* If the hardware has support for a paletted mode it takes precidence */
744 #if defined(HAVE_LCD_MODES)
745 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
746 (void) count;
747 rb->lcd_blit_pal256(src, 0, 0, 0, 0, LCD_WIDTH, LCD_HEIGHT);
748 #endif
749 #elif defined(HAVE_LCD_COLOR)
750 #if(LCD_HEIGHT>LCD_WIDTH)
751 if(rotate_screen)
753 int y;
755 for (y = 1; y <= SCREENHEIGHT; y++)
757 fb_data *dst = rb->lcd_framebuffer + LCD_WIDTH - y;
758 count = SCREENWIDTH;
762 *dst = palette[*src++];
763 dst += LCD_WIDTH;
765 while (--count);
768 else
769 #endif
771 fb_data *dst = rb->lcd_framebuffer;
772 count = SCREENWIDTH*SCREENHEIGHT;
775 *dst++ = palette[*src++];
776 while (--count);
778 rb->lcd_update();
779 #else /* !HAVE_LCD_COLOR */
781 unsigned char *dst;
782 int y;
784 for (y = 0; y < SCREENHEIGHT; y++)
786 dst = greybuffer;
787 count = SCREENWIDTH;
790 *dst++ = palette[*src++];
791 while (--count);
793 grey_ub_gray_bitmap(greybuffer, 0, y, SCREENWIDTH, 1);
795 #endif
796 #endif
800 // I_ReadScreen
802 void I_ReadScreen (byte* scr)
804 memcpy (scr, d_screens[0], LCD_WIDTH*LCD_HEIGHT);
808 // I_SetPalette
810 void I_SetPalette (int pal)
812 I_UploadNewPalette(pal);
816 // I_InitGraphics
818 void I_InitGraphics(void)
820 printf("Starting Graphics engine\n");
822 noprintf=1;
824 #if defined(HAVE_LCD_MODES)
825 #if (HAVE_LCD_MODES & LCD_MODE_PAL256)
826 rb->lcd_set_mode(LCD_MODE_PAL256);
827 #endif
828 #endif
830 /* Note: The other screens are allocated as needed */
832 #ifndef HAVE_LCD_COLOR
833 gbuf=malloc(GREYBUFSIZE);
834 grey_init(gbuf, GREYBUFSIZE, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL);
835 /* switch on greyscale overlay */
836 grey_show(true);
837 #endif
839 #ifdef CPU_COLDFIRE
840 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE);
841 d_screens[0] = fastscreen;
842 #else
843 // Don't know if this will fit in other IRAMs
844 d_screens[0] = malloc (LCD_WIDTH * LCD_HEIGHT * sizeof(unsigned char));
845 #endif