Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 386:d8cbbf2a3133
changed scratch ragisters from BC to DE.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 12 Apr 2012 06:27:03 -0500 |
parents | 3f3cfc89be91 |
children | 47d44bb54d32 |
comparison
equal
deleted
inserted
replaced
385:3f3cfc89be91 | 386:d8cbbf2a3133 |
---|---|
63 (if (< n 0) | 63 (if (< n 0) |
64 (+ 256 n) n)) | 64 (+ 256 n) n)) |
65 | 65 |
66 (defn frame-metronome [] | 66 (defn frame-metronome [] |
67 (let [timing-loop | 67 (let [timing-loop |
68 [0x01 ; \ | 68 [;;0x01 ; \ |
69 0x43 ; | | 69 ;;0x43 ; | |
70 0xFE ; | load 0xFF44 into BC without repeats | 70 ;;0xFE ; | load 0xFF44 into BC without repeats |
71 0x0C ; | | 71 ;;0x0C ; | |
72 0x04 ; / | 72 ;;0x04 ; / |
73 0x0A] ;; (BC) -> A, now A = LY (vertical line coord) | 73 ;;0x0A ;; (BC) -> A, now A = LY (vertical line coord) |
74 | |
75 0x11 ; \ | |
76 0x43 ; | | |
77 0xFE ; | load 0xFF44 into DE without repeats | |
78 0x1C ; | | |
79 0x14 ; / | |
80 0x1A ;; (DE) -> A, now A = LY (vertical line coord) | |
81 ] | |
74 continue-if-144 | 82 continue-if-144 |
75 [0xFE | 83 [0xFE |
76 144 ;; compare LY (in A) with 144 | 84 144 ;; compare LY (in A) with 144 |
77 0x20 ;; jump back to beginning if LY != 144 (not-v-blank) | 85 0x20 ;; jump back to beginning if LY != 144 (not-v-blank) |
78 (->signed-8-bit | 86 (->signed-8-bit |
79 (+ -4 (- (count timing-loop))))] | 87 (+ -4 (- (count timing-loop))))] |
80 spin-loop | 88 spin-loop |
81 [0x05 ;; dec B, which is 0xFF | 89 [;;0x05 ;; dec B, which is 0xFF |
90 0x15 ;; dec D, which is 0xFF | |
82 0x20 ;; spin until B==0 | 91 0x20 ;; spin until B==0 |
83 0xFD]] | 92 0xFD]] |
84 (concat timing-loop continue-if-144 spin-loop))) | 93 (concat timing-loop continue-if-144 spin-loop))) |
85 | 94 |
86 (defn test-frame-metronome | 95 (defn test-frame-metronome |
87 "Ensure that frame-metronome ticks exactly once every frame." | 96 "Ensure that frame-metronome ticks exactly once every frame." |
88 ([] (test-frame-metronome 151)) | 97 ([] (test-frame-metronome 151)) |
89 ([steps] | 98 ([steps] |
90 (let [inc-D [0x14 0x18 | 99 (let [inc-B [0x04 0x18 |
91 (->signed-8-bit | 100 (->signed-8-bit |
92 (+ -3 (- (count (frame-metronome)))))] | 101 (+ -3 (- (count (frame-metronome)))))] |
93 program (concat (frame-metronome) inc-D) | 102 program (concat (frame-metronome) inc-B) |
94 count-frames | 103 count-frames |
95 (-> (tick (mid-game)) | 104 (-> (tick (mid-game)) |
96 (IE! 0) | 105 (IE! 0) |
97 (DE! 0) | 106 (BC! 0) |
98 (set-memory-range pokemon-list-start program) | 107 (set-memory-range pokemon-list-start program) |
99 (PC! pokemon-list-start)) | 108 (PC! pokemon-list-start)) |
100 D-after-moves (D (run-moves count-frames (repeat steps [])))] | 109 B-after-moves (B (run-moves count-frames (repeat steps [])))] |
101 (println "D:" D-after-moves) | 110 (println "B:" B-after-moves) |
102 (assert (= steps D-after-moves)) | 111 (assert (= steps B-after-moves)) |
103 | 112 |
104 (println "D =" D-after-moves "after" steps "steps") | 113 (println "B =" B-after-moves "after" steps "steps") |
105 count-frames))) | 114 count-frames))) |
106 | 115 |
107 (defn read-user-input [] | 116 (defn read-user-input [] |
108 [0x01 ;\ | 117 [;;0x01 ;\ |
109 0x01 ;| | 118 ;;0x01 ;| |
110 0xFE ;| load 0xFF00 into BC without repeats | 119 ;;0xFE ;| load 0xFF00 into BC without repeats |
111 0x04 ;| | 120 ;;0x04 ;| |
112 0x0D ;/ | 121 ;;0x0D ;/ |
113 | 122 |
123 0x11 ; \ | |
124 0x01 ; | | |
125 0xFE ; | load 0xFF44 into DE without repeats | |
126 0x14 ; | | |
127 0x1D ; / | |
128 | |
114 0x3E | 129 0x3E |
115 (Integer/parseInt "00100000" 2) ; prepare to measure d-pad | 130 (Integer/parseInt "00100000" 2) ; prepare to measure d-pad |
116 | 131 |
117 0x02 | 132 0x12 |
118 0x0A ;; get D-pad info | 133 0x1A ;; get D-pad info |
119 | 134 |
120 0xF5 ;; push AF | 135 0xF5 ;; push AF |
121 | 136 |
122 0x3E | 137 0x3E |
123 (Integer/parseInt "00010000" 2) ; prepare to measure buttons | 138 (Integer/parseInt "00010000" 2) ; prepare to measure buttons |
124 | 139 |
125 0x02 | 140 0x12 |
126 0x0A ;; get button info | 141 0x1A ;; get button info |
127 | 142 |
128 | 143 |
129 0xE6 ;; select bottom bits of A | 144 0xE6 ;; select bottom bits of A |
130 0x0F | 145 0x0F |
131 | 146 |
146 | 161 |
147 (defn test-read-user-input [] | 162 (defn test-read-user-input [] |
148 (let [program | 163 (let [program |
149 (concat | 164 (concat |
150 (frame-metronome) (read-user-input) | 165 (frame-metronome) (read-user-input) |
151 [0x5F ;; A-> E | 166 [0x47 ;; A->B |
152 0x18 | 167 0x18 |
153 (->signed-8-bit | 168 (->signed-8-bit |
154 (+ (- (count (frame-metronome))) | 169 (+ (- (count (frame-metronome))) |
155 (- (count (read-user-input))) | 170 (- (count (read-user-input))) |
156 (- 3)))]) | 171 (- 3)))]) |
159 (IE! 0) | 174 (IE! 0) |
160 (set-memory-range pokemon-list-start program) | 175 (set-memory-range pokemon-list-start program) |
161 (PC! pokemon-list-start))] | 176 (PC! pokemon-list-start))] |
162 (dorun | 177 (dorun |
163 (for [i (range 0x100)] | 178 (for [i (range 0x100)] |
164 (assert (= (E (step read-input (buttons i))) i)))) | 179 (assert (= (B (step read-input (buttons i))) i)))) |
165 (println "Tested all inputs.") | 180 (println "Tested all inputs.") |
166 read-input)) | 181 read-input)) |
167 | 182 |
168 (def mode-select-mode (Integer/parseInt "00000000" 2)) | 183 (def mode-select-mode (Integer/parseInt "00000000" 2)) |
169 (def write-mode (Integer/parseInt "00000001" 2)) | 184 (def write-mode (Integer/parseInt "00000001" 2)) |