Mercurial > vba-clojure
view clojure/com/aurellem/exp/item_bridge.clj @ 317:3c5bf2221ea0
remove crufty functions.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 02 Apr 2012 21:25:24 -0500 |
parents | 8e63b0bb8ea3 |
children | 92c47a9cdaea |
line wrap: on
line source
1 (ns com.aurellem.exp.item-bridge2 (:use (com.aurellem.gb saves util constants gb-driver vbm items assembly))3 (:use (com.aurellem.run title save-corruption))4 ;;(:use (com.aurellem.exp pokemon))5 (:import [com.aurellem.gb.gb_driver SaveState]))7 (defn corrupt-item-state []8 (second (destroy-item-end-of-list-marker)))10 (defn corrupt-item-state []11 (read-state "corrupt-items"))13 (defn view-memory-range14 ([start end]15 (view-memory-range16 @current-state start end))17 ([state start end]18 (dorun19 (map (fn [loc val]20 (println (format "%04X : %02X" loc val)))21 (range start end) (subvec (vec (memory state)) start end)))22 state))24 (defn almost-broken25 "if one more memory location is turned into 0x03, the game crashes."26 [n]27 (view-memory-range28 (set-inv-mem (mid-game)29 (concat [0xFF] (repeat 64 0x03)30 (subvec (vec (memory (mid-game)))31 (+ item-list-start 65)32 (+ item-list-start 65 n))33 (repeat (- 255 65 n) 0x03)))34 item-list-start (+ item-list-start 255)))36 (defn actually-broken37 "if this memory location is turned into 0x03, the game crashes."38 []39 (set-memory (mid-game) 0xD35D 0x03))42 ;; (almost-broken 20) more or less works44 (defn capture-program-counter45 "records the program counter for each tick"46 [^SaveState state ticks]47 (let [i (atom 0)]48 (reduce (fn [[program-counters state] _]49 (println (swap! i inc))50 [(conj program-counters (PC state))51 (tick state)])52 [[] state]53 (range ticks))))56 (defn capture-program-counter57 [^SaveState state ticks]58 (tick state)60 (loop [i 061 pcs []]62 (if (= i ticks)63 (filter (partial < 0x2000)(sort (set pcs)))64 (do65 (com.aurellem.gb.Gb/tick)66 (recur (inc i)67 (conj pcs (first (registers))))))))69 (defn loop-program []70 [0x00 ;0xD31D ;; disable-interrupts72 0xC3 ;; loop forever73 0x1D74 0xD3])76 (def map-function-address-start 0xD36D)78 (defn test-loop []79 (continue!80 (-> (mid-game)81 (set-memory-range 0xD31D (loop-program))82 (set-memory-range83 map-function-address-start84 [0xD3 0x1D]))))86 (defn-memo corrupt-moves []87 (concat88 (first89 (->>90 [[] (mid-game)]91 (advance [:b] [:b :start])92 (advance [] [:d])93 (play-moves [[] [] [] [:d] [] [] [] [:d] [] [] [:a]])94 scroll-text95 (play-moves96 ;; this section is copied from speedrun-294297 ;; and corrupts the save so that the end-of-list marker98 ;; for the pokemon roster is destroyed, but the save is still99 ;; playable.100 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []101 [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])102 (title)103 (advance [] [:start])104 (advance [] [:a])105 (advance [:a] [:a :start])))106 [[]]))108 (defn corrupt109 "enter the codes to destroy the110 pokemon list using save corruption"111 ([^SaveState state]112 (run-moves113 state114 (corrupt-moves)))115 ([] (corrupt @current-state)))117 (defn mid-game-corrupt []118 (read-state "corrupt-mid-game"))120 (defn gen-start-game-corrupt []121 (->> (second (intro))122 (advance [:b] [:a :b :start])123 (play-moves (corrupt-moves))))125 (defn start-game-corrupt []126 (read-state "corrupt-start-game"))128 (defn test-memory-fun [n]129 (capture-program-counter130 (set-memory-range131 (tick (mid-game))132 0xD36D133 [0 0])134 n))136 ;;(def good (test-memory-fun 17000))138 ;;(def bad (test-memory-fun 18000))142 (defn menu-open-state []143 (read-state "menu-open"))145 (defn prepare-memory146 ([^SaveState state]147 (-> state148 (set-memory-range 0xD31D (loop-program))149 (set-memory-range 0xD36D [0x1D 0xD3])))150 ([] (prepare-memory @current-state)))152 (def memory-function-address-start 0xD36D)154 (defn read-map-function-address155 ([^SaveState state]156 (let [mem (memory state)]157 [(aget mem memory-function-address-start)158 (aget mem (inc memory-function-address-start))]))159 ([] (read-map-function-address @current-state)))161 (defn succesful-PC-capture162 "This function demonstrates successful PC capturing by163 setting 0xD36D to the value of the start location of164 a specially prepared program.166 You must run the function and then exit the open menu167 to see the effect."168 []169 (dorun170 (map #(println (Integer/toHexString %))171 (capture-program-counter172 (prepare-memory (menu-open-state))173 9000000))))175 (defn trampoline-assembly [^SaveState state]176 (flatten177 [0x3E ;;178 0x3E ;; load lemonade into A180 0xEA181 0x1D182 0xD3 ;; set first item to lemonade184 0xC3 ;; return control to the game via absolute jump.185 (read-map-function-address state)186 ]))188 (defn test-trampoline189 "Demonstrates item-program execution via the map-function that190 returns control to the main pokemon game after one loop."191 [assembly-fn state]192 (let [insertion-address 0xD33D193 insertion-address-bits [0x3D 0xD3]]194 (->195 state196 (set-memory-range197 insertion-address198 (assembly-fn state))199 (set-memory-range200 memory-function-address-start201 insertion-address-bits))))203 (def lemonade-trampoline204 (partial test-trampoline205 trampoline-assembly206 (menu-open-state)))208 (defn trampoline-assembly-burn-heal [^SaveState state]209 (flatten210 [0x3E ;;211 0x3E ;; load lemonade into A213 0xEA214 0x1D215 0xD3 ;; set first item to lemonade217 0xC3 ;; return control to the game via absolute jump218 0x0C ;; to Route 3's map-function219 0x55220 ]))224 (def pc-item-list-start 0xD539)225 (def pc-item-list-width 101)227 (def corrupted-items-width 512)229 (defn items-record230 ([^SaveState state]231 (subvec (vec (memory state))232 item-list-start233 (+ item-list-start corrupted-items-width)))234 ([] (items-record @current-state)))236 (defn pc-items-record237 ([^SaveState state]238 (subvec (vec (memory state))239 pc-item-list-start240 (+ pc-item-list-width pc-item-list-start)))241 ([] (pc-items-record @current-state)))243 (defn print-listing-items244 ([^SaveState state]245 (print-listing state item-list-start246 (+ item-list-start corrupted-items-width))247 state)248 ([] (print-listing-items @current-state)))250 (defn print-listing-pc-items251 ([^SaveState state]252 (print-listing253 state254 pc-item-list-start255 (+ pc-item-list-width pc-item-list-start))256 state)257 ([] (print-listing-pc-items @current-state)))