68 points · by ingve · 1y ago · 17 comments
No class instances. This is a severe limitation, to the point where it will change the character of the language entirely.
The transpiler also works for Linux eBPF kernel side applications without unsafe pointers and other odd things I need to do for SNES.
Since you can have methods on c# struct instances, things can still work pretty idiomatically.
You also do have statically sized arrays, or heap allocated arrays (the latter is only supported if host C application passes it in before hand, and is responsible for free ing it).
Then again, that's only viable if you don't use enough memory to require rom bank switching, or have better control over which class gets placed in which rom bank.
e.g. https://github.com/KallDrexx/DotnetSnes/blob/master/src/Dotn...
Some discussion 3 weeks ago
There's no heap on the SNES because the system has only one program running at all times (the game). There's no point using dynamic memory allocation when all of the memory on the system is available to the program, so you can just start writing to any valid, writeable address you want. Some addresses are, of course, not writeable (such as ROM space), and some addresses are not memory (memory-mapped IO) but that's not a problem.
The really nice thing about the SNES is that it uses a 24-bit address space instead of the 16-bit address space of the NES. Most NES games needed to use mapper chips to swap between different ROM banks since with 16 bits you can only address 64KB of memory at a time and many NES games were larger than that. Having 24 bits allows you to fit your game into far fewer ROM banks, greatly simplifying the programming model and making it much more realistic to use a high-level language like C#.
Modern programs have dynamic memory allocation. You can't just start writing to any address you want. You have to request memory from the operating system with malloc() and then free() it when you're done. Memory-managed programming languages handle this for you but it's still there under the covers.
On the SNES, you simply have all memory available from the beginning. No malloc/free, just start reading and writing.