# HG changeset patch # User Robert McIntyre # Date 1334229617 18000 # Node ID 3f3cfc89be914bbfe390a5f5c8cda79542c7b5ea # Parent 8013915a07b30c5945b2934ed201694f0cfb6838 working on mode-dispatch diff -r 8013915a07b3 -r 3f3cfc89be91 clojure/com/aurellem/gb/rlm_assembly.clj --- a/clojure/com/aurellem/gb/rlm_assembly.clj Wed Apr 11 14:04:21 2012 -0500 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj Thu Apr 12 06:20:17 2012 -0500 @@ -116,25 +116,31 @@ 0x02 0x0A ;; get D-pad info + + 0xF5 ;; push AF + + 0x3E + (Integer/parseInt "00010000" 2) ; prepare to measure buttons + + 0x02 + 0x0A ;; get button info + 0xE6 ;; select bottom bits of A 0x0F + 0x47 ;; A->B + + 0xF1 ;; pop AF + + 0xE6 + 0x0F ;; select bottom bits of A + 0xCB 0x37 ;; swap A nybbles - 0x57 ;; A->D - - 0x3E - (Integer/parseInt "00010000" 2) ; prepare to measure buttons - - 0x02 - 0x0A ;; get button info + 0xB0 ;; (AND A B) -> A - 0xE6 - 0x0F ;; select bottom bits of A - - 0xB2 ;; combine together into A 0x2F ;; (NOT A) -> A ]) @@ -154,16 +160,116 @@ (set-memory-range pokemon-list-start program) (PC! pokemon-list-start))] (dorun - (for [i (range 0x100)] - (assert (= (E (step read-input (buttons i))) i)))) - (println "Tested all inputs.") + (for [i (range 0x100)] + (assert (= (E (step read-input (buttons i))) i)))) + (println "Tested all inputs.") read-input)) - +(def mode-select-mode (Integer/parseInt "00000000" 2)) +(def write-mode (Integer/parseInt "00000001" 2)) +(def jump-mode (Integer/parseInt "10000000" 2)) + +(def input-high-addr-jump (Integer/parseInt "10000010" 2)) +(def input-high-addr-write (Integer/parseInt "00000010" 2)) +(def input-low-addr-jump (Integer/parseInt "10000100" 2)) +(def input-low-addr-write (Integer/parseInt "00000100" 2)) + +(def input-write-num-mode (Integer/parseInt "00001000" 2)) +(def do-write-mode (Integer/parseInt "00010000" 2)) + + + + + + (defn main-bootstrap-program [start-address] (let [[start-high start-low] (disect-bytes-2 start-address) - ] + jump-distance (+ (count (frame-metronome) + (read-user-input))) + + init + [0x1E 0xFF 0x1C] ;; 0-> E without repeats + + + ;; HL -> BC + ;; HL = here + ;; add E to HL + ;; jp HL + + mode-dispatch + [0x44 + + + + ;;(here) jr metronome + + ;;stuff + ;;modify E + ;;jr metronome + + ;;stuff + ;;jr metronome + + + + + + + + mode-dispatch + [0xCB + 0x43 ;; test bit 0 + + 0xCB + 0x4B ;; test bit 1 + + 0xCB + 0x53 ;; test bit 2 + + 0xCB + 0x5B ;; test bit 3 + + 0xCB + 0x63 ;; test bit 4 + + 0xCB + 0x6B ;; test bit 5 + + ];;default + + + mode-select + [0x5F] ;; A->E + + ;; delayed inputs + input-high 0x67 ;; A->H + input-low 0x6F ;; A->L + input-num 0x57 ;; A->D + + ;; final-actions + jump 0xE9 ;; jp (HL) + write 0x22 ;; A->(HL); inc HL + input-mode 0x00 ;; no-op + + + + input-high + [0x67 ;; A->H + 0x1E ;; change mode + input-low-mode] + + + + + mode-dispatch + + + + + + + ))