comparison 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
comparison
equal deleted inserted replaced
101:37711ff4a7bc 102:4d9ce3188655
97 79 :pp-up 97 79 :pp-up
98 80 :ether 98 80 :ether
99 81 :max-ether 99 81 :max-ether
100 82 :elixer 100 82 :elixer
101 83 :max-elixer 101 83 :max-elixer
102 196 :HM01 102 196 :HM01 ;; cut
103 197 :HM02 103 197 :HM02 ;; fly
104 198 :HM03 104 198 :HM03 ;; surf
105 199 :HM04 105 199 :HM04 ;; strength
106 200 :HM05 106 200 :HM05 ;; flash
107 201 :TM01 107 201 :TM01 ;; mega punch
108 202 :TM02 108 202 :TM02 ;; razor wind
109 203 :TM03 109 203 :TM03 ;; swords dance
110 204 :TM04 110 204 :TM04 ;; whirlwind
111 205 :TM05 111 205 :TM05 ;; mega kick
112 206 :TM06 112 206 :TM06 ;; toxic
113 207 :TM07 113 207 :TM07 ;; horn drill
114 208 :TM08 114 208 :TM08 ;; body slam
115 209 :TM09 115 209 :TM09 ;; take down
116 210 :TM10 116 210 :TM10 ;; double-edge
117 211 :TM11 117 211 :TM11 ;; bubblebeam
118 212 :TM12 118 212 :TM12 ;; water gun
119 213 :TM13 119 213 :TM13 ;; ice beam
120 214 :TM13 120 214 :TM14 ;; blizzard
121 215 :TM15 121 215 :TM15 ;; hyper beam
122 216 :TM16 122 216 :TM16 ;; pay day
123 217 :TM17 123 217 :TM17 ;; submission
124 218 :TM18 124 218 :TM18 ;; counter
125 219 :TM19 125 219 :TM19 ;; seismic toss
126 220 :TM20 126 220 :TM20 ;; rage
127 221 :TM21 127 221 :TM21 ;; mega drain
128 222 :TM22 128 222 :TM22 ;; solarbeam
129 223 :TM23 129 223 :TM23 ;; dragon rage
130 224 :TM24 130 224 :TM24 ;; thunderbolt
131 225 :TM25 131 225 :TM25 ;; thunder
132 226 :TM26 132 226 :TM26 ;; earthquake
133 227 :TM27 133 227 :TM27 ;; fissure
134 228 :TM28 134 228 :TM28 ;; dig
135 229 :TM29 135 229 :TM29 ;; psychic
136 230 :TM30 136 230 :TM30 ;; teleport
137 231 :TM31 137 231 :TM31 ;; mimic
138 232 :TM32 138 232 :TM32 ;; double team
139 233 :TM33 139 233 :TM33 ;; reflect
140 234 :TM34 140 234 :TM34 ;; bide
141 235 :TM35 141 235 :TM35 ;; metronome
142 236 :TM36 142 236 :TM36 ;; self destruct
143 237 :TM37 143 237 :TM37 ;; eggbomb
144 238 :TM38 144 238 :TM38 ;; fire blast
145 239 :TM39 145 239 :TM39 ;; swift
146 240 :TM40 146 240 :TM40 ;; skull bash
147 241 :TM41 147 241 :TM41 ;; softboiled
148 242 :TM42 148 242 :TM42 ;; dream eater
149 243 :TM43 149 243 :TM43 ;; sky attack
150 244 :TM44 150 244 :TM44 ;; rest
151 245 :TM45 151 245 :TM45 ;; thunder wave
152 246 :TM46 152 246 :TM46 ;; psywave
153 247 :TM47 153 247 :TM47 ;; explosion
154 248 :TM48 154 248 :TM48 ;; rock slide
155 249 :TM49 155 249 :TM49 ;; tri attack
156 250 :TM50 156 250 :TM50 ;; substitute
157 251 :TM51 157 251 :TM51 ;; "cut"
158 252 :TM52 158 252 :TM52 ;; "fly"
159 253 :TM53 159 253 :TM53 ;; "surf"
160 254 :TM54 160 254 :TM54 ;; "strength"
161 255 :end-of-list-sentinel)) 161 255 :end-of-list-sentinel))
162 162
163 (def item-name->item-code 163 (def item-name->item-code
164 (zipmap (vals item-code->item-name) 164 (zipmap (vals item-code->item-name)
165 (keys item-code->item-name))) 165 (keys item-code->item-name)))
172 quantity]) 172 quantity])
173 (partition 173 (partition
174 2 174 2
175 (next (take-while (partial not= 255) items)))))) 175 (next (take-while (partial not= 255) items))))))
176 176
177 (defn print-inventory [^SaveState state] 177 (defn print-inventory
178 (println 178 ([] (print-inventory @current-state))
179 (let [inv (inventory state)] 179 ([^SaveState state]
180 (reduce 180 (println
181 str 181 (let [inv (inventory state)]
182 (concat 182 (reduce
183 ["+-------------------+----------+\n" 183 str
184 "|##| Item | Quantity |\n" 184 (concat
185 "+--+----------------+----------+\n"] 185 ["+-------------------+----------+\n"
186 186 "|##| Item | Quantity |\n"
187 (map 187 "+--+----------------+----------+\n"]
188 (fn [index [item-name quantity]] 188
189 (str 189 (map
190 (format "|%-2d| %-14s | %3d |\n" index 190 (fn [index [item-name quantity]]
191 (apply str (rest (str item-name))) 191 (str
192 quantity))) 192 (format "|%-2d| %-14s | %3d |\n" index
193 (range 0 (count inv)) inv) 193 (apply str (rest (str item-name)))
194 ["+--+----------------+----------+\n"]))))) 194 quantity)))
195 (range 0 (count inv)) inv)
196 ["+--+----------------+----------+\n"]))))))
195 197
196 (defn inventory-codes [inventory] 198 (defn inventory-codes [inventory]
197 (flatten 199 (flatten
198 (concat [(count inventory)] 200 (concat [(count inventory)]
199 (map (fn [[item-name quantity]] 201 (map (fn [[item-name quantity]]
210 (aset mem index val)) 212 (aset mem index val))
211 (range item-list-start 213 (range item-list-start
212 (+ item-list-start (count inv))) inv)) 214 (+ item-list-start (count inv))) inv))
213 (write-memory! mem) 215 (write-memory! mem)
214 (update-state))) 216 (update-state)))
215 217
218 (def gliched-tms
219 [[:TM51 1]
220 [:TM52 1]
221 [:TM53 1]
222 [:TM54 1]])
223
224 (def good-items
225 [[: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 ])
237
238 (def some-badges
239 [[:cascadebadge 1]
240 [:thunderbadge 1]
241 [:rainbowbadge 1]
242 [:soulbadge 1]
243 ])
244
245 (defn run-item-program
246 "This is my first assembly/item program!
247 it just increments BC by one.
248
249 The code places a single 'great ball' at the beginning of the
250 inventory, then directly sets the program counter to start
251 executing at the position of the 'great ball' in memory.
252
253 Since a 'great ball' is represented in memory as 0x03, which
254 corresponts to the opcode which increments BC by one, that is
255 what happens.
256
257 Obviously, the game crashes more or less immediately after the
258 program counter advances past the 'great ball' into the next items
259 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)))
273