changeset 81:db8e0a563c8e

generated intro
author Robert McIntyre <rlm@mit.edu>
date Fri, 09 Mar 2012 01:43:25 -0600
parents ad6ebe886a21
children 04d539d26bdc
files clojure/com/aurellem/fragments.clj clojure/com/aurellem/gb_driver.clj clojure/com/aurellem/speedrun_2942.clj clojure/com/aurellem/title.clj java/src/com/aurellem/gb/Gb.java src/VisualBoyAdvance.cfg
diffstat 6 files changed, 154 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/fragments.clj	Thu Mar 08 22:29:11 2012 -0600
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,59 +0,0 @@
     1.4 -(ns com.aurellem.fragments
     1.5 -  (:use (com.aurellem gb-driver vbm)))
     1.6 -
     1.7 -
     1.8 -
     1.9 -
    1.10 -
    1.11 -  
    1.12 -
    1.13 -(def start-frames 401)
    1.14 -
    1.15 -
    1.16 -(defn play-start [start n]
    1.17 -  (let [moves
    1.18 -        (concat (repeat n [])
    1.19 -                [[:a]]
    1.20 -                (repeat (- start-frames n 1) []))
    1.21 -        moves (drop start moves)]
    1.22 -    (goto start)
    1.23 -    (dorun (map step! moves))
    1.24 -    (nth (registers) 2)))
    1.25 -
    1.26 -(defn earliest-press
    1.27 -  [start]
    1.28 -  (print "determining bad program-counter...")
    1.29 -  (reset)
    1.30 -  (dorun (dotimes [_ start-frames] (step)))
    1.31 -  (let [bad-counter (play-start 0 0)]
    1.32 -    (println bad-counter)
    1.33 -    (loop [n start]
    1.34 -      (print "trying" n "...")
    1.35 -      (let [nth-counter (play-start (dec n) n)]
    1.36 -        (println "got" nth-counter)
    1.37 -        (if (= nth-counter bad-counter)
    1.38 -          (recur (inc n)) n)))))
    1.39 -
    1.40 -
    1.41 -
    1.42 -(def start->menu
    1.43 -  [
    1.44 -
    1.45 -
    1.46 -
    1.47 -
    1.48 -
    1.49 -
    1.50 -
    1.51 -
    1.52 -   ])
    1.53 -
    1.54 -
    1.55 -
    1.56 -(defn full-script [] (concat start->menu))
    1.57 -
    1.58 -
    1.59 -(defn test-script []
    1.60 -  (reset)
    1.61 -  (dorun (map step (full-script))))
    1.62 -  
     2.1 --- a/clojure/com/aurellem/gb_driver.clj	Thu Mar 08 22:29:11 2012 -0600
     2.2 +++ b/clojure/com/aurellem/gb_driver.clj	Fri Mar 09 01:43:25 2012 -0600
     2.3 @@ -6,7 +6,7 @@
     2.4  
     2.5  (Gb/loadVBA)
     2.6  
     2.7 -(def ^:dynamic *max-history* 1e4)
     2.8 +(def ^:dynamic *max-history* 2e4)
     2.9  
    2.10  (def ^:dynamic *backup-saves-to-disk* true)
    2.11  
    2.12 @@ -136,10 +136,11 @@
    2.13    ([] (rewind 1))
    2.14    ([n] (goto (- @current-frame n))))
    2.15  
    2.16 -(defn backup-state [frame]
    2.17 +(defn backup-state
    2.18 +  [frame]
    2.19    (let [save (save-state)]
    2.20      (swap! history #(assoc % frame save))
    2.21 -    (store-save-to-disk save)
    2.22 +    ;;(store-save-to-disk save)
    2.23      (if (> (count @history) *max-history*)
    2.24        (swap! history #(dissoc % (first (first %)))))))
    2.25  
    2.26 @@ -156,6 +157,13 @@
    2.27         (Gb/step mask-or-buttons)
    2.28         (Gb/step (button-mask mask-or-buttons)))))
    2.29  
    2.30 +(defn play-moves
    2.31 +  ([start moves]
    2.32 +     (goto start)
    2.33 +     (dorun (map step moves)))
    2.34 +  ([moves]
    2.35 +     (dorun (map step moves))))
    2.36 +
    2.37  (defn play
    2.38    ([] (play Integer/MAX_VALUE))
    2.39    ([n] (dorun (dotimes [_ n] (step)))))
     3.1 --- a/clojure/com/aurellem/speedrun_2942.clj	Thu Mar 08 22:29:11 2012 -0600
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,1 +0,0 @@
     3.4 -(ns com.aurellem.speedrun-2942)
     3.5 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/clojure/com/aurellem/title.clj	Fri Mar 09 01:43:25 2012 -0600
     4.3 @@ -0,0 +1,140 @@
     4.4 +(ns com.aurellem.title
     4.5 +  (:use (com.aurellem gb-driver vbm)))
     4.6 +
     4.7 +(defn delayed-key
     4.8 +  ([key delay total]
     4.9 +     (concat (repeat delay []) [key] (repeat (- total delay 1) [])))
    4.10 +  ([key total]
    4.11 +     (delayed-key key (dec total) total)))
    4.12 +
    4.13 +(defn no-action [length]
    4.14 +  (repeat length []))
    4.15 +
    4.16 +(defn start-summary []
    4.17 +  (nth (registers) 2))
    4.18 +
    4.19 +(defn common-initial-elements [baseline moves]
    4.20 +  (loop [common 0 b baseline m moves]
    4.21 +    (if (empty? m) common
    4.22 +        (if (= (first b) (first m))
    4.23 +          (recur (inc common) (rest b) (rest m))
    4.24 +          common))))
    4.25 +    
    4.26 +(defn earliest-press
    4.27 +  [start-frame
    4.28 +   end-frame
    4.29 +   key
    4.30 +   summary-fn]
    4.31 +  (let [action-length (- end-frame start-frame)
    4.32 +        baseline (no-action action-length)]
    4.33 +    (print "establishing baseline...")
    4.34 +    (play-moves start-frame baseline)
    4.35 +    (let [bad-value (summary-fn)]
    4.36 +      (println bad-value)
    4.37 +      (loop [n 0]
    4.38 +        (let [moves (delayed-key key n action-length)
    4.39 +              header-length
    4.40 +              (common-initial-elements moves baseline)]
    4.41 +          (print "length" (inc n) "...")
    4.42 +          (without-saves
    4.43 +           (play-moves
    4.44 +            (+ start-frame header-length)
    4.45 +            (drop header-length moves)))
    4.46 +          (let [result (summary-fn)]
    4.47 +            (println result)
    4.48 +            (if (not= result bad-value)
    4.49 +              (let [keys (delayed-key key (inc n))]
    4.50 +                  (play-moves start-frame keys)
    4.51 +                  keys)
    4.52 +              (recur (inc n)))))))))
    4.53 +
    4.54 +
    4.55 +(defn search-first
    4.56 +  [start-frame
    4.57 +   baseline
    4.58 +   gen-move-fn
    4.59 +   summary-fn]
    4.60 +  (print "establishing baseline...")
    4.61 +  (play-moves start-frame baseline)
    4.62 +  (let [bad-value (summary-fn)]
    4.63 +    (println bad-value)
    4.64 +    (loop [n 0]
    4.65 +      (let [trial-moves (gen-move-fn n)
    4.66 +            header-length
    4.67 +            (common-initial-elements trial-moves baseline)]
    4.68 +        (print "length" (inc n) "...")
    4.69 +        (without-saves
    4.70 +         (play-moves
    4.71 +          (+ start-frame header-length)
    4.72 +          (drop header-length trial-moves)))
    4.73 +        (let [result (summary-fn)]
    4.74 +          (println result)
    4.75 +          (if (not= result bad-value)
    4.76 +            (let [keys (take (inc n) trial-moves)]
    4.77 +              (play-moves start-frame keys)
    4.78 +              keys)
    4.79 +            (recur (inc n))))))))
    4.80 +
    4.81 +(defn title-search
    4.82 +  [start-frame
    4.83 +   end-frame
    4.84 +   key
    4.85 +   summary-fn]
    4.86 +  (let [action-length (- end-frame start-frame)]
    4.87 +    (search-first
    4.88 +     start-frame
    4.89 +     (no-action action-length)
    4.90 +     (fn [n] (delayed-key key n action-length))
    4.91 +     summary-fn)))
    4.92 +
    4.93 +(defn gen-title []
    4.94 +  (let [start0 (no-action 300)]
    4.95 +    (play-moves 0 start0)
    4.96 +    (let [start->first-press
    4.97 +          (title-search (frame) (+ 50 (frame)) [:a] start-summary)
    4.98 +          first-press->second-press
    4.99 +          (title-search (frame) (+ 100 (frame)) [:start] start-summary)
   4.100 +          second-press->third-press
   4.101 +          (title-search (frame) (+ 151 (frame)) [:a] start-summary)
   4.102 +          new-game
   4.103 +          (title-search (frame) (+ 151 (frame)) [:a] start-summary)]
   4.104 +      (concat
   4.105 +       start0
   4.106 +       start->first-press
   4.107 +       first-press->second-press
   4.108 +       second-press->third-press
   4.109 +       new-game))))
   4.110 +  
   4.111 +(def title
   4.112 +  [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.113 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.114 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.115 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.116 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.117 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.118 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.119 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.120 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.121 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.122 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.123 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.124 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.125 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.126 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [ :a] [] [] [] [] [] [] []
   4.127 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.128 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.129 +   [] [] [] [] [] [] [] [] [] [:start] [] [] [] [] [] [] [] [] [] []
   4.130 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.131 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.132 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.133 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.134 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.135 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.136 +   [] [] [] [] [ :a] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.137 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.138 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.139 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.140 +   [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
   4.141 +   [] [] [] [] [] [ :a]])
   4.142 +
   4.143 +
     5.1 --- a/java/src/com/aurellem/gb/Gb.java	Thu Mar 08 22:29:11 2012 -0600
     5.2 +++ b/java/src/com/aurellem/gb/Gb.java	Fri Mar 09 01:43:25 2012 -0600
     5.3 @@ -64,7 +64,6 @@
     5.4  		position = i;
     5.5  		break;
     5.6  	    }}
     5.7 -	System.out.println("Position: " + position);
     5.8  	byte[] saveArray = new byte[position];
     5.9  	ByteBuffer save = createDirectByteBuffer(position);
    5.10  	buf.get(saveArray, 0 , position);
     6.1 --- a/src/VisualBoyAdvance.cfg	Thu Mar 08 22:29:11 2012 -0600
     6.2 +++ b/src/VisualBoyAdvance.cfg	Fri Mar 09 01:43:25 2012 -0600
     6.3 @@ -63,7 +63,7 @@
     6.4  Motion_Down=0102
     6.5  
     6.6  # Frame skip setting. Allowed values are from 0 to 5 only.
     6.7 -frameSkip=2
     6.8 +frameSkip=0
     6.9  
    6.10  # Gameboy Frame skip setting. Allowed values are from 0 to 5 only.
    6.11  gbFrameSkip=0
    6.12 @@ -154,7 +154,7 @@
    6.13  
    6.14  # Show emulation speed
    6.15  # 0=none, 1=percentage, 2=detailed
    6.16 -showSpeed=2
    6.17 +showSpeed=0
    6.18  
    6.19  # Show speed in transparent mode
    6.20  # 0=normal, anything else for transparent
    6.21 @@ -162,7 +162,7 @@
    6.22  
    6.23  # Enable/Disable auto frameskip
    6.24  # 0=disable, anything else to enable
    6.25 -autoFrameSkip=1
    6.26 +autoFrameSkip=0
    6.27  
    6.28  # Sets the desired throttle
    6.29  # 0=disable, 5...1000 valid throttle speeds