# HG changeset patch # User Dylan Holmes # Date 1332923316 18000 # Node ID 0c3fbb313e49b0b2c292a9eb610735f3d82f633b # Parent ca1afcef3542abfe649b4cdd12b88b137c9ef153 added price data. also, shop data seems a bit off. diff -r ca1afcef3542 -r 0c3fbb313e49 clojure/com/aurellem/gb/hxc.clj --- a/clojure/com/aurellem/gb/hxc.clj Tue Mar 27 22:41:24 2012 -0500 +++ b/clojure/com/aurellem/gb/hxc.clj Wed Mar 28 03:28:36 2012 -0500 @@ -24,6 +24,21 @@ (apply str (map #(if (= % \space) "-" %) s))))) + +;; used to decode item prices + +(defn decode-bcd + "Take a sequence of binary-coded digits (in written order) and return the number they represent." + [digits] + ((fn self [coll] + (if (empty? coll) 0 + (+ (first coll) (* 100 (self (rest coll)))))) + (map + #(+ (* 10 (int (/ % 16))) + (rem % 16)) + (reverse digits)))) + + (def pkmn-types @@ -653,6 +668,23 @@ (take (* entry-size pkmn-count) (drop 0x383DE rom))))))) + + + +(defn hxc-item-prices + "The hardcoded list of item prices in memory. List begins at ROM@4495" + ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom)) + ([rom] + (let [items (map format-name (hxc-items rom)) + price-size 3] + (zipmap items + (map (comp + ;; zero-cost items are "priceless" + #(if (zero? %) :priceless %) + decode-bcd butlast) + (partition price-size + (take (* price-size (count items)) + (drop 0x4495 rom)))))))) (defn hxc-shops ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom)) @@ -668,11 +700,13 @@ (partial + 1 -200) )) (take 200 (drop 200 (range))))) - + ] ((fn parse-shop [coll [num-items & items-etc]] - (let [inventory (take (dec num-items) (rest items-etc)) + (let [inventory (take-while + (partial not= 0xFF) + items-etc) [separator & items-etc] (drop num-items (rest items-etc))] (if (= separator 0x50) (map (partial mapv (comp items dec)) (conj coll inventory)) @@ -681,7 +715,7 @@ )) '() - (take 1000 (drop 0x233C rom))) + (drop 0x233C rom)) )))