home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Extra / wwarp.lha / wwarp / src / WWarp.asm < prev   
Assembly Source File  |  2000-08-06  |  53KB  |  2,525 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    WWarp.asm
  3. ;  :Contents.    Disk-Warper
  4. ;  :Author.    Bert Jahn
  5. ;  :EMail.    wepl@whdload.org
  6. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  7. ;  :Version    $Id: WWarp.asm 1.20 2000/08/06 13:13:01 jah Exp jah $
  8. ;  :History.    29.08.98 started
  9. ;        20.09.98 reading of std tracks added, and major rework
  10. ;        22.09.98 tracksize calculation added
  11. ;        08.10.98 def-tracklen changed from $7c00 to $6c00 (harry)
  12. ;        07.11.99 major rework started
  13. ;        24.12.99 varios stuff enhanced
  14. ;        28.05.00 gremlin format added, movehead fixed
  15. ;        21.06.00 writing std/gremlin added
  16. ;        28.06.00 remove fixed, _cmdwork improved
  17. ;        06.08.00 FORCE now skips all tracks which cannot be decoded
  18. ;  :Requires.    OS V37+, MC68020+
  19. ;  :Copyright.    ©1998-2000 Bert Jahn, All Rights Reserved
  20. ;  :Language.    68020 Assembler
  21. ;  :Translator.    Barfly V2.9
  22. ;  :To Do.
  23. ;---------------------------------------------------------------------------*
  24. ;##########################################################################
  25.  
  26.     INCDIR    Includes:
  27.     INCLUDE    lvo/exec.i
  28.     INCLUDE    exec/execbase.i
  29.     INCLUDE    exec/io.i
  30.     INCLUDE    exec/memory.i
  31.     INCLUDE    lvo/dos.i
  32.     INCLUDE    dos/datetime.i
  33.     INCLUDE    dos/dos.i
  34.     INCLUDE    devices/trackdisk.i
  35.     
  36.     INCLUDE    macros/ntypes.i
  37.  
  38. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  39.  
  40. DEFTRACKS    = 160        ;default amount tracks to process
  41. MAXTRACKS    = 160        ;amount tracks which can be procecced (currently)
  42.  
  43. ;length for mfm raw reads
  44. MINTRACKLEN    = $3000        ;minimal track length (limited physical)
  45. DEFTRACKLEN    = $6c00        ;default track length
  46. MAXTRACKLEN    = $7ffe        ;maximal track length (limited by trackdisk.device)
  47. DEFREADRETRY    = 6
  48.  
  49. FILEID        = "WWRP"
  50. FILEVER        = 1
  51. CREATORLEN    = 42
  52.  
  53.     STRUCTURE    WWarpFileHeader,0
  54.         ULONG    wfh_id            ;FILEID
  55.         UWORD    wfh_ver            ;structure format version
  56.         STRUCT    wfh_creator,CREATORLEN    ;creator of wwarp file
  57.         STRUCT    wfh_ctime,ds_SIZEOF    ;date of creation
  58.         STRUCT    wfh_mtime,ds_SIZEOF    ;date of last modification
  59.         LABEL    wfh_SIZEOF
  60.  
  61. TABLEID        = "TABL"
  62. TABLEVER    = 1
  63.  
  64.     STRUCTURE    WWarpTrackTable,0
  65.         ULONG    wtt_id            ;TABLEID
  66.         UWORD    wtt_ver            ;structure format version
  67.         UWORD    wtt_first        ;first track in list
  68.         UWORD    wtt_last        ;last track in list
  69.         LABEL    wtt_tab            ;track table, one bit for each track 
  70.  
  71. TRACKID        = "TRCK"
  72. TRACKVER    = 1
  73. SYNCLEN        = 16
  74.  
  75.     STRUCTURE    WWarpTrackHeader,0
  76.         ULONG    wth_id            ;TRACKID
  77.         UWORD    wth_ver            ;structure format version
  78.         UWORD    wth_num            ;track number
  79.         UWORD    wth_type        ;track data format type
  80.         UWORD    wth_flags        ;flags
  81.         ULONG    wth_len            ;length of data contained in wwp in bits!
  82.         ULONG    wth_wlen        ;lengtn of data to write back in bytes!
  83.         STRUCT    wth_sync,SYNCLEN    ;sync
  84.         STRUCT    wth_mask,SYNCLEN    ;sync mask (used bits in wth_sync)
  85.         LABEL    wth_data        ;track data
  86.  
  87. ;track types
  88.  
  89.  ENUM 0
  90.  EITEM TT_RAW        ;raw mfm data
  91.  EITEM TT_STD        ;standard dos format ($1600 bytes)
  92.  EITEM TT_GREM        ;gremlin format ($1800 bytes)
  93.  
  94. ;track flags
  95.  
  96.  BITDEF TF,INDEX,0    ;track data starts with index signal (only TT_RAW)
  97.  BITDEF TF,BZIP2,1    ;copressed wih bzip2
  98.  BITDEF TF,RAWSINGLE,2    ;raw mfm data is saved in exact bit length
  99.  BITDEF TF,LEQ,3    ;all longs equal
  100.  BITDEF TF,SLINC,4    ;sector longs incremented
  101.  
  102. FILENAMELEN    = 1024
  103.  
  104.     STRUCTURE    Globals,0
  105.         APTR    gl_execbase
  106.         APTR    gl_dosbase
  107.         APTR    gl_rdargs
  108.         LABEL    gl_rdarray
  109.         ULONG    gl_rd_file        ;name of the wwarp file
  110.         ULONG    gl_rd_cmd        ;operation to perform
  111.         ULONG    gl_rd_tracks        ;affected tracks
  112.         ULONG    gl_rd_arg        ;further argument depending on operation
  113.         ULONG    gl_rd_bpt        ;bytes per track
  114.         ULONG    gl_rd_unit        ;drive unit
  115.         ULONG    gl_rd_nostd        ;dont try to read std format
  116.         ULONG    gl_rd_retry        ;how many read retries
  117.         ULONG    gl_rc            ;programs return code
  118.         APTR    gl_chipbuf
  119.         APTR    gl_fastbuf
  120.         ALIGNLONG
  121.         STRUCT    gl_DateTime,dat_SIZEOF
  122.         STRUCT    gl_date,LEN_DATSTRING
  123.         STRUCT    gl_time,LEN_DATSTRING
  124.         STRUCT    gl_headin,wfh_SIZEOF    ;file header input
  125.         STRUCT    gl_headout,wfh_SIZEOF    ;file header output
  126.         STRUCT    gl_tabarg,wtt_tab+MAXTRACKS/8    ;tracks specified via command line
  127.                             ;default = argument || tabin
  128.         STRUCT    gl_tabin,wtt_tab+MAXTRACKS/8    ;tracks contained in input file
  129.         STRUCT    gl_tabread,wtt_tab+MAXTRACKS/8    ;tracks to read from the input file
  130.                             ;default = 0
  131.         STRUCT    gl_tabout,wtt_tab+MAXTRACKS/8    ;tracks to write to the output file
  132.                             ;default = tabin
  133.         STRUCT    gl_tabdo,wtt_tab+MAXTRACKS/8    ;tracks on which user func will called
  134.                             ;default = tabarg
  135.         STRUCT    gl_trk,wth_data
  136.         STRUCT    gl_filename,FILENAMELEN
  137.         STRUCT    gl_filename2,FILENAMELEN
  138.         STRUCT    gl_io,8            ;normal iorequest,msgport
  139.         STRUCT    gl_ioi,8        ;indexsync iorequest,msgport
  140.         STRUCT    gl_sync,SYNCLEN*2
  141.         STRUCT    gl_tmpbuf,$1800
  142.         BYTE    gl_break
  143.         ALIGNLONG
  144.         LABEL    gl_SIZEOF
  145.  
  146. ;##########################################################################
  147.  
  148. GL    EQUR    A4        ;a4 ptr to Globals
  149. LOC    EQUR    A5        ;a5 for local vars
  150. CPU    =    68020
  151.  
  152.     OUTPUT    C:WWarp
  153.     BOPT    O+        ;enable optimizing
  154.     ;BOPT    OG+        ;enable optimizing
  155.     BOPT    ODd-        ;disable mul optimizing
  156.     BOPT    ODe-        ;disable mul optimizing
  157.     BOPT    wo-        ;no optimize warnings
  158.  
  159.     IFND    .passchk
  160.     DOSCMD    "WBuild >T:build"
  161.     DOSCMD    "WDate  >T:date"
  162. .passchk
  163.     ENDC
  164.  
  165. Version        = 1
  166. Revision    = 6
  167.  
  168.     SECTION a,CODE
  169.  
  170.         bra    _Start
  171.  
  172.         dc.b    "$VER: "
  173. _txt_creator    sprintx    "WWarp %ld.%ld [build ",Version,Revision
  174.         INCBIN    "T:build"
  175.         dc.b    "] "
  176.         INCBIN    "T:date"
  177.         dc.b    0
  178.         dc.b    "$Id: WWarp.asm 1.20 2000/08/06 13:13:01 jah Exp jah $",0
  179.     EVEN
  180.  
  181. ;##########################################################################
  182.  
  183.     INCDIR    Sources:
  184.     INCLUDE    dosio.i
  185.         PrintLn
  186.         PrintArgs
  187.         CheckBreak
  188.         FlushOutput
  189.         GetKey
  190.     INCLUDE    strings.i
  191.         atoi
  192.         etoi
  193.         AppendString
  194.         StrNCaseCmp
  195.         CopyString
  196.         StrLen
  197.     INCLUDE    error.i
  198.         PrintErrorDOS
  199.         PrintErrorTD
  200.  
  201. ;##########################################################################
  202.  
  203. _StartErr    moveq    #33,d0            ;kick 1.2
  204.         lea    (_dosname),a1
  205.         jsr    (_LVOOpenLibrary,a6)
  206.         tst.l    d0
  207.         beq    .q
  208.         move.l    d0,a6
  209.         jsr    (_LVOOutput,a6)
  210.         move.l    d0,d1            ;file handle
  211.         move.l    (a7)+,d2
  212.         move.l    d2,a0
  213.         moveq    #-1,d3
  214. .c        addq.l    #1,d3
  215.         tst.b    (a0)+
  216.         bne    .c
  217.         jsr    (_LVOWrite,a6)
  218.         move.l    a6,a1
  219.         move.l    (gl_execbase,GL),a6
  220.         jsr    (_LVOCloseLibrary,a6)
  221. .q        move.l    (gl_rc,GL),d0
  222.         rts
  223.  
  224.     ;program start
  225. _Start        lea    (_Globals),GL
  226.         move.l    #RETURN_FAIL,(gl_rc,GL)
  227.         move.l    (4).w,a6
  228.         move.l    a6,(gl_execbase,GL)
  229.  
  230.     ;check cpu
  231.         btst    #AFB_68020,(AttnFlags+1,a6)
  232.         bne    .cpuok
  233.         pea    (_badcpu)
  234.         bra    _StartErr
  235. .cpuok
  236.     MC68020
  237.     ;open dos.library
  238.         move.l    #37,d0
  239.         lea    (_dosname),a1
  240.         move.l    (gl_execbase,GL),a6
  241.         jsr    _LVOOpenLibrary(a6)
  242.         move.l    d0,(gl_dosbase,GL)
  243.         bne    .dosok
  244.         pea    (_badkick)
  245.         bra    _StartErr
  246. .dosok
  247.     ;read arguments
  248.         lea    (_template),a0
  249.         move.l    a0,d1
  250.         lea    (gl_rdarray,GL),a0
  251.         move.l    a0,d2
  252.         moveq    #0,d3
  253.         move.l    (gl_dosbase,GL),a6
  254.         jsr    (_LVOReadArgs,a6)
  255.         move.l    d0,(gl_rdargs,GL)
  256.         bne    .argsok
  257.         lea    (_readargs),a0
  258.         bsr    _PrintErrorDOS
  259.         bsr    _help
  260.         bra    .noargs
  261. .argsok
  262.     ;check filename
  263.         move.l    (gl_rd_file,GL),a0
  264.         lea    (gl_filename,GL),a1
  265.         move.l    #FILENAMELEN,d0
  266.         bsr    _CopyString
  267.         lea    (gl_filename,GL),a0
  268.         bsr    _StrLen
  269.         cmp.l    #4,d0
  270.         bls    .cs_1
  271.         lea    (gl_filename-4.w,GL,d0.l),a0
  272.         lea    (_extension),a1
  273.         moveq    #4,d0
  274.         bsr    _StrNCaseCmp
  275.         tst.l    d0
  276.         beq    .cs_end
  277. .cs_1        lea    (gl_filename,GL),a0
  278.         move.l    a0,d1
  279.         move.l    #ACCESS_READ,d2
  280.         move.l    (gl_dosbase,GL),a6
  281.         jsr    (_LVOLock,a6)
  282.         move.l    d0,d1
  283.         beq    .cs_2
  284.         jsr    (_LVOUnLock,a6)
  285.         bra    .cs_end
  286. .cs_2        lea    (_extension),a0
  287.         lea    (gl_filename,GL),a1
  288.         move.l    #FILENAMELEN,d0
  289.         bsr    _AppendString
  290. .cs_end
  291.  
  292.     ;parse tracks
  293.         move    #0,(gl_tabarg+wtt_first,GL)
  294.         move    #MAXTRACKS-1,(gl_tabarg+wtt_last,GL)
  295.         move.l    (gl_rd_tracks,GL),a0
  296.         move.l    a0,d0
  297.         beq    .pt_def
  298.         cmp.w    #"*"<<8,(a0)
  299.         bne    .pt_loop
  300.         clr.l    (gl_rd_tracks,GL)
  301. .pt_def        move.l    #DEFTRACKS-1,d0
  302. .pt_1        bfset    (gl_tabarg+wtt_tab,GL){d0:1}
  303.         dbf    d0,.pt_1
  304.         bra    .pt_end
  305.  
  306. .pt_loop    bsr    .pt_getnum
  307.         move.b    (a0)+,d1
  308.         beq    .pt_single
  309.         cmp.b    #",",d1
  310.         beq    .pt_single
  311.         cmp.b    #"-",d1
  312.         beq    .pt_area
  313.         cmp.b    #"*",d1
  314.         beq    .pt_step
  315.         bra    .pt_err
  316.  
  317. .pt_single    bfset    (gl_tabarg+wtt_tab,GL){d0:1}
  318. .pt_check    tst.b    d1
  319.         beq    .pt_end
  320.         cmp.b    #",",d1
  321.         beq    .pt_loop
  322.         bra    .pt_err
  323.         
  324. .pt_step    move.l    d0,d2            ;D2 = start
  325.         move.l    #DEFTRACKS-1,d3        ;D3 = last
  326. .pt_step0    bsr    .pt_getnum        ;D0 = skip
  327.         tst.l    d0
  328.         ble    .pt_err
  329. .pt_step1    cmp.l    d2,d3
  330.         blo    .pt_err
  331. .pt_step_l    bfset    (gl_tabarg+wtt_tab,GL){d2:1}
  332.         add.l    d0,d2
  333.         cmp.l    d2,d3
  334.         bhs    .pt_step_l
  335.         move.b    (a0)+,d1
  336.         bra    .pt_check
  337.  
  338. .pt_area    move.l    d0,d2            ;D2 = start
  339.         bsr    .pt_getnum
  340.         move.l    d0,d3            ;D3 = last
  341.         moveq    #1,d0            ;D0 = skip
  342.         cmp.b    #"*",(a0)
  343.         bne    .pt_step1
  344.         addq.l    #1,a0
  345.         bra    .pt_step0
  346.  
  347. .pt_getnum    move.l    (a7)+,a1
  348.         move.l    a0,a3
  349.         bsr    _atoi
  350.         cmp.l    a0,a3
  351.         beq    .pt_err
  352.         cmp.l    #MAXTRACKS,d0
  353.         bhs    .pt_err
  354.         jmp    (a1)
  355.  
  356. .pt_err        lea    (_txt_badtracks),a0
  357.         bsr    _PrintBold
  358.         bsr    _help
  359.         bra    .badargs
  360.  
  361. .pt_end
  362.         move.l    #MAXTRACKLEN,d2        ;D2 = maximal rawreadlen
  363.         move.l    #DEFTRACKLEN,d0        ;default tracklength
  364.         move.l    (gl_rd_bpt,GL),d1
  365.         beq    .bptok
  366.         move.l    d1,a0
  367.         bsr    _atoi
  368.         addq.l    #1,d0
  369.         bclr    #0,d0            ;word aligned
  370.         cmp.l    d2,d0
  371.         blt    .bptok
  372.         move.l    d2,d0
  373. .bptok        move.l    d0,(gl_rd_bpt,GL)
  374.  
  375.         move.l    (gl_rd_unit,GL),d0
  376.         beq    .unitok
  377.         move.l    d0,a0
  378.         move.l    (a0),d0
  379. .unitok        move.l    d0,(gl_rd_unit,GL)
  380.  
  381.         move.l    #DEFREADRETRY,d1
  382.         move.l    (gl_rd_retry,GL),d0
  383.         beq    .retryok
  384.         move.l    d0,a0
  385.         move.l    (a0),d1
  386. .retryok    move.l    d1,(gl_rd_retry,GL)
  387.  
  388.     ;init globals
  389.         lea    (_chipbuf),a0
  390.         move.l    a0,(gl_chipbuf,GL)
  391.         move.l    #MAXTRACKLEN,d0
  392.         move.l    #MEMF_FAST,d1
  393.         move.l    (gl_execbase,GL),a6
  394.         jsr    (_LVOAllocVec,a6)
  395.         move.l    d0,(gl_fastbuf,GL)
  396.         bne    .memok
  397.         move.l    (gl_chipbuf,GL),(gl_fastbuf,GL)
  398. .memok
  399.         pea    (.return)
  400.         move.l    (gl_rd_cmd,GL),d0
  401.         beq    _cmd_create
  402.         move.l    d0,a0
  403.         move.b    (a0)+,d0
  404.         tst.b    (a0)
  405.         bne    _cmd_bad
  406.         UPPER    d0
  407.         cmp.b    #"C",d0
  408.         beq    _cmd_create
  409.         cmp.b    #"D",d0
  410.         beq    _cmd_dump
  411.         cmp.b    #"F",d0
  412.         beq    _cmd_force
  413.         cmp.b    #"I",d0
  414.         beq    _cmd_info
  415.         cmp.b    #"L",d0
  416.         beq    _cmd_length
  417.         cmp.b    #"M",d0
  418.         beq    _cmd_merge
  419.         cmp.b    #"P",d0
  420.         beq    _cmd_pack
  421.         cmp.b    #"R",d0
  422.         beq    _cmd_remove
  423.         cmp.b    #"S",d0
  424.         beq    _cmd_save
  425.         cmp.b    #"Y",d0
  426.         beq    _cmd_sync
  427.         cmp.b    #"W",d0
  428.         beq    _cmd_write
  429.         bra    _cmd_bad
  430. .return
  431.     ;free globals
  432.         move.l    (gl_fastbuf,GL),a1
  433.         cmp.l    (gl_chipbuf,GL),a1
  434.         beq    .fgle
  435.         move.l    (gl_execbase,GL),a6
  436.         jsr    (_LVOFreeVec,a6)
  437. .fgle
  438. .badargs
  439.         move.l    (gl_rdargs,GL),d1
  440.         move.l    (gl_dosbase,GL),a6
  441.         jsr    (_LVOFreeArgs,a6)
  442. .noargs
  443.         move.l    (gl_dosbase,GL),a1
  444.         move.l    (gl_execbase,GL),a6
  445.         jsr    (_LVOCloseLibrary,a6)
  446. .nodoslib
  447.         move.l    (gl_rc,GL),d7
  448. _rts        rts
  449.  
  450. ;##########################################################################
  451.  
  452. _cmd_bad    lea    (_txt_badcmd),a0
  453.         bsr    _PrintBold
  454.  
  455. _help        lea    (_txt_help),a0
  456.         bra    _Print
  457.  
  458. ;##########################################################################
  459. ;##########################################################################
  460.  
  461.     INCLUDE    cmdc.s
  462.  
  463. ;##########################################################################
  464. ;##########################################################################
  465.  
  466. _cmd_dump    moveq    #0,d4            ;D4 = sync specified
  467.         moveq    #1,d5            ;D5 = sync num
  468.         moveq    #0,d6            ;D6 = length
  469.         moveq    #0,d7            ;D7 = offset
  470.  
  471.     ;parse argument
  472.         move.l    (gl_rd_arg,GL),d0
  473.         beq    .argend
  474.         move.l    d0,a2            ;A2 = arg
  475.     ;sync
  476.         cmp.b    #",",(a2)
  477.         beq    .send
  478.         move.l    a2,a0
  479. .sl        move.b    (a0)+,d0
  480.         beq    .se
  481.         cmp.b    #",",d0
  482.         bne    .sl
  483. .se        move.b    -(a0),d2
  484.         clr.b    (a0)
  485.         exg.l    a0,a2
  486.         bsr    _parsesync
  487.         tst.l    d0
  488.         beq    _rts
  489.         moveq    #-1,d4
  490.         move.b    d2,(a2)
  491.     ;sync num
  492. .send        cmp.b    #",",(a2)+
  493.         bne    .arglast
  494.         cmp.b    #",",(a2)
  495.         beq    .snend
  496.         move.l    a2,a0
  497.         bsr    _atoi
  498.         cmp.l    a0,a2
  499.         beq    .argerr
  500.         move.l    a0,a2
  501.         move.l    d0,d5
  502.         ble    .argerr
  503.     ;length
  504. .snend        cmp.b    #",",(a2)+
  505.         bne    .arglast
  506.         cmp.b    #",",(a2)
  507.         beq    .lend
  508.         move.l    a2,a0
  509.         bsr    _etoi
  510.         cmp.l    a0,a2
  511.         beq    .argerr
  512.         move.l    a0,a2
  513.         move.l    d0,d6
  514.         ble    .argerr
  515.     ;offset
  516. .lend        cmp.b    #",",(a2)+
  517.         bne    .arglast
  518.         move.l    a2,a0
  519.         bsr    _etoi
  520.         cmp.l    a0,a2
  521.         beq    .argerr
  522.         move.l    d0,d7
  523.         lea    (1,a0),a2
  524. .arglast    tst.b    -(a2)
  525.         bne    .argerr
  526. .argend
  527.         move.l    #CMDF_IN,d0        ;flags
  528.         movem.l    d4-d7,-(a7)
  529.         move.l    a7,a0            ;cbdata
  530.         lea    .tracktable,a1        ;cbtt
  531.         lea    .tracks,a2        ;cbt
  532.         bsr    _cmdwork
  533.         add.w    #16,a7
  534.         rts
  535.  
  536. .argerr        lea    (_badarg),a0
  537.         bra    _Print
  538.  
  539. .tracktable    lea    (gl_tabarg,GL),a0
  540.         lea    (gl_tabread,GL),a1
  541.         bsr    _copytt
  542.         moveq    #-1,d0
  543.         rts
  544.  
  545. .tracks        movem.l    d2-d7/a2-a3,-(a7)
  546.         move.l    a0,a3            ;a3 = cbdata
  547.  
  548.     ;display track info
  549.         move.l    (gl_trk+wth_wlen,GL),-(a7)
  550.         move.l    (gl_trk+wth_len,GL),d0
  551.         move.l    d0,d1
  552.         and.l    #7,d1
  553.         lsr.l    #3,d0
  554.         movem.l    d0-d1,-(a7)
  555.         moveq    #" ",d0
  556.         btst    #TFB_INDEX,(gl_trk+wth_flags+1,GL)
  557.         beq    .fi
  558.         moveq    #"I",d0
  559. .fi        move.l    d0,-(a7)
  560.         bsr    _gettt
  561.         pea    (a0)
  562.         move.l    d5,-(a7)
  563.         lea    (_dump1),a0
  564.         move.l    a7,a1
  565.         bsr    _PrintArgs
  566.         add.w    #6*4,a7
  567.         lea    (gl_trk+wth_sync,GL),a0
  568.         bsr    _printsync
  569.         bsr    _PrintLn
  570.  
  571.     ;search syncs
  572.         moveq    #0,d7                ;d7 = bitoffset in buffer to display
  573.         cmp.w    #TT_RAW,(gl_trk+wth_type,GL)
  574.         bne    .dsend
  575.         lea    (gl_sync,GL),a2            ;a2 = sync (via arg)
  576.         tst.l    (a3)
  577.         bne    .syncarg
  578.         lea    (gl_trk+wth_sync,GL),a2        ;a2 = sync (from track header)
  579. .syncarg    move.l    a2,a0
  580.         bsr    _testsync
  581.         tst.l    d0
  582.         beq    .dsend
  583.         moveq    #0,d2                ;d2 = bitoffset in buffer
  584.         move.l    (gl_trk+wth_len,GL),d3        ;d3 = bitlength buffer
  585.         move.l    (gl_trk+wth_flags,GL),d0
  586.         btst    #TFF_RAWSINGLE,d0
  587.         bne    .dsraws
  588. .dsraw        sub.l    #SYNCLEN*8-1,d3
  589.         move.l    #DEFTRACKLEN/2*8,d0
  590.         cmp.l    d0,d3
  591.         bls    .dsgo
  592.         move.l    d0,d3
  593.         bra    .dsgo
  594. .dsraws        bsr    _doubleraws
  595. .dsgo        moveq    #0,d4                ;d4 = num of sync found
  596. .dsloop        move.l    d2,d0
  597.         move.l    d3,d1
  598.         move.l    (gl_fastbuf,GL),a0
  599.         move.l    a2,a1
  600.         bsr    _searchsync
  601.         move.l    d0,d2
  602.         bmi    .dsprint
  603.         addq.l    #1,d4
  604.         cmp.l    (4,a3),d4
  605.         bhi    .ds1
  606.         move.l    d2,d7
  607. .ds1        addq.l    #1,d2
  608.         cmp.l    d3,d2
  609.         blo    .dsloop
  610. .dsprint    lea    (_syncfound1),a0
  611.         bsr    _Print
  612.         move.l    a2,a0
  613.         bsr    _printsync
  614.         lea    (_syncfound2),a0
  615.         move.l    d4,-(a7)
  616.         move.l    a7,a1
  617.         bsr    _PrintArgs
  618.         addq.l    #4,a7
  619.         move.l    d7,d0
  620.         bsr    _printbitlen
  621.         bsr    _PrintLn
  622. .dsend
  623.     ;dump
  624.         move.l    (gl_trk+wth_len,GL),d4        ;d4 = buffersize in bits
  625.     ;offset
  626.         move.l    (12,a3),d6            ;d6 = offset in bytes
  627.         move.l    d6,d0
  628.         asl.l    #3,d0                ;in bits
  629.         add.l    d0,d7                ;d7 = shift + offset
  630.         bmi    .offerr
  631.         beq    .endshift
  632.         cmp.l    d7,d4
  633.         ble    .offerr
  634.         move.w    (gl_trk+wth_flags,GL),d0
  635.         btst    #TFF_RAWSINGLE,d0
  636.         beq    .single
  637.         sub.l    d7,d4
  638. .single        move.l    d7,d0
  639.         move.l    d4,d1                ;bitlen new buffer
  640.         move.l    (gl_fastbuf,GL),a0        ;buffer
  641.         bsr    _shiftmfm
  642. .endshift    addq.l    #7,d4
  643.         lsr.l    #3,d4                ;d4 = buffersize in bytes
  644.     ;length
  645.         move.l    (8,a3),d0            ;length
  646.         bne    .len1
  647.         move.l    (gl_trk+wth_wlen,GL),d0
  648.         beq    .lenok
  649. .len1        cmp.l    d0,d4
  650.         bls    .lenok
  651.         move.l    d0,d4
  652. .lenok
  653.     ;dump
  654.         move.l    d4,d0                ;length
  655.         move.l    d6,d1                ;delta
  656.         move.l    (gl_fastbuf,GL),a0        ;memory
  657.         bsr    _DumpMemory
  658.  
  659.     ;return
  660.         moveq    #-1,d0                ;success
  661. .end        movem.l    (a7)+,d2-d7/a2-a3
  662.         rts
  663.  
  664. .offerr        lea    (_offerr),a0
  665.         bsr    _Print
  666.         moveq    #0,d0
  667.         bra    .end
  668.  
  669. ;----------------------------------------
  670. ; dump memory
  671. ; IN:    d0 = ULONG len
  672. ;    d1 = ULONG delta
  673. ;    a0 = APTR  memory
  674. ; OUT:    d0 = BOOL success
  675.  
  676. _DumpMemory    movem.l    d1/d5-d6/a2-a3,-(a7)
  677.         move.l    a0,a2            ;A2 = actual address
  678.         lea    (a2,d0.l),a3        ;A3 = end address
  679.         clr.w    (a7)
  680.  
  681. .line        bsr    _CheckBreak        ;check for CTRL-C
  682.         tst.l    d0
  683.         bne    .break
  684.  
  685.         lea    (.adr),a0
  686.         lea    (2,a7),a1
  687.         bsr    _PrintArgs
  688.         
  689.         moveq    #7,d6
  690.         
  691. .mem        lea    (.space),a0
  692.         bsr    _Print
  693.         
  694.         moveq    #3,d5
  695.  
  696. .long        lea    (.byte),a0
  697.         move.b    (a2)+,(1,a7)
  698.         move.l    a7,a1
  699.         bsr    _PrintArgs
  700.         addq.w    #1,(2,a7)
  701.         cmp.l    a2,a3
  702.         bls    .ok
  703.         
  704.         dbf    d5,.long
  705.  
  706.         dbf    d6,.mem
  707.  
  708. .ok        bsr    _PrintLn
  709.  
  710.         cmp.l    a2,a3
  711.         bhi    .line
  712.         
  713. .break        movem.l    (a7)+,_MOVEMREGS
  714.         rts
  715.  
  716. .adr        dc.b    "$%04x",0
  717. .space        dc.b    " ",0
  718. .byte        dc.b    "%02x",0
  719.     EVEN
  720.  
  721. ;##########################################################################
  722. ;##########################################################################
  723.  
  724. _cmd_force    move.l    #CMDF_OUT|CMDF_IN,d0    ;flags
  725.         sub.l    a0,a0            ;cbdata
  726.         lea    .tracktable,a1        ;cbtt
  727.         lea    .tracks,a2        ;cbt
  728.         bra    _cmdwork
  729.  
  730. .tracktable    lea    (gl_tabin,GL),a0
  731.         lea    (gl_tabread,GL),a1
  732.         bsr    _copytt
  733.         moveq    #-1,d0
  734.         rts
  735.  
  736. .tracks
  737.     ;check type
  738.         cmp.w    #TT_RAW,(gl_trk+wth_type,GL)
  739.         bne    .badtype
  740.  
  741.     ;if single -> double
  742.         bsr    _doubleraws
  743.         move.l    d0,d5            ;D5 = mfm length
  744.  
  745.     ;search start
  746.         moveq    #0,d0
  747.         move.l    d5,d1
  748.         move.l    (gl_fastbuf,GL),a0
  749.         lea    (_syncstd2),a1
  750.         bsr    _searchsync
  751.         move.l    d0,d6            ;D6 = offset
  752.         bmi    .nosync
  753.  
  754.     ;check that remaining mfm data is sufficent
  755.         sub.l    d6,d5            ;in bits
  756.         cmp.l    #11*$440*8,d5
  757.         blo    .shortmfm
  758.  
  759.     ;decode track
  760.         move.l    #%11111111111,d4    ;D4 = sectors
  761.         move.l    #$55555555,d5        ;D5 = mfm decode
  762.         moveq    #11-1,d7        ;D7 = sector loop count
  763.         move.l    (gl_fastbuf,GL),a0    ;A0 = mfm buffer
  764.         subq.l    #4,a0            ;first $aaaaaaaa
  765.  
  766. .sector        bsr    .getlw            ;$2aaaaaaa
  767.         bsr    .getlw            ;$44894489
  768.         cmp.l    #$44894489,d0
  769.         bne    .no
  770.         
  771.         moveq    #0,d3            ;D3 = chksum
  772.  
  773.         bsr    .getlwd            ;sector header
  774.         
  775.         lsr.l    #8,d0            ;sector number 0..10
  776.         cmp.b    #10,d0
  777.         bhi    .no
  778.         bclr    d0,d4
  779.         beq    .no            ;same sector again
  780.         moveq    #0,d1
  781.         move.b    d0,d1
  782.         mulu    #$200,d1
  783.         lea    (gl_tmpbuf.w,GL,d1.l),a1
  784.         
  785.         moveq    #3,d2
  786. .label        bfextu    (a0){d6:32},d0
  787.         bfextu    (16,a0){d6:32},d1
  788.         eor.l    d0,d3
  789.         eor.l    d1,d3
  790.         and.l    d5,d0
  791.         bne    .no
  792.         and.l    d5,d1
  793.         bne    .no
  794.         addq.l    #4,a0
  795.         dbf    d2,.label
  796.         add.w    #16,a0
  797.  
  798.         move.l    d3,d2
  799.         and.l    d5,d2
  800.         bsr    .getlwd            ;header chksum
  801.         cmp.l    d2,d0
  802.         bne    .no
  803.         
  804.         bsr    .getlwd            ;data chksum
  805.         move.l    d0,d3
  806.  
  807.         moveq    #$200/4-1,d2
  808. .data        bfextu    (a0){d6:32},d0
  809.         bfextu    ($200,a0){d6:32},d1
  810.         eor.l    d0,d3
  811.         and.l    d5,d0
  812.         eor.l    d1,d3
  813.         and.l    d5,d1
  814.         add.l    d0,d0
  815.         addq.l    #4,a0
  816.         or.l    d0,d1
  817.         move.l    d1,(a1)+
  818.         dbf    d2,.data
  819.         add.w    #$200,a0
  820.         
  821.         and.l    d5,d3
  822.         bne    .no
  823.         
  824.         dbf    d7,.sector
  825.         
  826.     ;copy buffer
  827.         move.w    #$1600/4-1,d0
  828.         lea    (gl_tmpbuf,GL),a0
  829.         move.l    (gl_fastbuf,GL),a1
  830. .copy        move.l    (a0)+,(a1)+
  831.         dbf    d0,.copy
  832.  
  833.     ;set track header
  834.         move.w    #TT_STD,(gl_trk+wth_type,GL)
  835.         move.w    #0,(gl_trk+wth_flags,GL)
  836.         move.l    #$1600*8,(gl_trk+wth_len,GL)
  837.  
  838.         moveq    #-1,d0
  839.         rts
  840.  
  841. .getlw        bfextu    (a0){d6:32},d0
  842.         addq.l    #4,a0
  843.         eor.l    d0,d3
  844.         rts
  845.  
  846. .getlwd        bsr    .getlw
  847.         move.l    d0,d1
  848.         bsr    .getlw
  849.         and.l    d5,d1
  850.         and.l    d5,d0
  851.         add.l    d1,d1
  852.         or.l    d1,d0
  853.         rts
  854.  
  855. .badtype    lea    (_forcebadtype),a0
  856.         bra    .print
  857. .nosync        lea    (_forcenosync),a0
  858.         bra    .print
  859. .shortmfm    lea    (_forceshortmfm),a0
  860.         bra    .print
  861. .no        lea    (_forcebad),a0
  862. .print        lea    (gl_trk+wth_num,GL),a1
  863.         bsr    _PrintArgs
  864.         moveq    #1,d0
  865.         rts
  866.  
  867. ;##########################################################################
  868. ;##########################################################################
  869.  
  870. _cmd_info    move.l    #CMDF_NOTTC|CMDF_IN,d0    ;flags
  871.         lea    .tracktable,a1        ;cbtt
  872.         lea    .tracks,a2        ;cbt
  873.         bra    _cmdwork
  874.  
  875.     ;display for file
  876. .tracktable    lea    (_txt_infohead1),a0
  877.         bsr    _Print
  878.         lea    (gl_headin+wfh_creator,GL),a0
  879.         bsr    _Print
  880.  
  881.         lea    (gl_headin+wfh_ctime,GL),a0
  882.         bsr    _GetDate
  883.         lea    (_txt_infohead2),a0
  884.         pea    (gl_time,GL)
  885.         pea    (gl_date,GL)
  886.         move.l    a7,a1
  887.         bsr    _PrintArgs
  888.         add.w    #8,a7
  889.         
  890.         lea    (gl_headin+wfh_mtime,GL),a0
  891.         bsr    _GetDate
  892.         lea    (_txt_infohead3),a0
  893.         pea    (gl_time,GL)
  894.         pea    (gl_date,GL)
  895.         move.l    a7,a1
  896.         bsr    _PrintArgs
  897.         add.w    #8,a7
  898.  
  899.         moveq    #0,d0
  900.         move.l    #MAXTRACKS-1,d1
  901. .c0        bftst    (gl_tabin+wtt_tab,GL){d1:1}
  902.         beq    .c1
  903.         addq.l    #1,d0
  904. .c1        dbf    d1,.c0
  905.         
  906.         lea    (_txt_infohead4),a0
  907.         move.l    d0,-(a7)
  908.         move.l    a7,a1
  909.         bsr    _PrintArgs
  910.         addq.l    #4,a7
  911.  
  912.         moveq    #-1,d0
  913.         rts
  914.  
  915.     ;display for each track
  916. .tracks        bsr    _gettt
  917.         subq.l    #8,a7
  918.         move.l    a7,a1
  919.         pea    (a1)
  920.         moveq    #3,d0
  921. .fs1        move.b    (a0)+,(a1)+
  922.         dbeq    d0,.fs1
  923.         bne    .fs3
  924.         subq.l    #1,a1
  925. .fs2        move.b    #" ",(a1)+
  926.         dbf    d0,.fs2
  927. .fs3        clr.b    (a1)
  928.         lea    (_txt_infotrack),a0
  929.         move.l    d5,-(a7)
  930.         move.l    a7,a1
  931.         bsr    _PrintArgs
  932.         add.w    #16,a7
  933.  
  934.         moveq    #" ",d2
  935.         btst    #TFB_SLINC,(gl_trk+wth_flags+1,GL)
  936.         beq    .fc
  937.         moveq    #"C",d2
  938. .fc        move.l    (gl_dosbase,GL),a6
  939.         jsr    (_LVOOutput,a6)
  940.         move.l    d0,d1
  941.         jsr    (_LVOFPutC,a6)
  942.  
  943.         moveq    #" ",d2
  944.         btst    #TFB_LEQ,(gl_trk+wth_flags+1,GL)
  945.         beq    .fq
  946.         moveq    #"Q",d2
  947. .fq        move.l    (gl_dosbase,GL),a6
  948.         jsr    (_LVOOutput,a6)
  949.         move.l    d0,d1
  950.         jsr    (_LVOFPutC,a6)
  951.  
  952.         moveq    #" ",d2
  953.         btst    #TFB_RAWSINGLE,(gl_trk+wth_flags+1,GL)
  954.         beq    .fs
  955.         moveq    #"S",d2
  956. .fs        move.l    (gl_dosbase,GL),a6
  957.         jsr    (_LVOOutput,a6)
  958.         move.l    d0,d1
  959.         jsr    (_LVOFPutC,a6)
  960.  
  961.         moveq    #" ",d2
  962.         btst    #TFB_INDEX,(gl_trk+wth_flags+1,GL)
  963.         beq    .fi
  964.         moveq    #"I",d2
  965. .fi        move.l    (gl_dosbase,GL),a6
  966.         jsr    (_LVOOutput,a6)
  967.         move.l    d0,d1
  968.         jsr    (_LVOFPutC,a6)
  969.  
  970.         lea    (_length),a0
  971.         move.l    (gl_trk+wth_len,GL),d0
  972.         move.l    d0,d1
  973.         and.l    #7,d1
  974.         lsr.l    #3,d0
  975.         move.l    (gl_trk+wth_wlen,GL),d2
  976.         movem.l    d0-d2,-(a7)
  977.         move.l    a7,a1
  978.         bsr    _PrintArgs
  979.         add.w    #12,a7
  980.         
  981.     ;print sync
  982.         lea    (gl_trk+wth_sync,GL),a0
  983.         bsr    _printsync
  984.         
  985.         bsr    _PrintLn
  986.  
  987.     ;return
  988. .ret        moveq    #-1,d0                ;success
  989.         rts
  990.  
  991. ;##########################################################################
  992. ;##########################################################################
  993.  
  994. _cmd_length    move.l    (gl_rd_arg,GL),d0
  995.         bne    .1
  996.         lea    (_needlength),a0
  997.         bra    _Print
  998.  
  999. .wronglength    lea    (_wronglength),a0
  1000.         bra    _Print
  1001.  
  1002. .1        move.l    d0,a0
  1003.         bsr    _atoi
  1004.         tst.l    d0
  1005.         bmi    .wronglength
  1006.         btst    #0,d0
  1007.         bne    .wronglength
  1008.         
  1009.         move.l    d0,-(a7)
  1010.         move.l    #CMDF_OUT|CMDF_IN,d0    ;flags
  1011.         move.l    a7,a0            ;cbdata
  1012.         lea    .tracktable,a1        ;cbtt
  1013.         lea    .tracks,a2        ;cbt
  1014.         bsr    _cmdwork
  1015.         add.w    #4,a7
  1016.         rts
  1017.  
  1018. .tracktable    lea    (gl_tabin,GL),a0
  1019.         lea    (gl_tabread,GL),a1
  1020.         bsr    _copytt
  1021.         moveq    #-1,d0
  1022.         rts
  1023.  
  1024. .tracks        cmp.w    #TT_RAW,(gl_trk+wth_type,GL)
  1025.         bne    .badtype
  1026.         move.l    (gl_trk+wth_len,GL),d0
  1027.         lsr.l    #3,d0
  1028.         cmp.l    (a0),d0
  1029.         blo    .tobig
  1030.         move.l    (a0),(gl_trk+wth_wlen,GL)
  1031.         moveq    #-1,d0
  1032.         rts
  1033.  
  1034. .badtype    lea    (_lenbadtype),a0
  1035.         bra    .print
  1036. .tobig        lea    (_lentobig),a0
  1037. .print        lea    (gl_trk+wth_num,GL),a1
  1038.         bsr    _PrintArgs
  1039.         moveq    #0,d0
  1040.         rts
  1041.  
  1042. ;##########################################################################
  1043. ;##########################################################################
  1044.  
  1045. _cmd_merge    lea    .sorry,a0
  1046.         bra    _Print
  1047. .sorry        dc.b    "Sorry, this command is currently not implemented.",10,0,0
  1048.  
  1049. ;##########################################################################
  1050. ;##########################################################################
  1051.  
  1052. _cmd_pack    bra    _cmd_merge
  1053.  
  1054. ;##########################################################################
  1055. ;##########################################################################
  1056.  
  1057. _cmd_remove
  1058.         tst.l    (gl_rd_tracks,GL)
  1059.         bne    .1
  1060.         lea    (_notracks),a0
  1061.         bra    _Print
  1062.  
  1063. .1        move.l    #CMDF_OUT|CMDF_IN,d0    ;flags
  1064.         lea    .tracktable,a1        ;cbtt
  1065.         sub.l    a2,a2            ;cbt
  1066.         bra    _cmdwork
  1067.  
  1068. .tracktable
  1069.     ;remove all selected tracks from output
  1070.         move.l    #MAXTRACKS-1,d0
  1071. .loop        bftst    (gl_tabarg+wtt_tab,GL){d0:1}
  1072.         beq    .next
  1073.         bfclr    (gl_tabout+wtt_tab,GL){d0:1}
  1074. .next        dbf    d0,.loop
  1075.     ;skip removed tracks
  1076.         lea    (gl_tabout,GL),a0
  1077.         lea    (gl_tabread,GL),a1
  1078.         bsr    _copytt
  1079.     ;return
  1080.         moveq    #-1,d0
  1081.         rts
  1082.  
  1083. ;##########################################################################
  1084. ;##########################################################################
  1085.  
  1086. _cmd_save    bra    _cmd_merge
  1087.  
  1088. ;##########################################################################
  1089. ;##########################################################################
  1090.  
  1091. _cmd_sync    move.l    (gl_rd_arg,GL),d0
  1092.         bne    .1
  1093.         lea    (_needsync),a0
  1094.         bra    _Print
  1095.  
  1096. .1        move.l    d0,a0
  1097.         bsr    _parsesync
  1098.         tst.l    d0
  1099.         beq    _rts
  1100.  
  1101. .go        move.l    #CMDF_OUT|CMDF_IN,d0    ;flags
  1102.         lea    .tracktable,a1        ;cbtt
  1103.         lea    .tracks,a2        ;cbt
  1104.         bra    _cmdwork
  1105.  
  1106. .tracktable    lea    (gl_tabin,GL),a0
  1107.         lea    (gl_tabread,GL),a1
  1108.         bsr    _copytt
  1109.         moveq    #-1,d0
  1110.         rts
  1111.  
  1112. .tracks        cmp.w    #TT_RAW,(gl_trk+wth_type,GL)
  1113.         bne    .badtype
  1114.         lea    (gl_sync,GL),a0
  1115.         lea    (gl_trk+wth_sync,GL),a1
  1116.         move.w    #SYNCLEN-1,d0
  1117. .cp        move.w    (a0)+,(a1)+
  1118.         dbf    d0,.cp
  1119.         moveq    #-1,d0
  1120.         rts
  1121.  
  1122. .badtype    lea    (_lenbadtype),a0
  1123.         move.l    d5,-(a7)
  1124.         move.l    a7,a1
  1125.         bsr    _PrintArgs
  1126.         add.w    #4,a7
  1127.         moveq    #0,d0
  1128.         rts
  1129.  
  1130. ;----------------------------------------
  1131. ; translate arg into sync
  1132. ; sync will be stored in gl_sync
  1133. ; IN:    A0 = CPTR arg
  1134. ; OUT:    D0 = BOOL true if sync has been translated
  1135.  
  1136. _parsesync    movem.l    d2-d7/a2-a3,-(a7)
  1137.  
  1138.         move.l    a0,a2        ;A2 = string
  1139.         bsr    _StrLen
  1140.         move.l    d0,d2
  1141.         beq    .badsync
  1142.         subq.w    #1,d2        ;D2 = last char (mask)
  1143.         
  1144.         move.l    d2,d3        ;D3 = amparsent
  1145. .samp        cmp.b    #"&",(a2,d3.l)
  1146.         beq    .mfound
  1147.         dbf    d3,.samp
  1148. .mfound
  1149.         tst.w    d3        ;empty data?
  1150.         beq    .badsync
  1151.         cmp.w    d2,d3        ;empty mask?
  1152.         beq    .badsync
  1153.         
  1154.         move.w    d2,d4        ;D4 = last char data
  1155.         tst.w    d3
  1156.         bmi    .nomask
  1157.         move.w    d3,d4
  1158.         subq.w    #1,d4
  1159. .nomask
  1160.     ;decode sync data
  1161.         cmp.w    #31,d4        ;to many chars?
  1162.         bhi    .badsync
  1163.         lea    (gl_sync+SYNCLEN,GL),a3
  1164. .dloop        move.l    (gl_fastbuf,GL),a1
  1165.         move.b    #"$",(a1)+
  1166.         moveq    #7,d5
  1167.         cmp.w    d5,d4
  1168.         bhs    .2
  1169.         move.w    d4,d5
  1170. .2        move.w    d5,d0
  1171.         lea    (a2,d4.w),a0
  1172.         sub.w    d0,a0
  1173. .c1        move.b    (a0)+,(a1)+
  1174.         dbf    d0,.c1
  1175.         clr.b    (a1)
  1176.         move.l    a1,d7
  1177.         move.l    (gl_fastbuf,GL),a0
  1178.         bsr    _atoi
  1179.         cmp.l    a0,d7
  1180.         bne    .badsync
  1181.         move.l    d0,-(a3)
  1182.         sub.w    d5,d4
  1183.         subq.w    #1,d4
  1184.         bpl    .dloop
  1185.  
  1186.         tst.w    d3
  1187.         bpl    .mask
  1188.  
  1189.     ;calculate default mask
  1190.         moveq    #SYNCLEN-1,d0
  1191.         sf    d1
  1192.         lea    (gl_sync,GL),a0
  1193.         lea    (SYNCLEN,a0),a1
  1194. .dmloop        tst.b    (a0)+
  1195.         beq    .dm1
  1196.         st    d1
  1197. .dm1        move.b    d1,(a1)+
  1198.         dbf    d0,.dmloop
  1199.         bra    .success
  1200.  
  1201.     ;decode sync mask
  1202. .mask        lea    (1,a2,d3.w),a2
  1203.         move.w    d2,d4
  1204.         sub.w    d3,d4
  1205.         sub.w    #1,d4
  1206.         cmp.w    #31,d4        ;to many chars?
  1207.         bhi    .badsync
  1208.         lea    (gl_sync+SYNCLEN+SYNCLEN,GL),a3
  1209. .mloop        move.l    (gl_fastbuf,GL),a1
  1210.         move.b    #"$",(a1)+
  1211.         moveq    #7,d5
  1212.         cmp.w    d5,d4
  1213.         bhs    .m2
  1214.         move.w    d4,d5
  1215. .m2        move.w    d5,d0
  1216.         lea    (a2,d4.w),a0
  1217.         sub.w    d0,a0
  1218. .mc1        move.b    (a0)+,(a1)+
  1219.         dbf    d0,.mc1
  1220.         clr.b    (a1)
  1221.         move.l    a1,d7
  1222.         move.l    (gl_fastbuf,GL),a0
  1223.         bsr    _atoi
  1224.         cmp.l    a0,d7
  1225.         bne    .badsync
  1226.         move.l    d0,-(a3)
  1227.         sub.w    d5,d4
  1228.         subq.w    #1,d4
  1229.         bpl    .mloop
  1230.     ;apply mask on the sync
  1231.         lea    (gl_sync,GL),a0
  1232.         lea    (SYNCLEN,a0),a1
  1233.         moveq    #SYNCLEN/4-1,d1
  1234. .m        move.l    (a1)+,d0
  1235.         and.l    d0,(a0)+
  1236.         dbf    d1,.m
  1237.  
  1238. .success    moveq    #-1,d0
  1239. .end        movem.l    (a7)+,_MOVEMREGS
  1240.         rts
  1241.  
  1242. .badsync    lea    (_badsync),a0
  1243.         bsr    _Print
  1244.         moveq    #0,d0
  1245.         bra    .end
  1246.  
  1247. ;##########################################################################
  1248. ;##########################################################################
  1249.  
  1250. _cmd_write
  1251.     ;open the device
  1252.         move.l    #0,d0
  1253.         lea    (gl_io,GL),a0
  1254.         bsr    _OpenDevice
  1255.         tst.l    d0
  1256.         beq    .nodevice
  1257.  
  1258.     ;main
  1259.         move.l    #CMDF_IN,d0        ;flags
  1260.         lea    .tracktable,a1        ;cbtt
  1261.         lea    .tracks,a2        ;cbt
  1262.         bsr    _cmdwork
  1263.  
  1264.     ;close the device
  1265.         lea    (gl_io,GL),a0
  1266.         bsr    _CloseDevice
  1267. .nodevice
  1268.         rts
  1269.  
  1270.     ;copy tabarg to tabout so that the trackdata for all tracks
  1271.     ;to write will read
  1272. .tracktable    lea    (gl_tabarg,GL),a0
  1273.         lea    (gl_tabread,GL),a1
  1274.         bsr    _copytt
  1275.         moveq    #-1,d0
  1276.         rts
  1277.  
  1278. .tracks        cmp.w    #TT_RAW,(gl_trk+wth_type,GL)
  1279.         beq    _cmdw_raw
  1280.         cmp.w    #TT_STD,(gl_trk+wth_type,GL)
  1281.         beq    _cmdw_std
  1282.         cmp.w    #TT_GREM,(gl_trk+wth_type,GL)
  1283.         beq    _cmdw_grem
  1284.         lea    (_unknowntt),a0
  1285.         bsr    _Print
  1286.         moveq    #0,d0
  1287.         rts
  1288.  
  1289. _cmdw_std    move.w    (gl_trk+wth_flags,GL),d0
  1290.         move.l    (gl_trk+wth_len,GL),d7    ;D7 = length
  1291.         btst    #TFB_LEQ,d0
  1292.         bne    .leq
  1293.         btst    #TFB_SLINC,d0
  1294.         bne    .slinc
  1295.         
  1296.         cmp.l    #$1600*8,d7
  1297.         bne    _cmdw_corrupt
  1298.  
  1299. .go
  1300.     ;get length, print info
  1301.         bsr    _gettt
  1302.         move.l    d0,d7
  1303.         ble    _cmdw_corrupt
  1304.         move.l    a0,-(a7)
  1305.         move.w    (gl_trk+wth_num,GL),-(a7)
  1306.         clr.w    -(a7)
  1307.         lea    (_wtrack),a0
  1308.         move.l    a7,a1
  1309.         bsr    _PrintArgs
  1310.         addq.l    #8,a7
  1311.  
  1312.     ;write track
  1313.         move.l    (gl_io,GL),a1
  1314.         move.l    (gl_fastbuf,GL),(IO_DATA,a1)
  1315.         move.w    (gl_trk+wth_num,GL),d0
  1316.         mulu    d7,d0
  1317.         move.l    d0,(IO_OFFSET,a1)
  1318.         move.l    d7,(IO_LENGTH,a1)
  1319.         move.w    #ETD_WRITE,(IO_COMMAND,a1)
  1320.         clr.b    (IO_ERROR,a1)
  1321.         move.l    (gl_execbase,GL),a6
  1322.         jsr    (_LVODoIO,a6)
  1323.         move.l    (gl_io,GL),a1
  1324.         move.b    (IO_ERROR,a1),d0
  1325.         bne    .err
  1326.  
  1327.         moveq    #-1,d0
  1328.         rts
  1329.  
  1330. .err        lea    (_readdisk),a0
  1331.         bsr    _PrintErrorTD
  1332.         moveq    #0,d0
  1333.         rts
  1334.  
  1335. .leq        cmp.l    #4*8,d7
  1336.         bne    _cmdw_corrupt
  1337.         move.l    (gl_fastbuf,GL),a0
  1338.         move.w    #$1600/4-2,d0
  1339.         move.l    (a0)+,d1
  1340. .leq1        move.l    d1,(a0)+
  1341.         dbf    d0,.leq1
  1342.         bra    .go
  1343.  
  1344. .slinc        cmp.l    #11*4*8,d7
  1345.         bne    _cmdw_corrupt
  1346.         move.l    (gl_fastbuf,GL),a0
  1347.         lea    ($1600,a0),a1
  1348.         movem.l    (a0),d0-d7/a2-a3/a6
  1349.         movem.l    _MOVEMREGS,(a1)
  1350.         moveq    #11-1,d5
  1351. .slinc2        moveq    #$200/4-1,d6
  1352.         move.l    (a1)+,d7
  1353. .slinc1        move.l    d7,(a0)+
  1354.         addq.l    #1,d7
  1355.         dbf    d6,.slinc1
  1356.         dbf    d5,.slinc2
  1357.         bra    .go
  1358.  
  1359. _cmdw_grem
  1360.  
  1361.     ;get length, print info
  1362.         bsr    _gettt
  1363.         lsl.l    #3,d0
  1364.         cmp.l    (gl_trk+wth_len,GL),d0
  1365.         bne    _cmdw_corrupt
  1366.         move.l    a0,-(a7)
  1367.         move.w    (gl_trk+wth_num,GL),-(a7)
  1368.         clr.w    -(a7)
  1369.         lea    (_wtrack),a0
  1370.         move.l    a7,a1
  1371.         bsr    _PrintArgs
  1372.         addq.l    #8,a7
  1373.  
  1374.     ;copy to tmp
  1375.         move.l    (gl_fastbuf,GL),a0
  1376.         lea    (gl_tmpbuf,GL),a1
  1377.         move.w    #$1800/4-1,d0
  1378. .cpy        move.l    (a0)+,(a1)+
  1379.         dbf    d0,.cpy
  1380.  
  1381.     ;build mfm
  1382.         move.l    (gl_chipbuf,GL),a0
  1383.         move.l    #$55555555,d3
  1384.         move.w    #($3200-$3000-20)/4-1,d0
  1385. .gap        move.l    d3,(a0)+
  1386.         dbf    d0,.gap
  1387.         move.l    #$44894489,(a0)+    ;4
  1388.         move.l    #$44895555,(a0)+    ;4
  1389.         lea    (gl_tmpbuf,GL),a1
  1390.         moveq    #0,d5
  1391.         move.w    #$1800/2-1,d6
  1392. .data        move.w    (a1)+,d2        ;$3000
  1393.         add.w    d2,d5
  1394.         move.w    d2,d0
  1395.         swap    d2
  1396.         lsr.w    #1,d0
  1397.         move.w    d0,d2
  1398.         bsr    _encode_long
  1399.         dbf    d6,.data
  1400.         move.w    d5,d2
  1401.         swap    d2
  1402.         lsr.w    #1,d5
  1403.         move.w    d5,d2
  1404.         bsr    _encode_long        ;4
  1405.         move.w    (gl_trk+wth_num,GL),d2
  1406.         bchg    #0,d2
  1407.         move.w    d2,d0
  1408.         swap    d2
  1409.         lsr.w    #1,d0
  1410.         move.w    d0,d2
  1411.         bsr    _encode_long        ;4
  1412.         moveq    #0,d2
  1413.         bsr    _encode_long        ;4
  1414.  
  1415.     ;write track
  1416.         move.l    (gl_io,GL),a1
  1417.         move.l    (gl_chipbuf,GL),(IO_DATA,a1)
  1418.         move.w    (gl_trk+wth_num,GL),d0
  1419.         ext.l    d0
  1420.         move.l    d0,(IO_OFFSET,a1)
  1421.         move.l    #$3200,(IO_LENGTH,a1)
  1422.         move.w    #ETD_RAWWRITE,(IO_COMMAND,a1)
  1423.         clr.b    (IO_ERROR,a1)
  1424.         move.l    (gl_execbase,GL),a6
  1425.         jsr    (_LVODoIO,a6)
  1426.         move.l    (gl_io,GL),a1
  1427.         move.b    (IO_ERROR,a1),d0
  1428.         bne    .err
  1429.  
  1430.         moveq    #-1,d0
  1431.         rts
  1432.  
  1433. .err        lea    (_readdisk),a0
  1434.         bsr    _PrintErrorTD
  1435.         moveq    #0,d0
  1436.         rts
  1437.  
  1438. _cmdw_raw    bsr    _cmd_merge
  1439.         moveq    #0,d0
  1440.         rts
  1441.  
  1442. _cmdw_corrupt    lea    (_corrupt),a0
  1443.         bsr    _Print
  1444.         moveq    #0,d0
  1445.         rts
  1446.  
  1447. ; d2=long d3=55555555 a0=dest
  1448.  
  1449. _encode_long    and.l    d3,d2
  1450.         move.l    d2,d0
  1451.         eor.l    d3,d0
  1452.         move.l    d0,d1
  1453.         add.l    d0,d0
  1454.         lsr.l    #1,d1
  1455.         bset    #31,d1
  1456.         and.l    d0,d1
  1457.         or.l    d1,d2
  1458.         btst    #0,-1(a0)
  1459.         beq    .ok
  1460.         bclr    #31,d2
  1461. .ok        move.l    d2,(a0)+
  1462.         rts
  1463.  
  1464. ;##########################################################################
  1465. ;##########################################################################
  1466. ; read wwarp file,
  1467. ; call given function after tracktable has been read,
  1468. ; call given function on each track in the input file which is marked in gl_tabdo,
  1469. ; optionally copy all tracks marked in tabout to new wwarp file (which will
  1470. ; be created and renamed to the original on success)
  1471. ; IN:    D0 = ULONG flags
  1472. ;    A0 = APTR  data area for routines, provided in a0 on calling
  1473. ;    A1 = FPTR  routine for tracktable (a0 = data)
  1474. ;    A2 = FPTR  routine for tracks (d0 = trknum, a0 = data)
  1475. ; OUT:    D0 = BOOL  success
  1476.  
  1477.     NSTRUCTURE cmdwork_locals,0
  1478.         NULONG    wl_flags
  1479.         NBYTE    wl_tmpfile
  1480.         NSTRUCT    wl_pad,3
  1481.         NULONG    wl_cbdata
  1482.         NULONG    wl_cbtt
  1483.         NULONG    wl_cbt
  1484.         NULONG    wl_lt
  1485.         NLABEL    wl_SIZEOF
  1486.  
  1487.  BITDEF CMD,IN,0    ;read input (obsolete)
  1488.  BITDEF CMD,OUT,1    ;write output
  1489.  BITDEF CMD,NOTTC,2    ;dont check tabarg against tabin
  1490.  
  1491. _cmdwork    link    LOC,#wl_SIZEOF
  1492.         move.l    d0,(wl_flags,LOC)
  1493.         move.l    a0,(wl_cbdata,LOC)
  1494.         move.l    a1,(wl_cbtt,LOC)
  1495.         move.l    a2,(wl_cbt,LOC)
  1496.         sf    (wl_tmpfile,LOC)
  1497.         moveq    #0,d6                ;d6 = fh input
  1498.         moveq    #0,d7                ;d7 = fh output
  1499.  
  1500.         btst    #CMDB_IN,(wl_flags+3,LOC)
  1501.         beq    .noin1
  1502.     ;open input file
  1503.         lea    (gl_filename,GL),a0
  1504.         move.l    a0,d1
  1505.         move.l    #MODE_OLDFILE,d2
  1506.         move.l    (gl_dosbase,GL),a6
  1507.         jsr    (_LVOOpen,a6)
  1508.         move.l    d0,d6                ;d6 = fh input
  1509.         bne    .fhinok
  1510. .openerr    lea    (_openfile),a0
  1511.         bsr    _PrintErrorDOS
  1512.         bra    .error
  1513. .fhinok
  1514.     ;read input file header
  1515.         bsr    _readfilehead
  1516.         beq    .error
  1517.     ;read input track table
  1518.         bsr    _readtt
  1519.         beq    .error
  1520.     ;copy original stamp to output file header
  1521.         lea    (gl_headin+wfh_ctime,GL),a0
  1522.         lea    (gl_headout+wfh_ctime,GL),a1
  1523.         move.l    (a0)+,(a1)+
  1524.         move.l    (a0)+,(a1)+
  1525.         move.l    (a0)+,(a1)+
  1526.     ;if no track specification given copy gl_tabin to gl_tabarg
  1527.         tst.l    (gl_rd_tracks,GL)
  1528.         bne    .aftersetarg
  1529.         lea    (gl_tabin,GL),a0
  1530.         lea    (gl_tabarg,GL),a1
  1531.         bsr    _copytt
  1532. .aftersetarg
  1533.     ;compare tabarg against tabin and print a warning for all tracks
  1534.     ;delete also these tracks
  1535.     ;which are in tabarg but not in tabin
  1536.         btst    #CMDB_NOTTC,(wl_flags+3,LOC)
  1537.         bne    .nif2
  1538.         sf    d4
  1539.         move.l    #-1,d5
  1540. .loop        addq.l    #1,d5
  1541.         bftst    (gl_tabarg+wtt_tab,GL){d5:1}
  1542.         beq    .next
  1543.         bftst    (gl_tabin+wtt_tab,GL){d5:1}
  1544.         bne    .next
  1545.         bfclr    (gl_tabarg+wtt_tab,GL){d5:1}
  1546.         lea    (_notinfile1),a0
  1547.         tst.b    d4
  1548.         beq    .nif1
  1549.         lea    (_notinfile2),a0
  1550. .nif1        st    d4
  1551.         move.l    d5,-(a7)
  1552.         move.l    a7,a1
  1553.         bsr    _PrintArgs
  1554.         add.w    #4,a7
  1555. .next        cmp.l    #MAXTRACKS-1,d5
  1556.         bne    .loop
  1557.         tst.b    d4
  1558.         beq    .nif2
  1559.         lea    (_notinfile3),a0
  1560.         bsr    _Print
  1561. .nif2
  1562.     ;copy gl_tabin to gl_tabout
  1563.         lea    (gl_tabin,GL),a0
  1564.         lea    (gl_tabout,GL),a1
  1565.         bsr    _copytt
  1566. .noin1
  1567.  
  1568.         btst    #CMDB_OUT,(wl_flags+3,LOC)
  1569.         beq    .noout1
  1570.     ;check if creating new or modifying existing
  1571.         btst    #CMDB_IN,(wl_flags+3,LOC)
  1572.         sne    (wl_tmpfile,LOC)
  1573.         bne    .tmpout
  1574.     
  1575. .newout
  1576.     ;check file exists
  1577.         lea    (gl_filename,GL),a0
  1578.         move.l    a0,d1
  1579.         move.l    #ACCESS_READ,d2
  1580.         move.l    (gl_dosbase,GL),a6
  1581.         jsr    (_LVOLock,a6)
  1582.         move.l    d0,d1
  1583.         beq    .noold
  1584.         jsr    (_LVOUnLock,a6)
  1585.         lea    (_txt_exists),a0
  1586.         pea    (gl_filename,GL)
  1587.         move.l    a7,a1
  1588.         bsr    _PrintArgs
  1589.         addq.l    #4,a7
  1590.         bsr    _FlushOutput
  1591.         bsr    _GetKey
  1592.         move.b    d0,d2
  1593.         bsr    _PrintLn
  1594.         UPPER    d2
  1595.         cmp.b    #"Y",d2
  1596.         bne    .error
  1597.     ;open new output file
  1598. .noold        lea    (gl_filename,GL),a0
  1599.         move.l    a0,d1
  1600.         move.l    #MODE_NEWFILE,d2
  1601.         move.l    (gl_dosbase,GL),a6
  1602.         jsr    (_LVOOpen,a6)
  1603.         move.l    d0,d7                ;d7 = fh output
  1604.         bne    .fhoutok
  1605.         bra    .openerr
  1606.  
  1607.     ;open temp output file
  1608. .tmpout        lea    (gl_filename,GL),a0
  1609.         lea    (gl_filename2,GL),a1
  1610.         move.l    #FILENAMELEN,d0
  1611.         bsr    _CopyString
  1612.         move.l    #"!"<<24,-(a7)
  1613.         move.l    a7,a0
  1614.         lea    (gl_filename2,GL),a1
  1615.         move.l    #FILENAMELEN,d0
  1616.         bsr    _AppendString
  1617.         add.w    #4,a7
  1618.         lea    (gl_filename2,GL),a0
  1619.         move.l    a0,d1
  1620.         move.l    #MODE_NEWFILE,d2
  1621.         move.l    (gl_dosbase,GL),a6
  1622.         jsr    (_LVOOpen,a6)
  1623.         move.l    d0,d7                ;d7 = fh output
  1624.         beq    .openerr
  1625. .fhoutok
  1626.     ;write output file header
  1627.         bsr    _writefilehead
  1628.         beq    .error
  1629.  
  1630. .noout1
  1631.  
  1632.     ;copy gl_tabarg to gl_tabdo
  1633.         lea    (gl_tabarg,GL),a0
  1634.         lea    (gl_tabdo,GL),a1
  1635.         bsr    _copytt
  1636.         
  1637.     ;callback tracktable
  1638.         move.l    (wl_cbtt,LOC),d0
  1639.         beq    .s1
  1640.         move.l    (wl_cbdata,LOC),a0
  1641.         movem.l    d2-d7/a2-a6,-(a7)
  1642.         jsr    (d0.l)
  1643.         movem.l    (a7)+,_MOVEMREGS
  1644.         tst.l    d0
  1645.         beq    .error
  1646. .s1
  1647.     ;write output track table
  1648.         btst    #CMDB_OUT,(wl_flags+3,LOC)
  1649.         beq    .skipout2
  1650.         bsr    _writett
  1651.         beq    .error
  1652. .skipout2
  1653.  
  1654.     ;count last track to process
  1655.         lea    (gl_tabdo+wtt_tab,GL),a0
  1656.         btst    #CMDB_OUT,(wl_flags+3,LOC)
  1657.         beq    .clt1
  1658.         lea    (gl_tabout+wtt_tab,GL),a0
  1659. .clt1        move.l    #MAXTRACKS-1,d0
  1660. .clt2        bftst    (a0){d0:1}
  1661.         dbne    d0,.clt2
  1662.         beq    .finish
  1663.         move.l    d0,(wl_lt,LOC)
  1664.         
  1665.     ;***
  1666.     ;do for each input track upto wl_lt
  1667.     ;
  1668.         move.l    #-1,d5                ;d5 = actual track
  1669. .trkloop    addq.l    #1,d5
  1670.         cmp.l    (wl_lt,LOC),d5
  1671.         bhi    .finish
  1672.  
  1673.     ;check CTRL-C pressed
  1674.         bsr    _CheckBreak            ;check for CTRL-C
  1675.         tst.l    d0
  1676.         bne    .break
  1677.  
  1678.     ;input
  1679.         btst    #CMDB_IN,(wl_flags+3,LOC)
  1680.         beq    .noin2
  1681.         bftst    (gl_tabin+wtt_tab,GL){d5:1}
  1682.         beq    .noin2
  1683.     ;read input track header
  1684.         bsr    _readth
  1685.         beq    .error
  1686.     ;if track in gl_tabread read track data else skip it
  1687.         lea    (_skiptd),a0
  1688.         bftst    (gl_tabread+wtt_tab,GL){d5:1}
  1689.         beq    .indo
  1690.         lea    (_readtd),a0
  1691. .indo        jsr    (a0)
  1692.         beq    .error
  1693.  
  1694. .noin2
  1695.  
  1696.     ;callback track if in tabdo
  1697.         bftst    (gl_tabdo+wtt_tab,GL){d5:1}
  1698.         beq    .nodo
  1699.         move.l    (wl_cbt,LOC),d1
  1700.         beq    .nodo
  1701.         move.l    d5,d0
  1702.         move.l    (wl_cbdata,LOC),a0
  1703.         movem.l    d2-d7/a2-a6,-(a7)
  1704.         jsr    (d1.l)
  1705.         movem.l    (a7)+,_MOVEMREGS
  1706.         tst.l    d0
  1707.         beq    .error
  1708. .nodo
  1709.  
  1710.     ;write
  1711.         btst    #CMDB_OUT,(wl_flags+3,LOC)
  1712.         beq    .trkloop
  1713.         bftst    (gl_tabout+wtt_tab,GL){d5:1}
  1714.         beq    .trkloop
  1715.     ;write track
  1716.         bsr    _writet
  1717.         beq    .error
  1718.         bra    .trkloop
  1719.  
  1720.     ;success, all tracks
  1721. .finish        move.l    #0,(gl_rc,GL)
  1722. .break
  1723. .error
  1724.     ;close output file
  1725.         move.l    d7,d1
  1726.         beq    .noout
  1727.         move.l    (gl_dosbase,GL),a6
  1728.         jsr    (_LVOClose,a6)
  1729. .noout
  1730.     ;close input file
  1731.         move.l    d6,d1
  1732.         beq    .noin
  1733.         move.l    (gl_dosbase,GL),a6
  1734.         jsr    (_LVOClose,a6)
  1735. .noin
  1736.     ;success or fail
  1737.         tst.l    (gl_rc,GL)
  1738.         bne    .fail
  1739.  
  1740. .success
  1741.     ;if tmpfile rename
  1742.         tst.b    (wl_tmpfile,LOC)
  1743.         beq    .end
  1744.         lea    (gl_filename,GL),a0
  1745.         move.l    a0,d1
  1746.         move.l    (gl_dosbase,GL),a6
  1747.         jsr    (_LVODeleteFile,a6)
  1748.         lea    (gl_filename2,GL),a0
  1749.         move.l    a0,d1
  1750.         lea    (gl_filename,GL),a0
  1751.         move.l    a0,d2
  1752.         jsr    (_LVORename,a6)
  1753.         bra    .end
  1754.  
  1755. .fail
  1756.         tst.l    d7
  1757.         beq    .end
  1758.     ;delete output file
  1759.         lea    (gl_filename,GL),a0
  1760.         tst.b    (wl_tmpfile,LOC)
  1761.         beq    .del
  1762.         lea    (gl_filename2,GL),a0
  1763. .del        move.l    a0,d1
  1764.         move.l    (gl_dosbase,GL),a6
  1765.         jsr    (_LVODeleteFile,a6)
  1766.  
  1767. .end        unlk    LOC
  1768.         rts
  1769.  
  1770. ;##########################################################################
  1771. ;##########################################################################
  1772. ;----------------------------------------
  1773. ; open device
  1774. ; IN:    D0 = UBYTE flags for OpenDevice
  1775. ;    A0 = APTR  io structure (iorequest,msgport)
  1776. ; OUT:    D0 = BOOL  success
  1777.  
  1778. _OpenDevice    movem.l    d7/a2/a6,-(a7)
  1779.         move.l    d0,d7                ;D7 = flags
  1780.         move.l    a0,a2                ;A2 = struct
  1781.  
  1782.         move.l    (gl_execbase,GL),a6
  1783.         jsr    (_LVOCreateMsgPort,a6)
  1784.         move.l    d0,(4,a2)
  1785.         bne    .portok
  1786.         moveq    #0,d0
  1787.         lea    (_noport),a0
  1788.         sub.l    a1,a1
  1789.         bsr    _PrintError
  1790.         bra    .noport
  1791. .portok        
  1792.         move.l    d0,a0
  1793.         move.l    #IOTD_SIZE,d0
  1794.         jsr    (_LVOCreateIORequest,a6)
  1795.         move.l    d0,(a2)
  1796.         bne    .ioreqok
  1797.         moveq    #0,d0
  1798.         lea    (_noioreq),a0
  1799.         sub.l    a1,a1
  1800.         bsr    _PrintError
  1801.         bra    .noioreq
  1802. .ioreqok
  1803.         lea    (_trackdisk),a0
  1804.         move.l    (gl_rd_unit,GL),d0        ;unit
  1805.         move.l    (a2),a1                ;ioreq
  1806.         move.l    d7,d1                ;flags
  1807.         jsr    (_LVOOpenDevice,a6)
  1808.         tst.l    d0
  1809.         beq    .deviceok
  1810.         move.l    (a2),a1
  1811.         move.b    (IO_ERROR,a1),d0
  1812.         lea    (_opendevice),a0
  1813.         bsr    _PrintErrorTD
  1814.         bra    .nodevice
  1815. .deviceok
  1816.         move.l    (a2),a1
  1817.         move.w    #TD_CHANGENUM,(IO_COMMAND,a1)
  1818.         jsr    (_LVODoIO,a6)
  1819.         move.l    (a2),a1
  1820.         move.l    (IO_ACTUAL,a1),(IOTD_COUNT,a1)    ;the diskchanges
  1821.  
  1822.         moveq    #-1,d0                ;success
  1823.  
  1824. .end        movem.l    (a7)+,_MOVEMREGS
  1825.         rts
  1826.  
  1827. .nodevice    move.l    (a2),a0
  1828.         jsr    (_LVODeleteIORequest,a6)
  1829. .noioreq    move.l    (4,a2),a0
  1830.         jsr    (_LVODeleteMsgPort,a6)
  1831. .noport        moveq    #0,d0
  1832.         bra    .end
  1833.  
  1834. ;----------------------------------------
  1835. ; close device
  1836. ; IN:    A0 = APTR  io structure (iorequest,msgport)
  1837. ; OUT:    -
  1838.  
  1839. _CloseDevice    movem.l    a2/a6,-(a7)
  1840.         move.l    a0,a2                ;A2 = struct
  1841.  
  1842.         move.l    (a2),a1
  1843.         move.l    #0,(IO_LENGTH,a1)
  1844.         move.w    #ETD_MOTOR,(IO_COMMAND,a1)
  1845.         move.l    (gl_execbase,GL),a6
  1846.         jsr    (_LVODoIO,a6)
  1847.         
  1848.         move.l    (a2),a1
  1849.         jsr    (_LVOCloseDevice,a6)
  1850.  
  1851.         move.l    (a2),a0
  1852.         jsr    (_LVODeleteIORequest,a6)
  1853.  
  1854.         move.l    (4,a2),a0
  1855.         jsr    (_LVODeleteMsgPort,a6)
  1856.  
  1857.         movem.l    (a7)+,_MOVEMREGS
  1858.         rts
  1859.  
  1860. ;##########################################################################
  1861. ;----------------------------------------
  1862. ; write to file
  1863. ; IN:    D3 = ULONG length
  1864. ;    D7 = BPTR  filehandle
  1865. ;    A0 = APTR  data
  1866. ; OUT:    D0 = BOOL  success
  1867. ;    D2 = destroyed
  1868. ;    A6 = destroyed
  1869.  
  1870. _write        move.l    d7,d1
  1871.         move.l    a0,d2
  1872.         move.l    (gl_dosbase,GL),a6
  1873.         jsr    (_LVOWrite,a6)
  1874.         cmp.l    d0,d3
  1875.         beq    _success
  1876.         lea    (_txt_writing),a0
  1877.         bsr    _PrintErrorDOS
  1878. _writeerr    moveq    #0,d0
  1879.         rts
  1880.         
  1881. ;----------------------------------------
  1882. ; write fileheader
  1883. ; IN:    D7 = BPTR  filehandle
  1884. ; OUT:    D0 = BOOL  success
  1885. ;    D2 = destroyed
  1886. ;    D3 = destroyed
  1887. ;    A6 = destroyed
  1888.  
  1889. _writefilehead    move.l    #FILEID,(gl_headout+wfh_id,GL)
  1890.         move    #FILEVER,(gl_headout+wfh_ver,GL)
  1891.         lea    (gl_headout+wfh_creator,GL),a0
  1892.         move    #CREATORLEN-1,d0
  1893. .cc        clr.b    (a0)+
  1894.         dbf    d0,.cc
  1895.         lea    (_txt_creator),a0
  1896.         lea    (gl_headout+wfh_creator,GL),a1
  1897.         move.l    #CREATORLEN,d0
  1898.         bsr    _CopyString
  1899.         lea    (gl_headout+wfh_mtime,GL),a0
  1900.         move.l    a0,d1
  1901.         jsr    (_LVODateStamp,a6)
  1902.         move.l    #wfh_SIZEOF,d3
  1903.         lea    (gl_headout,GL),a0
  1904.         bra    _write
  1905.  
  1906. ;----------------------------------------
  1907. ; write track table
  1908. ; IN:    D7 = BPTR  filehandle
  1909. ; OUT:    D0 = BOOL  success
  1910. ;    D2 = destroyed
  1911. ;    D3 = destroyed
  1912. ;    A6 = destroyed
  1913.  
  1914. _writett    lea    (gl_tabout,GL),a0
  1915.         move.l    #TABLEID,(wtt_id,a0)
  1916.         move    #TABLEVER,(wtt_ver,a0)
  1917.         move.l    #wtt_tab+MAXTRACKS/8,d3
  1918.         bra    _write
  1919.  
  1920. ;----------------------------------------
  1921. ; write track
  1922. ; IN:    D7 = BPTR  filehandle
  1923. ; OUT:    D0 = BOOL  success
  1924. ;    D2 = destroyed
  1925. ;    D3 = destroyed
  1926. ;    A6 = destroyed
  1927.  
  1928. _writet        move.l    #TRACKID,(gl_trk+wth_id,GL)
  1929.         move    #TRACKVER,(gl_trk+wth_ver,GL)
  1930.         move.l    #wth_data,d3
  1931.         lea    (gl_trk,GL),a0
  1932.         bsr    _write
  1933.         beq    _writeerr
  1934.         move.l    (gl_trk+wth_len,GL),d3
  1935.         addq.l    #7,d3
  1936.         lsr.l    #3,d3
  1937.         move.l    (gl_fastbuf,GL),a0
  1938.         bra    _write
  1939.  
  1940. ;----------------------------------------
  1941. ; read from file
  1942. ; IN:    D3 = ULONG length
  1943. ;    D6 = BPTR  filehandle
  1944. ;    A0 = APTR  data
  1945. ; OUT:    D0 = BOOL  success
  1946. ;    D2 = destroyed
  1947. ;    A6 = destroyed
  1948.  
  1949. _read        move.l    d6,d1
  1950.         move.l    a0,d2
  1951.         move.l    (gl_dosbase,GL),a6
  1952.         jsr    (_LVORead,a6)
  1953.         cmp.l    d0,d3
  1954.         beq    _success
  1955.         lea    (_txt_reading),a0
  1956.         bsr    _PrintErrorDOS
  1957.         moveq    #0,d0
  1958.         rts
  1959.  
  1960. ;----------------------------------------
  1961. ; read fileheader
  1962. ; IN:    D6 = BPTR  filehandle
  1963. ; OUT:    D0 = BOOL  success
  1964. ;    D2 = destroyed
  1965. ;    D3 = destroyed
  1966. ;    A6 = destroyed
  1967.  
  1968. _readfilehead    move.l    #wfh_SIZEOF,d3
  1969.         lea    (gl_headin,GL),a0
  1970.         bsr    _read
  1971.         beq    _readerr
  1972.         
  1973.         cmp.l    #FILEID,(gl_headin+wfh_id,GL)
  1974.         bne    .badfile
  1975.         cmp.w    #FILEVER,(gl_headin+wfh_ver,GL)
  1976.         bne    _badstruct
  1977.         
  1978.         moveq    #-1,d0
  1979.         rts
  1980.  
  1981. .badfile    lea    (_txt_badfile),a0
  1982.         bsr    _Print
  1983.         bra    _readerr
  1984. _badstruct    lea    (_txt_badstruct),a0
  1985.         bsr    _Print
  1986. _readerr    moveq    #0,d0
  1987.         rts
  1988.  
  1989. ;----------------------------------------
  1990. ; read track table
  1991. ; IN:    D6 = BPTR  filehandle
  1992. ; OUT:    D0 = BOOL  success
  1993. ;    D2 = destroyed
  1994. ;    D3 = destroyed
  1995. ;    A6 = destroyed
  1996.  
  1997. _readtt        move.l    #wfh_SIZEOF,d3
  1998.         move.l    #wtt_tab,d3
  1999.         lea    (gl_tabin,GL),a0
  2000.         bsr    _read
  2001.         beq    _readerr
  2002.         
  2003.         cmp.l    #TABLEID,(gl_tabin+wtt_id,GL)
  2004.         bne    _badstruct
  2005.         cmp.w    #TABLEVER,(gl_tabin+wtt_ver,GL)
  2006.         bne    _badstruct
  2007.         
  2008.         moveq    #0,d3
  2009.         move    (gl_tabin+wtt_last,GL),d3
  2010.         sub    (gl_tabin+wtt_first,GL),d3
  2011.         bcs    _badstruct
  2012.         addq.l    #8,d3
  2013.         lsr.l    #3,d3
  2014.         lea    (gl_tabin+wtt_tab,GL),a0
  2015.         bsr    _read
  2016.         beq    _readerr
  2017.  
  2018.         lea    (gl_tabin,GL),a0
  2019.         bsr    _expandtt
  2020.         
  2021.         moveq    #-1,d0
  2022.         rts
  2023.  
  2024. ;----------------------------------------
  2025. ; read track header
  2026. ; IN:    D6 = BPTR  filehandle
  2027. ; OUT:    D0 = BOOL  success
  2028. ;    D2 = destroyed
  2029. ;    D3 = destroyed
  2030. ;    A6 = destroyed
  2031.  
  2032. _readth        move.l    #wth_data,d3
  2033.         lea    (gl_trk,GL),a0
  2034.         bsr    _read
  2035.         beq    _readerr
  2036.  
  2037.         cmp.l    #TRACKID,(gl_trk+wth_id,GL)
  2038.         bne    _badstruct
  2039.         cmp    #TRACKVER,(gl_trk+wth_ver,GL)
  2040.         bne    _badstruct
  2041.  
  2042. _success    moveq    #-1,d0
  2043.         rts
  2044.  
  2045. ;----------------------------------------
  2046. ; read track data
  2047. ; IN:    D6 = BPTR  filehandle
  2048. ; OUT:    D0 = BOOL  success
  2049. ;    D2 = destroyed
  2050. ;    D3 = destroyed
  2051. ;    A6 = destroyed
  2052.  
  2053. _readtd        move.l    (gl_trk+wth_len,GL),d3
  2054.         addq.l    #7,d3
  2055.         lsr.l    #3,d3
  2056.         move.l    (gl_fastbuf,GL),a0
  2057.         bra    _read
  2058.         
  2059. ;----------------------------------------
  2060. ; skip track data
  2061. ; IN:    D6 = BPTR  filehandle
  2062. ; OUT:    D0 = BOOL  success
  2063. ;    D2 = destroyed
  2064. ;    D3 = destroyed
  2065. ;    A6 = destroyed
  2066.  
  2067. _skiptd        move.l    d6,d1
  2068.         move.l    (gl_trk+wth_len,GL),d2
  2069.         addq.l    #7,d2
  2070.         lsr.l    #3,d2
  2071.         move.l    #OFFSET_CURRENT,d3
  2072.         move.l    (gl_dosbase,GL),a6
  2073.         jsr    (_LVOSeek,a6)
  2074.         jsr    (_LVOIoErr,a6)
  2075.         tst.l    d0
  2076.         beq    _success
  2077.         lea    (_seeking),a0
  2078.         bsr    _PrintErrorDOS
  2079.         bra    _readerr
  2080.         
  2081. ;----------------------------------------
  2082. ; convert given datestamp to strings
  2083. ; IN:    A0 = APTR  stamp
  2084. ; OUT:    -
  2085.  
  2086. _GetDate    move.l    a6,-(a7)
  2087.  
  2088.         move.b    #FORMAT_DOS,(gl_DateTime+dat_Format,GL)
  2089.         lea    (gl_time,GL),a1
  2090.         move.l    a1,(gl_DateTime+dat_StrTime,GL)
  2091.         lea    (gl_date,GL),a1
  2092.         move.l    a1,(gl_DateTime+dat_StrDate,GL)
  2093.         
  2094.         lea    (gl_DateTime+dat_Stamp,GL),a1
  2095.         move.l    (a0)+,(a1)+
  2096.         move.l    (a0)+,(a1)+
  2097.         move.l    (a0)+,(a1)+
  2098.  
  2099.         lea    (gl_DateTime,GL),a0
  2100.         move.l    a0,d1
  2101.         move.l    (gl_dosbase,GL),a6
  2102.         jsr    (_LVODateToStr,a6)
  2103.  
  2104.     ;fix that on some formats there is a trailing space
  2105.         lea    (gl_date,GL),a0
  2106. .l        tst.b    (a0)+
  2107.         bne    .l
  2108.         subq.l    #2,a0
  2109.         cmp.b    #" ",(a0)
  2110.         bne    .q
  2111.         clr.b    (a0)
  2112. .q
  2113.         move.l    (a7)+,a6
  2114.         rts
  2115.  
  2116. ;----------------------------------------
  2117. ; copy track table
  2118. ; IN:    A0 = APTR  wtt source
  2119. ;    A1 = APTR  wtt destination
  2120. ; OUT:    -
  2121.  
  2122. _copytt        move.w    #wtt_tab+MAXTRACKS/8-1,d0
  2123. .1        move.b    (a0)+,(a1)+
  2124.         dbf    d0,.1
  2125.         rts
  2126.  
  2127. ;----------------------------------------
  2128. ; expand given track table
  2129. ; IN:    A0 = APTR  wtt
  2130. ; OUT:    -
  2131.  
  2132. _expandtt    move.l    #MAXTRACKS-1,d0
  2133. .loop        cmp    (wtt_last,a0),d0
  2134.         bhi    .clear
  2135.         cmp    (wtt_first,a0),d0
  2136.         blo    .clear
  2137.         move.l    d0,d1
  2138.         add    (wtt_first,a0),d1
  2139.         bftst    (wtt_tab,a0){d1:1}
  2140.         bne    .set
  2141.  
  2142. .clear        bfclr    (wtt_tab,a0){d0:1}
  2143. .dbf        dbf    d0,.loop
  2144.         clr.w    (wtt_first,a0)
  2145.         move    #MAXTRACKS-1,(wtt_last,a0)
  2146.         rts
  2147.  
  2148. .set        bfset    (wtt_tab,a0){d0:1}
  2149.         bra    .dbf
  2150.  
  2151. ;----------------------------------------
  2152. ; check if there is a sync set in trkin
  2153. ; IN:    A0 = sync
  2154. ; OUT:    D0 = BOOL
  2155.  
  2156. _testsync    moveq    #-1,d0
  2157.         add.w    #SYNCLEN,a0
  2158.         tst.l    (a0)+
  2159.         bne    .true
  2160.         tst.l    (a0)+
  2161.         bne    .true
  2162.         tst.l    (a0)+
  2163.         bne    .true
  2164.         tst.l    (a0)+
  2165.         bne    .true
  2166.         moveq    #0,d0
  2167. .true        rts
  2168.  
  2169. ;##########################################################################
  2170. ;----------------------------------------
  2171. ; expand rawsinge track to double size
  2172. ; IN:    -
  2173. ; OUT:    d0 = ULONG track length in bits
  2174.  
  2175. _doubleraws    move.l    (gl_trk+wth_len,GL),d0
  2176.         btst    #TFB_RAWSINGLE,(gl_trk+wth_flags+1,GL)
  2177.         bne    .single
  2178.         rts
  2179.  
  2180. .single        move.l    d0,-(a7)
  2181.         add.l    d0,(a7)
  2182.         move.l    d2,a1
  2183.         move.l    d0,d1
  2184.         lsr.l    #5,d1
  2185.         move.l    (gl_fastbuf,GL),a0
  2186.         sub.l    #32,d0
  2187. .loop        move.l    (a0)+,d2
  2188.         bfins    d2,(a0){d0:32}
  2189.         dbf    d1,.loop
  2190.         move.l    a1,d2
  2191.         move.l    (a7)+,d0
  2192.         rts
  2193.  
  2194. ;----------------------------------------
  2195. ; get track type
  2196. ; IN:    -
  2197. ; OUT:    D0 = ULONG standard length of track
  2198. ;    A0 = CPTR  name/description
  2199.  
  2200. _gettt        move.w    (gl_trk+wth_type,GL),d0
  2201.         cmp.w    #TT_RAW,d0
  2202.         beq    .raw
  2203.         cmp.w    #TT_STD,d0
  2204.         beq    .std
  2205.         cmp.w    #TT_GREM,d0
  2206.         beq    .grem
  2207.         moveq    #0,d0
  2208.         lea    (.tunknown),a0
  2209.         rts
  2210.  
  2211. .raw        move.l    #DEFTRACKLEN,d0
  2212.         lea    (.traw),a0
  2213.         rts
  2214. .std        move.l    #$1600,d0
  2215.         lea    (.tstd),a0
  2216.         rts
  2217. .grem        move.l    #$1800,d0
  2218.         lea    (.tgrem),a0
  2219.         rts
  2220.  
  2221. .tunknown    dc.b    "unknown",0
  2222. .traw        dc.b    "raw",0
  2223. .tstd        dc.b    "dos",0
  2224. .tgrem        dc.b    "gremlin",0
  2225.     EVEN
  2226.  
  2227. ;----------------------------------------
  2228. ; shift mfm buffer
  2229. ; IN:    D0 = ULONG  bitoffset in buffer which make the new start
  2230. ;    D1 = ULONG  bitlength for new mfm-buffer
  2231. ;    A0 = APTR   mfm-buffer
  2232. ; OUT:    -
  2233.  
  2234. _shiftmfm    move.l    d2,a1
  2235.         lsr.l    #5,d1
  2236. .loop        bfextu    (a0){d0:32},d2
  2237.         move.l    d2,(a0)+
  2238.         dbf    d1,.loop
  2239.         move.l    a1,d2
  2240.         rts
  2241.  
  2242. ;----------------------------------------
  2243. ; search sync in mfm buffer
  2244. ; IN:    D0 = ULONG  bitoffset in buffer to start search
  2245. ;    D1 = ULONG  bitlength of mfm-buffer
  2246. ;    A0 = APTR   mfm-buffer
  2247. ;    A1 = STRUCT sync to search (16 byte sync + 16 byte mask)
  2248. ; OUT:    D0 = ULONG  bitoffset in buffer where sync has been found, -1 on error
  2249.  
  2250. _searchsync    movem.l    d2-d7/a2,-(a7)
  2251.  
  2252.     ;count bits to compare
  2253.         move.l    #SYNCLEN*8-1,d2
  2254.         moveq    #-1,d3
  2255. .cs        addq.l    #1,d3
  2256.         bftst    (SYNCLEN,a1){d3:1}
  2257.         dbne    d2,.cs
  2258.         addq.l    #1,d2            ;D2 = bits to compare (synclen)
  2259.         beq    .err
  2260.  
  2261.     ;search for sync
  2262.         subq.l    #1,d0            ;because loop starts with increment
  2263.         move.l    d2,a2            ;A2 = bits to compare (synclen)
  2264.  
  2265.     ;outer loop (128 bit - full size)
  2266. .lo        move.l    a2,d2            ;D2 = actual bits to compare (synclen)
  2267.         moveq    #32,d6
  2268.         cmp.l    d6,d2
  2269.         bhs    .s1
  2270.         move.l    d2,d6            ;D6 = actual synclen
  2271. .s1
  2272.         move.l    #SYNCLEN*8,d5
  2273.         sub.l    d2,d5            ;D5 = actual syncoffset
  2274.         bfextu    (SYNCLEN,a1){d5:d6},d3    ;D3 = mask
  2275.         bfextu    (a1){d5:d6},d4        ;D4 = sync
  2276.         and.l    d3,d4
  2277.  
  2278.     ;inner loop (32 bit)
  2279. .li        addq.l    #1,d0
  2280.         cmp.l    d1,d0
  2281.         bhs    .err
  2282.         bfextu    (a0){d0:d6},d7
  2283.         and.l    d3,d7
  2284.         cmp.l    d4,d7
  2285.         bne    .li
  2286.         
  2287.         sub.l    d6,d2
  2288.         beq    .end
  2289.  
  2290.         moveq    #32,d6
  2291.         cmp.l    d6,d2
  2292.         bhs    .s2
  2293.         move.l    d2,d6            ;D6 = actual synclen
  2294. .s2        move.l    #SYNCLEN*8,d5
  2295.         sub.l    d2,d5            ;D5 = actual syncoffset
  2296.         bfextu    (SYNCLEN,a1){d5:d6},d3    ;D3 = mask
  2297.         bfextu    (a1){d5:d6},d4        ;D4 = sync
  2298.         and.l    d3,d4
  2299.         bfextu    (4,a0){d0:d6},d7
  2300.         and.l    d3,d7
  2301.         cmp.l    d4,d7
  2302.         bne    .lo
  2303.         
  2304.         sub.l    d6,d2
  2305.         beq    .end
  2306.  
  2307.         moveq    #32,d6
  2308.         cmp.l    d6,d2
  2309.         bhs    .s3
  2310.         move.l    d2,d6            ;D6 = actual synclen
  2311. .s3        move.l    #SYNCLEN*8,d5
  2312.         sub.l    d2,d5            ;D5 = actual syncoffset
  2313.         bfextu    (SYNCLEN,a1){d5:d6},d3    ;D3 = mask
  2314.         bfextu    (a1){d5:d6},d4        ;D4 = sync
  2315.         and.l    d3,d4
  2316.         bfextu    (8,a0){d0:d6},d7
  2317.         and.l    d3,d7
  2318.         cmp.l    d4,d7
  2319.         bne    .lo
  2320.         
  2321.         sub.l    d6,d2
  2322.         beq    .end
  2323.  
  2324.         move.l    #SYNCLEN*8,d5
  2325.         sub.l    d2,d5            ;D5 = actual syncoffset
  2326.         bfextu    (SYNCLEN,a1){d5:d2},d3    ;D3 = mask
  2327.         bfextu    (a1){d5:d2},d4        ;D4 = sync
  2328.         and.l    d3,d4
  2329.         bfextu    (12,a0){d0:d2},d7
  2330.         and.l    d3,d7
  2331.         cmp.l    d4,d7
  2332.         bne    .lo
  2333.         
  2334. .end        movem.l    (a7)+,_MOVEMREGS
  2335.         rts
  2336.  
  2337. .err        moveq    #-1,d0
  2338.         bra    .end
  2339.  
  2340. ;##########################################################################
  2341. ;----------------------------------------
  2342. ; print sync
  2343. ; IN:    A0 = APTR   sync
  2344. ; OUT:    -
  2345.  
  2346. _printsync    movem.l    d2-d3/a2-a3,-(a7)
  2347.         move.l    a0,a3            ;a3 = sync
  2348.         lea    (SYNCLEN,a3),a0
  2349.         moveq    #SYNCLEN-1,d3
  2350. .cnt        tst.b    (a0)+
  2351.         dbne    d3,.cnt
  2352.         cmp.w    #1,d3
  2353.         bge    .ndef
  2354.         moveq    #1,d3
  2355. .ndef        lea    (SYNCLEN-1,a3),a2
  2356.         move.w    d3,d2
  2357.         bsr    .ps
  2358.         lea    (_amp),a0
  2359.         bsr    _Print
  2360.         lea    (2*SYNCLEN-1,a3),a2
  2361.         move.w    d3,d2
  2362.         bsr    .ps
  2363.         movem.l    (a7)+,_MOVEMREGS
  2364.         rts
  2365.  
  2366. .ps        sub.w    d2,a2
  2367. .p        lea    (_lx),a0
  2368.         moveq    #0,d0
  2369.         move.b    (a2)+,d0
  2370.         move.l    d0,-(a7)
  2371.         move.l    a7,a1
  2372.         bsr    _PrintArgs
  2373.         add.w    #4,a7
  2374.         dbf    d2,.p
  2375.         rts
  2376.         
  2377. ;----------------------------------------
  2378. ; print value as bit count in hex
  2379. ; IN:    D0 = ULONG value to print
  2380. ; OUT:    -
  2381.  
  2382. _printbitlen    move.l    d0,d1
  2383.         lsr.l    #3,d0
  2384.         and.l    #7,d1
  2385.         movem.l    d0-d1,-(a7)
  2386.         lea    (_bitlen),a0
  2387.         move.l    a7,a1
  2388.         bsr    _PrintArgs
  2389.         addq.l    #8,a7
  2390.         rts
  2391.  
  2392. _TxtBold    lea    (_txt_bold),a0
  2393.         bra    _Print
  2394.  
  2395. _TxtReset    lea    (_txt_reset),a0
  2396.         bra    _Print
  2397.  
  2398. _PrintBold    pea    (a0)
  2399.         bsr    _TxtBold
  2400.         move.l    (a7)+,a0
  2401.         bsr    _Print
  2402.         bra    _TxtReset
  2403.  
  2404. ;##########################################################################
  2405.  
  2406.     CNOP 0,4
  2407.         ;               even     odd
  2408.         ;       --sync--  ffTTSSGG  ffTTSSGG
  2409. _syncstd    dc.l    0,$44894489,$55000000,$55000000        ;finds one sector
  2410.         dc.l    0,$ffffffff,$ff000000,$ff000000
  2411. _syncstd2    dc.l    0,$44894489,$55000005,$55000001        ;finds first sector after gap
  2412.         dc.l    0,$ffffffff,$ff000055,$ff000055
  2413. _syncgrem    dc.l    0,0,$44894489,$44895555
  2414.         dc.l    0,0,$ffffffff,$ffffffff
  2415.  
  2416. _txt_help    dc.b    "Synopsis:",10
  2417.         dc.b    "    WWarp filename[.wwp] [command] [tracks] [args] [options...]",10
  2418.         dc.b    "valid commands are:",10
  2419.         dc.b    "    C - create wwarp file (default)",10
  2420.         dc.b    "    F - force tracks to std format",10
  2421.         dc.b    "    D - dump tracks",10
  2422.         dc.b    "        args = [sync[&mask]][,[syncno][,[len][,off]]]",10
  2423.         dc.b    "    I - print informations about wwarp file",10
  2424.         dc.b    "    L - set track length",10
  2425.         dc.b    "        args = length",10
  2426.         dc.b    "    M - merge two wwarp files together",10
  2427.         dc.b    "        args = wwarp-to-add",10
  2428.         dc.b    "    P - pack wwarp file",10
  2429.         dc.b    "    R - remove tracks from a wwarp file",10
  2430.         dc.b    "    S - save tracks",10
  2431.         dc.b    "    W - write wwarp file back to disk",10
  2432.         dc.b    "    Y - set sync",10
  2433.         dc.b    "        args = sync[&mask]",10
  2434.         dc.b    0
  2435. _txt_nl        dc.b    10,0
  2436. _txt_bold    dc.b    155,"1m",0
  2437. _txt_reset    dc.b    155,"22m",0
  2438. _txt_badtracks    dc.b    "Invalid [tracks] specification",10,0
  2439. _txt_badcmd    dc.b    "Invalid [command]",10,0
  2440. _extension    dc.b    ".wwp",0
  2441. _txt_create    dc.b    'creating new wwarp file "%s" from DF%ld: %ld tracks',10,0
  2442. _txt_exists    dc.b    'file "%s" already exists, overwrite ? (yN) ',0
  2443. _trackdisk    dc.b    "trackdisk.device",0
  2444. _diskprogress    dc.b    "reading track %ld",0
  2445. _openfile    dc.b    "open file",0
  2446. _txt_writing    dc.b    "writing file",0
  2447. _txt_reading    dc.b    "reading file",0
  2448. _seeking    dc.b    "seeking",0
  2449. _trklens    dc.b    " single"
  2450. _trklen        dc.b    " raw trklen=$%lx.%ld",10,0
  2451. _txt_badfile    dc.b    "file is not a WWarp file.",10,0
  2452. _txt_badstruct    dc.b    "structure of WWarp file is corrupt.",10,0
  2453. _txt_infohead1    dc.b    "created by: ",0
  2454. _txt_infohead2    dc.b    10,"created at: %s %s",10,0
  2455. _txt_infohead3    dc.b    "last modified at: %s %s",10,0
  2456. _txt_infohead4    dc.b    "total tracks in file: %ld",10
  2457.         dc.b    "trk type flags length  wlen  sync",10,0
  2458. _txt_infotrack    dc.b    "%3ld %s  ",0
  2459. _lx        dc.b    "%02lx",0
  2460. _amp        dc.b    "&",0
  2461. _length        dc.b    " $%4lx.%ld $%04lx ",0
  2462. _bitlen        dc.b    "$%lx.%ld",0
  2463. _needlength    dc.b    "length must be specified",10,0
  2464. _wronglength    dc.b    "invalid length",10,0
  2465. _notinfile1    dc.b    "warning, tracks %ld",0
  2466. _notinfile2    dc.b    ",%ld",0
  2467. _notinfile3    dc.b    " aren't contained in wwarp file!",10,0
  2468. _lenbadtype    dc.b    "error track %d, type must be raw!",10,0
  2469. _lentobig    dc.b    "error track %d, length cannot be larger than stored track size!",10,0
  2470. _forcebadtype    dc.b    "skipping track %d, no raw mfm-data!",10,0
  2471. _forcenosync    dc.b    "skipping track %d, sync not found",10,0
  2472. _forceshortmfm    dc.b    "skipping track %d, insufficient mfm-data",10,0
  2473. _forcebad    dc.b    "skipping track %d, could not decode",10,0
  2474. _needsync    dc.b    "sync must be specified",10,0
  2475. _badsync    dc.b    "invalid sync",10,0
  2476. _dump1        dc.b    "track=%ld type=%s flags=%lc len=$%4lx.%ld wlen=$%04lx sync=",0
  2477. _badarg        dc.b    "Invalid [arg]",10,0
  2478. _offerr        dc.b    "error, offset out of range",10,0
  2479. _syncfound1    dc.b    "sync ",0
  2480. _syncfound2    dc.b    " found %ld times, using offset ",0
  2481. _unknowntt    dc.b    "unknown track type",10,0
  2482. _corrupt    dc.b    "wwarp file is corrupt",0
  2483. _wtrack        dc.b    "writing track %ld fmt %s",10,0
  2484. _notracks    dc.b    "error, tracks must be specified",10,0
  2485.  
  2486. _decoded    dc.b    " format %s ($%lx bytes)",10,0
  2487. _nosync        dc.b    "no sync found",10,0
  2488. _noport        dc.b    "can't create MessagePort",0
  2489. _noioreq    dc.b    "can't create IO-Request",0
  2490. _readdisk    dc.b    "read disk",0
  2491. _opendevice    dc.b    "open device",0
  2492. _badkick    dc.b    "Sorry, WWarp requires Kickstart 2.0 or better.",10,0
  2493. _badcpu        dc.b    "Sorry, WWarp requires a 68020 or better.",10,0
  2494. _readargs    dc.b    "read arguments",0
  2495.  
  2496. ;subsystems
  2497. _dosname    DOSNAME
  2498.  
  2499. _template    dc.b    "Filename/A"        ;file to create
  2500.         dc.b    ",Command"        ;operation to perform
  2501.         dc.b    ",Tracks"        ;tracks affected
  2502.         dc.b    ",Argument"        ;depending on operation
  2503.         dc.b    ",BPT=BytesPerTrack/K"    ;
  2504.         dc.b    ",Unit/N/K"        ;drive unit to read from/write to
  2505.         dc.b    ",NoStd/S"        ;dont try to read std format
  2506.         dc.b    ",RetryCnt/N/K"        ;how many retries
  2507.         dc.b    0
  2508.  
  2509. ;##########################################################################
  2510.  
  2511.     SECTION c,BSS,CHIP
  2512.  
  2513. _chipbuf    dsb    MAXTRACKLEN
  2514.  
  2515. ;##########################################################################
  2516.  
  2517.     SECTION g,BSS
  2518.  
  2519. _Globals    dsb    gl_SIZEOF
  2520.  
  2521. ;##########################################################################
  2522.  
  2523.     END
  2524.  
  2525.