diff clojure/com/aurellem/exp/item_bridge.clj @ 233:49a709c555f2

succesful return of control to the game upon item injection.
author Robert McIntyre <rlm@mit.edu>
date Sat, 24 Mar 2012 16:19:43 -0500
parents 8523faa122b0
children 5becef6312b9
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/exp/item_bridge.clj	Sat Mar 24 15:21:24 2012 -0500
     1.2 +++ b/clojure/com/aurellem/exp/item_bridge.clj	Sat Mar 24 16:19:43 2012 -0500
     1.3 @@ -148,6 +148,14 @@
     1.4           (set-memory-range 0xD36D [0x1D 0xD3])))
     1.5    ([] (prepare-memory @current-state)))
     1.6  
     1.7 +(def memory-function-address-start 0xD36D)
     1.8 +
     1.9 +(defn read-map-function-address
    1.10 +  ([^SaveState state]
    1.11 +     (let [mem (memory state)]
    1.12 +       [(aget mem memory-function-address-start)
    1.13 +        (aget mem (inc memory-function-address-start))]))
    1.14 +  ([] (read-map-function-address @current-state)))
    1.15  
    1.16  (defn succesful-PC-capture
    1.17    "This function demonstrates successful PC capturing by
    1.18 @@ -162,4 +170,31 @@
    1.19          (capture-program-counter 
    1.20           (prepare-memory (menu-open-state))
    1.21           9000000))))
    1.22 -			      
    1.23 \ No newline at end of file
    1.24 +
    1.25 +(defn trampoline-assembly [^SaveState state]
    1.26 +  (flatten
    1.27 +   [0x3E ;; 
    1.28 +    0x3E ;; load lemonade into A
    1.29 +    
    1.30 +    0xEA
    1.31 +    0x1D
    1.32 +    0xD3 ;; set first item to lemonade
    1.33 +    
    1.34 +    0xC3 ;; return control to the game via absolute junp.
    1.35 +    (read-map-function-address state)
    1.36 +    ]))
    1.37 +
    1.38 +(defn test-trampoline
    1.39 +  "Demonstrates item-program execution via the map-function that
    1.40 +   returns control to the main pokemon game after one loop."
    1.41 +  []
    1.42 +  (let [insertion-address 0xD33D
    1.43 +        insertion-address-bits [0x3D 0xD3]]
    1.44 +  (->
    1.45 +   (menu-open-state)
    1.46 +   (set-memory-range
    1.47 +    insertion-address
    1.48 +    (trampoline-assembly (menu-open-state)))
    1.49 +   (set-memory-range 
    1.50 +    memory-function-address-start
    1.51 +    insertion-address-bits))))
    1.52 \ No newline at end of file