# HG changeset patch # User Robert McIntyre # Date 1331840659 18000 # Node ID f9dee79b221532b00b6db0482b75e21239b51bba # Parent c8b48102b17ca4ffb7c37e4934b12b92dd514c05 changed display for memory and registers to binary diff -r c8b48102b17c -r f9dee79b2215 clojure/com/aurellem/assembly.clj --- a/clojure/com/aurellem/assembly.clj Thu Mar 15 14:32:10 2012 -0500 +++ b/clojure/com/aurellem/assembly.clj Thu Mar 15 14:44:19 2012 -0500 @@ -64,58 +64,63 @@ (def buttons-port 0xFF00) -(defn view-register [state name reg-fn] - (println (format "%s : 0x%02X" name (reg-fn state))) - state) (defn A [state] (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8)) +(defn binary-str [num] + (format "%08d" + (Integer/parseInt + (Integer/toBinaryString num) 10))) + +(defn view-register [state name reg-fn] + (println (format "%s: %s" name + (binary-str (reg-fn state)))) + state) + + (defn view-memory [state mem] - (println (format "mem 0x%04X = 0x%02X" mem (aget (memory state) mem))) + (println (format "mem 0x%04X = %s" mem + (binary-str (aget (memory state) mem)))) state) (defn read-buttons [] - (let [button-pressed (tick (step (mid-game) [:d]))] - (-> button-pressed - (IE! 0) ; disable interrupts - (inject-item-assembly - (concat - ;; write 00010000 to 0xFF00 to select joypad - [0x18 ;D31D ; jump over - 0x01 ;D31E ; the next 8 bits - (Integer/parseInt "00010000" 2) ;D31F data section - 0x00 ;D320 ; take a break - 0xFA ;D321 ; put DC15 into A - 0x1F ;D322 --] - 0xD3 ;D323 --] DC1F ; data section - 0x01 ;D324 ; load 0xFF00 into BC - 0x00 ;D325 - 0xFF ;D326 - 0x02 ;D327 (BC)->A ; load (00010000) into FF00 - ; to select directional - ; buttons + + (-> (tick (mid-game)) + (IE! 0) ; disable interrupts + (inject-item-assembly + (concat + ;; write 00010000 to 0xFF00 to select joypad + [0x18 ;D31D ; jump over + 0x01 ;D31E ; the next 8 bits + (Integer/parseInt "00010000" 2) ;D31F data section + 0x00 ;D320 ; take a break - ] + 0xFA ;D321 ; put DC1F into A + 0x1F ;D322 --> + 0xD3 ;D323 --> D31F - [])) - (info) - (tick) ;; skip over data section - (info) - (tick) ;; no-op - (info) - (view-register "Register A" A) - (tick) ;; load-data into A - (view-register "Register A" A) - (info) - (view-register "Register BC" BC) - (tick) ;; store 0xFFOO into BC - (view-register "Register BC" BC) - (info) - (view-memory 0xFF00) - (tick) ;; load A into 0xFF00 - (view-memory 0xFF00) - ))) + 0xEA ;D324 ; load (A), which is + 0x00 ;D325 --> ; 00010000, into FF00 + 0xFF ;D326 --> FF00 + + 0x00 + ] + + [])) + (info) + (tick) ;; skip over data section + (info) + (tick) ;; no-op + (info) + (view-register "Register A" A) + (tick) ;; load-data into A + (view-register "Register A" A) + (info) + (view-memory 0xFF00) + (tick) ;; load A into 0xFF00 + (view-memory 0xFF00) + )) (defn trace [state]