A.D.A. Amiga Demoscene Archive

        Welcome guest!

  

  

  

log in with SceneID

  

Demos Amiga Demoscene Archive Forum / Coding / GNU Rocket

 

Author Message
Blueberry
Member
#1 - Posted: 4 Mar 2011 00:08
Reply Quote
Has anyone used GNU Rocket to control an Amiga demo running inside WinUAE? What is needed on the Amiga side? Does it work well?
Angry Retired Bastard
Member
#2 - Posted: 4 Mar 2011 00:29
Reply Quote
I believe Eph may have used it for their latest oilfoamdemo, but I *know* Kusma has created (and tested) an amiga-port of the client- / player-code using UAE.
rload
Member
#3 - Posted: 7 Mar 2011 23:52
Reply Quote
We didn't use it this time either, but it is always on the agenda of things to add for 'the next demo'.
yoki
Member
#4 - Posted: 8 Mar 2011 10:25
Reply Quote
is the amiga port available somewhere?
Angry Retired Bastard
Member
#5 - Posted: 8 Mar 2011 12:01
Reply Quote
Indeed it is: http://sourceforge.net/projects/rocket/develop

Note that it's not a separate port, but rather that the later versions of the code base is compatible with vbcc and amiga. (yes, it's still C ;)
Kusma also has some example code of how to use it, but that's not currently on there.
kusma
Member
#6 - Posted: 8 Mar 2011 12:07
Reply Quote
Thanks to Angry Retired Bastard for notifying me about this thread.

I have indeed ported and written a test-application for GNU Rocket on Amiga. The changes to the GNU Rocket player/client stub has been merged upstream, so it's available in the upstream repository. These changes are also a part of the 0.9 release, so if you don't want to use scary version control software, you can just download the tarball.

I haven't put the test-application anywhere public yet, but I can provide it if anyone is interested. It builds with VBCC and VLINK (and probably uses VASM for the C2P). Let me know you're interested.
Blueberry
Member
#7 - Posted: 9 Mar 2011 15:43 - Edited
Reply Quote
I got it working using SAS/C.

The biggest challenge was getting the right include files (the standard set of includes, or at least the SAS/C ones, do not cover the networking API) and making them compile. I searched and found this post recommending the Miami SDK. What followed was a somewhat lengthy struggle, in which I realized that disabling precompiled headers does not actually disable precompiled headers. ;)

Anyway, in the end, I just added these lines to sys/socket.h (right after the guarded include of sys/types.h):
typedef unsigned int uint32_t;
#include <proto/socket.h>
#define select(n,r,w,e,t) WaitSelect(n,r,w,e,t,0)

On the Rocket sync API side, all I had to do was to add
#define inline __inline
to base.h. It contained that line already for some platforms, but it wasn't triggered when compiling with SAS/C.

Since I want to code my demo in 100% asm (Asm-Pro is my home, you know), I wrote a small bridge application which handles the communication with the GNU Rocket tracker and communicates with the demo using message passing (standard Amiga IPC).

The whole thing works flawlessly, both in WinUAE and on my real Amiga! :-D
kusma
Member
#8 - Posted: 14 Mar 2011 17:30
Reply Quote
Nice to hear! I wouldn't mind adding something like this, if it helps:
diff --git a/sync/base.h b/sync/base.h
index bc46b00..5d1d973 100644
--- a/sync/base.h
+++ b/sync/base.h
@@ -13,6 +13,8 @@
#elif defined(__GNUC__)
#define inline __inline
#include <stdint.h>
+#elif defined(__SASC__)
+ #define inline __inline
#endif

#ifdef _WIN32
@@ -31,6 +33,11 @@
#define closesocket(x) close(x)
#endif

+#if defined(__amigaos__) || defined(AMIGA)
+# include <proto/socket.h>
+# define select(n,r,w,e,t) WaitSelect(n,r,w,e,t,0)
+#endif
+
#define CLIENT_GREET "hello, synctracker!"
#define SERVER_GREET "hello, demo!"



It seems "WaitSelect" is a more common interface to select on Amiga, so it's probably OK for all Amiga-targets. I'll test on my VBCC setup when I get home to double check.

As for uint32_t, does SAS/C or Miami SDK provide stdint.h? If it does, I could do this:
  #define strdup _strdup
#define snprintf _snprintf
typedef unsigned int uint32_t;
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) || defined(__SASC__)
#define inline __inline
#include <stdint.h>
#endif


