changeset 393:b21d28e6c966

saving progress.
author Robert McIntyre <rlm@mit.edu>
date Thu, 12 Apr 2012 01:25:28 -0500
parents 309614263aa9
children 5c0e12f0a833
files clojure/com/aurellem/gb/rlm_assembly.clj
diffstat 1 files changed, 28 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/rlm_assembly.clj	Thu Apr 12 00:52:19 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj	Thu Apr 12 01:25:28 2012 -0500
     1.3 @@ -176,17 +176,12 @@
     1.4       (println "Tested all inputs.")
     1.5      read-input))
     1.6  
     1.7 -(def mode-select-mode      (Integer/parseInt "00000000" 2))
     1.8 -(def write-mode            (Integer/parseInt "00000001" 2))
     1.9 -(def jump-mode             (Integer/parseInt "10000000" 2))
    1.10 +(def symbol-index
    1.11 +  (fn [symbol sequence]
    1.12 +    (count (take-while
    1.13 +            (partial not= symbol)
    1.14 +            sequence))))
    1.15  
    1.16 -(def input-high-addr-jump  (Integer/parseInt "10000010" 2))
    1.17 -(def input-high-addr-write (Integer/parseInt "00000010" 2))
    1.18 -(def input-low-addr-jump   (Integer/parseInt "10000100" 2))
    1.19 -(def input-low-addr-write  (Integer/parseInt "00000100" 2))
    1.20 -
    1.21 -(def input-write-num-mode  (Integer/parseInt "00001000" 2))
    1.22 -(def do-write-mode         (Integer/parseInt "00010000" 2))
    1.23  
    1.24  (defn main-bootstrap-program [start-address]
    1.25    ;; Register Use:
    1.26 @@ -196,12 +191,11 @@
    1.27    ;; A  user-input
    1.28    ;; HL target-address
    1.29    ;; B  bytes-to-write
    1.30 -  ;; C  current-mode
    1.31 +  ;; C  non-volatile scratch
    1.32  
    1.33    ;; Modes (with codes) are:
    1.34  
    1.35    ;; single-action-modes:
    1.36 -  ;; SET-MODE
    1.37    ;; SET-TARGET-HIGH     0x67 ;; A->H
    1.38    ;; SET-TARGET-LOW      0x6F ;; A->L
    1.39    ;; JUMP                0xE9 ;; jump to (HL)
    1.40 @@ -255,19 +249,14 @@
    1.41                    
    1.42           0x18
    1.43           :to-beginning-2]
    1.44 -
    1.45 -        symbol-index
    1.46 -        (fn [symbol sequence]
    1.47 -          (count (take-while
    1.48 -                  (partial not= symbol)
    1.49 -                  sequence)))
    1.50          
    1.51          symbols
    1.52          {:to-be-executed-address
    1.53 -         (disect-bytes-2
    1.54 -          (+ start-address jump-distance
    1.55 -             (count init)
    1.56 -             (symbol-index :to-be-executed input)))
    1.57 +         (reverse
    1.58 +          (disect-bytes-2
    1.59 +           (+ start-address jump-distance
    1.60 +              (count init)
    1.61 +              (symbol-index :to-be-executed input))))
    1.62           :to-be-executed 0x3F} ;; clear carry flag no-op
    1.63  
    1.64          program** (flatten
    1.65 @@ -289,10 +278,12 @@
    1.66          resolve-external-jumps
    1.67          {:to-beginning-1
    1.68           (->signed-8-bit
    1.69 -          (+ -2 (- (symbol-index :to-beginning-1 program*))))
    1.70 +          (+ (count init)
    1.71 +             -2 (- (inc (symbol-index :to-beginning-1 program*)))))
    1.72           :to-beginning-2
    1.73           (->signed-8-bit
    1.74 -          (+ -2 (- (symbol-index :to-beginning-2 program*))))}
    1.75 +          (+ (count init)
    1.76 +           -2 (- (inc (symbol-index :to-beginning-2 program*)))))}
    1.77  
    1.78          program
    1.79          (replace resolve-external-jumps program*)]
    1.80 @@ -309,6 +300,19 @@
    1.81          (set-memory-range pokemon-list-start program)
    1.82          (PC! pokemon-list-start))))
    1.83  
    1.84 +(defn test-set-H [n]
    1.85 +  (let [after
    1.86 +        (-> (bootstrap-base)
    1.87 +            (step [])
    1.88 +            (step [])
    1.89 +            (step [])
    1.90 +            (step (buttons 0x67))
    1.91 +            (step (buttons n))
    1.92 +            (step [])
    1.93 +            (step [])
    1.94 +            (step []))]
    1.95 +    (hex (H after))))
    1.96 +
    1.97  (defn test-write-bytes-mode []
    1.98    (let [target-address 0xC00F
    1.99          [target-high target-low] (disect-bytes-2 target-address)