402
|
1 ********************************************************************
|
|
2 * Emudsk - Virtual disk driver for CoCo emulators
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Ed. Comments Who YY/MM/DD
|
|
7 * ------------------------------------------------------------------
|
|
8 * 01 Modified to compile under OS9Source tjl 02/08/28
|
|
9
|
|
10 * EmuDisk floppy disk controller driver
|
|
11 * Edition #1
|
|
12 * 04/18/96 : Written from scratch by Alan DeKok
|
|
13 * aland@sandelman.ocunix.on.ca
|
|
14 *
|
|
15 * This program is Copyright (C) 1996 by Alan DeKok,
|
|
16 * All Rights Reserved.
|
|
17 * License is given to individuals for personal use only.
|
|
18 *
|
|
19 *
|
|
20 * Comments: Ensure that device descriptors mark it as a hard drive
|
|
21 *
|
|
22 *
|
|
23 * $FF80-$FF82: logical record number
|
|
24 LSN equ $FF80 where to put the logical sector number
|
|
25
|
|
26 *
|
|
27 * $FF83: command/status register.
|
|
28 * Output: 0=read, 1=write, 2=close.
|
|
29 * Input: 0=no error, non-zero=error codes (see below).
|
|
30 command equ $FF83 where to put the commands
|
|
31
|
|
32 *
|
|
33 * $FF84-$FF85: 6809's 16-bit buffer address (cannot cross an 8K boundary due
|
|
34 * to interference from the MMU emulation).
|
|
35 buffer equ $FF84 pointer to the buffer
|
|
36
|
|
37 *
|
|
38 * Returns:
|
|
39 *
|
|
40 * 0=successful
|
|
41 * 2=not enabled
|
|
42 * 4=too many MS-DOS files open,
|
|
43 * 5=access denied (virtual HD file locked by another program
|
|
44 * or MS-DOS read-only status)
|
|
45 * 6/12=internal error
|
|
46 * 254=invalid command byte
|
|
47 * 255=power-on state or closed.
|
|
48 *
|
|
49 * The "close" command just flushes all the read/write buffers and
|
|
50 * restores the metacontroller to its power-up state. The hard drive must be
|
|
51 * enabled by the user using the MS-DOS command "ECHO >COCO3.VHD" (another
|
|
52 * crash safeguard), so error code 2 indicates this has not been done.
|
|
53
|
|
54
|
|
55 nam EmuDsk
|
|
56 ttl os9 device driver
|
|
57
|
|
58 ifp1
|
|
59 use os9defs
|
|
60 use rbfdefs
|
|
61 endc
|
|
62
|
|
63 tylg set Drivr+Objct
|
|
64 atrv set ReEnt+rev
|
|
65 rev set $01
|
|
66
|
|
67 mod eom,name,tylg,atrv,start,size
|
|
68 fcb $ff
|
|
69
|
|
70 org 0
|
|
71 u0000 rmb $FF Normal RBF device mem for 4 drives
|
|
72 size equ .
|
|
73
|
|
74 fcb $FF This byte is the driver permissions
|
|
75 name fcs /EmuDsk/
|
|
76 fcb 1 edition #1
|
|
77
|
|
78
|
|
79 * Entry: Y=Ptr to device descriptor
|
|
80 * U=Ptr to device mem
|
|
81 *
|
|
82 * Default to only one drive supported, there's really no need for more.
|
|
83 INIT lda #$FF 'Invalid' value & # of drives
|
|
84 leax DRVBEG,u Point to start of drive tables
|
|
85 sta ,x DD.TOT MSB to bogus value
|
|
86 sta <V.TRAK,x Init current track # to bogus value
|
|
87
|
|
88 * for now, TERM routine goes here. Perhaps it should be pointing to the
|
|
89 * park routine? ... probably not.
|
|
90 TERM
|
|
91 GETSTA clrb no GetStt calls - return, no error, ignore
|
|
92 L0086 rts
|
|
93
|
|
94 start lbra INIT 3 bytes per entry to keep RBF happy
|
|
95 lbra READ
|
|
96 lbra WRITE
|
|
97 lbra GETSTA
|
|
98 lbra SETSTA
|
|
99 lbra TERM
|
|
100
|
|
101 * Entry: B:X = LSN
|
|
102 * Y = path dsc. ptr
|
|
103 * U = Device mem ptr
|
|
104 READ clra READ the sector
|
|
105 bsr GetSect Go read the sector, exiting if there's an error
|
|
106 tstb
|
|
107 bne GETSTA if not sector 0, return
|
|
108 leax ,x sets CC.Z bit
|
|
109 bne GETSTA if not sector zero, return
|
|
110
|
|
111 * LSN0, standard OS-9 format
|
|
112 * Actually, this isn't really necessary for a HD, as the information in
|
|
113 * LSN0 never changes after it's read in once. But we'll do it anyhow
|
|
114 ldx PD.BUF,y Get ptr to sector buffer
|
|
115 leau DRVBEG,u point to the beginning of the drive tables
|
|
116 ldb #DD.SIZ copy bytes over
|
|
117 copy.0 lda ,x+ grab from LSN0
|
|
118 sta ,u+ save into device static storage
|
|
119 decb
|
|
120 bne copy.0
|
|
121 clrb
|
|
122 rts
|
|
123
|
|
124 WRITE lda #$01 WRITE to emulator disk, and fall thru to GetSect
|
|
125
|
|
126 * Get Sector comes here with:
|
|
127 * Entry: A = read/write command code (0/1)
|
|
128 * B,X = LSN to read/write
|
|
129 * Y = path dsc. ptr
|
|
130 * U = Device static storage ptr
|
|
131 * Exit: A = error status from command register
|
|
132 GetSect tst <PD.DRV,y get drive number requested
|
|
133 bne DrivErr only one drive allowed, return error
|
|
134
|
|
135 pshs x,b save LSN for later
|
|
136 stb >LSN
|
|
137 stx >LSN+1
|
|
138
|
|
139 ldx PD.BUF,y where the 256-byte LSN should go
|
|
140 * Note: OS-9 allocates buffers from system memory on page boundaries, so
|
|
141 * the low byte of X should now be $00, ensuring that the sector is not
|
|
142 * falling over an 8K MMU block boundary.
|
|
143
|
|
144 stx >buffer set up the buffer address
|
|
145 sta >command get the emulator to blast over the sector
|
|
146 lda >command restore the error status
|
|
147 bne FixErr if non-zero, go fix the error and exit
|
|
148 puls b,x,pc restore LSN and exit
|
|
149
|
|
150 DrivErr leas 2,s kill address of calling routine (Read/Write)
|
|
151 comb
|
|
152 * FIND ERROR CODE TO USE
|
|
153 * ldb #E$ find appropriate error code...
|
|
154 ldb #E$NotRdy not ready
|
|
155 rts
|
|
156
|
|
157 * Emulator error codes translated to OS-9 error codes.
|
|
158 *
|
|
159 * 2=not enabled
|
|
160 * E$NotRDy - drive is not ready
|
|
161 *
|
|
162 * 4=too many MS-DOS files open,
|
|
163 * E$
|
|
164 *
|
|
165 * 5=access denied (virtual HD file locked by another program
|
|
166 * or MS-DOS read-only status)
|
|
167 * E$WP - write protect
|
|
168 *
|
|
169 * 6/12=internal error
|
|
170 * E$CRC - CRC error
|
|
171 *
|
|
172 * 254=invalid command byte
|
|
173 * E$
|
|
174 *
|
|
175 * 255=power-on state or closed.
|
|
176 * E$NotRdy - drive is not ready
|
|
177 *
|
|
178 FixErr leas 5,s kill B,X,PC from GetSect routine
|
|
179 cmpa #02
|
|
180 beq NotRdy
|
|
181 cmpa #255
|
|
182 beq NotRdy
|
|
183 cmpa #5
|
|
184 beq WP
|
|
185 cmpa #6
|
|
186 beq CRC
|
|
187 cmpa #12
|
|
188 beq CRC
|
|
189
|
|
190 * if it's something we don't recognize, it's a seek error
|
|
191 comb
|
|
192 ldb #E$Seek seek error
|
|
193 rts
|
|
194
|
|
195 NotRdy comb
|
|
196 ldb #E$NotRdy not ready
|
|
197 rts
|
|
198
|
|
199 WP comb
|
|
200 ldb #E$WP write protect
|
|
201 rts
|
|
202
|
|
203 CRC comb
|
|
204 ldb #E$CRC CRC error
|
|
205 rts
|
|
206
|
|
207 L03D4 comb
|
|
208 ldb #E$Write write error
|
|
209 rts
|
|
210
|
|
211
|
|
212 L03E0 comb
|
|
213 ldb #E$Read Read error
|
|
214 rts
|
|
215
|
|
216 SETSTA ldx PD.RGS,y Get caller's register stack ptr
|
|
217 ldb R$B,x Get function code
|
|
218 cmpb #SS.WTrk Write track?
|
|
219 beq format Yes, ignore it
|
|
220 cmpb #SS.Reset Restore head to track 0?
|
|
221 beq format Yes, ignore it
|
|
222 cmpb #SS.SQD sequence down the drive (i.e. park it)?
|
|
223 beq park
|
|
224 comb set carry for error
|
|
225 ldb #E$UnkSvc return illegal service request error
|
|
226 rts
|
|
227
|
|
228 park ldb #$02 close the drive
|
|
229 stb >command save in command register
|
|
230
|
|
231 format clrb ignore physical formats. They're not
|
|
232 rts necessary
|
|
233
|
|
234 emod
|
|
235
|
|
236 eom equ *
|