drcjt / CSharp-80

C# AOT compiler for Z80 based computers including the TRS-80 and ZX Spectrum
https://drcjt.github.io/CSharp-80/
GNU General Public License v3.0
51 stars 3 forks source link

How to connect arbitrary assembly language code? #539

Open SaymanNsk opened 1 week ago

SaymanNsk commented 1 week ago

Hello! How to connect arbitrary assembly language code? Meaning: I write classes and methods in c# to access OS subsystems on Sprinter. Reading a file, writing a file, and more. How can I do this? Sprinter has its own OS (Estex Dos). It has its own api working through rst #10. It has its own BIOS, working through RST 8. I would like to access all this somehow.

drcjt commented 6 days ago

I've added a wiki page, https://github.com/drcjt/CSharp-80/wiki/P-Invoke,-InternalCall-and-Intrinsics, to explain the three mechanisms that can be used to invoke native code.

It will depend on your use case as to which mechanism to use. However, note all three mechanisms currently require changes to be made to the CSharp-80 native runtime code. A good future enhancement would be to improve the support for P/Invoke to allow native z80 code outside of the CSharp-80 native runtime code to be used - I'll add an issue for this.

Looking at how operations for reading/writing files is implemented in dotnet coreclr there are various C# wrapper methods such as System.IO.File.Delete(..), and System.IO.FileSystem.DeleteFile(...) that use the PInvoke.Kernel32 class which uses P/Invoke to access operating system level methods to actually perform the file operations. You could follow this approach and use the P/Invoke support in CSharp-80 as documented in the wiki page.

I hope this answers your question.