diff clojure/com/aurellem/gb/rlm_assembly.clj @ 416:21b8b3350b20

everything works :) now I have total control over the game.
author Robert McIntyre <rlm@mit.edu>
date Sat, 14 Apr 2012 05:41:55 -0500
parents f2f1e0b8c1c7
children 9068685e7d96
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/rlm_assembly.clj	Sat Apr 14 04:09:51 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj	Sat Apr 14 05:41:55 2012 -0500
     1.3 @@ -224,7 +224,7 @@
     1.4    (if (< n 0)
     1.5      (+ 256 n) n))
     1.6  
     1.7 -(defn frame-metronome** []
     1.8 +(defn frame-metronome []
     1.9    (let [init [0xC5] ;; save value of BC
    1.10          timing-loop
    1.11          [0x01 ; \
    1.12 @@ -247,18 +247,18 @@
    1.13  
    1.14  (defn frame-metronome* []
    1.15    [0x3E   ;; smallest version, but uses repeated nybbles
    1.16 -   0x01    
    1.17 +   0x01
    1.18     0xE0
    1.19     0xFF])
    1.20  
    1.21 -
    1.22 -(defn frame-metronome []
    1.23 +(defn frame-metronome** []
    1.24    [0x06 ;; load 0xFE into B
    1.25     0xFE
    1.26     0x04 ;; inc B, now B == FF
    1.27 -   0x3E
    1.28 +
    1.29 +   0x3E ;;  RLM-debug
    1.30     0x01 ;; 1->A
    1.31 -   
    1.32 +  
    1.33     0x48 ;; B->C
    1.34     0x02]) ;; A->(BC) set exclusive v-blank interrupt
    1.35  
    1.36 @@ -266,8 +266,10 @@
    1.37    "Ensure that frame-metronome ticks exactly once every frame."
    1.38    ([] (test-frame-metronome 151))
    1.39    ([steps]
    1.40 -     (let [inc-E [0x1C 0x76 0x18 
    1.41 -                  (->signed-8-bit -4)]
    1.42 +     (let [inc-E [0x1C 0x18 
    1.43 +                  (->signed-8-bit
    1.44 +                   (+ -3
    1.45 +                      (-(count (frame-metronome)))))]
    1.46                     
    1.47             program (concat (frame-metronome) inc-E)
    1.48             count-frames
    1.49 @@ -284,10 +286,7 @@
    1.50         count-frames)))
    1.51  
    1.52  (defn read-user-input []
    1.53 -  [0xAF 0x4F 0x47 ;; 0->A; 0->C; 0->B
    1.54 -   0xC5 ;; save value of BC
    1.55 -      
    1.56 -   0x3E
    1.57 +  [0x3E
    1.58     0x20 ; prepare to measure d-pad
    1.59  
    1.60     0x3F ; clear carry flag no-op to prevent repeated nybbles
    1.61 @@ -378,7 +377,8 @@
    1.62       ;; multi-action-modes
    1.63       ;; WRITE               0x47 ;; A->B
    1.64  
    1.65 -     (let [header (concat (frame-metronome) (read-user-input))
    1.66 +     (let [init [0xAF 0x4F 0x47] ;; 0->A; 0->C; 0->B
    1.67 +           header (concat (frame-metronome) (read-user-input))
    1.68             
    1.69             input
    1.70             [0xC1  ;; pop BC so it's not volatile
    1.71 @@ -409,7 +409,7 @@
    1.72              0x7B ;; E->A
    1.73              0x4F ;; A->C now C stores previous instruction
    1.74              0x18           ;; return
    1.75 -            :to-halt]
    1.76 +            :to-jump]
    1.77             
    1.78             output
    1.79             [:output-start ;; just a label
    1.80 @@ -423,7 +423,6 @@
    1.81  
    1.82              0x23 ;; inc HL 
    1.83              
    1.84 -            0x76 ;; HALT, peasant!
    1.85              0x18
    1.86              :to-beginning] 
    1.87  
    1.88 @@ -433,11 +432,14 @@
    1.89               (disect-bytes-2
    1.90                (+ start-address
    1.91                   (count header)
    1.92 +                 (count init)
    1.93                   (symbol-index :to-be-executed input))))
    1.94              :to-be-executed 0x3F} ;; clear carry flag no-op
    1.95  
    1.96             program** (flatten
    1.97 -                      (replace symbols (concat header input output)))
    1.98 +                      (replace
    1.99 +                       symbols
   1.100 +                       (concat init header input output)))
   1.101             
   1.102             resolve-internal-jumps
   1.103             {:output-start []
   1.104 @@ -451,13 +453,13 @@
   1.105             (flatten (replace resolve-internal-jumps program**))
   1.106             
   1.107             resolve-external-jumps
   1.108 -           {:to-halt
   1.109 +           {:to-jump
   1.110              (- (- (symbol-index :to-beginning program*)
   1.111 -                  (symbol-index :to-halt program*)) 3)
   1.112 +                  (symbol-index :to-jump program*)) 2)
   1.113                 
   1.114              :to-beginning
   1.115              (->signed-8-bit
   1.116 -             (+ 2 (count (frame-metronome))
   1.117 +             (+ (count init) -1
   1.118                  (- (symbol-index :to-beginning program*))))}
   1.119  
   1.120             program