1 /* Emacs style mode select -*- C++ -*-
2 *-----------------------------------------------------------------------------
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.
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
76 * Revision 1.7 2006-04-03 16:30:12 kkurbjun
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
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.
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"
117 #include "rockmacros.h"
119 #ifndef HAVE_LCD_COLOR
120 #include "../lib/gray.h"
121 static unsigned char graybuffer
[8*LCD_WIDTH
] IBSS_ATTR
; /* off screen buffer */
122 static unsigned char *gbuf
;
123 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
124 #define GRAYBUFSIZE (((LCD_WIDTH+7)/8)*LCD_HEIGHT*32+200)
126 #define GRAYBUFSIZE (LCD_WIDTH*((LCD_HEIGHT+7)/8)*32+200)
130 #if defined(CPU_COLDFIRE)
131 static char fastscreen
[LCD_WIDTH
*LCD_HEIGHT
] IBSS_ATTR
;
134 static fb_data palette
[256] IBSS_ATTR
;
135 static fb_data
*paldata
=NULL
;
138 // I_ShutdownGraphics
140 void I_ShutdownGraphics(void)
142 #ifndef HAVE_LCD_COLOR
152 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
153 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
154 //#define DOOMBUTTON_SCROLLWHEEL
155 #define DOOMBUTTON_UP BUTTON_MENU
156 #define DOOMBUTTON_WEAPON BUTTON_SELECT
157 #define DOOMBUTTON_LEFT BUTTON_LEFT
158 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
159 #define DOOMBUTTON_SHOOT BUTTON_PLAY
160 #define DOOMBUTTON_ENTER BUTTON_SELECT
161 #define DOOMBUTTON_OPEN BUTTON_MENU
162 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
163 #define DOOMBUTTON_UP BUTTON_UP
164 #define DOOMBUTTON_DOWN BUTTON_DOWN
165 #define DOOMBUTTON_LEFT BUTTON_LEFT
166 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
167 #define DOOMBUTTON_SHOOT BUTTON_SELECT
168 #define DOOMBUTTON_OPEN BUTTON_PLAY
169 #define DOOMBUTTON_ESC BUTTON_POWER
170 #define DOOMBUTTON_ENTER BUTTON_SELECT
171 #define DOOMBUTTON_WEAPON BUTTON_REC
172 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
173 #define DOOMBUTTON_UP BUTTON_SCROLL_UP
174 #define DOOMBUTTON_DOWN BUTTON_SCROLL_DOWN
175 #define DOOMBUTTON_LEFT BUTTON_LEFT
176 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
177 #define DOOMBUTTON_SHOOT BUTTON_REW
178 #define DOOMBUTTON_OPEN BUTTON_PLAY
179 #define DOOMBUTTON_ESC BUTTON_POWER
180 #define DOOMBUTTON_ENTER BUTTON_REW
181 #define DOOMBUTTON_WEAPON BUTTON_FF
182 #elif CONFIG_KEYPAD == SANSA_E200_PAD
183 #define DOOMBUTTON_SCROLLWHEEL
184 #define DOOMBUTTON_SCROLLWHEEL_CC BUTTON_SCROLL_UP
185 #define DOOMBUTTON_SCROLLWHEEL_CW BUTTON_SCROLL_DOWN
186 #define DOOMBUTTON_UP BUTTON_UP
187 #define DOOMBUTTON_DOWN BUTTON_DOWN
188 #define DOOMBUTTON_LEFT BUTTON_LEFT
189 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
190 #define DOOMBUTTON_SHOOT BUTTON_SELECT
191 #define DOOMBUTTON_OPEN BUTTON_REC
192 #define DOOMBUTTON_ESC BUTTON_POWER
193 #define DOOMBUTTON_ENTER BUTTON_SELECT
194 #define DOOMBUTTON_WEAPON DOOMBUTTON_SCROLLWHEEL_CW
195 #elif CONFIG_KEYPAD == SANSA_C200_PAD
196 #define DOOMBUTTON_UP BUTTON_UP
197 #define DOOMBUTTON_DOWN BUTTON_DOWN
198 #define DOOMBUTTON_LEFT BUTTON_LEFT
199 #define DOOMBUTTON_RIGHT BUTTON_RIGHT
200 #define DOOMBUTTON_SHOOT BUTTON_SELECT
201 #define DOOMBUTTON_OPEN BUTTON_REC
202 #define DOOMBUTTON_ESC BUTTON_POWER
203 #define DOOMBUTTON_ENTER BUTTON_SELECT
204 #define DOOMBUTTON_WEAPON BUTTON_VOL_UP
205 #elif CONFIG_KEYPAD == GIGABEAT_PAD
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_A
211 #define DOOMBUTTON_OPEN BUTTON_MENU
212 #define DOOMBUTTON_ESC BUTTON_POWER
213 #define DOOMBUTTON_ENTER BUTTON_SELECT
214 #define DOOMBUTTON_WEAPON BUTTON_VOL_DOWN
215 #define DOOMBUTTON_MAP BUTTON_VOL_UP
216 #elif CONFIG_KEYPAD == MROBE500_PAD
217 #define DOOMBUTTON_ESC BUTTON_POWER
218 #define DOOMBUTTON_UP BUTTON_RC_PLAY
219 #define DOOMBUTTON_DOWN BUTTON_RC_DOWN
220 #define DOOMBUTTON_LEFT BUTTON_RC_REW
221 #define DOOMBUTTON_RIGHT BUTTON_RC_FF
222 #define DOOMBUTTON_OPEN BUTTON_RC_VOL_DOWN
223 #define DOOMBUTTON_SHOOT BUTTON_RC_VOL_UP
224 #define DOOMBUTTON_ENTER BUTTON_RC_MODE
225 #define DOOMBUTTON_WEAPON BUTTON_RC_HEART
226 #elif CONFIG_KEYPAD == IRIVER_H100_PAD || \
227 CONFIG_KEYPAD == IRIVER_H300_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_REC
233 #define DOOMBUTTON_OPEN BUTTON_MODE
234 #define DOOMBUTTON_ESC BUTTON_OFF
235 #define DOOMBUTTON_ENTER BUTTON_SELECT
236 #define DOOMBUTTON_WEAPON BUTTON_ON
238 #error Keymap not defined!
241 #ifdef DOOMBUTTON_SCROLLWHEEL
242 /* Scrollwheel events are posted directly and not polled by the button
243 driver - synthesize polling */
244 static inline unsigned int read_scroll_wheel(void)
246 unsigned int buttons
= BUTTON_NONE
;
249 /* Empty out the button queue and see if any scrollwheel events were
253 btn
= rb
->button_get_w_tmo(0);
256 while (btn
!= BUTTON_NONE
);
258 return buttons
& (DOOMBUTTON_SCROLLWHEEL_CC
| DOOMBUTTON_SCROLLWHEEL_CW
);
265 /* Same button handling as rockboy */
266 static unsigned int oldbuttonstate IDATA_ATTR
= 0;
268 unsigned int released
, pressed
, newbuttonstate
;
270 #ifdef HAS_BUTTON_HOLD
271 static unsigned int holdbutton IDATA_ATTR
=0;
272 static bool hswitch IDATA_ATTR
=0;
273 if (rb
->button_hold()&~holdbutton
)
277 event
.type
= ev_keydown
;
282 event
.type
= ev_keyup
;
285 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
286 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
287 /* Bring up the menu */
288 event
.data1
=KEY_ESCAPE
;
291 event
.data1
=KEY_CAPSLOCK
;
295 holdbutton
=rb
->button_hold();
298 newbuttonstate
= rb
->button_status();
299 #ifdef DOOMBUTTON_SCROLLWHEEL
300 newbuttonstate
|= read_scroll_wheel();
303 if(newbuttonstate
==oldbuttonstate
) /* Don't continue, nothing left to do */
305 released
= ~newbuttonstate
& oldbuttonstate
;
306 pressed
= newbuttonstate
& ~oldbuttonstate
;
307 oldbuttonstate
= newbuttonstate
;
310 event
.type
= ev_keyup
;
311 if(released
& DOOMBUTTON_LEFT
)
313 event
.data1
=KEY_LEFTARROW
;
316 if(released
& DOOMBUTTON_RIGHT
)
318 event
.data1
=KEY_RIGHTARROW
;
321 #ifdef DOOMBUTTON_DOWN
322 if(released
& DOOMBUTTON_DOWN
)
324 event
.data1
=KEY_DOWNARROW
;
328 if(released
& DOOMBUTTON_UP
)
330 event
.data1
=KEY_UPARROW
;
333 if(released
& DOOMBUTTON_SHOOT
)
335 event
.data1
=KEY_RCTRL
;
338 if(released
& DOOMBUTTON_OPEN
)
343 #ifdef DOOMBUTTON_ESC
344 if(released
& DOOMBUTTON_ESC
)
346 event
.data1
=KEY_ESCAPE
;
350 if(released
& DOOMBUTTON_ENTER
)
352 event
.data1
=KEY_ENTER
;
355 #ifdef DOOMBUTTON_WEAPON
356 if(released
& DOOMBUTTON_WEAPON
)
362 #ifdef DOOMBUTTON_MAP
363 if(released
& DOOMBUTTON_MAP
)
365 event
.data1
=KEY_TAB
;
372 event
.type
= ev_keydown
;
373 if(pressed
& DOOMBUTTON_LEFT
)
375 event
.data1
=KEY_LEFTARROW
;
378 if(pressed
& DOOMBUTTON_RIGHT
)
380 event
.data1
=KEY_RIGHTARROW
;
383 #ifdef DOOMBUTTON_DOWN
384 if(pressed
& DOOMBUTTON_DOWN
)
386 event
.data1
=KEY_DOWNARROW
;
390 if(pressed
& DOOMBUTTON_UP
)
392 event
.data1
=KEY_UPARROW
;
395 if(pressed
& DOOMBUTTON_SHOOT
)
397 event
.data1
=KEY_RCTRL
;
400 if(pressed
& DOOMBUTTON_OPEN
)
405 #ifdef DOOMBUTTON_ESC
406 if(pressed
& DOOMBUTTON_ESC
)
408 event
.data1
=KEY_ESCAPE
;
412 #ifdef DOOMBUTTON_ENTER
413 if(pressed
& DOOMBUTTON_ENTER
)
415 event
.data1
=KEY_ENTER
;
419 #ifdef DOOMBUTTON_WEAPON
420 if(pressed
& DOOMBUTTON_WEAPON
)
426 #ifdef DOOMBUTTON_MAP
427 if(pressed
& DOOMBUTTON_MAP
)
429 event
.data1
=KEY_TAB
;
436 inline void I_StartTic (void)
442 ///////////////////////////////////////////////////////////
445 static void I_UploadNewPalette(int pal
)
447 // This is used to replace the current 256 colour cmap with a new one
448 // Used by 256 colour PseudoColor modes
449 static int cachedgamma
;
450 static size_t num_pals
;
452 if ((paldata
== NULL
) || (cachedgamma
!= usegamma
)) {
453 int lump
= W_GetNumForName("PLAYPAL");
454 const byte
*pall
= W_CacheLumpNum(lump
);
455 register const byte
*const gtable
= gammatable
[cachedgamma
= usegamma
];
458 num_pals
= W_LumpLength(lump
) / (3*256);
462 // First call - allocate and prepare colour array
463 paldata
= malloc(sizeof(*paldata
)*num_pals
);
466 // set the colormap entries
467 for (i
=0 ; (size_t)i
<num_pals
; i
++) {
468 int r
= gtable
[pall
[0]];
469 int g
= gtable
[pall
[1]];
470 int b
= gtable
[pall
[2]];
472 #ifndef HAVE_LCD_COLOR
473 paldata
[i
]=(3*r
+6*g
+b
)/10;
475 paldata
[i
] = LCD_RGBPACK(r
,g
,b
);
479 W_UnlockLumpNum(lump
);
484 if ((size_t)pal
>= num_pals
)
485 I_Error("I_UploadNewPalette: Palette number out of range (%d>=%d)",
488 memcpy(palette
,paldata
+256*pal
,256*sizeof(fb_data
));
496 void I_FinishUpdate (void)
498 #if (CONFIG_LCD == LCD_H300) && !defined(SIMULATOR)
501 /* ASM screen update (drops 200 tics (100 asm)) */
503 "move.w #33,(%[LCD]) \n" /* Setup the LCD controller */
505 "move.w #34,(%[LCD]) \n" /* End LCD controller setup */
509 "move.l (%[screenptr])+, %%d0 \n"
511 "move.w %%d0, %%d1 \n"
513 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
514 "move.b %%d0,%%d1 \n"
515 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
517 "move.w %%d0, %%d1 \n"
519 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
520 "move.b %%d0,%%d1 \n"
521 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
522 "subq.l #4,%[WIDTH] \n"
524 "move.w #220,%[WIDTH] \n"
525 "subq.l #1,%[HEIGHT] \n"
529 [screenptr
] "a" (d_screens
[0]),
530 [palette
] "a" (palette
),
531 [LCD
] "a" (0xf0000000),
532 [LCD2
] "a" (0xf0000002),
539 /* C version of above (drops 100 tics) */
542 *(volatile unsigned short *) 0xf0000000 = 0x21; // register
543 *(volatile unsigned short *) 0xf0000002 = 0; // value
544 *(volatile unsigned short *) 0xf0000000 = 0x22; // GRAM
546 unsigned char *screenptr
=d_screens
[0];
547 int hcnt
=LCD_HEIGHT
*LCD_WIDTH
;
551 *(volatile unsigned short *)0xf0000002 = palette
[*screenptr
];
557 unsigned char paletteIndex
;
560 #ifdef HAVE_LCD_COLOR
561 #if(LCD_HEIGHT>LCD_WIDTH)
565 for (y
=0; y
<LCD_HEIGHT
; y
++)
567 for (x
=0; x
< LCD_WIDTH
; x
++)
569 paletteIndex
= d_screens
[0][SCREENWIDTH
*(SCREENHEIGHT
-1-x
) + y
];
570 rb
->lcd_framebuffer
[y
*LCD_WIDTH
+ x
] = palette
[paletteIndex
];
576 for (y
= 0; y
< LCD_HEIGHT
*LCD_WIDTH
; y
++)
578 paletteIndex
= d_screens
[0][y
];
579 rb
->lcd_framebuffer
[y
] = palette
[paletteIndex
];
582 #else /* !HAVE_LCD_COLOR */
585 for (y
= 0; y
< SCREENHEIGHT
; y
++)
587 for (x
= 0; x
< SCREENWIDTH
; x
++)
589 paletteIndex
= d_screens
[0][y
*SCREENWIDTH
+ x
];
590 graybuffer
[yd
* SCREENWIDTH
+ x
]=palette
[paletteIndex
];
594 gray_ub_gray_bitmap(graybuffer
, 0, y
& ~7, SCREENWIDTH
, 8);
599 gray_ub_gray_bitmap(graybuffer
, 0, y
& ~7, SCREENWIDTH
, yd
);
600 #endif /* !HAVE_LCD_COLOR */
607 void I_ReadScreen (byte
* scr
)
609 memcpy (scr
, d_screens
[0], LCD_WIDTH
*LCD_HEIGHT
);
615 void I_SetPalette (int pal
)
617 I_UploadNewPalette(pal
);
623 void I_InitGraphics(void)
625 printf("Starting Graphics engine\n");
629 /* Note: The other screens are allocated as needed */
631 #ifndef HAVE_LCD_COLOR
632 gbuf
=malloc(GRAYBUFSIZE
);
633 gray_init(rb
, gbuf
, GRAYBUFSIZE
, false, LCD_WIDTH
, LCD_HEIGHT
, 32,
634 3<<7 /* 1.5 */, NULL
);
635 /* switch on grayscale overlay */
640 coldfire_set_macsr(EMAC_FRACTIONAL
| EMAC_SATURATE
);
641 d_screens
[0] = fastscreen
;
643 // Don't know if this will fit in other IRAMs
644 d_screens
[0] = malloc (LCD_WIDTH
* LCD_HEIGHT
* sizeof(unsigned char));