diff clojure/com/aurellem/gb/rival_name.clj @ 225:0587f266a735

added functions for setting rival's name and text speed
author Robert McIntyre <rlm@mit.edu>
date Sat, 24 Mar 2012 05:26:33 -0500
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/clojure/com/aurellem/gb/rival_name.clj	Sat Mar 24 05:26:33 2012 -0500
     1.3 @@ -0,0 +1,27 @@
     1.4 +(ns com.aurellem.gb.rival-name
     1.5 +  (:use (com.aurellem.gb gb-driver util characters))
     1.6 +  (:import [com.aurellem.gb.gb_driver SaveState]))
     1.7 +
     1.8 +
     1.9 +(def rival-name-start-address 0xD349)
    1.10 +
    1.11 +(def rival-name-width 12)
    1.12 +
    1.13 +(defn read-rival-name
    1.14 +  ([^SaveState state]
    1.15 +     (read-name (subvec (vec (memory state))
    1.16 +                        rival-name-start-address
    1.17 +                        (+ rival-name-start-address
    1.18 +                           rival-name-width))))
    1.19 +  ([] (read-rival-name @current-state)))
    1.20 +
    1.21 +(defn set-rival-name
    1.22 +  ([^SaveState state new-name]
    1.23 +     (assert (<= (count new-name) 10))
    1.24 +     (let [codes (str->character-codes new-name)]
    1.25 +       (set-memory-range state
    1.26 +                         rival-name-start-address
    1.27 +                         (concat codes [end-of-name-sentinel]))))
    1.28 +  ([new-name] (set-rival-name @current-state new-name)))
    1.29 +     
    1.30 +