annotate java/src/com/aurellem/gb/Gb.java @ 80:ad6ebe886a21

worked out size of save files and reduced MAX_SAVE_SIZE to a more reasonable value
author Robert McIntyre <rlm@mit.edu>
date Thu, 08 Mar 2012 22:29:11 -0600
parents d7c38ce83421
children db8e0a563c8e
rev   line source
rlm@43 1 package com.aurellem.gb;
rlm@43 2
rlm@43 3 import java.nio.ByteBuffer;
rlm@60 4 import java.nio.IntBuffer;
rlm@56 5 import java.nio.ByteOrder;
rlm@43 6
rlm@43 7 public class Gb {
rlm@43 8
rlm@43 9
rlm@43 10 public Gb(){}
rlm@43 11
rlm@43 12
rlm@43 13 /**
rlm@43 14 * Hello World! This is just to test the native interface.
rlm@43 15 */
rlm@48 16 public static native void sayHello();
rlm@43 17
rlm@43 18 /**
rlm@43 19 * Run the emulator on a given rom
rlm@43 20 * @param rom - the name of the rom.
rlm@43 21 */
rlm@48 22 public static native void startEmulator(String rom);
rlm@48 23
rlm@48 24
rlm@48 25 public static void loadVBA(){
rlm@48 26 System.loadLibrary("vba");
rlm@48 27 }
rlm@43 28
rlm@53 29 public static native void step();
rlm@53 30
rlm@55 31 public static native void step(int keymask);
rlm@55 32
rlm@53 33 public static native void shutdown();
rlm@50 34
rlm@76 35 public static native long saveState(ByteBuffer buffer, int size);
rlm@56 36
rlm@56 37 public static native void loadState(ByteBuffer buffer, int size);
rlm@56 38
rlm@80 39 public static final int MAX_SAVE_SIZE = 20000;
rlm@56 40
rlm@76 41 public static ByteBuffer createDirectByteBuffer(int capacity){
rlm@76 42 byte[] zeros = new byte[capacity];
rlm@56 43 ByteBuffer buf =
rlm@76 44 ByteBuffer.allocateDirect(capacity)
rlm@56 45 .order(ByteOrder.nativeOrder());
rlm@76 46 buf.put(zeros);
rlm@56 47 buf.clear();
rlm@56 48 return buf;
rlm@56 49 }
rlm@56 50
rlm@76 51 public static ByteBuffer saveBuffer(){
rlm@76 52 return createDirectByteBuffer(MAX_SAVE_SIZE);
rlm@76 53 }
rlm@76 54
rlm@76 55 public static ByteBuffer saveState(){
rlm@76 56 ByteBuffer buf = saveBuffer();
rlm@76 57
rlm@76 58 saveState(buf, buf.capacity());
rlm@76 59
rlm@76 60 // determine the extent of the saved data
rlm@76 61 int position = buf.capacity() - 1;
rlm@76 62 for (int i = position; i > 0; i--){
rlm@76 63 if (0 != buf.get(i)){
rlm@76 64 position = i;
rlm@76 65 break;
rlm@76 66 }}
rlm@76 67 System.out.println("Position: " + position);
rlm@76 68 byte[] saveArray = new byte[position];
rlm@76 69 ByteBuffer save = createDirectByteBuffer(position);
rlm@76 70 buf.get(saveArray, 0 , position);
rlm@76 71 save.put(saveArray);
rlm@76 72 save.rewind();
rlm@76 73 return save;
rlm@76 74 }
rlm@76 75
rlm@56 76 public static void loadState(ByteBuffer saveState){
rlm@76 77 loadState(saveState, MAX_SAVE_SIZE);
rlm@56 78 }
rlm@56 79
rlm@59 80 public static native int getROMSize();
rlm@59 81 public static native int getRAMSize();
rlm@59 82
rlm@59 83
rlm@59 84 public static final int WRAM_SIZE = 0x8000;
rlm@59 85
rlm@59 86 public static final int VRAM_SIZE = 0x4000;
rlm@59 87
rlm@62 88 public static final int NUM_REGISTERS = 27;
rlm@62 89
rlm@60 90 public static native void getRAM(int[] store);
rlm@59 91
rlm@60 92 public static native void getROM(int[] store);
rlm@59 93
rlm@60 94 public static native void getWRAM(int[] store);
rlm@60 95
rlm@60 96 public static native void getVRAM(int[] store);
rlm@62 97
rlm@62 98 public static native void getRegisters(int[] store);
rlm@43 99 }