Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/rbdw.asm @ 3130:e0614e08fa5e
l1 boot modules: Expand documentation and clean up code
Tidy up white-space and indentation.
Expand documentation to show C flag is important on return
from HWRead.
Expand documentation to show how/why/when filler is needed at
end of file.
Delete dead code in some places. No functional changes.
author | Neal Crook <foofoobedoo@gmail.com> |
---|---|
date | Sun, 04 Dec 2016 21:01:42 +0000 |
parents | 28ed72477814 |
children |
rev | line source |
---|---|
2180 | 1 ******************************************************************** |
2724
05b648103e78
Renamed dw3.sb to dwio.sb and rbdw3 to rbdw
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2718
diff
changeset
|
2 * rbdw - DriveWire RBF driver |
2180 | 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 |
2724
05b648103e78
Renamed dw3.sb to dwio.sb and rbdw3 to rbdw
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2718
diff
changeset
|
33 nam rbdw |
05b648103e78
Renamed dw3.sb to dwio.sb and rbdw3 to rbdw
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2718
diff
changeset
|
34 ttl DriveWire RBF driver |
2180 | 35 |
36 NUMRETRIES equ 8 | |
37 | |
38 ifp1 | |
39 use defsfile | |
2624 | 40 use drivewire.d |
2180 | 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 | |
2724
05b648103e78
Renamed dw3.sb to dwio.sb and rbdw3 to rbdw
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2718
diff
changeset
|
59 name fcs /rbdw/ |
2180 | 60 fcb edition |
61 | |
62 start bra Init | |
63 nop | |
2713
37d3ee1458b6
Fixed stupid mistake in branch table
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2656
diff
changeset
|
64 lbra Read |
2180 | 65 lbra Write |
66 lbra GetStat | |
67 lbra SetStat | |
68 | |
69 * Term | |
70 * | |
71 * Entry: | |
72 * U = address of device memory area | |
73 * | |
74 * Exit: | |
75 * CC = carry set on error | |
76 * B = error code | |
77 * | |
78 Term | |
2656
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
79 clrb |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
80 pshs cc |
2180 | 81 * Send OP_TERM to the server |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
82 IFGT LEVEL-1 |
2656
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
83 ldu <D.DWSubAddr |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
84 ELSE |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
85 ldu >D.DWSubAddr |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
86 ENDC |
2298 | 87 * Fix crash in certain cases |
2656
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
88 beq no@ |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
89 ldy #$0001 |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
90 lda #OP_TERM |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
91 pshs a |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
92 leax ,s |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
93 orcc #IntMasks |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
94 jsr DW$Write,u |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
95 clrb |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
96 puls a |
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
97 no@ 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 | |
2724
05b648103e78
Renamed dw3.sb to dwio.sb and rbdw3 to rbdw
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2718
diff
changeset
|
140 leax dwiosub,pcr |
2180 | 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 | |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
150 jsr DW$Init,u |
2180 | 151 lda #OP_INIT |
2640
8d24c482646e
o increased timeout in atari dwread.asm module
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2636
diff
changeset
|
152 sta ,s |
2180 | 153 leax ,s |
154 ldy #$0001 | |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
155 jsr DW$Write,u |
2180 | 156 clrb |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
157 |
2211 | 158 InitEx |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
159 IFGT Level-1 |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
160 puls a,x |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
161 stx <D.Proc |
2309 | 162 InitEx2 |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
163 rts |
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
164 ELSE |
2309 | 165 InitEx2 |
2180 | 166 puls a,pc |
2210
7ee1bed662f2
Fixed driver to copy D.SysPrc in Level 2 to D.Proc before link
boisy
parents:
2195
diff
changeset
|
167 ENDC |
2180 | 168 |
169 * Read | |
170 * | |
171 * Entry: | |
172 * B = MSB of LSN | |
173 * X = LSB of LSN | |
174 * Y = address of path descriptor | |
175 * U = address of device memory area | |
176 * | |
177 * Exit: | |
178 * CC = carry set on error | |
179 * B = error code | |
180 * | |
181 Read | |
182 lda #NUMRETRIES | |
183 sta retries,u | |
184 cmpx #$0000 LSN 0? | |
185 bne ReadSect branch if not | |
186 tstb LSN 0? | |
187 bne ReadSect branch if not | |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
188 * At this point we are reading LSN0 |
2180 | 189 bsr ReadSect read the sector |
190 bcs CpyLSNEx if error, exit | |
191 leax DRVBEG,u point to start of drive table | |
192 ldb <PD.DRV,y get drive number | |
193 NextDrv beq CopyLSN0 branch if terminal count | |
194 leax <DRVMEM,x else move to next drive table entry | |
195 decb decrement counter | |
196 bra NextDrv and continue | |
197 CopyLSN0 ldb #DD.SIZ get size to copy | |
198 ldy PD.BUF,y point to buffer | |
199 CpyLSNLp lda ,y+ get byte from buffer | |
200 sta ,x+ and save in drive table | |
201 decb | |
202 bne CpyLSNLp | |
203 CpyLSNEx rts | |
204 | |
205 | |
206 ReadSect pshs cc | |
207 pshs u,y,x,b,a,cc then push CC and others on stack | |
208 * Send out op code and 3 byte LSN | |
209 lda PD.DRV,y get drive number | |
210 cmpa #NumDrvs | |
211 blo Read1 | |
212 ldb #E$Unit | |
213 bra ReadEr2 | |
214 Read1 sta driveno,u | |
215 lda #OP_READEX load A with READ opcode | |
216 | |
217 Read2 | |
218 ldb driveno,u | |
219 leax ,s | |
220 std ,x | |
2656
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
221 ldy #5 |
2180 | 222 IFGT LEVEL-1 |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
223 ldu <D.DWSubAddr |
2180 | 224 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
225 ldu >D.DWSubAddr |
2180 | 226 ENDC |
227 orcc #IntMasks | |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
228 jsr DW$Write,u |
2180 | 229 |
230 * Get 256 bytes of sector data | |
231 ldx 5,s | |
232 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
|
233 ldy #$0100 |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
234 jsr DW$Read,u |
2180 | 235 bcs ReadEr1 |
236 bne ReadEr1 | |
237 pshs y | |
238 leax ,s | |
239 ldy #$0002 | |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
240 jsr DW$Write,u write checksum to server |
2180 | 241 |
242 * Get error code byte | |
243 leax ,s | |
2231
27f07aa0bca0
Updated modules to use Darren Atkinson's latest changes to low level read/write routines
boisy
parents:
2211
diff
changeset
|
244 ldy #$0001 |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
245 jsr DW$Read,u |
2656
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
246 puls d |
2194 | 247 bcs ReadEr0 branch if we timed out |
248 bne ReadEr0 | |
2180 | 249 tfr a,b transfer byte to B (in case of error) |
250 tstb is it zero? | |
251 beq ReadEx if not, exit with error | |
252 cmpb #E$CRC | |
253 bne ReadEr2 | |
254 ldu 7,s get U from stack | |
255 dec retries,u decrement retries | |
256 beq ReadEr1 | |
257 | |
258 lda #OP_REREADEX reread opcode | |
259 bra Read2 and try getting sector again | |
2656
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
260 ReadEr0 |
2180 | 261 ReadEr1 ldb #E$Read read error |
262 ReadEr2 lda 9,s | |
263 ora #Carry | |
264 sta 9,s | |
265 ReadEx leas 5,s | |
266 puls y,u | |
267 puls cc,pc | |
268 | |
269 * Write | |
270 * | |
271 * Entry: | |
272 * B = MSB of LSN | |
273 * X = LSB of LSN | |
274 * Y = address of path descriptor | |
275 * U = address of device memory area | |
276 * | |
277 * Exit: | |
278 * CC = carry set on error | |
279 * B = error code | |
280 * | |
281 Write lda #NUMRETRIES | |
282 sta retries,u | |
283 pshs cc | |
284 pshs u,y,x,b,a,cc | |
2656
2ebf5e737ceb
Updated to address Atari port problems
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2640
diff
changeset
|
285 ENDC |
2180 | 286 * Send out op code and 3 byte LSN |
287 lda PD.DRV,y | |
288 cmpa #NumDrvs | |
289 blo Write1 | |
290 comb set Carry | |
291 ldb #E$Unit | |
292 bra WritEx | |
293 Write1 sta driveno,u | |
294 lda #OP_WRITE | |
295 Write15 | |
296 ldb driveno,u | |
297 leax ,s | |
298 std ,x | |
299 ldy #$0005 | |
300 IFGT LEVEL-1 | |
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 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
303 ldu >D.DWSubAddr |
2180 | 304 ENDC |
305 orcc #IntMasks | |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
306 jsr DW$Write,u |
2180 | 307 |
308 * Compute checksum on sector we just sent and send checksum to server | |
309 ldy 5,s get Y from stack | |
310 ldx PD.BUF,y point to buffer | |
311 ldy #256 | |
312 jsr 6,u | |
313 leax -256,x | |
314 bsr DoCSum | |
315 pshs d | |
316 leax ,s | |
317 ldy #$0002 | |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
318 jsr DW$Write,u |
2180 | 319 |
320 * Await acknowledgement from server on receipt of sector | |
321 leax ,s | |
2231
27f07aa0bca0
Updated modules to use Darren Atkinson's latest changes to low level read/write routines
boisy
parents:
2211
diff
changeset
|
322 ldy #$0001 |
2636
4e5ff2c5b512
Optimized Term routine
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2624
diff
changeset
|
323 jsr DW$Read,u read ack byte from server |
2194 | 324 bcs WritEx0 |
325 bne WritEx0 | |
2180 | 326 puls d |
327 tsta | |
328 beq WritEx yep | |
329 tfr a,b | |
330 cmpb #E$CRC checksum error? | |
331 bne WritEx2 | |
332 ldu 7,s get U from stack | |
333 dec retries,u decrement retries | |
334 beq WritEx1 exit with error if no more | |
335 lda #OP_REWRIT else resend | |
336 bra Write15 | |
2194 | 337 WritEx0 puls d |
2180 | 338 WritEx1 ldb #E$Write |
339 WritEx2 lda 9,s | |
340 ora #Carry | |
341 sta 9,s | |
342 WritEx leas 5,s | |
343 puls y,u | |
344 puls cc,pc | |
345 | |
346 use dwcheck.asm | |
347 | |
348 * SetStat | |
349 * | |
350 * Entry: | |
351 * R$B = function code | |
352 * Y = address of path descriptor | |
353 * U = address of device memory area | |
354 * | |
355 * Exit: | |
356 * CC = carry set on error | |
357 * B = error code | |
358 * | |
359 SetStat lda #OP_SETSTA | |
360 * Size optimization | |
361 fcb $8C skip next two bytes | |
362 | |
363 | |
364 * GetStat | |
365 * | |
366 * Entry: | |
367 * R$B = function code | |
368 * Y = address of path descriptor | |
369 * U = address of device memory area | |
370 * | |
371 * Exit: | |
372 * CC = carry set on error | |
373 * B = error code | |
374 * | |
375 GetStat | |
376 lda #OP_GETSTA | |
377 clrb clear Carry | |
378 pshs cc and push CC on stack | |
379 leas -3,s | |
380 sta ,s | |
381 lda PD.DRV,y get drive number | |
382 ldx PD.RGS,y | |
383 ldb R$B,x | |
384 std 1,s | |
385 leax ,s | |
386 ldy #$0003 | |
387 IFGT LEVEL-1 | |
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 ELSE |
2270
07b2433f0c65
moved dwdefs.d to defs/, major changes to drivers due to new globals arrangement.
boisy
parents:
2231
diff
changeset
|
390 ldu >D.DWSubAddr |
2180 | 391 ENDC |
392 jsr 6,u | |
393 leas 3,s | |
394 puls cc,pc | |
2724
05b648103e78
Renamed dw3.sb to dwio.sb and rbdw3 to rbdw
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2718
diff
changeset
|
395 |
05b648103e78
Renamed dw3.sb to dwio.sb and rbdw3 to rbdw
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2718
diff
changeset
|
396 dwiosub fcs /dwio/ |
2180 | 397 |
398 emod | |
399 eom equ * | |
400 end |