changeset 110:f9dee79b2215

changed display for memory and registers to binary
author Robert McIntyre <rlm@mit.edu>
date Thu, 15 Mar 2012 14:44:19 -0500
parents c8b48102b17c
children 8be7ce890184
files clojure/com/aurellem/assembly.clj
diffstat 1 files changed, 47 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/assembly.clj	Thu Mar 15 14:32:10 2012 -0500
     1.2 +++ b/clojure/com/aurellem/assembly.clj	Thu Mar 15 14:44:19 2012 -0500
     1.3 @@ -64,58 +64,63 @@
     1.4  
     1.5  (def buttons-port 0xFF00)
     1.6  
     1.7 -(defn view-register [state name reg-fn]
     1.8 -  (println (format "%s : 0x%02X" name (reg-fn state)))
     1.9 -  state)
    1.10  
    1.11  (defn A [state]
    1.12    (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8))
    1.13  
    1.14 +(defn binary-str [num]
    1.15 +  (format "%08d"
    1.16 +          (Integer/parseInt
    1.17 +           (Integer/toBinaryString num) 10)))
    1.18 +
    1.19 +(defn view-register [state name reg-fn]
    1.20 +  (println (format "%s: %s" name
    1.21 +                   (binary-str (reg-fn state))))
    1.22 +  state)
    1.23 +
    1.24 +
    1.25  (defn view-memory [state mem]
    1.26 -  (println (format "mem 0x%04X = 0x%02X" mem (aget (memory state) mem)))
    1.27 +  (println (format "mem 0x%04X = %s" mem
    1.28 +                   (binary-str (aget (memory state) mem))))
    1.29    state)
    1.30  
    1.31  (defn read-buttons []
    1.32 -  (let [button-pressed (tick (step (mid-game) [:d]))]
    1.33 -    (-> button-pressed
    1.34 -        (IE! 0) ; disable interrupts
    1.35 -        (inject-item-assembly
    1.36 -         (concat
    1.37 -          ;; write 00010000 to 0xFF00 to select joypad
    1.38 -          [0x18   ;D31D                 ; jump over          
    1.39 -           0x01   ;D31E                 ; the next 8 bits
    1.40 -           (Integer/parseInt "00010000" 2) ;D31F data section 
    1.41 -           0x00   ;D320                 ; take a break
    1.42 -           0xFA   ;D321                 ; put DC15 into A
    1.43 -           0x1F   ;D322      --]       
    1.44 -           0xD3   ;D323      --]  DC1F  ; data section
    1.45 -           0x01   ;D324                 ; load 0xFF00 into BC
    1.46 -           0x00   ;D325
    1.47 -           0xFF   ;D326
    1.48 -           0x02   ;D327    (BC)->A      ; load (00010000) into FF00
    1.49 -                                        ; to select directional
    1.50 -                                        ; buttons
    1.51 +  
    1.52 +  (-> (tick (mid-game))
    1.53 +      (IE! 0) ; disable interrupts
    1.54 +      (inject-item-assembly
    1.55 +       (concat
    1.56 +        ;; write 00010000 to 0xFF00 to select joypad
    1.57 +        [0x18   ;D31D                    ; jump over          
    1.58 +         0x01   ;D31E                    ; the next 8 bits
    1.59 +         (Integer/parseInt "00010000" 2) ;D31F data section 
    1.60 +         0x00   ;D320                    ; take a break
    1.61  
    1.62 -           ]
    1.63 +         0xFA   ;D321                    ; put DC1F into A
    1.64 +         0x1F   ;D322      -->       
    1.65 +         0xD3   ;D323      -->  D31F     
    1.66  
    1.67 -          []))
    1.68 -        (info)
    1.69 -        (tick)  ;; skip over data section
    1.70 -        (info)  
    1.71 -        (tick)  ;; no-op
    1.72 -        (info)
    1.73 -        (view-register "Register A" A)
    1.74 -        (tick)  ;; load-data into A
    1.75 -        (view-register "Register A" A)
    1.76 -        (info)
    1.77 -        (view-register "Register BC" BC)
    1.78 -        (tick) ;;  store 0xFFOO into BC
    1.79 -        (view-register "Register BC" BC)
    1.80 -        (info)
    1.81 -        (view-memory 0xFF00)
    1.82 -        (tick) ;; load A into 0xFF00
    1.83 -        (view-memory 0xFF00)
    1.84 -        )))
    1.85 +         0xEA   ;D324                    ; load (A), which is 
    1.86 +         0x00   ;D325      -->           ; 00010000, into FF00
    1.87 +         0xFF   ;D326      -->  FF00     
    1.88 +
    1.89 +         0x00
    1.90 +         ]
    1.91 +        
    1.92 +        []))
    1.93 +      (info)
    1.94 +      (tick)  ;; skip over data section
    1.95 +      (info)  
    1.96 +      (tick)  ;; no-op
    1.97 +      (info)
    1.98 +      (view-register "Register A" A)
    1.99 +      (tick)  ;; load-data into A
   1.100 +      (view-register "Register A" A)
   1.101 +      (info)
   1.102 +      (view-memory 0xFF00)
   1.103 +      (tick) ;; load A into 0xFF00
   1.104 +      (view-memory 0xFF00)
   1.105 +      ))
   1.106            
   1.107           
   1.108  (defn trace [state]