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