# HG changeset patch # User Dylan Holmes # Date 1333045891 18000 # Node ID eec3e69500d9200449b297cfac046a7a5cb368c8 # Parent 7918c0dcc0bd24bf4bd917557f6d26ee3ffa2e36 Made hxc-pokenames and hxc-items return keywords instead of strings by default; added hxc-pokenames-raw and hxc-items-raw for the string version. diff -r 7918c0dcc0bd -r eec3e69500d9 clojure/com/aurellem/gb/hxc.clj --- a/clojure/com/aurellem/gb/hxc.clj Wed Mar 28 06:06:13 2012 -0500 +++ b/clojure/com/aurellem/gb/hxc.clj Thu Mar 29 13:31:31 2012 -0500 @@ -1,7 +1,7 @@ (ns com.aurellem.gb.hxc (:use (com.aurellem.gb assembly characters gb-driver util constants species)) - (:use (com.aurellem.world practice)) + ;; (:use (com.aurellem.world practice)) (:import [com.aurellem.gb.gb_driver SaveState])) @@ -11,37 +11,6 @@ -(defn low-high - [low high] - (+ low (* 256 high))) - - -(defn format-name - "Convert the string of alphabetic/space characters into a keyword by - replacing spaces with hyphens and converting to lowercase." - [s] - (if (nil? s) nil - (keyword (.toLowerCase - (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 [:normal ;;0 :fighting ;;1 @@ -197,7 +166,50 @@ ;; -------------------------------------------------- -(def hxc-items + + +(defn hxc-pokenames-raw + "The hardcoded names of the 190 species in memory. List begins at +ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters + long, these names are stripped of padding. See also, hxc-pokedex-names" + ([] + (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom)) + ([rom] + (let [count-species 190 + name-length 10] + (map character-codes->str + (partition name-length + (map #(if (= 0x50 %) 0x00 %) + (take (* count-species name-length) + (drop 0xE8000 + rom)))))))) +(def hxc-pokenames + (comp + (partial map format-name) + hxc-pokenames-raw)) + + + + +(defn hxc-pokedex-names + "The names of the pokemon in hardcoded pokedex order. List begins at +ROM@410B1. See also, hxc-pokenames." + ([] (hxc-pokedex-names + com.aurellem.gb.gb-driver/original-rom)) + ([rom] + (let [names (hxc-pokenames rom)] + (#(mapv % + ((comp range count keys) %)) + (zipmap + (take (count names) + (drop 0x410b1 rom)) + + names))))) + + + + +(def hxc-items-raw "The hardcoded names of the items in memory. List begins at ROM@045B7" (hxc-thunk-words 0x45B7 870)) @@ -213,11 +225,18 @@ (hxc-thunk-words 0x27E77 196)) -(def hxc-pokedex-text* +(def hxc-pokedex-text-raw "The hardcoded pokedex entries in memory. List begins at ROM@B8000, shortly before move names." (hxc-thunk-words 0xB8000 14754)) + + +(def hxc-items + "The hardcoded names of the items in memory, presented as + keywords. List begins at ROM@045B7. See also, hxc-items-raw." + (comp (partial map format-name) hxc-items-raw)) + (defn hxc-pokedex-text "The hardcoded pokedex entries in memory, presented as an associative hash map. List begins at ROM@B8000." @@ -226,7 +245,7 @@ (zipmap (hxc-pokedex-names rom) (cons nil ;; for missingno. - (hxc-pokedex-text* rom))))) + (hxc-pokedex-text-raw rom))))) ;; In red/blue, pokedex stats are in internal order. ;; In yellow, pokedex stats are in pokedex order. @@ -234,13 +253,10 @@ (defn hxc-pokedex-stats "The hardcoded pokedex stats (species height weight) in memory. List begins at ROM@40687" - ;; uses hxc-pokedex-text to count pokemon - ;; since hxc-pokenames includes several missingno" ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom)) ([rom] - (let [poketext (hxc-pokedex-text rom) - pkmn-count (count poketext) - pokedex-names (zipmap (range) (hxc-pokedex-names rom)) + (let [pokedex-names (zipmap (range) (hxc-pokedex-names rom)) + pkmn-count (count pokedex-names) ] ((fn capture-stats [n stats data] @@ -399,46 +415,13 @@ dec) (take 100 (drop 0x1232D rom)))))))) - -(defn hxc-pokenames - "The hardcoded names of the 190 species in memory. List begins at -ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters - long, these names are stripped of padding. See also, hxc-pokedex-names" - ([] - (hxc-pokenames com.aurellem.gb.gb-driver/original-rom)) - ([rom] - (let [count-species 190 - name-length 10] - (map character-codes->str - (partition name-length - (map #(if (= 0x50 %) 0x00 %) - (take (* count-species name-length) - (drop 0xE8000 - rom)))))))) - - - -(defn hxc-pokedex-names - "The names of the pokemon in hardcoded pokedex order. List begins at -ROM@410B1. See also, hxc-pokenames." - ([] (hxc-pokedex-names - com.aurellem.gb.gb-driver/original-rom)) - ([rom] - (let [names (hxc-pokenames rom)] - (#(mapv % - ((comp range count keys) %)) - (zipmap - (take (count names) - (drop 0x410b1 rom)) - - (map format-name names)))))) (defn internal-id ([rom] (zipmap - (map format-name (hxc-pokenames rom)) + (hxc-pokenames rom) (range))) ([] (internal-id com.aurellem.gb.gb-driver/original-rom))) @@ -511,8 +494,8 @@ ([] (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom)) ([rom] - (let [names (hxc-pokenames rom) - pkmn-count (count names) + (let [ + pkmn-count (count (hxc-pokenames-raw)) ;; 190 ptrs (map (fn [[a b]] (low-high a b)) (partition 2 @@ -533,7 +516,7 @@ (apply assoc {} (interleave - (map format-name (hxc-pokenames rom)) + (hxc-pokenames rom) (map (comp (partial map (fn [[lvl mv]] [lvl (dec mv)])) @@ -568,7 +551,7 @@ ([rom] (apply assoc {} (interleave - (map format-name (hxc-pokenames rom)) + (hxc-pokenames rom) (map (comp format-evo @@ -583,8 +566,8 @@ ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom)) ([rom] (let - [poke-names (vec (map format-name (hxc-pokenames rom))) - item-names (vec (map format-name (hxc-items rom))) + [poke-names (vec (hxc-pokenames rom)) + item-names (vec (hxc-items rom)) use-names (fn [m] (loop [ks (keys m) new-map m] @@ -615,9 +598,6 @@ (map (fn [[pkmn evo-coll]] [pkmn (map use-names evo-coll)]) (hxc-evolution rom)))))) - - - (defn hxc-pokemon-base @@ -635,6 +615,7 @@ (range) (map format-name (hxc-move-names rom)))) + machines (hxc-machines) ] (zipmap pokemon @@ -722,7 +703,7 @@ "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)) + (let [items (hxc-items rom) price-size 3] (zipmap items (map (comp @@ -736,7 +717,7 @@ (defn hxc-shops ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom)) ([rom] - (let [items (zipmap (range) (map format-name (hxc-items rom))) + (let [items (zipmap (range) (hxc-items rom)) ;; temporarily softcode the TM items items (into @@ -774,7 +755,7 @@ (defn same-type ([pkmn move] - (same-type? + (same-type com.aurellem.gb.gb-driver/original-rom pkmn move)) ([rom pkmn move] (((comp :types (hxc-pokemon-base rom)) pkmn) diff -r 7918c0dcc0bd -r eec3e69500d9 clojure/com/aurellem/gb/util.clj --- a/clojure/com/aurellem/gb/util.clj Wed Mar 28 06:06:13 2012 -0500 +++ b/clojure/com/aurellem/gb/util.clj Thu Mar 29 13:31:31 2012 -0500 @@ -29,6 +29,47 @@ (Integer/parseInt (Integer/toBinaryString num) 10))) +(defn bit-list + "List the bits of n in order of decreasing significance." + [n] + ((fn this [coll n] + (if (zero? n) coll + (recur + (conj coll (rem n 2)) + (int (/ n 2))))) + [] n)) + + +(defn low-high + [low high] + (+ low (* 256 high))) + + +(defn format-name + "Convert the string of alphabetic/space characters into a keyword by + replacing spaces with hyphens and converting to lowercase." + [s] + (if (nil? s) nil + (keyword (.toLowerCase + (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)))) + + + (defn view-register [state name reg-fn] (println (format "%s: %s" name