# HG changeset patch # User Dylan Holmes # Date 1333953859 18000 # Node ID 998702f021e32884a271e8e39c83fcdddfd8363c # Parent b477970d0b7aef051977f7a39ee0db5a0724adff# Parent 8d8023057b3c07509d67d867931fe2fd646a4980 merged changes diff -r b477970d0b7a -r 998702f021e3 clojure/com/aurellem/exp/cartography --- a/clojure/com/aurellem/exp/cartography Mon Apr 09 01:40:26 2012 -0500 +++ b/clojure/com/aurellem/exp/cartography Mon Apr 09 01:44:19 2012 -0500 @@ -505,14 +505,14 @@ D35A Q D35B T D35C Q -D35D BEGIN MAP DATA T +D35D BEGIN MAP DATA (current-map) T D35E Q D35F T D360 Q D361 Player Offset X T D362 Player Offset Y Q D363 T -D364 Q +D364 FLOOR MAT WARP DESTINATION Q D365 T D366 Q D367 T diff -r b477970d0b7a -r 998702f021e3 clojure/com/aurellem/exp/item_bridge.clj --- a/clojure/com/aurellem/exp/item_bridge.clj Mon Apr 09 01:40:26 2012 -0500 +++ b/clojure/com/aurellem/exp/item_bridge.clj Mon Apr 09 01:44:19 2012 -0500 @@ -220,11 +220,6 @@ 0x55 ])) - - -(def pc-item-list-start 0xD539) -(def pc-item-list-width 101) - (def corrupted-items-width 512) (defn items-record diff -r b477970d0b7a -r 998702f021e3 clojure/com/aurellem/exp/warp.clj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clojure/com/aurellem/exp/warp.clj Mon Apr 09 01:44:19 2012 -0500 @@ -0,0 +1,289 @@ +(ns com.aurellem.exp.warp + (:use (com.aurellem.gb gb-driver vbm items util saves)) + (:use (com.aurellem.run util)) + (:import [com.aurellem.gb.gb_driver SaveState])) + + +;; special thanks to http://tasvideos.org/2913S.html for revealing +;; 0xD364 as the floor-map warp location + + +(def mat-warp-address 0xD364) + +(defn view-warp-id [warp-id] + (->> + [[] (set-memory (at-mat) mat-warp-address warp-id)] + (do-nothing 20) + (play-moves [↓]) + (do-nothing 100))) + +(defn iterate-locations [start] + (dorun + (map + #(do + (printf "0x%02X\n" %) + (view-warp-id %) + (Thread/sleep 10000)) + (range start (inc 0xFF))))) + + +(comment +0x00 pallet-town-home +0x01 viridian-poke-center +0x02 pewter-science-meuseum +0x03 cereluan-dig-house +0x04 lavender-town-poke-center +0x05 vermillion-poke-center +0x06 celedon-department-store !!!!!!!!!!! +0x07 fuchia-mart +0x08 cinnibar-mansion +0x09 elite-four-HQ +0x0A saffron-mimic-house +0x0B CRASHING GLITCH +0x0C route-1-inside-junk +0x0D diglett-cave-vermillion-side +0x0E GLITCH +0x0F poke-center-outside-mt-moon +0x10 cereullean->saffron +0x11 GLITCH +0x12 saffron->celadon +0x13 saffron->lavendar +0x14 GLITCH +0x15 poke-center-by-rock-tunnel +0x16 vermillion->lavender +0x17 lavender->fuchia +0x18 GLITCH +0x19 GLITCH +0x1A unknown +0x1B cycling-road->celadon +0x1C GLITCH +0x1D cycling-road->fuschia +0x1E surfing-house +0x1F seafom-island-cinnabar-side +0x20 GLITCH +0x21 indigo-plateu-gate +0x22 plateau-path-start +0x23 GLITCH +0x24 bills-house +0x25 house-again +0x26 stairs-to-house +0x27 gary's-house +0x28 oak's-lab +0x29 poke-center-unknown +0x2A inside-viridian-mart +0x2B viridian-school-house +0x2C unknown +0x2D viridian-gym +0x2E diglett's-cave-unknown-side +0x2F glitched-viridian-forest-entrance +0x30 unknown +0x31 unknown +0x32 unknown +0x33 viridian-forest-pewter-side +0x34 pewter-meuseum-first-floor +0x35 pweter-meuseum-second-floor +0x36 pewter-gym +0x37 unknown-house +0x38 unknown-mart +0x39 unknown-house +0x3A inside-pewter-poke-center +0x3B inside-mt-moon-entrance +0x3C mt-moon-unknown +0x3D mt-moon-unknown +0x3E inside-dig-house-cereulan? +0x3F inside-bulbasaur-house-cerulean +0x40 unknown-poke-center +0x41 cereulan-gym +0x42 inside-bike-shop +0x43 unknown-mart +0x44 unknown-poke-center +0x45 inside-dig-house-cereulan? +0x46 unknown-guard-path +0x47 unknown-undeground-path-entrance +0x48 unknown-house +0x49 unknown-undeground-path-entrance +0x4A unknown-undeground-path-entrance +0x4B unknown-undeground-path-entrance +0x4C unknown-guard-path +0x4D unknown-undeground-path-entrance +0x4E unknown-undeground-path-entrance +0x4F unknown-guard-path +0x50 unknown-undeground-path-entrance +0x51 unknown-poke-center +0x52 mt-moon-unknown +0x53 inside-power-plant-start +0x54 unknown-guard-path +0x55 diglet's-cave-vermillion-entrange +0x56 unknown-2nd-floor-guard-path +0x57 unknown-guard-path +0x58 inside-bill's-house +0x59 unknown-poke-center +0x5A inside-pokemon-fan-club +0x5B unknown-mart +0x5C unknown-gym? +0x5D unknown-house +0x5E s.s.anne-catwalk +0x5F s.s.anne-entrance +0x60 unknown-ss-anne-door +0x61 unknown-ss-anne +0x62 unknown-ss-anne +0x63 ss-anne-bow +0x64 ss-anne-cafeteria +0x65 ss-anne-inside-captian's-room +0x66 ss-anne-inside-room +0x67 ss-anne-inside-room +0x68 ss-anne-inside-room +0x69 CRASHING GLITCH +0x6A CRASHING GLITCH +0x6B CRASHING GLITCH +0x6C moltres-cave-entrance +0x6D CRASHING GLITCH +0x6E CRASHING GLITCH +0x6F CRASHING GLITCH +0x70 CRASHING GLITCH +0x71 unknown-ss-anne +0x72 CRASHING GLITCH +0x73 CRASHING GLITCH +0x74 CRASHING GLITCH +0x75 CRASHING GLITCH +0x76 elite-four-hall-of-fame +0x77 unknown-inside-underground-tunnel +0x78 unknown +0x79 unknown-inside-underground-tunnel +0x7A unknown +0x7B unknown-celadon-dept-store-floor ! +0x7C unknown-celadon-dept-store-floor ! +0x7D unknown-celadon-dept-store-floor ! +0x7E celedon-dept-roof ! +0x7F celadon-dept-elevator +0x80 celadon-pokemon-mansion-first-floor +0x81 celadon-pokemon-mansion-second-floor +0x82 celadon-pokemon-mansion-third-floor(computers) +0x83 celadon-pokemon-mansion-boring-roof +0x84 celadon-pokemon-mansion-eevee-room +0x85 unknown-poke-center +0x86 inside-celadon-gym +0x87 inside-celadon-game-corner +0x88 unknown-celadon-dept-store-floor ! +0x89 celadon-game-corner-prize-claim +0x8A celadon-cafeteria +0x8B celadon-rocket-house +0x8C unknown-poke-center (maybe celadon?) +0x8D unknown-poke-venter (maybe celadon hotel?) +0x8E unknown-pokemon-tower +0x8F unknown-pokemon-tower +0x90 unknown-pokemon-tower +0x91 unknown-pokemon-tower +0x92 unknown-pokemon-tower +0x93 unknown-pokemon-tower +0x94 unknown-pokemon-tower +0x95 inside-fiji's-house +0x96 unknown-mart +0x97 unknown-house +0x98 unknown-mart +0x99 unknown-house +0x9A unknown-poke-center +0x9B inside-game-warden's-house +0x9C inside-safari-zone-gate +0x9D vermillion-gym +0x9E unknown-fuscia +0x9F unknown-cave +0xA0 unknown-cave +0xA1 unknown-moltres-cave +0xA2 unknown-seafoam-cave +0xA3 unknown-fishing-guru-house +0xA4 cereulan-house +0xA5 cinibar-mansion-first-floor +0xA6 saffron-gym +0xA7 cinibar-fossil-regen-lab-entrance +0xA8 unknown-house +0xA9 cinibar-fossil-regen-room +0xAA cinibar-fossil-regen-regen-room +0xAB unknown-poke-center +0xAC unknown-mart +0xAD unknown-mart +0xAE eilte-four-poke-center +0xAF glitched-house +0xB0 mimic's-room +0xB1 inside-fighting-dojo +0xB2 saffron-gym +0xB3 unknown-house (lavender?) +0xB4 unknown-mart +0xB5 sliph-co-first-floor +0xB6 unknown-poke-center +0xB7 unknown-house +0xB8 unknown-guard-path +0xB9 unknown-guard-path-2nd-floor +0xBA unknown-guard-path +0xBB unknown-guard-path-2nd-floor +0xBC unknown-house +0xBD unknown-house (fishing guru?) +0xBE unknown-guard-path +0xBF unknown-guard-path-2nd-floor +0xC0 unknown-cave +0xC1 elite-four-gate-entrance +0xC2 unknown-moltres-cave +0xC3 unknown-guard-path-2nd-floor +0xC4 unknown-house +0xC5 unknown-cave +0xC6 unknown-moltres-cave +0xC7 unknown-game-corner +0xC8 unknown-game-corner +0xC9 unknown-game-corner +0xCA unknown-game-corner +0xCB game-corner-elevator +0xCC GLITCH +0xCD GLITCH +0xCE GLITCH +0xCF unknown-silph-co +0xD0 unknown-silph-co +0xD1 unknown-silph-co +0xD2 unknown-silph-co +0xD3 unknown-silph-co +0xD4 unknown-silph-co +0xD5 unknown-silph-co +0xD6 unknown-cinnibar-mansion +0xD7 unknown-cinnibar-mansion +0xD8 unknown-cinnibar-mansion +0xD9 unknown-safari-zone +0xDA unknown-safari-zone +0xDB unknown-safari-zone +0xDC unknown-safari-zone +0xDD unknown-safari-zone-rest-room +0xDE safari-zone-surf-room +0xDF unknown-safari-zone-rest-room +0xE0 unknown-safari-zone-rest-room +0xE1 unknown-safari-zone-rest-room +0xE2 unknown-mewtwo-cave +0xE3 unknown-mewtwo-cave +0xE4 mewtwo-cave-entrance +0xE5 unknown-house +0xE6 cereulan-badge-description-room +0xE7 CRASHING GLITCH +0xE8 unknown-cave +0xE9 unknown-silph-co +0xEA unknown-silph-co +0xEB silph-co-boring-top-floor +0xEC silph-co-elevator +0xED GLITCH +0xEE GLITCH +0xEF GLITCH +0xF0 GLITCH +0xF1 GLITCH +0xF2 GLITCH +0xF3 GLITCH +0xF4 GLITCH +0xF5 loreli-room +0xF6 bruno-room +0xF7 agatha-room +0xF8 inside-surfing-room +0xF9 GLITCH (dark) +0xFA GLITCH (dark) +0xFB CRASHING GLITCH +0xFC GLITCH (dark) +0xFD CRASHING GLITCH +0xFE CRASHING GLITCH +0xFF CRASHING GLITCH + + +) \ No newline at end of file diff -r b477970d0b7a -r 998702f021e3 clojure/com/aurellem/gb/items.clj --- a/clojure/com/aurellem/gb/items.clj Mon Apr 09 01:40:26 2012 -0500 +++ b/clojure/com/aurellem/gb/items.clj Mon Apr 09 01:44:19 2012 -0500 @@ -8,6 +8,9 @@ (map char (subvec (vec (memory)) 0x134 0x142))) (def item-list-start 0xD31C) +(def pc-item-list-start 0xD539) +(def pc-item-list-width 101) + (defn item-list ([^SaveState state] @@ -16,7 +19,23 @@ item-list-start (+ item-list-start 255))) ([] (item-list @current-state))) - + +(defn nth-item + ([^SaveState state n] + (let [mem (memory state)] + [(aget mem (+ item-list-start 1 (* 2 n))) + (aget mem (+ item-list-start 2 (* 2 n)))])) + ([n] (nth-item @current-state n))) + + +(defn nth-pc-item + ([^SaveState state n] + (let [mem (memory state)] + [(aget mem (+ pc-item-list-start 1 (* 2 n))) + (aget mem (+ pc-item-list-start 2 (* 2 n)))])) + ([n] (nth-pc-item @current-state n))) + + (def item-code->item-name (hash-map 0x01 :master-ball diff -r b477970d0b7a -r 998702f021e3 clojure/com/aurellem/gb/saves.clj --- a/clojure/com/aurellem/gb/saves.clj Mon Apr 09 01:40:26 2012 -0500 +++ b/clojure/com/aurellem/gb/saves.clj Mon Apr 09 01:44:19 2012 -0500 @@ -41,4 +41,6 @@ (gen-save cursor-item-3) (gen-save cursor-item-4) (gen-save cursor-item-5) -(gen-save cursor-item-6) \ No newline at end of file +(gen-save cursor-item-6) + +(gen-save at-mat) \ No newline at end of file diff -r b477970d0b7a -r 998702f021e3 clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Mon Apr 09 01:40:26 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Mon Apr 09 01:44:19 2012 -0500 @@ -397,22 +397,30 @@ "Set the quantity of an item to buy or sell to the desired value using the fewest possible button presses." ([total-quantity desired-quantity [moves state :as script]] - (let [current-quantity (item-quantity-selected state) - loop-point (if (> total-quantity 99) 0xFF 99) - distance (- desired-quantity current-quantity) - loop-distance (int(* -1 (Math/signum (float distance)) - (- loop-point (Math/abs distance)))) - best-path (first (sort-by #(Math/abs %) - [distance loop-distance])) - direction (if (< 0 best-path) ↑ ↓)] - (println "best-path" best-path) - (reduce - (fn [script _] - (delayed-difference [] direction 5 item-quantity-selected - script)) - - script - (range (Math/abs best-path))))) + (cond (= desired-quantity 1) (do (println "1 of 1") script) + (= total-quantity desired-quantity) + (do (println "get everything!") + (delayed-difference [] ↓ 5 item-quantity-selected + script)) + true + (let [current-quantity (item-quantity-selected state) + loop-point (if (= 0 total-quantity) 0x100 total-quantity) + distance (- desired-quantity current-quantity) + loop-distance (int(* -1 (Math/signum (float distance)) + (- loop-point (Math/abs distance)))) + best-path (first (sort-by #(Math/abs %) + [distance loop-distance])) + direction (if (< 0 best-path) ↑ ↓)] + (println "best-path" best-path) + (println "current-quantity" current-quantity) + (println "desired-quantity" desired-quantity) + (println "options" [distance loop-distance]) + (reduce + (fn [script _] + (delayed-difference [] direction 5 item-quantity-selected + script)) + script + (range (Math/abs best-path)))))) ([desired-quantity [moves state :as script]] (set-quantity 99 desired-quantity script))) @@ -426,11 +434,15 @@ (println "wait-time" wait-time) (do-nothing wait-time script))) -(defn select-menu-entry [script] - (->> script - (wait-until (partial set-cursor-relative 1)) - (play-moves [[:a] []]))) - +(defn select-menu-entry + ([test-direction [moves state :as script]] + (->> script + (wait-until (partial set-cursor-relative test-direction)) + (play-moves [[] [:a] []]))) + ([[moves state :as script]] + (select-menu-entry + 1 script))) + (defn restart "The two button presses after a restart event are converted to blanks. Due to weirdness with the VBM format. To compensate, ensure @@ -441,10 +453,11 @@ (defn-memo do-save-corruption ([] (do-save-corruption (walk-to-counter))) - ([script] + ([script] (do-save-corruption 4 script)) + ([n script] (->> script activate-start-menu - (set-cursor 4) + (set-cursor n) select-menu-entry select-menu-entry (play-moves @@ -470,8 +483,45 @@ (def menu do-nothing ) + +(defn investivate-close-menu [] + (clojure.pprint/pprint + (apply harmonic-compare + (map read-state + ["start-up-1" + "start-down-1" + ;;"start-up-2" + ;;"start-down-2" + ;;"start-up-3" + ;;"start-down-3" + ;;"computer-up-1" + ;;"computer-down-2" + "computer-up-2" + "computer-down-2" + "pokemon-up-1" + "pokemon-down-1" + "pokemon-up-2" + "pokemon-down-2" + "item-up-1" + "item-down-1" + "save-up-1" + "save-down-1" + "item-nest-up-1" + "item-nest-down-1"])))) + +(def list-nesting-depth-address 50339) + +(defn current-depth + ([^SaveState state] (aget (memory state) list-nesting-depth-address)) + ([] (current-depth @current-state))) + + (defn close-menu [script] - (first-difference [] [:b] AF script)) + (delayed-difference + [] [:b] 50 + current-depth + script)) + (defn purchase-item "Assumes that the cursor is over the desired item, and purchases @@ -492,10 +542,11 @@ ;;(corrupted-checkpoint) (do-save-corruption) )) - ([script] + ([script] (corrupt-item-list 1)) + ([n script] (->> script activate-start-menu - (set-cursor 1) ; select "POKEMON" from + (set-cursor n) ; select "POKEMON" select-menu-entry ; from main menu. (set-cursor 5) ; select 6th pokemon select-menu-entry @@ -1042,159 +1093,3 @@ ((fn [_] (println "===========") _)) (print-listing 0xD162 (+ 0xD162 20))))) -(defn pc-item-writer-program - [] - (let [limit 201 - [target-high target-low] (disect-bytes-2 0xD162)] - (flatten - [[0x00 ;; (item-hack) set increment stack pointer no-op - 0x1E ;; load limit into E - limit - 0x3F ;; (item-hack) set carry flag no-op - - ;; load 2 into C. - 0x0E ;; C == 1 means input-first nybble - 0x04 ;; C == 0 means input-second nybble - - 0x21 ;; load target into HL - target-low - target-high - 0x37 ;; (item-hack) set carry flag no-op - - 0x00 ;; (item-hack) no-op - 0x37 ;; (item-hack) set carry flag no-op - - 0x00 ;; (item-hack) no-op - 0xF3 ;; disable interrupts - ;; Input Section - - 0x3E ;; load 0x20 into A, to measure buttons - 0x10 - - 0x00 ;; (item-hack) no-op - 0xE0 ;; load A into [FF00] - 0x00 - - 0xF0 ;; load 0xFF00 into A to get - 0x00 ;; button presses - - 0xE6 - 0x0F ;; select bottom four bits of A - 0x37 ;; (item-hack) set carry flag no-op - - 0x00 ;; (item-hack) no-op - 0xB8 ;; see if input is different (CP A B) - - 0x00 ;; (item-hack) (INC SP) - 0x28 ;; repeat above steps if input is not different - ;; (jump relative backwards if B != A) - 0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37) - - 0x47 ;; load A into B - - 0x0D ;; dec C - 0x37 ;; (item-hack) set-carry flag - ;; branch based on C: - 0x20 ;; JR NZ - 23 ;; skip "input second nybble" and "jump to target" below - - ;; input second nybble - - 0x0C ;; inc C - 0x0C ;; inc C - - 0x00 ;; (item-hack) no-op - 0xE6 ;; select bottom bits - 0x0F - 0x37 ;; (item-hack) set-carry flag no-op - - 0x00 ;; (item-hack) no-op - 0xB2 ;; (OR A D) -> A - - 0x22 ;; (do (A -> (HL)) (INC HL)) - - 0x1D ;; (DEC E) - - 0x00 ;; (item-hack) - 0x20 ;; jump back to input section if not done - 0xDA ;; literal -36 == TM 18 (counter) - 0x01 ;; (item-hack) set BC to literal (no-op) - - ;; jump to target - 0x00 ;; (item-hack) these two bytes can be anything. - 0x01 - - 0x00 ;; (item-hack) no-op - 0xBF ;; (CP A A) ensures Z - - 0xCA ;; (item-hack) jump if Z - target-low - target-high - 0x01 ;; (item-hack) will never be reached. - - ;; input first nybble - 0x00 - 0xCB - 0x37 ;; swap nybbles on A - - 0x57 ;; A -> D - - 0x37 ;; (item-hack) set carry flag no-op - 0x18 ;; relative jump backwards - 0xCD ;; literal -51 == TM05; go back to input section - 0x01 ;; (item-hack) will never reach this instruction - - ] - (repeat 8 [0xFF 0x01]) - - [;; jump to actual program - 0x00 - 0x37 ;; (item-hack) set carry flag no-op - - 0x2E ;; 0x3A -> L - 0x3A - - - 0x00 ;; (item-hack) no-op - 0x26 ;; 0xD5 -> L - 0xD5 - 0x01 ;; (item-hack) set-carry BC - - 0x00 ;; (item-hack) these can be anything - 0x00 - - ;; 0x00 - ;; 0x44 ;; H -> B - - ;; 0x00 - ;; 0x7D ;; L -> A - - ;; 0x00 - ;; 0x7C ;; A -> H - - ;; 0x00 - ;; 0x68 ;; B -> L - - 0x00 - 0xE9 ;; jump to (HL) - ]]))) - - -(defn test-pc-item-writer [] - (-> (read-state "bootstrap-init") - (set-memory pc-item-list-start 50) - (set-memory-range - map-function-address-start - [0x8B 0xD5]) - (set-memory-range - (inc pc-item-list-start) - (pc-item-writer-program)))) - -(defn test-pc-item-writer-2 [] - (let [orig (read-state "pc-item-writer")] - (-> orig - (print-listing 0xD162 (+ 0xD162 20)) - (run-moves (reduce concat - (repeat 10 [[:a :b :start :select] []]))) - ((fn [_] (println "===========") _)) - (print-listing 0xD162 (+ 0xD162 20))))) diff -r b477970d0b7a -r 998702f021e3 clojure/com/aurellem/run/bootstrap_1.clj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clojure/com/aurellem/run/bootstrap_1.clj Mon Apr 09 01:44:19 2012 -0500 @@ -0,0 +1,570 @@ +(ns com.aurellem.run.bootstrap-1 + (:use (com.aurellem.gb saves gb-driver util + items vbm characters money)) + (:use (com.aurellem.run util title save-corruption bootstrap-0)) + (:use (com.aurellem.exp item-bridge)) + (:import [com.aurellem.gb.gb_driver SaveState])) + +(defn pc-item-writer-program + [] + (let [limit 201 + [target-high target-low] (disect-bytes-2 0xD162)] + (flatten + [[0x00 ;; (item-hack) set increment stack pointer no-op + 0x1E ;; load limit into E + limit + 0x3F ;; (item-hack) set carry flag no-op + + ;; load 2 into C. + 0x0E ;; C == 1 means input-first nybble + 0x04 ;; C == 0 means input-second nybble + + 0x21 ;; load target into HL + target-low + target-high + 0x37 ;; (item-hack) set carry flag no-op + + 0x00 ;; (item-hack) no-op + 0x37 ;; (item-hack) set carry flag no-op + + 0x00 ;; (item-hack) no-op + 0xF3 ;; disable interrupts + ;; Input Section + + 0x3E ;; load 0x20 into A, to measure buttons + 0x10 + + 0x00 ;; (item-hack) no-op + 0xE0 ;; load A into [FF00] + 0x00 + + 0xF0 ;; load 0xFF00 into A to get + 0x00 ;; button presses + + 0xE6 + 0x0F ;; select bottom four bits of A + 0x37 ;; (item-hack) set carry flag no-op + + 0x00 ;; (item-hack) no-op + 0xB8 ;; see if input is different (CP A B) + + 0x00 ;; (item-hack) (INC SP) + 0x28 ;; repeat above steps if input is not different + ;; (jump relative backwards if B != A) + 0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37) + + 0x47 ;; load A into B + + 0x0D ;; dec C + 0x37 ;; (item-hack) set-carry flag + ;; branch based on C: + 0x20 ;; JR NZ + 23 ;; skip "input second nybble" and "jump to target" below + + ;; input second nybble + + 0x0C ;; inc C + 0x0C ;; inc C + + 0x00 ;; (item-hack) no-op + 0xE6 ;; select bottom bits + 0x0F + 0x37 ;; (item-hack) set-carry flag no-op + + 0x00 ;; (item-hack) no-op + 0xB2 ;; (OR A D) -> A + + 0x22 ;; (do (A -> (HL)) (INC HL)) + + 0x1D ;; (DEC E) + + 0x00 ;; (item-hack) + 0x20 ;; jump back to input section if not done + 0xDA ;; literal -36 == TM 18 (counter) + 0x01 ;; (item-hack) set BC to literal (no-op) + + ;; jump to target + 0x00 ;; (item-hack) these two bytes can be anything. + 0x01 + + 0x00 ;; (item-hack) no-op + 0xBF ;; (CP A A) ensures Z + + 0xCA ;; (item-hack) jump if Z + target-low + target-high + 0x01 ;; (item-hack) will never be reached. + + ;; input first nybble + 0x00 + 0xCB + 0x37 ;; swap nybbles on A + + 0x57 ;; A -> D + + 0x37 ;; (item-hack) set carry flag no-op + 0x18 ;; relative jump backwards + 0xCD ;; literal -51 == TM05; go back to input section + 0x01 ;; (item-hack) will never reach this instruction + + ] + (repeat 8 [0x00 0x01]) + + [;; jump to actual program + 0x00 + 0x37 ;; (item-hack) set carry flag no-op + + 0x2E ;; 0x3A -> L + 0x3A + + + 0x00 ;; (item-hack) no-op + 0x26 ;; 0xD5 -> L + 0xD5 + 0x01 ;; (item-hack) set-carry BC + + 0x00 ;; (item-hack) these can be anything + 0x01 + + 0x00 + 0xE9 ;; jump to (HL) + ]]))) + +(defn view-desired-item-layout [] + (clojure.pprint/pprint + (raw-inventory->inventory (pc-item-writer-program)))) + +(defn pc-item-writer-state [] + (-> (read-state "bootstrap-init") + (set-memory pc-item-list-start 50) + (set-memory-range + map-function-address-start + [0x8B 0xD5]) + (set-memory-range + (inc pc-item-list-start) + (pc-item-writer-program)))) + +(defn test-pc-item-writer [] + (let [orig (read-state "pc-item-writer")] + (-> orig + (print-listing 0xD162 (+ 0xD162 20)) + (run-moves (reduce concat + (repeat 10 [[:a :b :start :select] []]))) + ((fn [_] (println "===========") _)) + (print-listing 0xD162 (+ 0xD162 20))))) + +(defn close-all-menus [[moves state :as script]] + (loop [s script] + (let [depth (current-depth (second (do-nothing 50 s)))] + (println "depth" depth) + (if (= depth 1) + s + (recur (close-menu s)))))) + +(defn-memo name-rival + ([] (name-rival (to-rival-name))) + ([script] + (->> script + (first-difference [] [:a] AF) + (first-difference [] [:r] DE) + (play-moves + [[] + [] [] [:r] [] [:d] [:a] ;; L + [:r] [] [:r] [] [:r] [] [:r] [] + [:r] [] [:d] [] [:d] [:a] ;; [PK] + [:d] [] [:r] [:a] + ])))) + +(defn-memo to-room-pc + ([] (to-room-pc (name-rival))) + ([script] + (->> script + finish-title + (walk [← ← ↑ ← ↑ ↑ ↑])))) + +(defn-memo bootstrap-corrupt-save + ([] (bootstrap-corrupt-save (to-room-pc))) + ([script] + (->> script + (do-save-corruption 2) + (corrupt-item-list 0) + close-all-menus))) + +(defn-memo begin-initial-deposits + ([] (begin-initial-deposits + (bootstrap-corrupt-save))) + ([script] + (->> script + (first-difference [] [:a] AF) + (scroll-text) + (set-cursor 1) + select-menu-entry))) + +(defn wait-for-quantity + [[moves state :as script]] + (if (not= (item-quantity-selected state) 1) + (repeat-until-different [] item-quantity-selected script) + script)) + +(defn wait-for-cursor + [[moves state :as script]] + (if (not= (list-offset state) 0) + (repeat-until-different [] list-offset script) + script)) + +(defn deposit-held-item [n quantity [moves state :as script]] + (let [total-quantity (second (nth-item state n))] + (println "total-quantity" total-quantity) + (->> script + (set-cursor n) + (select-menu-entry 1) + (wait-for-quantity) + (set-quantity total-quantity quantity) + (delayed-difference [] [:a] 100 #(search-string % "stored")) + (scroll-text)))) + +(defn sell-held-item [n quantity [moves state :as script]] + (let [total-quantity (second (nth-item state n))] + (->> script + (wait-for-cursor) ;; when selling, the cursor always + (set-cursor n) ;; returns to the top of the list. + (select-menu-entry 1) + (wait-for-quantity) + (set-quantity total-quantity quantity) + (delayed-difference [] [:a] 100 current-depth) + (play-moves (repeat 20 [:b])) + (delayed-difference [] [:a] 100 #(search-string % "What")) + ))) + +(defn widthdraw-pc-item [n quantity [moves state :as script]] + (let [total-quantity (second (nth-pc-item state n))] + (->> script + (set-cursor n) + (select-menu-entry 1) + (wait-for-quantity) + (set-quantity total-quantity quantity) + (delayed-difference [] [:a] 100 #(search-string % "Withdrew")) + (scroll-text)))) + +(defn toss-held-item [n quantity [moves state :as script]] + (let [total-quantity (second (nth-item state n))] + (->> script + (set-cursor n) + (select-menu-entry 1) + (set-cursor-relative 1) + (select-menu-entry -1) + (wait-for-quantity) + (set-quantity total-quantity quantity) + (play-moves [[:a]]) + (scroll-text) + (delayed-difference [] [:a] 100 #(search-string % "Threw")) + (scroll-text) + ))) + +(defn buy-item [n quantity [moves state :as script]] + (->> script + (set-cursor n) + (purchase-item quantity))) + + +(def desired-zero-quantities + (map second (filter (comp (partial = 0) first) + (partition 2 (pc-item-writer-program))))) + +(defn-memo initial-deposits + ([] (initial-deposits (begin-initial-deposits))) + ([script] + (->> script + (deposit-held-item 0 0x1) + ((fn [script] + (reduce + (fn [script item] (deposit-held-item item 0xFF script)) + script + (range 3 (+ 13 3))))) + close-all-menus))) + + +(defn-memo prepare-celadon-warp + ([] (prepare-celadon-warp (initial-deposits))) + ([script] + (->> script + (activate-start-menu) + (set-cursor-relative 1) + (select-menu-entry) + (toss-held-item 35 0xFA) + (close-all-menus)))) + + +;;0 -- 256 +;;1 -- 254 +;;2 -- 254 +;;3 -- 255 + +(defn-memo restore-items + ([] (restore-items (prepare-celadon-warp))) + ([script] + (->> script + (first-difference [] [:a] AF) + (scroll-text) + (select-menu-entry) + (widthdraw-pc-item 0 1) + ;;(widthdraw-pc-item 0 99) + ;;(widthdraw-pc-item 1 1) + (widthdraw-pc-item 13 255) + (close-all-menus)))) + +(defn-memo to-celadon + ([] (to-celadon (restore-items))) + ([script] + (->> script + (walk [→ → → → → → → ↑ + ↓ ↓ ↓ ↓ ↓ ← ← ← ← + ↓ ↓])))) + + +;; celadon store inventory + +;; Floor 2 +;;===================================== +;; Great Ball TM32 (double-team) +;; Super Potion TM33 (reflect) +;; Revive TM02 (razor-wind) +;; Super Repel TM07 (horn-drill) +;; Antidote TM37 (egg-bomb) +;; Burn Heal TM01 (mega-punch) +;; Ice Heal TM05 (mega-kick) +;; Awakening TM09 (take-down) +;; Parlyz Heal TM17 (submission) + + +;; Floor 3 +;;===================================== +;; TM18 (counter) + + +;; Floor 4 +;;===================================== +;; Poke Doll +;; Fire Stone +;; Thunder Stone +;; Water Stone +;; Leaf Stone + +;; Floor 5 +;;===================================== +;; X Accuracy HP UP +;; Guard Spec. Protein +;; Dire Hit Iron +;; X Attack Carbos +;; X Defend Calcium +;; X Speed +;; X Special + +;; Roof +;;===================================== +;; Fresh Water TM13 (ice-beam) +;; Soda Pop TM48 (rock-slide) +;; Lemonade :) TM49 (tri-attack) + + +(defn-memo go-to-floor-two + ([] (go-to-floor-two (to-celadon))) + ([script] + (->> script + (walk [↑ → → → → → → → → → → → + ↑ ↑ ↑ ↑ ↑ ↑ + ← ← ← ← + ↓ ↓ ↓ + ← ←]) + (first-difference [] ↑ AF)))) + +(defn talk + "Assumes that you are facing something that initiates text and + causes it to do so." + [script] + (->> script + (delayed-difference [] [:a] 100 + #(aget (memory %) text-address)))) + +(defn-memo get-money-floor-two + ([] (get-money-floor-two (go-to-floor-two))) + ([script] + (->> script + talk + (set-cursor 1) + (select-menu-entry) + (sell-held-item 0 1) + (sell-held-item 0 1) + (close-menu)))) + +(defn-memo floor-two-TMs + ([] (floor-two-TMs (get-money-floor-two))) + ([script] + (->> script + (wait-for-cursor) + (select-menu-entry) + (buy-item 2 98) ;; TM02 (razor-wind) + (buy-item 4 71) ;; TM37 (doubleteam) + (buy-item 5 63) ;; TM01 (mega-punch) + (buy-item 6 1) ;; TM05 (mega-kick) + (buy-item 7 56) ;; TM09 (take-down) + (close-menu)))) + +(defn end-shop-conversation + [script] + (->> script + (wait-until scroll-text [:b]) + (play-moves [[] [:b]]) + close-menu)) + +(defn-memo floor-two-more-money + ([] (floor-two-more-money (floor-two-TMs))) + ([script] + (->> script + (wait-for-cursor) + (set-cursor 1) + (select-menu-entry) + (sell-held-item 0 1) + (sell-held-item 0 1) + close-menu + end-shop-conversation))) + +(defn turn [direction script] + (->> script + (first-difference [] direction AF))) + +(defn-memo floor-two-items + ([] (floor-two-items (floor-two-more-money))) + ([script] + (->> script + (walk [←]) + (turn ↑) + talk + select-menu-entry + (buy-item 5 12) ;; burn heal + (buy-item 6 55) ;; ice heal + (buy-item 7 4) ;; awakening + (buy-item 8 99) ;; parlyz heal + (buy-item 8 55) ;; parlyz heal + close-menu + end-shop-conversation))) + +(defn-memo go-to-floor-three + ([] (go-to-floor-three (floor-two-items))) + ([script] + (->> script + (walk [→ → → → → → → → → → ↑ ↑ ↑ + → ↑])))) +(defn-memo get-TM18 + ([] (get-TM18 (go-to-floor-three))) + ([script] + (->> script + (walk [↓ ↓]) + talk + (scroll-text 3) + end-text))) + +(defn-memo go-to-floor-four + ([] (go-to-floor-four (get-TM18))) + ([script] + (->> script + (walk [← ← ← ← ↑ ↑ + ↓ ← ← ↓ ↓ ↓ + ← ← ← ← ←]) + (turn ↓)))) + +(defn-memo floor-four-items + ([] (floor-four-items (go-to-floor-four))) + ([script] + (->> script + talk + select-menu-entry + (buy-item 1 23) ;; Fire Stone + (buy-item 2 98) ;; Thunder Stone + (buy-item 3 29) ;; Water Stone + close-menu + end-shop-conversation))) + +(defn-memo go-to-floor-five + ([] (go-to-floor-five (floor-four-items))) + ([script] + (->> script + (walk [→ → → → → → + ↑ ↑ ↑ + → → → → → ↑ ;; leave floor four + ↓ ← ← ← ← ← ← ← ← + ↓ ↓ ↓ ← ← ← ]);; go to five's clerk + (turn ↑)))) + +(defn-memo floor-five-items + ([] (floor-five-items (go-to-floor-five))) + ([script] + (->> script + talk + select-menu-entry + (buy-item 0 58) ;; X-Accuracy + (buy-item 1 99) ;; Guard Spec. + (buy-item 1 24) ;; Guard Spec. + close-menu + end-shop-conversation))) + +(defn-memo go-to-roof + ([] (go-to-roof (floor-five-items))) + ([script] + (->> script + (walk [→ → → → ↑ ↑ ↑ → → → ↑ ;; leave floor five + ↓ ← ← ←]) ;; walk to vending machine + (turn ↑)))) + +(defn buy-drink + "Assumes you're in front of the vending machine. Buys the indicated + drink." + [n script] + (->> script + (do-nothing 20) + (play-moves [[:a][:a]]) + scroll-text + (wait-for-cursor) + (set-cursor n) + select-menu-entry + close-menu)) + +(defn-memo roof-drinks + ([] (roof-drinks (go-to-roof))) + ([script] + (->> script + (buy-drink 0) ;; fresh water (for TM13) + ;; buy 16 lemonades + ;; LEMONADE is the best item <3 :) + (multiple-times 16 (partial buy-drink 2))))) + +(defn-memo get-TM13 + ([] (get-TM13 (roof-drinks))) + ([script] + (->> script + (walk [← ← ← ← ← ← ↓]) + (play-moves [[][:a][:a][]]) + (scroll-text 3) + select-menu-entry + select-menu-entry + (scroll-text 6) + close-menu))) + +(defn to-celadon-poke-center + ([] (to-celadon-poke-center (get-TM13))) + ([script] + (->> script + (walk [↑ → → → → → → → → → ↑]) ; leave roof + (walk [↓ ← ← ← ← ↓ ↓ ↓ ← ← ← ← ← + ↑ ↑ ↑ ← ← ↑]) ; to elevator + + (walk [→ → ↑ ↑]) ; to controls + talk + select-menu-entry ; to floor 1 + (walk [↓ ↓ ← ←]) + (walk [↓ → ↓ ↓ ↓ ↓ ↓ ↓]) ; leave store + (walk [↓ → → → → → → → → → → ↑ ↑]) + (walk (repeat 23 →)) + (walk [↑ ↑ ↑ ↑]) ; enter poke center + (walk [↑ ↑ ↑ → → → → → → → → → →]) ; to computer + (turn ↑)))) diff -r b477970d0b7a -r 998702f021e3 moves/temp.vbm Binary file moves/temp.vbm has changed diff -r b477970d0b7a -r 998702f021e3 org/rom.org --- a/org/rom.org Mon Apr 09 01:40:26 2012 -0500 +++ b/org/rom.org Mon Apr 09 01:44:19 2012 -0500 @@ -810,6 +810,7 @@ *** + #+name: type-advantage #+begin_src clojure (defn hxc-advantage diff -r b477970d0b7a -r 998702f021e3 save-states/at-mat.sav Binary file save-states/at-mat.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/computer-down-1.sav Binary file save-states/computer-down-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/computer-down-2.sav Binary file save-states/computer-down-2.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/computer-up-1.sav Binary file save-states/computer-up-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/computer-up-2.sav Binary file save-states/computer-up-2.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/item-down-1.sav Binary file save-states/item-down-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/item-nest-down-1.sav Binary file save-states/item-nest-down-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/item-nest-up-1.sav Binary file save-states/item-nest-up-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/item-up-1.sav Binary file save-states/item-up-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/pokemon-down-1.sav Binary file save-states/pokemon-down-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/pokemon-down-2.sav Binary file save-states/pokemon-down-2.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/pokemon-up-1.sav Binary file save-states/pokemon-up-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/pokemon-up-2.sav Binary file save-states/pokemon-up-2.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/save-down-1.sav Binary file save-states/save-down-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/save-up-1.sav Binary file save-states/save-up-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/start-down-1.sav Binary file save-states/start-down-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/start-down-2.sav Binary file save-states/start-down-2.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/start-down-3.sav Binary file save-states/start-down-3.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/start-up-1.sav Binary file save-states/start-up-1.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/start-up-2.sav Binary file save-states/start-up-2.sav has changed diff -r b477970d0b7a -r 998702f021e3 save-states/start-up-3.sav Binary file save-states/start-up-3.sav has changed