diff --git a/src/common.h b/src/common.h
index 6ffc191..c0635ec 100644
--- a/src/common.h
+++ b/src/common.h
@@ -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 */
diff --git a/src/delay.c b/src/delay.c
index db14436..d537982 100644
--- a/src/delay.c
+++ b/src/delay.c
@@ -6,6 +6,9 @@
* file for more information.
*/
+#include
+#include "common.h"
+
#if defined(_WIN32)
#include
@@ -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
+#include
+#include
+#include
+#include
+#include
+
+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
diff --git a/src/main.c b/src/main.c
index 532275b..085264f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,6 +6,8 @@
* file for more information.
*/
+#include
+#include "common.h"
#include
#include
#include
@@ -15,6 +17,10 @@
#ifdef HAVE_SYS_TIME_H
#include
#endif
+#if defined(XMP_AMIGA)
+#include
+#include
+#endif
#if defined(__WATCOMC__)
#include
#endif
@@ -30,10 +36,8 @@
#else
#include "getopt_long.h"
#endif
-#include
#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);
diff --git a/src/read_config.c b/src/read_config.c
index e45f931..5d8322e 100644
--- a/src/read_config.c
+++ b/src/read_config.c
@@ -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];