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