Mercurial > vba-clojure
view java/src/com/aurellem/gb/Gb.java @ 81:db8e0a563c8e
generated intro
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 09 Mar 2012 01:43:25 -0600 |
parents | ad6ebe886a21 |
children | 95cb2152d7cd |
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 step(int keymask);33 public static native void shutdown();35 public static native long saveState(ByteBuffer buffer, int size);37 public static native void loadState(ByteBuffer buffer, int size);39 public static final int MAX_SAVE_SIZE = 20000;41 public static ByteBuffer createDirectByteBuffer(int capacity){42 byte[] zeros = new byte[capacity];43 ByteBuffer buf =44 ByteBuffer.allocateDirect(capacity)45 .order(ByteOrder.nativeOrder());46 buf.put(zeros);47 buf.clear();48 return buf;49 }51 public static ByteBuffer saveBuffer(){52 return createDirectByteBuffer(MAX_SAVE_SIZE);53 }55 public static ByteBuffer saveState(){56 ByteBuffer buf = saveBuffer();58 saveState(buf, buf.capacity());60 // determine the extent of the saved data61 int position = buf.capacity() - 1;62 for (int i = position; i > 0; i--){63 if (0 != buf.get(i)){64 position = i;65 break;66 }}67 byte[] saveArray = new byte[position];68 ByteBuffer save = createDirectByteBuffer(position);69 buf.get(saveArray, 0 , position);70 save.put(saveArray);71 save.rewind();72 return save;73 }75 public static void loadState(ByteBuffer saveState){76 loadState(saveState, MAX_SAVE_SIZE);77 }79 public static native int getROMSize();80 public static native int getRAMSize();83 public static final int WRAM_SIZE = 0x8000;85 public static final int VRAM_SIZE = 0x4000;87 public static final int NUM_REGISTERS = 27;89 public static native void getRAM(int[] store);91 public static native void getROM(int[] store);93 public static native void getWRAM(int[] store);95 public static native void getVRAM(int[] store);97 public static native void getRegisters(int[] store);98 }