comparison clojure/com/aurellem/run/adv_choreo.clj @ 558:6f8b15c2fb48

trying to track down major problem with storing variables in RAM.
author Robert McIntyre <rlm@mit.edu>
date Fri, 31 Aug 2012 04:22:08 -0500
parents cd54ac4a8701
children 91e99cc36bda
comparison
equal deleted inserted replaced
557:cd54ac4a8701 558:6f8b15c2fb48
123 "0" ;; OBJ-on flag 123 "0" ;; OBJ-on flag
124 "1") ;; no-effect 124 "1") ;; no-effect
125 2))])] 125 2))])]
126 (concat A B ))) 126 (concat A B )))
127 127
128
129 ;; handle-delay*
130 ;; (flatten
131 ;; [0xA7 ;; test if delay is zero
132 ;; ;; if delay is not 0, decrement and skip to cleanup
133 ;; 0x28 ;; JR Z, skip this section if A==0
134 ;; 4
135 ;; 0x3D ;; dec A
136 ;; 0x77 ;; (dec delay) -> delay
137 ;; 0x18
138 ;; :to-cleanup])
139
140 ;; handle-glyph-count*
141 ;; (flatten
142 ;; [;; if glyph-count is 0, go directly to stack-cleanup
143
144 ;; ;;0x79 0xB0 ;; check if BC == 0
145 ;; 0 0
146 ;; 0x20 ;; JR NZ, skip if BC !=0
147 ;; 2
148 ;; 0 0
149 ;; ;;0x18
150 ;; ;;:to-stack-cleanup
151 ;; ])
152 ;; handle-glyph-count* [0 0 0 0]
153
154
155 ;; handle-delay
156 ;; (replace {:to-cleanup
157 ;; (+ (count display-glyph) (count handle-glyph-count*))}
158 ;; handle-delay*)
159
160 ;; handle-glyph-count
161 ;; (replace {:to-stack-cleanup
162 ;; (+ (count display-glyph) (count cleanup))}
163 ;; handle-glyph-count*)
164
165
128 (defn glyph-display-program 166 (defn glyph-display-program
129 [start-address 167 [start-address
130 monitor-address 168 monitor-address
131 delay-count 169 delay-count
132 total-glyph-count] 170 total-glyph-count]
151 189
152 ;; save all registers 190 ;; save all registers
153 0xC5 0xD5 0xE5 0xF5 191 0xC5 0xD5 0xE5 0xF5
154 192
155 ;; load data from data region into registers 193 ;; load data from data region into registers
156
157 0x21 194 0x21
158 (disect-bytes-2 monitor-address-high) 195 (reverse (disect-bytes-2 data-start))
159 196
160 0x2A 0x47 ;; monitor-address-high -> B 197 0x2A 0x47 ;; monitor-address-high -> B
161 0x2A 0x4F ;; monitor-address-low -> C 198 0x2A 0x4F ;; monitor-address-low -> C
162 199
163 0x2A 0x57 ;; glyph-count-high -> D 200 0x2A 0x57 ;; glyph-count-high -> D
164 0x2A 0x5F ;; glyph-count-low -> E 201 0x2A 0x5F ;; glyph-count-low -> E
165 202
166 0x2A ;; delay -> A 203 0x7E ;; delay -> A
167 ]) 204 ])
168 205
169 handle-delay* 206 display-glyph [0 0 0]
170 (flatten
171 [0xA7 ;; test if A is zero
172 ;; if A is not 0, decrement and skip to cleanup
173 0x20
174 5
175 0x3D
176 0x77
177 0xC3
178 :cleanup-address-low
179 :cleanup-address-high])
180
181
182
183 cleanup 207 cleanup
184 ;; restore all registers 208 ;; restore all registers
209
210 (flatten
211 [;; HL points to delay currently,
212 ;; decrement HL and then restore everything
213
214 0x03 ;; (inc monitor-address) -> monitor-address
215 0x1B ;; (dec glyph-count) -> glyph-count
216
217 ;; Reset HL to initial value
218 0x21
219 (reverse (disect-bytes-2 data-start))
220
221 0x78 0x22 ;; B -> monitor-address-high
222 0x79 0x22 ;; C -> monitor-address-low
223
224 ;;0x7A 0x22 ;; D -> glyph-count-high
225 ;;0x7B 0x22 ;; E -> glyph-count-low
226 ])
227
228 stack-cleanup
185 [0xF1 0xE1 0xD1 0xC1] 229 [0xF1 0xE1 0xD1 0xC1]
186 230
187 [cleanup-address-high 231 ]
188 cleanup-address-low] (disect-bytes-2 232 (concat load-data
189 (+ start-address (count load-data) 233 ;;handle-delay handle-glyph-count
190 (count handle-delay*))) 234 display-glyph
191 235 cleanup stack-cleanup)))
192 handle-delay
193 (replace {:cleanup-address-low cleanup-address-low
194 :cleanup-address-high cleanup-address-high}
195 handle-delay*)]
196 (concat load-data handle-delay cleanup)))
197 236
198 237
199 238
200 (def main-program-base-address 0xC000) 239 (def main-program-base-address 0xC000)
201 240
206 245
207 glyph-display (glyph-display-program 246 glyph-display (glyph-display-program
208 (+ (count init) (count header) 247 (+ (count init) (count header)
209 start-address) 248 start-address)
210 main-program-base-address 100 249 main-program-base-address 100
211 (- (count (program-data 0)) 100)) 250 200)
251 ;;(- (count (program-data 0)) 100))
212 252
213 state-machine-start-address 253 state-machine-start-address
214 (+ start-address (count init) (count header) (count glyph-display)) 254 (+ start-address (count init) (count header) (count glyph-display))
215 state-machine 255 state-machine
216 (bootstrap-state-machine state-machine-start-address) 256 (bootstrap-state-machine state-machine-start-address)
229 269
230 (concat init glyph-display header state-machine return-to-header))) 270 (concat init glyph-display header state-machine return-to-header)))
231 271
232 272
233 273
234 (defn begin-glyph-bootstrap 274 (defn-memo begin-glyph-bootstrap
235 ([] (begin-glyph-bootstrap (launch-main-bootstrap-program))) 275 ([] (begin-glyph-bootstrap (launch-main-bootstrap-program)))
236 ([script] 276 ([script]
237 (let [glyph-init (glyph-init-program relocated-bootstrap-start) 277 (let [glyph-init (glyph-init-program relocated-bootstrap-start)
238 main-glyph-start (+ relocated-bootstrap-start 278 main-glyph-start (+ relocated-bootstrap-start
239 (count glyph-init)) 279 (count glyph-init))