Otherwise, I could add something like this some place:
#if defined(__m68k__) || defined(M68000)
typedef unsigned int uint32_t;
#endif
Blueberry
Member
#9 - Posted: 14 Mar 2011 18:32 - Edited
Reply Quote
The __SASC__ symbol seems to be defined only in C++ code, not for C. However, the __SASC symbol seems to be defined in all cases.

The proto and select part of the fix works fine.

Neither SAS/C nor the Miami SDK provide stdint.h. It also doesn't seem to define any of the m68k symbols you use in your last snip. So the uint32_t define should just go with the inline define.

Thus, this diff works with an off-the-shelf Miami SDK:
--- /d/Source/rocket-0.9/sync/base.h    2010-12-14 19:37:02.000000000 +0100
+++ /d/AmigaDrives/Data/C/Sources/synctest/base.h 2011-03-14 18:19:04.820988700 +0100
@@ -13,6 +13,9 @@
#elif defined(__GNUC__)
#define inline __inline
#include <stdint.h>
+#elif defined(__SASC)
+ #define inline __inline
+ typedef unsigned int uint32_t;
#endif

#ifdef _WIN32
@@ -31,6 +34,11 @@
#define closesocket(x) close(x)
#endif

+#if defined(__amigaos__) || defined(AMIGA)
+#include <proto/socket.h>
+#define select(n,r,w,e,t) WaitSelect(n,r,w,e,t,0)
+#endif
+
#define CLIENT_GREET "hello, synctracker!"
#define SERVER_GREET "hello, demo!"
kusma
Member
#10 - Posted: 14 Mar 2011 19:41
Reply Quote
Thanks for the corrections. There's still some problems, though.

First, my VBCC doesn't seem to like including proto/socket.h, it complains about some redefinitions. On the other hand, it doesn't define AMIGA or __amigaos__ either. However, it is an indication that my impresison of "WaitSelect" being The Right Thing(tm) to do on Amiga isn't 100% correct, so something like that might be a bit fishy.

libcurl does something like this:
#if defined(__AMIGA__) && !defined(select)
#define select(n,r,w,e,t) WaitSelect(n,r,w,e,t,0)
#endif


..but it does NOT include proto/socket.h. However, it does include a bunch of other headers, some of which (proto/dos.h in particular) break my VBCC-setup. Bleh :P

I'm starting to wonder if my includes are messed up somehow. My headers are a mishmash of the base VBCC-headers, the POSIXlib headers, and those from NDK39.

I also find it a bit curious that it explicitly load "bsdsocket.library" on startup. Why are we getting away without it? :P

Second, SAS/C supports 64-bit targets as far as I can tell from it's homepage, so assuming sizeof(int) might be problematic. Perhaps you could just do "echo 'CPPFLAGS += -DM68000' > config.mak" to get it defined instead of depending on SAS/C == 32bit target?
kusma
Member
#11 - Posted: 17 Mar 2011 08:53
Reply Quote
OK, it seems I've figured it all out:
1) My include-setup was indeed a bit messed up; PosixLib should not be mixed with NDK-headers. Thanks to some e-mail support from Frank Wille, I've figured out that I should use NDK + AmiTCP instead. MiamiSDK should be compatible with the AmiTCP libraries AFAICT.
2) VBCC (and I suppose SAS/C also) has a library called libauto that automatically loads libraries. The reason why libCurl explicitly loads it, is in case some caller does not use libauto.

Would you mind testing the following patch, and let me know if it works for you? You should probably create a file called config.mak in the root of the GNU Rocket source tree with the following content:
CPPFLAGS += -DUSE_AMITCP -DM68000


Here's the patch:
diff --git a/sync/base.h b/sync/base.h
index bc46b00..62c39b3 100644
--- a/sync/base.h
+++ b/sync/base.h
@@ -5,21 +5,42 @@
#ifndef SYNC_BASE_H
#define SYNC_BASE_H

+/* configure inline keyword */
+#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
+ #if defined(_MSC_VER) || defined(__GNUC__) || defined(__SASC)
+ #define inline __inline
+ #else
+ /* compiler does not support inline, make function static instead */
+ #define inline static
+ #endif
+#endif
+
+/* configure lacking CRT features */
#ifdef _MSC_VER
- #define inline __inline
#define strdup _strdup
#define snprintf _snprintf
+ /* int is 32-bit for both x86 and x64 */
typedef unsigned int uint32_t;
#elif defined(__GNUC__)
- #define inline __inline
#include <stdint.h>
+#elif defined(M68000)
+ typedef unsigned int uint32_t;
#endif

