Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/rbdw3.asm @ 2298:d806d969eb17
Fixed a potential crash in Term
author | boisy |
---|---|
date | Thu, 31 Dec 2009 19:29:59 +0000 |
parents | 07b2433f0c65 |
children | f3e79ee2ffef |
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 | |
131 * Link to subroutine module | |
132 clra | |
133 leax name+2,pcr | |
134 os9 F$Link | |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
135 bcs InitEx |
2180 | 136 tfr y,u |
137 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
138 stu <D.DWSubAddr |
2180 | 139 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
140 stu >D.DWSubAddr |
2180 | 141 ENDC |
142 * Initialize the low level device | |
143 jsr ,u | |
144 lda #OP_INIT | |
145 leax ,s | |
146 ldy #$0001 | |
147 jsr 6,u | |
148 clrb | |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
149 |
2211 | 150 InitEx |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
151 IFGT Level-1 |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
152 puls a,x |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
153 stx <D.Proc |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
154 rts |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
155 ELSE |
2180 | 156 puls a,pc |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
157 ENDC |
2180 | 158 |
159 * Read | |
160 * | |
161 * Entry: | |
162 * B = MSB of LSN | |
163 * X = LSB of LSN | |
164 * Y = address of path descriptor | |
165 * U = address of device memory area | |
166 * | |
167 * Exit: | |
168 * CC = carry set on error | |
169 * B = error code | |
170 * | |
171 Read | |
172 lda #NUMRETRIES | |
173 sta retries,u | |
174 cmpx #$0000 LSN 0? | |
175 bne ReadSect branch if not | |
176 tstb LSN 0? | |
177 bne ReadSect branch if not | |
178 * At this point we're reading LSN0 | |
179 bsr ReadSect read the sector | |
180 bcs CpyLSNEx if error, exit | |
181 leax DRVBEG,u point to start of drive table | |
182 ldb <PD.DRV,y get drive number | |
183 NextDrv beq CopyLSN0 branch if terminal count | |
184 leax <DRVMEM,x else move to next drive table entry | |
185 decb decrement counter | |
186 bra NextDrv and continue | |
187 CopyLSN0 ldb #DD.SIZ get size to copy | |
188 ldy PD.BUF,y point to buffer | |
189 CpyLSNLp lda ,y+ get byte from buffer | |
190 sta ,x+ and save in drive table | |
191 decb | |
192 bne CpyLSNLp | |
193 CpyLSNEx rts | |
194 | |
195 | |
196 ReadSect pshs cc | |
197 pshs u,y,x,b,a,cc then push CC and others on stack | |
198 * Send out op code and 3 byte LSN | |
199 lda PD.DRV,y get drive number | |
200 cmpa #NumDrvs | |
201 blo Read1 | |
202 ldb #E$Unit | |
203 bra ReadEr2 | |
204 Read1 sta driveno,u | |
205 lda #OP_READEX load A with READ opcode | |
206 | |
207 Read2 | |
208 ldb driveno,u | |
209 leax ,s | |
210 std ,x | |
211 ldy #5 | |
212 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
213 ldu <D.DWSubAddr |
2180 | 214 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
215 ldu >D.DWSubAddr |
2180 | 216 ENDC |
217 orcc #IntMasks | |
218 jsr 6,u | |
219 | |
220 * Get 256 bytes of sector data | |
221 ldx 5,s | |
222 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
|
223 ldy #$0100 |
2180 | 224 jsr 3,u |
225 bcs ReadEr1 | |
226 bne ReadEr1 | |
227 pshs y | |
228 leax ,s | |
229 ldy #$0002 | |
230 jsr 6,u write checksum to server | |
231 | |
232 * Get error code byte | |
233 leax ,s | |
2231
27f07aa0bca0
Updated modules to use Darren Atkinson's latest changes to low level read/write routines
boisy
parents:
2211
diff
changeset
|
234 ldy #$0001 |
2180 | 235 jsr 3,u |
2194 | 236 bcs ReadEr0 branch if we timed out |
237 bne ReadEr0 | |
2180 | 238 puls d |
239 tfr a,b transfer byte to B (in case of error) | |
240 tstb is it zero? | |
241 beq ReadEx if not, exit with error | |
242 cmpb #E$CRC | |
243 bne ReadEr2 | |
244 ldu 7,s get U from stack | |
245 dec retries,u decrement retries | |
246 beq ReadEr1 | |
247 | |
248 lda #OP_REREADEX reread opcode | |
249 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
|
250 ReadEr0 puls d |
2180 | 251 ReadEr1 ldb #E$Read read error |
252 ReadEr2 lda 9,s | |
253 ora #Carry | |
254 sta 9,s | |
255 ReadEx leas 5,s | |
256 puls y,u | |
257 puls cc,pc | |
258 | |
259 * Write | |
260 * | |
261 * Entry: | |
262 * B = MSB of LSN | |
263 * X = LSB of LSN | |
264 * Y = address of path descriptor | |
265 * U = address of device memory area | |
266 * | |
267 * Exit: | |
268 * CC = carry set on error | |
269 * B = error code | |
270 * | |
271 Write lda #NUMRETRIES | |
272 sta retries,u | |
273 pshs cc | |
274 pshs u,y,x,b,a,cc | |
275 * Send out op code and 3 byte LSN | |
276 lda PD.DRV,y | |
277 cmpa #NumDrvs | |
278 blo Write1 | |
279 comb set Carry | |
280 ldb #E$Unit | |
281 bra WritEx | |
282 Write1 sta driveno,u | |
283 lda #OP_WRITE | |
284 Write15 | |
285 ldb driveno,u | |
286 leax ,s | |
287 std ,x | |
288 ldy #$0005 | |
289 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
290 ldu <D.DWSubAddr |
2180 | 291 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
292 ldu >D.DWSubAddr |
2180 | 293 ENDC |
294 orcc #IntMasks | |
295 jsr 6,u | |
296 | |
297 * Compute checksum on sector we just sent and send checksum to server | |
298 ldy 5,s get Y from stack | |
299 ldx PD.BUF,y point to buffer | |
300 ldy #256 | |
301 jsr 6,u | |
302 leax -256,x | |
303 bsr DoCSum | |
304 pshs d | |
305 leax ,s | |
306 ldy #$0002 | |
307 jsr 6,u | |
308 | |
309 * Await acknowledgement from server on receipt of sector | |
310 leax ,s | |
2231
27f07aa0bca0
Updated modules to use Darren Atkinson's latest changes to low level read/write routines
boisy
parents:
2211
diff
changeset
|
311 ldy #$0001 |
2180 | 312 jsr 3,u read ack byte from server |
2194 | 313 bcs WritEx0 |
314 bne WritEx0 | |
2180 | 315 puls d |
316 tsta | |
317 beq WritEx yep | |
318 tfr a,b | |
319 cmpb #E$CRC checksum error? | |
320 bne WritEx2 | |
321 ldu 7,s get U from stack | |
322 dec retries,u decrement retries | |
323 beq WritEx1 exit with error if no more | |
324 lda #OP_REWRIT else resend | |
325 bra Write15 | |
2194 | 326 WritEx0 puls d |
2180 | 327 WritEx1 ldb #E$Write |
328 WritEx2 lda 9,s | |
329 ora #Carry | |
330 sta 9,s | |
331 WritEx leas 5,s | |
332 puls y,u | |
333 puls cc,pc | |
334 | |
335 use dwcheck.asm | |
336 | |
337 * SetStat | |
338 * | |
339 * Entry: | |
340 * R$B = function code | |
341 * Y = address of path descriptor | |
342 * U = address of device memory area | |
343 * | |
344 * Exit: | |
345 * CC = carry set on error | |
346 * B = error code | |
347 * | |
348 SetStat lda #OP_SETSTA | |
349 * Size optimization | |
350 fcb $8C skip next two bytes | |
351 | |
352 | |
353 * GetStat | |
354 * | |
355 * Entry: | |
356 * R$B = function code | |
357 * Y = address of path descriptor | |
358 * U = address of device memory area | |
359 * | |
360 * Exit: | |
361 * CC = carry set on error | |
362 * B = error code | |
363 * | |
364 GetStat | |
365 lda #OP_GETSTA | |
366 clrb clear Carry | |
367 pshs cc and push CC on stack | |
368 leas -3,s | |
369 sta ,s | |
370 lda PD.DRV,y get drive number | |
371 ldx PD.RGS,y | |
372 ldb R$B,x | |
373 std 1,s | |
374 leax ,s | |
375 ldy #$0003 | |
376 IFGT LEVEL-1 | |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
377 ldu <D.DWSubAddr |
2180 | 378 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
379 ldu >D.DWSubAddr |
2180 | 380 ENDC |
381 jsr 6,u | |
382 leas 3,s | |
383 puls cc,pc | |
384 | |
385 emod | |
386 eom equ * | |
387 end |