summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Kurbjun <kkurbjun@gmail.com>2006-04-20 19:39:56 +0000
committerKarl Kurbjun <kkurbjun@gmail.com>2006-04-20 19:39:56 +0000
commit29ab31e8f1c68dd89dad1e9a92fe3c8a8dd223a9 (patch)
tree304b247322f0adefca4c27d1bf7c5a8cfe1a44e8
parent9e9921b08731367ebcaf19976d8e4c6c2534a016 (diff)
downloadrockbox-29ab31e8f1c68dd89dad1e9a92fe3c8a8dd223a9.tar.gz
rockbox-29ab31e8f1c68dd89dad1e9a92fe3c8a8dd223a9.zip
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
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9747 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/doom/i_sound.c44
-rw-r--r--apps/plugins/doom/i_video.c48
-rw-r--r--apps/plugins/doom/m_fixed.h12
-rw-r--r--apps/plugins/doom/r_draw.c53
4 files changed, 107 insertions, 50 deletions
diff --git a/apps/plugins/doom/i_sound.c b/apps/plugins/doom/i_sound.c
index 7579ada5b5..271444527f 100644
--- a/apps/plugins/doom/i_sound.c
+++ b/apps/plugins/doom/i_sound.c
@@ -48,11 +48,11 @@
48// mixing buffer, and the samplerate of the raw data. 48// mixing buffer, and the samplerate of the raw data.
49 49
50// Needed for calling the actual sound output. 50// Needed for calling the actual sound output.
51#define SAMPLECOUNT 512 51#define SAMPLECOUNT 512
52 52
53#define NUM_CHANNELS 16 53#define NUM_CHANNELS 16
54// It is 2 for 16bit, and 2 for two channels. 54// It is 2 for 16bit, and 2 for two channels.
55#define BUFMUL 4 55#define BUFMUL 2
56#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL) 56#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL)
57 57
58#if (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD) 58#if (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD)
@@ -66,7 +66,7 @@
66// Basically, samples from all active internal channels 66// Basically, samples from all active internal channels
67// are modifed and added, and stored in the buffer 67// are modifed and added, and stored in the buffer
68// that is submitted to the audio device. 68// that is submitted to the audio device.
69signed short *mixbuffer=NULL; 69signed short mixbuffer[MIXBUFFERSIZE] IBSS_ATTR;
70 70
71typedef struct { 71typedef struct {
72 // SFX id of the playing sound effect. 72 // SFX id of the playing sound effect.
@@ -91,7 +91,7 @@ typedef struct {
91 int *rightvol_lookup; 91 int *rightvol_lookup;
92} channel_info_t; 92} channel_info_t;
93 93
94channel_info_t channelinfo[NUM_CHANNELS]; 94channel_info_t channelinfo[NUM_CHANNELS] IBSS_ATTR;
95 95
96int *vol_lookup; // Volume lookups. 96int *vol_lookup; // Volume lookups.
97 97
@@ -355,13 +355,6 @@ int I_SoundIsPlaying(int handle)
355// This function currently supports only 16bit. 355// This function currently supports only 16bit.
356// 356//
357 357
358bool swap=0;
359bool lastswap=1;
360 // Pointers in global mixbuffer, left, right, end.
361 signed short* leftout;
362 signed short* rightout;
363 signed short* leftend;
364
365void I_UpdateSound( void ) 358void I_UpdateSound( void )
366{ 359{
367 // Mix current sound data. 360 // Mix current sound data.
@@ -370,25 +363,26 @@ void I_UpdateSound( void )
370 register int dl; 363 register int dl;
371 register int dr; 364 register int dr;
372 365
366 // Pointers in global mixbuffer, left, right, end.
367 signed short* leftout;
368 signed short* rightout;
369 signed short* leftend;
370
373 // Step in mixbuffer, left and right, thus two. 371 // Step in mixbuffer, left and right, thus two.
374 int step; 372 int step;
375 373
376 // Mixing channel index. 374 // Mixing channel index.
377 int chan; 375 int chan;
378 376
379 if(lastswap==swap)
380 return;
381 lastswap=swap;
382
383 // Left and right channel 377 // Left and right channel
384 // are in global mixbuffer, alternating. 378 // are in global mixbuffer, alternating.
385 leftout = (swap ? mixbuffer : mixbuffer + SAMPLECOUNT*2); 379 leftout = mixbuffer;
386 rightout = (swap ? mixbuffer : mixbuffer + SAMPLECOUNT*2)+1; 380 rightout = mixbuffer +1;
387 step = 2; 381 step = 2;
388 382
389 // Determine end, for left channel only 383 // Determine end, for left channel only
390 // (right channel is implicit). 384 // (right channel is implicit).
391 leftend = (swap ? mixbuffer : mixbuffer + SAMPLECOUNT*2) + SAMPLECOUNT*step; 385 leftend = mixbuffer + SAMPLECOUNT*step;
392 386
393 // Mix sounds into the mixing buffer. 387 // Mix sounds into the mixing buffer.
394 // Loop over step*SAMPLECOUNT, 388 // Loop over step*SAMPLECOUNT,
@@ -467,15 +461,10 @@ void I_UpdateSound( void )
467 461
468void get_more(unsigned char** start, size_t* size) 462void get_more(unsigned char** start, size_t* size)
469{ 463{
470 // This code works fine, the only problem is that doom runs slower then the sound 464 I_UpdateSound(); // Force sound update
471 // updates (sometimes). This code forces the update if the sound hasn't been
472 // remixed.
473 if(lastswap!=swap)
474 I_UpdateSound(); // Force sound update (We don't want stutters)
475 465
476 *start = (unsigned char*)((swap ? mixbuffer : mixbuffer + SAMPLECOUNT*2)); 466 *start = (unsigned char*)(mixbuffer);
477 *size = SAMPLECOUNT*2*sizeof(short); 467 *size = SAMPLECOUNT*2*sizeof(short);
478 swap=!swap;
479} 468}
480 469
481 470
@@ -520,9 +509,6 @@ void I_InitSound()
520 509
521 printf( " pre-cached all sound data\n"); 510 printf( " pre-cached all sound data\n");
522 511
523 if(mixbuffer==NULL)
524 mixbuffer=malloc(sizeof(short)*MIXBUFFERSIZE);
525
526 // Now initialize mixbuffer with zero. 512 // Now initialize mixbuffer with zero.
527 for ( i = 0; i< MIXBUFFERSIZE; i++ ) 513 for ( i = 0; i< MIXBUFFERSIZE; i++ )
528 mixbuffer[i] = 0; 514 mixbuffer[i] = 0;
diff --git a/apps/plugins/doom/i_video.c b/apps/plugins/doom/i_video.c
index a4db5f2672..db6adfa75e 100644
--- a/apps/plugins/doom/i_video.c
+++ b/apps/plugins/doom/i_video.c
@@ -16,7 +16,10 @@
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * $Log$ 18 * $Log$
19 * Revision 1.15 2006/04/16 23:14:04 kkurbjun 19 * Revision 1.16 2006/04/20 19:39:56 kkurbjun
20 * 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
21 *
22 * Revision 1.15 2006-04-16 23:14:04 kkurbjun
20 * Fix run so that it stays enabled across level loads. Removed some unused code and added some back in for hopeful future use. 23 * Fix run so that it stays enabled across level loads. Removed some unused code and added some back in for hopeful future use.
21 * 24 *
22 * Revision 1.14 2006-04-15 22:08:36 kkurbjun 25 * Revision 1.14 2006-04-15 22:08:36 kkurbjun
@@ -359,10 +362,43 @@ static void I_UploadNewPalette(int pal)
359void I_FinishUpdate (void) 362void I_FinishUpdate (void)
360{ 363{
361#if (CONFIG_LCD == LCD_H300) && !defined(SIMULATOR) 364#if (CONFIG_LCD == LCD_H300) && !defined(SIMULATOR)
362 /* 365
363 Lookup tables are no longer needed (H300 specific, decreases timedemo 366#if 1
364 by about 500 tics) 367 /* ASM screen update (drops 600 tics (100 asm)) */
365 */ 368 asm (
369 "move.w #33,(%[LCD]) \n" /* Setup the LCD controller */
370 "clr.w (%[LCD2]) \n"
371 "move.w #34,(%[LCD]) \n" /* End LCD controller setup */
372 "move.l #220,%%d2 \n"
373 "move.l #176,%%d3 \n"
374 "clr.l %%d1 \n"
375 "widthloop: \n"
376 "move.b (%[screenptr])+, %%d1 \n" /* Unrolled by 5 */
377 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
378 "move.b (%[screenptr])+, %%d1 \n"
379 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
380 "move.b (%[screenptr])+, %%d1 \n"
381 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
382 "move.b (%[screenptr])+, %%d1 \n"
383 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
384 "move.b (%[screenptr])+, %%d1 \n"
385 "move.w (%[palette], %%d1.l:2), (%[LCD2]) \n"
386 "subq.l #5,%%d2 \n"
387 "bne widthloop \n"
388 "move.w #220,%%d2 \n"
389 "subq.l #1,%%d3 \n"
390 "bne widthloop \n"
391 : /* outputs */
392 : /* inputs */
393 [screenptr] "a" (d_screens[0]),
394 [palette] "a" (palette),
395 [LCD] "a" (0xf0000000),
396 [LCD2] "a" (0xf0000002)
397 : /* clobbers */
398 "d1", "d2", "d3"
399 );
400#else
401 /* C version of above (drops 500 tics) */
366 402
367 // Start the write 403 // Start the write
368 *(volatile unsigned short *) 0xf0000000 = 0x21; // register 404 *(volatile unsigned short *) 0xf0000000 = 0x21; // register
@@ -383,6 +419,8 @@ void I_FinishUpdate (void)
383 wcnt=0; 419 wcnt=0;
384 hcnt++; 420 hcnt++;
385 } 421 }
422#endif
423
386#else 424#else
387 unsigned char paletteIndex; 425 unsigned char paletteIndex;
388 int x, y; 426 int x, y;
diff --git a/apps/plugins/doom/m_fixed.h b/apps/plugins/doom/m_fixed.h
index 3c922e8f50..e29933befd 100644
--- a/apps/plugins/doom/m_fixed.h
+++ b/apps/plugins/doom/m_fixed.h
@@ -47,15 +47,15 @@ inline static int FixedMul( int a, int b )
47#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) 47#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
48 // Code contributed by Thom Johansen 48 // Code contributed by Thom Johansen
49 register int result; 49 register int result;
50 asm volatile ( 50 asm (
51 "mac.l %[x],%[y],%%acc0 \n" /* multiply */ 51 "mac.l %[x],%[y],%%acc0 \n" /* multiply */
52 "move.l %[y],%%d2 \n" 52 "move.l %[y],%%d2 \n"
53 "mulu.l %[x],%%d2 \n" /* get lower half, avoid emac stall */ 53 "mulu.l %[x],%%d2 \n" /* get lower half, avoid emac stall */
54 "movclr.l %%acc0,%[result] \n" /* get higher half */ 54 "movclr.l %%acc0,%[result] \n" /* get higher half */
55 "moveq.l #15,%%d1 \n" 55 "asl.l #8,%[result] \n" /* hi <<= 15, plus one free */
56 "asl.l %%d1,%[result] \n" /* hi <<= 15, plus one free */ 56 "asl.l #7,%[result] \n" /* hi <<= 15, plus one free */
57 "moveq.l #16,%%d1 \n" 57 "lsr.l #8,%%d2 \n" /* (unsigned)lo >>= 16 */
58 "lsr.l %%d1,%%d2 \n" /* (unsigned)lo >>= 16 */ 58 "lsr.l #8,%%d2 \n" /* (unsigned)lo >>= 16 */
59 "or.l %%d2 ,%[result] \n" /* combine result */ 59 "or.l %%d2 ,%[result] \n" /* combine result */
60 : /* outputs */ 60 : /* outputs */
61 [result]"=&d"(result) 61 [result]"=&d"(result)
@@ -63,7 +63,7 @@ inline static int FixedMul( int a, int b )
63 [x] "d" (a), 63 [x] "d" (a),
64 [y] "d" (b) 64 [y] "d" (b)
65 : /* clobbers */ 65 : /* clobbers */
66 "d1", "d2" 66 "d2"
67 ); 67 );
68 return result; 68 return result;
69#else 69#else
diff --git a/apps/plugins/doom/r_draw.c b/apps/plugins/doom/r_draw.c
index a6bc21e420..5f45323a36 100644
--- a/apps/plugins/doom/r_draw.c
+++ b/apps/plugins/doom/r_draw.c
@@ -526,16 +526,48 @@ byte *ds_source IBSS_ATTR;
526 526
527void R_DrawSpan (void) 527void R_DrawSpan (void)
528{ 528{
529 register unsigned count,xfrac = ds_xfrac,yfrac = ds_yfrac; 529#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
530 530 // only slightly faster
531 byte *source; 531 asm volatile (
532 byte *colormap; 532 "tst %[count] \n"
533 byte *dest; 533 "beq endspanloop \n"
534 534 "clr.l %%d4 \n"
535 source = ds_source; 535 "spanloop: \n"
536 colormap = ds_colormap; 536 "move.l %[xfrac], %%d1 \n"
537 dest = topleft + ds_y*SCREENWIDTH + ds_x1; 537 "move.l %[yfrac], %%d2 \n"
538 count = ds_x2 - ds_x1 + 1; 538 "lsr.l #8,%%d1 \n"
539 "lsr.l #8,%%d2 \n"
540 "lsr.l #8,%%d1 \n"
541 "lsr.l #2,%%d2 \n"
542 "and.l #63,%%d1 \n"
543 "and.l #4032,%%d2 \n"
544 "or.l %%d2, %%d1 \n"
545 "move.b (%[source], %%d1), %%d4 \n"
546 "add.l %[ds_xstep], %[xfrac] \n"
547 "add.l %[ds_ystep], %[yfrac] \n"
548 "move.b (%[colormap],%%d4.l), (%[dest])+ \n"
549 "subq.l #1, %[count] \n"
550 "bne spanloop \n"
551 "endspanloop: \n"
552 : /* outputs */
553 : /* inputs */
554 [count] "d" (ds_x2-ds_x1+1),
555 [xfrac] "d" (ds_xfrac),
556 [yfrac] "d" (ds_yfrac),
557 [source] "a" (ds_source),
558 [colormap] "a" (ds_colormap),
559 [dest] "a" (topleft+ds_y*SCREENWIDTH +ds_x1),
560 [ds_xstep] "d" (ds_xstep),
561 [ds_ystep] "d" (ds_ystep)
562 : /* clobbers */
563 "d1", "d2", "d4"
564 );
565#else
566 register unsigned count = ds_x2 - ds_x1 + 1,xfrac = ds_xfrac,yfrac = ds_yfrac;
567
568 register byte *source = ds_source;
569 register byte *colormap = ds_colormap;
570 register byte *dest = topleft + ds_y*SCREENWIDTH + ds_x1;
539 571
540 while (count) 572 while (count)
541 { 573 {
@@ -550,6 +582,7 @@ void R_DrawSpan (void)
550 *dest++ = colormap[source[spot]]; 582 *dest++ = colormap[source[spot]];
551 count--; 583 count--;
552 } 584 }
585#endif
553} 586}
554 587
555// 588//