        IFND    HIDEUNITS19_I
HIDEUNITS19_I   SET     (1)

*****************************************************************
*                                                               *
*  Filename:    hideunits19.i                                   *
*  Release:     1.59                                            *
*  Date:        13.11.1991 17:04                                *
*                                                               *
*  'hidedisk.device' - Unit definitions.                        *
*  19 sectors version.                                          *
*                                                               *
*  (C) Copyright 1991 Stefan Klensch All Rights Reserved        *
*                                                               *
*****************************************************************

        IFND    EXEC_TYPES_I
        INCLUDE "exec/types.i"
        ENDC

        INCLUDE "exec/exec.i"

        IFND    EXEC_SEMAPHORES_I
        INCLUDE "exec/semaphores.i"
        ENDC

        IFND    DEVICES_TIMER_I
        INCLUDE "devices/timer.i"
        ENDC

        IFND    RESOURCES_DISK_I
        INCLUDE "resources/disk.i"
        ENDC

        IFND    HIDESECS19_I
        INCLUDE "hidesecs19.i"
        ENDC

*****************************************************************
* UserUnit                                                      *
*****************************************************************
* This little structure will be relinked into user's iosr on    *
* successful Opens.                                             *
*****************************************************************

        STRUCTURE UserUnit,0                    ; startof

        APTR    usu_PrivateUnit                 ; ptr to privateunit
        ULONG   usu_OpenFlags                   ; user's openflags

        LABEL   UserUnit_SIZE                   ; sizeof

*****************************************************************
* PrivateUnit                                                   *
*****************************************************************
* This keeps all informations necessary for accessing HD/DD     *
* disks correctly.                                              *
*****************************************************************

        STRUCTURE PrivateUnit,0                 ; startof

*****************************************************************
* Jmptable for mode-specific routines.                          *
*****************************************************************

        APTR    pru_JmpTable                    ; this unit's jmptab

*****************************************************************
* Backward reference to master-device and public unit.          *
*****************************************************************

        APTR    pru_Device                      ; ref to device
        APTR    pru_PublicUnit                  ; ref to public unit

*****************************************************************
* Technical constants this unit.                                *
*****************************************************************

        UWORD   pru_NumSecs                     ; # sectors
        UWORD   pru_NumTracks                   ; # tracks
        UWORD   pru_Sync                        ; syncword 16 bit
        UWORD   pru_Precomp01                   ; precomp start track

        UWORD   pru_ReadSz                      ; read-size DMA
        UWORD   pru_WriteSz                     ; write-size DMA
        UWORD   pru_GapSz                       ; sizeof gap front/rear
        UWORD   pru_SecSz                       ; rawsector size (encoded)
        UWORD   pru_TrackSz                     ; sizeof rawtrack

        UWORD   pru_SearchGap                   ; gap for searching hdrs
        UWORD   pru_SearchSectorSkip            ; skipsize searching hdrs
        UWORD   pru_LinearSkipBack              ; skipback for linearsectors
        UWORD   pru_LSyncToHdr                  ; offset lsync->header
        UWORD   pru_SecDatOff                   ; sector data offset from hdr
        UWORD   pru_ReadBufOff                  ; offset read

        ULONG   pru_LSync                       ; syncword 32 bit
        ULONG   pru_MaxOffset                   ; max. offset
        ULONG   pru_TimeOut                     ; timeout blkdma

*****************************************************************
* Private diskstate/type.                                       *
*****************************************************************

        UBYTE   pru_DiskType                    ; type of (HD or not)
        UBYTE   pru_DiskEmpty                   ; TRUE if this has no disk
        UBYTE   pru_DiskDense                   ; 1 if HD
        UBYTE   pru_Retries                     ; private # retries
        UBYTE   pru_SecId                       ; sector id
        UBYTE   pru_Pad0                        ; fill

*****************************************************************
* Private diskchange-support.                                   *
*****************************************************************

        STRUCT  pru_ChgIrList,MLH_SIZE          ; list for diskchange-link

        APTR    pru_SingleChgIr                 ; single-ir
        ULONG   pru_ChangeCnt                   ; changecounter
        
        LABEL   PrivateUnit_SIZE                ; sizeof

