Starting point:Traditional game simulators (FC, Neo, FBA, GBA, Mame, n64, NDS, and PSP) are all moved to Android phones, the game Rom is then saved to the SD card and run through the simulator. However, considering that mobile games must follow the fast forward and fast forward principles, I have implemented the following micro-innovations on this basis:
1. directly put the game Rom in the android APK, click the application to start the game, saving the process of searching for the game through the file browser.
2. Use interpolation algorithms to enlarge game images to support Android tablet resolutions
3. Make full use of the unique features of the mobile phone gravity sensor (compared with the other two screens, PC monitors and TVs), using the mobile phone sensor as the direction key
Procedure:
1. Select an open-source Linux-based fcgame Simulator
2. Implement the Java JNI interface for accessing the C layer
Public class game {</P> <p> Public static native void loadgame (byte [] data) throws illegalstateexception; <br/> Public static native void destroygame () throws illegalstateexception; <br/> Public static native void sendevent (INT keystate, int event) throws illegalstateexception; <br/> Public static native void setvideosurface (surface) throws illegalstateexception; <br/> Public static native void setskipframe (INT skip); <br/>}
3. Use ralativielayout in the acitemedilayout layout of Android to move the five keys and buttons to the two ends of the game interface.
Common JNI practices can be obtained through JNI spec. Pay attention to the following points:
1. If the static native method is defined, the class of the object cannot be obtained using getobjectclass in C/C ++ code.
2. If the Java and C/C ++ layers need to share the memory, you can use the getdirectbufferadress () API
3. jchar occupies two bytes (typedef unsigned short jchar ;)
4. Global Reference remember to release (newglobalref, deleteglobalref)
5. Exceptions to be captured in Java can be thrown in JNI (that is, in the C/C ++ layer), such:
Int jnithrowexception (jnienv * ENV, const char * classname, const char * MSG) {<br/> jclass exceptionclass = env-> findclass (classname ); <br/> If (exceptionclass = NULL) {<br/> _ android_log_print (android_log_error, <br/> tag, <br/> "unable to find exception class % s", <br/> classname); <br/> return-1; <br/>}< br/> If (env-> thrownew (exceptionclass, MSG )! = Jni_ OK) {<br/> _ android_log_print (android_log_error, <br/> tag, <br/> "failed throwing '% s' % S '", <br/> classname, MSG); <br/>}< br/> return 0; <br/>}
6. It is best to register the native method at one time.
Running result:
Download: Soldado