annotate java/src/com/aurellem/gb/Gb.java @ 343:652c5abee892

constructing exact item-pc layout for item-writer.
author Robert McIntyre <rlm@mit.edu>
date Sun, 08 Apr 2012 08:27:55 -0500
parents 893c753f8088
children 09b3bc0b71b5
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@93 104 public static native void getMemory(int[] store);
rlm@93 105
rlm@96 106 public static native void writeMemory(int[] newMemory);
rlm@96 107
rlm@60 108 public static native void getRAM(int[] store);
rlm@59 109
rlm@60 110 public static native void getROM(int[] store);
rlm@59 111
rlm@191 112 public static native void writeROM(int[] newROM);
rlm@191 113
rlm@60 114 public static native void getWRAM(int[] store);
rlm@60 115
rlm@60 116 public static native void getVRAM(int[] store);
rlm@62 117
rlm@62 118 public static native void getRegisters(int[] store);
rlm@100 119
rlm@100 120 public static native void writeRegisters(int[] newRegisters);
rlm@100 121
rlm@43 122 }