home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / digicomp.c < prev    next >
Text File  |  1998-06-08  |  3KB  |  121 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/digicomp.c $
  15.  * $Revision: 2.0 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 11:33:04 $
  18.  * 
  19.  * Routines for manipulating digi samples.
  20.  * 
  21.  * $Log: digicomp.c $
  22.  * Revision 2.0  1995/02/27  11:33:04  john
  23.  * New version 2.0, which has no anonymous unions, builds with
  24.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25.  * 
  26.  * Revision 1.2  1994/12/07  18:42:21  john
  27.  * Initial, unused version..
  28.  * 
  29.  * Revision 1.1  1994/12/05  09:37:13  john
  30.  * Initial revision
  31.  * 
  32.  * 
  33.  */
  34.  
  35.  
  36. #pragma off (unreferenced)
  37. static char rcsid[] = "$Id: digicomp.c 2.0 1995/02/27 11:33:04 john Exp $";
  38. #pragma on (unreferenced)
  39.  
  40. #include "soscomp.h"
  41.  
  42. #pragma pack (4);                        // Use 32-bit packing!
  43. #pragma off (check_stack);            // No stack checking!
  44. #include "sos.h"
  45. #include "sosm.h"
  46.  
  47. ubyte digicomp_initialized = 0;
  48.  
  49. #define MAX_DIGI_BLOCKS 32
  50. ubyte * digicomp_memory[ MAX_DIGI_MEMORY ];
  51. int N_blocks = 0;
  52. int Next_block = 0;
  53.  
  54. typedef struct digi_block {
  55.     int offset;
  56.     int len;
  57.     int soundno;
  58. } digi_block;
  59.  
  60. digi_block Digi_blocks[MAX_DIGI_BLOCKS];
  61.  
  62. void digicomp_init()
  63. {
  64.     int i;
  65.  
  66.     if ( digicomp_initialized  ) return;
  67.     digicomp_initialized = 1;
  68.  
  69.     Digi_blocks[0].len = MAX_DIGI_MEMORY;
  70.     Digi_blocks[0].offset = 0;
  71.     Digi_blocks[0].soundno = -1;
  72.     N_blocks = 1;
  73.  
  74.     for (i=1; i<MAX_DIGI_BLOCKS; i++ )    {
  75.         Digi_blocks[i].len = 0;
  76.         Digi_blocks[i].offset = 0;
  77.         Digi_blocks[i].soundno = -1;
  78.     }    
  79. }
  80.  
  81. ubyte * digicomp_get_data(int soundnum)
  82. {
  83.     int mysize;
  84.     int i;
  85.     if ( !digicomp_initialized ) digicomp_init();
  86.  
  87.     // See if this sound already exists...
  88.     for (i=0; i<MAX_DIGI_BLOCKS; i++ )    {
  89.         Digi_blocks[i].len = 0;
  90.         Digi_blocks[i].offset = 0;
  91.         if ( Digi_blocks[i].soundno == soundnum )    {
  92.             return &digicomp_memory[Digi_blocks[i].offset];
  93.         }
  94.     }
  95.     
  96.     // It doesn't exits, so look for the next unused hole that this data can fit into...
  97.     mysize = (Sounds[soundnum].length+1)/2;
  98.     i = Next_block;
  99.     
  100.     while( ((Digi_blocks[i].soundno >-1) && (  Digi_blocks[i].len < mysize ) )    {
  101.         i++;
  102.         if ( i > MAX_DIGI_BLOCKS )
  103.             i = 0;
  104.         if ( i == Next_block ) {
  105.             // An unused block that this can fit into wasn't found, so find the next one it can fit into
  106.             // and stop it...
  107.             return NULL;
  108.         }
  109.     }
  110.  
  111.     
  112.     
  113.         
  114.     
  115.  
  116. }
  117.  
  118.  
  119.  
  120. 
  121.