home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Amos / amproe2x.dms / in.adf / Boot_Disk_Maker.AMOS / Boot_Disk_Maker.amosSourceCode < prev   
Encoding:
AMOS Source Code  |  1993-06-16  |  21.4 KB  |  801 lines

  1. ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. '
  3. '  BOOT DISK MAKER  V2.0 
  4. '
  5. '  by Jean-Baptiste Bolcato  
  6. '
  7. '  Trackdisk procedures
  8. '  by Francois Lionet  
  9. '
  10. '  (c) 1993 Europress Software Ltd.
  11. '
  12. ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13.  
  14. ' --- Inits ---
  15.  
  16. Break Off 
  17.  
  18. Dim F$(32)
  19. Global DB$
  20. Global XSLI,YSLI,SXSLI,SYSLI,MSLI
  21. Global COMP$,SRCE$,DEST$
  22. Global F$(),NF,NF_DONE,NF_MAX
  23.  
  24. ' max buffered files/directory 
  25. NF_MAX=32
  26.  
  27. Resource Screen Open 1,64,16,0 : Screen Hide 1
  28. Resource Screen Open 0,640,144,0 : Screen Hide 0
  29. Screen Display 0,,88+28*(Ntsc=True),,
  30. Palette 0,0,0,0,0,0,0,0
  31. Paper 6 : Pen 7
  32.  
  33. _INIT_DIALOG
  34. Dialog Open 1,DB$
  35. Screen Show 0
  36.  
  37. ' --- Main Loop ---
  38.  
  39. Do 
  40.    
  41.    X=Free
  42.    
  43.    D=Dialog Run(1,1)
  44.    Fade 2 To 1 : Wait 30
  45.    
  46.    ' --- choose compiled program ---
  47.    
  48.    Do 
  49.       COMP$=Fsel$("**","",Resource$(10),Resource$(11))
  50.       Trap Open In 1,COMP$
  51.       If Errtrap=0
  52.          L=Lof(1)
  53.          Close 1
  54.          Trap Reserve As Work 10,L
  55.          If Errtrap=0
  56.             Trap Bload COMP$,Start(10)
  57.             If Errtrap=0
  58.                COMP$=Right$(COMP$,Len(COMP$)-Len(Dir$))
  59.                Exit 
  60.             End If 
  61.          End If 
  62.       End If 
  63.       _WARN[2,Resource$(21)]
  64.       If Param=1
  65.          Exit 2
  66.       End If 
  67.    Loop 
  68.    
  69.    ' --- disk copy ---
  70.    
  71.    _WARN[2,Resource$(17)]
  72.    _VERIFY=(Param=2)
  73.    _DISK_COPY["AMOSPro_System (v2.0 or over)",_VERIFY]
  74.    If Param=0
  75.       
  76.       ' --- remove unecessary files ---
  77.       
  78.       Print At(5,7);Space$(70);
  79.       Centre Resource$(34)
  80.       Set Dir 32,""
  81.       _REMOVE[DEST$+"APSystem/",1]
  82.       _REMOVE[DEST$+"Install_Data/",1]
  83.       _REMOVE[DEST$+"Extra_Configs/",1]
  84.       _REMOVE[DEST$,0]
  85.       
  86.       ' --- write back compiled program ---
  87.       
  88.       Print At(5,7);Space$(70);
  89.       Centre Resource$(35)
  90.       Trap Bsave DEST$+COMP$,Start(10) To Start(10)+Length(10)
  91.       If Errtrap
  92.          _WARN[3,Resource$(23)]
  93.       Else 
  94.          
  95.          ' --- write turbo-startup-sequence --- 
  96.          
  97.          Print At(5,7);Space$(70);
  98.          Centre Resource$(36)
  99.          Trap Open Out 1,DEST$+"s/startup-sequence"
  100.          If Errtrap=0
  101.             Print #1,"Run >Nil: "+COMP$;Chr$(10);
  102.             Print #1,"EndCli >Nil: ";Chr$(10);
  103.             Close 1
  104.             _WARN[1,Resource$(38)]
  105.             _WARN[2,Resource$(37)]
  106.             Exit If Param<>2
  107.          Else 
  108.             _WARN[3,Resource$(23)]
  109.          End If 
  110.       End If 
  111.    End If 
  112.    
  113. Loop 
  114.  
  115. Fade 1 : Wait 15
  116. Screen Close 0
  117. Screen Close 1
  118. Erase 10
  119. End 
  120.  
  121. ' --- Procedures --- 
  122.  
  123. Procedure _INIT_DIALOG
  124.    
  125.    Resource Bank 16
  126.    
  127.    Restore DBL
  128.    Repeat 
  129.       Read A$ : DB$=DB$+A$
  130.    Until A$=""
  131.    
  132.    ' Definition of quick-run dialog boxes 
  133.    DBL:
  134.    Data "SIze   1VA TW 48+ SW MIn,72;"
  135.    Data "BAse   SWidth SX- 2/,SHeight SY- 2/;"
  136.    Data "SAve   1;"
  137.    Data "RB     0,0,SX,SY,0;"
  138.    Data "RB     16,8,SX16-,24,0;"
  139.    Data "POut   20MECX,12,20ME,0,7;"
  140.    Data "PR     1VACX,32,1VA,3;"
  141.    ' One button OK  
  142.    Data "IF     0VA 1=;"
  143.    Data "["
  144.    Data "BJ     1,SX 96- 2/,SY24-,96,3ME; KY 13,0;"
  145.    Data "]"
  146.    ' Two buttons OK CANCEL  
  147.    Data "IF     0VA 2=;"
  148.    Data "["
  149.    Data "BJ     1,16,SY24-,96,4ME; KY 27,0;"
  150.    Data "BJ     2,SX112-,SY24-,96,3ME; KY 13,0;"
  151.    Data "]"
  152.    ' One Button CANCEL  
  153.    Data "IF     0VA 3=;"
  154.    Data "["
  155.    Data "BJ     1,SX 96- 2/,SY24-,96,4ME; KY 27,0;"
  156.    Data "]"
  157.    ' Two buttons RETRY CANCEL   
  158.    Data "IF     0VA 4=;"
  159.    Data "["
  160.    Data "BJ     1,16,SY24-,96,4ME; KY 27,0;"
  161.    Data "BJ     2,SX112-,SY24-,96,5ME; KY 13,0;"
  162.    Data "]"
  163.    Data "RUn    0,3; EXit;"
  164.    
  165.    
  166.    ' Definition of Welcome Screen 
  167.    Data "LA 1:"
  168.    Data "BAse   0,0; SIze SW,SH;"
  169.    Data "RB     0,0,SX,SY,0;"
  170.    Data "RB     16,8,SX16-,SY8-,0;"
  171.    Data "RB     160,16,SX160-,40,0;"
  172.    Data "PO     1MECX,24,1ME,7,0;"
  173.    Data "RB     32,48,SX32-,SY16-,0;"
  174.    Data "EXit;"
  175.    
  176.    
  177.    ' Installing... Slider screen
  178.    Data "LAbel  2:"
  179.    Data "BAse   32,48; SIze SW64-,SH64-;"
  180.    Data "BOx    0,0,1,SX,SY;"
  181.    Data "SV     4,16; "
  182.    Data "SV     0,16; SV1,24; SV2,SX32-; SV3,36;"
  183.    Data "BOx    0VA,1VA,67,0VA2VA+,1VA3VA+;"
  184.    Data "PR     XB40-,1VA3VA+4+,'100 %',7; PR 0VA,1VA3VA+4+,'0 %',7;"
  185.    Data "KY 27,0;"
  186.    Data "EXit;"
  187.    
  188.    
  189.    ' User instructions
  190.    '--------------------------------------- 
  191.    
  192.    Data "UI     PP,2;["
  193.    Data "PR     P1MECX,P2,P1ME,7;]"
  194.    
  195.    ' *** temporaire!!! - a changer en PP si 'text' en ME resource$  
  196.    
  197.    Data "UI     PQ,2;["
  198.    Data "PR     P1CX,P2,P1,7;]"
  199.    
  200.    '----------------------------------------
  201.    ' Text in a RBox, on the left
  202.    ' RC x,y,sx,sy,act,txt 
  203.    Data "UI     RC,6;["
  204.    Data "RB     P1,P2,P1P3+,P2P4+,P5;SW0;"
  205.    Data "PR     6P1+,P4TH-2/ P2+,P6,3;"
  206.    Data "]"
  207.    
  208.    ' -------------------------------- 
  209.    ' List Slider: draw a list + a slider, linked together 
  210.    ' LS zone,x1,y1,x2,y2,flags  
  211.    Data "UI     LS,6; ["
  212.    Data "VLine  P2,P3,76,P5;"
  213.    Data "BOx    XB,YA,67,P4,P5;"
  214.    Data "SZone  P1;"
  215.    Data "VSlide P1,P2 8+,P3 4+,8,P5 P3- 8-,P1VA,P5 P3- 8- 8/,1P1+VA AS,1;[ZChange ZNum 1+,ZPos;]"
  216.    Data "AList  P1 1+,P2 48+,P3 6+,P4 P2- 64- 8/,P5 P3- 8- 8/,1P1+VA,P1VA,P6,2,3;[]"
  217.    Data "XY     P2,P3,P4,P5;]"
  218.    
  219.    '----------------------------------------
  220.    ' One button, with text, click only  
  221.    ' BT zone,x,y,sx,text  
  222.    Data "UI     BT,5; ["
  223.    Data "SZone  P5;"
  224.    Data "BU     P1,P2,P3,P4,16,0,0,1;"
  225.    Data "       [LIne 0,0,88 3BP*+,SX;SW0;"
  226.    Data "        PR ZV CX BP+,16 TH- 2/ BP+,ZV,3;]"
  227.    Data "       [BR 0;]"
  228.    Data "]"
  229.    
  230.    '----------------------------------------
  231.    ' ??? ï¿½ effacer si pas label25 ? 
  232.    Data "UI BI,4;["
  233.    Data "PR P2 32+,P3 2+,P4ME,3; SV 0,P2 272+; PR 0VA,YA,P1VA#,3; PR XA72+,YA,76ME,3;"
  234.    Data "BU P1,P2,P3,24,12,6P1+VA,0,1;[UN 0,0,15BP+;][SV ZN 6+,BP;]"
  235.    Data "XY P2,P3,P2,P3 12+;]"
  236.    
  237.    '----------------------------------------
  238.    ' One button, with text, click only, QUIT!   
  239.    ' BJ zone,x,y,sx,text  
  240.    Data "UI     BJ,5; ["
  241.    Data "SZone  P5;"
  242.    Data "BU     P1,P2,P3,P4,16,0,0,1;"
  243.    Data "       [LIne 0,0,88 3BP*+,SX;SW0;"
  244.    Data "        PR ZV CX BP+,16 TH- 2/ BP+,ZV,3;]"
  245.    Data "       [BR 0;BQuit;]"
  246.    Data "]"
  247.    
  248.    '----------------------------------------
  249.    ' Box definition 
  250.    ' RB x1,y1,x2,y2,activated 
  251.    Data "UI     RB,5; ["
  252.    Data "BOx    P1,P2,1P5 78*+,P3,P4;]"
  253.    Data "]"
  254.    Data ""
  255.    
  256. End Proc
  257. Procedure _WARN[REQ,W$]
  258.    Trap D=Dialog Box(DB$,REQ,W$)
  259.    If Errtrap : XSLI=Errtrap : End : End If 
  260. End Proc[D]
  261. Procedure _INIT_SLIDER[M,A,B]
  262.    Set Slider A,A,A,0,B,B,B,0
  263.    XSLI=Vdialog(1,0)+10+32 : YSLI=Vdialog(1,1)+5+48
  264.    SXSLI=Vdialog(1,2)-20 : SYSLI=Vdialog(1,3)-11
  265.    MSLI=M : _SLIDER[0]
  266. End Proc
  267. Procedure _SLIDER[P]
  268.    P=Min(P,MSLI)
  269.    Hslider XSLI,YSLI To XSLI+SXSLI,YSLI+SYSLI,MSLI,0,P
  270. End Proc
  271. Procedure _DISK_COPY[S$,_VERIFY]
  272.    
  273.    Global _TDTRACKS,_TDB
  274.    
  275.    D=Dialog Run(1,2)
  276.    
  277.    SWP=False
  278.    SRCE=0 : SRCE$="df0:"
  279.    DEST=0
  280.    Repeat 
  281.       Inc DEST
  282.    Until Drive("df"+Right$(Str$(DEST),1)+":") or DEST=4
  283.    If DEST=4
  284.       DEST=0
  285.       SWP=True
  286.    End If 
  287.    DEST$="df"+Right$(Str$(DEST),1)+":"
  288.    
  289.    ' One drive copy 
  290.    
  291.    If SWP=True
  292.       
  293.       E=1
  294.       _TRACK_OPEN[0,SRCE]
  295.       _INIT_SLIDER[_TDTRACKS-1,2,4]
  296.       _TD=0
  297.       Repeat 
  298.          _DISK_BUSY[SRCE,False]
  299.          While Not Exist(SRCE$+"APsystem/")
  300.             _WARN[2,Resource$(12)+Resource$(16)+S$+Resource$(13)+SRCE$]
  301.             If Param=1 : E=2 : Exit 2 : End If 
  302.          Wend 
  303.          _DISK_BUSY[SRCE,True]
  304.          For T=_TD To _TDTRACKS-1
  305.             _SLIDER[T]
  306.             Print At(32,7);Resource$(30);T;"   "
  307.             _TRACK_READ[0,T]
  308.             If Param : _WARN[3,Resource$(22)] : Exit 2 : End If 
  309.             _TRACK_STORE[0,T]
  310.             Exit If Param or(Chip Free+Fast Free<100000)
  311.          Next T
  312.          _TD2=T
  313.          
  314.          _WARN[2,Resource$(12)+Resource$(14)+Resource$(13)+DEST$]
  315.          If Param=1 : E=2 : Exit : End If 
  316.          
  317.          For T=_TD To _TD2-1
  318.             _SLIDER[T]
  319.             Print At(32,7);Resource$(31);T;"   "
  320.             _TRACK_USTORE[0,T]
  321.             _TRACK_FORMAT[0,T]
  322.             If Param : _WARN[3,Resource$(23)] : Exit 2 : End If 
  323.             If _VERIFY
  324.                Print At(32,7);Resource$(32);T;"   "
  325.                _TRACK_VERIFY[0,T]
  326.                If Param
  327.                   _WARN[4,Resource$(25)]
  328.                   If Param=2
  329.                      Exit 2
  330.                   Else 
  331.                      T=T-1
  332.                   End If 
  333.                End If 
  334.             End If 
  335.          Next T
  336.          E=0
  337.          _TD=_TD2-1
  338.          _TRACK_FREE
  339.          
  340.       Until _TD2=_TDTRACKS
  341.       
  342.       _TRACK_FREE
  343.       _TRACK_CLOSE[0]
  344.       _DISK_BUSY[0,False]
  345.       
  346.    Else 
  347.       
  348.       ' Two drives copy  
  349.       
  350.       While Not Exist(SRCE$+"APsystem/")
  351.          _WARN[2,Resource$(12)+Resource$(16)+S$+Resource$(13)+SRCE$]
  352.          If Param=1 : E=2 : Goto FINISH_DISKCOPY : End If 
  353.       Wend 
  354.       
  355.       _WARN[2,Resource$(12)+Resource$(15)+Resource$(13)+DEST$]
  356.       If Param=1 : E=2 : Goto FINISH_DISKCOPY : End If 
  357.       
  358.       _TRACK_OPEN[0,SRCE]
  359.       _DISK_BUSY[SRCE,True]
  360.       _TRACK_OPEN[1,DEST]
  361.       _DISK_BUSY[DEST,True]
  362.       _INIT_SLIDER[_TDTRACKS-1,2,4]
  363.       
  364.       
  365.       E=1
  366.       For T=0 To _TDTRACKS-1
  367.          _SLIDER[T]
  368.          Print At(32,7);Resource$(30);T;"   "
  369.          _TRACK_READ[0,T]
  370.          If Param : _WARN[3,Resource$(22)] : Exit : End If 
  371.          Print At(32,7);Resource$(31);T;"   "
  372.          Copy Start(_TDB),Start(_TDB)+Length(_TDB) To Start(_TDB+1)
  373.          _TRACK_FORMAT[1,T]
  374.          If Param : _WARN[3,Resource$(23)] : Exit : End If 
  375.          If _VERIFY
  376.             Print At(32,7);Resource$(32);T;"   "
  377.             _TRACK_VERIFY[0,T]
  378.             If Param
  379.                _WARN[4,Resource$(25)]
  380.                If Param=2
  381.                   Exit 
  382.                Else 
  383.                   T=T-1
  384.                End If 
  385.             End If 
  386.          End If 
  387.       Next T
  388.       E=0
  389.       
  390.       _TRACK_FREE
  391.       _TRACK_CLOSE[0]
  392.       _DISK_BUSY[SRCE,False]
  393.       _TRACK_CLOSE[1]
  394.       _DISK_BUSY[DEST,False]
  395.       
  396.    End If 
  397.    
  398.    FINISH_DISKCOPY:
  399.    
  400.    If E
  401.       If E=2
  402.          A$=Resource$(25)
  403.       Else 
  404.          A$=Resource$(26)
  405.       End If 
  406.       _WARN[1,A$]
  407.    Else 
  408.       Print At(32,7); : Centre "   "+Resource$(33)+"   "
  409.    End If 
  410.    
  411. End Proc[E]
  412. Procedure _REMOVE[DR$,RECUR]
  413.    
  414.    If Exist(DR$)
  415.       A$=Dir First$(DR$+"**")
  416.       While A$<>""
  417.          B$=DR$+(Mid$(A$,2,31)-" ")
  418.          If Left$(A$,1)="*"
  419.             If RECUR
  420.                _REMOVE[B$+"/**",RECUR]
  421.                Trap Kill B$
  422.             End If 
  423.          Else 
  424.             Trap Kill B$
  425.          End If 
  426.          A$=Dir Next$
  427.       Wend 
  428.       If Right$(DR$,1)="/"
  429.          Trap Kill Left$(DR$,Len(DR$)-1)
  430.       End If 
  431.    End If 
  432.    
  433. End Proc
  434.  
  435. Procedure _DISK_BUSY[S,D]
  436.    '--------------------------------------------------------------- DISK_BUSY 
  437.    ' This procedure calls the disk validator, and tell it not to  
  438.    ' check the floppy any more. 
  439.    ' _DISK_BUSY[drive,flag] 
  440.    ' Where:  drive= the number of the drive, 0=DF0:, 1=DF1: 2=DF2 
  441.    '         flag=  True: turns the drive into busy 
  442.    '                False: turns the drive back to normal 
  443.    ' You should ALWAYS call DISC_BUSY before modifying anything on the floppy.
  444.    
  445.    D$="Df"+Chr$(48+S)+":"+Chr$(0)
  446.    
  447.    Dreg(1)=Varptr(D$) : DEV=Doscall(Lvo("DeviceProc"))
  448.    
  449.    If DEV
  450.       
  451.       Areg(1)=0 : TSK=Execall(Lvo("FindTask"))
  452.       PRT=TSK+Equ("pr_MsgPort")
  453.       
  454.       _RESFREEBANK[Equ("dp_SIZEOF")] : B=Param : S=Start(B)
  455.       PKT=S+Equ("sp_Pkt") : MSG=S+Equ("sp_Msg")
  456.       Struc(MSG,"LN_NAME")=PKT
  457.       Struc(PKT,"dp_Link")=MSG
  458.       Struc(PKT,"dp_Port")=PRT
  459.       Struc(PKT,"dp_Type")=Equ("ACTION_INHIBIT")
  460.       Struc(PKT,"dp_Arg1")=D
  461.       
  462.       Areg(0)=DEV : Areg(1)=MSG : A=Execall(Lvo("PutMsg"))
  463.       Areg(0)=PRT : A=Execall(Lvo("WaitPort"))
  464.       Areg(0)=PRT : A=Execall(Lvo("GetMsg"))
  465.       
  466.       Erase B
  467.       Wait 50
  468.       
  469.    End If 
  470.    
  471. End Proc
  472. Procedure _TRACK_OPEN[S,D]
  473.    '--------------------------------------------------------------- TRACK_OPEN
  474.    ' This procedure opens the trackdisc device, for one of the drives.
  475.    '_TRACK_OPEN[channel,drive]
  476.    ' Where: 
  477.    '        channel= the number of an internal channel, from 0 to 3 
  478.    '        drive=   the drive number (as above) associated to the channel
  479.    '
  480.    ' The procedure automatically reserves a memory bank for input/output, 
  481.    ' All reads will be done into this bank, all writes from this bank.
  482.    ' The number of the bank is: _TDB+channel, where _TDB is a variable
  483.    ' defined within the procedure (here, _TDB is 1000)
  484.    '
  485.    ' The size of the bank is the size of one floppy track, in chip ram. 
  486.    '
  487.    ' The procedure ask informations about the device before returning, and
  488.    ' store it into variables: 
  489.    '        _TDNUMSEC= number of sectors per track
  490.    '        _TDSECTOR= size of a sector 
  491.    '        _TDTRACKS= number of tracks 
  492.    '        _TDSIZE=   size of one track (and of the banks) 
  493.    '
  494.    ' Return: Param=0 device opened
  495.    '         Param<>0= number of the trackdisc.device error 
  496.    '
  497.    ' Note: you can open more than one channel for a single disc, but this 
  498.    ' is not wise! 
  499.    '
  500.    
  501.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  502.    
  503.    _TDB=1000 : E=1
  504.    
  505.    Trap Dev Open S,"trackdisk.device",Equ("IOTD_SIZE"),D,0
  506.    If Errtrap=0
  507.       
  508.       _TDNUMSEC=Equ("NUMSECS")
  509.       _TDSECTOR=Equ("TD_SECTOR")
  510.       
  511.       Trap Lib Open 3,"intuition.library",36
  512.       If Errtrap=0
  513.          Lib Close 3
  514.          _RESFREEBANK[Equ("dg_SIZEOF")] : B=Param : A=Start(B)
  515.          Struc(Dev Base(S),"IO_DATA")=A
  516.          Dev Do S,Equ("TD_GETGEOMETRY")
  517.          _TDSECTOR=Struc(A,"dg_SectorSize")
  518.          _TDNUMSEC=Struc(A,"dg_TrackSectors")
  519.          Erase B
  520.       End If 
  521.       
  522.       _TDSIZE=_TDNUMSEC*_TDSECTOR
  523.       
  524.       Dev Do S,Equ("TD_GETNUMTRACKS")
  525.       _TDTRACKS=Struc(Dev Base(S),"IO_ACTUAL")
  526.       
  527.       Reserve As Chip Work _TDB+S,_TDSIZE
  528.       Reserve As Work _TDB+4,_TDSIZE*2
  529.       E=0
  530.    End If 
  531.    
  532. End Proc[E]
  533. Procedure _TRACK_CLOSE[S]
  534.    '--------------------------------------------------------------- TRACK_CLOSE 
  535.    ' This procedure closes a channel previously opened. 
  536.    ' _TRACK_CLOSE[channel]
  537.    '
  538.    
  539.    Dev Close S
  540.    Erase _TDB+S
  541.    Erase _TDB+4
  542.    
  543. End Proc
  544. Procedure _TRACK_PROTECTED[S]
  545.    
  546.    '----------------------------------------------------------- TRACK_PROTECTED 
  547.    ' This procedure asks the current state of a channel, and reports
  548.    ' whether or not the disc in the drive handled by the channel is 
  549.    ' write-protected or not.
  550.    '
  551.    ' _TRACK_PROTECTED[channel]
  552.    '
  553.    ' On return: 
  554.    '        Param= 0 not protected
  555.    '        Param<>0 protected      
  556.    '
  557.    
  558.    Trap Dev Do S,Equ("TD_PROTSTATUS")
  559.    P=-1
  560.    If Errtrap=0
  561.       P=Sgn(Struc(Dev Base(S),"IO_ACTUAL"))
  562.    End If 
  563.    
  564. End Proc[P]
  565. Procedure _TRACK_MOTOR[S,M]
  566.    '----------------------------------------------------------- TRACK_MOTOR 
  567.    ' This procedure turns on or off the drive's motor of the channel. 
  568.    ' NOTE: it is not necessary to turn the motor ON, but the programmer 
  569.    ' must turn it OFF!
  570.    '
  571.    ' _TRACK_MOTOR[channel,flag] 
  572.    ' Where
  573.    '        Flag=False OFF
  574.    '        Flag=True  ON 
  575.    '  
  576.    
  577.    Struc(Dev Base(S),"IO_LENGTH")=M
  578.    Trap Dev Do S,Equ("TD_MOTOR")
  579.    P=-1
  580.    If Errtrap=0
  581.       P=Sgn(Struc(Dev Base(S),"IO_ACTUAL"))
  582.    End If 
  583.    
  584. End Proc[P]
  585. Procedure _TRACK_READ[S,T]
  586.    '------------------------------------------------------------ TRACK_READ 
  587.    ' This procedure reads a track into the channel's memory bank. 
  588.    '
  589.    ' _TRACK_READ[channel,track] 
  590.    ' Where
  591.    '        Track= the number of the track to read
  592.    '
  593.    ' Returns
  594.    '        Param= 0 no errors  
  595.    '        Param<>0 the device's error 
  596.    '
  597.    ' The bank used is the one associated with the channel: _TDB+channel 
  598.    '
  599.    
  600.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  601.    
  602.    T=_TDSIZE*T
  603.    Struc(Dev Base(S),"IO_DATA")=Start(_TDB+S)
  604.    Struc(Dev Base(S),"IO_OFFSET")=T
  605.    Struc(Dev Base(S),"IO_LENGTH")=_TDSIZE
  606.    Trap Dev Do S,Equ("CMD_READ")
  607.    
  608. End Proc[Errtrap]
  609. Procedure _TRACK_WRITE[S,T]
  610.    '------------------------------------------------------------- TRACK_WRITE 
  611.    ' This procedure writes a track on a previously formatted disc.
  612.    '
  613.    ' _TRACK_WRITE[channel,track]  
  614.    ' Where
  615.    '        Track= the number of the track to write 
  616.    '
  617.    ' Returns
  618.    '        Param= 0 no errors  
  619.    '        Param<>0 the device's error 
  620.    '
  621.    ' Valid track data must be poked in the bank associated with the 
  622.    ' channel: _TDB+channel before calling this function.  
  623.    ' To write on a non-formated track, you should use _TRACK_FORMAT 
  624.    '  
  625.    
  626.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  627.    
  628.    T=_TDSIZE*T
  629.    Struc(Dev Base(S),"IO_DATA")=Start(_TDB+S)
  630.    Struc(Dev Base(S),"IO_OFFSET")=T
  631.    Struc(Dev Base(S),"IO_LENGTH")=_TDSIZE
  632.    Trap Dev Do S,Equ("CMD_WRITE")
  633.    
  634. End Proc[Errtrap]
  635. Procedure _TRACK_FORMAT[S,T]
  636.    '------------------------------------------------------------- TRACK_FORMAT
  637.    ' This procedure writes a track on a non-formated disc.
  638.    '
  639.    ' _TRACK_FORMAT[channel,track]   
  640.    ' Where
  641.    '        Track= the number of the track to write 
  642.    '
  643.    ' Returns
  644.    '        Param= 0 no errors  
  645.    '        Param<>0 the device's error 
  646.    '
  647.    ' Valid track data must be poked in the bank associated with the 
  648.    ' channel: _TDB+channel before calling this function.  
  649.    '  
  650.    
  651.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  652.    
  653.    T=_TDSIZE*T
  654.    Struc(Dev Base(S),"IO_DATA")=Start(_TDB+S)
  655.    Struc(Dev Base(S),"IO_OFFSET")=T
  656.    Struc(Dev Base(S),"IO_LENGTH")=_TDSIZE
  657.    Trap Dev Do S,Equ("TD_FORMAT")
  658.    
  659. End Proc[Errtrap]
  660. Procedure _TRACK_CHECKSUM[S]
  661.    '------------------------------------------------------------- TRACK_CHECKSUM
  662.    ' This procedure performs a checksum on every sectors of track stored
  663.    ' in the channel's bank..
  664.    '
  665.    ' _TRACK_CHECKSUM[channel]   
  666.    '
  667.    ' This procedure performs a checksum calculation within the  
  668.    ' channel's memory bank. You should call this procedure after modifying
  669.    ' anything in any sector of the track. 
  670.    ' This procedure checks every sector of the track. 
  671.    '
  672.    ' Warning: you'll get a disc corrupted error if you write a track with 
  673.    ' bad checksums! 
  674.    '  
  675.    
  676.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  677.    
  678.    For SEC=0 To _TDNUMSEC-1
  679.       A=Start(_TDB+S)+_TDSECTOR*SEC
  680.       Loke A+20,0
  681.       C=0
  682.       For B=A To A+_TDSECTOR-4 Step 4
  683.          Add C,-Leek(B)
  684.       Next 
  685.       Loke A+20,C
  686.    Next 
  687.    
  688. End Proc
  689. Procedure _TRACK_VERIFY[S,T]
  690.    '------------------------------------------------------------- TRACK_VERIFY
  691.    ' This procedure performs a verify on the data stored into the channels
  692.    ' bank. You should usually call it after a FORMAT or a WRITE 
  693.    ' It copy the datas onto another bank, call _TRACK_READ to re-load the 
  694.    ' data, and compare them byte by byte. 
  695.    '
  696.    ' _TRACK_VERIFY[channel,track] 
  697.    ' Where
  698.    '        track= number of the track to check 
  699.    '
  700.    ' Returns: 
  701.    '        param=0  no errors  
  702.    '        param<>0 error found  
  703.    '        
  704.    
  705.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  706.    E=1
  707.    A=Start(_TDB+S) : B=Start(_TDB+4) : Copy A,A+_TDSIZE To B
  708.    _TRACK_READ[S,T]
  709.    If Param=0
  710.       Repeat 
  711.          For C=0 To _TDSIZE-4 Step 4
  712.             Exit If Leek(A+C)<>Leek(B+C),2
  713.          Next 
  714.          E=0
  715.       Until True
  716.    End If 
  717.    
  718. End Proc[E]
  719. Procedure _TRACK_STORE[S,T]
  720.    '-------------------------------------------------------------- TRACK_STORE
  721.    ' This procedure compress and copy the data hold in the channels bank
  722.    ' into another memory bank automatically. Use this procedure when you
  723.    ' want to perform a disc-copy. 
  724.    '
  725.    ' _TRACK_STORE[channel,track]
  726.    '
  727.    ' Returns: 
  728.    '        Param=0  no errors  
  729.    '        Param<>0 out of memory  
  730.    '
  731.    ' The number of the bank reserved is _TDB+5+track
  732.    '  
  733.    
  734.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  735.    
  736.    _CRUNCHIT[0,_TDSIZE,Start(_TDB+S),Start(_TDB+4)] : L=Param
  737.    Trap Reserve As Work _TDB+5+T,L
  738.    If Errtrap=0
  739.       Copy Start(_TDB+4),Start(_TDB+4)+L To Start(_TDB+5+T)
  740.    End If 
  741. End Proc[Errtrap]
  742. Procedure _TRACK_USTORE[S,T]
  743.    '-------------------------------------------------------------- TRACK_USTORE 
  744.    ' This procedure unpack the data from a compressed bank create by STORE  
  745.    ' into the channels internal bank. 
  746.    '
  747.    ' _TRACK_USTORE[channel,track] 
  748.    '
  749.    ' If the bank is not defined, the channels bank is filled with 0 
  750.    '  
  751.    ' The number of the bank unpacked is _TDB+5+track
  752.    ' If you call this procedure on other bank than the one created by 
  753.    ' TRACK_STORE, it will crash the system! 
  754.    '  
  755.    
  756.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  757.    
  758.    If Length(_TDB+4+T)
  759.       _CRUNCHIT[1,0,Start(_TDB+5+T),Start(_TDB+S)]
  760.    Else 
  761.       Fill Start(_TDB+S) To Start(_TDB+S)+Length(_TDB+S),0
  762.    End If 
  763. End Proc
  764. Procedure _TRACK_FREE
  765.    '-------------------------------------------------------------- TRACK_FREE 
  766.    ' This procedure free all banks reserved by TRACK_STORE
  767.    '
  768.    ' _TRACK_FREE
  769.    '
  770.    
  771.    Global _TDB,_TDNUMSEC,_TDSECTOR,_TDTRACKS,_TDSIZE
  772.    
  773.    For B=_TDB+5 To _TDB+5+_TDTRACKS
  774.       Erase B
  775.    Next 
  776.    
  777. End Proc
  778. Procedure _RESFREEBANK[S]
  779.    '-------------------------------------------------------------- TRACK_STORE
  780.    ' This small procedure is used by the others, it looks for a free  
  781.    ' free memory bank, and reserves it, as a "work" bank..  
  782.    '
  783.    ' _RESFREEBANK[size] 
  784.    '
  785.    ' Returns: 
  786.    '        Param=0  out of mem 
  787.    '        Param<>0 the number of the bank 
  788.    '
  789.    
  790.    E=0
  791.    For B=65535 To 0 Step -1 : Exit If Length(B)=0 : Next 
  792.    Trap Reserve As Work B,S
  793.    If Errtrap=0
  794.       Fill Start(B) To Start(B)+Length(B),0
  795.       E=B
  796.    End If 
  797.    
  798. End Proc[E]
  799. Procedure _CRUNCHIT[A,B,C,D]
  800.    ' COMPILED PROCEDURE -- can't convert this to AMOS code
  801. End Proc