amiga-specific timer code

master
Ozkan Sezer 4 years ago committed by Ozkan Sezer
parent 2ce2f45824
commit c35288c66f
  1. 4
      src/common.h
  2. 118
      src/delay.c
  3. 18
      src/main.c
  4. 4
      src/read_config.c

@ -79,6 +79,10 @@ extern struct player_mode pmode[];
int report(const char *, ...);
void delay_ms(unsigned int msec);
#ifdef XMP_AMIGA
void amiga_inittimer(void);
void amiga_getsystime(void *);
#endif
char *xmp_strdup(const char *);
int xmp_strcasecmp(const char *, const char *); /* locale-insensitive */

@ -6,6 +6,9 @@
* file for more information.
*/
#include <xmp.h>
#include "common.h"
#if defined(_WIN32)
#include <windows.h>
@ -28,6 +31,121 @@ void delay_ms(unsigned int msec) {
delay(msec); /* doesn't seem to use int 15h. */
}
#elif defined(XMP_AMIGA)
#ifdef __amigaos4__
#define __USE_INLINE__
#else
#endif
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/timer.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct MsgPort *timerport;
#ifdef __amigaos4__
struct TimeRequest *timerio;
struct TimerIFace *ITimer;
#else
struct timerequest *timerio;
#endif
#ifdef __amigaos4__
struct Device *TimerBase = NULL;
#elif defined(__MORPHOS__) || defined(__VBCC__)
struct Library *TimerBase = NULL;
#else
struct Device *TimerBase = NULL;
#endif
static void amiga_atexit (void) {
#ifdef __amigaos4__
if (ITimer) {
DropInterface((struct Interface *)ITimer);
}
#endif
if (TimerBase) {
WaitIO((struct IORequest *) timerio);
CloseDevice((struct IORequest *) timerio);
DeleteIORequest((struct IORequest *) timerio);
DeleteMsgPort(timerport);
TimerBase = NULL;
}
}
void amiga_inittimer (void)
{
timerport = CreateMsgPort();
if (timerport != NULL) {
#if defined(__amigaos4__)
timerio = (struct TimeRequest *) CreateIORequest(timerport, sizeof(struct TimeRequest));
#else
timerio = (struct timerequest *) CreateIORequest(timerport, sizeof(struct timerequest));
#endif
if (timerio != NULL) {
if (OpenDevice((STRPTR) TIMERNAME, UNIT_MICROHZ, (struct IORequest *) timerio, 0) == 0) {
#if defined(__amigaos4__)
TimerBase = timerio->Request.io_Device;
ITimer = (struct TimerIFace *) GetInterface(TimerBase, "main", 1, NULL);
#elif defined(__MORPHOS__) || defined(__VBCC__)
TimerBase = (struct Library *)timerio->tr_node.io_Device;
#else
TimerBase = timerio->tr_node.io_Device;
#endif
} else {
DeleteIORequest((struct IORequest *)timerio);
DeleteMsgPort(timerport);
}
} else {
DeleteMsgPort(timerport);
}
}
if (!TimerBase) {
fprintf(stderr, "Can't open timer.device\n");
exit (-1);
}
/* 1us wait, for timer cleanup success */
#if defined(__amigaos4__)
timerio->Request.io_Command = TR_ADDREQUEST;
timerio->Time.Seconds = 0;
timerio->Time.Microseconds = 1;
#else
timerio->tr_node.io_Command = TR_ADDREQUEST;
timerio->tr_time.tv_secs = 0;
timerio->tr_time.tv_micro = 1;
#endif
SendIO((struct IORequest *) timerio);
WaitIO((struct IORequest *) timerio);
atexit (amiga_atexit);
}
void amiga_getsystime(void *tv)
{
#ifdef __amigaos4__
GetSysTime((struct TimeVal *)tv);
#else
GetSysTime((struct timeval *)tv);
#endif
}
void delay_ms(unsigned int msec) {
#if defined(__amigaos4__)
timerio->Request.io_Command = TR_ADDREQUEST;
timerio->Time.Seconds = msec / 1000000;
timerio->Time.Microseconds = msec % 1000000;
#else
timerio->tr_node.io_Command = TR_ADDREQUEST;
timerio->tr_time.tv_secs = msec / 1000000;
timerio->tr_time.tv_micro = msec % 1000000;
#endif
SendIO((struct IORequest *) timerio);
WaitIO((struct IORequest *) timerio);
}
#elif defined(HAVE_USLEEP)
#include <unistd.h>

@ -6,6 +6,8 @@
* file for more information.
*/
#include <xmp.h>
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -15,6 +17,10 @@
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if defined(XMP_AMIGA)
#include <proto/timer.h>
#include <time.h>
#endif
#if defined(__WATCOMC__)
#include <time.h>
#endif
@ -30,10 +36,8 @@
#else
#include "getopt_long.h"
#endif
#include <xmp.h>
#include "errno.h"
#include "sound.h"
#include "common.h"
#include "xmp_version.h"
#ifdef _WIN32
@ -260,6 +264,16 @@ int main(int argc, char **argv)
srand(GetTickCount());
#elif defined(__WATCOMC__)
srand(time(NULL));
#elif defined(__amigaos4__)
struct TimeVal tv;
amiga_inittimer();
amiga_getsystime(&tv);
srand(tv.Microseconds);
#elif defined(XMP_AMIGA)
struct timeval tv;
amiga_inittimer();
amiga_getsystime(&tv);
srand(tv.tv_micro);
#else
struct timeval tv;
gettimeofday(&tv, NULL);

@ -17,6 +17,10 @@
#define SYSCONFDIR "."
#endif
#if defined(XMP_AMIGA) && !defined(PATH_MAX) /* e.g.: vbcc headers */
#define PATH_MAX 1024
#endif
static char driver[32];
static char instrument_path[256];

Loading…
Cancel
Save