Mercurial > vba-clojure
view java/src/com/aurellem/gb/Gb.java @ 89:2f478abe57d0
added sanity check for title
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 10 Mar 2012 15:55:10 -0600 |
parents | 95cb2152d7cd |
children | 1ff2c546f5ad |
line wrap: on
line source
1 package com.aurellem.gb;3 import java.nio.ByteBuffer;4 import java.nio.IntBuffer;5 import java.nio.ByteOrder;7 public class Gb {10 public Gb(){}13 /**14 * Hello World! This is just to test the native interface.15 */16 public static native void sayHello();18 /**19 * Run the emulator on a given rom20 * @param rom - the name of the rom.21 */22 public static native void startEmulator(String rom);25 public static void loadVBA(){26 System.loadLibrary("vba");27 }29 public static native void step();31 public static native void nstep(int keymask);33 public static void step(int keymask){34 if (-1 == keymask) {step();}35 else {nstep(keymask);}}37 public static native void shutdown();39 public static native long saveState(ByteBuffer buffer, int size);41 public static native void loadState(ByteBuffer buffer, int size);43 public static final int MAX_SAVE_SIZE = 20000;45 public static ByteBuffer createDirectByteBuffer(int capacity){46 byte[] zeros = new byte[capacity];47 ByteBuffer buf =48 ByteBuffer.allocateDirect(capacity)49 .order(ByteOrder.nativeOrder());50 buf.put(zeros);51 buf.clear();52 return buf;53 }55 public static ByteBuffer saveBuffer(){56 return createDirectByteBuffer(MAX_SAVE_SIZE);57 }59 public static ByteBuffer saveState(){60 ByteBuffer buf = saveBuffer();62 saveState(buf, buf.capacity());64 // determine the extent of the saved data65 int position = buf.capacity() - 1;66 for (int i = position; i > 0; i--){67 if (0 != buf.get(i)){68 position = i;69 break;70 }}71 byte[] saveArray = new byte[position];72 ByteBuffer save = createDirectByteBuffer(position);73 buf.get(saveArray, 0 , position);74 save.put(saveArray);75 save.rewind();76 return save;77 }79 public static void loadState(ByteBuffer saveState){80 loadState(saveState, MAX_SAVE_SIZE);81 }83 public static native int getROMSize();84 public static native int getRAMSize();87 public static final int WRAM_SIZE = 0x8000;89 public static final int VRAM_SIZE = 0x4000;91 public static final int NUM_REGISTERS = 27;93 public static native void getRAM(int[] store);95 public static native void getROM(int[] store);97 public static native void getWRAM(int[] store);99 public static native void getVRAM(int[] store);101 public static native void getRegisters(int[] store);102 }