Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/rbdw3.asm @ 2535:44f8ba0d87a4
Fixed crash in init routine
author | boisy |
---|---|
date | Wed, 28 Apr 2010 04:07:18 +0000 |
parents | f3e79ee2ffef |
children | b8c7b7fbf3c9 |
rev | line source |
---|---|
2180 | 1 ******************************************************************** |
2 * rbdw3 - DriveWire 3 driver | |
3 * | |
4 * $Id$ | |
5 * | |
6 * This driver works in conjuction with the DriveWire Server on Linux, | |
7 * Mac or Windows, providing the CoCo with pseudo-disk access through | |
8 * the serial port. | |
9 * | |
10 * It adheres to the DriveWire Version 3 Protocol. | |
11 * | |
12 * The baud rate is set at 115200 and the communications requirements | |
13 * are set to 8-N-1. For OS-9 Level One on a CoCo 2, the baud rate | |
14 * is 57600. | |
15 * | |
16 * Edt/Rev YYYY/MM/DD Modified by | |
17 * Comment | |
18 * ------------------------------------------------------------------ | |
19 * 1 2008/02/08 Boisy G. Pitre | |
20 * Started from drivewire.asm in DriveWire 2 Product folder. | |
21 * | |
22 * 2 2008/04/22 Boisy G. Pitre | |
23 * Verified working operation on a CoCo 3 running NitrOS-9/6809 Level 1 @ 57.6Kbps | |
2194 | 24 * |
25 * 3 2009/03/09 Boisy G. Pitre | |
26 * Added checks for size after reading as noted by Darren A's email. | |
2298 | 27 * |
28 * 4 2009/12/31 Boisy G. Pitre | |
29 * Fixed a crash in Term by adding a check for DWSubAddr of $0000 | |
30 * (possible if Init fails due to subroutine module not being in | |
31 * memory and I$Detach calls Term) | |
2180 | 32 |
33 nam rbdw3 | |
34 ttl DriveWire 3 driver | |
35 | |
36 NUMRETRIES equ 8 | |
37 | |
38 ifp1 | |
39 use defsfile | |
40 use dwdefs.d | |
41 endc | |
42 | |
43 NumDrvs set 4 | |
44 | |
45 tylg set Drivr+Objct | |
46 atrv set ReEnt+rev | |
47 rev set $01 | |
2298 | 48 edition set 4 |
2180 | 49 |
50 mod eom,name,tylg,atrv,start,size | |
51 | |
52 rmb DRVBEG+(DRVMEM*NumDrvs) | |
53 driveno rmb 1 | |
54 retries rmb 1 | |
55 size equ . | |
56 | |
57 fcb DIR.+SHARE.+PEXEC.+PREAD.+PWRIT.+EXEC.+UPDAT. | |
58 | |
59 name fcs /rbdw3/ | |
60 fcb edition | |
61 | |
62 start bra Init | |
63 nop | |
64 bra Read | |
65 nop | |
66 lbra Write | |
67 lbra GetStat | |
68 lbra SetStat | |
69 | |
70 * Term | |
71 * | |
72 * Entry: | |
73 * U = address of device memory area | |
74 * | |
75 * Exit: | |
76 * CC = carry set on error | |
77 * B = error code | |
78 * | |
79 Term | |
80 * Send OP_TERM to the server | |
81 clrb clear Carry | |
2298 | 82 pshs cc then push CC on stack |
2180 | 83 lda #OP_TERM |
2298 | 84 pshs a |
85 leax ,s | |
2180 | 86 ldy #$0001 |
87 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
88 ldu <D.DWSubAddr |
2180 | 89 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
90 ldu >D.DWSubAddr |
2180 | 91 ENDC |
2298 | 92 * Fix crash in certain cases |
93 beq no@ | |
94 orcc #IntMasks | |
2180 | 95 jsr 6,u |
2298 | 96 no@ puls a |
97 puls cc,pc | |
2180 | 98 |
99 * Init | |
100 * | |
101 * Entry: | |
102 * Y = address of device descriptor | |
103 * U = address of device memory area | |
104 * | |
105 * Exit: | |
106 * CC = carry set on error | |
107 * B = error code | |
108 * | |
109 Init | |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
110 IFGT Level-1 |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
111 * Perform this so we can successfully do F$Link below |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
112 ldx <D.Proc |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
113 pshs a,x |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
114 ldx <D.SysPrc |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
115 stx <D.Proc |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
116 ELSE |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
117 pshs a |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
118 ENDC |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
119 |
2180 | 120 ldb #NumDrvs |
121 stb V.NDRV,u | |
122 leax DRVBEG,u | |
123 lda #$FF | |
124 Init2 sta DD.TOT,x invalidate drive tables | |
125 sta DD.TOT+1,x | |
126 sta DD.TOT+2,x | |
127 leax DRVMEM,x | |
128 decb | |
129 bne Init2 | |
130 | |
2309 | 131 * Check if subroutine module has already been linked |
132 IFGT LEVEL-1 | |
133 ldu <D.DWSubAddr | |
134 ELSE | |
135 ldu >D.DWSubAddr | |
136 ENDC | |
2535 | 137 bne InitEx |
2180 | 138 * Link to subroutine module |
139 clra | |
140 leax name+2,pcr | |
141 os9 F$Link | |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
142 bcs InitEx |
2180 | 143 tfr y,u |
144 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
145 stu <D.DWSubAddr |
2180 | 146 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
147 stu >D.DWSubAddr |
2180 | 148 ENDC |
149 * Initialize the low level device | |
150 jsr ,u | |
151 lda #OP_INIT | |
152 leax ,s | |
153 ldy #$0001 | |
154 jsr 6,u | |
155 clrb | |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
156 |
2211 | 157 InitEx |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
158 IFGT Level-1 |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
159 puls a,x |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
160 stx <D.Proc |
2309 | 161 InitEx2 |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
162 rts |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
163 ELSE |
2309 | 164 InitEx2 |
2180 | 165 puls a,pc |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
166 ENDC |
2180 | 167 |
168 * Read | |
169 * | |
170 * Entry: | |
171 * B = MSB of LSN | |
172 * X = LSB of LSN | |
173 * Y = address of path descriptor | |
174 * U = address of device memory area | |
175 * | |
176 * Exit: | |
177 * CC = carry set on error | |
178 * B = error code | |
179 * | |
180 Read | |
181 lda #NUMRETRIES | |
182 sta retries,u | |
183 cmpx #$0000 LSN 0? | |
184 bne ReadSect branch if not | |
185 tstb LSN 0? | |
186 bne ReadSect branch if not | |
187 * At this point we're reading LSN0 | |
188 bsr ReadSect read the sector | |
189 bcs CpyLSNEx if error, exit | |
190 leax DRVBEG,u point to start of drive table | |
191 ldb <PD.DRV,y get drive number | |
192 NextDrv beq CopyLSN0 branch if terminal count | |
193 leax <DRVMEM,x else move to next drive table entry | |
194 decb decrement counter | |
195 bra NextDrv and continue | |
196 CopyLSN0 ldb #DD.SIZ get size to copy | |
197 ldy PD.BUF,y point to buffer | |
198 CpyLSNLp lda ,y+ get byte from buffer | |
199 sta ,x+ and save in drive table | |
200 decb | |
201 bne CpyLSNLp | |
202 CpyLSNEx rts | |
203 | |
204 | |
205 ReadSect pshs cc | |
206 pshs u,y,x,b,a,cc then push CC and others on stack | |
207 * Send out op code and 3 byte LSN | |
208 lda PD.DRV,y get drive number | |
209 cmpa #NumDrvs | |
210 blo Read1 | |
211 ldb #E$Unit | |
212 bra ReadEr2 | |
213 Read1 sta driveno,u | |
214 lda #OP_READEX load A with READ opcode | |
215 | |
216 Read2 | |
217 ldb driveno,u | |
218 leax ,s | |
219 std ,x | |
220 ldy #5 | |
221 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
222 ldu <D.DWSubAddr |
2180 | 223 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
224 ldu >D.DWSubAddr |
2180 | 225 ENDC |
226 orcc #IntMasks | |
227 jsr 6,u | |
228 | |
229 * Get 256 bytes of sector data | |
230 ldx 5,s | |
231 ldx PD.BUF,x get buffer pointer into X | |
2231
27f07aa0bca0
Updated modules to use Darren Atkinson's latest changes to low level read/write routines
boisy
parents:
2211
diff
changeset
|
232 ldy #$0100 |
2180 | 233 jsr 3,u |
234 bcs ReadEr1 | |
235 bne ReadEr1 | |
236 pshs y | |
237 leax ,s | |
238 ldy #$0002 | |
239 jsr 6,u write checksum to server | |
240 | |
241 * Get error code byte | |
242 leax ,s | |
2231
27f07aa0bca0
Updated modules to use Darren Atkinson's latest changes to low level read/write routines
boisy
parents:
2211
diff
changeset
|
243 ldy #$0001 |
2180 | 244 jsr 3,u |
2194 | 245 bcs ReadEr0 branch if we timed out |
246 bne ReadEr0 | |
2180 | 247 puls d |
248 tfr a,b transfer byte to B (in case of error) | |
249 tstb is it zero? | |
250 beq ReadEx if not, exit with error | |
251 cmpb #E$CRC | |
252 bne ReadEr2 | |
253 ldu 7,s get U from stack | |
254 dec retries,u decrement retries | |
255 beq ReadEr1 | |
256 | |
257 lda #OP_REREADEX reread opcode | |
258 bra Read2 and try getting sector again | |
2195
8b38d4f75b44
Addressed issue raised by Darren A about checking error code size
boisy
parents:
2194
diff
changeset
|
259 ReadEr0 puls d |
2180 | 260 ReadEr1 ldb #E$Read read error |
261 ReadEr2 lda 9,s | |
262 ora #Carry | |
263 sta 9,s | |
264 ReadEx leas 5,s | |
265 puls y,u | |
266 puls cc,pc | |
267 | |
268 * Write | |
269 * | |
270 * Entry: | |
271 * B = MSB of LSN | |
272 * X = LSB of LSN | |
273 * Y = address of path descriptor | |
274 * U = address of device memory area | |
275 * | |
276 * Exit: | |
277 * CC = carry set on error | |
278 * B = error code | |
279 * | |
280 Write lda #NUMRETRIES | |
281 sta retries,u | |
282 pshs cc | |
283 pshs u,y,x,b,a,cc | |
284 * Send out op code and 3 byte LSN | |
285 lda PD.DRV,y | |
286 cmpa #NumDrvs | |
287 blo Write1 | |
288 comb set Carry | |
289 ldb #E$Unit | |
290 bra WritEx | |
291 Write1 sta driveno,u | |
292 lda #OP_WRITE | |
293 Write15 | |
294 ldb driveno,u | |
295 leax ,s | |
296 std ,x | |
297 ldy #$0005 | |
298 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
299 ldu <D.DWSubAddr |
2180 | 300 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
301 ldu >D.DWSubAddr |
2180 | 302 ENDC |
303 orcc #IntMasks | |
304 jsr 6,u | |
305 | |
306 * Compute checksum on sector we just sent and send checksum to server | |
307 ldy 5,s get Y from stack | |
308 ldx PD.BUF,y point to buffer | |
309 ldy #256 | |
310 jsr 6,u | |
311 leax -256,x | |
312 bsr DoCSum | |
313 pshs d | |
314 leax ,s | |
315 ldy #$0002 | |
316 jsr 6,u | |
317 | |
318 * Await acknowledgement from server on receipt of sector | |
319 leax ,s | |
2231
27f07aa0bca0
Updated modules to use Darren Atkinson's latest changes to low level read/write routines
boisy
parents:
2211
diff
changeset
|
320 ldy #$0001 |
2180 | 321 jsr 3,u read ack byte from server |
2194 | 322 bcs WritEx0 |
323 bne WritEx0 | |
2180 | 324 puls d |
325 tsta | |
326 beq WritEx yep | |
327 tfr a,b | |
328 cmpb #E$CRC checksum error? | |
329 bne WritEx2 | |
330 ldu 7,s get U from stack | |
331 dec retries,u decrement retries | |
332 beq WritEx1 exit with error if no more | |
333 lda #OP_REWRIT else resend | |
334 bra Write15 | |
2194 | 335 WritEx0 puls d |
2180 | 336 WritEx1 ldb #E$Write |
337 WritEx2 lda 9,s | |
338 ora #Carry | |
339 sta 9,s | |
340 WritEx leas 5,s | |
341 puls y,u | |
342 puls cc,pc | |
343 | |
344 use dwcheck.asm | |
345 | |
346 * SetStat | |
347 * | |
348 * Entry: | |
349 * R$B = function code | |
350 * Y = address of path descriptor | |
351 * U = address of device memory area | |
352 * | |
353 * Exit: | |
354 * CC = carry set on error | |
355 * B = error code | |
356 * | |
357 SetStat lda #OP_SETSTA | |
358 * Size optimization | |
359 fcb $8C skip next two bytes | |
360 | |
361 | |
362 * GetStat | |
363 * | |
364 * Entry: | |
365 * R$B = function code | |
366 * Y = address of path descriptor | |
367 * U = address of device memory area | |
368 * | |
369 * Exit: | |
370 * CC = carry set on error | |
371 * B = error code | |
372 * | |
373 GetStat | |
374 lda #OP_GETSTA | |
375 clrb clear Carry | |
376 pshs cc and push CC on stack | |
377 leas -3,s | |
378 sta ,s | |
379 lda PD.DRV,y get drive number | |
380 ldx PD.RGS,y | |
381 ldb R$B,x | |
382 std 1,s | |
383 leax ,s | |
384 ldy #$0003 | |
385 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
386 ldu <D.DWSubAddr |
2180 | 387 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
388 ldu >D.DWSubAddr |
2180 | 389 ENDC |
390 jsr 6,u | |
391 leas 3,s | |
392 puls cc,pc | |
393 | |
394 emod | |
395 eom equ * | |
396 end |