Mercurial > vba-clojure
view clojure/com/aurellem/items.clj @ 102:4d9ce3188655
made first 'hello-world' item based assembly insertion.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 12 Mar 2012 20:03:05 -0500 |
parents | 2090bcb78f44 |
children | 3305490a8f62 |
line wrap: on
line source
1 (ns com.aurellem.items2 (:use (com.aurellem gb-driver vbm title))3 ;; this is bullshit4 (:import [com.aurellem.gb_driver SaveState]))6 (defn game-name []7 (map char (subvec (vec (memory)) 0x134 0x142)))9 (def item-list-start 0xD31C)11 (defn item-list [^SaveState state]12 (subvec13 (vec (memory state))14 item-list-start15 (+ item-list-start 150)))17 (def item-hack-3 (read-state 77557))19 (def item-code->item-name20 (hash-map21 1 :master-ball22 2 :ultra-ball23 3 :great-ball24 4 :poke-ball25 5 :town-map26 6 :bicycle27 8 :safari-ball28 9 :pokedex29 10 :moon-stone30 11 :antidote31 12 :burn-heal32 13 :ice-heal33 14 :awakening34 15 :parlyz-heal35 16 :full-restore36 17 :max-potion37 18 :hyper-potion38 19 :super-potion39 20 :potion40 21 :boulderbadge41 22 :cascadebadge42 23 :thunderbadge43 24 :rainbowbadge44 25 :soulbadge45 26 :marshbadge46 27 :volcanobadge47 28 :earthbadge48 29 :escape-rope49 30 :repel50 31 :old-amber51 32 :fire-stone52 33 :thunderstone53 34 :water-stone54 35 :hp-up55 36 :protein56 37 :iron57 38 :carbos58 39 :calcium59 40 :rare-candy60 41 :dome-fossil61 42 :helix-fossil62 43 :secret-key63 45 :bike-voucher64 46 :x-accuracy65 47 :leaf-stone66 48 :card-key67 49 :nugget68 50 :pp-up69 51 :poke-doll70 52 :full-heal71 53 :revive72 54 :max-revive73 55 :guard-spec74 56 :super-repel75 57 :max-repel76 58 :dire-hit77 59 :coin78 60 :fresh-water79 61 :soda-pop80 62 :lemonade81 63 :s.s.ticket82 64 :gold-teeth83 65 :x-attach84 66 :x-defend85 67 :x-speed86 68 :x-special87 69 :coin-case88 70 :oaks-parcel89 71 :itemfinder90 72 :silph-scope91 73 :poke-flute92 74 :lift-key93 75 :exp.all94 76 :old-rod95 77 :good-rod96 78 :super-rod97 79 :pp-up98 80 :ether99 81 :max-ether100 82 :elixer101 83 :max-elixer102 196 :HM01 ;; cut103 197 :HM02 ;; fly104 198 :HM03 ;; surf105 199 :HM04 ;; strength106 200 :HM05 ;; flash107 201 :TM01 ;; mega punch108 202 :TM02 ;; razor wind109 203 :TM03 ;; swords dance110 204 :TM04 ;; whirlwind111 205 :TM05 ;; mega kick112 206 :TM06 ;; toxic113 207 :TM07 ;; horn drill114 208 :TM08 ;; body slam115 209 :TM09 ;; take down116 210 :TM10 ;; double-edge117 211 :TM11 ;; bubblebeam118 212 :TM12 ;; water gun119 213 :TM13 ;; ice beam120 214 :TM14 ;; blizzard121 215 :TM15 ;; hyper beam122 216 :TM16 ;; pay day123 217 :TM17 ;; submission124 218 :TM18 ;; counter125 219 :TM19 ;; seismic toss126 220 :TM20 ;; rage127 221 :TM21 ;; mega drain128 222 :TM22 ;; solarbeam129 223 :TM23 ;; dragon rage130 224 :TM24 ;; thunderbolt131 225 :TM25 ;; thunder132 226 :TM26 ;; earthquake133 227 :TM27 ;; fissure134 228 :TM28 ;; dig135 229 :TM29 ;; psychic136 230 :TM30 ;; teleport137 231 :TM31 ;; mimic138 232 :TM32 ;; double team139 233 :TM33 ;; reflect140 234 :TM34 ;; bide141 235 :TM35 ;; metronome142 236 :TM36 ;; self destruct143 237 :TM37 ;; eggbomb144 238 :TM38 ;; fire blast145 239 :TM39 ;; swift146 240 :TM40 ;; skull bash147 241 :TM41 ;; softboiled148 242 :TM42 ;; dream eater149 243 :TM43 ;; sky attack150 244 :TM44 ;; rest151 245 :TM45 ;; thunder wave152 246 :TM46 ;; psywave153 247 :TM47 ;; explosion154 248 :TM48 ;; rock slide155 249 :TM49 ;; tri attack156 250 :TM50 ;; substitute157 251 :TM51 ;; "cut"158 252 :TM52 ;; "fly"159 253 :TM53 ;; "surf"160 254 :TM54 ;; "strength"161 255 :end-of-list-sentinel))163 (def item-name->item-code164 (zipmap (vals item-code->item-name)165 (keys item-code->item-name)))167 (defn inventory [^SaveState state]168 (let [items (item-list state)]169 (map170 (fn [[item-code quantity]]171 [(item-code->item-name item-code)172 quantity])173 (partition174 2175 (next (take-while (partial not= 255) items))))))177 (defn print-inventory178 ([] (print-inventory @current-state))179 ([^SaveState state]180 (println181 (let [inv (inventory state)]182 (reduce183 str184 (concat185 ["+-------------------+----------+\n"186 "|##| Item | Quantity |\n"187 "+--+----------------+----------+\n"]189 (map190 (fn [index [item-name quantity]]191 (str192 (format "|%-2d| %-14s | %3d |\n" index193 (apply str (rest (str item-name)))194 quantity)))195 (range 0 (count inv)) inv)196 ["+--+----------------+----------+\n"]))))))198 (defn inventory-codes [inventory]199 (flatten200 (concat [(count inventory)]201 (map (fn [[item-name quantity]]202 [(item-name->item-code item-name)203 quantity]) inventory)204 [(item-name->item-code :end-of-list-sentinel)])))206 (defn set-inventory [^SaveState state new-inventory]207 (set-state! state)208 (let [mem (memory state)209 inv (inventory-codes new-inventory)]211 (dorun (map (fn [index val]212 (aset mem index val))213 (range item-list-start214 (+ item-list-start (count inv))) inv))215 (write-memory! mem)216 (update-state)))218 (def gliched-tms219 [[:TM51 1]220 [:TM52 1]221 [:TM53 1]222 [:TM54 1]])224 (def good-items225 [[:bicycle 1]226 [:ultra-ball 15]227 [:pp-up 1]228 [:master-ball 5]229 [:rare-candy 99]230 [:full-restore 25]231 [:max-revive 8]232 [:max-repel 40]233 [:TM25 1]234 [:TM11 1]235 [:TM15 1]236 ])238 (def some-badges239 [[:cascadebadge 1]240 [:thunderbadge 1]241 [:rainbowbadge 1]242 [:soulbadge 1]243 ])245 (defn run-item-program246 "This is my first assembly/item program!247 it just increments BC by one.249 The code places a single 'great ball' at the beginning of the250 inventory, then directly sets the program counter to start251 executing at the position of the 'great ball' in memory.253 Since a 'great ball' is represented in memory as 0x03, which254 corresponts to the opcode which increments BC by one, that is255 what happens.257 Obviously, the game crashes more or less immediately after the258 program counter advances past the 'great ball' into the next items259 in the inventory."260 []261 (set-inventory (read-state 578544) [[:great-ball 1]])262 (print-inventory)263 (println "3 ticks") (tick) (tick) (tick)264 (println "PC before:" (PC))265 (println "BC before:" (BC))266 (PC! (inc item-list-start))267 (println "PC after setting:" (PC))268 (println "data at PC:" (aget (memory) (PC)))269 (println "one tick")270 (tick)271 (println "PC after one tick:" (PC))272 (println "BC after one tick:" (BC)))