]>
Commit | Line | Data |
---|---|---|
1 | ; Various functions: init, (RAM) disk, mmc, timer | |
2 | ; This file needs to get split up. | |
3 | ; | |
4 | ; Copyright (C) 2010 Sprite_tm | |
5 | ; Copyright (C) 2010 Leo C. | |
6 | ; | |
7 | ; This file is part of avrcpm. | |
8 | ; | |
9 | ; avrcpm is free software: you can redistribute it and/or modify it | |
10 | ; under the terms of the GNU General Public License as published by | |
11 | ; the Free Software Foundation, either version 3 of the License, or | |
12 | ; (at your option) any later version. | |
13 | ; | |
14 | ; avrcpm is distributed in the hope that it will be useful, | |
15 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ; GNU General Public License for more details. | |
18 | ; | |
19 | ; You should have received a copy of the GNU General Public License | |
20 | ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>. | |
21 | ; | |
22 | ; $Id$ | |
23 | ; | |
24 | ||
25 | ||
26 | ; ------------------- DRAM Refresh Interrupt -------------------- | |
27 | ||
28 | .cseg | |
29 | ; refresh interupt; exec 2 cbr cycles | |
30 | refrint: ;4 | |
31 | .org OC2Aaddr | |
32 | rjmp refrint ; tim2cmpa | |
33 | ||
34 | .org refrint | |
35 | sbis P_RAS,ram_ras ;2 | |
36 | reti | |
37 | ; CAS RAS | |
38 | cbi P_CAS,ram_cas ;2 1| 1| | |
39 | ; 1| 1| | |
40 | cbi P_RAS,ram_ras ;2 |0 1| | |
41 | ; |0 1| | |
42 | nop ;1 |0 |0 | |
43 | ; nop ;1 |0 |0 | |
44 | sbi P_RAS,ram_ras ;2 |0 |0 | |
45 | ; |0 |0 | |
46 | dram_wait DRAM_WAITSTATES-1 ; | | | |
47 | ; nop ;1 |0 |0 | |
48 | cbi P_RAS,ram_ras ;2 |0 1| | |
49 | ; |0 1| | |
50 | sbi P_CAS,ram_cas ;2 |0 |0 | |
51 | ; |0 |0 | |
52 | sbi P_RAS,ram_ras ;2 1| |0 | |
53 | ; 1| 1| | |
54 | reti ;4 --> 21 cycles | |
55 | ||
56 | ||
57 | ||
58 | ||
59 | ;Print a unsigned lonng value to the uart | |
60 | ; temp4:temp3:temp2:temp = value | |
61 | ||
62 | print_ultoa: | |
63 | push yh | |
64 | push yl | |
65 | push z_flags | |
66 | push temp4 | |
67 | push temp3 | |
68 | push temp2 | |
69 | push temp | |
70 | ||
71 | clr yl ;yl = stack level | |
72 | ||
73 | ultoa1: ldi z_flags, 32 ;yh = temp4:temp % 10 | |
74 | clr yh ;temp4:temp /= 10 | |
75 | ultoa2: lsl temp | |
76 | rol temp2 | |
77 | rol temp3 | |
78 | rol temp4 | |
79 | rol yh | |
80 | cpi yh,10 | |
81 | brcs ultoa3 | |
82 | subi yh,10 | |
83 | inc temp | |
84 | ultoa3: dec z_flags | |
85 | brne ultoa2 | |
86 | cpi yh, 10 ;yh is a numeral digit '0'-'9' | |
87 | subi yh, -'0' | |
88 | push yh ;Stack it | |
89 | inc yl | |
90 | cp temp,_0 ;Repeat until temp4:temp gets zero | |
91 | cpc temp2,_0 | |
92 | cpc temp3,_0 | |
93 | cpc temp4,_0 | |
94 | brne ultoa1 | |
95 | ||
96 | ldi temp, '0' | |
97 | ultoa5: cpi yl,3 ; at least 3 digits (ms) | |
98 | brge ultoa6 | |
99 | push temp | |
100 | inc yl | |
101 | rjmp ultoa5 | |
102 | ||
103 | ultoa6: pop temp ;Flush stacked digits | |
104 | rcall uartputc | |
105 | dec yl | |
106 | brne ultoa6 | |
107 | ||
108 | pop temp | |
109 | pop temp2 | |
110 | pop temp3 | |
111 | pop temp4 | |
112 | pop z_flags | |
113 | pop yl | |
114 | pop yh | |
115 | ret | |
116 | ||
117 | ||
118 | ;Prints temp2:temp in hex to the uart | |
119 | printhexw: | |
120 | push temp | |
121 | mov temp,temp2 | |
122 | rcall printhex | |
123 | pop temp | |
124 | ;fall thru | |
125 | ||
126 | ;Prints temp in hex to the uart | |
127 | printhex: | |
128 | swap temp | |
129 | rcall printhexn | |
130 | swap temp | |
131 | ;fall thru | |
132 | ||
133 | ;Prints the lower nibble | |
134 | printhexn: | |
135 | push temp | |
136 | andi temp,0xf | |
137 | cpi temp,0xA | |
138 | brlo printhexn_isno | |
139 | subi temp,-7 | |
140 | printhexn_isno: | |
141 | subi temp,-'0' | |
142 | rcall uartputc | |
143 | pop temp | |
144 | ret | |
145 | ||
146 | ;Prints the zero-terminated string following the call statement. | |
147 | ||
148 | printstr: | |
149 | push zh | |
150 | push zl | |
151 | push yh | |
152 | push yl | |
153 | push temp | |
154 | in yh,sph | |
155 | in yl,spl | |
156 | ldd zl,y+7 | |
157 | ldd zh,y+6 | |
158 | ||
159 | lsl zl | |
160 | rol zh | |
161 | printstr_loop: | |
162 | lpm temp,z+ | |
163 | cpi temp,0 | |
164 | breq printstr_end | |
165 | rcall uartputc | |
166 | cpi temp,13 | |
167 | brne printstr_loop | |
168 | ldi temp,10 | |
169 | rcall uartputc | |
170 | rjmp printstr_loop | |
171 | ||
172 | printstr_end: | |
173 | adiw zl,1 ;rounding | |
174 | lsr zh | |
175 | ror zl | |
176 | ||
177 | std y+7,zl | |
178 | std y+6,zh | |
179 | pop temp | |
180 | pop yl | |
181 | pop yh | |
182 | pop zl | |
183 | pop zh | |
184 | ret | |
185 | \r | |
186 | .dseg\r | |
187 | ||
188 | ||
189 | .cseg | |
190 | ||
191 | ||
192 | ||
193 | ||
194 | ||
195 | ||
196 | ; **************************************************************************** | |
197 | ||
198 | ; ------------- system timer 1ms --------------- | |
199 | ||
200 | .dseg | |
201 | ||
202 | delay_timer1: | |
203 | .byte 1 | |
204 | delay_timer2: | |
205 | .byte 1 | |
206 | timer_base: | |
207 | timer_ms: | |
208 | .byte 2 | |
209 | timer_s: | |
210 | .byte 4 | |
211 | ; don't change order here, clock put/get depends on it. | |
212 | cntms_out: ; register for ms | |
213 | .byte 2 | |
214 | utime_io: ; register for uptime. | |
215 | .byte 4 | |
216 | cnt_1ms: | |
217 | .byte 2 | |
218 | uptime: | |
219 | .byte 4 | |
220 | timer_top: | |
221 | .equ timer_size = timer_top - timer_base | |
222 | ||
223 | .equ clkofs = cnt_1ms-cntms_out | |
224 | .equ timerofs = cnt_1ms-timer_ms | |
225 | ||
226 | ||
227 | .cseg | |
228 | sysclockint: | |
229 | .org OC1Baddr ; Timer/Counter1 Compare Match B | |
230 | rjmp sysclockint ; 1ms system timer | |
231 | ||
232 | .org sysclockint | |
233 | push zl | |
234 | in zl,SREG | |
235 | push zl | |
236 | push zh | |
237 | inm8 zl,OCR1BL | |
238 | inm8 zh,OCR1BH | |
239 | addiw z,F_CPU/1000 | |
240 | outm8 OCR1BH,zh | |
241 | outm8 OCR1BL,zl | |
242 | ||
243 | #if DRAM_8BIT /* Implies software uart */ | |
244 | lds zl,srx_char_to | |
245 | subi zl,1 | |
246 | brcs syscl0 | |
247 | sts srx_char_to,zl | |
248 | brne syscl0 | |
249 | rcall srx_to | |
250 | syscl0: | |
251 | #endif | |
252 | lds zl,delay_timer1 | |
253 | subi zl,1 | |
254 | brcs syscl_t1n | |
255 | sts delay_timer1,zl | |
256 | syscl_t1n: | |
257 | lds zl,delay_timer2 | |
258 | subi zl,1 | |
259 | brcs syscl_t2n | |
260 | sts delay_timer2,zl | |
261 | syscl_t2n: | |
262 | lds zl,cnt_1ms | |
263 | lds zh,cnt_1ms+1 | |
264 | adiw z,1 | |
265 | ||
266 | sts cnt_1ms,zl | |
267 | sts cnt_1ms+1,zh | |
268 | cpi zl,low(1000) | |
269 | ldi zl,high(1000) ;doesn't change flags | |
270 | cpc zh,zl | |
271 | brlo syscl_end | |
272 | ||
273 | sts cnt_1ms,_0 | |
274 | sts cnt_1ms+1,_0 | |
275 | ||
276 | lds zl,uptime+0 | |
277 | inc zl | |
278 | sts uptime+0,zl | |
279 | brne syscl_end | |
280 | lds zl,uptime+1 | |
281 | inc zl | |
282 | sts uptime+1,zl | |
283 | brne syscl_end | |
284 | lds zl,uptime+2 | |
285 | inc zl | |
286 | sts uptime+2,zl | |
287 | brne syscl_end | |
288 | lds zl,uptime+3 | |
289 | inc zl | |
290 | sts uptime+3,zl | |
291 | ||
292 | syscl_end: | |
293 | pop zh | |
294 | pop zl | |
295 | out SREG,zl | |
296 | pop zl | |
297 | reti | |
298 | ||
299 | ; wait for temp ms | |
300 | ||
301 | delay_ms: | |
302 | sts delay_timer1,temp | |
303 | dly_loop: | |
304 | lds temp,delay_timer1 | |
305 | cpi temp,0 | |
306 | brne dly_loop | |
307 | ret | |
308 | ||
309 | ; | |
310 | ||
311 | clockget: | |
312 | ldi temp,0xFF | |
313 | subi temp2,TIMER_MSECS | |
314 | brcs clkget_end ;Port number in range? | |
315 | ldiw z,cntms_out | |
316 | breq clkget_copy ;lowest byte requestet, latch clock | |
317 | cpi temp2,6 | |
318 | brsh clkget_end ;Port number to high? | |
319 | ||
320 | add zl,temp2 | |
321 | brcc PC+2 | |
322 | inc zh | |
323 | ld temp,z | |
324 | clkget_end: | |
325 | ret | |
326 | ||
327 | ||
328 | ||
329 | clkget_copy: | |
330 | ldi temp2,6 | |
331 | cli | |
332 | clkget_l: | |
333 | ldd temp,z+clkofs | |
334 | st z+,temp | |
335 | dec temp2 | |
336 | brne clkget_l | |
337 | sei | |
338 | lds temp,cntms_out | |
339 | ;req. byte in temp | |
340 | ret | |
341 | ||
342 | clockput: | |
343 | subi temp2,TIMERPORT | |
344 | brcs clkput_end ;Port number in range? | |
345 | brne clkput_1 | |
346 | ||
347 | ; clock control | |
348 | ||
349 | cpi temp,starttimercmd | |
350 | breq timer_start | |
351 | cpi temp,quitTimerCmd | |
352 | breq timer_quit | |
353 | cpi temp,printTimerCmd | |
354 | breq timer_print | |
355 | cpi temp,uptimeCmd | |
356 | brne cp_ex | |
357 | rjmp uptime_print | |
358 | cp_ex: | |
359 | ret | |
360 | ||
361 | timer_quit: | |
362 | rcall timer_print | |
363 | rjmp timer_start | |
364 | ||
365 | clkput_1: | |
366 | dec temp2 | |
367 | ldiw z,cntms_out | |
368 | breq clkput_copy ;lowest byte requestet, latch clock | |
369 | cpi temp2,6 | |
370 | brsh clkput_end ;Port number to high? | |
371 | ||
372 | add zl,temp2 | |
373 | brcc PC+2 | |
374 | inc zh | |
375 | st z,temp | |
376 | clkput_end: | |
377 | ret | |
378 | ||
379 | clkput_copy: | |
380 | st z,temp | |
381 | adiw z,5 | |
382 | ldi temp2,6 | |
383 | cli | |
384 | clkput_l: | |
385 | ldd temp,z+clkofs | |
386 | st z+,temp | |
387 | dec temp2 | |
388 | brne clkput_l | |
389 | sei | |
390 | ret | |
391 | ||
392 | ; start/reset timer | |
393 | ; | |
394 | timer_start: | |
395 | ldiw z,timer_ms | |
396 | ldi temp2,6 | |
397 | cli | |
398 | ts_loop: | |
399 | ldd temp,z+timerofs | |
400 | st z+,temp | |
401 | dec temp2 | |
402 | brne ts_loop | |
403 | sei | |
404 | ret | |
405 | ||
406 | ||
407 | ; print timer | |
408 | ; | |
409 | ||
410 | timer_print: | |
411 | push yh | |
412 | push yl | |
413 | ldiw z,timer_ms | |
414 | ||
415 | ; put ms on stack (16 bit) | |
416 | ||
417 | cli | |
418 | ldd yl,z+timerofs | |
419 | ld temp2,z+ | |
420 | sub yl,temp2 | |
421 | ldd yh,z+timerofs | |
422 | ld temp2,z+ | |
423 | sbc yh,temp2 | |
424 | brsh tp_s | |
425 | ||
426 | addiw y,1000 | |
427 | sec | |
428 | tp_s: | |
429 | push yh | |
430 | push yl | |
431 | ||
432 | ldd temp,z+timerofs | |
433 | ld yl,z+ | |
434 | sbc temp,yl | |
435 | ||
436 | ldd temp2,z+timerofs | |
437 | ld yh,z+ | |
438 | sbc temp2,yh | |
439 | ||
440 | ldd temp3,z+timerofs | |
441 | ld yl,z+ | |
442 | sbc temp3,yl | |
443 | ||
444 | sei | |
445 | ldd temp4,z+timerofs | |
446 | ld yh,z+ | |
447 | sbc temp4,yh | |
448 | ||
449 | printnewline | |
450 | printstring "Timer running. Elapsed: " | |
451 | rcall print_ultoa | |
452 | ||
453 | printstring "." | |
454 | pop temp | |
455 | pop temp2 | |
456 | ldi temp3,0 | |
457 | ldi temp4,0 | |
458 | rcall print_ultoa | |
459 | printstring "s." | |
460 | ||
461 | pop yl | |
462 | pop yh | |
463 | ret | |
464 | ||
465 | uptime_print: | |
466 | ||
467 | ldiw z,cnt_1ms | |
468 | ||
469 | cli | |
470 | ld temp,z+ | |
471 | push temp | |
472 | ld temp,z+ | |
473 | push temp | |
474 | ||
475 | ld temp,z+ | |
476 | ld temp2,z+ | |
477 | ld temp3,z+ | |
478 | sei | |
479 | ld temp4,z+ | |
480 | ||
481 | printnewline | |
482 | printstring "Uptime: " | |
483 | ||
484 | rcall print_ultoa | |
485 | printstring "," | |
486 | ||
487 | ldi temp3,0 | |
488 | ldi temp4,0 | |
489 | pop temp2 | |
490 | pop temp | |
491 | rcall print_ultoa | |
492 | printstring "s." | |
493 | ||
494 | ret | |
495 | ||
496 | ||
497 | ||
498 | ; --------------- Debugging stuff --------------- | |
499 | ; Print a line with the Z80 main registers | |
500 | ||
501 | ;.if INS_DEBUG | |
502 | ||
503 | zflags_to_ch: | |
504 | .db "SZ H PNC",0,0 | |
505 | ||
506 | printregs: | |
507 | printnewline | |
508 | ||
509 | push zl | |
510 | push zh | |
511 | ldiw z,zflags_to_ch*2 | |
512 | mov temp2,z_flags | |
513 | pr_zfl_next: | |
514 | lpm temp,z+ | |
515 | tst temp | |
516 | breq pr_zfl_end | |
517 | cpi temp,' ' ; Test if no flag | |
518 | breq pr_zfl_noflag | |
519 | sbrs temp2,7 ; | |
520 | ldi temp,' ' ; Flag not set | |
521 | rcall uartputc | |
522 | pr_zfl_noflag: | |
523 | rol temp2 | |
524 | rjmp pr_zfl_next | |
525 | pr_zfl_end: | |
526 | pop zh | |
527 | pop zl | |
528 | ||
529 | printstring " A =" | |
530 | mov temp,z_a | |
531 | rcall printhex | |
532 | printstring " BC =" | |
533 | lds temp2,z_b | |
534 | lds temp, z_c | |
535 | rcall printhexw | |
536 | printstring " DE =" | |
537 | lds temp2,z_d | |
538 | lds temp, z_e | |
539 | rcall printhexw | |
540 | printstring " HL =" | |
541 | lds temp2,z_h | |
542 | lds temp, z_l | |
543 | rcall printhexw | |
544 | printstring " SP =" | |
545 | movw temp, z_spl | |
546 | rcall printhexw | |
547 | printstring " PC =" | |
548 | movw temp, z_pcl | |
549 | rcall printhexw | |
550 | printstring " " | |
551 | movw xl,z_pcl | |
552 | mem_read | |
553 | rcall printhex | |
554 | printstring " " | |
555 | adiw x,1 | |
556 | mem_read | |
557 | rcall printhex | |
558 | printstring " " | |
559 | adiw x,1 | |
560 | mem_read | |
561 | rcall printhex | |
562 | printstring " " | |
563 | ret | |
564 | ;.endif | |
565 | ||
566 |