0
|
1 ********************************************************************
|
|
2 * FlashPak - FLASH Pak device driver based on Disto's RAM Pak driver
|
|
3 * Copyright 2001 by Agesino Primatic, Jr.
|
|
4 * Free for any use as long as this copyright message is included.
|
|
5 *
|
|
6 * $Id$
|
|
7 *
|
|
8 * Ed. Comments Who YY/MM/DD
|
|
9 * ------------------------------------------------------------------
|
|
10 * 1 Original version by A. Primatic AP 01/04/05
|
|
11
|
|
12
|
|
13 nam FlashPak
|
|
14 ttl FLASH Pak device driver
|
|
15
|
|
16 ifp1
|
|
17 use defsfile
|
|
18 endc
|
|
19
|
|
20 tylg set Drivr+Objct
|
|
21 atrv set ReEnt+rev
|
|
22 rev set $01
|
|
23 edition set 1
|
|
24
|
|
25
|
|
26 mod eom,name,tylg,atrv,start,size
|
|
27
|
|
28
|
|
29 * RBF Data Area
|
|
30 rmb 129
|
|
31
|
|
32
|
|
33 * Free for driver use
|
|
34 ORGSlot rmb 1
|
|
35 BlkAdr rmb 2 address of our 16K block of memory
|
|
36 CurPD rmb 2 our current path descriptor
|
|
37 CurLSN rmb 2 our current LSN
|
|
38
|
|
39
|
|
40 FOffset equ 0
|
|
41 FLSNLo equ 1
|
|
42 FLSNHi equ 2
|
|
43 FData equ 3
|
|
44
|
|
45
|
|
46 size equ .
|
|
47 fcb $FF
|
|
48
|
|
49
|
|
50 name fcs /FlashPak/
|
|
51 fcb edition
|
|
52
|
|
53
|
|
54 start lbra Init
|
|
55 lbra Read
|
|
56 lbra Write
|
|
57 lbra GetStat
|
|
58 lbra SetStat
|
|
59 lbra Term
|
|
60
|
|
61
|
|
62 * Init
|
|
63 *
|
|
64 * Entry:
|
|
65 * Y = address of device descriptor
|
|
66 * U = address of device memory area
|
|
67 *
|
|
68 * Exit:
|
|
69 * CC = carry set on error
|
|
70 * B = error code
|
|
71 *
|
|
72 Init ldd #($FF*256)+3 this driver can handle 3 "disks"
|
|
73 stb V.NDRV,u
|
|
74 leax DRVBEG,u start at beginning of drive table of disk 0
|
|
75
|
|
76
|
|
77 * For each B, compute total sectors...
|
|
78 InitLp sta V.TRAK,x initialize to 0xff so first seek gets LSN0
|
|
79 pshs b,a
|
|
80 lda IT.CYL+1,y compute total sectors
|
|
81 ldb IT.SCT+1,y
|
|
82 mul
|
|
83 std DD.TOT+1,x fill in table
|
|
84 puls b,a
|
|
85 leax DRVMEM,x move to drive table of next disk
|
|
86 decb
|
|
87 bne InitLp
|
|
88
|
|
89
|
|
90 * Reserve 16K of memory for sector copies
|
|
91 ldd #$4000 request 16K bytes
|
|
92 pshs u save address of device memory area
|
|
93 os9 F$SRqMem Request System Memory
|
|
94 tfr u,x X = starting address of memory area
|
|
95 puls u restore address of device memory area
|
|
96 bcs InitErr branch if error
|
|
97
|
|
98
|
|
99 stx BlkAdr,u store starting address
|
|
100 clrb no errors here
|
|
101
|
|
102
|
|
103 InitErr rts all done with intialization
|
|
104
|
|
105
|
|
106 * Write
|
|
107 *
|
|
108 * Entry:
|
|
109 * B = MSB of the disk's LSN
|
|
110 * X = LSW of the disk's LSN
|
|
111 * Y = address of path descriptor
|
|
112 * U = address of device memory area
|
|
113 *
|
|
114 * Exit:
|
|
115 * CC = carry set on error
|
|
116 * B = error code
|
|
117 *
|
|
118 Write pshs cc save carry flags (including interrupt enable)
|
|
119 * orcc #IntMasks mask interrupts
|
|
120 lbsr SelSlot get to the proper MPI slot
|
|
121 stx CurLSN,u save LSN
|
|
122 tfr x,d now, D = LSN
|
|
123 ldx PD.BUF,y get address of path buffer
|
|
124 sty CurPD,u save path descriptor
|
|
125 ldy V.PORT,u get base address of FlashPak
|
|
126 sta FLSNHi,y write LSN hi byte to FlashPak
|
|
127 stb FLSNLo,y write LSN lo byte to FlashPak
|
|
128 clrb set up for 256 transfers
|
|
129
|
|
130
|
|
131 * First, we need to see if a write would work
|
|
132 WrLp1 stb FOffset,y write offset to FlashPak
|
|
133 lda ,x get what we want to write
|
|
134 coma data on flash is stored complemented
|
|
135 * nop
|
|
136 anda FData,y logical-and with data from FlashPak
|
|
137 coma get back uncomplemented version
|
|
138 * nop
|
|
139 cmpa ,x+ does result match with what we want to write?
|
|
140 bne WrErase if no, then we need to erase sector
|
|
141
|
|
142
|
|
143 incb go to next word
|
|
144 bne WrLp1 branch if not done
|
|
145
|
|
146
|
|
147 * At this point, write can proceed
|
|
148 ldx CurPD,u get back path descriptor
|
|
149 ldx PD.BUF,x get address of the path buffer
|
|
150 ldy V.PORT,u get base address of FlashPak
|
|
151 bsr WrBlock write 256-byte block
|
|
152
|
|
153
|
|
154 WrExit lbra RstSlot restore MPI slot
|
|
155
|
|
156
|
|
157 * WrBlock -- copies 256 bytes from memory to flash
|
|
158 *
|
|
159 * Entry:
|
|
160 * B = Offset into flash
|
|
161 * X = Address of first memory location
|
|
162 * CurLSN,u = current LSN (for WrByte)
|
|
163 *
|
|
164 * Exit:
|
|
165 * X = Address of next memory location
|
|
166 *
|
|
167 * Destroys:
|
|
168 * A, B
|
|
169 WrBlock clrb start at offset of 0
|
|
170 pshs b push offset (of 0) on stack
|
|
171
|
|
172
|
|
173 WrLoop lda ,x+ get data from buffer
|
|
174 bsr WrByte write that byte
|
|
175 bcs WrBlkDn if there was an error, break out
|
|
176
|
|
177
|
|
178 inc ,s increment offset
|
|
179 ldb ,s get new offset
|
|
180 bne WrLoop
|
|
181
|
|
182
|
|
183 WrBlkDn leas 1,s remove offset from stack
|
|
184 rts
|
|
185
|
|
186
|
|
187 * WrByte
|
|
188 *
|
|
189 * Entry:
|
|
190 * A = Byte to write
|
|
191 * B = Offset to write
|
|
192 * Y = base address of FlashPak
|
|
193 * U = address of device memory area
|
|
194 * CurLSN,u = current LSN
|
|
195 *
|
|
196 * Destroys:
|
|
197 * B
|
|
198 *
|
|
199 WrByte pshs d,x save d and x for later
|
|
200 bsr DoAA55
|
|
201
|
|
202
|
|
203 ldx #$55 flash[0x5555] = 0xa0
|
|
204 ldd #$a055
|
|
205 bsr XfrByte
|
|
206
|
|
207
|
|
208 puls d flash[addr] = ~data
|
|
209 coma data on flash is complemented
|
|
210 * nop
|
|
211 ldx CurLSN,u
|
|
212 bsr XfrByte
|
|
213
|
|
214
|
|
215 pshs a save byte that was written on stack
|
|
216
|
|
217
|
|
218 * Now, loop until done
|
|
219 WrBWait ldb FData,y get flash data
|
|
220 cmpb ,s does it match?
|
|
221 beq WrBDone if yes, write passed
|
|
222
|
|
223
|
|
224 bitb #$20 did we exceed the time limit?
|
|
225 beq WrBWait if no, try again
|
|
226
|
|
227
|
|
228 * We exceed time limit -- try one more time
|
|
229 ldb FData,y get flash data
|
|
230 cmpb ,s does it match?
|
|
231 beq WrBDone whew! just made it
|
|
232
|
|
233
|
|
234 * Write Failure
|
|
235 lbsr RstFlsh reset flash to read mode
|
|
236 comb set carry flag
|
|
237 ldb #E$Write set error code
|
|
238 bra WrBExit
|
|
239
|
|
240
|
|
241 WrBDone clrb no error here
|
|
242
|
|
243
|
|
244 WrBExit puls a,x restore stack
|
|
245 rts
|
|
246
|
|
247
|
|
248 * XfrByte -- transfers one byte to flash
|
|
249 *
|
|
250 * Entry:
|
|
251 * A = Byte to transfer
|
|
252 * B = Offset
|
|
253 * X = LSN
|
|
254 * Y = base address of FlashPak
|
|
255 XfrByte exg d,x get LSN into D
|
|
256 sta FLSNHi,y write LSN hi byte to FlashPak
|
|
257 stb FLSNLo,y write LSN lo byte to FlashPak
|
|
258 exg d,x get byte/offset into D
|
|
259 stb FOffset,y write offset to FlashPak
|
|
260 sta Fdata,y write data to FlashPak
|
|
261 rts all done
|
|
262
|
|
263
|
|
264 * DoAA55 Sends 0x5555=0xaa, then 0xaaaa=0x55 to flash
|
|
265 DoAA55 ldx #$55 flash[0x5555] = 0xaa
|
|
266 ldd #$aa55
|
|
267 bsr XfrByte
|
|
268
|
|
269
|
|
270 ldx #$2a flash[0x2aaa] = 0x55
|
|
271 ldd #$55aa
|
|
272 bra XfrByte will also return
|
|
273
|
|
274
|
|
275 * WrErase
|
|
276 *
|
|
277 * Entry:
|
|
278 * Y = base address of FlashPak
|
|
279 * U = address of device memory area
|
|
280 * CurLSN,u = current LSN
|
|
281 *
|
|
282 * First, we need to read the entire sector into BlkAdr
|
|
283 WrErase ldx BlkAdr,u Get start of BlkAddr
|
|
284 ldd CurLSN,u Get current LSN
|
|
285 sta FLSNHi,y write LSN hi byte to FlashPak
|
|
286 andb #$C0 Get to first LSN of this sector
|
|
287
|
|
288
|
|
289 WrErLp1 stb FLSNLo,y write LSN lo byte to FlashPak
|
|
290 pshs b save LSN_lsb on stack
|
|
291 lbsr RdBlock transfer 256 bytes from flash to memory
|
|
292 puls b get back LSN_lsb
|
|
293 incb go to next LSN
|
|
294 bitb #$3f are we done?
|
|
295 bne WrErLp1 if no, go back for some more
|
|
296
|
|
297
|
|
298 * Now, we have the entire sector copied into memory
|
|
299 * Replace the old LSN with the new one
|
|
300 ldx BlkAdr,u get start of BlkAddr
|
|
301 ldd CurLSN,u get current LSN
|
|
302 exg a,b
|
|
303 anda #$3f find offset
|
|
304 clrb start at beginning of LSN
|
|
305 leax d,x move to LSN in memory
|
|
306 ldy CurPD,u get back path descriptor
|
|
307 ldy PD.BUF,y get address of path buffer
|
|
308
|
|
309
|
|
310 WrErLp2 lda ,y+ get byte from path buffer
|
|
311 sta ,x+ put byte into BlkMem
|
|
312 incb move to next byte
|
|
313 bne WrErLp2 branch if not done
|
|
314
|
|
315
|
|
316 * Now, we have the entire sector with the new LSN in memory
|
|
317 * Erase sector
|
|
318 ldy V.PORT,u
|
|
319 bsr DoAA55
|
|
320
|
|
321
|
|
322 ldx #$55 flash[0x5555] = 0x80
|
|
323 ldd #$8055
|
|
324 bsr XfrByte
|
|
325
|
|
326
|
|
327 bsr DoAA55
|
|
328
|
|
329
|
|
330 ldd CurLSN,u flash[SectAddr] = 0x30
|
|
331 andb #$C0
|
|
332 tfr d,x
|
|
333 ldd #$3000
|
|
334 bsr XfrByte
|
|
335
|
|
336
|
|
337 * Now, loop until done
|
|
338 WrEWait ldb FData,y get flash data
|
|
339 bmi WrEDone if DQ7 is set, then we're done
|
|
340
|
|
341
|
|
342 bitb #$20 did we exceed the time limit?
|
|
343 bne WrETime if yes, go on
|
|
344
|
|
345
|
|
346 * Sleep for 250ms
|
|
347 ldx #15 15 * 1/60 = 250ms
|
|
348 os9 F$Sleep
|
|
349 bra WrEWait go back for more
|
|
350
|
|
351
|
|
352 * We exceeded the time limit -- try one more time
|
|
353 WrETime ldb FData,y get flash data
|
|
354 bmi WrEDone whew! just made it
|
|
355
|
|
356
|
|
357 * Erase Failure
|
|
358 bsr RstFlsh reset flash to read mode
|
|
359 comb set carry flag
|
|
360 ldb #E$Write set error code
|
|
361 bra WrEExit
|
|
362
|
|
363
|
|
364 * Finally, we need to write the sector back
|
|
365 WrEDone ldx BlkAdr,u get pointer to memory version of sector
|
|
366 ldy V.PORT,u get base address of FlashPak
|
|
367 ldd CurLSN,u get current LSN
|
|
368 andb #$C0 get to beginning of sector
|
|
369 pshs b push LSN_lsb on stack
|
|
370
|
|
371
|
|
372 WrErLp3 stb CurLSN+1,u write new LSN lsb to CurLSN
|
|
373 lbsr WrBlock transfer 256 bytes from memory to flash
|
|
374 bcs WrEExit branch if error
|
|
375
|
|
376
|
|
377 inc ,s go to next LSB_lsb
|
|
378 ldb ,s get back LSN_lsb
|
|
379 bitb #$3f are we done?
|
|
380 bne WrErLp3 if no, go back for some more
|
|
381
|
|
382
|
|
383 clrb no error here
|
|
384
|
|
385
|
|
386 WrEExit leas 1,s remove LSN_lsb from stack
|
|
387 bra RstSlot will also return
|
|
388
|
|
389
|
|
390 * RstFlash -- Resets flash to read mode
|
|
391 *
|
|
392 RstFlsh lbsr DoAA55
|
|
393
|
|
394
|
|
395 ldx #$55 flash[0x5555] = 0xf0
|
|
396 ldd #$f055
|
|
397 lbra XfrByte will also return
|
|
398
|
|
399
|
|
400 * Read
|
|
401 *
|
|
402 * Entry:
|
|
403 * B = MSB of the disk's LSN
|
|
404 * X = LSW of the disk's LSN
|
|
405 * Y = address of path descriptor
|
|
406 * U = address of device memory area
|
|
407 *
|
|
408 * Exit:
|
|
409 * CC = carry set on error
|
|
410 * B = error code
|
|
411 *
|
|
412 Read cmpx #$0000 check to see if we're reading LSN0
|
|
413 beq RdLSN0 if we are, do special read
|
|
414
|
|
415
|
|
416 RdSect pshs cc save flags (including interrupt enable)
|
|
417 * orcc #IntMasks mask interrupts
|
|
418 bsr SelSlot select the proper MPI slot
|
|
419 tfr x,d now, D = LSN_lsw
|
|
420 ldx PD.BUF,y get address of the path buffer
|
|
421 ldy V.PORT,u get base address of FlashPak
|
|
422 sta FLSNHi,y write LSN hi byte to FlashPak
|
|
423 stb FLSNLo,y write LSN lo byte to FlashPak
|
|
424 bsr RdBlock go get the 256-byte block
|
|
425
|
|
426
|
|
427 * Restore the original MPI slot value we saved off
|
|
428 RstSlot lda >ORGSlot,u get original slot value
|
|
429 sta >MPI.Slct put it back
|
|
430 puls cc get back flags (including interrupt enable)
|
|
431 clrb no errors
|
|
432 rts we're done
|
|
433
|
|
434
|
|
435 * RdBlock -- copies 256 bytes from flash to memory
|
|
436 *
|
|
437 * Entry:
|
|
438 * B = Offset into flash
|
|
439 * X = Address of first memory location
|
|
440 *
|
|
441 * Exit:
|
|
442 * X = Address of next memory location
|
|
443 *
|
|
444 * Destroys:
|
|
445 * A, B
|
|
446 RdBlock clrb will do this 256 times
|
|
447
|
|
448
|
|
449 RdLoop stb FOffset,y write offset to FlashPak
|
|
450 lda FData,y get data from FlashPak
|
|
451 coma data on flash is stored complemented
|
|
452 * nop
|
|
453 sta ,x+ write it into buffer
|
|
454 incb go to next word
|
|
455 bne RdLoop branch if not done
|
|
456
|
|
457
|
|
458 rts all done with RdBlock
|
|
459
|
|
460
|
|
461 * Read LSN0 into our path descriptor
|
|
462 RdLSN0 pshs y save address of path descriptor
|
|
463 bsr RdSect go get the sector
|
|
464 puls y restore address of path descriptor
|
|
465 ldx PD.BUF,y get address of the path buffer
|
|
466 lda <PD.DRV,y get drive number
|
|
467 leay DRVBEG,u get address of beginning of drive table
|
|
468 ldb #DRVMEM
|
|
469 mul now, D = offset into table
|
|
470 leay d,y get address of byte following drive table
|
|
471 ldb #DD.SIZ-1 get size of device descriptor
|
|
472
|
|
473
|
|
474 * Copy LSN0 device descriptor to drive table
|
|
475 LSN0Lp lda b,x get byte from path buffer
|
|
476 sta b,y store byte in drive table
|
|
477 decb move to previous entry
|
|
478 bne LSN0Lp loop if not done
|
|
479
|
|
480
|
|
481 rts all done
|
|
482
|
|
483
|
|
484 * SelSlot - This routine selects the MPI slot
|
|
485 *
|
|
486 * Entry:
|
|
487 * None
|
|
488 *
|
|
489 * Exit:
|
|
490 * None
|
|
491 *
|
|
492 * Destroys:
|
|
493 * A, B
|
|
494 SelSlot lda >MPI.Slct get current selected slot
|
|
495 sta >ORGSlot,u save off
|
|
496 lda PD.DRV,y get drive no.
|
|
497 ldb #$11
|
|
498 mul multiply drive no. times $11
|
|
499 stb >MPI.Slct set new MPI slot no.
|
|
500 rts all done
|
|
501
|
|
502
|
|
503 * GetStat
|
|
504 *
|
|
505 * Entry:
|
|
506 * A = function code
|
|
507 * Y = address of path descriptor
|
|
508 * U = address of device memory area
|
|
509 *
|
|
510 * Exit:
|
|
511 * CC = carry set on error
|
|
512 * B = error code
|
|
513 *
|
|
514 GetStat comb
|
|
515 ldb #E$UnkSvc
|
|
516 rts
|
|
517
|
|
518
|
|
519 SetStat clrb
|
|
520 rts
|
|
521
|
|
522
|
|
523 * Term
|
|
524 *
|
|
525 * Entry:
|
|
526 * U = address of device memory area
|
|
527 *
|
|
528 * Exit:
|
|
529 * CC = carry set on error
|
|
530 * B = error code
|
|
531 *
|
|
532 Term
|
|
533 ldu BlkAdr,u release 16384-byte block
|
|
534 ldd #$2000
|
|
535 os9 F$SRtMem
|
|
536 bcs TermErr
|
|
537
|
|
538
|
|
539 clrb no errors here
|
|
540
|
|
541
|
|
542 TermErr rts
|
|
543
|
|
544
|
|
545 emod
|
|
546 eom equ *
|
|
547 end
|