I’ve been relaxing at home with a bit of XNA, I like it.
One thing i don’t like about it is C# only, not cos C# is rubbish but because I have ALOT of C++ code i want to use. The official line is only C# works for XNA on 360… so I believed them, then I heard F# was working on 360… this intrigued me, what is it that allows F# to work but not Managed C++.
The answer after a bit of digging is the .Net 2.0 Compact (using on PocketPC and X360) misses a few IL instructions used by C++ (they only bothered implementing those used by C# and Visual Basic.NET)…
hmmm looked like a serious pain in the arse to fix… but being me, i dug further.
And I found an interesting fact… to be completely correct C# isn’t supported on .Net 2.0 compact either… You see a rare (tho quite useful) part of C# v2 is missing, the local stack IL instructions isn’t supported, so if you use this in your C# code it will break under .Net 2.0 Compact.
This made me think hard… so if your Managed C++ code doesn’t generate any of the unsupported opcodes, it should run on XNA 360, in the same way that C# only runs IF u don’t use any unsupported opcodes.
This blog entry was very helpful with my investigations
Now looking at the v2 opcodes it doesn’t support, the ones that look problematic are indirect function calls and varialble length arguements list ones. Well i’m guessing that as long as you don’t do any varargs stuff that eliminates the second set and for the first, one is marked as native/managed interop which doesn’t exist on 360. Which leaves just calli and localalloc as possible problems, localalloc is used like alloca() which should be easy to avoid and i’m hoping calli won’t happen much (haven’t yet looked what its for).
VS 2005 has a safe Managed C++ compile option which should produce code the XNA 360 likes, after all if the code is safe to that level, it already has removed much of the stuff the XNA won’t like (you can think of XNA as being a platform that wants safe verifiable code, exactly what /clr:safe was invented for).
After a bit of messing around with assemblies, I can now confirm that at least very simple Managed C++ CAN run on XNA 360, I know cos I’ve done it… So far its nothing more complex than a class with some getters and setters, but still I can new it and access the member variables in C# and run it on XNA 360 no problem.
Now for some more experimentation to see if the dodgy opcodes will get generated in standard code. The two localalloc and calli that I could see being generated are my worry, just gonna have to write some more complex code and see if I generate those opcodes and therefore upset to XNA360 version of .Net