<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 09 Nov 2006 21:50:36 +0000
From   : splodge@... (Richard Gellman)
Subject: Some ADFS / WDC 1770 questions.

BRAHMS wrote:
> I've been poking around all day and have come up with the following 
> questions (I'm attempting to write and adf/adl to adfs disc 
> writer/formatter):
>  
> 1) How easy is it to format discs using the WDC 1770? Has anybody got 
> any sample code?
The process of formatting a disc is rather involved, and requires 
sending the complete data stream for a whole track (including sector 
headers and gaps) as an uninterrupted NMI-triggered sequence. This is 
probably one of the reasons why the ADFS formatter on the Welcome disc 
is written in machine code, and not a BASIC program like most of the 
other utilities :)

For other operations (e.g. reading, writing of files, etc) you have the 
handy DFS/ADFS to do this sort of business for you. For formatting you 
have to do it yourself (or use the DFS/ADFS formatters). The sequence 
would be along the lines of (pseudo-ish code):

SEI
LD #NMI_handler>
ST <NMI vector>
JSR prepare_headers
LDA #&ff
STA status_byte
STA sector
LDA #0
STA blk_offset
LD #format_track_command
ST fdc
.loop
LDA status_byte
BNE loop
CLI
RTS

.NMI_Handler
LDA sector
CMP #&FF
BEQ track_block
LDX blk_offset
LDA sector_blk, X
ST fdc
INC blk_offset
TAX
CMP #blklen
BEQ inc_sector_num_and_compare
RTI
.track_block
LDX blk_offset
LDA trackheader_blk,X
ST fdc
INC blk_offset
TXA
CMP #blklen
BNE exit
INC sector
.exit
RTI
.inc_sector_num_and_compare
INC sector
LDA #0
STA blk_offset
LDA sector
STA sector + sector_num_offset
CMP #(max_sector +1)
BNE exit
LDA #0
STA status_byte
RTI

DISCLAIMER: Under no circumstances is this even likely to work. Its a 
rough idea of how to format a disk using the FDC's DRQ/ACK system. There 
is also the setup of the Floppy Disk Control register (density select, 
drive select, etc). I've probably also missed out a few details 
somewhere, FDC setup commands, etc. You will also need to consult the 
WD1770 Datasheet on header formats and such. It also assumes from my 
rather poor memory that the FDC requires a track header. This stage may 
be completely unnecessary. Again consult the datasheet.

Also there is no code in there for operation abort, register preserving 
on exit of NMI, or any other niceties.
>  
> 2) When accessing the disc using OSWORD&72 I have to add 4 to the 
> drive number (when mounted on drive 0) to access the floppy drive 0 ( 
> is this "rule" correct?)
Check *STATUS. I believe the setting of "Floppy" or "Hard" (a 
potentially euphemistic reference if I ever saw one) causes ADFS to 
invert the drive numbers so that the Hard drive optionally appears as 
drive :0 instead of drive :4. On a floppy only system both do the same 
thing outside of OSWORD &72.
>  
> 3) In the documentation it indicates that the drive in the OSWORD 
> control block is ORed with the "current" drive number - what is the 
> best thing to do here if I want to read / write sectors on drive 0 if 
> drive 4 is current - do I really have to change drives to 0 - if so how?
>  
I've not seen this. IIRC, the setup block for OSWORD &72 is reminiscent 
of a SCSI command block. Certainly functions &08 and &0A (read bytes, 
write bytes) match up with the same in the SCSI specification. I'm not 
entirely certain how OSWORD &72 selects drives, but ORing with the 
current drive seems daft to me, not that such things ever stopped Acorn 
:) (Econet read bytes function springs to mind... )

-- Richard


<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>