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@83
|
31 public static native void nstep(int keymask);
|
rlm@83
|
32
|
rlm@83
|
33 public static void step(int keymask){
|
rlm@83
|
34 if (-1 == keymask) {step();}
|
rlm@83
|
35 else {nstep(keymask);}}
|
rlm@55
|
36
|
rlm@53
|
37 public static native void shutdown();
|
rlm@50
|
38
|
rlm@76
|
39 public static native long saveState(ByteBuffer buffer, int size);
|
rlm@56
|
40
|
rlm@56
|
41 public static native void loadState(ByteBuffer buffer, int size);
|
rlm@56
|
42
|
rlm@80
|
43 public static final int MAX_SAVE_SIZE = 20000;
|
rlm@56
|
44
|
rlm@76
|
45 public static ByteBuffer createDirectByteBuffer(int capacity){
|
rlm@76
|
46 byte[] zeros = new byte[capacity];
|
rlm@56
|
47 ByteBuffer buf =
|
rlm@76
|
48 ByteBuffer.allocateDirect(capacity)
|
rlm@56
|
49 .order(ByteOrder.nativeOrder());
|
rlm@76
|
50 buf.put(zeros);
|
rlm@56
|
51 buf.clear();
|
rlm@56
|
52 return buf;
|
rlm@56
|
53 }
|
rlm@56
|
54
|
rlm@76
|
55 public static ByteBuffer saveBuffer(){
|
rlm@76
|
56 return createDirectByteBuffer(MAX_SAVE_SIZE);
|
rlm@76
|
57 }
|
rlm@76
|
58
|
rlm@76
|
59 public static ByteBuffer saveState(){
|
rlm@76
|
60 ByteBuffer buf = saveBuffer();
|
rlm@76
|
61
|
rlm@76
|
62 saveState(buf, buf.capacity());
|
rlm@76
|
63
|
rlm@76
|
64 // determine the extent of the saved data
|
rlm@76
|
65 int position = buf.capacity() - 1;
|
rlm@76
|
66 for (int i = position; i > 0; i--){
|
rlm@76
|
67 if (0 != buf.get(i)){
|
rlm@76
|
68 position = i;
|
rlm@76
|
69 break;
|
rlm@76
|
70 }}
|
rlm@76
|
71 byte[] saveArray = new byte[position];
|
rlm@76
|
72 ByteBuffer save = createDirectByteBuffer(position);
|
rlm@76
|
73 buf.get(saveArray, 0 , position);
|
rlm@76
|
74 save.put(saveArray);
|
rlm@76
|
75 save.rewind();
|
rlm@76
|
76 return save;
|
rlm@76
|
77 }
|
rlm@76
|
78
|
rlm@56
|
79 public static void loadState(ByteBuffer saveState){
|
rlm@76
|
80 loadState(saveState, MAX_SAVE_SIZE);
|
rlm@56
|
81 }
|
rlm@56
|
82
|
rlm@59
|
83 public static native int getROMSize();
|
rlm@59
|
84 public static native int getRAMSize();
|
rlm@59
|
85
|
rlm@59
|
86
|
rlm@59
|
87 public static final int WRAM_SIZE = 0x8000;
|
rlm@59
|
88
|
rlm@59
|
89 public static final int VRAM_SIZE = 0x4000;
|
rlm@59
|
90
|
rlm@62
|
91 public static final int NUM_REGISTERS = 27;
|
rlm@62
|
92
|
rlm@60
|
93 public static native void getRAM(int[] store);
|
rlm@59
|
94
|
rlm@60
|
95 public static native void getROM(int[] store);
|
rlm@59
|
96
|
rlm@60
|
97 public static native void getWRAM(int[] store);
|
rlm@60
|
98
|
rlm@60
|
99 public static native void getVRAM(int[] store);
|
rlm@62
|
100
|
rlm@62
|
101 public static native void getRegisters(int[] store);
|
rlm@43
|
102 }
|