comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 393:b21d28e6c966

saving progress.
author Robert McIntyre <rlm@mit.edu>
date Thu, 12 Apr 2012 01:25:28 -0500
parents 309614263aa9
children 5c0e12f0a833
comparison
equal deleted inserted replaced
392:309614263aa9 393:b21d28e6c966
174 (for [i (range 0x100)] 174 (for [i (range 0x100)]
175 (assert (= (E (step read-input (buttons i))) i)))) 175 (assert (= (E (step read-input (buttons i))) i))))
176 (println "Tested all inputs.") 176 (println "Tested all inputs.")
177 read-input)) 177 read-input))
178 178
179 (def mode-select-mode (Integer/parseInt "00000000" 2)) 179 (def symbol-index
180 (def write-mode (Integer/parseInt "00000001" 2)) 180 (fn [symbol sequence]
181 (def jump-mode (Integer/parseInt "10000000" 2)) 181 (count (take-while
182 182 (partial not= symbol)
183 (def input-high-addr-jump (Integer/parseInt "10000010" 2)) 183 sequence))))
184 (def input-high-addr-write (Integer/parseInt "00000010" 2)) 184
185 (def input-low-addr-jump (Integer/parseInt "10000100" 2))
186 (def input-low-addr-write (Integer/parseInt "00000100" 2))
187
188 (def input-write-num-mode (Integer/parseInt "00001000" 2))
189 (def do-write-mode (Integer/parseInt "00010000" 2))
190 185
191 (defn main-bootstrap-program [start-address] 186 (defn main-bootstrap-program [start-address]
192 ;; Register Use: 187 ;; Register Use:
193 188
194 ;; ED non-volitale scratch 189 ;; ED non-volitale scratch
195 190
196 ;; A user-input 191 ;; A user-input
197 ;; HL target-address 192 ;; HL target-address
198 ;; B bytes-to-write 193 ;; B bytes-to-write
199 ;; C current-mode 194 ;; C non-volatile scratch
200 195
201 ;; Modes (with codes) are: 196 ;; Modes (with codes) are:
202 197
203 ;; single-action-modes: 198 ;; single-action-modes:
204 ;; SET-MODE
205 ;; SET-TARGET-HIGH 0x67 ;; A->H 199 ;; SET-TARGET-HIGH 0x67 ;; A->H
206 ;; SET-TARGET-LOW 0x6F ;; A->L 200 ;; SET-TARGET-LOW 0x6F ;; A->L
207 ;; JUMP 0xE9 ;; jump to (HL) 201 ;; JUMP 0xE9 ;; jump to (HL)
208 202
209 ;; multi-action-modes 203 ;; multi-action-modes
253 0xEA 247 0xEA
254 :to-be-executed-address 248 :to-be-executed-address
255 249
256 0x18 250 0x18
257 :to-beginning-2] 251 :to-beginning-2]
258
259 symbol-index
260 (fn [symbol sequence]
261 (count (take-while
262 (partial not= symbol)
263 sequence)))
264 252
265 symbols 253 symbols
266 {:to-be-executed-address 254 {:to-be-executed-address
267 (disect-bytes-2 255 (reverse
268 (+ start-address jump-distance 256 (disect-bytes-2
269 (count init) 257 (+ start-address jump-distance
270 (symbol-index :to-be-executed input))) 258 (count init)
259 (symbol-index :to-be-executed input))))
271 :to-be-executed 0x3F} ;; clear carry flag no-op 260 :to-be-executed 0x3F} ;; clear carry flag no-op
272 261
273 program** (flatten 262 program** (flatten
274 (replace 263 (replace
275 symbols 264 symbols
287 (flatten (replace resolve-internal-jumps program**)) 276 (flatten (replace resolve-internal-jumps program**))
288 277
289 resolve-external-jumps 278 resolve-external-jumps
290 {:to-beginning-1 279 {:to-beginning-1
291 (->signed-8-bit 280 (->signed-8-bit
292 (+ -2 (- (symbol-index :to-beginning-1 program*)))) 281 (+ (count init)
282 -2 (- (inc (symbol-index :to-beginning-1 program*)))))
293 :to-beginning-2 283 :to-beginning-2
294 (->signed-8-bit 284 (->signed-8-bit
295 (+ -2 (- (symbol-index :to-beginning-2 program*))))} 285 (+ (count init)
286 -2 (- (inc (symbol-index :to-beginning-2 program*)))))}
296 287
297 program 288 program
298 (replace resolve-external-jumps program*)] 289 (replace resolve-external-jumps program*)]
299 program)) 290 program))
300 291
306 ;; make sure program is valid output for item-writer 297 ;; make sure program is valid output for item-writer
307 ;;(bootstrap-pattern program) 298 ;;(bootstrap-pattern program)
308 (-> (tick (mid-game)) 299 (-> (tick (mid-game))
309 (set-memory-range pokemon-list-start program) 300 (set-memory-range pokemon-list-start program)
310 (PC! pokemon-list-start)))) 301 (PC! pokemon-list-start))))
302
303 (defn test-set-H [n]
304 (let [after
305 (-> (bootstrap-base)
306 (step [])
307 (step [])
308 (step [])
309 (step (buttons 0x67))
310 (step (buttons n))
311 (step [])
312 (step [])
313 (step []))]
314 (hex (H after))))
311 315
312 (defn test-write-bytes-mode [] 316 (defn test-write-bytes-mode []
313 (let [target-address 0xC00F 317 (let [target-address 0xC00F
314 [target-high target-low] (disect-bytes-2 target-address) 318 [target-high target-low] (disect-bytes-2 target-address)
315 assembly [0xF3 0x18 0xFE 0x12] 319 assembly [0xF3 0x18 0xFE 0x12]