• Single API that abstracts many retro console emulators. • Specifically designed to make writing frontends easy. • Free, open-source. • Well documented API. • Lightweight cross-platform C library. • Perfect?
• Single API that abstracts many retro console emulators • Specifically designed to make writing frontends easy. • Free, open-source. • Well documented API. • Lightweight cross-platform C library. • Perfect? h no…
“JNA provides Java programs easy access to native shared libraries without writing anything but Java code - no JNI or native code is required. This functionality is comparable to C#’s PInvoke and Python's ctypes.” github.com/java-native-access/jna JNA: Java Native Access Kotlin Kotlin
Static methods for loading native libraries, JNA configuration, and other utility tasks. final class Native val lib = Native.loadLibrary( "libName", TestLibrary::class.java) lib.some_method()
Base type for classes that are automatically mapped to/from native structs. abstract class Structure class example_struct : Structure() { } @JvmField var field1: String? = null @JvmField var field2: String? = null override fun getFieldOrder() = listOf("field1", “field2")
Base type for callback interfaces to be used as function pointers. Requires one public method. interface Callback interface my_callback : Callback { fun invoke() } interface TestLibrary : Library { fun set_callback(cb: my_callback) } val lib = Native.loadLibrary(/* … */) lib.set_callback(object : my_callback { override fun invoke() { /* TODO */ } })
Represents a native pointer, used for accessing arbitrary memory. class Pointer interface TestLibrary : Library { fun set_memory(pointer: Pointer) fun get_memory(): Pointer } interface my_callback : Callback { fun invoke(data: Pointer) }
JNA Performance https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md • Call overhead up to 10x slower • Ease of programing outweighs difference • Build, measure, optimize • Incrementally rewrite using JNI if needed
Calling our function from Kotlin with JNI…? external fun say_hello(name: String) System.loadLibrary("test") say_hello("Droidcon") void say_hello(const char* name)
Libretro Architecture Init Callbacks Load Game ROM Run Game Loop Waveform https://thenounproject.com/icon/1345324/ NES Cartridge https://thenounproject.com/icon/1127992/ Refresh https://thenounproject.com/icon/974170/
Libretro Architecture: Callbacks Video Callback: Called once per frame with a pointer to video data. Input Callback: Called for every supported button on every frame. Return true if button is pressed. Audio Callback: Called once per frame with a pointer to audio data. “Environment” Callback: Generic callback for obscure functions. Mostly unused, per documentation.
wat libc F Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 12676 ( DEBUG F #00 pc 00000000 F #01 pc 00010fc9 /data/app/com.codebutler.funwithnativecode-n1T9 F #02 pc 00010c40 /data/app/com.codebutler.funwithnativecode-n1T9 F #03 pc 000051e0 /data/app/com.codebutler.funwithnativecode-n1T9 F #04 pc 00007c8f /data/app/com.codebutler.funwithnativecode-n1T9 F #05 pc 0063ec67 /system/lib/libart.so (art_quick_generic_jni_tr F #06 pc 00638ea2 /system/lib/libart.so (art_quick_invoke_static_ F #07 pc 00112b92 /system/lib/libart.so (_ZN3art9ArtMethod6Invoke F #08 pc 003231ff /system/lib/libart.so (_ZN3art11interpreter34Ar F #09 pc 0031bde1 /system/lib/libart.so (_ZN3art11interpreter6DoC F #10 pc 0061faf4 /system/lib/libart.so (MterpInvokeStatic+484)
ODYSSEY github.com/codebutler/odyssey Current Features 7 Console Systems Early Leanback UI Controller Support Game Covert Art Game Save/Restore WebDAV Future Features More Console Systems Better UI Local Multiplayer Game State Save/Restore Dropbox/GDrive Cheat Codes Internet Multiplayer Twitch/YouTube (Named after the Magnavox Odyssey, the first commercial home video game console released in 1972)