home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #2 / amigaacscoverdisc1998-021998.iso / games / doom / adoom / src / amiga_system.c < prev    next >
C/C++ Source or Header  |  1998-01-08  |  5KB  |  192 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdarg.h>
  6. #include <time.h>
  7.  
  8. #include <exec/exec.h>
  9. #include <proto/exec.h>
  10.  
  11. #include "doomdef.h"
  12. #include "m_misc.h"
  13. #include "i_system.h"
  14. #include "i_video.h"
  15. #include "i_sound.h"
  16.  
  17. #include "d_net.h"
  18. #include "g_game.h"
  19. #include "m_argv.h"
  20.  
  21. void amiga_getevents (void);
  22.  
  23. #define MIN_ZONESIZE  (2*1024*1024)
  24. #define MAX_ZONESIZE  (6*1024*1024)
  25.  
  26. /**********************************************************************/
  27. // Called by DoomMain.
  28. void I_Init (void)
  29. {
  30.   int p, taskpriority;
  31.  
  32.   taskpriority = -5;
  33.   p = M_CheckParm ("-taskpriority");
  34.   if (p && p < myargc - 1) {
  35.     taskpriority = atoi (myargv[p+1]);
  36.   }
  37.   SetTaskPri (FindTask(NULL), taskpriority);
  38.  
  39.   I_InitSound ();
  40.   I_InitMusic ();
  41.   //  I_InitGraphics ();
  42. }
  43.  
  44. /**********************************************************************/
  45. // Called by startup code
  46. // to get the ammount of memory to malloc
  47. // for the zone management.
  48. byte*    I_ZoneBase (int *size)
  49. {
  50.   byte *zone;
  51.   ULONG memfree, largest;
  52.  
  53.   memfree = AvailMem (MEMF_FAST);
  54.   largest = AvailMem (MEMF_FAST | MEMF_LARGEST);
  55.   printf ("Memfree = %d, largest = %d\n", memfree, largest);
  56.  
  57.   if (largest > MAX_ZONESIZE + 65536 &&
  58.       memfree > MAX_ZONESIZE + (2 * 1024 * 1024))
  59.     *size = MAX_ZONESIZE;
  60.   else if (memfree < largest + (2 * 1024 * 1024))
  61.     *size = memfree - (2 * 1024 * 1024) - 65536;
  62.   else
  63.     *size = largest - 65536;
  64.  
  65.   if (*size < MIN_ZONESIZE)
  66.     I_Error ("Unable to allocate at least %d fastmem for zone management\n"
  67.              "while leaving 2Mb fastmem free\n"
  68.              "Fastmem free = %d, largest block = %d",
  69.              MIN_ZONESIZE, memfree, largest);
  70.  
  71.   if ((zone = (byte *)malloc(*size)) == NULL)
  72.     I_Error ("malloc() %d bytes for zone management failed", *size);
  73.  
  74.   printf ("I_ZoneBase(): Allocated %d bytes for zone management\n", *size);
  75.  
  76.   return zone;
  77. }
  78.  
  79. /**********************************************************************/
  80. // Called by D_DoomLoop,
  81. // returns current time in tics.
  82. int I_GetTime (void)
  83. {
  84.   int newtics;
  85.   static int basetime=0;
  86.   unsigned int clock[2];
  87.  
  88.   timer (clock);
  89.   if (!basetime)
  90.     basetime = clock[0];
  91.   newtics = (clock[0]-basetime)*TICRATE + clock[1]*TICRATE/1000000;
  92.   return newtics;
  93. }
  94.  
  95. /**********************************************************************/
  96. //
  97. // Called by D_DoomLoop,
  98. // called before processing any tics in a frame
  99. // (just after displaying a frame).
  100. // Time consuming syncronous operations
  101. // are performed here (joystick reading).
  102. // Can call D_PostEvent.
  103. //
  104. void I_StartFrame (void)
  105. {
  106.   amiga_getevents ();
  107. }
  108.  
  109. /**********************************************************************/
  110. //
  111. // Called by D_DoomLoop,
  112. // called before processing each tic in a frame.
  113. // Quick syncronous operations are performed here.
  114. // Can call D_PostEvent.
  115. void I_StartTic (void)
  116. {
  117. }
  118.  
  119. /**********************************************************************/
  120. // Asynchronous interrupt functions should maintain private queues
  121. // that are read by the synchronous functions
  122. // to be converted into events.
  123.  
  124. // Either returns a null ticcmd,
  125. // or calls a loadable driver to build it.
  126. // This ticcmd will then be modified by the gameloop
  127. // for normal input.
  128. ticcmd_t    emptycmd;
  129. ticcmd_t* I_BaseTiccmd (void)
  130. {
  131.   return &emptycmd;
  132. }
  133.  
  134. /**********************************************************************/
  135. // Called by M_Responder when quit is selected.
  136. // Clean exit, displays sell blurb.
  137. void I_Quit (void)
  138. {
  139.   D_QuitNetGame ();
  140.   I_ShutdownSound();
  141.   I_ShutdownMusic();
  142.   M_SaveDefaults ();
  143.   I_ShutdownGraphics();
  144.   exit(0);
  145. }
  146.  
  147. /**********************************************************************/
  148. // Allocates from low memory under dos,
  149. // just mallocs under unix
  150. byte* I_AllocLow (int length)
  151. {
  152.   byte*    mem;
  153.  
  154.   if ((mem = (byte *)malloc (length)) == NULL)
  155.     I_Error ("Out of memory allocating %d bytes", length);
  156.   memset (mem,0,length);
  157.   return mem;
  158. }
  159.  
  160. /**********************************************************************/
  161. void I_Tactile (int on, int off, int total)
  162. {
  163.   // UNUSED.
  164.   on = off = total = 0;
  165. }
  166.  
  167. /**********************************************************************/
  168. void I_Error (char *error, ...)
  169. {
  170.   va_list    argptr;
  171.  
  172.   // Message first.
  173.   va_start (argptr, error);
  174.   fprintf (stderr, "Error: ");
  175.   vfprintf (stderr, error, argptr);
  176.   fprintf (stderr, "\n");
  177.   va_end (argptr);
  178.  
  179.   fflush (stderr);
  180.  
  181.   // Shutdown. Here might be other errors.
  182.   if (demorecording)
  183.     G_CheckDemoStatus ();
  184.  
  185.   D_QuitNetGame ();
  186.   I_ShutdownGraphics ();
  187.  
  188.   exit (20);
  189. }
  190.  
  191. /**********************************************************************/
  192.