FS#8708: D2/m:robe500 touchscreen keymaps by Andreas Mueller.
[kugel-rb.git] / apps / plugins / doom / i_video.c
blob117c2b921b0fa2f9030c18aff50597e3d55d3b93
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 #ifndef HAVE_LCD_COLOR
144 grey_release();
145 #endif
146 noprintf=0;
150 // I_StartTic
153 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
154 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
155 //#define DOOMBUTTON_SCROLLWHEEL
156 #define DOOMBUTTON_UP BUTTON_MENU
157 #define DOOMBUTTON_WEAPON BUTTON_SELECT
158 #define DOOMBUTTON_LEFT BUTTON_LEFT
159 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
160 #define DOOMBUTTON_SHOOT BUTTON_PLAY
161 #define DOOMBUTTON_ENTER BUTTON_SELECT
162 #define DOOMBUTTON_OPEN BUTTON_MENU
163 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
164 #define DOOMBUTTON_UP BUTTON_UP
165 #define DOOMBUTTON_DOWN BUTTON_DOWN
166 #define DOOMBUTTON_LEFT BUTTON_LEFT
167 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
168 #define DOOMBUTTON_SHOOT BUTTON_SELECT
169 #define DOOMBUTTON_OPEN BUTTON_PLAY
170 #define DOOMBUTTON_ESC BUTTON_POWER
171 #define DOOMBUTTON_ENTER BUTTON_SELECT
172 #define DOOMBUTTON_WEAPON BUTTON_REC
173 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
174 #define DOOMBUTTON_UP BUTTON_SCROLL_UP
175 #define DOOMBUTTON_DOWN BUTTON_SCROLL_DOWN
176 #define DOOMBUTTON_LEFT BUTTON_LEFT
177 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
178 #define DOOMBUTTON_SHOOT BUTTON_REW
179 #define DOOMBUTTON_OPEN BUTTON_PLAY
180 #define DOOMBUTTON_ESC BUTTON_POWER
181 #define DOOMBUTTON_ENTER BUTTON_REW
182 #define DOOMBUTTON_WEAPON BUTTON_FF
183 #elif CONFIG_KEYPAD == SANSA_E200_PAD
184 #define DOOMBUTTON_SCROLLWHEEL
185 #define DOOMBUTTON_SCROLLWHEEL_CC BUTTON_SCROLL_BACK
186 #define DOOMBUTTON_SCROLLWHEEL_CW BUTTON_SCROLL_FWD
187 #define DOOMBUTTON_UP BUTTON_UP
188 #define DOOMBUTTON_DOWN BUTTON_DOWN
189 #define DOOMBUTTON_LEFT BUTTON_LEFT
190 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
191 #define DOOMBUTTON_SHOOT BUTTON_SELECT
192 #define DOOMBUTTON_OPEN BUTTON_REC
193 #define DOOMBUTTON_ESC BUTTON_POWER
194 #define DOOMBUTTON_ENTER BUTTON_SELECT
195 #define DOOMBUTTON_WEAPON DOOMBUTTON_SCROLLWHEEL_CW
196 #elif CONFIG_KEYPAD == SANSA_C200_PAD
197 #define DOOMBUTTON_UP BUTTON_UP
198 #define DOOMBUTTON_DOWN BUTTON_DOWN
199 #define DOOMBUTTON_LEFT BUTTON_LEFT
200 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
201 #define DOOMBUTTON_SHOOT BUTTON_SELECT
202 #define DOOMBUTTON_OPEN BUTTON_REC
203 #define DOOMBUTTON_ESC BUTTON_POWER
204 #define DOOMBUTTON_ENTER BUTTON_SELECT
205 #define DOOMBUTTON_WEAPON BUTTON_VOL_UP
206 #elif CONFIG_KEYPAD == GIGABEAT_PAD
207 #define DOOMBUTTON_UP BUTTON_UP
208 #define DOOMBUTTON_DOWN BUTTON_DOWN
209 #define DOOMBUTTON_LEFT BUTTON_LEFT
210 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
211 #define DOOMBUTTON_SHOOT BUTTON_A
212 #define DOOMBUTTON_OPEN BUTTON_MENU
213 #define DOOMBUTTON_ESC BUTTON_POWER
214 #define DOOMBUTTON_ENTER BUTTON_SELECT
215 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
216 #define DOOMBUTTON_MAP BUTTON_VOL_UP
217 #elif CONFIG_KEYPAD == MROBE500_PAD
218 #define DOOMBUTTON_ESC BUTTON_POWER
219 #define DOOMBUTTON_UP BUTTON_RC_PLAY
220 #define DOOMBUTTON_DOWN BUTTON_RC_DOWN
221 #define DOOMBUTTON_LEFT BUTTON_RC_REW
222 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
223 #define DOOMBUTTON_OPEN BUTTON_RC_VOL_DOWN
224 #define DOOMBUTTON_SHOOT BUTTON_RC_VOL_UP
225 #define DOOMBUTTON_ENTER BUTTON_RC_MODE
226 #define DOOMBUTTON_WEAPON BUTTON_RC_HEART
227 #elif CONFIG_KEYPAD == IRIVER_H100_PAD || \
228 CONFIG_KEYPAD == IRIVER_H300_PAD
229 #define DOOMBUTTON_UP BUTTON_UP
230 #define DOOMBUTTON_DOWN BUTTON_DOWN
231 #define DOOMBUTTON_LEFT BUTTON_LEFT
232 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
233 #define DOOMBUTTON_SHOOT BUTTON_REC
234 #define DOOMBUTTON_OPEN BUTTON_MODE
235 #define DOOMBUTTON_ESC BUTTON_OFF
236 #define DOOMBUTTON_ENTER BUTTON_SELECT
237 #define DOOMBUTTON_WEAPON BUTTON_ON
238 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
239 #define DOOMBUTTON_ESC BUTTON_RC_REC
240 #define DOOMBUTTON_UP BUTTON_RC_VOL_UP
241 #define DOOMBUTTON_DOWN BUTTON_RC_VOL_DOWN
242 #define DOOMBUTTON_LEFT BUTTON_RC_REW
243 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
244 #define DOOMBUTTON_OPEN BUTTON_RC_PLAY
245 #define DOOMBUTTON_SHOOT BUTTON_RC_MODE
246 #define DOOMBUTTON_ENTER BUTTON_RC_PLAY
247 #define DOOMBUTTON_WEAPON BUTTON_RC_MENU
248 #elif CONFIG_KEYPAD == COWOND2_PAD
249 #define DOOMBUTTON_ESC BUTTON_POWER
250 #elif CONFIG_KEYPAD == MROBE100_PAD
251 #define DOOMBUTTON_UP BUTTON_UP
252 #define DOOMBUTTON_DOWN BUTTON_DOWN
253 #define DOOMBUTTON_LEFT BUTTON_LEFT
254 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
255 #define DOOMBUTTON_SHOOT BUTTON_SELECT
256 #define DOOMBUTTON_OPEN BUTTON_PLAY
257 #define DOOMBUTTON_ESC BUTTON_POWER
258 #define DOOMBUTTON_ENTER BUTTON_MENU
259 #define DOOMBUTTON_WEAPON BUTTON_DISPLAY
260 #else
261 #error Keymap not defined!
262 #endif
264 #ifdef HAVE_TOUCHPAD
265 #ifndef DOOMBUTTON_UP
266 #define DOOMBUTTON_UP BUTTON_TOPMIDDLE
267 #endif
268 #ifndef DOOMBUTTON_DOWN
269 #define DOOMBUTTON_DOWN BUTTON_BOTTOMMIDDLE
270 #endif
271 #ifndef DOOMBUTTON_LEFT
272 #define DOOMBUTTON_LEFT BUTTON_MIDLEFT
273 #endif
274 #ifndef DOOMBUTTON_RIGHT
275 #define DOOMBUTTON_RIGHT BUTTON_MIDRIGHT
276 #endif
277 #ifndef DOOMBUTTON_SHOOT
278 #define DOOMBUTTON_SHOOT BUTTON_CENTER
279 #endif
280 #ifndef DOOMBUTTON_OPEN
281 #define DOOMBUTTON_OPEN BUTTON_TOPRIGHT
282 #endif
283 #ifndef DOOMBUTTON_ESC
284 #define DOOMBUTTON_ESC BUTTON_TOPLEFT
285 #endif
286 #ifndef DOOMBUTTON_ENTER
287 #define DOOMBUTTON_ENTER BUTTON_BOTTOMLEFT
288 #endif
289 #ifndef DOOMBUTTON_WEAPON
290 #define DOOMBUTTON_WEAPON BUTTON_BOTTOMRIGHT
291 #endif
292 #endif
294 #ifdef DOOMBUTTON_SCROLLWHEEL
295 /* Scrollwheel events are posted directly and not polled by the button
296 driver - synthesize polling */
297 static inline unsigned int read_scroll_wheel(void)
299 unsigned int buttons = BUTTON_NONE;
300 unsigned int btn;
302 /* Empty out the button queue and see if any scrollwheel events were
303 posted */
306 btn = rb->button_get_w_tmo(0);
307 buttons |= btn;
309 while (btn != BUTTON_NONE);
311 return buttons & (DOOMBUTTON_SCROLLWHEEL_CC | DOOMBUTTON_SCROLLWHEEL_CW);
313 #endif
315 inline void getkey()
317 event_t event;
318 /* Same button handling as rockboy */
319 static unsigned int oldbuttonstate IDATA_ATTR = 0;
321 unsigned int released, pressed, newbuttonstate;
323 #ifdef HAS_BUTTON_HOLD
324 static unsigned int holdbutton IDATA_ATTR=0;
325 static bool hswitch IDATA_ATTR=0;
326 if (rb->button_hold()&~holdbutton)
328 if(hswitch==0)
330 event.type = ev_keydown;
331 hswitch=1;
333 else
335 event.type = ev_keyup;
336 hswitch=0;
338 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
339 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
340 /* Bring up the menu */
341 event.data1=KEY_ESCAPE;
342 #else
343 /* Enable run */
344 event.data1=KEY_CAPSLOCK;
345 #endif
346 D_PostEvent(&event);
348 holdbutton=rb->button_hold();
349 #endif
351 newbuttonstate = rb->button_status();
352 #ifdef DOOMBUTTON_SCROLLWHEEL
353 newbuttonstate |= read_scroll_wheel();
354 #endif
356 if(newbuttonstate==oldbuttonstate) /* Don't continue, nothing left to do */
357 return;
358 released = ~newbuttonstate & oldbuttonstate;
359 pressed = newbuttonstate & ~oldbuttonstate;
360 oldbuttonstate = newbuttonstate;
361 if(released)
363 event.type = ev_keyup;
364 if(released & DOOMBUTTON_LEFT)
366 event.data1=KEY_LEFTARROW;
367 D_PostEvent(&event);
369 if(released & DOOMBUTTON_RIGHT)
371 event.data1=KEY_RIGHTARROW;
372 D_PostEvent(&event);
374 #ifdef DOOMBUTTON_DOWN
375 if(released & DOOMBUTTON_DOWN)
377 event.data1=KEY_DOWNARROW;
378 D_PostEvent(&event);
380 #endif
381 if(released & DOOMBUTTON_UP)
383 event.data1=KEY_UPARROW;
384 D_PostEvent(&event);
386 if(released & DOOMBUTTON_SHOOT)
388 event.data1=KEY_RCTRL;
389 D_PostEvent(&event);
391 if(released & DOOMBUTTON_OPEN)
393 event.data1=' ';
394 D_PostEvent(&event);
396 #ifdef DOOMBUTTON_ESC
397 if(released & DOOMBUTTON_ESC)
399 event.data1=KEY_ESCAPE;
400 D_PostEvent(&event);
402 #endif
403 if(released & DOOMBUTTON_ENTER)
405 event.data1=KEY_ENTER;
406 D_PostEvent(&event);
408 #ifdef DOOMBUTTON_WEAPON
409 if(released & DOOMBUTTON_WEAPON)
411 event.data1 ='w';
412 D_PostEvent(&event);
414 #endif
415 #ifdef DOOMBUTTON_MAP
416 if(released & DOOMBUTTON_MAP)
418 event.data1 =KEY_TAB;
419 D_PostEvent(&event);
421 #endif
423 if(pressed)
425 event.type = ev_keydown;
426 if(pressed & DOOMBUTTON_LEFT)
428 event.data1=KEY_LEFTARROW;
429 D_PostEvent(&event);
431 if(pressed & DOOMBUTTON_RIGHT)
433 event.data1=KEY_RIGHTARROW;
434 D_PostEvent(&event);
436 #ifdef DOOMBUTTON_DOWN
437 if(pressed & DOOMBUTTON_DOWN)
439 event.data1=KEY_DOWNARROW;
440 D_PostEvent(&event);
442 #endif
443 if(pressed & DOOMBUTTON_UP)
445 event.data1=KEY_UPARROW;
446 D_PostEvent(&event);
448 if(pressed & DOOMBUTTON_SHOOT)
450 event.data1=KEY_RCTRL;
451 D_PostEvent(&event);
453 if(pressed & DOOMBUTTON_OPEN)
455 event.data1=' ';
456 D_PostEvent(&event);
458 #ifdef DOOMBUTTON_ESC
459 if(pressed & DOOMBUTTON_ESC)
461 event.data1=KEY_ESCAPE;
462 D_PostEvent(&event);
464 #endif
465 #ifdef DOOMBUTTON_ENTER
466 if(pressed & DOOMBUTTON_ENTER)
468 event.data1=KEY_ENTER;
469 D_PostEvent(&event);
471 #endif
472 #ifdef DOOMBUTTON_WEAPON
473 if(pressed & DOOMBUTTON_WEAPON)
475 event.data1='w';
476 D_PostEvent(&event);
478 #endif
479 #ifdef DOOMBUTTON_MAP
480 if(pressed & DOOMBUTTON_MAP)
482 event.data1 =KEY_TAB;
483 D_PostEvent(&event);
485 #endif
489 inline void I_StartTic (void)
491 getkey();
495 ///////////////////////////////////////////////////////////
496 // Palette stuff.
498 static void I_UploadNewPalette(int pal)
500 // This is used to replace the current 256 colour cmap with a new one
501 // Used by 256 colour PseudoColor modes
502 static int cachedgamma;
503 static size_t num_pals;
505 if ((paldata == NULL) || (cachedgamma != usegamma)) {
506 int lump = W_GetNumForName("PLAYPAL");
507 const byte *pall = W_CacheLumpNum(lump);
508 register const byte *const gtable = gammatable[cachedgamma = usegamma];
509 register int i;
511 num_pals = W_LumpLength(lump) / (3*256);
512 num_pals *= 256;
514 if (!paldata) {
515 // First call - allocate and prepare colour array
516 paldata = malloc(sizeof(*paldata)*num_pals);
519 // set the colormap entries
520 for (i=0 ; (size_t)i<num_pals ; i++) {
521 int r = gtable[pall[0]];
522 int g = gtable[pall[1]];
523 int b = gtable[pall[2]];
524 pall+=3;
525 #ifndef HAVE_LCD_COLOR
526 paldata[i]=(3*r+6*g+b)/10;
527 #else
528 paldata[i] = LCD_RGBPACK(r,g,b);
529 #endif
532 W_UnlockLumpNum(lump);
533 num_pals/=256;
536 #ifdef RANGECHECK
537 if ((size_t)pal >= num_pals)
538 I_Error("I_UploadNewPalette: Palette number out of range (%d>=%d)",
539 pal, num_pals);
540 #endif
541 memcpy(palette,paldata+256*pal,256*sizeof(fb_data));
546 // I_FinishUpdate
549 void I_FinishUpdate (void)
551 int count;
552 byte *src = d_screens[0];
553 #if (CONFIG_LCD == LCD_H300) && !defined(SIMULATOR)
554 count = SCREENWIDTH*SCREENHEIGHT;
556 /* ASM screen update (drops ~300 tics) */
557 asm volatile (
558 "move.w #33, (%[LCD]) \n" /* Setup the LCD controller */
559 "nop \n"
560 "clr.w (%[LCD2]) \n"
561 "nop \n"
562 "move.w #34, (%[LCD]) \n" /* End LCD controller setup */
563 "clr.l %%d1 \n"
564 ".loop: \n"
565 "move.l (%[scrp])+, %%d0 \n"
566 "swap.w %%d0 \n"
567 "move.w %%d0, %%d1 \n"
568 "lsr.l #8,%%d1 \n"
569 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
570 "move.b %%d0,%%d1 \n"
571 "swap.w %%d0 \n"
572 "nop \n"
573 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
574 "move.w %%d0, %%d1 \n"
575 "lsr.l #8,%%d1 \n"
576 "nop \n"
577 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
578 "move.b %%d0,%%d1 \n"
579 "nop \n"
580 "move.w (%[pal], %%d1.l:2), (%[LCD2]) \n"
581 "subq.l #4,%[cnt] \n"
582 "bne.b .loop \n"
583 : /* outputs */
584 [scrp]"+a"(src),
585 [cnt] "+d"(count)
586 : /* inputs */
587 [pal] "a" (palette),
588 [LCD] "a" (0xf0000000),
589 [LCD2]"a" (0xf0000002)
590 : /* clobbers */
591 "d0", "d1"
593 #elif (CONFIG_LCD == LCD_X5) && !defined(SIMULATOR) \
594 && defined(CPU_COLDFIRE) /* protect from using it on e200 (sic!) */
595 count = SCREENWIDTH*SCREENHEIGHT;
597 /* ASM screen update (drops ~230 tics) */
598 asm volatile (
599 "clr.w (%[LCD]) \n" /* Setup the LCD controller */
600 "move.w #(33<<1), (%[LCD]) \n"
601 "clr.w (%[LCD2]) \n"
602 "clr.w (%[LCD2]) \n"
603 "clr.w (%[LCD]) \n" /* End LCD controller setup */
604 "move.w #(34<<1), (%[LCD]) \n"
605 "clr.l %%d1 \n"
606 ".loop: \n"
607 "move.l (%[scrp])+, %%d0 \n"
608 "swap.w %%d0 \n"
609 "move.w %%d0, %%d1 \n"
610 "lsr.l #8,%%d1 \n"
611 "move.w (%[pal], %%d1.l:2), %%d2 \n"
612 "move.l %%d2, %%d3 \n"
613 "lsr.l #7, %%d3 \n"
614 "move.w %%d3, (%[LCD2]) \n"
615 "lsl.l #1, %%d2 \n"
616 "move.w %%d2, (%[LCD2]) \n"
617 "move.b %%d0,%%d1 \n"
618 "move.w (%[pal], %%d1.l:2), %%d2 \n"
619 "move.l %%d2, %%d3 \n"
620 "lsr.l #7, %%d3 \n"
621 "move.w %%d3, (%[LCD2]) \n"
622 "lsl.l #1, %%d2 \n"
623 "move.w %%d2, (%[LCD2]) \n"
624 "swap.w %%d0 \n"
625 "move.w %%d0, %%d1 \n"
626 "lsr.l #8,%%d1 \n"
627 "move.w (%[pal], %%d1.l:2), %%d2 \n"
628 "move.l %%d2, %%d3 \n"
629 "lsr.l #7, %%d3 \n"
630 "move.w %%d3, (%[LCD2]) \n"
631 "lsl.l #1, %%d2 \n"
632 "move.w %%d2, (%[LCD2]) \n"
633 "move.b %%d0,%%d1 \n"
634 "move.w (%[pal], %%d1.l:2), %%d2 \n"
635 "move.l %%d2, %%d3 \n"
636 "lsr.l #7, %%d3 \n"
637 "move.w %%d3, (%[LCD2]) \n"
638 "lsl.l #1, %%d2 \n"
639 "move.w %%d2, (%[LCD2]) \n"
640 "subq.l #4,%[cnt] \n"
641 "bne.b .loop \n"
642 : /* outputs */
643 [scrp]"+a"(src),
644 [cnt] "+d"(count)
645 : /* inputs */
646 [pal] "a" (palette),
647 [LCD] "a" (0xf0008000),
648 [LCD2]"a" (0xf0008002)
649 : /* clobbers */
650 "d0", "d1", "d2", "d3"
652 #else
653 #ifdef HAVE_LCD_COLOR
654 #if(LCD_HEIGHT>LCD_WIDTH)
655 if(rotate_screen)
657 int y;
659 for (y = 0; y < SCREENHEIGHT; y++)
661 fb_data *dst = rb->lcd_framebuffer + LCD_WIDTH - y;
662 count = SCREENWIDTH;
666 *dst = palette[*src++];
667 dst += LCD_WIDTH;
669 while (--count);
672 else
673 #endif
675 fb_data *dst = rb->lcd_framebuffer;
676 count = SCREENWIDTH*SCREENHEIGHT;
679 *dst++ = palette[*src++];
680 while (--count);
682 rb->lcd_update();
683 #else /* !HAVE_LCD_COLOR */
684 unsigned char *dst;
685 int y;
687 for (y = 0; y < SCREENHEIGHT; y++)
689 dst = greybuffer;
690 count = SCREENWIDTH;
693 *dst++ = palette[*src++];
694 while (--count);
696 grey_ub_gray_bitmap(greybuffer, 0, y, SCREENWIDTH, 1);
698 #endif /* !HAVE_LCD_COLOR */
699 #endif
703 // I_ReadScreen
705 void I_ReadScreen (byte* scr)
707 memcpy (scr, d_screens[0], LCD_WIDTH*LCD_HEIGHT);
711 // I_SetPalette
713 void I_SetPalette (int pal)
715 I_UploadNewPalette(pal);
719 // I_InitGraphics
721 void I_InitGraphics(void)
723 printf("Starting Graphics engine\n");
725 noprintf=1;
727 /* Note: The other screens are allocated as needed */
729 #ifndef HAVE_LCD_COLOR
730 gbuf=malloc(GREYBUFSIZE);
731 grey_init(rb, gbuf, GREYBUFSIZE, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL);
732 /* switch on greyscale overlay */
733 grey_show(true);
734 #endif
736 #ifdef CPU_COLDFIRE
737 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE);
738 d_screens[0] = fastscreen;
739 #else
740 // Don't know if this will fit in other IRAMs
741 d_screens[0] = malloc (LCD_WIDTH * LCD_HEIGHT * sizeof(unsigned char));
742 #endif