[Windows RT Development and Hacking] BBUK:
Dear all.

I have built the latest version of Mame for hacked Surface RTs.

First of all, I'm aware that this post should be on this http://xdaforums.com/showthread.php?t=2092348 thread but I don't have enough posts. Perhaps someone could x-link...

There were some very basic changes to the source to enable it to build, most particularly around the lack of dinput on the Surface (keyboard and mouse still work fine nonetheless). Most of the work was building the compilation environment. Broadly:

(a) I followed the instructions at http://xdaforums.com/showthread.php?t=2096820 to make a basic VS environment to cross-compile for the Surface target. Note that you will not need to go into the VS IDE for anything, the build is done entirely on the command line (but we are not ready for that just yet). Note also that I cannot remember whether had to change c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h so that the line:

#define _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE 0

read

#define _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE 1

but good to check nonetheless. It is, however, necessary to pull the dlls from a Surface and convert them to libs as described in that page. Also, I worked on a Windows 7 machine and that was OK (so Windows 8 for a build machine is not necessary).

(b) the most recent versions of Mame already come with options to build from Visual Studio, I followed the instructions at http://mamedev.org/tools/ - the easy way - to install mingw64-32 (this page describes building Mame using mingw - we are not doing this, we are just getting this part of the toolchain in place). I then followed the instructions at http://mamedev.org/devwiki/index.php?title=Building_MAME_using_Microsoft_Visual_Studio_compilers but the relevant configuration (for ARM cross-compilation) is: c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat x86_arm and not as stated on that page.

(c) Unfortunately, we can not just get the sources, patch them and make as Mame builds a number of tools in order to process various source files. These must run on the build machine (x86) and not the target machine (arm). The Mame makefile already has an option to do build these tools "make buildtools" so this must be run first to create the build tools natively. What results is not quite what is needed. Firstly, Mame builds the buildtools into a "obj/windows" folder whereas for a VS compile the tools need to be in a "obj/vwindows" folder. Secondly, it builds some tools that should be linked into the ARM executable rather than x86 compiled. This can be sorted by just copying all files in "obj/vwindows/build" to a new folder "obj/vwindows/build".

(d) As stated above, there are a couple of files that need minor patching. I have included these in the src folder in zip file linked below. These should be extracted in the same folder as the Mame source code 0.148 (which is available at http://www.mamedev.org/oldrel.html) such that it overwrites the relevant Mame sources (from Explorer you will probably have to change the default extract folder). The zip file includes the patched Mame sources so you don't need to download the sources or patch.

(e) To make the ARM executable the make recipe is as follows: "make MSVC_BUILD=1 CROSS_BUILD=1 NOWERROR=1 SUBTARGET=tiny". Note that the build does not like to operate from a folder that has a space in the path. Best to compile from "c:\surfacemame" or the like rather than "...My Documents".

To make this easier for everyone, I have prepared a batch file such that if you: (i) follow (a) and (b) above to create the build environment (mingw must be installed to "C:\mingw64-w32" and the relevant binaries should be in "C:\mingw64-w32\bin"); (ii) get and extract the Mame sources (from the zip or from mamedev.org); (iii) (if sources are downloaded from mamedev.org) patch the sources with the files in the zip "src" folder, you can then just double click go.bat (which must be in the same folder as the Mame makefile). Build takes about 20-30 mins on my machine.

The result will be a vmametiny.exe which can be copied to the surface to a folder with a "roms" folder in it with your roms. To get the mouse to work, vmametiny.exe will have to be run with the -mouse option. The easiest way to do this is (on the Surface) create a shortcut to the exe, then edit the properties of the shortcut to add " -mouse" (without quotes but with a space after vmametiny.exe).

To make this even easier, I have included the executable in the zip. To comply with the Mame licence, I have to include the patched sources as well (which is why the file is so large).

There is a catch. Try as I might I could not get the full Mame build to work - the Mame build process programatically creates a file driverlist.c which is then compiled and linked into the executable. For some reason this did not work for me (I tried a lot of different approaches). The tiny build of Mame does not fully use this process and so works. The catch is that the tiny build only supports a very limited subset of games, I have built on this substantially by editing the relevant files tiny.lst and tiny.mak to include loads of popular games but it is a slow process as the dependencies have to be worked on a game by game basis (note that some of the dependencies may not have been fully worked out so Mame could throw an error (somtimes with blank dialog boxes) so just click OK until the boxes disappear and the game runs). I will update the zip at some point so that it runs (say) the top 250 games. I would love it if someone would help with this tiny build problem...

Zip file is here ... EDIT: this version now outdated, see link later in thread

Finally, the speed of most of the games I tried was excellent (eg rtypeleo and smashruns at 100%). The big disappointment was Atari vector games that only run at 50% speed. I don't know why this is the case but perhaps someone could help with that too...

Have fun all.

BBUK