Apple II
Technical Notes
_____________________________________________________________________________
                                                  Developer Technical Support


UniDisk 3.5
#4:    Accessing Macintosh Disks

Revised by:    Matt Deatherage                                  November 1988
Written by:    Mike Askins                                           May 1985

This Technical Note formerly discussed drive-specific SmartPort calls.  These 
calls are now documented in the Apple IIGS Firmware Reference.  This Note now 
describes how to access Macintosh disks from a UniDisk 3.5 disk drive, as this 
information was not documented in the manual.
_____________________________________________________________________________


Macintosh Disk Access

The disk data format used in the UniDisk 3.5 is essentially identical to that 
used for Macintosh disks.  There are three notable differences between the two 
formats:

o    Macintosh blocks are 524 bytes; UniDisk 3.5 blocks are 512 bytes.
o    Macintosh MFS disks are single sided; UniDisk 3.5 disks are double 
     sided.  (Macintosh HFS disks are double sided.)
o    The Macintosh uses a 2:1 physical block interleave; the UniDisk 
     3.5 uses a 4:1 interleave.


Accessing Blocks on a Macintosh Disk

Reading from a Macintosh disk is accomplished with the use of the READ command 
(as opposed to the READBLOCK command, which enforces 512 byte data.)  A call 
to load block zero from the Macintosh disk in Unit #1 into memory at $2000 
would look like this:

MacRead    JSR    Dispatch                ;Normal SmartPort Entry point
           DFB    $08                     ;Character READ command code
           DW     Cmd_List                ;The parameter list
           BCS    Error                   ;Optional error handling...
           ...
Cmd_List   DFB    $04                     ;CharRead has four parameters
           DFB    $01                     ;Unit number
           DW     $2000                   ;Buffer address
           DW     524                     ;Always transfer 524 bytes
           DFB    $00                     ;Block (lo)
           DFB    $00                     ;Block (med)
           DFB    $00                     ;Block (hi) 


Writing to a Macintosh disk is accomplished with the use of the WRITE command.  
A call to write block zero to the Macintosh disk in Unit #1 with data at 
memory location $2000 would look like this:

MacWrite   JSR    Dispatch                ;Normal SmartPort Entry point
           DFB    $09                     ;Character WRITE command code
           DW     Cmd_List                ;The parameter list
           BCS    Error                   ;Optional error handling...
        
The Cmd_List is the same as in the READ example.


Formatting Macintosh Disks

The formatting routine in the UniDisk 3.5 firmware can format single- or 
double-sided disks of variable physical block interleave.  The parameters 
controlling the interleave and the number of disk sides are located in the 
controller's zero page and are set to defaults whenever the INIT call is 
issued to SmartPort.  These parameters can be altered by using the 
SET_DOWN_ADR and DOWNLOAD subcalls of the CONTROL call.  Once altered, the 
FORMAT call uses these values in the formatting process.  These zero page 
locations and their values are detailed below:

Parameter      Location                 Values
Interleave     $0062           $02 = Mac,    $04 = UniDisk 3.5
DoubleSided    $0063           $00 = Single, $80 = Double-sided

The following code example formats the media in Unit #1 as a Macintosh disk:

MacFormat  JSR    Dispatch                ;Set address to patch interleave
           DFB    $04                     ;Control call (Set_Down_Adr)
           DW     Cmd_ListA               ;Parameter List
           BCS    Error
;
           JSR    Dispatch                ;Now patch the interleave byte
           DFB    $04                     ;Control call (DOWNLOAD)
           DW     Cmd_ListB               ;Parameter List
           BCS    Error
;
           JSR    Dispatch                ;Set address to patch single sided
           DFB    $04                     ;Control call (Set_Down_Adr)
           DW     Cmd_ListC               ;Parameter List
           BCS    Error
;
           JSR    Dispatch                ;Now patch the single sided byte
           DFB    $04                     ;Control call (DOWNLOAD)
           DW     Cmd_ListD               ;Parameter List
           BCS    Error
;
           JSR    Dispatch                ;Finally...
           DFB    $03                     ;This is the actual format call
           DW     Cmd_ListE               ;Parameter List
           BCS    Error
;
           RTS

The parameter lists are as follows:

Cmd_ListA  DFB    $03                     ;All control calls are 3 parms long
           DFB    $01                     ;Unit #1
           DW     Ctrl_ListA              ;This has the interleave address
           DFB    $06                     ;Set_Down_Adr control code

Ctrl_ListA DW    $02                      ;Two bytes for download address
           DW    $0062                    ;Interleave address

Cmd_ListB  DFB    $03                     ;All control calls are 3 parms long
           DFB    $01                     ;Unit #1
           DW     Ctrl_ListB              ;This has the interleave value
           DFB    $07                     ;Download control code

Ctrl_ListB DW     $01                     ;Two bytes for download address
           DFB    $02                     ;Mac Disk Interleave value

Cmd_ListC  DFB    $03                     ;All control calls are 3 parms long
           DFB    $01                     ;Unit #1
           DW     Ctrl_ListC              ;This has the sides byte address
           DFB    $06                     ;Set_Down_Adr control code

Ctrl_ListC DW    $02                      ;Two bytes for download address
           DW    $0062                    ;Interleave address

Cmd_ListD  DFB    $03                     ;All control calls are 3 parms long
           DFB    $01                     ;Unit #1
           DW     Ctrl_ListD              ;This has the sides value
           DFB    $07                     ;Download control code

Ctrl_ListD DW     $01                     ;Two bytes for download address
           DFB    $00                     ;Value for single sided disk

Ctrl_ListE DFB    $01                     ;Format call has just one parameter
           DFB    $01                     ;Unit number

Note:    You may encounter difficulties when switching 400K single-
sided disks and 800K double-sided disks in the same drive.  STATUS 
requests for the number of blocks on the disk in the drive are 
valid for the disk last accessed.  Thus, when you READ from an 
800K disk, eject it, and insert a 400K disk, a STATUS call will 
reveal a size of 800K until a READ or WRITE command is issued.  
Applications which intend to handle both 800K and 400K disks 
should do a READ before each STATUS call.


Further Reference
o    Apple IIGS Firmware Reference
o    Apple IIc Technical Reference Manual, Second Edition