*****************************************************************
* JmpTable                                                      *
*****************************************************************
* An address of such a jmptable will be relinked into private   *
* unit structure for relative jumping on mode (HD/DD)           *
*****************************************************************

        STRUCTURE JmpTable,0                    ; startof

        APTR    jt_DecodeLong                   ; decode one long
        APTR    jt_DecodeData                   ; decode no checksum
        APTR    jt_DecWithChk                   ; decode + chksum
        APTR    jt_DecodeSecLabel               ; decode sector label

        APTR    jt_EncodeLong                   ; encode one long
        APTR    jt_EncodeLongs                  ; encode more longs
        APTR    jt_EncChkSetData                ; encode,make+set datachksum
        APTR    jt_EncodeSecLabel               ; encode sector label

        APTR    jt_AdjustFormatSec              ; make edges of sec

        APTR    jt_SetHdrChkSum                 ; set header's chk
        APTR    jt_CmpHdrChkSum                 ; compare chksum hdr
        APTR    jt_SetDatChkSum                 ; set data chk
        APTR    jt_CmpDatChkSum                 ; compare data chksum

        APTR    jt_CopyRawSecs                  ; copy raw sectors

        LABEL   JmpTable_SIZE                   ; sizeof

*****************************************************************
* HideBltNode                                                   *
*****************************************************************
* This structure will be used for blitter - usage in MFM mode.  *
* It keeps all stuff necessary for blitter, pointers...         *
*****************************************************************

        STRUCTURE HideBltNode,0                 ; startof

*****************************************************************
* From here to hbn_Cleanup, this is a standard bltnode (see     *
* hardware/blit.i).                                             *
*****************************************************************

        APTR    hbn_Next                        ; next in list
        APTR    hbn_Function                    ; func to call

        BYTE    hbn_Stat                        ; not used
        BYTE    hbn_Dummy                       ; not used

        WORD    hbn_BltSize                     ; blitter's size
        WORD    hbn_BeamSync                    ; not used

        APTR    hbn_Cleanup                     ; not used

*****************************************************************
* # of bytes, source and destination address.                   *
*****************************************************************

        ULONG   hbn_Bytes                       ; # bytes blitting
        APTR    hbn_Source                      ; srcptr
        APTR    hbn_Dest                        ; dstptr

*****************************************************************
* Backward reference to private unit.                           *
*****************************************************************

        APTR    hbn_PrivUnit                    ; public unitptr caller's

*****************************************************************
* Field to store next B/A/Dptr. On multiple blit operations     *
* (MFM encoding), pointers will be precomputed while blit is    *
* in progress and stuffed when blit finished.                   *
*****************************************************************

        STRUCT  hbn_NextBAD,(4*3)               ; next ptrs to stuff

        LABEL   HideBltNode_SIZE                ; sizeof

*****************************************************************
* IndexData                                                     *
*****************************************************************
* This data is linked into DRU_INDEX - interrupt's IS_DATA      *
* field and is used for easier transfer-start of DMA.           *
*****************************************************************

        STRUCTURE IndexData,0                   ; startof
        
        ULONG   ixdat_DmaWords                  ; # words for transfer
        APTR    ixdat_DmaStart                  ; start-routine DMA
        APTR    ixdat_PrivUnit                  ; privunit current
        APTR    ixdat_Device                    ; dev-reference

        LABEL   IndexData_SIZE                  ; sizeof

*****************************************************************
* PublicUnit                                                    *
*****************************************************************
* This structure is and keeps the public part, which is shared  *
* by the unit owners HD and DD                                  *
*****************************************************************

        STRUCTURE PublicUnit,UNIT_SIZE          ; std execunit

*****************************************************************
* Cache control section, MUST stand here (xx(ax,dx))            *
* On 19 sectors, GCR_SECTORS is increased to 20 sectors to      *
* be equal with 20 sector unit.                                 *
*****************************************************************

        STRUCT  puu_CachePtrs,(GCR_SECTORS*4)   ; ptrs for HD/DD
        APTR    puu_CachePtrsPad                ; longpad for 20 secs
        STRUCT  puu_CacheErrs,(GCR_SECTORS*1)   ; error-field
        UBYTE   puu_CacheErrsPad                ; bytepad for 20 secs

        UWORD   puu_CacheTrack                  ; track in cache
        APTR    puu_CacheDataStart              ; start of cachedata
        UBYTE   puu_CacheFlags                  ; flags
        UBYTE   puu_CachePad0                   ; fillbyte 

*****************************************************************
* DD and HD private unit                                        *
*****************************************************************

        STRUCT  puu_DDPru,PrivateUnit_SIZE      ; privunit DD
        STRUCT  puu_HDPru,PrivateUnit_SIZE      ; privunit HD

*****************************************************************
* Backward reference to master.                                 *
*****************************************************************

        APTR    puu_Device                      ; devptr

