annotate java/src/com/aurellem/gb/Gb.java @ 537:04f61ade7879

allow repositioning of music data.
author Robert McIntyre <rlm@mit.edu>
date Mon, 25 Jun 2012 14:50:28 -0500
parents 2620d6318e8d
children
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 public static void loadVBA(){
rlm@48 25 System.loadLibrary("vba");
rlm@48 26 }
rlm@43 27
rlm@53 28 public static native void step();
rlm@92 29
rlm@92 30 public static native int ntick();
rlm@92 31
rlm@92 32 public static boolean tick(){
rlm@92 33 return (1 == ntick());
rlm@92 34 }
rlm@53 35
rlm@83 36 public static native void nstep(int keymask);
rlm@83 37
rlm@83 38 public static void step(int keymask){
rlm@83 39 if (-1 == keymask) {step();}
rlm@83 40 else {nstep(keymask);}}
rlm@55 41
rlm@53 42 public static native void shutdown();
rlm@50 43
rlm@76 44 public static native long saveState(ByteBuffer buffer, int size);
rlm@56 45
rlm@56 46 public static native void loadState(ByteBuffer buffer, int size);
rlm@56 47
rlm@80 48 public static final int MAX_SAVE_SIZE = 20000;
rlm@56 49
rlm@76 50 public static ByteBuffer createDirectByteBuffer(int capacity){
rlm@76 51 byte[] zeros = new byte[capacity];
rlm@56 52 ByteBuffer buf =
rlm@76 53 ByteBuffer.allocateDirect(capacity)
rlm@56 54 .order(ByteOrder.nativeOrder());
rlm@76 55 buf.put(zeros);
rlm@56 56 buf.clear();
rlm@56 57 return buf;
rlm@56 58 }
rlm@56 59
rlm@76 60 public static ByteBuffer saveBuffer(){
rlm@76 61 return createDirectByteBuffer(MAX_SAVE_SIZE);
rlm@76 62 }
rlm@76 63
rlm@76 64 public static ByteBuffer saveState(){
rlm@76 65 ByteBuffer buf = saveBuffer();
rlm@76 66
rlm@76 67 saveState(buf, buf.capacity());
rlm@76 68
rlm@76 69 // determine the extent of the saved data
rlm@76 70 int position = buf.capacity() - 1;
rlm@76 71 for (int i = position; i > 0; i--){
rlm@76 72 if (0 != buf.get(i)){
rlm@76 73 position = i;
rlm@76 74 break;
rlm@76 75 }}
rlm@76 76 byte[] saveArray = new byte[position];
rlm@76 77 ByteBuffer save = createDirectByteBuffer(position);
rlm@76 78 buf.get(saveArray, 0 , position);
rlm@76 79 save.put(saveArray);
rlm@76 80 save.rewind();
rlm@76 81 return save;
rlm@76 82 }
rlm@76 83
rlm@56 84 public static void loadState(ByteBuffer saveState){
rlm@76 85 loadState(saveState, MAX_SAVE_SIZE);
rlm@56 86 }
rlm@56 87
rlm@59 88 public static native int getROMSize();
rlm@59 89 public static native int getRAMSize();
rlm@59 90
rlm@59 91
rlm@59 92 public static final int WRAM_SIZE = 0x8000;
rlm@59 93
rlm@59 94 public static final int VRAM_SIZE = 0x4000;
rlm@93 95
rlm@93 96 public static final int RAM_SIZE = 0x8000;
rlm@93 97
rlm@93 98 public static final int ROM_SIZE = 0x100000;
rlm@59 99
rlm@107 100 public static final int NUM_REGISTERS = 29;
rlm@62 101
rlm@93 102 public static final int GB_MEMORY = 0x10000;
rlm@93 103
rlm@526 104 public static final int MAX_SOUND_BYTES = 44100*2;
rlm@523 105
rlm@93 106 public static native void getMemory(int[] store);
rlm@93 107
rlm@96 108 public static native void writeMemory(int[] newMemory);
rlm@96 109
rlm@60 110 public static native void getRAM(int[] store);
rlm@59 111
rlm@60 112 public static native void getROM(int[] store);
rlm@59 113
rlm@191 114 public static native void writeROM(int[] newROM);
rlm@191 115
rlm@60 116 public static native void getWRAM(int[] store);
rlm@60 117
rlm@60 118 public static native void getVRAM(int[] store);
rlm@62 119
rlm@62 120 public static native void getRegisters(int[] store);
rlm@100 121
rlm@100 122 public static native void writeRegisters(int[] newRegisters);
rlm@100 123
rlm@488 124 public static native void translateRGB(int[] rgb, int[] store);
rlm@488 125
rlm@496 126 public static final int DISPLAY_WIDTH = 160;
rlm@496 127
rlm@496 128 public static final int DISPLAY_HEIGHT = 144;
rlm@496 129
rlm@496 130 public static native void getPixels(int[] store);
rlm@496 131
rlm@496 132 public static native void nwritePNG(String filename);
rlm@496 133
rlm@522 134 public static native int readMemory(int address);
rlm@523 135
rlm@524 136 public static native void getFrameSound(byte[] store);
rlm@524 137
rlm@523 138 public static native int getSoundFrameWritten();
rlm@523 139
rlm@523 140 public static native void setSoundFrameWritten(int frames);
rlm@523 141
rlm@525 142 public static native void getFrameSound2(byte[] store);
rlm@525 143
rlm@43 144 }