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 byte[] saveArray = new byte[position];
|
rlm@76
|
68 ByteBuffer save = createDirectByteBuffer(position);
|
rlm@76
|
69 buf.get(saveArray, 0 , position);
|
rlm@76
|
70 save.put(saveArray);
|
rlm@76
|
71 save.rewind();
|
rlm@76
|
72 return save;
|
rlm@76
|
73 }
|
rlm@76
|
74
|
rlm@56
|
75 public static void loadState(ByteBuffer saveState){
|
rlm@76
|
76 loadState(saveState, MAX_SAVE_SIZE);
|
rlm@56
|
77 }
|
rlm@56
|
78
|
rlm@59
|
79 public static native int getROMSize();
|
rlm@59
|
80 public static native int getRAMSize();
|
rlm@59
|
81
|
rlm@59
|
82
|
rlm@59
|
83 public static final int WRAM_SIZE = 0x8000;
|
rlm@59
|
84
|
rlm@59
|
85 public static final int VRAM_SIZE = 0x4000;
|
rlm@59
|
86
|
rlm@62
|
87 public static final int NUM_REGISTERS = 27;
|
rlm@62
|
88
|
rlm@60
|
89 public static native void getRAM(int[] store);
|
rlm@59
|
90
|
rlm@60
|
91 public static native void getROM(int[] store);
|
rlm@59
|
92
|
rlm@60
|
93 public static native void getWRAM(int[] store);
|
rlm@60
|
94
|
rlm@60
|
95 public static native void getVRAM(int[] store);
|
rlm@62
|
96
|
rlm@62
|
97 public static native void getRegisters(int[] store);
|
rlm@43
|
98 }
|