English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 27 January 2013, 21:02   #1
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,225
Disk controller coding: where is my disk?

For a new project I wrote a trackloader. During initialization I want to check all four drives for my disk, as it is allowed to boot from any drive since OS2.0.

It seems that I am missing something. AFAIK I don't have to start the drive's motor to evaluate the DSKCHANGE signal. A step to a different track should be sufficient.

The following code fragment works with UAE, but not with a real A3000. With real hardware it only works when the disk is in drive 0.

Code:
        lea     CIAA+CIAPRA,a2
        lea     CIAB+CIAPRB,a3

        ; Motor off for all drives
        or.b    #$f8,(a3)
        nop
        and.b   #$87,(a3)
        moveq   #100,d0
        bsr     td_delay
        move.b  #$78,(a3)       ; deselect all
        moveq   #100,d0
        bsr     td_delay

        ; Find the first drive with a disk inserted. Start with drive 0.
        moveq   #DSKSEL0,d2

.1:     bclr    d2,(a3)         ; select drive
        nop
        bclr    #DSKDIREC,(a3)
        bsr     td_step
        move.w  #SETTLEDELAY,d0
        bsr     td_delay
        bset    #DSKDIREC,(a3)
        bsr     td_step
        
        btst    #DSKCHANGE,(a2)
        bne     .2              ; found a disk in this drive
        
        bset    d2,(a3)         ; deselect
        addq.b  #1,d2           ; next drive
        cmp.b   #DSKSEL0+3,d2
        bls     .1
        
        ; no disk in any drive!
        moveq   #-1,d0
        bra     .exit

        ; deselect and remember the used drive bit
.2:     bset    d2,(a3)
        move.b  d2,DriveSel(a4)
td_delay busy-waits for the number of rasterlines in d0. td_step steps to the next cylinder, like this:
Code:
td_step:
; Step a track into selected direction.
; a2 = CIAAPRA
; a3 = CIABPRB

        moveq   #STEPDELAY,d0
        bsr     td_delay
        bclr    #DSKSTEP,(a3)
        moveq   #2,d0
        bsr     td_delay
        bset    #DSKSTEP,(a3)
        rts
STEPDELAY is 50, ~3ms. SETTLEDELAY is 300, ~19ms.
phx is offline  
Old 27 January 2013, 21:19   #2
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,111
One possible problem is that drive selection also turns on the motor. During spinup different drives seem to report status signals differently.

There is no need to step if you only want to check if disk is still in the drive.
Toni Wilen is offline  
Old 27 January 2013, 21:56   #3
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,225
Floppy disk

Thanks. Thinking about your comment I realized that I made a typo. This line should be fixed:
Code:
-       move.b  #$78,(a3)       ; deselect all
+       or.b    #$78,(a3)       ; deselect all
Some debugging later I got an impression about the problem. My A3000 has three drives connected: DF0, DF2 and DF3. I am trying to boot from DF2. But my code detects a disk in DF1, although there is no drive connected! Later it hangs in an endless loop while waiting for the DSKREADY signal from this drive.

