diff clojure/com/aurellem/world/practice.clj @ 194:67c42608ef9d

Further explorations in memory.
author Dylan Holmes <ocsenave@gmail.com>
date Fri, 23 Mar 2012 00:24:54 -0500
parents c8ec477beeac
children d5dddf33543c
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/world/practice.clj	Thu Mar 22 22:37:35 2012 -0500
     1.2 +++ b/clojure/com/aurellem/world/practice.clj	Fri Mar 23 00:24:54 2012 -0500
     1.3 @@ -1,299 +1,23 @@
     1.4  (ns com.aurellem.world.practice
     1.5    (:use (com.aurellem.gb saves util constants gb-driver vbm items
     1.6 -  assembly))
     1.7 +  assembly characters))
     1.8    (:use (com.aurellem.run title save-corruption))
     1.9    ;;(:use (com.aurellem.exp pokemon))
    1.10    (:use (com.aurellem.exp item-bridge))
    1.11 -  (:import [com.aurellem.gb.gb_driver SaveState]))
    1.12 -
    1.13 -(def opcodes
    1.14 -  [
    1.15 -   "NOP"
    1.16 -   "LD BC,nn"
    1.17 -   "LD (BC),A"
    1.18 -   "INC BC"
    1.19 -   "INC B"
    1.20 -   "DEC B"
    1.21 -   "LD B,n"
    1.22 -   "RLC A"
    1.23 -   "LD (nn),SP"
    1.24 -   "ADD HL,BC"
    1.25 -   "LD A,(BC)"
    1.26 -   "DEC BC"
    1.27 -   "INC C"
    1.28 -   "DEC C"
    1.29 -   "LD C,n"
    1.30 -   "RRC A"
    1.31 -
    1.32 -   "STOP"
    1.33 -   "LD DE,nn"
    1.34 -   "LD (DE),A"
    1.35 -   "INC DE"
    1.36 -   "INC D"
    1.37 -   "DEC D"
    1.38 -   "LD D,n"
    1.39 -   "RL A"
    1.40 -   "JR n"
    1.41 -   "ADD HL,DE"
    1.42 -   "LD A,(DE)"
    1.43 -   "DEC DE"
    1.44 -   "INC E"
    1.45 -   "DEC E"
    1.46 -   "LD E,n"
    1.47 -   "RR A"
    1.48 -
    1.49 -   "JR NZ,n"
    1.50 -   "LD HL,nn"
    1.51 -   "LDI (HL),A"
    1.52 -   "INC HL"
    1.53 -   "INC H"
    1.54 -   "DEC H"
    1.55 -   "LD H,n"
    1.56 -   "DAA"
    1.57 -   "JR Z,n"
    1.58 -   "ADD HL,HL"
    1.59 -   "LDI A,(HL)"
    1.60 -   "DEC HL"
    1.61 -   "INC L"
    1.62 -   "DEC L"
    1.63 -   "LD L,n"
    1.64 -   "CPL"
    1.65 -
    1.66 -   "JR NC,n"
    1.67 -   "LD SP,nn"
    1.68 -   "LDD (HL),A"
    1.69 -   "INC SP"
    1.70 -   "INC (HL)"
    1.71 -   "DEC (HL)"
    1.72 -   "LD (HL),n"
    1.73 -   "SCF"
    1.74 -   "JR C,n"
    1.75 -   "ADD HL,SP"
    1.76 -   "LDD A,(HL)"
    1.77 -   "DEC SP"
    1.78 -   "INC A"
    1.79 -   "DEC A"
    1.80 -   "LD A,n"
    1.81 -   "CCF"
    1.82 -
    1.83 -   "LD B,B"
    1.84 -   "LD B,C"
    1.85 -   "LD B,D"
    1.86 -   "LD B,E"
    1.87 -   "LD B,H"
    1.88 -   "LD B,L"
    1.89 -   "LD B,(HL)"
    1.90 -   "LD B,A"
    1.91 -   "LD C,B"
    1.92 -   "LD C,C"
    1.93 -   "LD C,D"
    1.94 -   "LD C,E"
    1.95 -   "LD C,H"
    1.96 -   "LD C,L"
    1.97 -   "LD C,(HL)"
    1.98 -   "LD C,A"
    1.99 -
   1.100 -   "LD D,B"
   1.101 -   "LD D,C"
   1.102 -   "LD D,D"
   1.103 -   "LD D,E"
   1.104 -   "LD D,H"
   1.105 -   "LD D,L"
   1.106 -   "LD D,(HL)"
   1.107 -   "LD D,A"
   1.108 -   "LD E,B"
   1.109 -   "LD E,C"
   1.110 -   "LD E,D"
   1.111 -   "LD E,E"
   1.112 -   "LD E,H"
   1.113 -   "LD E,L"
   1.114 -   "LD E,(HL)"
   1.115 -   "LD E,A"
   1.116 -
   1.117 -   "LD H,B"
   1.118 -   "LD H,C"
   1.119 -   "LD H,D"
   1.120 -   "LD H,E"
   1.121 -   "LD H,H"
   1.122 -   "LD H,L"
   1.123 -   "LD H,(HL)"
   1.124 -   "LD H,A"
   1.125 -   "LD L,B"
   1.126 -   "LD L,C"
   1.127 -   "LD L,D"
   1.128 -   "LD L,E"
   1.129 -   "LD L,H"
   1.130 -   "LD L,L"
   1.131 -   "LD L,(HL)"
   1.132 -   "LD L,A"
   1.133 -
   1.134 -   "LD (HL),B"
   1.135 -   "LD (HL),C"
   1.136 -   "LD (HL),D"
   1.137 -   "LD (HL),E"
   1.138 -   "LD (HL),H"
   1.139 -   "LD (HL),L"
   1.140 -   "HALT"
   1.141 -   "LD (HL),A"
   1.142 -   "LD A,B"
   1.143 -   "LD A,C"
   1.144 -   "LD A,D"
   1.145 -   "LD A,E"
   1.146 -   "LD A,H"
   1.147 -   "LD A,L"
   1.148 -   "LD A,(HL)"
   1.149 -   "LD A,A"
   1.150 -
   1.151 -   "ADD A,B"
   1.152 -   "ADD A,C"
   1.153 -   "ADD A,D"
   1.154 -   "ADD A,E"
   1.155 -   "ADD A,H"
   1.156 -   "ADD A,L"
   1.157 -   "ADD A,(HL)"
   1.158 -   "ADD A,A"
   1.159 -   "ADC A,B"
   1.160 -   "ADC A,C"
   1.161 -   "ADC A,D"
   1.162 -   "ADC A,E"
   1.163 -   "ADC A,H"
   1.164 -   "ADC A,L"
   1.165 -   "ADC A,(HL)"
   1.166 -   "ADC A,A"
   1.167 -
   1.168 -   "SUB A,B"
   1.169 -   "SUB A,C"
   1.170 -   "SUB A,D"
   1.171 -   "SUB A,E"
   1.172 -   "SUB A,H"
   1.173 -   "SUB A,L"
   1.174 -   "SUB A,(HL)"
   1.175 -   "SUB A,A"
   1.176 -   "SBC A,B"
   1.177 -   "SBC A,C"
   1.178 -   "SBC A,D"
   1.179 -   "SBC A,E"
   1.180 -   "SBC A,H"
   1.181 -   "SBC A,L"
   1.182 -   "SBC A,(HL)"
   1.183 -   "SBC A,A"
   1.184 -
   1.185 -   "AND B"
   1.186 -   "AND C"
   1.187 -   "AND D"
   1.188 -   "AND E"
   1.189 -   "AND H"
   1.190 -   "AND L"
   1.191 -   "AND (HL)"
   1.192 -   "AND A"
   1.193 -   "XOR B"
   1.194 -   "XOR C"
   1.195 -   "XOR D"
   1.196 -   "XOR E"
   1.197 -   "XOR H"
   1.198 -   "XOR L"
   1.199 -   "XOR (HL)"
   1.200 -   "XOR A"
   1.201 -
   1.202 -   "OR B"
   1.203 -   "OR C"
   1.204 -   "OR D"
   1.205 -   "OR E"
   1.206 -   "OR H"
   1.207 -   "OR L"
   1.208 -   "OR (HL)"
   1.209 -   "OR A"
   1.210 -   "CP B"
   1.211 -   "CP C"
   1.212 -   "CP D"
   1.213 -   "CP E"
   1.214 -   "CP H"
   1.215 -   "CP L"
   1.216 -   "CP (HL)"
   1.217 -   "CP A"
   1.218 -
   1.219 -   "RET NZ"
   1.220 -   "POP BC"
   1.221 -   "JP NZ,nn"
   1.222 -   "JP nn"
   1.223 -   "CALL NZ,nn"
   1.224 -   "PUSH BC"
   1.225 -   "ADD A,n"
   1.226 -   "RST 0"
   1.227 -   "RET Z"
   1.228 -   "RET"
   1.229 -   "JP Z,nn"
   1.230 -   "Ext ops"
   1.231 -   "CALL Z,nn"
   1.232 -   "CALL nn"
   1.233 -   "ADC A,n"
   1.234 -   "RST 8"
   1.235 -
   1.236 -   "RET NC"
   1.237 -   "POP DE"
   1.238 -   "JP NC,nn"
   1.239 -   "XX"
   1.240 -   "CALL NC,nn"
   1.241 -   "PUSH DE"
   1.242 -   "SUB A,n"
   1.243 -   "RST 10"
   1.244 -   "RET C"
   1.245 -   "RETI"
   1.246 -   "JP C,nn"
   1.247 -   "XX"
   1.248 -   "CALL C,nn"
   1.249 -   "XX"
   1.250 -   "SBC A,n"
   1.251 -   "RST 18"
   1.252 -
   1.253 -   "LDH (n),A"
   1.254 -   "POP HL"
   1.255 -   "LDH (C),A"
   1.256 -   "XX"
   1.257 -   "XX"
   1.258 -   "PUSH HL"
   1.259 -   "AND n"
   1.260 -   "RST 20"
   1.261 -   "ADD SP,d"
   1.262 -   "JP (HL)"
   1.263 -   "LD (nn),A"
   1.264 -   "XX"
   1.265 -   "XX"
   1.266 -   "XX"
   1.267 -   "XOR n"
   1.268 -   "RST 28"
   1.269 -
   1.270 -   "LDH A,(n)"
   1.271 -   "POP AF"
   1.272 -   "XX"
   1.273 -   "DI"
   1.274 -   "XX"
   1.275 -   "PUSH AF"
   1.276 -   "OR n"
   1.277 -   "RST 30"
   1.278 -   "LDHL SP,d"
   1.279 -   "LD SP,HL"
   1.280 -   "LD A,(nn)"
   1.281 -   "EI"
   1.282 -   "XX"
   1.283 -   "XX"
   1.284 -   "CP n"
   1.285 -   "RST 38"])
   1.286 -
   1.287 -
   1.288 -
   1.289 -
   1.290 -
   1.291 -
   1.292 -
   1.293 +  (:import [com.aurellem.gb.gb_driver SaveState])
   1.294 +  
   1.295 +  )
   1.296  
   1.297  (def hex-pc (comp hex PC))
   1.298  
   1.299 +(defn nstep [state n]
   1.300 +  (if (zero? n) state
   1.301 +      (recur (step state) (dec n))))
   1.302  
   1.303  
   1.304  (defn view-memory* [state start length]
   1.305    ((comp vec map)
   1.306 -   #((comp hex aget) (memory state) %)
   1.307 +   #((comp  aget) (memory state) %)
   1.308     (range start (+ start length))))
   1.309  
   1.310  
   1.311 @@ -312,12 +36,152 @@
   1.312     ;(step [:r])
   1.313     ;(step [:r])
   1.314     ))
   1.315 +(defn state-inject
   1.316 +  "I have replaced the letter e with e-acute @ 0xC4E8."
   1.317 +  []
   1.318 +  (read-state "inject-surprise"))
   1.319  
   1.320  
   1.321  
   1.322  
   1.323 +(defn pc-trail
   1.324 +  "Track the PC for a number of ticks."
   1.325 +  [state ticks]
   1.326 +  (tick state)
   1.327 +  (set-state! state)
   1.328 +  (loop [pcs [(PC)] ]
   1.329 +    (if (> (count pcs) ticks) pcs
   1.330 +        (do
   1.331 +          (com.aurellem.gb.Gb/tick)
   1.332 +          (recur (conj pcs (PC)))))))
   1.333  
   1.334  
   1.335  
   1.336 -(def surprise-pcs
   1.337 -  [8755 8757 8760 8761 8762 8763 8764 8767 8768 8770 8771 8774 8777 8780 8783 8786 8787 8810 8811 8814 8817 8836 8837 8838 8839 8840 8842 8843 8846 8849 8851 8852 8853 8854 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8872 8873 8874 8875 8876 8877 8879 8880 8882 8885 8888 8889 8892 8893 8894 8895 8896 8897 8898 8899 8901 8902 8904 8907 8910 8911 8914 8915 8916 8917 8918 8919 8920 8921 8923 8924 8926 8929 8932 8933 8936 8937 8938 8939 8940 8942 8943 8946 8949 8951 8953 8954 8957 8959 8961 8969 8971 8973 8974 8977 8983 8984 8987 8988 8991 8992 8993 8995 8996 8998 9001 9003 9006 9009 9011 9014 9015 9018 10178 10181 10182 10184 10187 10189 10190 10192 10194 10263 10265 10266 10268 10271 10274 10277 10279 10281 10283 10286 10289 10291 10293 10296 10297 10298 10299 10301 10303 10306 10307 10310 10312 10315 10317 10320 10322 10325 10327 10330 10332 10335 10338 10339 10341 10342 10344 10346 10347 10350 10352 10353 10354 10355 10357 10358 10359 10360 10361 10362 10363 10365 10366 10367 10368 10369 10370 10371 10373 10376 10378 10381 10383 10386 10388 10391 10393 10396 10398 10410 10412 10415 10417 10429 12215 12218 12220 12304 12306 12307 12309 12312 12315 12316 12317 12320 12321 12322 12324 12325 12327 12328 12329 12330 12332 12333 12336 12337 12347 12348 12349 12350 12351 12352 12353 12355 12356 12358 12359 12360 12361 12363 12364 12367 12368 12380 12381 12382 12383 12384 12385 12386 12388 12389 12391 12392 12393 12394 12396 12397 12400 12401 12413 12414 12415 12416 12417 12445 12448 12449 12450 12453 12455 12456 12459 12461 12462 12465 12467 12469 12471 12474 12475 12531 12532 12535 12536 12539 12540 12541 12542 12545 12546 12547 12548 12551 12553 12555 12560 12561 12564 12567 12570 12591 12592 12593 12595 12596 12599 12600 12601 12602 12603 12604 12605 12607 12608 12611 12613 12615 12617 12619 12638 12639 12640 12641 12642 12643 12645 12648 12651 12652 12655 12657 12660 12663 12664 12666 12669 12670 12671 12681 12683 12686 12725 12728 12731 12733 12735 12736 12739 12742 12743 12746 12748 12751 12752 12755 12757 12760 12762 12765 12766 12768 12771 12774 12775 12776 12779 12781 12782 12785 12788 12790 12907 12909 12912 12962 12963 12966 12967 12968 12971 12972 12975 12978 12980 12981 12983 12986 12988 12991 12992 12995 12996 12997 12999 13000 13001 13002 13003 13006 13007 13008 13009 13012 13015 13017 13020 13022 13025 13026 13027 13030 13031 13032 13035 13036 13037 13038 13062 13065 13067 13070 13071 13072 13073 13074 13075 13078 13079 13082 13177 13180 13182 13183 13185 13186 13188 13189 13192 13193 13194 13195 13198 13201 13203 13206 13209 13212 13213 13216 13217 13219 13221 13222 13224 13226 13245 13248 13354 13357 13359 13362 13365 13367 13369 13370 13372 13374 13375 13378 13379 13380 13381 13383 13384 13385 13387 13388 13389 13391 13392 13393 13403 13404 13407 13408 13409 13411 13414 13415 13416 13417 13420 13422 13425 13426 13427 13428 13431 13433 13436 13643 13645 13647 13649 13651 13652 13785 13788 13790 13793 13796 13799 13800 13803 13806 13878 13879 13880 13881 13883 13884 13888 13889 13890 13893 13894 13895 13898 13900 13901 13902 13903 13904 13906 13908 13909 13912 13913 13916 13918 13919 13920 13923 13926 13927 13930 13933 13955 13957 13959 13975 13978 13981 13984 14127 14130 14131 14133 14536 14539 14541 14542 14545 14547 14548 14549 14550 14551 14554 14556 14558 14561 14563 14565 14571 14574 14576 14578 14582 14584 14591 14593 14594 14596 14597 14598 14599 14980 14982 14984 14985 14988 14989 14991 14992 14993 14996 14997 14999 15000 15001 15004 15006 15007 15008 15009 15010 15011 15012 15013 15014 15015 15016 15017 15018 15401 15402 15406 15409 15410 15413 15414 15415 15417 15420 15423 15426 15429 15430 15433 15763 15764 15765 15766 15767 15769 15770 15771 15772 15773 15774 15777 15778 15779 15780 15781 15782 15783 15785 15786 15787 15789 15791 15792 15794 15795 15796 15798 15799 15800 15801 15835 15837 15981 15982 15983 15984 15986 15989 15992 15994 15995 15996 15997 15998 16000 16003 16004 16006 16007 16008 16010 16013 16016 16017 16018 16020 16023 16024 16052 16055 16057 16060 16061 16063 16065 16068 16071 16074 16077 16080 16081 16082 16083 16086 16087 16090 16091 16094 16095 16098 16099 16102 16103 16106 16107 16110 16111 16384 16386 16387 16388 16390 16392 16394 16396 16397 16399 16401 16402 16404 16406 16408 16410 16412 16414 16416 16418 16419 16421 16422 16424 16426 16428 16429 16431 16432 16434 16436 16439 16441 16442 16443 16444 16445 16447 16448 16449 16451 16452 16454 16457 16459 16461 16463 16465 16468 16469 16470 16471 16472 16474 16475 16477 16479 16480 16482 16652 16655 16656 16659 16660 16663 16664 16666 16669 16671 16674 16675 16678 16681 16682 16685 16688 16690 16693 16694 16696 16698 16701 16702 16704 16705 16706 16708 16710 16711 16714 16791 16792 16793 16795 16798 16799 16800 16801 16803 16819 16821 16838 16841 16842 16843 16844 16846 16865 16867 16870 16871 16872 16873 16875 16878 16881 16883 16885 16886 16887 16888 16890 16891 16893 16894 16895 16896 16897 16900 16902 16903 16906 16909 16912 16913 16914 16915 16916 16919 16928 16931 16932 16933 16936 16937 16938 16941 16943 16944 16945 16946 16947 16948 16949 16950 16952 16953 16954 16955 16957 16959 16960 16962 16964 16965 16967 17105 17108 17111 17112 17115 17116 17119 17120 17128 17130 17138 17140 17148 17150 17152 17155 17156 17157 17160 17374 17377 17378 17381 17384 17386 17389 17392 17394 17397 17400 17401 17404 17407 17410 17413 17415 17418 17421 17424 17427 17428 17430 17520 17521 17522 17523 17525 17528 17529 17530 17533 17534 17535 17537 17540 17543 17544 17546 17547 17549 17550 17551 17554 17555 17556 17558 17559 17560 17574 17576 17579 17580 17581 17602 17603 17606 17607 17610 17611 17629 17630 17632 17633 17634 17636 17639 17641 17643 17646 17647 17648 17651 17652 17654 17655 18052 18055 18056 18125 18126 18129 18131 18132 18133 18136 18139 18140 18141 18144 18145 18146 18149 18152 18153 18155 18158 18161 18163 18166 18169 18172 18173 18175 18177 18180 18181 18182 18184 18187 18188 18189 18190 18191 18215 18218 18220 18223 18224 18233 18234 18282 18283 18284 18286 18287 18288 18289 18291 18292 18294 18295 18297 18298 18299 18301 18302 18303 18304 18305 18306 18307 18310 18311 18313 18316 18317 18319 18322 18346 18349 18352 18353 18354 18356 18357 18358 18361 18362 18363 18364 18365 18366 18369 18370 18371 18372 18373 18376 18377 18378 18379 18380 18381 18382 18383 18384 18387 18388 18389 18391 18394 18397 18400 18435 18438 18439 18442 18443 18444 18446 18447 18450 18451 18453 18455 18457 18460 18462 18465 18466 18467 18468 18471 18472 18473 18474 18477 18478 18481 18482 18843 18846 18847 18849 18851 18858 18859 18861 18863 18864 18866 18867 18868 18871 18872 18873 18874 18877 18878 18879 18880 18881 18883 18884 18886 18888 18889 18892 18894 18895 18896 18897 18898 18899 18901 18902 18903 18904 18905 18906 18907 18908 18909 18910 18912 18913 18914 18916 18918 18919 18922 18924 18925 18927 18929 18931 18934 18937 18939 18940 18942 18943 18944 18946 18948 18949 18950 18951 18952 18954 18956 18957 18958 18959 18960 18963 18964 18966 18968 18969 18971 18972 18973 18974 18975 18976 18978 18980 18982 18983 18985 18987 18991 18992 18993 18994 18995 18997 18998 19000 19002 19003 19004 19005 19006 19007 19008 19009 19011 19012 19013 19014 19015 19016 19017 19018 19019 19020 19022 19023 19024 19025 19027 19028 19031 19033 19034 19035 19036 19038 19039 19040 19041 19042 19044 19045 19046 19047 19048 19049 19051 19052 19053 19054 19055 19056 19057 19058 19059 19060 19061 19063 19064 19065 19066 19067 19068 19069 19070 19071 19073 19075 19077 19079 19082 19083 19084 19085 19086 19087 19088 19089 19090 19091 19092 19093 19095 19096 19097 19100 19102 19104 19107 19108 19109 19110 19112 19113 19114 19116 19117 19118 19119 19120 19121 19123 19124 19125 19126 19127 19128 19129 19130 19132 19134 19137 19138 19140 19143 19144 19145 19146 19147 19150 19151 19152 19170 19173 19174 19176 19177 19179 19180 19181 19182 19183 19184 19186 19187 19188 19189 19190 19191 19192 19194 19195 19199 19200 19332 19333 19336 19338 19339 19342 19343 19346 19347 19348 19351 19352 19353 19355 19358 19359 19360 19361 19364 19367 19368 19371 19372 19375 19378 19379 19382 19383 19384 19385 19386 19388 19389 19391 19392 19394 19395 19396 19398 19399 19400 19401 19404 19405 19406 19407 19408 19410 19412 19414 19415 19417 19418 19419 19421 19422 19423 19424 19425 19426 19427 19428 19429 19430 19432 19435 19436 19438 19439 19440 19441 19444 19447 19449 19451 19452 19453 19454 19455 19456 19457 19458 19459 19460 19461 19463 19464 19466 19467 19468 19469 19470 19471 19472 19473 19475 19476 19477 19478 19479 19480 19481 19482 19483 19484 19486 19487 19488 19489 19490 19491 19492 19493 19494 19495 19496 19497 19498 19499 19501 19502 19503 19504 19505 19508 19509 19510 19511 19512 19514 19515 19516 19517 19518 19519 19521 19522 19523 19525 19526 19527 19528 19530 19531 19532 19533 19534 19535 19536 19538 19539 19540 19542 19543 19544 19546 19547 19549 19550 19551 19553 19555 19556 19558 19562 19564 19565 19567 19568 19570 19572 19574 19575 19576 19577 19578 19580 19582 19584 19585 19587 19589 19590 19591 19592 19593 19596 19597 19598 19599 19601 19602 19603 19604 19605 19606 19607 19608 19610 19611 19613 19614 19615 19617 19619 19620 19621 19622 19624 19625 19626 19627 19628 19629 19630 19631 19632 19633 19634 19636 19637 19638 19639 19640 19641 19642 19644 19646 19647 19648 19649 19650 19651 19652 19653 19654 19656 19658 19659 19662 19663 19664 19666 19673 19675 19676 19677 19678 19679 19680 19681 19682 19684 19688 19689 19690 19691 19692 19693 19694 19695 19697 19698 19700 19701 19702 19703 19705 19706 19707 19708 19709 19710 19711 19712 19713 19715 19716 19717 19718 19719 19721 19722 19733 19734 19735 19738 19740 19741 19743 19745 19746 19747 19749 19751 19753 19755 19756 19757 19759 19760 19761 19763 19764 19765 19767 19768 19770 19771 19772 19775 19776 19778 19780 19782 19783 19785 19788 19790 19791 19792 19793 19795 19796 19797 19799 19802 19803 19804 19805 19807 19808 19809 19823 19825 19827 19829 19830 19833 19834 19836 19840 19841 19842 19843 19845 19847 19849 19850 19851 19853 19855 19857 19858 19860 19861 19862 19864 19866 19868 19870 19872 19874 19875 19877 19878 19879 19880 19881 19882 19883 19884 19885 19886 19887 19890 19892 19893 19894 19895 19896 19898 19899 19900 19902 19905 19906 19907 19908 19909 19910 19911 19912 19914 19916 19917 19918 19920 19921 19922 19924 19925 19926 19928 19929 19930 19931 19932 19933 19935 19936 19937 19938 19939 19941 19942 19943 19944 19945 19949 19950 19952 19953 19954 19955 19958 19959 19960 19961 19962 19963 19964 19965 19966 19967 19969 19970 19971 19972 19973 19974 19975 19976 19977 19980 19983 19986 19988 19991 19993 19995 19998 20001 20003 20004 20007 20008 20010 20014 20017 20018 20021 20022 20025 20026 20029 20030 20032 20034 20035 20036 20039 20040 20041 20042 20045 20047 20049 20050 20051 20052 20053 20056 20059 20060 20062 20064 20065 20066 20067 20069 20072 20073 20076 20078 20081 20082 20084 20087 20089 20092 20094 20097 20100 20101 20102 20105 20107 20109 20111 20112 20113 20114 20117 20118 20121 20122 20123 20124 20125 20128 20129 20130 20133 20136 20138 20141 20143 20145 20146 20149 20151 20152 20155 20158 20159 20161 20171 20172 20175 20176 20177 20180 20183 20186 20187 20190 20192 20194 20196 20198 20200 20202 20204 20241 20244 20245 20248 20251 20281 20282 20283 20286 20289 20294 20295 20298 20299 20300 20301 20304 20305 20306 20309 20311 20312 20314 20315 20316 20318 20321 20324 20326 20328 20329 20330 20331 20332 20333 20334 20335 20336 20337 20338 20339 20341 20342 20343 20344 20345 20346 20347 20349 20350 20351 20352 20354 20356 20358 20359 20360 20361 20363 20393 20395 20397 20399 20400 20401 20402 20403 20405 20407 20409 20411 20412 20414 20415 20417 20418 20419 20421 20423 20425 20427 20428 20430 20498 20500 20502 20504 20505 20508 20509 20510 20511 20514 20516 20517 20518 20519 20522 20523 20524 20525 20528 20529 20530 20531 20540 20542 20543 20545 20548 20550 20551 20554 20556 20558 20560 20561 20562 20564 20565 20566 20568 20570 20571 20572 20574 20575 20576 20577 20578 20580 20582 20583 20585 20586 20587 20590 20591 20593 20595 20597 20598 20600 20603 20605 20606 20607 20609 20610 20611 20613 20616 20617 20618 20619 20621 20622 20623 20625 20627 20629 20631 20632 20634 20635 20637 20638 20639 20641 20642 20644 20645 20646 20647 20648 20649 20650 20652 20653 20654 20656 20657 20658 20659 20663 20664 20665 20666 20668 20670 20672 20673 20674 20675 20676 20677 20678 20680 20681 20682 20683 20684 20685 20686 20687 20688 20689 20690 20691 20692 20693 20695 20696 20697 20699 20701 20702 20703 20704 20705 20706 20707 20708 20709 20710 20712 20713 20714 20715 20716 20717 20718 20721 20722 20724 20729 20731 20734 20735 20737 20739 20742 20743 20745 20747 20749 20750 20751 20752 20753 20755 20757 20758 20760 20761 20762 20763 20764 20765 20766 20767 20768 20770 20771 20772 20773 20774 20775 20776 20777 20778 20781 20782 20783 20785 20786 20788 20789 20790 20791 20793 20794 20795 20798 20799 20800 20803 20804 20806 20808 20810 20811 20812 20813 20814 20815 20816 20817 20818 20820 20821 20822 20823 20824 20825 20826 20827 20829 20830 20831 20832 20834 20835 20837 20839 20840 20841 20842 20844 20845 20846 20847 20848 20849 20850 20851 20852 20854 20855 20856 20857 20858 20859 20860 20861 20862 20863 20864 20865 20866 20867 20869 20871 20872 20875 20876 20877 20878 20879 20880 20881 20882 20883 20884 20885 20886 20887 20888 20889 20890 20891 20892 20894 20895 20896 20897 20898 20899 20900 20901 20902 20903 20904 20905 20906 20907 20908 20909 20910 20911 20912 20913 20914 20915 20916 20917 20918 20921 20923 20924 20925 20926 20927 20928 20929 20930 20931 20932 20933 20934 20937 20938 20940 20941 20942 20943 20944 20945 20946 20947 20948 20949 20950 20951 20953 20954 20956 20957 20958 20961 20962 20963 20964 20965 20966 20967 20968 20969 20970 20972 20975 20977 20978 20981 20983 20984 20985 20986 20988 20990 21016 21019 21020 21021 21022 21023 21024 21075 21077 21108 21110 21112 21113 21115 21116 21117 21119 21120 21121 21122 21123 21124 21126 21127 21128 21130 21132 21134 21136 21138 21140 21141 21142 21144 21146 21148 21149 21150 21151 21152 21154 21156 21158 21159 21160 21161 21163 21165 21167 21174 21177 21178 21180 21181 21182 21184 21186 21187 21189 21192 21193 21194 21197 21198 21200 21202 21204 21207 21208 21209 21211 21212 21215 21217 21271 21273 21278 21281 21283 21285 21287 21303 21305 21307 21308 21310 21311 21313 21315 21316 21317 21318 21319 21320 21321 21323 21325 21327 21328 21329 21330 21331 21332 21333 21334 21335 21336 21338 21340 21343 21344 21345 21348 21350 21352 21353 21355 21357 21360 21363 21366 21369 21370 21373 21376 21379 21382 21409 21412 21414 21425 21427 21457 21459 21487 21489 21491 21494 21496 21499 21501 21514 21516 21518 21520 21523 21525 21526 21527 21529 21530 21533 21535 21537 21538 21540 21542 21544 21547 21548 21550 21552 21555 21556 21558 21561 21562 21563 21564 21565 21567 21570 21571 21574 21575 21577 21580 21581 21584 21585 21586 21588 21590 21597 21598 21599 21602 21605 21606 21609 21610 21611 21613 21638 21639 21641 21643 21644 21646 21648 21664 21665 21667 21668 21669 21672 21673 21676 21677 21679 21680 21683 21684 21685 21686 21687 21689 21690 21692 21693 21694 21697 21698 21699 21700 21703 21704 21706 21708 21711 21712 21715 21716 21718 21720 21722 21724 21737 21738 21740 21743 21744 21745 21748 21749 21750 21753 21754 21755 21756 21759 21760 21761 21764 21765 21767 21769 21772 21773 21775 21777 21778 21779 21780 21782 21784 21786 21787 21789 21791 21794 21795 21796 21797 21799 21800 21802 21804 21806 21808 21810 21813 21814 21816 21817 21819 21821 21823 21826 21828 21829 21830 21832 21833 21834 21836 21838 21841 21842 21843 21846 21848 21851 21852 21854 21859 21860 21861 21863 21865 21868 21870 21871 21872 21873 21874 21876 21880 21882 21885 21886 21887 21889 21892 21893 21896 21899 21900 21902 21905 21906 21908 21910 21911 21914 21917 21918 21919 21922 21923 21925 21928 21929 21931 21932 21933 21934 21936 21938 21940 21942 21945 21946 21947 21948 21950 21953 21956 21957 21958 21959 21961 21964 21965 21966 21967 21968 21969 21971 21972 21974 21977 21978 21979 21980 21982 21984 21986 21988 21989 21991 21992 21995 21996 21997 21998 21999 22001 22004 22005 22006 22007 22009 22011 22013 22015 22016 22019 22021 22026 22027 22028 22030 22031 22034 22035 22036 22037 22038 22041 22043 22045 22047 22048 22049 22050 22051 22052 22053 22055 22057 22059 22060 22061 22063 22065 22066 22068 22071 22072 22073 22074 22075 22077 22079 22082 22140 22143 22145 22148 22191 22194 22196 22198 22206 22207 22208 22211 22214 22216 22236 22237 22540 22543 22544 22545 22548 22549 22552 22553 22554 22555 22556 22558 22559 22561 22563 22565 22566 22568 22570 22571 22573 22575 22576 22578 22579 22580 22581 22582 22585 22586 22587 22588 22589 22590 22592 22594 22596 22598 22599 22601 22603 22604 22605 22606 22609 22612 22614 22617 22619 22622 22638 22639 22640 22642 22643 22644 22645 22648 22649 22650 22653 22654 22657 22658 22660 22661 22662 22663 22664 22665 22666 22667 22668 22670 22673 22674 22677 22678 22679 22680 22681 22683 22684 22686 22689 22690 22691 22692 22723 22726 22727 22728 22735 22738 22739 22742 22743 22744 22746 22747 22748 22749 22752 22753 22754 22755 22758 22759 22760 22761 22762 22764 22765 22766 22768 22769 22770 22771 22773 22774 22776 22777 22778 22779 22781 22782 22783 22784 22786 22787 22789 22791 22794 22795 22797 22798 22799 22800 22801 22802 22803 22804 22805 22806 22807 22808 22810 22811 22814 22815 22818 22819 22820 22821 22822 22823 22824 22825 22826 22827 22829 22832 22834 22836 22880 22898 22899 22900 22903 22905 22907 22908 22910 22913 22914 22915 22916 23032 23033 23036 23039 23042 23045 23048 23050 23053 23056 23059 23062 23064 23067 23070 23073 23076 23079 23082 23085 23088 23091 23094 23097 23100 23103 23106 23109 23112 23115 23118 23121 23124 23127 23130 23133 23136 23139 23142 23145 23148 23151 23154 23157 23160 23163 23166 23169 23172 23174 23177 23180 23183 23186 23189 23192 23195 23197 23200 23201 23203 23205 23207 23209 23211 23212 23214 23216 23218 23220 23222 23223 23224 23225 23226 23227 23228 23229 23230 23233 23234 23235 23236 23239 23240 23241 23242 23243 23246 23247 23248 23251 23252 23253 23256 23257 23258 23261 23262 23263 23266 23267 23268 23271 23272 23273 23276 23277 23278 23281 23282 23283 23286 23287 23288 23291 23292 23293 23296 23297 23298 23301 23302 23303 23306 23307 23308 23311 23312 23313 23316 23317 23318 23321 23322 23323 23326 23327 23328 23331 23332 23333 23335 23338 23339 23340 23343 23344 23345 23348 23349 23350 23351 23353 23359 23361 23363 23365 23366 23368 23370 23372 23374 23376 23378 23380 23382 23384 23386 23388 23390 23392 23393 23396 23399 23402 23405 23408 23411 23414 23416 23419 23422 23424 23426 23429 23432 23435 23438 23440 23443 23444 23445 23446 23447 23449 24562 24565 24566 24579 24582 24584 24591 24594 24595 24596 24599 24601 24604 25377 25380 25382 25412 25413 25416 26501 26502 26505 26508 26511 26514 26515 26517 26518 26519 26520 26521 26524 26525 26526 26527 26529 26530 26534 26535 26573 26576 26578 26581 26584 26587 26588 26590 26591 26592 26593 26594 26596 26598 26599 26601 26602 26604 26605 26606 26609 26610 26612 26613 26615 26616 26617 26618 26619 26620 26621 26622 26623 26624 26625 26626 26628 26629 26631 26632 26633 26634 26635 26636 26638 26639 26640 26641 26642 26643 26644 26646 26647 26648 26649 26650 26651 26652 26654 26655 26656 26662 26663 26664 26665 26684 26687 26690 26693 26695 26698 26700 26715 26716 26717 26720 26722 26724 26725 26728 26729 26730 26732 26734 26737 26740 26742 26744 26745 26748 26749 26750 26753 26756 26759 26760 26762 26763 26765 26768 26769 26771 26772 26774 26775 26797 26800 26801 26803 26806 26808 26811 26817 26820 26823 26824 26826 26829 26831 26834 26836 26839 26840 26841 26842 26845 26847 26849 26850 26853 26854 26855 26858 26861 26863 26865 26866 26869 26870 26871 26874 26875 26876 26879 26880 26884 26887 26889 26891 26893 26905 26908 26909 26911 26923 26924 26927 26930 26932 26935 26938 26940 26942 26943 26946 26947 26948 26950 26954 26957 26960 26962 26964 26965 26968 26969 26970 26973 26976 26978 26989 26991 26993 26996 26998 27022 27024 27027 27030 28430 28431 28434 28437 28439 28441 28443 28444 28467 28470 28473 28476 28479 28481 28484 28486 28488 28490 28493 28496 28498 28501 28502 28503 28504 28505 28506 28507 28509 28512 28515 28516 28517 28519 28521 28523 28524 28525 28526 28528 28530 28533 28534 28536 28539 28541 28543 28706 28708 28710 28711 28714 28715 28717 28736 28737 28739 28833 28836 28838 29119 29122 29124 29127 29128 29131 29134 29137 29139 29142 29145 29148 29170 29173 29176 29179 29217 29218 29219 29221 29223 29224 29226 29227 29229 29230 29231 29232 29233 29234 29235 29236 29237 29238 29239 29240 29241 29242 29243 29258 29259 29262 29265 29266 29267 29269 29270 29271 29273 29274 29275 29932 29935 29936 29937 29938 29939 29940 29942 29943 29944 29946 29948 29950 29951 29952 29955 29956 29958 29959 29961 29963 29965 29966 29967 29969 29971 29987 29988 29989 29990 29991 29992 29993 29994 30778 30781 30782 30783 30786 30787 30788 30791 30793 30796 30802 30805 30807 30810 30812 30815 30816 30824 30827 30828 30831 30832 30835 30837 30839 30840 30843 30845 30848 30850 30940 30942 30943 65408 65410 65412 65414 65415 65417])
   1.338 \ No newline at end of file
   1.339 +(defn differences [list-1 list-2]
   1.340 +  (remove
   1.341 +   (fn [[a b c]] (= b c))
   1.342 +   (map vector
   1.343 +        (range)
   1.344 +        list-1
   1.345 +        list-2)))
   1.346 +
   1.347 +(defn pc-diff [state-1 state-2]
   1.348 +  (differences (map hex (pc-trail state-1 10000))
   1.349 +               (map hex (pc-trail state-2 10000))))
   1.350 +
   1.351 +
   1.352 +(defn memory-diff [state-1 state-2]
   1.353 +  (remove
   1.354 +  (fn[[a b c]] (= b c))
   1.355 +  (map (comp vec (partial map hex) list)
   1.356 +       (range)
   1.357 +       (vec (memory state-1))
   1.358 +       (vec (memory state-2)))
   1.359 +   )
   1.360 +  )
   1.361 +
   1.362 +
   1.363 +
   1.364 +(defn state-speak
   1.365 +  "This is when the trainer speaks."
   1.366 +  []
   1.367 +  (->
   1.368 +   (pre-trainer-battle)
   1.369 +   (set-memory 0xD354 0x0)
   1.370 +   (step [:r])
   1.371 +   (step)
   1.372 +   (ntick 88147)
   1.373 +   (tick)
   1.374 +   (nstep 102)
   1.375 +
   1.376 +   ;(step [:r])
   1.377 +
   1.378 +   ;(step [:r])
   1.379 +   ;(step [:r])
   1.380 +   ;(step [:r])
   1.381 +   ;(step [:r])
   1.382 +   ))
   1.383 +  
   1.384 +  
   1.385 +
   1.386 +(defn get-memory [state n]
   1.387 +  (aget (memory state) n))
   1.388 +
   1.389 +(defn first-change
   1.390 +  "Watch the current memory location as it ticks,
   1.391 +return the first state that differs at location mem." 
   1.392 +  [state n]
   1.393 +  (tick state)
   1.394 +  (set-state! state)
   1.395 +  (let [init (aget (memory state) n)]
   1.396 +    (loop []
   1.397 +      (if (= (aget (memory) n) init)
   1.398 +        (do
   1.399 +          (com.aurellem.gb.Gb/tick)
   1.400 +          (recur))))
   1.401 +    (update-state)))
   1.402 +
   1.403 +
   1.404 +
   1.405 +(defn spell [state mem n]
   1.406 +  (print (character-codes->str
   1.407 +          (take n (drop mem
   1.408 +                        (vec(memory state)))))))
   1.409 +
   1.410 +
   1.411 +(do
   1.412 +  (println)
   1.413 +  (print (character-codes->str (take 6000 (drop 0xA75F4
   1.414 +                                               (vec(com.aurellem.gb.gb-driver/rom))))))
   1.415 +  )
   1.416 +
   1.417 +;(dorun (map println (view-memory* (state-surprise)  0x1AEF 1600)))
   1.418 +
   1.419 +
   1.420 +
   1.421 +(def surprise-words
   1.422 +  [0x80 0xAB 0xAB 0x7F 0xB1 0xA8 0xA6 0xA7 0xB3 0xE7 0x7F 0x8B 0xA4 0xB3 0xE0 0xB2 0x7F 0xB1 0xAE 0xAB 0xAB 0x7F 0xB3 0xA7 0xA4 0x7F 0xA3 0xA8 0xA2 0xA4 0xE7])
   1.423 +
   1.424 +(defn sublist
   1.425 +  "Unshifts the list until the sublist is at the start."
   1.426 +  [list sub]
   1.427 +  (cond
   1.428 +    (empty? sub) list
   1.429 +    (empty? list) nil
   1.430 +    (= (take (count sub) list) sub) list
   1.431 +    :else (recur (rest list) sub)))
   1.432 +
   1.433 +(defn subloc
   1.434 +  "Returns the position of the first occurence of sublist."
   1.435 +  [list sub]
   1.436 +  (loop [n 0 a list]
   1.437 +    (cond
   1.438 +      (empty? a) nil
   1.439 +      (= (take (count sub) a) sub) n
   1.440 +      :else (recur (inc n) (rest a)))))
   1.441 +
   1.442 +
   1.443 +
   1.444 +
   1.445 +(defn change-speech
   1.446 +  ([state str k]
   1.447 +     (loop [ops str
   1.448 +            s state
   1.449 +            n k]
   1.450 +       (if (empty? ops) s
   1.451 +           (recur
   1.452 +            (rest ops)
   1.453 +            (set-memory (first-change s (+ 0xC4B9 n)) (+ 0xC4B9 n)
   1.454 +                        (first ops))
   1.455 +            (if (not= n 19) (inc n)
   1.456 +                (+ n 21))))))
   1.457 +  ([str k]
   1.458 +     (change-speech (state-speak) str k))
   1.459 +  ([str]
   1.460 +     (change-speech str 0))
   1.461 +       
   1.462 +         
   1.463 +    
   1.464 +      
   1.465 +  )
   1.466 +