fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / Games / Doom / amiga_system.c
blobd071cc1171ee6cc74751916abc6f072e6a35a254
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdarg.h>
6 #include <time.h>
8 #include <exec/exec.h>
9 #include <dos/dos.h>
10 #include <dos/dosextens.h>
11 #include <graphics/gfx.h>
12 #include <graphics/gfxbase.h>
13 #include <intuition/intuition.h>
14 #include <intuition/intuitionbase.h>
15 #include <proto/exec.h>
16 //#include <powerup/clib/ppc_protos.h>
18 #include "doomdef.h"
19 #include "m_misc.h"
20 #include "i_system.h"
21 #include "i_video.h"
22 #include "i_sound.h"
24 #include "d_net.h"
25 #include "g_game.h"
26 #include "m_argv.h"
28 extern void ppctimer (unsigned int *time);
29 extern double tb_scale_lo;
30 extern double tb_scale_hi;
32 extern byte *vid_mem;
34 void amiga_getevents (void);
36 #define MIN_ZONESIZE (2*1024*1024)
37 #define MAX_ZONESIZE (6*1024*1024)
39 /**********************************************************************/
41 extern struct ExecBase *SysBase;
42 extern struct DosLibrary *DOSBase;
43 struct GfxBase *GfxBase;
44 struct IntuitionBase *IntuitionBase;
46 /**********************************************************************/
47 // Called by DoomMain.
48 void I_Init (void)
50 if ((GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 39)) == NULL)
51 I_Error ("OpenLibrary(""graphics.library"", 39) failed");
52 if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 39)) == NULL)
53 I_Error ("OpenLibrary(""intuition.library"", 39) failed");
55 I_InitSound ();
56 I_InitMusic ();
57 // I_InitGraphics ();
60 /**********************************************************************/
61 // Called by startup code
62 // to get the ammount of memory to malloc
63 // for the zone management.
64 byte* I_ZoneBase (int *size)
66 byte *zone;
67 ULONG memfree, largest;
68 int p;
70 memfree = AvailMem (MEMF_FAST);
71 largest = AvailMem (MEMF_FAST | MEMF_LARGEST);
72 printf ("Memfree = %d, largest = %d\n", memfree, largest);
74 p = M_CheckParm ("-heapsize");
75 if (p && p < myargc - 1) {
77 *size = 1024 * atoi (myargv[p+1]);
79 } else {
81 if (largest > MAX_ZONESIZE + 65536 &&
82 memfree > MAX_ZONESIZE + (2 * 1024 * 1024))
83 *size = MAX_ZONESIZE;
84 else if (memfree < largest + (2 * 1024 * 1024))
85 *size = memfree - (2 * 1024 * 1024) - 65536;
86 else
87 *size = largest - 65536;
89 if (*size < MIN_ZONESIZE)
90 I_Error ("Unable to allocate at least %d fastmem for zone management\n"
91 "while leaving 2Mb fastmem free\n"
92 "Fastmem free = %d, largest block = %d",
93 MIN_ZONESIZE, memfree, largest);
96 if ((zone = (byte *)malloc(*size)) == NULL)
97 I_Error ("malloc() %d bytes for zone management failed", *size);
99 printf ("I_ZoneBase(): Allocated %d bytes for zone management\n", *size);
101 return zone;
104 /**********************************************************************/
105 // Called by D_DoomLoop,
106 // returns current time in tics.
107 int I_GetTime (void)
109 unsigned int clock[2];
110 double currtics;
111 static double basetics=0.0;
113 ppctimer (clock);
114 if (basetics == 0.0)
115 basetics = ((double) clock[0])*tb_scale_hi + ((double) clock[1])/tb_scale_lo;
117 currtics = ((double) clock[0])*tb_scale_hi + ((double) clock[1])/tb_scale_lo;
118 return (int) (currtics-basetics);
121 /**********************************************************************/
123 // Called by D_DoomLoop,
124 // called before processing any tics in a frame
125 // (just after displaying a frame).
126 // Time consuming syncronous operations
127 // are performed here (joystick reading).
128 // Can call D_PostEvent.
130 void I_StartFrame (void)
132 amiga_getevents ();
135 /**********************************************************************/
137 // Called by D_DoomLoop,
138 // called before processing each tic in a frame.
139 // Quick syncronous operations are performed here.
140 // Can call D_PostEvent.
141 void I_StartTic (void)
145 /**********************************************************************/
146 // Asynchronous interrupt functions should maintain private queues
147 // that are read by the synchronous functions
148 // to be converted into events.
150 // Either returns a null ticcmd,
151 // or calls a loadable driver to build it.
152 // This ticcmd will then be modified by the gameloop
153 // for normal input.
154 ticcmd_t emptycmd;
155 ticcmd_t* I_BaseTiccmd (void)
157 return &emptycmd;
160 /**********************************************************************/
161 // Called by M_Responder when quit is selected.
162 // Clean exit, displays sell blurb.
163 void I_Quit (void)
165 D_QuitNetGame ();
166 I_ShutdownSound();
167 I_ShutdownMusic();
168 M_SaveDefaults ();
169 I_ShutdownGraphics();
171 if (GfxBase != NULL) {
172 CloseLibrary ((struct Library *) GfxBase);
173 GfxBase = NULL;
175 if (IntuitionBase != NULL) {
176 CloseLibrary ((struct Library *) IntuitionBase);
177 IntuitionBase = NULL;
180 if (vid_mem != NULL)
181 PPCFreeVec (vid_mem);
183 exit(0);
186 /**********************************************************************/
187 // Allocates from low memory under dos,
188 // just mallocs under unix
189 byte* I_AllocLow (int length)
191 byte* mem;
193 if ((mem = (byte *)malloc (length)) == NULL)
194 I_Error ("Out of memory allocating %d bytes", length);
195 memset (mem,0,length);
196 return mem;
199 /**********************************************************************/
200 void I_Tactile (int on, int off, int total)
202 // UNUSED.
203 on = off = total = 0;
206 /**********************************************************************/
207 void *I_malloc (size_t size)
209 void *b;
211 if ((b = malloc (size)) == NULL)
212 I_Error ("Out of memory allocating %d bytes", size);
213 return b;
216 /**********************************************************************/
217 void *I_calloc (size_t nelt, size_t esize)
219 void *b;
221 if ((b = calloc (nelt, esize)) == NULL)
222 I_Error ("Out of memory allocating %d bytes", nelt * esize);
223 return b;
226 /**********************************************************************/
227 void I_Error (char *error, ...)
229 va_list argptr;
231 // Message first.
232 va_start (argptr, error);
233 fprintf (stderr, "Error: ");
234 vfprintf (stderr, error, argptr);
235 fprintf (stderr, "\n");
236 va_end (argptr);
238 fflush (stderr);
240 // Shutdown. Here might be other errors.
241 if (demorecording)
242 G_CheckDemoStatus ();
244 D_QuitNetGame ();
245 I_ShutdownGraphics ();
247 if (GfxBase != NULL) {
248 CloseLibrary ((struct Library *) GfxBase);
249 GfxBase = NULL;
251 if (IntuitionBase != NULL) {
252 CloseLibrary ((struct Library *) IntuitionBase);
253 IntuitionBase = NULL;
256 if (vid_mem != NULL)
257 PPCFreeVec (vid_mem);
259 exit (20);
262 /**********************************************************************/