*****************************************************************
* Unitnumber and process-control flags.                         *
*****************************************************************

        UBYTE   puu_UnitNum                     ; number of unit
        UBYTE   puu_Flags                       ; own flags, see below
        UBYTE   puu_MotOffDelays                ; delaycnt motor off
        UBYTE   puu_DskCtrl                     ; current state disk
        UBYTE   puu_Turbo                       ; set if 68020/higher
        UBYTE   puu_UserMemOdd                  ; true, if usermem odd
        UBYTE   puu_UserMemChip                 ; true, if usermem in chip

*****************************************************************
* Read/Write section (std read/write).                          *
*****************************************************************

        UBYTE   puu_RWSector                    ; read/write sector
        UWORD   puu_RWTrack                     ; read/write track
        APTR    puu_RWBuf                       ; read/write buf
        APTR    puu_RWSecLabel                  ; read/write seclabel

*****************************************************************
* Current track head is above.                                  *
*****************************************************************

        UWORD   puu_CurTrack                    ; current track

*****************************************************************
* Msgports for timer/dru message - sends/replies.               *
*****************************************************************

        STRUCT  puu_DruTimerMp,MP_SIZE          ; timer reply/dru

*****************************************************************
* Diskresource-Unit for port allocation and INDEX/WORDSYNC      *
* interrupt recognition.                                        *
*****************************************************************

        STRUCT  puu_Dru,DRU_SIZE                ; DiskResource-Unit

*****************************************************************
* VBlank and MicroHz Timer for waiting.                         *
*****************************************************************

        STRUCT  puu_VBTimerIO,IOTV_SIZE         ; timereq vblank
        STRUCT  puu_MHTimerIO,IOTV_SIZE         ; timereq micro

*****************************************************************
* Task section, std Exec task                                   *
*****************************************************************

        STRUCT  puu_Task,TC_SIZE                ; task struct

*****************************************************************
* Buffer section, chipbuffer r/w pointer to current for hard-   *
* read/write and private chip sector for fast -> chip copy.     *
*****************************************************************

        APTR    puu_TrackBuf                    ; trackbuffer
        APTR    puu_PrivChipSec                 ; private chip sector

*****************************************************************
* Bsy section, masterflag, sectors decoded, read as write-      *
* prepare and syncs found by synchandler.                       *
*****************************************************************

        UBYTE   puu_BsyMode                     ; TRUE, if to do busy
        UBYTE   puu_BsySecsDecode               ; # secs decoded bsy
        UBYTE   puu_BsyWriteRead                ; read before write
        UBYTE   puu_BsyPad0                     ; fill
        UWORD   puu_BsySyncsFound               ; #syncs found

*****************************************************************
* Signal semaphore for change-support.                          *
* This inhibits those ugly problems removing/adding diskchange- *
* interrupts while unittask scans list after diskremove/insert. *
*****************************************************************

        STRUCT  puu_ChgSigSem,SS_SIZE           ; signalsem for lock

*****************************************************************
* Delays for step/settle/recalibrate.                           *
*****************************************************************

        ULONG   puu_StepDelay                   ; delay one step
        ULONG   puu_SettleDelay                 ; delay after seekend
        ULONG   puu_Seek000Delay                ; recalibrate

*****************************************************************
* HideBlitNode for MFM blitter support.                         *
*****************************************************************

        STRUCT  puu_Hbn,HideBltNode_SIZE        ; private bltnode       

*****************************************************************
* Custom base of Amiga hardware                                 *
* Remarked here to avoid absolute long 'lea' (codespace).       *
*****************************************************************

        APTR    puu_CustomBase                  ; ptr customregs

        LABEL   PublicUnit_SIZE                 ; sizeof

*****************************************************************
* Definitions for puu_CacheFlags                                *
*****************************************************************

        BITDEF  PUUC,HIGHDENS,5                 ; buf has high-density cache
        BITDEF  PUUC,REORG,4                    ; buf reorganized for write
        BITDEF  PUUC,SHORT,3                    ; short cache (write -2)
        BITDEF  PUUC,ERROR,2                    ; buf has chksum/sector err(s)
        BITDEF  PUUC,NODMA,1                    ; nosechdr reading wordsync
        BITDEF  PUUC,CHANGED,0                  ; buf was changed by write

*****************************************************************
* Unknown track for cache-clearing/making invalid.              *
*****************************************************************

PUUC_UNKNOWN            EQU     (-1)            ; this doesn't exist

*****************************************************************
* Clearmask for search headers.                                 *
*****************************************************************

