home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / sourcecode / various / drive_write.amos / drive_write.amosSourceCode
AMOS Source Code  |  1993-01-08  |  3KB  |  113 lines

  1. Screen Open 0,640,200,2,Hires : Colour 1,$FFF : Flash Off 
  2. MSGBANK=7 : IOBANK=8 : BUFBANK=9 : BUFLEN=512
  3. Reserve As Chip Work BUFBANK,BUFLEN
  4. ' change params if you want to access hard drive 
  5. UNIT=0 : DEVICE$="trackdisk.device"
  6. CREATEPORT[MSGBANK]
  7. CREATEIO[IOBANK,MSGBANK]
  8. OPENDEVICE[DEVICE$,UNIT,IOBANK,0]
  9. If Param<>0
  10. Print "opendevice failed"
  11. DELETEIO[IOBANK]
  12. DELETEPORT[MSGBANK]
  13. End 
  14. End If 
  15. ' turn motor on, read sector then turn motor off 
  16. TD_MOTOR[IOBANK,1]
  17. If Param<>0 Then Print "warning doio returned an error ";Param
  18. CMD_READ[IOBANK,0,BUFBANK]
  19. If Param<>0 Then Print "warning doio returned an error ";Param
  20. TD_MOTOR[IOBANK,0]
  21. If Param<>0 Then Print "warning doio returned an error ";Param
  22. ' close the device, free the port and free the banks 
  23. KLOSEDEVICE[IOBANK]
  24. DELETEIO[IOBANK]
  25. DELETEPORT[MSGBANK]
  26. 'format and print the bootblock
  27. For AD=Start(BUFBANK) To Start(BUFBANK)+492 Step 20
  28. For AD2=AD To AD+16 Step 4
  29. Print Right$(Hex$(Leek(AD2),8),8);" ";
  30. Next 
  31. Print "  ";
  32. For AD2=AD To AD+19
  33. If Peek(AD2)>32
  34. Print Chr$(Peek(AD2));
  35. Else 
  36. Print ".";
  37. End If 
  38. Next 
  39. Print 
  40. Next 
  41. Procedure CREATEPORT[BANK]
  42. ' routine to allocate & initialise a message port
  43. 'note: this port is not placed on the system port list 
  44. Dreg(0)=-1 : Rem this means use any of the available signal bits
  45. SIGNAL_NUMBER=Execall(-330)
  46. If SIGNAL_NUMBER=-1
  47. Print "Signal allocation failed in createport"
  48. Direct 
  49. End If 
  50. Reserve As Work BANK,34
  51. MSGPORT=Start(BANK)
  52. 'at offset 276 of execbase is the address of the currently executing task  
  53. ' That must be us if we are looking at it
  54. EXECBASE=Leek(4)
  55. MY_TASK=Leek(EXECBASE+276)
  56. 'fill in the necessary information for the msgport structure 
  57. Poke MSGPORT+9,0 : Rem port priority
  58. Poke MSGPORT+8,16 : Rem node type is message port
  59. Poke MSGPORT+14,0 : Rem flags
  60. Poke MSGPORT+15,SIGNAL_NUMBER : Rem signal number
  61. Loke MSGPORT+16,MY_TASK : Rem address of our task structure
  62. End Proc
  63. Procedure DELETEPORT[BANK]
  64. ' routine to free an alocated port 
  65. MSGPORT=Start(BANK)
  66. Dreg(0)=Peek(MSGPORT+15)
  67. X=Execall(-336) : Rem free the signal
  68. Erase BANK : Rem free memory
  69. End Proc
  70. Procedure CREATEIO[IOBANK,MSGBANK]
  71. ' routine to initialise the io request structure 
  72. Reserve As Work IOBANK,48
  73. IOSTDREQ=Start(IOBANK)
  74. Poke IOSTDREQ+8,32 : Rem insert message type
  75. Doke IOSTDREQ+18,48 : Rem length of structure
  76. Loke IOSTDREQ+14,Start(MSGBANK) : Rem address of message port structure
  77. End Proc
  78. Procedure DELETEIO[IOBANK]
  79. ' this routine frees an io request structure 
  80. Erase IOBANK
  81. End Proc
  82. Procedure TD_MOTOR[IOBANK,FLAG]
  83. 'switch motor on or off
  84. IOSTDREQ=Start(IOBANK)
  85. Doke IOSTDREQ+28,9 : Rem io command switch motor
  86. Loke IOSTDREQ+36,FLAG : Rem switch motor on/off
  87. Areg(1)=IOSTDREQ
  88. X=Execall(-456) : Rem dolo 
  89. End Proc[X]
  90. Procedure CMD_READ[IOBANK,BLOCK,BUFBANK]
  91. 'routine to get a block
  92. IOSTDREQ=Start(IOBANK)
  93. Doke IOSTDREQ+28,2 : Rem io command to read 
  94. Loke IOSTDREQ+36,Length(BUFBANK) : Rem amount of data is given by length of this buffer 
  95. Loke IOSTDREQ+40,Start(BUFBANK) : Rem address of data buffer 
  96. Loke IOSTDREQ+44,BLOCK*512 : Rem offset at which to start reading 
  97. Areg(1)=IOSTDREQ
  98. X=Execall(-456) : Rem dolo 
  99. End Proc[X]
  100. Procedure OPENDEVICE[DEVNAME$,UNIT,IOBANK,FLAGS]
  101. 'routine to open a device prior to doing io to it
  102. DEVNAME$=DEVNAME$+Chr$(0)
  103. Areg(0)=Varptr(DEVNAME$)
  104. Dreg(0)=UNIT
  105. Areg(1)=Start(IOBANK)
  106. Dreg(1)=FLAGS
  107. X=Execall(-444)
  108. End Proc[X]
  109. Procedure KLOSEDEVICE[IOBANK]
  110. 'routine to close device 
  111. Areg(1)=Start(IOBANK)
  112. X=Execall(-450)
  113. End Proc