+/* configure socket-stack */
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <winsock2.h>
#include <windows.h>
+#elif defined(USE_AMITCP)
+ #include <proto/exec.h>
+ #include <proto/socket.h>
+ #include <netdb.h>
+ #define SOCKET int
+ #define INVALID_SOCKET -1
+ #define select(n,r,w,e,t) WaitSelect(n,r,w,e,t,0)
+ #define closesocket(x) CloseSocket(x)
#else
#include <sys/socket.h>
#include <sys/time.h>
diff --git a/sync/device.c b/sync/device.c
index 93deb5a..1c6aa70 100644
--- a/sync/device.c
+++ b/sync/device.c
@@ -36,6 +36,13 @@ static SOCKET server_connect(const char *host, unsigned short nport)
return INVALID_SOCKET;
need_init = 0;
}
+#elif defined(USE_AMITCP)
+ static struct Library *socket_base = NULL;
+ if (!socket_base) {
+ socket_base = OpenLibrary("bsdsocket.library", 4);
+ if (!socket_base)
+ return INVALID_SOCKET;
+ }
#endif

he = gethostbyname(host);
Blueberry
Member
#12 - Posted: 18 Mar 2011 10:51
Reply Quote
Missing:
#define SOCK_STREAM 1

With that line added, and the two defines added in the SAS/C configuration, it compiles.

However, the explicit OpenLibrary should not be there, it seems. The library is opened twice and only closed once, leaking the library open count (which means for instance that Miami will not be able to quit, since it believes someone is still using the network stack). It works fine with the explicit OpenLibrary code removed.

Is there perhaps a way to get rid of the two defines? Not that they are problematic for me now that I know about them, but it could be nice to have an off-the-shelf solution.
kusma
Member
#13 - Posted: 18 Mar 2011 18:01
Reply Quote
Blueberry:
Missing:
#define SOCK_STREAM 1

With that line added, and the two defines added in the SAS/C configuration, it compiles.

Hm, this is defined in <sys/socket.h>, which is included by <clib/socket_protos.h> in the AmiTCP headers, which again is included by <proto/sockets.h> in the VBCC. If it's also in <sys/socket.h> in MiamiSDK, I'd prefer including that to duplicating a definition.

Blueberry:
However, the explicit OpenLibrary should not be there, it seems. The library is opened twice and only closed once, leaking the library open count (which means for instance that Miami will not be able to quit, since it believes someone is still using the network stack). It works fine with the explicit OpenLibrary code removed.

Yeah, I'm aware of the library-leak, and I'll definitely fix it before committing. But I think I prefer having the explicit OpenLibrary, as it works even without auto.a.

Blueberry:
Is there perhaps a way to get rid of the two defines? Not that they are problematic for me now that I know about them, but it could be nice to have an off-the-shelf solution.

I'm not entirely sure, but it'd be nice if it somehow worked off-the-shelf indeed. The biggest question is to figure out what target and compiler should be used.

If you're compiling on the Amiga, then it's very easy to solve, but for cross-compiling it becomes tricky as it's not obvious what target and compiler should be used. We'd probably still need some kind of configuration for that, but it'd be nice if it was somewhat more streamlined.

Perhaps something like a TARGET variable to configure the platform would do? Or maybe even a configure-script to generate config.mak?
kusma
Member
#14 - Posted: 25 Mar 2011 00:59
Reply Quote
blueberry, would you mind giving this branch a go with SAS/C? If it works, I'll merge it...

https://github.com/kusma/rocket/tree/work/amiga
Blueberry
Member
#15 - Posted: 26 Mar 2011 16:47 - Edited
Reply Quote
It seems to work fine. It opens bsdsocket.library twice, but it closes it twice as well.

The sync API in this version is incompatible with the 0.9 (from the main GNU Rocket SourceForge page) I was using (missing sync_set_callbacks). Which one is the more recent?
kusma
Member
#16 - Posted: 28 Mar 2011 17:57
Reply Quote
This branch is more recent. The callbacks are now passed directly to sync_update. Thanks for testing, I will merge the branch ASAP.

 

  Please log in to comment

  

  

  

 

A.D.A. Amiga Demoscene Archive, Version 3.0