comparison clojure/com/aurellem/assembly.clj @ 113:0831da75d2c5

completed frame-counting machine language program with dylan's help
author Robert McIntyre <rlm@mit.edu>
date Fri, 16 Mar 2012 00:43:28 -0500
parents 6fe33bb5ea22
children a454730d92dd
comparison
equal deleted inserted replaced
112:6fe33bb5ea22 113:0831da75d2c5
72 (defn view-memory [state mem] 72 (defn view-memory [state mem]
73 (println (format "mem 0x%04X = %s" mem 73 (println (format "mem 0x%04X = %s" mem
74 (binary-str (aget (memory state) mem)))) 74 (binary-str (aget (memory state) mem))))
75 state) 75 state)
76 76
77 (defn read-buttons [] 77 (defn read-down-button []
78 (-> (tick (mid-game)) 78 (-> (tick (mid-game))
79 (IE! 0) ; disable interrupts 79 (IE! 0) ; disable interrupts
80 (inject-item-assembly 80 (inject-item-assembly
81 (concat 81 (concat
82 ;; write 00010000 to 0xFF00 to select joypad 82 ;; write 00010000 to 0xFF00 to select joypad
83 [0x18 ;D31D ; jump over 83 [0x18 ;D31D ; jump over
84 0x01 ;D31E ; the next 8 bits 84 0x01 ;D31E ; the next 8 bits
85 (Integer/parseInt "00100000" 2) ;D31F data section 85 ;D31F
86 (Integer/parseInt "00100000" 2) ; data section
86 87
87 0xFA ;D320 ; load (D31F) into A 88 0xFA ;D320 ; load (D31F) into A
88 0x1F ;D321 --> 89 0x1F ;D321 -->
89 0xD3 ;D322 --> D31F 90 0xD3 ;D322 --> D31F
90 91
121 0xD3 ;D332 122 0xD3 ;D332
122 ] 123 ]
123 124
124 [])))) 125 []))))
125 126
127
128 ;; specs for main bootstrap program
129 ;; starts in "mode-select" mode
130 ;; Each button press takes place in a single frame.
131 ;; mode-select-mode takes one of the main buttons
132 ;; which selects one of up to eight modes
133 ;; mode 1 activated by the "A" button
134 ;; the next two button presses indicates the start
135 ;; memory location which to which the bootstrap
136 ;; program will write.
137 ;; This is done by using each of the eight buttons to
138 ;; spell out an 8 bit number. The order of buttons is
139 ;; ["A" "B" "start" "select" "up" "right" "down" "left"],
140 ;; [:a :start :l] --> 10100001
141
142 ;; the next button press determines how many bytes are to be
143 ;; written, starting at the start position.
144
145 ;; then, the actual bytes are entered and are written to the
146 ;; start address in sequence.
147
148
149 (defn count-frames []
150 (-> (tick (mid-game))
151 (IE! 0) ; disable interrupts
152 (inject-item-assembly
153 ;; write 00010000 to 0xFF00 to select joypad
154 [0x18 ;D31D ; jump over
155 0x02 ;D31E ; the next 2 bytes
156 0x00 ;D31F ; frame-count
157 0x00 ;D320 ; v-blank-prev
158
159 0xFA ;D321
160 0x41 ;D322 ; load (FF41) into A
161 0xFF ;D323 ; this contains mode flags
162
163
164
165 ;; if we're in v-blank, the bit-1 is 0
166 ;; and bit-2 is 1 Otherwise, it is not v-blank.
167 0xCB ;D324 ; test bit-1 of A
168 0x4F ;D325
169
170 0xC2 ;D326 ; if bit-1 is not 0
171 0x43 ;D327 ; GOTO not-v-blank
172 0xD3 ;D328
173
174 0xCB ;D329 ; test bit-0 of A
175 0x47 ;D32A
176
177 0xCA ;D32B ; if bit-0 is not 1
178 0x43 ;D32C ; GOTO not-v-blank
179 0xD3 ;D32D
180
181 ;; in v-blank mode
182
183 ;; if v-blank-prev was 0,
184 ;; increment frame-count
185
186 0xFA ;D32E ; load v-blank-prev to A
187 0x20 ;D32F
188 0xD3 ;D330
189
190 0xCB ;D331
191 0x47 ;D332 ; test bit-0 of A
192
193 0x20 ;D333 ; skip next section
194 0x07 ;D334 ; if v-blank-prev was not zero
195
196 ;; v-blank was 0, increment frame-count
197 0xFA ;D335 ; load frame-count into A
198 0x1F ;D336
199 0xD3 ;D337
200
201 0x3C ;D338 ; inc A
202
203 0xEA ;D339 ; load A into frame-count
204 0x1F ;D33A
205 0xD3 ;D33B
206
207 ;; set v-blank? to 1
208 0x3E ;D33C ; load 1 into A
209 0x01 ;D33D
210
211 0xEA ;D33E ; load A into v-blank-prev
212 0x20 ;D33F
213 0xD3 ;D340
214
215 0x18 ;D341 ; skip not-in-v-blank section
216 0x05 ;D342
217
218 ;; not in v-blank mode
219 ;; set b-blank? to 0
220 0x3E ;D343 ; load 0 into A
221 0x00 ;D344
222
223 0xEA ;D345 ; load A into v-blank-prev
224 0x20 ;D346
225 0xD3 ;D347
226
227
228 0xC3 ;D348 ; return to beginning
229 0x1D ;D349
230 0xD3 ;D34A
231
232
233
234 ])))
235
236
237
238
126 (defn run-a-bit [] 239 (defn run-a-bit []
127 (-> (read-buttons) 240 (-> (read-down-button)
128 (info) 241 (info)
129 (tick) ;; skip over data section 242 (tick) ;; skip over data section
130 (info) 243 (info)
131 (view-register "Register A" A) 244 (view-register "Register A" A)
132 (tick) ;; load-data into A 245 (tick) ;; load-data into A