diff clojure/com/aurellem/item_bridge.clj @ 133:424510993296

saving progress
author Robert McIntyre <rlm@mit.edu>
date Sun, 18 Mar 2012 00:33:00 -0500
parents d16cf9d829dd
children b12d2408fd9b
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/item_bridge.clj	Sat Mar 17 21:32:29 2012 -0500
     1.2 +++ b/clojure/com/aurellem/item_bridge.clj	Sun Mar 18 00:33:00 2012 -0500
     1.3 @@ -9,294 +9,64 @@
     1.4  (defn corrupt-item-state []
     1.5    (read-state "corrupt-items"))
     1.6  
     1.7 -(defn talk-to-rival []
     1.8 -  (read-state "talk-to-rival"))
     1.9  
    1.10 -(def rival-name-start 0xD349)
    1.11 +(defn view-memory-range [state start end]
    1.12 +  (dorun
    1.13 +   (map (fn [loc val]
    1.14 +          (println (format "%04X : %02X" loc val)))
    1.15 +        
    1.16 +        (range start end) (subvec (vec (memory state)) start end)))
    1.17 +  state)
    1.18  
    1.19 -
    1.20 -(defn set-rival-name [^SaveState state codes]
    1.21 +(defn set-memory [state location value]
    1.22    (set-state! state)
    1.23    (let [mem (memory state)]
    1.24 -    (dorun (map (fn [index val]
    1.25 -                  (aset mem index val))
    1.26 -                (range rival-name-start
    1.27 -                       (+ rival-name-start
    1.28 -                          (count codes))) codes))
    1.29 +    (aset mem location value)
    1.30      (write-memory! mem)
    1.31      (update-state)))
    1.32  
    1.33 -(defn view-rival-name [name-codes]
    1.34 -  (->
    1.35 -   (set-rival-name (talk-to-rival) name-codes)
    1.36 -   (step [:a])
    1.37 -   (play 50)))
    1.38 +(defn almost-broken
    1.39 +  "if one more memory location is turned into 0x03, the game crashes."
    1.40 +  [n]
    1.41 +  (view-memory-range
    1.42 +   (set-inv-mem (mid-game)
    1.43 +                (concat [0xFF] (repeat 64 0x03)
    1.44 +                        (subvec (vec (memory (mid-game)))
    1.45 +                                (+ item-list-start 65)
    1.46 +                                (+ item-list-start 65 n))
    1.47 +                        (repeat (- 255 65 n) 0x03)
    1.48 +                        ))
    1.49 +                
    1.50 +   item-list-start (+ item-list-start 255)))
    1.51  
    1.52 -(defn rival-name-sequence []
    1.53 -  (let [i (atom 1)]
    1.54 -    (fn []
    1.55 -      (let [codes (range @i (+ 5 @i))]
    1.56 -        (println codes)
    1.57 -        (view-rival-name codes)
    1.58 -        (reset! i (+ 5 @i))))))
    1.59 -      
    1.60 +(defn actually-broken
    1.61 +  "if one more memory location is turned into 0x03, the game crashes."
    1.62 +  []
    1.63 +  (set-memory (mid-game) 0xD35D 0x03))
    1.64  
    1.65  
    1.66 -;; 0x00 :  end-of-name-sentinel
    1.67 -;; 0x01 :  
    1.68 -;; 0x02 :  
    1.69 -;; 0x03 :  
    1.70 -;; 0x04 :  
    1.71 -;; 0x05 :  
    1.72 -;; 0x06 :  
    1.73 -;; 0x07 :  
    1.74 -;; 0x08 :  
    1.75 -;; 0x09 :  
    1.76 -;; 0x0A :  
    1.77 -;; 0x0B :  
    1.78 -;; 0x0C :  
    1.79 -;; 0x0D :  
    1.80 -;; 0x0E :  
    1.81 -;; 0x0F :  
    1.82 -;; 0x10 :  
    1.83 -;; 0x11 :  
    1.84 -;; 0x12 :  
    1.85 -;; 0x13 :  
    1.86 -;; 0x14 :  
    1.87 -;; 0x15 :  
    1.88 -;; 0x16 :  
    1.89 -;; 0x17 :  
    1.90 -;; 0x18 :  
    1.91 -;; 0x19 :  
    1.92 -;; 0x1A :  
    1.93 -;; 0x1B :  
    1.94 -;; 0x1C :  
    1.95 -;; 0x1D :  
    1.96 -;; 0x1E :  
    1.97 -;; 0x1F :  
    1.98 -;; 0x20 :  
    1.99 -;; 0x21 :  
   1.100 -;; 0x22 :  
   1.101 -;; 0x23 :  
   1.102 -;; 0x24 :  
   1.103 -;; 0x25 :  
   1.104 -;; 0x26 :  
   1.105 -;; 0x27 :  
   1.106 -;; 0x28 :  
   1.107 -;; 0x29 :  
   1.108 -;; 0x2A :  
   1.109 -;; 0x2B :  
   1.110 -;; 0x2C :  
   1.111 -;; 0x2D :  
   1.112 -;; 0x2E :  
   1.113 -;; 0x2F :  
   1.114 -;; 0x30 :  
   1.115 -;; 0x31 :  
   1.116 -;; 0x32 :  
   1.117 -;; 0x33 :  
   1.118 -;; 0x34 :  
   1.119 -;; 0x35 :  
   1.120 -;; 0x36 :  
   1.121 -;; 0x37 :  
   1.122 -;; 0x38 :  
   1.123 -;; 0x39 :  
   1.124 -;; 0x3A :  
   1.125 -;; 0x3B :  
   1.126 -;; 0x3C :  
   1.127 -;; 0x3D :  
   1.128 -;; 0x3E :  
   1.129 -;; 0x3F :  
   1.130 -;; 0x40 :  
   1.131 -;; 0x41 :  
   1.132 -;; 0x42 :  
   1.133 -;; 0x43 :  
   1.134 -;; 0x44 :  
   1.135 -;; 0x45 :  
   1.136 -;; 0x46 :  
   1.137 -;; 0x47 :  
   1.138 -;; 0x48 :  
   1.139 -;; 0x49 :  
   1.140 -;; 0x4A :  
   1.141 -;; 0x4B :  
   1.142 -;; 0x4C :  
   1.143 -;; 0x4D :  
   1.144 -;; 0x4E :  
   1.145 -;; 0x4F :  
   1.146 -;; 0x50 :  
   1.147 -;; 0x51 :  
   1.148 -;; 0x52 :  
   1.149 -;; 0x53 :  
   1.150 -;; 0x54 :  
   1.151 -;; 0x55 :  
   1.152 -;; 0x56 :  
   1.153 -;; 0x57 :  
   1.154 -;; 0x58 :  
   1.155 -;; 0x59 :  
   1.156 -;; 0x5A :  
   1.157 -;; 0x5B :  
   1.158 -;; 0x5C :  
   1.159 -;; 0x5D :  
   1.160 -;; 0x5E :  
   1.161 -;; 0x5F :  
   1.162 -;; 0x60 :  A (small-bold)
   1.163 -;; 0x61 :  B (small-bold)
   1.164 -;; 0x62 :  C (small-bold)
   1.165 -;; 0x63 :  D (small-bold)
   1.166 -;; 0x64 :  E (small-bold)
   1.167 -;; 0x65 :  F (small-bold)
   1.168 -;; 0x66 :  G (small-bold)
   1.169 -;; 0x67 :  H (small-bold)
   1.170 -;; 0x68 :  I (small-bold)
   1.171 -;; 0x69 :  V (small-bold)
   1.172 -;; 0x6A :  S (small-bold)
   1.173 -;; 0x6B :  L (small-bold)
   1.174 -;; 0x6C :  M (small-bold)
   1.175 -;; 0x6D :  
   1.176 -;; 0x6E :  
   1.177 -;; 0x6F :  
   1.178 -;; 0x70 :  
   1.179 -;; 0x71 :  
   1.180 -;; 0x72 :  
   1.181 -;; 0x73 :  
   1.182 -;; 0x74 :  
   1.183 -;; 0x75 :  
   1.184 -;; 0x76 :  
   1.185 -;; 0x77 :  
   1.186 -;; 0x78 :  
   1.187 -;; 0x79 :  
   1.188 -;; 0x7A :  
   1.189 -;; 0x7B :  
   1.190 -;; 0x7C :  
   1.191 -;; 0x7D :  
   1.192 -;; 0x7E :  
   1.193 -;; 0x7F :  
   1.194 -;; 0x80 :  A
   1.195 -;; 0x81 :  B
   1.196 -;; 0x82 :  C
   1.197 -;; 0x83 :  D
   1.198 -;; 0x84 :  E
   1.199 -;; 0x85 :  F
   1.200 -;; 0x86 :  G
   1.201 -;; 0x87 :  H
   1.202 -;; 0x88 :  I
   1.203 -;; 0x89 :  J
   1.204 -;; 0x8A :  K
   1.205 -;; 0x8B :  L
   1.206 -;; 0x8C :  M
   1.207 -;; 0x8D :  N
   1.208 -;; 0x8E :  O
   1.209 -;; 0x8F :  P
   1.210 -;; 0x90 :  Q
   1.211 -;; 0x91 :  R
   1.212 -;; 0x92 :  S
   1.213 -;; 0x93 :  T
   1.214 -;; 0x94 :  U
   1.215 -;; 0x95 :  V
   1.216 -;; 0x96 :  W
   1.217 -;; 0x97 :  X
   1.218 -;; 0x98 :  Y
   1.219 -;; 0x99 :  Z
   1.220 -;; 0x9A :  (
   1.221 -;; 0x9B :  )
   1.222 -;; 0x9C :   :
   1.223 -;; 0x9D :  ;
   1.224 -;; 0x9E :  
   1.225 -;; 0x9F :  
   1.226 -;; 0xA0 :  a
   1.227 -;; 0xA1 :  b
   1.228 -;; 0xA2 :  c
   1.229 -;; 0xA3 :  d
   1.230 -;; 0xA4 :  e
   1.231 -;; 0xA5 :  f
   1.232 -;; 0xA6 :  g
   1.233 -;; 0xA7 :  h
   1.234 -;; 0xA8 :  i
   1.235 -;; 0xA9 :  j
   1.236 -;; 0xAA :  k
   1.237 -;; 0xAB :  l
   1.238 -;; 0xAC :  m
   1.239 -;; 0xAD :  n
   1.240 -;; 0xAE :  o
   1.241 -;; 0xAF :  p
   1.242 -;; 0xB0 :  q
   1.243 -;; 0xB1 :  r
   1.244 -;; 0xB2 :  s
   1.245 -;; 0xB3 :  t
   1.246 -;; 0xB4 :  u
   1.247 -;; 0xB5 :  v
   1.248 -;; 0xB6 :  w
   1.249 -;; 0xB7 :  x
   1.250 -;; 0xB8 :  y
   1.251 -;; 0xB9 :  z
   1.252 -;; 0xBA :  e-with-grave
   1.253 -;; 0xBB :  
   1.254 -;; 0xBC :  
   1.255 -;; 0xBD :  
   1.256 -;; 0xBE :  
   1.257 -;; 0xBF :  
   1.258 -;; 0xC0 :  
   1.259 -;; 0xC1 :  
   1.260 -;; 0xC2 :  
   1.261 -;; 0xC3 :  
   1.262 -;; 0xC4 :  
   1.263 -;; 0xC5 :  
   1.264 -;; 0xC6 :  
   1.265 -;; 0xC7 :  
   1.266 -;; 0xC8 :  
   1.267 -;; 0xC9 :  
   1.268 -;; 0xCA :  
   1.269 -;; 0xCB :  
   1.270 -;; 0xCC :  
   1.271 -;; 0xCD :  
   1.272 -;; 0xCE :  
   1.273 -;; 0xCF :  
   1.274 -;; 0xD0 :  
   1.275 -;; 0xD1 :  
   1.276 -;; 0xD2 :  
   1.277 -;; 0xD3 :  
   1.278 -;; 0xD4 :  
   1.279 -;; 0xD5 :  
   1.280 -;; 0xD6 :  
   1.281 -;; 0xD7 :  
   1.282 -;; 0xD8 :  
   1.283 -;; 0xD9 :  
   1.284 -;; 0xDA :  
   1.285 -;; 0xDB :  
   1.286 -;; 0xDC :  
   1.287 -;; 0xDD :  
   1.288 -;; 0xDE :  
   1.289 -;; 0xDF :  
   1.290 -;; 0xE0 :  '
   1.291 -;; 0xE1 :  PK
   1.292 -;; 0xE2 :  MN
   1.293 -;; 0xE3 :  
   1.294 -;; 0xE4 :  
   1.295 -;; 0xE5 :  
   1.296 -;; 0xE6 :  ?
   1.297 -;; 0xE7 :  !
   1.298 -;; 0xE8 :  .
   1.299 -;; 0xE9 :  
   1.300 -;; 0xEA :  
   1.301 -;; 0xEB :  
   1.302 -;; 0xEC :  
   1.303 -;; 0xED :  
   1.304 -;; 0xEE :  
   1.305 -;; 0xEF :  male-symbol
   1.306 -;; 0xF0 :  pokemon-money-symbol
   1.307 -;; 0xF1 :  .
   1.308 -;; 0xF2 :  /
   1.309 -;; 0xF3 :  ,
   1.310 -;; 0xF4 :  female-symbol
   1.311 -;; 0xF5 :  
   1.312 -;; 0xF6 :  0 
   1.313 -;; 0xF7 :  1
   1.314 -;; 0xF8 :  2
   1.315 -;; 0xF9 :  3
   1.316 -;; 0xFA :  4
   1.317 -;; 0xFB :  5
   1.318 -;; 0xFC :  6
   1.319 -;; 0xFD :  7
   1.320 -;; 0xFE :  8
   1.321 -;; 0xFF :  9
   1.322 -           
   1.323 -                
   1.324 +;; (almost-broken 20) more or less works
   1.325 +
   1.326 +(defn capture-program-counter
   1.327 +  "records the program counter for each tick"
   1.328 +  [^SaveState state ticks]
   1.329 +  (let [i (atom 0)]
   1.330 +    (reduce (fn [[program-counters state] _]
   1.331 +              (println (swap! i inc))
   1.332 +               [(conj program-counters (PC state))
   1.333 +                (tick state)])
   1.334 +              [[] state]
   1.335 +              (range ticks))))
   1.336 +
   1.337 +
   1.338 +(defn capture-program-counter
   1.339 +  [^SaveState state ticks]
   1.340 +  (set-state! state)
   1.341 +  (loop [i 0
   1.342 +         pcs []]
   1.343 +    (if (= i ticks)
   1.344 +      pcs
   1.345 +      (do 
   1.346 +        (com.aurellem.gb.Gb/tick)
   1.347 +        (recur (inc i)
   1.348 +               (conj pcs (first (registers))))))))