PUUC_SEARCH             EQU     (~(PUUCF_REORG|PUUCF_ERROR|PUUCF_SHORT))

*****************************************************************
* Unknown track for CurTrack                                    *
*****************************************************************

CURTRACK_UNKNOWN        EQU     (-2)            ; not equal PUUC_UNKNOWN !

*****************************************************************
* Flags for OpenDevice(). Unit's default is read/write with     *
* BsyDecode/Encode (Decodes while Disk-DMA is in progress !!)   *
* and no 'click' if no disk is in drive.                        *
*                                                               *
* PUUOF_NOTBSY  = 1 disables bsy-decoding (= trackdisk).        *
* PUUOF_DOKLICK = 1 enables those noisy 'click's.               *
*****************************************************************

        BITDEF  PUUO,NOTBSY,4                   ; read not busy, if 1
        BITDEF  PUUO,DOKLICK,5                  ; clicks on, if 1

*****************************************************************
* Flags - Definitions for puu_Flags                             *
*****************************************************************

        BITDEF  PUU,DELOFF,7                    ; delayed motor off
        BITDEF  PUU,NOKLICK,6                   ; no click, if 1
        BITDEF  PUU,STOPPED,5                   ; unit stopped
        BITDEF  PUU,MOTON,4                     ; motor on, if 1
        BITDEF  PUU,CLOSE,3                     ; unit closed, remove
        BITDEF  PUU,EXT,2                       ; ext cmd, if 1
        BITDEF  PUU,EMPTY,1                     ; no disk in drive, if 1
        BITDEF  PUU,LAB,0                       ; seclabel usage, if 1

*****************************************************************
* Private task-signals unittask.                                *
* DMABLK occurs after read/write end of Disk-DMA.               *
*****************************************************************

        BITDEF  SIG,DMABLK,11                   ; dma block end

*****************************************************************
* TIMEDRU will be sent by disk.resource, if we got our stuff or *
* by end of microhz-delay.                                      *
*****************************************************************

        BITDEF  SIG,DRUTIME,10                  ; dru regot/timer end

*****************************************************************
* NEWIO sent by VBlankTimer - Reply (DChange) or IOSTD from     *
* BeginIO's PutMsg.                                             *
*****************************************************************

        BITDEF  SIG,NEWIO,9                     ; new io inport

*****************************************************************
* KICKON restarts task after unit has been stopped.             *
*****************************************************************

        BITDEF  SIG,KICKON,8                    ; kickon after sleep

*****************************************************************
* BLTEND will arrive after QBlit is finished in MFM mode.       *
*****************************************************************

        BITDEF  SIG,BLTEND,4                    ; qblit finished

*****************************************************************
* INITREPLY is the answer of unittask when he's ready with      *
* own initialization.                                           *
*****************************************************************

        BITDEF  SIG,INITREPLY,4                 ; initanswer task

*****************************************************************
* NEWSYNC will be sent by SyncWatcher routine only.             *
*****************************************************************

        BITDEF  SIG,NEWSYNC,2                   ; new sync occured

*****************************************************************
* Task-priority/stack                                           *
*****************************************************************

PUU_TASKPRI     EQU     (10)                    ; std devicetask-priority
PUU_TASKSTK     EQU     (800)                   ; stack for task

*****************************************************************
* InitUnitMemList                                               *
*****************************************************************
* This structure is for allocating all stuff needed for a unit. *
* Private, for documentation only.                              *
*****************************************************************

        STRUCTURE InitUnitMemList,0             ; startof

        STRUCT  iuml_Node,LN_SIZE               ; normal node
        UWORD   iuml_NumEntries                 ; # entries

        ULONG   iuml_UnitMem                    ; mem for unit-struct
        ULONG   iuml_UnitSz                     ; sizeof

        ULONG   iuml_StackMem                   ; taskstack-reqs/mem
        ULONG   iuml_StackSz                    ; sizeof

        ULONG   iuml_TrackMem                   ; chiptrack-reqs
        ULONG   iuml_TrackSz                    ; sizeof

        ULONG   iuml_ChipSecMem                 ; chip-sector memory
        ULONG   iuml_ChipSecSz                  ; sizeof

        LABEL   InitUnitMemList_SIZE            ; sizeof

*****************************************************************
* Number of entries in above memlist.                           *
*****************************************************************

IUML_MEMENTRIES EQU     (4)                     ; 4 entries requested

*****************************************************************
* END of hideunits19.i                                          *
*****************************************************************

        ENDC
