# HG changeset patch # User Robert McIntyre # Date 1333891675 18000 # Node ID 652c5abee8923800ccd015c500e4059f400bd339 # Parent 4e0b64ea7b66da22ea43def2b8f2d3efa1a75134 constructing exact item-pc layout for item-writer. diff -r 4e0b64ea7b66 -r 652c5abee892 clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Sun Apr 08 06:11:29 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Sun Apr 08 08:27:55 2012 -0500 @@ -1030,7 +1030,6 @@ (inc pc-item-list-start) (item-writer 0xD162 201 0xD162)))) - (defn item-writer-state [] (read-state "item-writer")) @@ -1038,9 +1037,158 @@ (let [orig (item-writer-state)] (-> orig (print-listing 0xD162 (+ 0xD162 20)) - (run-moves (reduce - concat [[:a] [:b]] - (repeat 5 [[:a :b :start :select] []]))) + (run-moves (reduce concat + (repeat 10 [[:a :b :start :select] []]))) ((fn [_] (println "===========") _)) (print-listing 0xD162 (+ 0xD162 20))))) - \ No newline at end of file + +(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 + + 0x2F ;; (item-hack) cpl A + 0x2F ;; (item-hack) cpl A --together a spacer 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 + + 0x00 + 0x21 + + 0x3A + 0xD5 + + ;; 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 4e0b64ea7b66 -r 652c5abee892 save-states/pc-item-writer.sav Binary file save-states/pc-item-writer.sav has changed