changeset 106:3a60bb14a64a

better functional assembly interface; removed frame numbers from SaveStates
author Robert McIntyre <rlm@mit.edu>
date Wed, 14 Mar 2012 21:37:37 -0500
parents 2f8089eacab9
children ad96e9464d6a
files clojure/com/aurellem/assembly.clj clojure/com/aurellem/experiments/items.clj clojure/com/aurellem/gb_driver.clj clojure/com/aurellem/items.clj java/src/com/aurellem/gb/Gb.java
diffstat 5 files changed, 227 insertions(+), 197 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/assembly.clj	Tue Mar 13 14:40:01 2012 -0500
     1.2 +++ b/clojure/com/aurellem/assembly.clj	Wed Mar 14 21:37:37 2012 -0500
     1.3 @@ -2,14 +2,13 @@
     1.4    (:use (com.aurellem gb-driver vbm title items))
     1.5    (:import [com.aurellem.gb_driver SaveState]))
     1.6  
     1.7 -
     1.8 -
     1.9 +(defn mid-game []
    1.10 +  (read-state "mid-game"))
    1.11  
    1.12  (defn inject-assembly
    1.13    [^SaveState state
    1.14     program-counter registers
    1.15     assembly-code]
    1.16 -  (set-state! state)
    1.17    (let [scratch-memory (memory state)]
    1.18      ;; inject assembly code
    1.19      (dorun (map (fn [index val]
    1.20 @@ -17,12 +16,11 @@
    1.21                  (range program-counter
    1.22                         (+ program-counter (count assembly-code)))
    1.23                  assembly-code))
    1.24 -    (write-memory! scratch-memory)
    1.25 -    (set-state! (update-state))
    1.26 -    (write-registers! registers)
    1.27 -    (set-state! (update-state))
    1.28 -    (PC! program-counter)
    1.29 -    (update-state)))
    1.30 +    (-> state
    1.31 +        (write-memory! scratch-memory)
    1.32 +        (write-registers! registers)
    1.33 +        (PC! program-counter))))
    1.34 +        
    1.35  
    1.36  (defn inject-item-assembly
    1.37    ([^SaveState state assembly-code]
    1.38 @@ -34,19 +32,17 @@
    1.39  
    1.40  (defn info
    1.41    ([^SaveState state]
    1.42 -     (set-state! state)
    1.43 -     (println "PC: " (PC))
    1.44 -     (println "Instruction:" (format "0x%02X" (aget (memory state) (PC))))
    1.45 +     (println "PC: " (PC state))
    1.46 +     (println "Instruction:"
    1.47 +              (format "0x%02X" (aget (memory state) (PC state))))
    1.48       state))    
    1.49  
    1.50 -(defn irony [] (read-state 578544))
    1.51 -
    1.52  (defn run-assembly
    1.53    ([info-fn assembly n]
    1.54       (let [final-state
    1.55             (reduce (fn [state _]
    1.56                       (tick (info-fn state)))
    1.57 -                   (inject-item-assembly (tick (tick (tick (irony)))) assembly)
    1.58 +                   (inject-item-assembly (tick (tick (tick (mid-game)))) assembly)
    1.59                     (range n))]
    1.60         (shutdown!)
    1.61         final-state))
     2.1 --- a/clojure/com/aurellem/experiments/items.clj	Tue Mar 13 14:40:01 2012 -0500
     2.2 +++ b/clojure/com/aurellem/experiments/items.clj	Wed Mar 14 21:37:37 2012 -0500
     2.3 @@ -1,3 +1,7 @@
     2.4 +(ns com.aurellem.experiments.items
     2.5 +   (:use (com.aurellem gb-driver vbm title items))
     2.6 +   (:import [com.aurellem.gb_driver SaveState]))
     2.7 +
     2.8  ;; try just buying five potions in sequence and see what changes
     2.9  ;; each time.
    2.10  
    2.11 @@ -10,28 +14,27 @@
    2.12  
    2.13  ;; trying to find how items are represented in memory
    2.14  
    2.15 -(comment
    2.16 -  (def empty-inventory @current-state)
    2.17 -  
    2.18 -  (def one-potion @current-state)
    2.19 -  
    2.20 -  (def two-potions @current-state)
    2.21 -  
    2.22 -  (def three-potions @current-state)
    2.23 -  
    2.24 -  (def four-potions @current-state)
    2.25 -  
    2.26 -  (def five-potions @current-state)
    2.27 +(def zero-potions (read-state "zero-potions"))
    2.28 +
    2.29 +(def one-potion (read-state "one-potion"))
    2.30 +
    2.31 +(def two-potions (read-state "two-potions"))
    2.32 +
    2.33 +(def three-potions (read-state "three-potions"))
    2.34 +
    2.35 +(def four-potions (read-state "four-potions"))
    2.36 +
    2.37 +(def five-potions (read-state "five-potions"))
    2.38    
    2.39    
    2.40    ;; result
    2.41 -  (def canidates
    2.42 -    (apply common-differences
    2.43 -           (map (comp vec memory)
    2.44 -                [empty-inventory one-potion two-potions three-potions
    2.45 -                 four-potions five-potions])))
    2.46 +(defn canidates []
    2.47 +  (apply common-differences
    2.48 +         (map (comp vec memory)
    2.49 +              [zero-potions one-potion two-potions three-potions
    2.50 +               four-potions five-potions])))
    2.51  
    2.52 -  [55875 (37 15 49 27 14 44)]
    2.53 + (comment [55875 (37 15 49 27 14 44)]
    2.54    [55876 (30 1 49 56 55 23)]
    2.55    [49158 (154 191 78 135 70 73)]
    2.56    [54087 (49 40 37 34 25 22)]
    2.57 @@ -53,10 +56,6 @@
    2.58  
    2.59  
    2.60  
    2.61 -(def item-hack (read-state 7999))
    2.62 -
    2.63 -(def item-hack2 (read-state 75882))
    2.64 -
    2.65  (defn get-mem []
    2.66    (subvec (vec (memory @current-state)) 54040 (+ 54046 100)))
    2.67  
    2.68 @@ -92,14 +91,19 @@
    2.69  
    2.70  ;; now it's time to learn the item codes
    2.71  
    2.72 -(def item-hack-3 (read-state 77557))
    2.73 +(def inventory-begin
    2.74 +  (read-state "inventory-begin"))
    2.75 +
    2.76  (defn show-item
    2.77    "Run a saved pokemon with the first item replaced by the item named
    2.78     by n."
    2.79    [n]
    2.80 -  (set-state! item-hack-3)
    2.81 +  (set-state! inventory-begin)
    2.82    (let [mem (memory)]
    2.83 +    (aset mem 54044 1)
    2.84      (aset mem 54045 n)
    2.85 +    (aset mem 54046 1)
    2.86 +    (aset mem 54047 255)
    2.87      (write-memory! mem))
    2.88    (step)
    2.89    (->> [[] @current-state]
    2.90 @@ -372,3 +376,128 @@
    2.91  ;; 253   TM53
    2.92  ;; 254   TM54
    2.93  ;; 255   end-of-list-sentinel   
    2.94 +
    2.95 +
    2.96 +
    2.97 +(defn run-item-program
    2.98 +  "This is my first assembly/item program!
    2.99 +   it just increments BC by one.
   2.100 +
   2.101 +   The code places a 3 'great balls' at the beginning of the
   2.102 +   inventory, then directly sets the program counter to start
   2.103 +   executing at the position of the 'great balls' in memory.
   2.104 +
   2.105 +   Since a 'great ball' is represented in memory as 0x03, which
   2.106 +   corresponts to the opcode which increments BC by one, that is
   2.107 +   what happens. Then the program counter to the 0x03 quantity entry
   2.108 +   and BC is incremented again.
   2.109 +
   2.110 +   Obviously, the game crashes more or less immediately after the
   2.111 +   program counter advances past the 'great balls' into the next items
   2.112 +   in the inventory, thus I call shutdown! before anything bad happens."
   2.113 +  []
   2.114 +  (set-inventory (read-state "mid-game") [[:great-ball 3]])
   2.115 +  (print-inventory)
   2.116 +  (println "3 ticks") (tick) (tick) (tick)
   2.117 +  (println "PC before:" (PC))
   2.118 +  (println "BC before:" (BC))
   2.119 +  (PC! (inc item-list-start))
   2.120 +  (println "PC after setting:" (PC))
   2.121 +  (println "data at PC:" (aget (memory) (PC)))
   2.122 +  (println "one tick")
   2.123 +  (tick)
   2.124 +  (println "PC after one tick:" (PC))
   2.125 +  (println "BC after one tick:" (BC))
   2.126 +  (tick)
   2.127 +  (println "PC after two ticks:" (PC))
   2.128 +  (println "BC after two ticks:" (BC))
   2.129 +
   2.130 +  (shutdown!))
   2.131 +
   2.132 +
   2.133 +
   2.134 +
   2.135 +(defn test-opcodes-1
   2.136 +  []
   2.137 +  (let [final-state
   2.138 +        (->
   2.139 +         (read-state "mid-game")
   2.140 +         (set-inv-mem 
   2.141 +          [20 0x02 0x00 0x00 0x02 0x00 0x00
   2.142 +           0x00 0x0 0xFF])
   2.143 +         (print-inventory)
   2.144 +         ;;((fn [_] (println "3 ticks") _))
   2.145 +         (tick) (tick) (tick)
   2.146 +         
   2.147 +         ;;(println "PC before:" (PC))
   2.148 +         ;;(println "BC before:" (BC))
   2.149 +         ;;(println "AF:" (AF))
   2.150 +         (PC! (inc item-list-start))
   2.151 +         (BC! (+ 1 item-list-start))
   2.152 +         ;;(println "PC after setting:" (PC))
   2.153 +         ;;(println "data at PC:" (aget (memory) (PC)))
   2.154 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
   2.155 +         
   2.156 +         ;;(println "one tick")
   2.157 +         (tick)
   2.158 +         ;;(println "PC after one tick:" (PC))
   2.159 +         ;;(println "BC after one tick:" (BC))
   2.160 +         ;;(println "data at PC:" (aget (memory) (PC)))
   2.161 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
   2.162 +         (tick)
   2.163 +         (AF! 0xFFFF)
   2.164 +         ;;(println "PC after two ticks:" (PC))
   2.165 +         ;;(println "BC after two ticks:" (BC))
   2.166 +         ;;(println "data at PC:" (aget (memory) (PC)))
   2.167 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
   2.168 +         (tick)
   2.169 +         ;;(println "PC after three ticks:" (PC))
   2.170 +         ;;(println "BC after three ticks:" (BC))
   2.171 +         ;;(println "data at PC:" (aget (memory) (PC)))
   2.172 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
   2.173 +         (tick)
   2.174 +         ;;(println "PC after four ticks:" (PC))
   2.175 +         ;;(println "BC after four ticks:" (BC))
   2.176 +         ;;(println "data at PC:" (aget (memory) (PC)))
   2.177 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
   2.178 +         (tick)
   2.179 +         ;;(println "PC after five ticks:" (PC))
   2.180 +         ;;(println "BC after five ticks:" (BC))
   2.181 +         ;;(println "data at PC:" (aget (memory) (PC)))
   2.182 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
   2.183 +         (print-inventory)
   2.184 +         )]
   2.185 +    
   2.186 +    (shutdown!)
   2.187 +    final-state))
   2.188 +
   2.189 +
   2.190 +
   2.191 +(defn test-opcodes-2
   2.192 +  []
   2.193 +  (set-inv-mem (read-state "mid-game")
   2.194 +               [20 0x08 0x1D 0xD3 0x00 0x00 0x00
   2.195 +                0x00 0x0 0xFF])
   2.196 +  (print-inventory)
   2.197 +  (println "3 ticks") (tick) (tick) (tick)
   2.198 +  (println "PC before:" (PC))
   2.199 +  (println "SP:" (SP))
   2.200 +  (PC! (inc item-list-start))
   2.201 +  (println "PC after setting:" (PC))
   2.202 +  (println "SP:" (Integer/toBinaryString (SP)))
   2.203 +  (println "data at PC:" (aget (memory) (PC)))
   2.204 +  (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
   2.205 +  (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
   2.206 +  (println "one tick")
   2.207 +  (tick)
   2.208 +  (println "PC after one tick:" (PC))
   2.209 +  (println "data at PC:" (aget (memory) (PC)))
   2.210 +  (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
   2.211 +  (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
   2.212 +  (tick) (tick) (tick)
   2.213 +  (println "PC aftter four tick:" (PC))
   2.214 +  (println "data at PC:" (aget (memory) (PC)))
   2.215 +  (println "data at 0xD31D:" (aget (memory) 0xD31D))
   2.216 +  
   2.217 +  (print-inventory)
   2.218 +  (shutdown!))
     3.1 --- a/clojure/com/aurellem/gb_driver.clj	Tue Mar 13 14:40:01 2012 -0500
     3.2 +++ b/clojure/com/aurellem/gb_driver.clj	Wed Mar 14 21:37:37 2012 -0500
     3.3 @@ -5,31 +5,36 @@
     3.4      (:import (java.nio IntBuffer ByteOrder)))
     3.5  
     3.6  ;; Savestates
     3.7 -(defrecord SaveState [frame data])
     3.8 +(defrecord SaveState [data])
     3.9  
    3.10  (def ^:dynamic *save-state-cache*
    3.11    (File. "/home/r/proj/pokemon-escape/save-states/"))
    3.12  
    3.13 -(defn frame->filename [frame]
    3.14 -  (File. *save-state-cache* (format "%07d.sav" frame)))
    3.15 -  
    3.16 -(defn write-state! [^SaveState save]
    3.17 -  (let [buf (:data save)
    3.18 -        bytes (byte-array (.limit buf))
    3.19 -        dest (frame->filename (:frame save))]
    3.20 -    (.get buf bytes)
    3.21 -    (FileUtils/writeByteArrayToFile dest bytes)
    3.22 -    (.rewind buf)
    3.23 -    dest))
    3.24 +(def current-state (atom nil))
    3.25  
    3.26 -(defn read-state [frame]
    3.27 -  (let [save (frame->filename frame)]
    3.28 +(defn state-cache-file [name]
    3.29 +  (File. *save-state-cache* (str name ".sav")))
    3.30 +
    3.31 +(defn write-state!
    3.32 +  ([^SaveState name]
    3.33 +     (write-state! @current-state name))
    3.34 +  ([^SaveState save ^String name]
    3.35 +     (let [buffer (:data save)
    3.36 +           bytes (byte-array (.limit buffer))
    3.37 +           dest (state-cache-file name)]
    3.38 +       (.get buffer bytes)
    3.39 +       (FileUtils/writeByteArrayToFile dest bytes)
    3.40 +       (.rewind buffer)
    3.41 +       dest)))
    3.42 +
    3.43 +(defn read-state [name]
    3.44 +  (let [save (state-cache-file name)]
    3.45      (if (.exists save)
    3.46 -      (let [buf (Gb/saveBuffer)
    3.47 +      (let [buffer (Gb/saveBuffer)
    3.48              bytes (FileUtils/readFileToByteArray save)]
    3.49 -        (.put buf bytes)
    3.50 -        (.flip buf)
    3.51 -        (SaveState. frame buf)))))
    3.52 +        (.put buffer bytes)
    3.53 +        (.flip buffer)
    3.54 +        (SaveState. buffer)))))
    3.55  ;;;;;;;;;;;;;;;;
    3.56  
    3.57  ;; Gameboy management
    3.58 @@ -54,13 +59,12 @@
    3.59  ;;; The first state!
    3.60  (defn gen-root! []
    3.61    (restart!)
    3.62 -  (let [state (SaveState. 0  (Gb/saveState))]
    3.63 -    (write-state! state)
    3.64 -    state))
    3.65 +  (let [state (SaveState. (Gb/saveState))]
    3.66 +    (write-state! state "root" ) state))
    3.67  
    3.68  (defn root []
    3.69 -  (if (.exists (frame->filename 0))
    3.70 -    (read-state 0)
    3.71 +  (if (.exists (state-cache-file "root"))
    3.72 +    (read-state "root")
    3.73      (gen-root!)))
    3.74  
    3.75  ;;;; Press Buttons
    3.76 @@ -88,27 +92,24 @@
    3.77  (defn button-mask [buttons]
    3.78    (reduce bit-or 0x0000 (map button-code buttons)))
    3.79  
    3.80 -(def current-state (atom nil))
    3.81 -
    3.82  (defn set-state! [^SaveState state]
    3.83    (assert (:data state) "Not a valid state!")
    3.84    (if (not @on?) (restart!))
    3.85 -  (Gb/loadState (:data state))
    3.86 -  (reset! current-state state))
    3.87 -
    3.88 -(defrecord Move [keys state])
    3.89 +  (if (not= state @current-state)
    3.90 +    (do 
    3.91 +      (Gb/loadState (:data state))
    3.92 +      (reset! current-state state))))
    3.93  
    3.94  (defn update-state []
    3.95    (reset! current-state
    3.96 -          (SaveState. (:frame @current-state)
    3.97 -                      (Gb/saveState))))
    3.98 +          (SaveState. (Gb/saveState))))
    3.99  
   3.100  (defn step
   3.101    ([^SaveState state buttons]
   3.102       (set-state! state)
   3.103       (Gb/step (button-mask buttons))
   3.104       (reset! current-state 
   3.105 -             (SaveState. (inc (:frame state))(Gb/saveState))))
   3.106 +             (SaveState. (Gb/saveState))))
   3.107    ([^SaveState state]
   3.108       (step state [:listen]))
   3.109    ([] (step (if @current-state @current-state (root)))))
   3.110 @@ -120,18 +121,24 @@
   3.111       (Gb/tick)
   3.112       (update-state)))
   3.113  
   3.114 -(defn move
   3.115 -  [^Move move buttons]
   3.116 -  (Move. (step (:state move) buttons) buttons))
   3.117 -
   3.118  (defn play
   3.119    ([^SaveState state n]
   3.120 -     (reduce (fn [s _] (step s)) state (range n)))
   3.121 +     (try
   3.122 +       (set-state! state)
   3.123 +       (dorun (dotimes [_ n]
   3.124 +                (Thread/sleep 1)
   3.125 +                (Gb/step)))
   3.126 +
   3.127 +       (finally
   3.128 +             (update-state))))
   3.129    ([n]
   3.130       (play @current-state n)))
   3.131  
   3.132 -(defn continue! []
   3.133 -  (play @current-state Integer/MAX_VALUE))
   3.134 +(defn continue!
   3.135 +  ([state]
   3.136 +     (play state Integer/MAX_VALUE))
   3.137 +  ([]
   3.138 +    (continue! @current-state)))
   3.139  
   3.140  (defn play-moves
   3.141    ([moves [prev state]]
   3.142 @@ -152,10 +159,16 @@
   3.143           (set-state! state) (arr-fn store) store))))
   3.144  
   3.145  (defn write-cpu-data [size store-fn]
   3.146 -  (fn [new-data]
   3.147 -    (let [store (int-array new-data)]
   3.148 -      (assert (= size (count new-data)))
   3.149 -      (store-fn store))))
   3.150 +  (fn store-data
   3.151 +    ([state new-data]
   3.152 +       (set-state! state)
   3.153 +       (let [store (int-array new-data)]
   3.154 +         (assert (= size (count new-data)))
   3.155 +         (store-fn store)
   3.156 +         (update-state)))
   3.157 +    ([new-data]
   3.158 +       (store-data @current-state new-data))))
   3.159 +    
   3.160  
   3.161  (def memory
   3.162    (cpu-data Gb/GB_MEMORY #(Gb/getMemory %)))
     4.1 --- a/clojure/com/aurellem/items.clj	Tue Mar 13 14:40:01 2012 -0500
     4.2 +++ b/clojure/com/aurellem/items.clj	Wed Mar 14 21:37:37 2012 -0500
     4.3 @@ -214,7 +214,8 @@
     4.4                    (aset mem index val))
     4.5                  (range item-list-start
     4.6                         (+ item-list-start (count inv-codes))) inv-codes))
     4.7 -    (write-memory! mem)))
     4.8 +    (write-memory! mem)
     4.9 +    (update-state)))
    4.10    
    4.11    
    4.12  (defn set-inventory [^SaveState state new-inventory]
    4.13 @@ -235,7 +236,11 @@
    4.14                      (concat items (inventory state))))
    4.15    ([items]
    4.16       (give @current-state items)))
    4.17 -  
    4.18 +
    4.19 +(defn clear-inventory
    4.20 +  ([^SaveState state]
    4.21 +     (set-inventory state []))
    4.22 +  ([] (clear-inventory @current-state)))
    4.23  
    4.24  (def gliched-tms
    4.25    [[:TM51 1]
    4.26 @@ -264,115 +269,3 @@
    4.27     [:soulbadge 1]    
    4.28     ])
    4.29    
    4.30 -(defn run-item-program
    4.31 -  "This is my first assembly/item program!
    4.32 -   it just increments BC by one.
    4.33 -
    4.34 -   The code places a 3 'great balls' at the beginning of the
    4.35 -   inventory, then directly sets the program counter to start
    4.36 -   executing at the position of the 'great balls' in memory.
    4.37 -
    4.38 -   Since a 'great ball' is represented in memory as 0x03, which
    4.39 -   corresponts to the opcode which increments BC by one, that is
    4.40 -   what happens. Then the program counter to the 0x03 quantity entry
    4.41 -   and BC is incremented again.
    4.42 -
    4.43 -   Obviously, the game crashes more or less immediately after the
    4.44 -   program counter advances past the 'great balls' into the next items
    4.45 -   in the inventory, thus I call shutdown! before anything bad happens."
    4.46 -  []
    4.47 -  (set-inventory (read-state 578544) [[:great-ball 3]])
    4.48 -  (print-inventory)
    4.49 -  (println "3 ticks") (tick) (tick) (tick)
    4.50 -  (println "PC before:" (PC))
    4.51 -  (println "BC before:" (BC))
    4.52 -  (PC! (inc item-list-start))
    4.53 -  (println "PC after setting:" (PC))
    4.54 -  (println "data at PC:" (aget (memory) (PC)))
    4.55 -  (println "one tick")
    4.56 -  (tick)
    4.57 -  (println "PC after one tick:" (PC))
    4.58 -  (println "BC after one tick:" (BC))
    4.59 -  (tick)
    4.60 -  (println "PC after two ticks:" (PC))
    4.61 -  (println "BC after two ticks:" (BC))
    4.62 -
    4.63 -  (shutdown!))
    4.64 -
    4.65 -
    4.66 -(defn test-opcodes-1
    4.67 -  []
    4.68 -  (set-inv-mem (read-state 578544)
    4.69 -               [20 0x02 0x00 0x00 0x02 0x00 0x00
    4.70 -                0x00 0x0 0xFF])
    4.71 -  (print-inventory)
    4.72 -  (println "3 ticks") (tick) (tick) (tick)
    4.73 -  (println "PC before:" (PC))
    4.74 -  (println "BC before:" (BC))
    4.75 -  (println "AF:" (AF))
    4.76 -  (PC! (inc item-list-start))
    4.77 -  (BC! (+ 1 item-list-start))
    4.78 -  (println "PC after setting:" (PC))
    4.79 -  (println "data at PC:" (aget (memory) (PC)))
    4.80 -  (println "data at " (BC) "(BC):" (aget (memory) (BC)))
    4.81 -  
    4.82 -  (println "one tick")
    4.83 -  (tick)
    4.84 -  (println "PC after one tick:" (PC))
    4.85 -  (println "BC after one tick:" (BC))
    4.86 -  (println "data at PC:" (aget (memory) (PC)))
    4.87 -  (println "data at " (BC) "(BC):" (aget (memory) (BC)))
    4.88 -  (tick)
    4.89 -  (AF! 0xFFFF)
    4.90 -  (println "PC after two ticks:" (PC))
    4.91 -  (println "BC after two ticks:" (BC))
    4.92 -  (println "data at PC:" (aget (memory) (PC)))
    4.93 -  (println "data at " (BC) "(BC):" (aget (memory) (BC)))
    4.94 -  (tick)
    4.95 -  (println "PC after three ticks:" (PC))
    4.96 -  (println "BC after three ticks:" (BC))
    4.97 -  (println "data at PC:" (aget (memory) (PC)))
    4.98 -  (println "data at " (BC) "(BC):" (aget (memory) (BC)))
    4.99 -  (tick)
   4.100 -  (println "PC after four ticks:" (PC))
   4.101 -  (println "BC after four ticks:" (BC))
   4.102 -  (println "data at PC:" (aget (memory) (PC)))
   4.103 -  (println "data at " (BC) "(BC):" (aget (memory) (BC)))
   4.104 -  (tick)
   4.105 -  (println "PC after five ticks:" (PC))
   4.106 -  (println "BC after five ticks:" (BC))
   4.107 -  (println "data at PC:" (aget (memory) (PC)))
   4.108 -  (println "data at " (BC) "(BC):" (aget (memory) (BC)))
   4.109 -  (print-inventory)
   4.110 -  (shutdown!))
   4.111 -
   4.112 -
   4.113 -
   4.114 -(defn test-opcodes-2
   4.115 -  []
   4.116 -  (set-inv-mem (read-state 578544)
   4.117 -               [20 0x08 0x1D 0xD3 0x00 0x00 0x00
   4.118 -                0x00 0x0 0xFF])
   4.119 -  (print-inventory)
   4.120 -  (println "3 ticks") (tick) (tick) (tick)
   4.121 -  (println "PC before:" (PC))
   4.122 -  (println "SP:" (SP))
   4.123 -  (PC! (inc item-list-start))
   4.124 -  (println "PC after setting:" (PC))
   4.125 -  (println "SP:" (Integer/toBinaryString (SP)))
   4.126 -  (println "data at PC:" (aget (memory) (PC)))
   4.127 -  (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
   4.128 -  (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
   4.129 -  (println "one tick")
   4.130 -  (tick)
   4.131 -  (println "PC after one tick:" (PC))
   4.132 -  (println "data at PC:" (aget (memory) (PC)))
   4.133 -  (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
   4.134 -  (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
   4.135 -  (tick) (tick) (tick)
   4.136 -  (println "PC aftter four tick:" (PC))
   4.137 -  (println "data at PC:" (aget (memory) (PC)))
   4.138 -  (println "data at 0xD31D:" (aget (memory) 0xD31D))
   4.139 -  
   4.140 -  (print-inventory)
   4.141 -  (shutdown!))
     5.1 --- a/java/src/com/aurellem/gb/Gb.java	Tue Mar 13 14:40:01 2012 -0500
     5.2 +++ b/java/src/com/aurellem/gb/Gb.java	Wed Mar 14 21:37:37 2012 -0500
     5.3 @@ -20,7 +20,6 @@
     5.4       * @param rom - the name of the rom.
     5.5       */
     5.6      public static native void startEmulator(String rom);
     5.7 -
     5.8      
     5.9      public static void loadVBA(){
    5.10  	System.loadLibrary("vba");