changeset 385:3f3cfc89be91

working on mode-dispatch
author Robert McIntyre <rlm@mit.edu>
date Thu, 12 Apr 2012 06:20:17 -0500
parents 8013915a07b3
children d8cbbf2a3133
files clojure/com/aurellem/gb/rlm_assembly.clj
diffstat 1 files changed, 122 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/rlm_assembly.clj	Wed Apr 11 14:04:21 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj	Thu Apr 12 06:20:17 2012 -0500
     1.3 @@ -116,25 +116,31 @@
     1.4  
     1.5     0x02 
     1.6     0x0A ;; get D-pad info
     1.7 +   
     1.8 +   0xF5 ;; push AF
     1.9 +      
    1.10 +   0x3E
    1.11 +   (Integer/parseInt "00010000" 2) ; prepare to measure buttons
    1.12 +   
    1.13 +   0x02
    1.14 +   0x0A ;; get button info
    1.15  
    1.16 +   
    1.17     0xE6 ;; select bottom bits of A
    1.18     0x0F
    1.19  
    1.20 +   0x47 ;; A->B
    1.21 +
    1.22 +   0xF1 ;; pop AF
    1.23 +
    1.24 +   0xE6
    1.25 +   0x0F ;; select bottom bits of A
    1.26 +
    1.27     0xCB
    1.28     0x37 ;; swap A nybbles
    1.29     
    1.30 -   0x57 ;; A->D
    1.31 -
    1.32 -   0x3E
    1.33 -   (Integer/parseInt "00010000" 2) ; prepare to measure buttons
    1.34 -
    1.35 -   0x02
    1.36 -   0x0A ;; get button info
    1.37 +   0xB0 ;; (AND A B) -> A
    1.38     
    1.39 -   0xE6
    1.40 -   0x0F ;; select bottom bits of A
    1.41 -
    1.42 -   0xB2 ;; combine together into A
    1.43     0x2F ;; (NOT A) -> A
    1.44     ])
    1.45  
    1.46 @@ -154,16 +160,116 @@
    1.47              (set-memory-range pokemon-list-start program)
    1.48              (PC! pokemon-list-start))]
    1.49      (dorun
    1.50 -     (for [i (range 0x100)]
    1.51 -       (assert (= (E (step read-input (buttons i))) i))))
    1.52 -    (println "Tested all inputs.")
    1.53 +      (for [i (range 0x100)]
    1.54 +        (assert (= (E (step read-input (buttons i))) i))))
    1.55 +     (println "Tested all inputs.")
    1.56      read-input))
    1.57  
    1.58 -        
    1.59 +(def mode-select-mode      (Integer/parseInt "00000000" 2))
    1.60 +(def write-mode            (Integer/parseInt "00000001" 2))
    1.61 +(def jump-mode             (Integer/parseInt "10000000" 2))
    1.62 +
    1.63 +(def input-high-addr-jump  (Integer/parseInt "10000010" 2))
    1.64 +(def input-high-addr-write (Integer/parseInt "00000010" 2))
    1.65 +(def input-low-addr-jump   (Integer/parseInt "10000100" 2))
    1.66 +(def input-low-addr-write  (Integer/parseInt "00000100" 2))
    1.67 +
    1.68 +(def input-write-num-mode  (Integer/parseInt "00001000" 2))
    1.69 +(def do-write-mode         (Integer/parseInt "00010000" 2))
    1.70 +
    1.71 +
    1.72 +
    1.73 +
    1.74 +
    1.75 +
    1.76  
    1.77  (defn main-bootstrap-program [start-address]
    1.78    (let [[start-high start-low] (disect-bytes-2 start-address)
    1.79 -        ]
    1.80 +        jump-distance (+ (count (frame-metronome)
    1.81 +                                (read-user-input)))
    1.82 +
    1.83 +        init
    1.84 +        [0x1E 0xFF 0x1C] ;; 0-> E without repeats
    1.85 +
    1.86 +        
    1.87 +        ;; HL -> BC
    1.88 +        ;; HL = here
    1.89 +        ;; add E to HL
    1.90 +        ;; jp HL
    1.91 +        
    1.92 +        mode-dispatch
    1.93 +        [0x44
    1.94 +
    1.95 +
    1.96 +
    1.97 +        ;;(here) jr metronome
    1.98 +        
    1.99 +        ;;stuff
   1.100 +        ;;modify E
   1.101 +        ;;jr metronome
   1.102 +        
   1.103 +        ;;stuff
   1.104 +        ;;jr metronome
   1.105 +
   1.106 +        
   1.107 +        
   1.108 +        
   1.109 +        
   1.110 +        
   1.111 +        
   1.112 +        mode-dispatch
   1.113 +        [0xCB
   1.114 +         0x43  ;; test bit 0
   1.115 +
   1.116 +         0xCB
   1.117 +         0x4B  ;; test bit 1
   1.118 +         
   1.119 +         0xCB
   1.120 +         0x53  ;; test bit 2
   1.121 +
   1.122 +         0xCB
   1.123 +         0x5B  ;; test bit 3
   1.124 +
   1.125 +         0xCB
   1.126 +         0x63  ;; test bit 4
   1.127 +
   1.128 +         0xCB
   1.129 +         0x6B  ;; test bit 5
   1.130 +
   1.131 +         ];;default
   1.132 +         
   1.133 +
   1.134 +        mode-select
   1.135 +        [0x5F]  ;; A->E
   1.136 +
   1.137 +        ;; delayed inputs
   1.138 +        input-high 0x67  ;; A->H
   1.139 +        input-low  0x6F  ;; A->L
   1.140 +        input-num  0x57  ;; A->D
   1.141 +
   1.142 +        ;; final-actions
   1.143 +        jump       0xE9  ;; jp (HL)
   1.144 +        write      0x22  ;; A->(HL); inc HL
   1.145 +        input-mode 0x00  ;; no-op
   1.146 +          
   1.147 +
   1.148 +
   1.149 +         input-high
   1.150 +         [0x67   ;; A->H
   1.151 +          0x1E   ;; change mode
   1.152 +          input-low-mode]
   1.153 +        
   1.154 +        
   1.155 +
   1.156 +
   1.157 +        mode-dispatch
   1.158 +        
   1.159 +        
   1.160 +
   1.161 +         
   1.162 +         
   1.163 +
   1.164 +    
   1.165      ))
   1.166  
   1.167