NEWS ARTICLES


    What's News in the PlayBasic world ? - Find out here.



 PlayBasic To DLL (Research Project)

By: Kevin Picone Added: August 23rd, 2013

Category: All,Machine Code,Tools

PlayBasic To DLL (Research Project)

     With the completion of the V1.64O retail upgrade, our focus has shifted onto the way forward for the classic PlayBasic platform. There's a number of options with equally as many positives and negatives. One of those options was building a translation tool to convert PlayBasic byte code to machine code in the form of a DLL.

     Such a tool would mean PlayBasic programmers can create plug in's that perform any brute force processing required. The programmer could then bind (and execute) the DLL functions directly from PB resource in memory, never needing to be extracted them to disc.

     The project is already up and running, you can following it's development on our forums. You'll need to sign up & log in to do so. Bellow is a few snippets from the blog.



Work In Progress (The Dissassembler Short Cut)

This idea has been floating around for a while now, there's a number of older tech demos that convert VM instructions into x86 machine code at run time (JIT). The process is relatively easy, it's just those programs are doing it manually (in PB code). So it'd read the byte code and drop out an equivalent x86 code into some executable memory, then call when done as a viability test. In principal you could do the same to export binary as dll, but an easier option would be to spit out raw assembly an pass through an assembler and hey presto job done.

     Ok, so what does this have to do with the dissassembly tool written last year ? - Well, that program runs through PB byte code and converts it back into a semi readable text file for internal debugging. The result isn't pretty, but the same raw process could be used to drop x86 assembly out in place of the command simulations. So it should be possible, Relatively easy actually to get it to output at least simple operational code. It'd probably required the user PlayBasic code be set up in particular way, so the export and ID what functions are to be exported.

     To export a function, the function name needs DLL_ like so,
PlayBasic Code:
Function DLL_FillMemoryInt(StartPtr,Count,ThisValue)
   do
      pokeint StartPtr,ThisValue
      StartPtr+=4   
   decloop Count
EndFunction


COMMANDS USED: POKEINT |


     The nice thing about using PlayBasic compiler as the initial stage of the process (apart from saving me work), is that we get whatever benefits it applies to the input source in terms of optimizations. The output code wouldn't be comparable to hand written equivalent but obviously it'd give you some brute force muscle.

     We've tested the above running in PlayBasic V1.64O compared to an equivalent assembly function and the classic VM takes about 90 milliseconds to poke (800*600) pixels and the Dll function takes about 3.5 milliseconds. So in this case, it's more like 25 times faster than the classic VM. Not only that, the compiled DLL is also 25% faster than one competitor and about 10 times faster than another.






 

 
     
 
       

(c) Copyright 2002 / 2024 Kevin Picone , UnderwareDesign.com  - Privacy Policy   Site: V0.99a [Alpha]