<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Mon, 13 Dec 2004 13:48:53 +0000
From   : jgh@... (Jonathan Graham Harston)
Subject: Debugging ADFS and IDE drives

I'm having some peculiar problems with IDE drives.
 
If the final byte of a sector is &FE or &FF, then:
 
* if reading a single sector, the sector is read, but
 IDEStatus remains at &58 indicating "Ready to transfer
 data".
 
* if reading several sectors, then the final byte of that
  sector is returned incorrectly, but IDEStatus returns
  &50 indicating all data transfered.
 
I was almost tearing my hair out at this one. I'd copied
some music programs onto the drive, including a "Hello"
program with the last line: OSCLI"VData 30047". That
OSCLI command - token &FF - just happened to be byte &FF
in the last sector but one of the file.
 
On loading "Hello", the line had changed to EXT"VData 30047".
Oh, dodgy sector, I thought, and mapped it out and recopied
"Hello". On loading it again, the final line had changed
*again*! Another dodgy sector?!? I saved several copies with
different names and in each one the last line had changed.
Dodgy sectors appearing everywhere, but only if I save
this one program?!?!?!?!?
 
I did some experimenting with a sector editor and with different
drives and resolved the symptoms to those above. This will be
what was also giving me "Bad FS map" errors previously.
 
Has anybody else experienced this? The code is on my website,
but is essentially this:
 
\ &80/1=>address, &87/86/85=sector, &88=count
 
.CommandStart                    :\ C=R/W, &B0/1=>block
JSR SetGeometry                  :\ Set shape to cylinder*4*64
.CommandLoop
JSR SetSector:LDY #0             :\ Set sector, count, command
JSR WaitForData:AND #&21:BNE TransError
.TransferLoop
BIT &CD:BVS TransTube:BCC IORead
.IOWrite  :LDA (&80),Y:STA &FC40:BRA TransferByte
.IORead   :LDA &FC40:STA (&80),Y:BRA TransferByte
.TransTube:BCC TubeRead
.TubeWrite:LDA &FEE5:STA &FC40:BRA TransferByte
.TubeRead :LDA &FC40:STA &FEE5:BRA TransferByte
:
.TransferByte
INY:BNE TransferLoop:INC &81     :\ Loop for 256 bytes
LDA &FC47:AND #&21:BNE TransError:\ Error occured
INC &87:BNE TransCount           :\ Increment sector
INC &86:BNE TransCount:INC &85
.TransCount
DEC &88:BNE CommandLoop          :\ Loop for all sectors
...tidy up and exit...
 
.SetSector
PHP:JSR WaitNotBusy                      :\ Save CC/CS Read/Write
LDY #8:LDA #1:STA &FC42                  :\ One sector
CLC:LDA (&B0),Y:AND #63:ADC #1:STA &FC43 :\ Set sector b0-b5
DEY:LDA (&B0),Y:STA &FC44                :\ Set sector b8-b15
DEY:LDA (&B0),Y:PHA:AND #&1F:STA &FC45   :\ Set sector b16-b20
PLA:LSR A:LSR A:LSR A:LSR A:AND #&02     :\ Get Drive 0/1
INY:INY:EOR (&B0),Y:AND #&02:EOR (&B0),Y :\ Merge Drive and Head
JSR SetDrive:DEY:DEY:DEY:LDA (&B0),Y     :\ Get command &08 or &0A
.SetCommand
AND #2:PHA:EOR #2:LSR A:LSR A            :\ Copy ~b1 into Cy
PLA:ASL A:ASL A:ASL A:ORA #&20           :\ Translate CS->&20 or CC->&30
STA &FC47:PLP:RTS                        :\ Set command &08 or &0A
:
.SetDrive
ROL A:ROL A:ROL A:AND #&13:STA &FC46:RTS :\ Set device + sector b6-b7
:
.SetGeometry
JSR WaitNotBusy                          :\ Should check device
LDA #64:STA &FC42:STA &FC43              :\ 64 sectors per track
LDA #3:STA &FC46:LDA #&91:STA &FC47      :\ 4 heads per cylinder
RTS
:
.WaitNotBusy
PHP:JSR &806F                    :\ Get IDE status
AND #&80:BNE &8333:PLP           :\ Wait for IDE not busy
:
.WaitForData
LDA &FC47:AND #8:BEQ WaitForData
LDA &FC47:RTS
 
-- 
J.G.Harston - jgh@...                - mdfs.net/User/JGH
Badly formed email is deleted unseen as spam
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>