view java/src/com/aurellem/gb/Gb.java @ 549:6ce1d5fd4911

update choreo files.
author Robert McIntyre <rlm@mit.edu>
date Thu, 23 Aug 2012 19:58:14 -0400
parents 2620d6318e8d
children
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 rom
20 * @param rom - the name of the rom.
21 */
22 public static native void startEmulator(String rom);
24 public static void loadVBA(){
25 System.loadLibrary("vba");
26 }
28 public static native void step();
30 public static native int ntick();
32 public static boolean tick(){
33 return (1 == ntick());
34 }
36 public static native void nstep(int keymask);
38 public static void step(int keymask){
39 if (-1 == keymask) {step();}
40 else {nstep(keymask);}}
42 public static native void shutdown();
44 public static native long saveState(ByteBuffer buffer, int size);
46 public static native void loadState(ByteBuffer buffer, int size);
48 public static final int MAX_SAVE_SIZE = 20000;
50 public static ByteBuffer createDirectByteBuffer(int capacity){
51 byte[] zeros = new byte[capacity];
52 ByteBuffer buf =
53 ByteBuffer.allocateDirect(capacity)
54 .order(ByteOrder.nativeOrder());
55 buf.put(zeros);
56 buf.clear();
57 return buf;
58 }
60 public static ByteBuffer saveBuffer(){
61 return createDirectByteBuffer(MAX_SAVE_SIZE);
62 }
64 public static ByteBuffer saveState(){
65 ByteBuffer buf = saveBuffer();
67 saveState(buf, buf.capacity());
69 // determine the extent of the saved data
70 int position = buf.capacity() - 1;
71 for (int i = position; i > 0; i--){
72 if (0 != buf.get(i)){
73 position = i;
74 break;
75 }}
76 byte[] saveArray = new byte[position];
77 ByteBuffer save = createDirectByteBuffer(position);
78 buf.get(saveArray, 0 , position);
79 save.put(saveArray);
80 save.rewind();
81 return save;
82 }
84 public static void loadState(ByteBuffer saveState){
85 loadState(saveState, MAX_SAVE_SIZE);
86 }
88 public static native int getROMSize();
89 public static native int getRAMSize();
92 public static final int WRAM_SIZE = 0x8000;
94 public static final int VRAM_SIZE = 0x4000;
96 public static final int RAM_SIZE = 0x8000;
98 public static final int ROM_SIZE = 0x100000;
100 public static final int NUM_REGISTERS = 29;
102 public static final int GB_MEMORY = 0x10000;
104 public static final int MAX_SOUND_BYTES = 44100*2;
106 public static native void getMemory(int[] store);
108 public static native void writeMemory(int[] newMemory);
110 public static native void getRAM(int[] store);
112 public static native void getROM(int[] store);
114 public static native void writeROM(int[] newROM);
116 public static native void getWRAM(int[] store);
118 public static native void getVRAM(int[] store);
120 public static native void getRegisters(int[] store);
122 public static native void writeRegisters(int[] newRegisters);
124 public static native void translateRGB(int[] rgb, int[] store);
126 public static final int DISPLAY_WIDTH = 160;
128 public static final int DISPLAY_HEIGHT = 144;
130 public static native void getPixels(int[] store);
132 public static native void nwritePNG(String filename);
134 public static native int readMemory(int address);
136 public static native void getFrameSound(byte[] store);
138 public static native int getSoundFrameWritten();
140 public static native void setSoundFrameWritten(int frames);
142 public static native void getFrameSound2(byte[] store);
144 }