annotate clojure/com/aurellem/gb/status.clj @ 340:dea7e476eba7

preliminary item-writer complete
author Robert McIntyre <rlm@mit.edu>
date Sun, 08 Apr 2012 04:10:49 -0500
parents fd549c8f42ae
children
rev   line source
rlm@176 1 (ns com.aurellem.gb.status
rlm@192 2 (:use (com.aurellem.gb gb-driver util constants))
rlm@176 3 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@176 4
rlm@176 5 (def status-name->status-code
rlm@176 6 {:normal (Integer/parseInt "00000000" 2)
rlm@176 7 :sleep-1 (Integer/parseInt "00000001" 2)
rlm@176 8 :sleep-2 (Integer/parseInt "00000010" 2)
rlm@176 9 :sleep-3 (Integer/parseInt "00000011" 2)
rlm@176 10 :sleep-4 (Integer/parseInt "00000100" 2)
rlm@176 11 :sleep-5 (Integer/parseInt "00000101" 2)
rlm@176 12 :sleep-6 (Integer/parseInt "00000111" 2)
rlm@176 13 :poisoned (Integer/parseInt "00001000" 2)
rlm@176 14 :burned (Integer/parseInt "00010000" 2)
rlm@176 15 :frozen (Integer/parseInt "00100000" 2)
rlm@176 16 :paralyzed (Integer/parseInt "01000000" 2)})
rlm@176 17
rlm@176 18 (def status-code->status-name
rlm@176 19 (zipmap (vals status-name->status-code)
rlm@176 20 (keys status-name->status-code)))
rlm@176 21
rlm@176 22 (def pokemon-1-status-address 0xD16E)
rlm@176 23
rlm@176 24 (defn pokemon-status-address [poke-num]
rlm@176 25 (+ pokemon-1-status-address
rlm@176 26 (* poke-num pokemon-record-width)))
rlm@176 27
rlm@191 28 (defn read-status
rlm@191 29 ([^SaveState state poke-num]
rlm@191 30 (assert (<= 0 poke-num 5))
rlm@191 31 (status-code->status-name
rlm@191 32 (aget (memory state)
rlm@191 33 (pokemon-status-address poke-num))))
rlm@191 34 ([poke-num]
rlm@191 35 (read-status @current-state poke-num)))
rlm@191 36
rlm@191 37 (defn give-status
rlm@176 38 ([^SaveState state poke-num status]
rlm@176 39 (assert (<= 0 poke-num 5))
rlm@176 40 (let [status-code
rlm@176 41 (status-name->status-code status)]
rlm@176 42 (assert status-code)
rlm@176 43 (set-memory state
rlm@176 44 (pokemon-status-address poke-num)
rlm@176 45 status-code)))
rlm@176 46 ([poke-num status]
rlm@192 47 (give-status @current-state poke-num status))
rlm@176 48 ([status]
rlm@192 49 (give-status @current-state 0 status)))
rlm@176 50