# HG changeset patch # User Robert McIntyre # Date 1332623983 18000 # Node ID 49a709c555f2f9e2787df5e8334b6181aef69ab4 # Parent e1dd3624d295373a507acaa4159f8d47730db47b succesful return of control to the game upon item injection. diff -r e1dd3624d295 -r 49a709c555f2 clojure/com/aurellem/exp/item_bridge.clj --- a/clojure/com/aurellem/exp/item_bridge.clj Sat Mar 24 15:21:24 2012 -0500 +++ b/clojure/com/aurellem/exp/item_bridge.clj Sat Mar 24 16:19:43 2012 -0500 @@ -148,6 +148,14 @@ (set-memory-range 0xD36D [0x1D 0xD3]))) ([] (prepare-memory @current-state))) +(def memory-function-address-start 0xD36D) + +(defn read-map-function-address + ([^SaveState state] + (let [mem (memory state)] + [(aget mem memory-function-address-start) + (aget mem (inc memory-function-address-start))])) + ([] (read-map-function-address @current-state))) (defn succesful-PC-capture "This function demonstrates successful PC capturing by @@ -162,4 +170,31 @@ (capture-program-counter (prepare-memory (menu-open-state)) 9000000)))) - \ No newline at end of file + +(defn trampoline-assembly [^SaveState state] + (flatten + [0x3E ;; + 0x3E ;; load lemonade into A + + 0xEA + 0x1D + 0xD3 ;; set first item to lemonade + + 0xC3 ;; return control to the game via absolute junp. + (read-map-function-address state) + ])) + +(defn test-trampoline + "Demonstrates item-program execution via the map-function that + returns control to the main pokemon game after one loop." + [] + (let [insertion-address 0xD33D + insertion-address-bits [0x3D 0xD3]] + (-> + (menu-open-state) + (set-memory-range + insertion-address + (trampoline-assembly (menu-open-state))) + (set-memory-range + memory-function-address-start + insertion-address-bits)))) \ No newline at end of file