Probably the DSKCHANGE signal is invalid when there is no physical drive. So the only solution would be to check first which drives are present?
phx is offline  
Old 27 January 2013, 22:28   #4
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,111
Yeah, drive type must be checked first, disk status signals are undefined (I think they are normally pulled to high state but it isn't good idea to depend on it..) if non-existing drive is selected.

HRM has good disk id check example. Disk.resource can be also used if system hasn't been taken over yet.
Toni Wilen is offline  
Old 27 January 2013, 23:56   #5
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,225
Hmm... I'm doing something wrong again, as it seems. Enough for today.
Here is my code to determine the drive ID. With UAE (DF0 and DF1 connected) it detects DF0, DF2 and DF3. On my A3000 (DF0, DF2 and DF3 connected) it detects DF0 and DF1.

Code:
        moveq   #DSKSEL0,d2
        moveq   #0,d3

.1:     bclr    #DSKMOTOR,(a3)
        nop
        bclr    d2,(a3)
        nop
        st      (a3)
        nop
        bclr    d2,(a3)
        nop
        st      (a3)

        ; read drive's serial ID code
        moveq   #31,d1
        moveq   #0,d0
.2:     add.l   d0,d0
        bclr    d2,(a3)
        nop
        btst    #DSKRDY,(a2)
        beq     .3
        addq.b  #1,d0
.3:     bset    d2,(a3)
        dbf     d1,.2
        
        addq.l  #1,d0
        bne     .4
        
        ; ID is $ffffffff: Amiga 3.5" disk drive present
        bset    d2,d3
        
.4:     addq.b  #1,d2           ; next drive
        cmp.b   #DSKSEL0+3,d2
        bls     .1
phx is offline  
Old 28 January 2013, 09:47   #6
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,111
You are missing HRM step 3. (selxb = high)

Check also UAE advanced chipset panel df0: id setting, it should be ticked if you want matching A3000-like configuration. Remember that A500 always returns no drive state when DF0: id is queried! (AOS always assumes DF0: is connected)

AFAIK only way to actually detect DF0: if it returned no drive id is to select the drive, check track0, if not active, step towards track zero and so on. There really is no drive if track0 still isn't active after 80+ steps.
Toni Wilen is offline  
Old 28 January 2013, 13:06   #7
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,225
Quote:
Originally Posted by Toni Wilen View Post
You are missing HRM step 3. (selxb = high)
In line 23 I am resetting the SELx bit:
Code:
.3:     bset    d2,(a3)
Or what do you mean?

Quote:
Check also UAE advanced chipset panel df0: id setting, it should be ticked if you want matching A3000-like configuration.
I don't think it is available under E-UAE, which I'm using under MorphOS and NetBSD.

Quote:
Remember that A500 always returns no drive state when DF0: id is queried! (AOS always assumes DF0: is connected)
So it would be the best not to check DF0, but only the IDs of DF1, DF2 and DF3? Assuming that DF0 is present should work for me.
phx is offline  
Old 28 January 2013, 13:11   #8
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,111
Quote:
Originally Posted by phx View Post
In line 23 I am resetting the SELx bit:
Code:
.3:     bset    d2,(a3)
Or what do you mean?
Sequence is: motor low, sel low, sel high (this is missing in your code), motor high, sel low, sel high, loop: sel low, read rdy, sel high, goto loop.

Quote:
I don't think it is available under E-UAE, which I'm using under MorphOS and NetBSD.
Then it is best to ignore what it reports or does (EDIT: I mean ignore it if testing anything non-standard, old floppy ID emulation was written to match documentation, not hardware behavior)

Quote:
So it would be the best not to check DF0, but only the IDs of DF1, DF2 and DF3? Assuming that DF0 is present should work for me.
Yeah.

Last edited by Toni Wilen; 28 January 2013 at 13:56.
Toni Wilen is offline  
Old 28 January 2013, 17:46   #9
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,225
Quote:
Originally Posted by Toni Wilen View Post
Sequence is: motor low, sel low, sel high (this is missing in your code), motor high,
Everything there. Although I was under the impression that setting motor and sel to high can be done with a single write access (st (a3)). The state of DSKMOTOR is only latched when SEL goes from high to low (according to the HRM).
Code:
.1:     bclr    #DSKMOTOR,(a3)
        nop
        bclr    d2,(a3)
        nop
        st      (a3)
phx is offline  
Old 28 January 2013, 18:09   #10
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,111
Oops, I forgot that st sets all bits, not just high bit

Anyway, this is not about motor setup. Id sequence should be initialized exactly as documented, step by step. (Setting both select and motor at the same time is undocumented side-effect of standard motor flipflop circuitry)
Toni Wilen is offline  
Old 28 January 2013, 20:47   #11
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,225
Ok, got it! The problem was the interpretation of the RDY bit.

In the HRM is written "Read and save the state of RDY". But RDY is active low, so I have to save a 1-bit when RDY is 0. The "st" is no problem then.

But DF0 cannot be detected. I have to assume that it is present.
phx is offline  
Old 29 January 2013, 09:12   #12
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 43
Posts: 22,111
I'd personally do this "by the book" because this is not part of Amiga hardware. Abusing custom chipset undocumented features is perfectly fine for me

This feature is located on tiny PCB that comes with external floppy drives and some special drives (perhaps HD drives with some more intelligence, not just 2 standard TTL chips?) may expect exactly right sequence.
Toni Wilen is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
WANTED: Kronos SCSI controller partition tool disk komprasz request.Other 0 25 July 2011 12:37
Where? 82077AA PLCC68 Floppy Disk Controller chip for vortex GoldenGate cards... keropi request.Other 2 29 January 2007 22:18
Disk-2-Disk by Central Coast Software (full or demo version) mark_k request.Apps 3 09 July 2006 15:10
Newbie question: how to access files on an Amiga disk using PC disk drive? Nethead New to Emulation or Amiga scene 5 05 July 2003 00:07
Amiga nd the CatWeasel Floppy Disk Controller wibble82 support.Hardware 4 17 May 2002 21:13

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:45.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.07639 seconds with 13 queries