diff clojure/com/aurellem/assembly.clj @ 113:0831da75d2c5

completed frame-counting machine language program with dylan's help
author Robert McIntyre <rlm@mit.edu>
date Fri, 16 Mar 2012 00:43:28 -0500
parents 6fe33bb5ea22
children a454730d92dd
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/assembly.clj	Thu Mar 15 17:29:49 2012 -0500
     1.2 +++ b/clojure/com/aurellem/assembly.clj	Fri Mar 16 00:43:28 2012 -0500
     1.3 @@ -74,7 +74,7 @@
     1.4                     (binary-str (aget (memory state) mem))))
     1.5    state)
     1.6  
     1.7 -(defn read-buttons []
     1.8 +(defn read-down-button []
     1.9    (-> (tick (mid-game))
    1.10        (IE! 0) ; disable interrupts
    1.11        (inject-item-assembly
    1.12 @@ -82,7 +82,8 @@
    1.13          ;; write 00010000 to 0xFF00 to select joypad
    1.14          [0x18   ;D31D                    ; jump over          
    1.15           0x01   ;D31E                    ; the next 8 bits
    1.16 -         (Integer/parseInt "00100000" 2) ;D31F data section 
    1.17 +                ;D31F
    1.18 +         (Integer/parseInt "00100000" 2) ; data section 
    1.19           
    1.20           0xFA   ;D320                    ; load (D31F) into A
    1.21           0x1F   ;D321      -->       
    1.22 @@ -123,8 +124,120 @@
    1.23          
    1.24          []))))
    1.25  
    1.26 +
    1.27 +;; specs for main bootstrap program
    1.28 +;; starts in "mode-select" mode
    1.29 +;;   Each button press takes place in a single frame.
    1.30 +;;   mode-select-mode takes one of the main buttons
    1.31 +;;   which selects one of up to eight modes
    1.32 +;;   mode 1 activated by the "A" button
    1.33 +;;   the next two button presses indicates the start
    1.34 +;;   memory location which to which the bootstrap
    1.35 +;;   program will write.
    1.36 +;;   This is done by using each of the eight buttons to
    1.37 +;;   spell out an 8 bit number.  The order of buttons is
    1.38 +;;   ["A" "B" "start" "select" "up" "right" "down" "left"],
    1.39 +;;   [:a :start :l]  -->  10100001
    1.40 +
    1.41 +;;   the next button press determines how many bytes are to be
    1.42 +;;   written, starting at the start position.
    1.43 +
    1.44 +;;   then, the actual bytes are entered and are written to the
    1.45 +;;   start address in sequence.
    1.46 +
    1.47 +
    1.48 +(defn count-frames []
    1.49 +  (-> (tick (mid-game))
    1.50 +      (IE! 0) ; disable interrupts
    1.51 +      (inject-item-assembly
    1.52 +       ;; write 00010000 to 0xFF00 to select joypad
    1.53 +       [0x18   ;D31D                    ; jump over          
    1.54 +        0x02   ;D31E                    ; the next 2 bytes
    1.55 +        0x00   ;D31F                    ; frame-count
    1.56 +        0x00   ;D320                    ; v-blank-prev
    1.57 +        
    1.58 +        0xFA   ;D321
    1.59 +        0x41   ;D322                    ; load (FF41) into A
    1.60 +        0xFF   ;D323                    ; this contains mode flags
    1.61 +
    1.62 +
    1.63 +        
    1.64 +        ;; if we're in v-blank, the bit-1 is 0
    1.65 +        ;; and bit-2 is 1  Otherwise, it is not v-blank.
    1.66 +        0xCB   ;D324                     ; test bit-1 of A
    1.67 +        0x4F   ;D325                         
    1.68 +
    1.69 +        0xC2   ;D326                     ; if bit-1 is not 0
    1.70 +        0x43   ;D327                     ; GOTO not-v-blank
    1.71 +        0xD3   ;D328
    1.72 +        
    1.73 +        0xCB   ;D329                     ; test bit-0 of A 
    1.74 +        0x47   ;D32A
    1.75 +
    1.76 +        0xCA   ;D32B                     ; if bit-0 is not 1
    1.77 +        0x43   ;D32C                     ; GOTO not-v-blank
    1.78 +        0xD3   ;D32D
    1.79 +        
    1.80 +        ;; in v-blank mode
    1.81 +
    1.82 +           ;; if v-blank-prev was 0,
    1.83 +           ;; increment frame-count
    1.84 +
    1.85 +        0xFA   ;D32E                    ; load v-blank-prev to A
    1.86 +        0x20   ;D32F
    1.87 +        0xD3   ;D330
    1.88 +        
    1.89 +        0xCB   ;D331
    1.90 +        0x47   ;D332                    ; test bit-0 of A 
    1.91 +
    1.92 +        0x20   ;D333                    ; skip next section
    1.93 +        0x07   ;D334                    ; if v-blank-prev was not zero 
    1.94 +        
    1.95 +           ;; v-blank was 0, increment frame-count
    1.96 +        0xFA   ;D335                    ; load frame-count into A
    1.97 +        0x1F   ;D336
    1.98 +        0xD3   ;D337                   
    1.99 +
   1.100 +        0x3C   ;D338                    ; inc A
   1.101 +
   1.102 +        0xEA   ;D339                    ; load A into frame-count
   1.103 +        0x1F   ;D33A
   1.104 +        0xD3   ;D33B
   1.105 +
   1.106 +           ;; set v-blank? to 1
   1.107 +        0x3E   ;D33C                    ; load 1 into A
   1.108 +        0x01   ;D33D                    
   1.109 +
   1.110 +        0xEA   ;D33E                    ; load A into v-blank-prev
   1.111 +        0x20   ;D33F
   1.112 +        0xD3   ;D340
   1.113 +
   1.114 +        0x18   ;D341                    ; skip not-in-v-blank section
   1.115 +        0x05   ;D342
   1.116 +
   1.117 +        ;; not in v-blank mode
   1.118 +           ;; set b-blank? to 0
   1.119 +        0x3E   ;D343                    ; load 0 into A        
   1.120 +        0x00   ;D344
   1.121 +
   1.122 +        0xEA   ;D345                    ; load A into v-blank-prev
   1.123 +        0x20   ;D346
   1.124 +        0xD3   ;D347
   1.125 +        
   1.126 +
   1.127 +        0xC3   ;D348                   ; return to beginning
   1.128 +        0x1D   ;D349
   1.129 +        0xD3   ;D34A
   1.130 + 
   1.131 +        
   1.132 +        
   1.133 +        ])))
   1.134 +
   1.135 +
   1.136 +
   1.137 +
   1.138  (defn run-a-bit []
   1.139 -  (-> (read-buttons)
   1.140 +  (-> (read-down-button)
   1.141        (info)
   1.142        (tick)  ;; skip over data section
   1.143        (info)