Mercurial > vba-clojure
comparison java/src/com/aurellem/gb/Gb.java @ 76:d7c38ce83421
working on disk-backup for save-states
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 08 Mar 2012 19:48:54 -0600 |
parents | 4699c7bab77d |
children | ad6ebe886a21 |
comparison
equal
deleted
inserted
replaced
75:eb7d4efe0f34 | 76:d7c38ce83421 |
---|---|
30 | 30 |
31 public static native void step(int keymask); | 31 public static native void step(int keymask); |
32 | 32 |
33 public static native void shutdown(); | 33 public static native void shutdown(); |
34 | 34 |
35 public static native void saveState(ByteBuffer buffer, int size); | 35 public static native long saveState(ByteBuffer buffer, int size); |
36 | 36 |
37 public static native void loadState(ByteBuffer buffer, int size); | 37 public static native void loadState(ByteBuffer buffer, int size); |
38 | 38 |
39 public static final int SAVE_SIZE = 90000; | 39 public static final int MAX_SAVE_SIZE = 90000; |
40 | 40 |
41 public static ByteBuffer saveState(){ | 41 public static ByteBuffer createDirectByteBuffer(int capacity){ |
42 byte[] zeros = new byte[capacity]; | |
42 ByteBuffer buf = | 43 ByteBuffer buf = |
43 ByteBuffer.allocateDirect(SAVE_SIZE) | 44 ByteBuffer.allocateDirect(capacity) |
44 .order(ByteOrder.nativeOrder()); | 45 .order(ByteOrder.nativeOrder()); |
46 buf.put(zeros); | |
45 buf.clear(); | 47 buf.clear(); |
46 saveState(buf, SAVE_SIZE); | |
47 buf.flip(); | |
48 return buf; | 48 return buf; |
49 } | 49 } |
50 | 50 |
51 public static ByteBuffer saveBuffer(){ | |
52 return createDirectByteBuffer(MAX_SAVE_SIZE); | |
53 } | |
54 | |
55 public static ByteBuffer saveState(){ | |
56 ByteBuffer buf = saveBuffer(); | |
57 | |
58 saveState(buf, buf.capacity()); | |
59 | |
60 // determine the extent of the saved data | |
61 int position = buf.capacity() - 1; | |
62 for (int i = position; i > 0; i--){ | |
63 if (0 != buf.get(i)){ | |
64 position = i; | |
65 break; | |
66 }} | |
67 System.out.println("Position: " + position); | |
68 byte[] saveArray = new byte[position]; | |
69 ByteBuffer save = createDirectByteBuffer(position); | |
70 buf.get(saveArray, 0 , position); | |
71 save.put(saveArray); | |
72 save.rewind(); | |
73 return save; | |
74 } | |
75 | |
51 public static void loadState(ByteBuffer saveState){ | 76 public static void loadState(ByteBuffer saveState){ |
52 loadState(saveState, SAVE_SIZE); | 77 loadState(saveState, MAX_SAVE_SIZE); |
53 } | 78 } |
54 | 79 |
55 public static native int getROMSize(); | 80 public static native int getROMSize(); |
56 public static native int getRAMSize(); | 81 public static native int getRAMSize(); |
57 | 82 |