Mercurial > hg > Members > kono > nitros9-code
comparison 3rdparty/booters/boot_mmc.asm @ 1168:3be7fce1a56b
Added Jim Hathaway's MMC booter, made other source changes
author | boisy |
---|---|
date | Mon, 19 May 2003 11:22:34 +0000 |
parents | |
children | 481618f41f1d |
comparison
equal
deleted
inserted
replaced
1167:a3d0ac951684 | 1168:3be7fce1a56b |
---|---|
1 ******************************************************************** | |
2 * Boot - MMC Boot Module | |
3 * | |
4 * $Id$ | |
5 * | |
6 * This module allows booting from MMC devices using Jim Hathaway's | |
7 * MMC Interface for the Color Computer. | |
8 * | |
9 * This booter was created on May 17th, 2003 by Jim Hathaway and Boisy Pitre | |
10 * at the 12th Annual "Last" Chicago CoCoFEST! in Elgin, Illinois at the | |
11 * Cloud-9 booth. | |
12 * | |
13 * Ed. Comments Who YY/MM/DD | |
14 * ------------------------------------------------------------------ | |
15 * 1 Created JH 03/05/17 | |
16 | |
17 nam Boot | |
18 ttl MMC Boot Module | |
19 | |
20 ifp1 | |
21 use defsfile | |
22 endc | |
23 | |
24 tylg set Systm+Objct | |
25 atrv set ReEnt+rev | |
26 rev set 2 | |
27 edition set 1 | |
28 | |
29 mod eom,name,tylg,atrv,start,size | |
30 | |
31 blockloc rmb 2 pointer to memory requested | |
32 blockimg rmb 2 duplicate of the above | |
33 bootloc rmb 3 sector pointer; not byte pointer | |
34 bootsize rmb 2 size in bytes | |
35 size equ . | |
36 | |
37 name fcs /Boot/ | |
38 fcb edition | |
39 | |
40 start clra | |
41 ldb #size | |
42 clean pshs a | |
43 decb | |
44 bne clean | |
45 tfr s,u get pointer to data area | |
46 pshs u save pointer to data area | |
47 | |
48 lda #$d0 forced interrupt; kill floppy activity | |
49 sta $FF48 command register | |
50 | |
51 clrb | |
52 pause decb | |
53 bne pause | |
54 lda $FF48 clear controller | |
55 clr $FF40 make sure motors are turned off | |
56 | |
57 * Init hardware | |
58 lbsr INITCRD | |
59 bcs error | |
60 | |
61 * Request memory for LSN0 | |
62 ldd #1 | |
63 os9 F$SRqMem request one page of RAM | |
64 bcs error | |
65 bsr getpntr | |
66 | |
67 * Get LSN0 into memory | |
68 clrb MSB sector | |
69 ldx #0 LSW sector | |
70 bsr mread | |
71 bcs error | |
72 ldd bootsize,u | |
73 bcs error | |
74 pshs d | |
75 | |
76 * Return memory | |
77 ldd #$100 | |
78 ldu blockloc,u | |
79 os9 F$SRtMem | |
80 puls d | |
81 ifgt Level-1 | |
82 os9 F$BtMem | |
83 else | |
84 os9 F$SRqMem | |
85 endc | |
86 bcs error | |
87 bsr getpntr | |
88 std blockimg,u | |
89 | |
90 * Get os9boot into memory | |
91 ldd bootsize,u | |
92 leas -2,s same as a PSHS D | |
93 getboot std ,s | |
94 ldb bootloc,u MSB sector location | |
95 ldx bootloc+1,u LSW sector location | |
96 bsr mread | |
97 ldd bootloc+1,u update sector location by one to 24bit word | |
98 addd #1 | |
99 std bootloc+1,u | |
100 ldb bootloc,u | |
101 adcb #0 | |
102 stb bootloc,u | |
103 inc blockloc,u update memory pointer for upload | |
104 ldd ,s update size of file left to read | |
105 subd #$100 file read one sector at a time | |
106 bhi getboot | |
107 | |
108 leas 4+size,s reset the stack same as PULS U,D | |
109 ldd bootsize,u | |
110 ldx blockimg,u pointer to start of os9boot in memory | |
111 andcc #^Carry clear carry | |
112 rts back to os9p1 | |
113 | |
114 error leas 2+size,s | |
115 rts | |
116 | |
117 getpntr tfr u,d save pointer to requested memory | |
118 ldu 2,s recover pointer to data stack | |
119 std blockloc,u | |
120 rts | |
121 | |
122 mread tstb | |
123 bne hwread | |
124 cmpx #0 | |
125 bne hwread | |
126 bsr hwread | |
127 bcc readlsn0 | |
128 rts | |
129 | |
130 readlsn0 pshs a,x,y | |
131 ldy blockloc,u | |
132 lda DD.Bt,y os9boot pointer | |
133 ldx DD.Bt+1,y LSW of 24 bit address | |
134 sta bootloc,u | |
135 stx bootloc+1,u | |
136 ldx DD.BSZ,y os9boot size in bytes | |
137 stx bootsize,u | |
138 clrb | |
139 puls a,x,y,pc | |
140 | |
141 * Generic read | |
142 hwread pshs x | |
143 lbsr READ | |
144 puls x,pc | |
145 | |
146 | |
147 CMDREAD equ $51 Command to read a single block | |
148 MMCCSB equ $80 MMC control register slow clock bit | |
149 MMCCRO equ 1 MMC control register offset from data port | |
150 MMCDPR equ $FF7A MMC Data port register | |
151 | |
152 | |
153 | |
154 ******************************** | |
155 * Command bytes storage area | |
156 ******************************** | |
157 CMD0 fcb $40,0,0,0 | |
158 CMD1 fcb $41,0,0,0 | |
159 CMD171 fcb $50,0,0,1 | |
160 | |
161 *************************************************************** | |
162 * Send a command string to the MMC (6 bytes) 4 user 2 hard code | |
163 * Entry: y= Pointer to command string to send | |
164 * x= MMC data register | |
165 * b= Not used | |
166 * a= Used to copy data | |
167 *************************************************************** | |
168 SNDC lda ,y Get cmd byte 1 | |
169 sta ,x Send command byte | |
170 lbsr DLYSTRT Call our delay routine | |
171 lda 1,y Get cmd byte 2 | |
172 sta ,x Send command byte | |
173 lbsr DLYSTRT Call our delay routine | |
174 lda 2,y Get cmd byte 3 | |
175 sta ,x Send command byte | |
176 lbsr DLYSTRT Call our delay routine | |
177 lda 3,y Get cmd byte 4 | |
178 sta ,x Send command byte | |
179 lbsr DLYSTRT Call our delay routine | |
180 lda #0 Get cmd byte 5 | |
181 sta ,x Send command byte | |
182 lbsr DLYSTRT Call our delay routine | |
183 lda #$95 Get cmd byte 6 | |
184 sta ,x Send command byte | |
185 lbsr DLYSTRT Call our delay routine | |
186 rts Complete sending command return | |
187 | |
188 *********************************************************** | |
189 * CHKR - Check card response | |
190 * Used to check response from a card | |
191 * Entry: a= Expected Response byte code | |
192 * b= used for loop / set on exit to flag error/no error | |
193 *********************************************************** | |
194 CHKR pshs b Save reg b | |
195 clrb Use for loop counter | |
196 CHKRL1 bsr DLYSTRT Call our delay routine | |
197 cmpa ,x Check for response | |
198 beq CHKRG Response is good, exit without error | |
199 decb Keep looping? | |
200 bne CHKRL1 Done yet? | |
201 CHKRB comb Set error state | |
202 puls b,pc Return | |
203 CHKRG clrb Set no error | |
204 puls b,pc Return | |
205 * End CHKR routine | |
206 | |
207 ********************************************************************* | |
208 * DLYSTRT: Delay routine for use as a delay for sending commands | |
209 * or clock pulses as the slower spi rate. | |
210 * Delay is hard coded at $14 | |
211 * All registers perserved | |
212 ********************************************************************* | |
213 DLYSTRT pshs b Save b register for return | |
214 ldb #$14 Default delay needed | |
215 DLYLP1 decb Start of delay loop | |
216 bne DLYLP1 End of delay loop | |
217 puls b,pc Get value of b register back | |
218 * End delay routine | |
219 | |
220 ************************************************************ | |
221 * INITCRD: Init a single card, no register values needed, | |
222 * all preserved | |
223 * Entry: y = Used, and not preserved | |
224 * x = Address to MMC data port | |
225 ************************************************************ | |
226 INITCRD ldx #MMCDPR Address to MMC | |
227 lda #MMCCSB Select no cards and slow speed | |
228 sta MMCCRO,x Store to control register | |
229 lda #$0A A= 10 clocks | |
230 CLKPL1 tst ,x Pulse the clock 80 times to init all cards | |
231 bsr DLYSTRT Call our delay routine | |
232 deca Loop counter | |
233 bne CLKPL1 Keep looping till we send 80 clocks | |
234 | |
235 lda #$81 Select crd 1 @ slow speed | |
236 sta MMCCRO,x Write to MMC control register slow speed | |
237 leay CMD0,pcr Load address into y for cmd0 | |
238 lbsr SNDC Go send the command (cmd0) | |
239 | |
240 lda #$01 Expected response | |
241 lbsr CHKR Go check for response bit | |
242 lbcs INITCE1 | |
243 | |
244 ldb #20 Number of times to send CMD1 before error | |
245 | |
246 leay CMD1,pcr Load address into y for cmd1 | |
247 INCMD1L lbsr SNDC Go send the command (cmd1) | |
248 | |
249 lda #$00 Expected response | |
250 lbsr CHKR Go check for response bit | |
251 bcc INC1C We got our response, continue | |
252 | |
253 decb Loop counter | |
254 bne INCMD1L Keep trying to get a response of 0 | |
255 lbcc INC1C | |
256 lda #81 | |
257 lbra INITCE1 This card is not ready exit | |
258 | |
259 INC1C lda #$01 Get card number, always use card 0 | |
260 sta MMCCRO,x Write to MMC control register full speed | |
261 leay CMD171,pcr Get command to change sector to 256 bytes | |
262 lbsr SNDC Go send the command (cmd17-1) | |
263 | |
264 lda #0 Expected response | |
265 lbsr CHKR Go check for response byte | |
266 bcs INITCE1 | |
267 | |
268 clrb No error | |
269 puls pc Clean exit | |
270 | |
271 INITCE1 comb Error, we could not init card | |
272 tfr a,b | |
273 puls pc | |
274 * End of INITCRD | |
275 | |
276 ***************************************************************** | |
277 * READ - Read a single 256 byte sector. | |
278 * y= Location to store data to | |
279 * b,x= LSN number | |
280 * x not preserved | |
281 ***************************************************************** | |
282 READ pshs d,x Save LSN | |
283 ldy blockloc,u | |
284 lda #$1 Get drive #1 | |
285 sta MMCCRO+MMCDPR Select card 1 | |
286 lda MMCDPR Burn a byte - bug fix | |
287 | |
288 lda #CMDREAD Read cmd byte 1 | |
289 sta MMCDPR Save read command | |
290 nop Delay | |
291 stb MMCDPR Save cmd byte 2 | |
292 tfr x,d Move the rest of the LSN | |
293 sta MMCDPR Save cmd byte 3 | |
294 ldx #MMCDPR Get MMC address and delay | |
295 stb ,x Save cmd byte 4 | |
296 lda #$0 Cmd byte 5 | |
297 sta ,x Save cmd byte 5 | |
298 lda #$95 Cmd byte 6 CRC | |
299 sta ,x Save cmd byte 6 | |
300 | |
301 RDN2 lda #$FE Expected response | |
302 lbsr CHKR Check for response | |
303 bcs RDEEX1 Card should have read sector, read error! | |
304 | |
305 clra Number of loops 256 | |
306 RDLP1 ldb ,x Get byte from MMC | |
307 stb ,y+ Save byte | |
308 deca Loop counter | |
309 bne RDLP1 | |
310 | |
311 ldd ,x Get CRC Byte 1 | |
312 lda ,x Get CRC Byte 2 | |
313 | |
314 RDEX1 clr MMCCRO,x Deselect any cards in use | |
315 clrb Set no errors | |
316 puls d,x,pc Read complete with no errors | |
317 RDEEX1 clr MMCCRO,x Deselect any cards in use | |
318 comb Error reading sector | |
319 puls d,x,pc Return with error | |
320 * End of READ | |
321 | |
322 | |
323 ifgt Level-1 | |
324 * Fillers to get to $1D0 | |
325 Pad fill $39,$1D0-3-* | |
326 endc | |
327 | |
328 emod | |
329 eom equ * | |
330 end | |
331 |