diff clojure/com/aurellem/gb/rlm_assembly.clj @ 388:a0d0e1a46b1d

had to change programs to prevent repeats.
author Robert McIntyre <rlm@mit.edu>
date Thu, 12 Apr 2012 10:20:38 -0500
parents 47d44bb54d32
children bb8978d370d8
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/rlm_assembly.clj	Thu Apr 12 09:21:40 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj	Thu Apr 12 10:20:38 2012 -0500
     1.3 @@ -65,20 +65,12 @@
     1.4  
     1.5  (defn frame-metronome []
     1.6    (let [timing-loop
     1.7 -        [;;0x01 ; \
     1.8 -         ;;0x43 ;  |
     1.9 -         ;;0xFE ;  |  load 0xFF44 into BC without repeats
    1.10 -         ;;0x0C ;  |
    1.11 -         ;;0x04 ; /
    1.12 -         ;;0x0A ;; (BC) -> A, now A = LY (vertical line coord)
    1.13 -         
    1.14 -         0x11 ; \                                           
    1.15 -         0x43 ;  |                                           
    1.16 -         0xFE ;  |  load 0xFF44 into DE without repeats      
    1.17 -         0x1C ;  |                                           
    1.18 -         0x14 ; /                                           
    1.19 -         0x1A ;; (DE) -> A, now A = LY (vertical line coord)
    1.20 -         ]
    1.21 +        [0x01 ; \
    1.22 +         0x43 ;  |
    1.23 +         0xFE ;  |  load 0xFF44 into BC without repeats
    1.24 +         0x0C ;  |
    1.25 +         0x04 ; /
    1.26 +         0x0A] ;; (BC) -> A, now A = LY (vertical line coord)
    1.27          continue-if-144
    1.28          [0xFE
    1.29           144     ;; compare LY (in A) with 144
    1.30 @@ -86,8 +78,7 @@
    1.31           (->signed-8-bit
    1.32            (+ -4 (- (count timing-loop))))]
    1.33          spin-loop
    1.34 -        [;;0x05 ;; dec B, which is 0xFF
    1.35 -         0x15 ;; dec D, which is 0xFF
    1.36 +        [0x05 ;; dec B, which is 0xFF
    1.37           0x20 ;; spin until B==0
    1.38           0xFD]]
    1.39      (concat timing-loop continue-if-144 spin-loop)))
    1.40 @@ -96,55 +87,50 @@
    1.41    "Ensure that frame-metronome ticks exactly once every frame."
    1.42    ([] (test-frame-metronome 151))
    1.43    ([steps]
    1.44 -     (let [inc-B [0x04 0x18
    1.45 +     (let [inc-E [0x1C 0x18
    1.46                    (->signed-8-bit
    1.47                     (+ -3 (- (count (frame-metronome)))))]
    1.48 -           program (concat (frame-metronome) inc-B)
    1.49 +           program (concat (frame-metronome) inc-E)
    1.50             count-frames
    1.51             (-> (tick (mid-game))
    1.52                 (IE! 0)
    1.53 -               (BC! 0)
    1.54 +               (DE! 0)
    1.55                 (set-memory-range pokemon-list-start program)
    1.56                 (PC! pokemon-list-start))
    1.57 -           B-after-moves (B (run-moves count-frames (repeat steps [])))]
    1.58 -       (println "B:" B-after-moves) 
    1.59 -       (assert (= steps B-after-moves))
    1.60 +           E-after-moves (E (run-moves count-frames (repeat steps [])))]
    1.61 +       (println "E:" E-after-moves) 
    1.62 +       (assert (= steps E-after-moves))
    1.63  
    1.64 -       (println "B =" B-after-moves "after" steps "steps")
    1.65 +       (println "E =" E-after-moves "after" steps "steps")
    1.66         count-frames)))
    1.67  
    1.68  (defn read-user-input []
    1.69 -  [;;0x01 ;\
    1.70 -   ;;0x01 ; |
    1.71 -   ;;0xFE ; |  load 0xFF00 into BC without repeats
    1.72 -   ;;0x04 ; |
    1.73 -   ;;0x0D ;/
    1.74 +  [0x3E
    1.75 +   0x20 ; prepare to measure d-pad
    1.76  
    1.77 -   0x11 ; \                                           
    1.78 -   0x01 ;  |                                           
    1.79 -   0xFE ;  |  load 0xFF44 into DE without repeats      
    1.80 -   0x14 ;  |                                           
    1.81 -   0x1D ; /                                           
    1.82 +   0x01 ;\
    1.83 +   0x01 ; |
    1.84 +   0xFE ; |  load 0xFF00 into BC without repeats
    1.85 +   0x04 ; |
    1.86 +   0x0D ;/
    1.87     
    1.88 -   0x3E
    1.89 -   (Integer/parseInt "00100000" 2) ; prepare to measure d-pad
    1.90 -
    1.91 -   0x12 
    1.92 -   0x1A ;; get D-pad info
    1.93 +   0x02 
    1.94 +   0x0A ;; get D-pad info
    1.95     
    1.96     0xF5 ;; push AF
    1.97        
    1.98     0x3E
    1.99 -   (Integer/parseInt "00010000" 2) ; prepare to measure buttons
   1.100 +   0x10 ; prepare to measure buttons
   1.101 +
   1.102 +   0x3F ;; clear carry flag no-op to prevent repeated nybbbles
   1.103     
   1.104 -   0x12
   1.105 -   0x1A ;; get button info
   1.106 -
   1.107 +   0x02
   1.108 +   0x0A ;; get button info
   1.109     
   1.110     0xE6 ;; select bottom bits of A
   1.111     0x0F
   1.112  
   1.113 -   0x57 ;; A->D
   1.114 +   0x47 ;; A->B
   1.115  
   1.116     0xF1 ;; pop AF
   1.117  
   1.118 @@ -154,8 +140,7 @@
   1.119     0xCB
   1.120     0x37 ;; swap A nybbles
   1.121  
   1.122 -   0x5A ;; D->E            \ necessary to 
   1.123 -   0xB3 ;; (or A D) -> A   / prevent repeats.
   1.124 +   0xB0 ;; (or A B) -> A
   1.125   
   1.126     0x2F ;; (NOT A) -> A
   1.127     ])
   1.128 @@ -164,7 +149,7 @@
   1.129    (let [program
   1.130          (concat
   1.131           (frame-metronome) (read-user-input)
   1.132 -         [0x47 ;; A->B
   1.133 +         [0x5F ;; A-> E
   1.134            0x18
   1.135            (->signed-8-bit
   1.136             (+ (- (count (frame-metronome)))
   1.137 @@ -177,7 +162,7 @@
   1.138              (PC! pokemon-list-start))]
   1.139      (dorun
   1.140        (for [i (range 0x100)]
   1.141 -        (assert (= (B (step read-input (buttons i))) i))))
   1.142 +        (assert (= (E (step read-input (buttons i))) i))))
   1.143       (println "Tested all inputs.")
   1.144      read-input))
   1.145  
   1.146 @@ -193,12 +178,6 @@
   1.147  (def input-write-num-mode  (Integer/parseInt "00001000" 2))
   1.148  (def do-write-mode         (Integer/parseInt "00010000" 2))
   1.149  
   1.150 -
   1.151 -
   1.152 -
   1.153 -
   1.154 -
   1.155 -
   1.156  (defn main-bootstrap-program [start-address]
   1.157    (let [[start-high start-low] (disect-bytes-2 start-address)
   1.158          jump-distance (+ (count (frame-metronome)
   1.159 @@ -206,59 +185,51 @@
   1.160  
   1.161          init
   1.162          [0xAF 0x4F] ;; 0->A; 0->C;
   1.163 +
   1.164 +
   1.165          
   1.166          ;; HL = here
   1.167          ;; add C to HL
   1.168          ;; jp HL
   1.169          
   1.170          prepare-HL
   1.171 -        [0x21] ;; load HL from literal nn
   1.172 -               ;; nn == here defined below
   1.173 +        [0xD1 ;; pop DE causes D and E to be non-volitale
   1.174 +
   1.175 +         0x21           ;; load HL from literal nn
   1.176 +         :dispatch-high 
   1.177 +         :dispatch-low]
   1.178           
   1.179          mode-dispatch
   1.180 -        [0x06  ;\
   1.181 +        [0xC5 ;; push BC
   1.182 +         0x06  ;\
   1.183           0x01  ; | 0->B without repeats
   1.184           0x05  ;/
   1.185           0x09  ;; add BC to HL
   1.186 +         0xC1 ;; pop BC
   1.187           0xE9] ;; jp
   1.188 +        
   1.189 +        mode-select
   1.190 +        [0x4F  ;; A->C  (this is the address of dispatch above)
   1.191 +         0x18  ;; return
   1.192 +         :jump-to-end]
   1.193  
   1.194 -        here
   1.195 -        (disect-bytes-2 (+ 2 start-address (count init)
   1.196 -                           jump-distance prepare-HL
   1.197 -                           (count mode-dispatch)))
   1.198 -        
   1.199 +        input-bytes-to-write
   1.200 +        [0x47  ;; A->B
   1.201 +         0x18  ;; return
   1.202 +         :jump-to-end]
   1.203  
   1.204 -
   1.205 -        ;;(here) jr end
   1.206 -        
   1.207 -        ;;stuff
   1.208 -        ;;modify E
   1.209 -        ;;jr metronome
   1.210 -        
   1.211 -        ;;stuff
   1.212 -        ;;jr metronome
   1.213 -                        
   1.214 -        input-number
   1.215 -
   1.216 -         [0x47  ;; A->B
   1.217 -          0x1E  ;;
   1.218 -          input-high-write-jump
   1.219 -          0x18
   1.220 -          (jump-distance ??)]
   1.221          
   1.222  
   1.223          
   1.224 -        input-high-write
   1.225 -        [0x
   1.226 +        
   1.227 +         cleanup
   1.228 +         [0xD5 ;; push DE
   1.229 +          0x18
   1.230 +          0x??];; jump all the way back to frame-metronome
   1.231  
   1.232 -        
   1.233 -        
   1.234 -        
   1.235 -        
   1.236  
   1.237 -
   1.238 -         (concat init (frame-metronome) (read-user-input)
   1.239 -                 prepare-HL here mode-dispatch)
   1.240 +;;          (concat init (frame-metronome) (read-user-input)
   1.241 +;;                  prepare-HL here mode-dispatch)
   1.242                   
   1.243          
   1.244          
   1.245 @@ -267,7 +238,7 @@
   1.246           
   1.247  
   1.248      
   1.249 -    ))
   1.250 +;;     ))
   1.251  
   1.252          
   1.253       
   1.254 @@ -276,7 +247,7 @@
   1.255  
   1.256          
   1.257      
   1.258 -
   1.259 +(comment
   1.260  
   1.261  ;;;;;; TESTS ;;;;;;
   1.262  
   1.263 @@ -334,3 +305,4 @@
   1.264      (println program-counters)
   1.265      (assert (contains? (set program-counters) target-address))
   1.266      post-jump))
   1.267 +)
   1.268 \ No newline at end of file