Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 382:3c24216e0080
decreased frame-metronome by one opcode
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 11 Apr 2012 13:17:08 -0500 |
parents | 1bfa43d35403 |
children | 9eae7e914bf0 |
comparison
equal
deleted
inserted
replaced
381:1bfa43d35403 | 382:3c24216e0080 |
---|---|
61 | 61 |
62 (defn ->signed-8-bit [n] | 62 (defn ->signed-8-bit [n] |
63 (if (< n 0) | 63 (if (< n 0) |
64 (+ 256 n) n)) | 64 (+ 256 n) n)) |
65 | 65 |
66 0x01 | |
67 0x44 | |
68 0xFF | |
69 inc C | |
70 inc D | |
71 | |
66 (defn frame-metronome [] | 72 (defn frame-metronome [] |
67 (let [timing-loop | 73 (let [timing-loop |
68 [0x16 | 74 [0x01 |
69 0xFE ;; load FF into D without repeats | 75 0x43 |
70 0x14 | 76 0xFE ;; load 0xFF44 into BC without repeats |
77 0x0C | |
78 0x04 | |
71 | 79 |
72 0x1E | 80 0x0A] ;; (BC) -> A, now A = LY (vertical line coord) |
73 0x43 ;; load 44 into E without repeats | |
74 0x1C | |
75 | |
76 0x1A ;; (DE) -> A, now A = LY (vertical line coord) | |
77 ] | |
78 continue-if-144 | 81 continue-if-144 |
79 [0xFE | 82 [0xFE |
80 144 ;; compare LY (in A) with 144 | 83 144 ;; compare LY (in A) with 144 |
81 0x20 ;; jump back to beginning if LY != 144 (not-v-blank) | 84 0x20 ;; jump back to beginning if LY != 144 (not-v-blank) |
82 (->signed-8-bit | 85 (->signed-8-bit |
83 (+ -4 (- (count timing-loop))))] | 86 (+ -4 (- (count timing-loop))))] |
84 spin-loop | 87 spin-loop |
85 [0x15 ;; dec D, which is 0xFF | 88 [0x05 ;; dec B, which is 0xFF |
86 0x20 ;; spin until D==0 | 89 0x20 ;; spin until B==0 |
87 0xFD]] | 90 0xFD]] |
88 (concat timing-loop continue-if-144 spin-loop))) | 91 (concat timing-loop continue-if-144 spin-loop))) |
89 | 92 |
90 | 93 |
91 (defn test-frame-metronome | 94 (defn test-frame-metronome |
92 "Ensure that frame-metronome ticks exactly once every frame." | 95 "Ensure that frame-metronome ticks exactly once every frame." |
93 ([] (test-frame-metronome 151)) | 96 ([] (test-frame-metronome 151)) |
94 ([steps] | 97 ([steps] |
95 (let [inc-C [0x0C 0x18 | 98 (let [inc-D [0x14 0x18 |
96 (->signed-8-bit | 99 (->signed-8-bit |
97 (+ -3 (- (count (frame-metronome)))))] | 100 (+ -3 (- (count (frame-metronome)))))] |
98 program (concat (frame-metronome) inc-C) | 101 program (concat (frame-metronome) inc-D) |
99 count-frames | 102 count-frames |
100 (-> (tick (mid-game)) | 103 (-> (tick (mid-game)) |
101 (IE! 0) | 104 (IE! 0) |
102 (BC! 0) | 105 (DE! 0) |
103 (set-memory-range pokemon-list-start program) | 106 (set-memory-range pokemon-list-start program) |
104 (PC! pokemon-list-start)) | 107 (PC! pokemon-list-start)) |
105 C-after-moves (C (run-moves count-frames (repeat steps [])))] | 108 D-after-moves (D (run-moves count-frames (repeat steps [])))] |
106 (println "C:" C-after-moves) | 109 (println "D:" D-after-moves) |
107 ;;(assert (= steps C-after-moves)) | 110 (assert (= steps D-after-moves)) |
108 | 111 |
109 (println "C =" C-after-moves "after" steps "steps") | 112 (println "D =" D-after-moves "after" steps "steps") |
110 count-frames))) | 113 count-frames))) |
111 | 114 |
112 (defn main-bootstrap-program [start-address] | 115 (defn main-bootstrap-program [start-address] |
113 (let [[start-high start-low] (disect-bytes-2 start-address) | 116 (let [[start-high start-low] (disect-bytes-2 start-address) |
114 ] | 117 ] |