changeset 111:8be7ce890184

now I have an assembly program that can read button presses!
author Robert McIntyre <rlm@mit.edu>
date Thu, 15 Mar 2012 17:20:55 -0500
parents f9dee79b2215
children 6fe33bb5ea22
files clojure/com/aurellem/assembly.clj
diffstat 1 files changed, 61 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/assembly.clj	Thu Mar 15 14:44:19 2012 -0500
     1.2 +++ b/clojure/com/aurellem/assembly.clj	Thu Mar 15 17:20:55 2012 -0500
     1.3 @@ -85,7 +85,6 @@
     1.4    state)
     1.5  
     1.6  (defn read-buttons []
     1.7 -  
     1.8    (-> (tick (mid-game))
     1.9        (IE! 0) ; disable interrupts
    1.10        (inject-item-assembly
    1.11 @@ -93,26 +92,53 @@
    1.12          ;; write 00010000 to 0xFF00 to select joypad
    1.13          [0x18   ;D31D                    ; jump over          
    1.14           0x01   ;D31E                    ; the next 8 bits
    1.15 -         (Integer/parseInt "00010000" 2) ;D31F data section 
    1.16 -         0x00   ;D320                    ; take a break
    1.17 +         (Integer/parseInt "00100000" 2) ;D31F data section 
    1.18 +         
    1.19 +         0xFA   ;D320                    ; load (D31F) into A
    1.20 +         0x1F   ;D321      -->       
    1.21 +         0xD3   ;D322      -->  D31F     
    1.22  
    1.23 -         0xFA   ;D321                    ; put DC1F into A
    1.24 -         0x1F   ;D322      -->       
    1.25 -         0xD3   ;D323      -->  D31F     
    1.26 +         0xEA   ;D323                    ; load (A), which is 
    1.27 +         0x00   ;D324      -->           ; 00010000, into FF00
    1.28 +         0xFF   ;D325      -->  FF00     
    1.29 +         
    1.30 +         0x18   ;D326                    ; this is the place where
    1.31 +         0x01   ;D327                    ; we will store whether
    1.32 +         0x00   ;D328                    ; "down" is pressed.
    1.33  
    1.34 -         0xEA   ;D324                    ; load (A), which is 
    1.35 -         0x00   ;D325      -->           ; 00010000, into FF00
    1.36 -         0xFF   ;D326      -->  FF00     
    1.37 +         0xFA   ;D329                    ; (FF00) -> A
    1.38 +         0x00   ;D32A                   
    1.39 +         0xFF   ;D32B
    1.40  
    1.41 -         0x00
    1.42 +         0xCB   ;D32C                    ; Test whether "down"
    1.43 +         0x5F   ;D32D                    ; is pressed.
    1.44 +
    1.45 +         0x28   ;D32E                    ; if down is pressed,
    1.46 +         0x03   ;D32F                    ; skip the next section 
    1.47 +                                         ; of code.
    1.48 +         ;; down-is-not-pressed
    1.49 +         0xC3   ;D330
    1.50 +         0x1D   ;D331                    ; return to beginning
    1.51 +         0xD3   ;D332
    1.52 +         
    1.53 +         ;; down-is-pressed 
    1.54 +         0xEA   ;D334                    ; write A to D328 if 
    1.55 +         0x28   ;D335                    ; "down" was pressed
    1.56 +         0xD3   ;D336
    1.57 +
    1.58 +         0xC3   ;D330
    1.59 +         0x1D   ;D331                    ; return to beginning
    1.60 +         0xD3   ;D332
    1.61           ]
    1.62          
    1.63 -        []))
    1.64 +        []))))
    1.65 +
    1.66 +
    1.67 +(defn run-a-bit []
    1.68 +  (-> (read-buttons)
    1.69        (info)
    1.70        (tick)  ;; skip over data section
    1.71        (info)  
    1.72 -      (tick)  ;; no-op
    1.73 -      (info)
    1.74        (view-register "Register A" A)
    1.75        (tick)  ;; load-data into A
    1.76        (view-register "Register A" A)
    1.77 @@ -120,9 +146,28 @@
    1.78        (view-memory 0xFF00)
    1.79        (tick) ;; load A into 0xFF00
    1.80        (view-memory 0xFF00)
    1.81 -      ))
    1.82 -          
    1.83 -         
    1.84 +      (info)
    1.85 +      (tick)
    1.86 +      (info)
    1.87 +      (tick)
    1.88 +      (info)
    1.89 +      (tick)
    1.90 +      (info)
    1.91 +      (tick)
    1.92 +      (info)
    1.93 +      (tick)
    1.94 +      (info)
    1.95 +      (tick)
    1.96 +      (print-inventory)))
    1.97 +
    1.98 +
    1.99 +(comment
   1.100 +  (view-memory (step (step (read-buttons) [:d])) 0xD328)
   1.101 +  ;;mem 0xD328 = 11100111
   1.102 +  (view-memory (step (step (read-buttons))) 0xD328)
   1.103 +  ;;mem 0xD328 = 00000000
   1.104 +  )
   1.105 +  
   1.106  (defn trace [state]
   1.107    (loop [program-counters []
   1.108           opcodes []]