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>
28 extern void ppctimer (unsigned int *time
);
29 extern double tb_scale_lo
;
30 extern double tb_scale_hi
;
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.
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");
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
)
67 ULONG memfree
, largest
;
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]);
81 if (largest
> MAX_ZONESIZE
+ 65536 &&
82 memfree
> MAX_ZONESIZE
+ (2 * 1024 * 1024))
84 else if (memfree
< largest
+ (2 * 1024 * 1024))
85 *size
= memfree
- (2 * 1024 * 1024) - 65536;
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
);
104 /**********************************************************************/
105 // Called by D_DoomLoop,
106 // returns current time in tics.
109 unsigned int clock
[2];
111 static double 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)
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
155 ticcmd_t
* I_BaseTiccmd (void)
160 /**********************************************************************/
161 // Called by M_Responder when quit is selected.
162 // Clean exit, displays sell blurb.
169 I_ShutdownGraphics();
171 if (GfxBase
!= NULL
) {
172 CloseLibrary ((struct Library
*) GfxBase
);
175 if (IntuitionBase
!= NULL
) {
176 CloseLibrary ((struct Library
*) IntuitionBase
);
177 IntuitionBase
= NULL
;
181 PPCFreeVec (vid_mem
);
186 /**********************************************************************/
187 // Allocates from low memory under dos,
188 // just mallocs under unix
189 byte
* I_AllocLow (int length
)
193 if ((mem
= (byte
*)malloc (length
)) == NULL
)
194 I_Error ("Out of memory allocating %d bytes", length
);
195 memset (mem
,0,length
);
199 /**********************************************************************/
200 void I_Tactile (int on
, int off
, int total
)
203 on
= off
= total
= 0;
206 /**********************************************************************/
207 void *I_malloc (size_t size
)
211 if ((b
= malloc (size
)) == NULL
)
212 I_Error ("Out of memory allocating %d bytes", size
);
216 /**********************************************************************/
217 void *I_calloc (size_t nelt
, size_t esize
)
221 if ((b
= calloc (nelt
, esize
)) == NULL
)
222 I_Error ("Out of memory allocating %d bytes", nelt
* esize
);
226 /**********************************************************************/
227 void I_Error (char *error
, ...)
232 va_start (argptr
, error
);
233 fprintf (stderr
, "Error: ");
234 vfprintf (stderr
, error
, argptr
);
235 fprintf (stderr
, "\n");
240 // Shutdown. Here might be other errors.
242 G_CheckDemoStatus ();
245 I_ShutdownGraphics ();
247 if (GfxBase
!= NULL
) {
248 CloseLibrary ((struct Library
*) GfxBase
);
251 if (IntuitionBase
!= NULL
) {
252 CloseLibrary ((struct Library
*) IntuitionBase
);
253 IntuitionBase
= NULL
;
257 PPCFreeVec (vid_mem
);
262 /**********************************************************************/