# HG changeset patch # User Robert McIntyre # Date 1333819872 18000 # Node ID 92f0011925d2e07ed58d7b18b5e1fc5715608c53 # Parent 2dd40f6b6a1f6bfb4c1e8e4baeb71801fd253dc7 created 40-byte program to bootstrap main bootstrap program diff -r 2dd40f6b6a1f -r 92f0011925d2 clojure/com/aurellem/gb/util.clj --- a/clojure/com/aurellem/gb/util.clj Sat Apr 07 07:43:17 2012 -0500 +++ b/clojure/com/aurellem/gb/util.clj Sat Apr 07 12:31:12 2012 -0500 @@ -223,11 +223,8 @@ (File. user-home "proj/vba-clojure/clojure/com/aurellem/exp/cartography")) - - (defn print-D-memory ([^SaveState state] - (let [descriptions (clojure.string/split-lines (slurp cartography))] diff -r 2dd40f6b6a1f -r 92f0011925d2 clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Sat Apr 07 07:43:17 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Sat Apr 07 12:31:12 2012 -0500 @@ -750,3 +750,128 @@ 0x04 ;; target ID (pokeball) 0x3E ;; target Quantity (lemonade) ]])))) + + + + + +(defn basic-writer [target-address limit return-address] + (let [[target-high target-low] (disect-bytes-2 target-address) + [return-high return-low] (disect-bytes-2 return-address)] + (flatten + [0xF3 ;; disable interrupts + ;;0xC5 ;; push junk onto stack + ;;0xD5 + ;;0xE5 + ;;0xF5 + + 0x1E ;; load limit into E + limit + + 0x21 ;; load target into HL + target-low + target-high + + ;; load 1 into C. + 0x0E ;; C == 1 means input-first nybble + 0x01 ;; C == 0 means input-second nybble + + + ;; Input Section + + 0x3E ;; load 0x20 into A, to measure dpad + 0x20 + + 0xE0 ;; load A into [FF00] + 0x00 + + 0xF0 ;; load 0xFF00 into A to get + 0x00 ;; d-pad presses + + 0xE6 + 0x0F ;; select bottom four bits of A + + 0xB8 ;; see if input is different (CP A B) + + 0x28 ;; repeat above steps if input is not different + ;; (jump relative backwards if B != A) + 0xF5 ;; (literal -11) + + 0x47 ;; load A into B + + 0x0D ;; dec C + ;; branch based on C: + 0x20 ;; JR NZ + 0x07 ;; skip "input first nybble" below + + + ;; input first nybble + + 0xCB + 0x37 ;; swap nybbles on A + + 0x57 ;; A -> D + + 0x18 + 0xEC ;; literal -20 -- go back to input section + + ;; input second nybble + + 0x0C ;; inc C + + 0xE6 ;; select bottom bits + 0x0F + + 0xB2 ;; (OR A D) -> A + + 0x22 ;; (do (A -> (HL)) (INC HL)) + + 0x1D ;; (DEC E) + + 0x20 ;; jump back to input section if not done + 0xE4 ;; literal -28 + + ;; cleanup + ;;0xF1 + ;;0xE1 + ;;0xD1 + ;;0xC1 + + 0xFB ;; re-enable interrupts + + 0xC3 + return-low + return-high ]))) + + +(defn test-basic-writer [] + (-> (read-state "bootstrap-init") + (set-memory pc-item-list-start 50) + (set-memory-range + map-function-address-start + (reverse (disect-bytes-2 (inc pc-item-list-start)))) + (set-memory-range + (inc pc-item-list-start) + (basic-writer 0xD162 10 0x5F0C)))) + +(defn debug-basic-writer [] + (PC! (test-basic-writer) (inc pc-item-list-start))) + +(defn d-ticks [state n] + (reduce (fn [state _] (d-tick state)) + state (range n))) + +(defn d-print [state message] + (println message) state) + +(defn dddd + [] + (-> (debug-basic-writer) + (d-ticks 20) + (set-memory 0xFF00 0xFF) + (d-print "============== second cycle") + (d-ticks 14) + (d-print "============== end") + (d-ticks 20))) + + \ No newline at end of file