home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Extra / RawDIC17.lha / Includes / RawDIC.i
Text File  |  1999-06-14  |  12KB  |  438 lines

  1.  
  2.     ;    Include file for RawDIC V1.3 to V1.7
  3.  
  4.     ; incdir    Includes:
  5.         ifnd    EXEC_TYPES_I
  6.         include    exec/types.i
  7.         endc
  8.  
  9.     ; RawDIC library:
  10.  
  11.     ; calling conventions:    all registers remain unchanged except
  12.     ;            for registers containing return values.
  13.  
  14.  STRUCTURE    RawDIC,0
  15.  
  16.     ULONG    rawdic_ReadTrack
  17.         ; Reads a track into the trackbuffer. This function
  18.         ; will use the tle_Decoder routine for MFM decoding.
  19.         ; DO NOT USE THIS FUNCTION IN YOUR TRACK DECODER
  20.         ; ROUTINES!
  21.  
  22.         ; D0.w=track
  23.         ; => D0.l=errorcode
  24.         ; => A1=trackbuffer
  25.  
  26.         ; errors:
  27.         ; IERR_NOSYNC
  28.         ; IERR_CHECKSUM
  29.         ; IERR_NOSECTOR
  30.         ; IERR_NODISK
  31.         ; IERR_NOTRACK
  32.  
  33.     ULONG    rawdic_NextSync
  34.         ; Search for the next sync-signal on the track.
  35.         ; The trackbuffer will be shifted to the END of the
  36.         ; sync signal (may contain more than one sync word).
  37.         ; If no sync is found, this routine will not return
  38.         ; but display an errormessage. Set DFLG_ERRORS if
  39.         ; you want this function to return.
  40.  
  41.         ; => D0.l=errorcode
  42.         ; => A0=MFM data buffer
  43.  
  44.         ; errors:
  45.         ; IERR_NOSYNC
  46.  
  47.     ULONG    rawdic_NextMFMword
  48.         ; Search for the next sync-signal on the track.
  49.         ; D0 must contain the bit pattern of the signal.
  50.         ; The trackbuffer will be shifted to the END of the
  51.         ; sync signal (may contain more than one sync word).
  52.         ; If no sync is found, this routine will not return
  53.         ; but display an errormessage. Set DFLG_ERRORS if
  54.         ; you want this function to return.
  55.  
  56.         ; D0.w=bitpattern
  57.         ; => D0.l=errorcode
  58.         ; => A0=MFM data buffer
  59.  
  60.         ; errors:
  61.         ; IERR_NOSYNC
  62.  
  63.     ULONG    rawdic_SaveFile
  64.         ; Stores a memory block as file.
  65.         ; An existing file will be overwritten.
  66.  
  67.         ; A0=filename
  68.         ; A1=memory adress
  69.         ; D0.l=length
  70.         ; => D0.l=errorcode
  71.  
  72.         ; errors:
  73.         ; IERR_NOWFILE
  74.  
  75.     ULONG    rawdic_SaveDiskFile
  76.         ; Stores a part of the diskimage as file.
  77.         ; An existing file will be overwritten.
  78.         ; ONLY USE IN dsk_DiskCode!
  79.  
  80.         ; A0=filename
  81.         ; D0.l=offset in diskimage
  82.         ; D1.l=length
  83.         ; => D0.l=errorcode
  84.  
  85.         ; errors:
  86.         ; IERR_NOWFILE
  87.  
  88.     ULONG    rawdic_AppendFile
  89.         ; Similar to rawdic_SaveFile, but if the file already
  90.         ; exists, the data will be appended to the existing file.
  91.  
  92.         ; A0=filename
  93.         ; A1=memory adress
  94.         ; D0.l=length
  95.         ; => D0.l=errorcode
  96.  
  97.         ; errors:
  98.         ; IERR_NOWFILE
  99.  
  100.     ULONG    rawdic_Reserved
  101.         ; DO NOT USE!
  102.  
  103.     ULONG    rawdic_DMFM_STANDARD
  104.         ; Decodes the MFM buffer as standard DOS track.
  105.         ; This function will behave like a standard tle_Decoder and will
  106.         ; ALWAYS return on errors, even with DFLG_ERRORS is not set!
  107.  
  108.         ; D0.b=sectors per track (normally 11)
  109.         ; => D0.l=errorcode
  110.  
  111.         ; errors:
  112.         ; IERR_NOSYNC
  113.         ; IERR_CHECKSUM
  114.         ; IERR_NOSECTOR
  115.  
  116.     ; error codes:
  117.  
  118. IERR_OK        equ    0    ; ok
  119. IERR_CHECKSUM    equ    -1    ; checksum error
  120. IERR_NOSYNC    equ    -2    ; MFM 16-bit pattern not found
  121. IERR_NOSECTOR    equ    -3    ; sector not found (for sector-based disk formats)
  122. IERR_NOWFILE    equ    -4    ; a file could not be stored
  123. IERR_OUTOFMEM    equ    -5    ; no memory to allocate memory
  124. IERR_DISKRANGE    equ    -6    ; a file exceeds diskrange
  125. IERR_NOTRACK    equ    -7    ; not existant track (tracklist...)
  126. IERR_UNDEFINED    equ    -8    ; undefined error message, for private use only!
  127. IERR_NODISK    equ    -9    ; no disk in drive
  128. IERR_CRCFAIL    equ    -10    ; CRC check failed
  129. IERR_TRACKLIST    equ    -11    ; tracklist is invalid
  130. IERR_FILELIST    equ    -12    ; filelist is invalid
  131. IERR_VERSION    equ    -13    ; slave has higher version number than imager
  132. IERR_DSKVERSION    equ    -14    ; disk structure has not supported version number
  133. IERR_FLAGS    equ    -15    ; slave uses flags not to be used with the specified version
  134. IERR_NOFUNCTION    equ    -16    ; function may not be called at the current programstate
  135.  
  136.  STRUCTURE    SlaveStructure,0
  137.  
  138.     UBYTE    slv_Version    ; slave version
  139.     UBYTE    slv_Flags    ; slave flags
  140.     APTR    slv_FirstDisk    ; pointer to the first disk structure
  141.     APTR    slv_Text    ; pointer to the text displayed in the imager window
  142.     LABEL    slv_SIZEOF
  143.  
  144. SFLG_DEBUG    equ    1    ; automatically output debug information
  145. SFLG_VERSION1    equ    SFLG_DEBUG
  146.  
  147.     ; Following files will be saved when SFLG_DEBUG is set:
  148.  
  149.     ; .RawDIC_Debug        ; contains all CRC16 values and the errorcodes which
  150.                 ; tle_Decoder returned
  151.  
  152.     ; While SFLG_DEBUG is set, tle_Decoder errors will NOT terminate slave execution!
  153.     ; All other errors (i.e. while RawDIC function calls) WILL terminate execution!
  154.  
  155.  STRUCTURE    Disk,0
  156.  
  157.     APTR    dsk_NextDisk    ; pointer to next disk structure
  158.     UWORD    dsk_Version    ; disk structure version
  159.     UWORD    dsk_Flags    ; flags (look below)
  160.     APTR    dsk_TrackList    ; list of tracks which contain data
  161.     APTR    dsk_TLExtension    ; CURRENTLY NOT SUPPORTED, ALWAYS SET TO 0!
  162.     APTR    dsk_FileList    ; list of files to be saved
  163.     APTR    dsk_CRCList    ; table of tracks with CRC values
  164.     APTR    dsk_AltDisk    ; alternative disk structure, if CRC failed
  165.     FPTR    dsk_InitCode    ; called before a disk is read
  166.     FPTR    dsk_DiskCode    ; called after a disk has been read
  167.     LABEL    dsk_SIZEOF
  168.  
  169.  ; dsk_NextDisk: contains the pointer to the next disk structure or 0
  170.  ;              if this is the last disk
  171.  
  172.  ; dsk_Flags: possible flags are...
  173.  
  174. DFLG_SINGLESIDE    equ    1    ; only one side of the disk contains data
  175. DFLG_SWAPSIDES    equ    2    ; swap sides in the trackcounter
  176. DFLG_ERRORSWAP    equ    4    ; swap sides on read error
  177. DFLG_ERRORS    equ    8    ; RawDIC functions will return on errors
  178. DFLG_RAWREADONLY equ    16    ; RawDIC will not try to read standard tracks via CMD_READ first
  179. DFLG_NORESTRICTIONS equ    32    ; RawDIC will not check the TrackList
  180. DFLG_DOUBLEINC    equ    64|DFLG_NORESTRICTIONS    ; The track counter will increment by 2 and not 1 as usual
  181. DFLG_VERSION1    equ    DFLG_SWAPSIDES|DFLG_SINGLESIDE|DFLG_ERRORSWAP|DFLG_ERRORS|DFLG_RAWREADONLY|DFLG_NORESTRICTIONS|DFLG_DOUBLEINC    ; used bits
  182.  
  183.  ; dsk_TrackList: A pointer to a table of tracks defined as "valid", other
  184.  ;               tracks will not be read. This is the ONLY field which
  185.  ;               absolutely MUST be used.
  186.  ;               Look below for structure definition.
  187.  
  188.  ; dsk_FileList: A pointer to a table of files which will be written.
  189.  ;              In normal cases files are just parts of the disk image,
  190.  ;              and this is how they are described in this list.
  191.  ;              Setting this pointer to FL_DISKIMAGE will automatically save the
  192.  ;              diskimage as "Disk.#".
  193.  ;        Setting to FL_NULL will save no files.
  194.  
  195.  ; dsk_CRCList:  A table of track numbers and their CRC16 values.
  196.  ;              Use this table to check for special versions.
  197.  ;              Set to 0 when no version check is needed.
  198.  ;              Look below for structure definition.
  199.  ;        To get the CRC16 values, use the SFLG_DEBUG flag and look into the
  200.  ;        debug file.
  201.  
  202.  ; dsk_AltDisk:  A pointer to an ALTERNATIVE disk structure which is
  203.  ;              used when the above CRC check failed.
  204.  ;              Set to 0 if this disk structure has no alternative.
  205.  
  206.  ; dsk_InitCode: A pointer to a subroutine which is called once every time
  207.  ;              RawDIC starts to read a disk. Put your initialisations
  208.  ;              here... if you have any. If not, set to 0!
  209.  
  210.  ;        A5=RawDIC library base
  211.  ;              D0.b=disknumber
  212.  ;              => D0.l=errorcode
  213.  
  214.  ; dsk_DiskCode: A pointer to a subroutine which is called once every time
  215.  ;              RawDIC has FINISHED reading a disk. If you build up your
  216.  ;              FileList out of the disks data, put the routines here!
  217.  ;              Otherwise set to 0.
  218.  
  219.  ;        A5=RawDIC library base
  220.  ;              D0.b=disknumber
  221.  ;              => D0.l=errorcode
  222.  
  223.  STRUCTURE    TrackListEntry,0
  224.  
  225.     WORD    tle_FirstTrack        ; first track of a segment (-1 for last entry)
  226.     WORD    tle_LastTrack        ; last track of a segment
  227.     UWORD    tle_BlockLength        ; length of each track in bytes
  228.     UWORD    tle_Sync        ; sync signal for each track
  229.     FPTR    tle_Decoder        ; MFM decoder routine
  230.     LABEL    tle_SIZEOF
  231.  
  232.  ; tle_Decoder: A pointer to a subroutine which is called after the MFM data of
  233.  ;        a track has been read.
  234.  ;        Put your MFM track to RAW track conversion routines here!!!
  235.  
  236.  ;        A0=MFM data
  237.  ;        A1=trackbuffer
  238.  ;        A5=RawDIC library base
  239.  ;              D0.w=tracknumber
  240.  ;              => D0.l=errorcode
  241.  
  242.  
  243.  STRUCTURE    FileListEntry,0
  244.  
  245.     APTR    fle_Name        ; name of the file (0 for last entry)
  246.     LONG    fle_Offset        ; starting offset in the diskimage
  247.     LONG    fle_Length        ; length of the file
  248.     LABEL    fle_SIZEOF
  249.  
  250.  STRUCTURE    CRCListEntry,0
  251.  
  252.     WORD    crc_Track    ; number of track (-1 for last entry)
  253.     UWORD    crc_Checksum    ; CRC16 value for this track
  254.     LABEL    crc_SIZEOF
  255.  
  256.  
  257.     ; macros:
  258.  
  259.     ; header of imager slaves:
  260.  
  261. SLAVE_HEADER    MACRO
  262.         moveq    #-1,d0
  263.         rts
  264.         dc.b    "RAWDIC"
  265.         ENDM
  266.  
  267.     ; ### macros for MFM decoding:
  268.  
  269.     ; word to byte conversion by skipping every odd bit
  270.  
  271.     ; \1 must be a data register, d7 will be used as loopcounter
  272.     ; d7 is a working register
  273.  
  274.     ; example:    BITSKIP_B d0
  275.  
  276. BITSKIP_B    MACRO
  277.         moveq    #7,d7        ; d7 should be unused
  278. .l0\@        add.w    \1,\1
  279.         add.l    \1,\1
  280.         dbra    d7,.l0\@
  281.         swap    \1
  282.         ENDM
  283.  
  284.     ; long to word conversion by skipping every odd bit
  285.  
  286.     ; \1 must be a data register
  287.     ; d7 is a working register
  288.  
  289.     ; example:    BITSKIP_W d0
  290.  
  291. BITSKIP_W    MACRO
  292.         swap    \1
  293.         move.l    \1,d7
  294.         move.w    #7,d7        ; d7 should be unused
  295. .l0\@        add.w    \1,\1
  296.         add.l    \1,\1
  297.         dbra    d7,.l0\@
  298.         swap    d7
  299.         move.w    d7,\1
  300.         moveq    #7,d7        ; d7 should be unused
  301. .l1\@        add.w    \1,\1
  302.         add.l    \1,\1
  303.         dbra    d7,.l1\@
  304.         swap    \1
  305.         ENDM
  306.  
  307.     ; decodes a byte
  308.  
  309.     ; \1 can be a register, an adress, an indirekt adress etc.
  310.     ; \2 is the source of the bitmask ($5555), it can be
  311.     ;    immediate or a data register
  312.     ; \3 is the target data register which will contain the decoded word
  313.     ; d7 is a working register
  314.  
  315.     ; example:    DECODE_W d6,d1,d0
  316.  
  317. DECODE_B    MACRO
  318.         move.w    \1,\3
  319.         and.w    \2,\3
  320.         move.w    \3,d7
  321.         lsr.w    #7,d7
  322.         add.b    d7,\3
  323.         ENDM
  324.  
  325.     ; decodes a word
  326.  
  327.     ; \1 can be a register, an adress, an indirekt adress etc.
  328.     ; \2 is the source of the bitmask ($55555555), it can be
  329.     ;    immediate or a data register
  330.     ; \3 is the target data register which will contain the decoded word
  331.     ; d7 is a working register
  332.  
  333.     ; example:    DECODE_W d6,d1,d0
  334.  
  335. DECODE_W    MACRO
  336.         move.l    \1,\3
  337.         and.l    \2,\3
  338.         move.l    \3,d7
  339.         swap    d7
  340.         add.w    d7,d7
  341.         add.w    d7,\3
  342.         ENDM
  343.  
  344.     ; decodes a longword
  345.  
  346.     ; \1 must be of (A?)+
  347.     ; \2 is the source of the bitmask ($55555555), it can be
  348.     ;    immediate or a data register
  349.     ; \3 is the target data register which will contain the decoded word
  350.     ; d7 is a working register
  351.  
  352.     ; example:    DECODE_L (a0)+,#$55555555,d0
  353.  
  354. DECODE_L    MACRO
  355.         move.l    \1,\3
  356.         move.l    \1,d7
  357.         and.l    \2,\3
  358.         and.l    \2,d7
  359.         add.l    \3,\3
  360.         add.l    d7,\3
  361.         ENDM
  362.  
  363.     ; values which terminate lists:
  364.  
  365. TL_END        equ    -1
  366. FL_END        equ    -1
  367. CRC_END        equ    -1
  368.  
  369.  ; TL_ENTRY: a tracklist entry
  370.  ; format:    TL_ENTRY tle_FirstTrack,tle_LastTrack,tle_BlockLength,tle_Sync,tle_Decoder
  371.  ; example:    TL_ENTRY 0,19,$1600,SYNC_STANDARD,DMFM_STANDARD
  372.  
  373.     ; defines for sync signals: (tle_Sync)
  374.  
  375. SYNC_INDEX    equ    0    ; used for indexsync (this is NOT syncword 0)
  376. SYNC_STD    equ    $4489    ; standard sync signal
  377. ;SYNC_STANDARD    equ    SYNC_STD    ; obsolete
  378.  
  379.     ; defines for decoder routines: (tle_Decoder)
  380.  
  381. DMFM_NULL    equ    0    ; track contains no data (filled with zeros)
  382. DMFM_STD    equ    1    ; track will be decoded with standard dos track decoder
  383. ;DMFM_STANDARD    equ    DMFM_STD    ; obsolete
  384.  
  385. TLENTRY    MACRO
  386.         dc.w    \1,\2,\3,\4
  387.         dc.l    \5
  388.         ENDM
  389.  
  390.  ; TL_END: terminates a tracklist
  391.  
  392. TLEND        MACRO
  393.         dc.w    TL_END
  394.         ENDM
  395.  
  396.     ; dsk_FileList pre-defined FileLists:
  397.  
  398. FL_DISKIMAGE    equ    0    ; Diskimage only.
  399. FL_NULL        equ    -1    ; Empty FileList, no files will be saved!
  400. FL_NOFILES    equ    FL_NULL
  401.  
  402.  ; FL_ENTRY: a filelist entry
  403.  ; format:    FL_ENTRY fle_Name,fle_Offset,fle_Length
  404.  ; example:    FL_ENTRY FL_DISKNAME,$400,$18a00
  405.  ; diskimage:    FL_ENTRY FL_DISKNAME,0,FL_DISKLENGTH
  406.  
  407.     ; defines for special FLENTRY values:
  408.  
  409. FL_DISKNAME    equ    0    ; put this at fle_Name to get "Disk.???" as filename.
  410. FL_DISKLENGTH    equ    -1    ; put this at fle_Length to get the length of the diskimage (fle_Offset should be 0)
  411.  
  412. FLENTRY    MACRO
  413.         dc.l    \1,\2,\3
  414.         ENDM
  415.  
  416.  ; FL_END: terminates a filelist
  417.  
  418. FLEND        MACRO
  419.         dc.l    FL_END
  420.         ENDM
  421.  
  422.  ; CRC_ENTRY: a crclist entry
  423.  ; format:    FL_ENTRY crc_Track,crc_Checksum
  424.  ; example:    FL_ENTRY 19,$b25a
  425.  
  426. CRCENTRY    MACRO
  427.         dc.w    \1,\2
  428.         ENDM
  429.  
  430.  ; CRC_END: terminates a crclist
  431.  
  432. CRCEND        MACRO
  433.         dc.w    CRC_END
  434.         ENDM
  435.  
  436.  
  437.  
  438.