home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / sourcecode / general / format.amos / format.amosSourceCode
Encoding:
AMOS Source Code  |  1992-05-23  |  5.2 KB  |  177 lines

  1. Screen Open 0,640,256,2,Hires : Colour 1,$FFF : Curs Off 
  2. '--------------------------------------------------------- 
  3. '  The various structures are placed in AMOS banks.
  4. '  They could just as easily be placed in memory allocated 
  5. '  (and then freed) using the AllocMem() Execall.  
  6. '  The IO buffer must be in chip under version 1.3 of the
  7. '  operating system
  8. '--------------------------------------------------------- 
  9. MSGBANK=7 : IOBANK=8 : BUFBANK=9 : BUFLEN=512*11
  10. Reserve As Chip Work BUFBANK,BUFLEN
  11. '--------------------------------------------------------------- 
  12. ' Change these parameters if you want to access your hard drive
  13. '--------------------------------------------------------------- 
  14. UNIT=0 : DEVICE$="trackdisk.device"
  15. '
  16. '--------------------------------------------------------------
  17. '  Allocate the port then initialise the IO request structure. 
  18. '  When this is done open the device for IO. 
  19. '--------------------------------------------------------------
  20. CREATEPORT[MSGBANK]
  21. CREATEIO[IOBANK,MSGBANK]
  22. OPENDEVICE[DEVICE$,UNIT,IOBANK,0]
  23. '
  24. If Param<>0
  25.    Print "OpenDevice() failed"
  26.    DELETEIO[IOBANK]
  27.    DELETEPORT[MSGBANK]
  28.    End 
  29. End If 
  30. '
  31. '------------------------------------------------------- 
  32. '  Turn the motor on, read the sector then turn it off.  
  33. '------------------------------------------------------- 
  34. TD_MOTOR[IOBANK,1]
  35. If Param<>0 Then Print "Warning - DoIO returned error";Param
  36. For X=0 To 159
  37.    CMD_READ[IOBANK,X,BUFBANK]
  38.    Locate 0,10 : Cline : Locate 0,10 : Print X
  39.    If Param<>0 Then Print "Warning - DoIO returned error";Param
  40. Next X
  41. '  
  42. TD_MOTOR[IOBANK,0]
  43. If Param<>0 Then Print "Warning - DoIO returned error";Param
  44. '
  45. '------------------------------------------------------
  46. '  Close the device, free the port and free the banks. 
  47. '------------------------------------------------------
  48. KLOSEDEVICE[IOBANK]
  49. DELETEIO[IOBANK]
  50. DELETEPORT[MSGBANK]
  51. '
  52. '--------------------------------- 
  53. '  Format and print the bootblock
  54. '--------------------------------- 
  55. For AD=Start(BUFBANK) To Start(BUFBANK)+492 Step 20
  56.    For AD2=AD To AD+16 Step 4
  57.       Print Right$(Hex$(Leek(AD2),8),8);" ";
  58.    Next 
  59.    Print "    ";
  60.    For AD2=AD To AD+19
  61.       If Peek(AD2)>32
  62.          Print Chr$(Peek(AD2));
  63.       Else 
  64.          Print ".";
  65.       End If 
  66.    Next 
  67.    Print 
  68. Next 
  69. '
  70. Procedure CREATEPORT[BANK]
  71.    '
  72.    '-------- Routine to allocate & initialise a message port
  73.    '-------- Note: This port is not placed on the system port list
  74.    '
  75.    Dreg(0)=-1 : Rem This means use any of the available signal bits
  76.    SIGNAL_NUMBER=Execall(-330)
  77.    If SIGNAL_NUMBER=-1
  78.       Print "Signal allocation failed in CREATEPORT"
  79.       Direct 
  80.    End If 
  81.    '  
  82.    Reserve As Work BANK,34
  83.    MSGPORT=Start(BANK)
  84.    '
  85.    '--------------------------------------------------- 
  86.    '   At offset 276 of ExecBase is the address of the  
  87.    '   currently executing task. That must be us if we  
  88.    '   are looking at it! 
  89.    '--------------------------------------------------- 
  90.    EXECBASE=Leek(4)
  91.    MY_TASK=Leek(EXECBASE+276)
  92.    '
  93.    '--------------------------------------------
  94.    '  Fill in the nessacary information for the 
  95.    '  MsgPort structure.  
  96.    '--------------------------------------------
  97.    Poke MSGPORT+9,0 : Rem port priority  
  98.    Poke MSGPORT+8,16 : Rem node type is message port
  99.    Poke MSGPORT+14,0 : Rem flags
  100.    Poke MSGPORT+15,SIGNAL_NUMBER : Rem signal number acquired earlier 
  101.    Loke MSGPORT+16,MY_TASK : Rem address of our task structure
  102.    '
  103. End Proc
  104. '
  105. Procedure DELETEPORT[BANK]
  106.    '
  107.    '---------Routine to free an allocated port
  108.    '
  109.    MSGPORT=Start(BANK)
  110.    '
  111.    Dreg(0)=Peek(MSGPORT+15)
  112.    X=Execall(-336) : Rem free the signal
  113.    '
  114.    Erase BANK : Rem free the memory
  115. End Proc
  116. '
  117. Procedure CREATEIO[IOBANK,MSGBANK]
  118.    '
  119.    '---------Routine to initialise the IO request structure 
  120.    '
  121.    Reserve As Work IOBANK,48
  122.    IOSTDREQ=Start(IOBANK)
  123.    Poke IOSTDREQ+8,32 : Rem insert message type
  124.    Doke IOSTDREQ+18,48 : Rem length of strucure 
  125.    Loke IOSTDREQ+14,Start(MSGBANK) : Rem address of message port structure
  126. End Proc
  127. '
  128. Procedure DELETEIO[IOBANK]
  129.    '
  130.    '--------This routine frees an IO request structure
  131.    '
  132.    Erase IOBANK
  133. End Proc
  134. '
  135. Procedure TD_MOTOR[IOBANK,FLAG]
  136.    '
  137.    '--------Switch motor on or off
  138.    '
  139.    IOSTDREQ=Start(IOBANK)
  140.    Doke IOSTDREQ+28,9 : Rem IO command switch motor
  141.    Loke IOSTDREQ+36,FLAG : Rem Switch motor on or off 
  142.    Areg(1)=IOSTDREQ
  143.    X=Execall(-456) : Rem DoIo     
  144. End Proc[X]
  145. '
  146. Procedure CMD_READ[IOBANK,BLOCK,BUFBANK]
  147.    '
  148.    '----------Routine to get a block
  149.    '
  150.    IOSTDREQ=Start(IOBANK)
  151.    Doke IOSTDREQ+28,11 : Rem IO command to read 
  152.    Loke IOSTDREQ+36,Length(BUFBANK) : Rem amount of data is given by length of the buffer
  153.    Loke IOSTDREQ+40,Start(BUFBANK) : Rem address of data buffer 
  154.    Loke IOSTDREQ+44,BLOCK*(512*11) : Rem offset at which to start reading 
  155.    Areg(1)=IOSTDREQ
  156.    X=Execall(-456) : Rem DoIo 
  157. End Proc[X]
  158. '
  159. Procedure OPENDEVICE[DEVNAME$,UNIT,IOBANK,FLAGS]
  160.    '
  161.    '---------Routine to open device prior to doing IO to it 
  162.    '
  163.    DEVNAME$=DEVNAME$+Chr$(0) : Rem string must be null terminated 
  164.    Areg(0)=Varptr(DEVNAME$)
  165.    Dreg(0)=UNIT
  166.    Areg(1)=Start(IOBANK)
  167.    Dreg(1)=FLAGS
  168.    X=Execall(-444)
  169. End Proc[X]
  170. '
  171. Procedure KLOSEDEVICE[IOBANK]
  172.    '
  173.    '-------- Routine to close a device
  174.    '
  175.    Areg(1)=Start(IOBANK)
  176.    X=Execall(-450)
  177. End Proc