]>
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 | #define REFR_PRE 8 /* timer prescale factor 1/8 */ | |
26 | #define REFR_CS 0x02 /* timer clock select for 1/8 */ | |
27 | #define REFR_CNT F_CPU / REFR_RATE / REFR_PRE | |
28 | ||
29 | .cseg | |
30 | regval_tab: | |
31 | .db 0,0 | |
32 | .db 0xFE,0xFC ; _RAS0 _CAS0 | |
33 | .db 0xF8,0xF4 ; _OE _WE | |
34 | .db 255,0 ; _255 _0 | |
35 | regval_tab_e: | |
36 | ||
37 | start: | |
38 | ldi temp,low(RAMEND) ; top of memory | |
39 | out SPL,temp ; init stack pointer | |
40 | ldi temp,high(RAMEND) ; top of memory | |
41 | out SPH,temp ; init stack pointer | |
42 | ||
43 | ; - Load some registers with constant values | |
44 | ||
45 | ldiw z,regval_tab*2 | |
46 | ldiw y,0 | |
47 | cp_l: lpm xh,z+ | |
48 | st y+,xh | |
49 | cpi zl,low(regval_tab_e*2) | |
50 | brne cp_l | |
51 | ||
52 | ; - Kill wdt | |
53 | ||
54 | wdr | |
55 | out MCUSR,_0 | |
56 | ||
57 | ldi temp,(1<<WDCE) | (1<<WDE) | |
58 | outm8 WDTCSR,temp | |
59 | ldi temp,(1<<WDCE) | |
60 | outm8 WDTCSR,temp | |
61 | ||
62 | ; - Setup Ports | |
63 | ||
64 | ldi temp,(1<<PUD) ;disable pullups | |
65 | outm8 P_PUD,temp | |
66 | out PORTD,_255 ;all pins high | |
67 | out PORTB,_255 | |
68 | out PORTC,_255 | |
69 | out DDRD,_255 ; all outputs | |
70 | out DDRB,_255 | |
71 | out DDRC,_255 | |
72 | cbi P_RXD-1,RXD ; RXD pin is input | |
73 | ||
74 | outm8 TIMSK1,_0 | |
75 | outm8 TIMSK2,_0 | |
76 | outm8 TCCR2A,_0 | |
77 | outm8 TCCR2B,_0 | |
78 | ||
79 | ; - Clear RAM | |
80 | ||
81 | ldiw z,SRAM_START | |
82 | ldi temp2,high(ramtop) | |
83 | clr_l: | |
84 | st z+,_0 | |
85 | cpi zl,low(ramtop) | |
86 | cpc zh,temp2 | |
87 | brne clr_l | |
88 | ||
89 | ||
90 | ; Init clock/timer system | |
91 | ||
92 | ; Init timer 1 as 1 ms system clock tick. | |
93 | ||
94 | ldi temp, low (F_CPU/1000) | |
95 | ldi temp2,high(F_CPU/1000) | |
96 | outm8 OCR1BH,temp2 | |
97 | outm8 OCR1BL,temp | |
98 | ldi temp,(1<<ICNC1)|(1<<CS10) ;Noise cancel, fall. edge, Normal Mode, clk/1 | |
99 | outm8 TCCR1B,temp | |
100 | inm8 temp,TIMSK1 | |
101 | ori temp,(1<<OCIE1B) ;Enable 1ms int. | |
102 | outm8 TIMSK1,temp | |
103 | ||
104 | ; - Init serial port | |
105 | ||
106 | rcall uart_init | |
107 | ||
108 | ;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles. | |
109 | ||
110 | ldi temp,REFR_CNT*2 ; 2 cycles per int | |
111 | outm8 OCR2A,temp | |
112 | inm8 temp,TCCR2A | |
113 | ori temp,(1<<WGM21) ;CTC mode | |
114 | outm8 TCCR2A,temp | |
115 | inm8 temp,TCCR2B | |
116 | ori temp,REFR_CS ;clk/REFR_PRE | |
117 | outm8 TCCR2B,temp | |
118 | inm8 temp,TIMSK2 | |
119 | ori temp, (1<<OCIE2A) | |
120 | outm8 TIMSK2,temp | |
121 | ||
122 | sei | |
123 | ||
124 | ||
125 | .if BOOTWAIT | |
126 | ldi temp,10 | |
127 | rcall delay_ms | |
128 | ||
129 | .endif | |
130 | ||
131 | rcall printstr | |
132 | .db 13,13,"CPM on an AVR, v" | |
133 | db_version VMAJOR, VMINOR | |
134 | ||
135 | .if MEMTEST | |
136 | printnewline | |
137 | printstring "Testing RAM: fill..." | |
138 | ||
139 | ;Fill RAM | |
140 | ldiw x,0 | |
141 | ramtestw: | |
142 | mov temp,xh | |
143 | eor temp,xl | |
144 | mem_write | |
145 | adiw xl,1 | |
146 | brcc ramtestw | |
147 | printstring "wait..." | |
148 | ||
149 | ldi temp2,8 | |
150 | ramtestwl: | |
151 | ldi temp,255 | |
152 | rcall delay_ms | |
153 | dec temp2 | |
154 | brne ramtestwl | |
155 | ||
156 | printstring "reread..." | |
157 | ||
158 | ;re-read RAM | |
159 | ldiw x,0 | |
160 | clr temp3 | |
161 | ramtestr: | |
162 | mem_read | |
163 | mov temp2,xh | |
164 | eor temp2,xl | |
165 | cp temp,temp2 | |
166 | breq ramtestrok | |
167 | push temp | |
168 | cpi temp3,0 ;if first error | |
169 | brne ramtest2 | |
170 | inc temp3 | |
171 | ldi temp,10 ;newline | |
172 | rcall uartPutc | |
173 | ramtest2: | |
174 | ldi temp,13 ;return | |
175 | rcall uartPutc | |
176 | pop temp | |
177 | rcall printhex | |
178 | ldi temp,'<' | |
179 | rcall uartPutc | |
180 | mov temp,xh | |
181 | eor temp,xl | |
182 | rcall printhex | |
183 | ldi temp,'@' | |
184 | rcall uartPutc | |
185 | movw temp,x | |
186 | rcall printhexw | |
187 | ramtestrok: | |
188 | adiw xl,1 | |
189 | brcc ramtestr | |
190 | ||
191 | .endif | |
192 | ||
193 | .if MEMFILL | |
194 | ldiw x,0 | |
195 | ramfillw: | |
196 | ldi temp,MEMFILL_VAL | |
197 | mem_write | |
198 | adiw xl,1 | |
199 | brcc ramfillw | |
200 | .endif | |
201 | ||
202 | ||
203 | ;---------------------------------------------------------------------------- | |
204 | ||
205 | boot_again: | |
206 | printnewline | |
207 | printstring "Initing mmc...",0 | |
208 | rcall dsk_partinit | |
209 | ||
210 | cbr temp,0x80 | |
211 | brne boot_ipl2 | |
212 | printstring "No bootable CP/M disk found! Please change MMC/SD-Card." | |
213 | ldi temp2,18 | |
214 | boot_iplwl: | |
215 | ldi temp,255 | |
216 | rcall delay_ms | |
217 | dec temp2 | |
218 | brne boot_iplwl | |
219 | rjmp boot_again | |
220 | ||
221 | ||
222 | boot_ipl2: | |
223 | rcall prnt_parttbl | |
224 | printnewline | |
225 | printstring "Partinit done." | |
226 | ||
227 | ; Read first sector of first CP/M partition | |
228 | ||
229 | lds xl,hostparttbl | |
230 | lds xh,hostparttbl+1 | |
231 | lds yl,hostparttbl+2 | |
232 | lds yh,hostparttbl+3 | |
233 | rcall mmcReadSect | |
234 | ||
235 | rcall dsk_cboot ;init (de)blocking buffer | |
236 | ||
237 | ;First sector of disk or first CP/M partition is in hostbuf. | |
238 | ||
239 | ;Save to Z80 RAM (only 128 bytes because that's retro) | |
240 | ldiw z,hostbuf | |
241 | ldiw x,IPLADDR | |
242 | iplwriteloop: | |
243 | ld temp,z+ | |
244 | mem_write | |
245 | adiw xl,1 | |
246 | cpi zl,low(hostbuf+128) | |
247 | brne iplwriteloop | |
248 | cpi zh,high(hostbuf+128) | |
249 | brne iplwriteloop | |
250 | rjmp z80_init | |
251 | ||
252 |