diff clojure/com/aurellem/gb/hxc.clj @ 282:0c3fbb313e49

added price data. also, shop data seems a bit off.
author Dylan Holmes <ocsenave@gmail.com>
date Wed, 28 Mar 2012 03:28:36 -0500
parents ca1afcef3542
children 516acb83410f
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/hxc.clj	Tue Mar 27 22:41:24 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/hxc.clj	Wed Mar 28 03:28:36 2012 -0500
     1.3 @@ -24,6 +24,21 @@
     1.4              (apply str
     1.5                     (map #(if (= % \space) "-" %) s)))))
     1.6  
     1.7 +
     1.8 +;; used to decode item prices
     1.9 +
    1.10 +(defn decode-bcd
    1.11 +  "Take a sequence of binary-coded digits (in written order) and return the number they represent."
    1.12 +  [digits]
    1.13 +  ((fn self [coll]
    1.14 +     (if (empty? coll) 0
    1.15 +         (+ (first coll) (* 100 (self (rest coll))))))
    1.16 +   (map
    1.17 +    #(+ (* 10 (int (/ % 16)))
    1.18 +        (rem % 16))
    1.19 +    (reverse digits))))
    1.20 +
    1.21 +
    1.22    
    1.23  
    1.24  (def pkmn-types
    1.25 @@ -653,6 +668,23 @@
    1.26                          (take (* entry-size pkmn-count)
    1.27                                (drop 0x383DE
    1.28                                      rom)))))))
    1.29 +                       
    1.30 +
    1.31 +
    1.32 +(defn hxc-item-prices
    1.33 +  "The hardcoded list of item prices in memory. List begins at ROM@4495"
    1.34 +  ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
    1.35 +  ([rom]
    1.36 +     (let [items (map format-name (hxc-items rom))
    1.37 +           price-size 3]
    1.38 +       (zipmap items
    1.39 +               (map (comp
    1.40 +                     ;; zero-cost items are "priceless"
    1.41 +                     #(if (zero? %) :priceless %)
    1.42 +                     decode-bcd butlast)
    1.43 +                    (partition price-size
    1.44 +                               (take (* price-size (count items))
    1.45 +                                     (drop 0x4495 rom))))))))
    1.46  
    1.47  (defn hxc-shops
    1.48    ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
    1.49 @@ -668,11 +700,13 @@
    1.50                                     (partial + 1 -200)
    1.51                                     )) 
    1.52                         (take 200 (drop 200 (range)))))
    1.53 -                        
    1.54 +                       
    1.55             ]
    1.56  
    1.57         ((fn parse-shop [coll [num-items & items-etc]]
    1.58 -         (let [inventory (take (dec num-items) (rest items-etc))
    1.59 +          (let [inventory (take-while
    1.60 +                           (partial not= 0xFF)
    1.61 +                           items-etc)
    1.62                 [separator & items-etc] (drop num-items (rest items-etc))]
    1.63             (if (= separator 0x50)
    1.64               (map (partial mapv (comp items dec)) (conj coll inventory))
    1.65 @@ -681,7 +715,7 @@
    1.66           ))
    1.67  
    1.68          '()
    1.69 -        (take 1000 (drop 0x233C rom)))
    1.70 +        (drop 0x233C rom))
    1.71  
    1.72       
    1.73       )))