Deeper, harder, faster! ;)

wonder

Expert
Licensed User
Longtime User
<<< WARNING >>>
This post is extremely computer nerdy.
Viewer discretion is advised.

As you all know, thanks to B4A's external library support, we've been able to write our own Java libraries for a while now. This is such an incredible feature, but since I was never familiar with Java, whenever I needed something really specific, I was always dependent on someone else's good will to write some code for me.

I was, however, familiar with the C language, so last summer I decided to give JNI a try. After some (many) NDK/JNI tutorials, I was finally able to take my first steps on creating native-based B4A libraries.
Happy with the result, but unhappy with the JNI syntax (which is horrible, btw), I created a helper tool which allowed me to write regular C/C++ code and have a B4A library generated in seconds.

Unchained from having to carefully craft JNI functions by hand, my productivity was immensely increased.
Soon I realized, from a game designer perspective, B4A and C++ is a match made in heaven! The possibilities are endless. The friendliness of Erel's IDE and B4x syntex, powered by natively written functions.

Just when I thought things couldn't get any faster, I discovered that C/C++ has inline support for assembly commands. Of course, one has to be very careful because when using those, since they're quite hardware specific.

At this point it really feels like I've reached the core. I'm as close to the hardware as humanly possible.
I started to measure my cycles and loops in nanoseconds. Suddenly now, a millisecond seems like an eternity.

So there you have it, if you have a mad scientist spirit like me, I'm here to let you know that, you can write Assembly code, using C/C++ inline functions, compile it into an .so library to be used by a Java library which can be wrapped into a B4A library.

tl;dr:
B4A --> Java --> C/C++ --> Assembly
B4A <-- Java <-- C/C++ <-- Assembly
Yes, we can.

...and that's how we can go deeper, harder and faster, at least in terms of coding.
 
Last edited:

JordiCP

Expert
Licensed User
Longtime User

It's like some kind of drug. Once you have tasted it....you will want more, and more....

Once on the NDK side, don't forget NEON and openmp if you want to further boost performance
 

wonder

Expert
Licensed User
Longtime User
It's not enough, for me. I want to develop in binary, then:
Binary --> Assembly --> C --> Java --> B4A

B4X:
00000000  7f 45 4c 46 01 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  02 00 03 00 01 00 00 00  80 80 04 08 34 00 00 00  |............4...|
00000020  c8 00 00 00 00 00 00 00  34 00 20 00 02 00 28 00  |........4. ...(.|
00000030  04 00 03 00 01 00 00 00  00 00 00 00 00 80 04 08  |................|
00000040  00 80 04 08 9d 00 00 00  9d 00 00 00 05 00 00 00  |................|
00000050  00 10 00 00 01 00 00 00  a0 00 00 00 a0 90 04 08  |................|
00000060  a0 90 04 08 0e 00 00 00  0e 00 00 00 06 00 00 00  |................|
00000070  00 10 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  ba 0e 00 00 00 b9 a0 90  04 08 bb 01 00 00 00 b8  |................|
00000090  04 00 00 00 cd 80 b8 01  00 00 00 cd 80 00 00 00  |................|
000000a0  48 65 6c 6c 6f 2c 20 77  6f 72 6c 64 21 0a 00 2e  |Hello, world!...|
000000b0  73 68 73 74 72 74 61 62  00 2e 74 65 78 74 00 2e  |shstrtab..text..|
000000c0  64 61 74 61 00 00 00 00  00 00 00 00 00 00 00 00  |data............|
000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000000f0  0b 00 00 00 01 00 00 00  06 00 00 00 80 80 04 08  |................|
00000100  80 00 00 00 1d 00 00 00  00 00 00 00 00 00 00 00  |................|
00000110  10 00 00 00 00 00 00 00  11 00 00 00 01 00 00 00  |................|
00000120  03 00 00 00 a0 90 04 08  a0 00 00 00 0e 00 00 00  |................|
00000130  00 00 00 00 00 00 00 00  04 00 00 00 00 00 00 00  |................|
00000140  01 00 00 00 03 00 00 00  00 00 00 00 00 00 00 00  |................|
00000150  ae 00 00 00 17 00 00 00  00 00 00 00 00 00 00 00  |................|
00000160  01 00 00 00 00 00 00 00                           |........|

http://stackoverflow.com/questions/10821875/how-could-i-write-hello-world-in-binary
 

Cableguy

Expert
Licensed User
Longtime User
That Hex Edit reminded me of when I used to FF all my floppys when they returned bad sectors... LOL
 

Cableguy

Expert
Licensed User
Longtime User
The old floppy disks, were about 25€/pack (equivalent) in the early 80's, which was very expensive for that time, so whenever a floppy disk gave me bad sector, I would edit it with an HEX editor, and FF all the non FF contents ( formatting filled the disk with FFs), then I would retry the format, and a few bad sectors would go away at each format/edit.
 

Beja

Expert
Licensed User
Longtime User
It's not enough, for me. I want to develop in binary, then:
Binary --> Assembly --> C --> Java --> B4A

I would start from transistors and solid-state physics..
Transistors --> SSI --> MSI --> LSI --> ULSI --> MCUs --> Binary --> Hex --> Assembly --> C --> Java --> B4A.
Only this way I can know what exactly I am doing when I use B4A
 

sorex

Expert
Licensed User
Longtime User
writing or editing code the hex way was common and it still is if you are into patching pc programs or coding on cheap minimal electronics processors.

every coder who knows assembler well should be able to insert common (patch) commands like ret, nop, jne/jnz/jz, mov ax/ah/al/bx/bl/bh/cx/cl/ch/dx/dl/dh, call/jmp ...
as their hex values.

Here's an example on how to do it on a C64. (notice the Q/A typo... we use azerty here in Belgium so I needed to adapt again to qwerty )

 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…