comparison clojure/com/aurellem/run/adv_choreo.clj @ 562:114f58b5b6d0

new glyph rendering skeleton complete.
author Robert McIntyre <rlm@mit.edu>
date Fri, 31 Aug 2012 09:22:52 -0500
parents c57398047795
children a70d9223f6eb
comparison
equal deleted inserted replaced
561:c57398047795 562:114f58b5b6d0
127 127
128 128
129 129
130 (defn glyph-display-program 130 (defn glyph-display-program
131 [start-address 131 [start-address
132 monitor-address 132 max-glyphs]
133 delay-count
134 total-glyph-count]
135 (let [data-start (+ 2 start-address) 133 (let [data-start (+ 2 start-address)
134 [max-glyphs-high max-glyphs-low]
135 (disect-bytes-2 max-glyphs)
136 load-data 136 load-data
137 (flatten 137 (flatten
138 [;; data region 138 [;; data region
139
140 0x18 139 0x18
141 5 140 2
142 (disect-bytes-2 monitor-address) 141 0 0 ;; current num of glyphs-rendered
143 (disect-bytes-2 total-glyph-count)
144 delay-count
145 142
146 ;; save all registers 143 ;; save all registers
147 0xC5 0xD5 0xE5 0xF5 144 0xC5 0xD5 0xE5 0xF5
148 145
149 ;; load data from data region into registers 146 ;; load data from data region into registers
150 0x21 147
148 0xF5 ;; push A
149 0x21 ;; begin data load
151 (reverse (disect-bytes-2 data-start)) 150 (reverse (disect-bytes-2 data-start))
152 151
153 0x2A 0x47 ;; monitor-address-high -> B 152 0x2A 0x47 ;; glyphs-rendered -> BC
154 0x2A 0x4F ;; monitor-address-low -> C 153 0x2A 0x4F
155 154
156 0x2A 0x57 ;; glyph-count-high -> D 155 0x16 max-glyphs-high ;; load max-glyphs
157 0x2A 0x5F ;; glyph-count-low -> E 156 0x1E max-glyphs-low ;; into DE
158 157 ])
159 0x7E ;; delay -> A
160 ])
161
162 handle-delay*
163 (flatten
164 [0xA7 ;; test if delay is zero
165 ;; if delay is not 0, decrement and skip to cleanup
166 0x28 ;; JR Z, skip this section if A==0
167 4
168 0x3D ;; dec A
169 0x77 ;; (dec delay) -> delay
170 0x18
171 :to-cleanup])
172 158
173 handle-glyph-count* 159 handle-glyph-count*
174 (flatten 160 (flatten
175 [;; if glyph-count is 0, go directly to stack-cleanup 161 [;; if glyphs-rendered = max-glyph count, go directly
176 0x79 0xB0 ;; check if BC == 0 162 ;; to stack-cleanup
177 0x20 ;; JR NZ, skip if BC !=0 163
178 2 164 0x47 0xBA ;; compare B to D
179 0x18 165 0x20 ;; skip next section B != D
180 :to-stack-cleanup 166 7 ;; this is equal to the number of instructions in the next
181 ]) 167 ;; indented region!
182 168
183 display-glyph [0 0 0] 169 0x79 0xBB ;; compare C to E
170 0x20 ;; JR NZ, skip if C != E
171 3
172 0xF1 ;; pop AF for stack maintainance!
173 0x18
174 :to-stack-cleanup
175 ])
176
177 display-glyph
178 (flatten
179 [0xF1 ;; pop A, now A is equal to key input
180
181 0 0 0
182
183
184 ])
185
186
184 cleanup 187 cleanup
185 ;; restore all registers 188 ;; restore all registers
186 189 (flatten
187 (flatten 190 [0x03 ;; (inc glyphs-rednered) -> glyphs-rendered
188 [0x03 ;; (inc monitor-address) -> monitor-address 191
189 0x1B ;; (dec glyph-count) -> glyph-count
190
191 ;; Reset HL to initial value 192 ;; Reset HL to initial value
192 0x21 193 0x21
193 (reverse (disect-bytes-2 data-start)) 194 (reverse (disect-bytes-2 data-start))
194 195
195 0x78 0x22 ;; B -> monitor-address-high 196 0x78 0x22 ;; B -> save glyphs-rendered
196 0x79 0x22 ;; C -> monitor-address-low 197 0x79 0x22 ;;
197
198 0x7A 0x22 ;; D -> glyph-count-high
199 0x7B 0x22 ;; E -> glyph-count-low
200 ]) 198 ])
201 199
202 stack-cleanup 200 stack-cleanup
203 [0xF1 0xE1 0xD1 0xC1] 201 [0xF1 0xE1 0xD1 0xC1]
204 202
205 handle-delay
206 (replace {:to-cleanup
207 (+ (count display-glyph) (count handle-glyph-count*))}
208 handle-delay*)
209
210 handle-glyph-count 203 handle-glyph-count
211 (replace {:to-stack-cleanup 204 (replace {:to-stack-cleanup
212 (+ (count display-glyph) (count cleanup))} 205 (+ (count display-glyph) (count cleanup))}
213 handle-glyph-count*)] 206 handle-glyph-count*)]
214 (concat load-data 207 (concat load-data
215 handle-delay handle-glyph-count 208 handle-glyph-count
216 display-glyph 209 display-glyph
217 cleanup stack-cleanup))) 210 cleanup stack-cleanup)))
218 211
219 (def main-program-base-address 0xC000) 212 (def main-program-base-address 0xC000)
220 213
223 (let [init [0xAF 0x4F 0x47] ;; 0->A; 0->C; 0->B 216 (let [init [0xAF 0x4F 0x47] ;; 0->A; 0->C; 0->B
224 header (concat (frame-metronome) (read-user-input)) 217 header (concat (frame-metronome) (read-user-input))
225 218
226 glyph-display (glyph-display-program 219 glyph-display (glyph-display-program
227 (+ (count init) 220 (+ (count init)
228 ;;(count header) 221 (count header)
229 start-address) 222 start-address)
230 main-program-base-address 100 223 2000)
231 200)
232 ;;(- (count (program-data 0)) 100)) 224 ;;(- (count (program-data 0)) 100))
233 225
234 state-machine-start-address 226 state-machine-start-address
235 (+ start-address (count init) (count header) (count glyph-display)) 227 (+ start-address (count init) (count header) (count glyph-display))
236 state-machine 228 state-machine
246 ;; need to investigate. 238 ;; need to investigate.
247 (count glyph-display) 239 (count glyph-display)
248 (count header) 240 (count header)
249 (count state-machine)))])] 241 (count state-machine)))])]
250 242
251 (concat init glyph-display header state-machine return-to-header))) 243 (concat init header glyph-display state-machine return-to-header)))
252 244
253 245
254 246
255 (defn-memo begin-glyph-bootstrap 247 (defn-memo begin-glyph-bootstrap
256 ([] (begin-glyph-bootstrap (launch-main-bootstrap-program))) 248 ([] (begin-glyph-bootstrap (launch-main-bootstrap-program)))