home *** CD-ROM | disk | FTP | other *** search
/ Light / Light_Vol.1_June_1992_Datasphere_Publications_Disk_1_of_2_Side_B.d64 / de3 (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  11KB  |  237 lines

  1. 1 a=a+1:ifa=1thenload"de.code",8,1
  2. 2 ky=49235:l=49152:dimh$(15):c(0)=1:c(1)=15:c(2)=12:c(3)=11
  3. 3 poke53280,5:poke53281,11:print"[147] [207]nce a disk has been  formatted by the"
  4. 4 print" [195]ommodore 64  it  contains  35 tracks,"
  5. 5 print" each  one  having  between  17 and  21"
  6. 6 print" sectors (or blocks).  [193]ltogether there"
  7. 7 print" are 683 blocks per disk,  664 of which"
  8. 8 print" can be used  freely by you for storing"
  9. 9 print" whatever[160]sort of data you  wish.  [197]ach"
  10. 10 print" time  a program  is  saved,  the drive"
  11. 11 print" needs to know  as quickly  as possible"
  12. 12 print" which sectors are free, without having"
  13. 13 print" to search through the entire disk.":fori=0to15:readh$(i)
  14. 14 h$(i)=h$(i)+"[145][145][145]":next:sysky:print"[147] [201]t is for this reason that sector zero"
  15. 15 print" of the directory  track is home to the"
  16. 16 print" most  important  block  of  140  bytes"
  17. 17 print" anywhere on the disk.  [201]t is the [194]lock"
  18. 18 print" [193]llocation [205]ap  and it keeps  a record"
  19. 19 print" of  exactly  which of  the 664 sectors"
  20. 20 print" are available  for use.  [197]ach track on"
  21. 21 print" the disk is represented by four bytes,"
  22. 22 print" the [160]first being  the  total number of"
  23. 23 print" free sectors on that track, the others"
  24. 24 print" storing the information for the break-"
  25. 25 print" down of exactly which sectors are free"
  26. 26 sysky:print"[147] [212]o  demonstrate  the  [194]lock [193]llocation"
  27. 27 print" [205]ap  - [194][193][205] for short -  you should now"
  28. 28 print" insert a disk of your choice. [212]he data"
  29. 29 print" from the  [194][193][205] on that disk  will  then"
  30. 30 print" be  used  in the  rest of  this  demo."
  31. 31 print" [201]t is important that you do not remove"
  32. 32 print" that disk until  the demonstration has":print" finished.":sysky
  33. 33 print"[147][212]rack 18, [211]ector 0":print"[155]";:open15,8,15:open8,8,8,"#"
  34. 34 print#15,"u1 8 0 18 0":fori=0to7:fork=0to1:forj=1to16
  35. 35 get#8,a$:a=asc(a$+chr$(0)):h$="":form=1to2:d=int(a/16)
  36. 36 h$=mid$("0123456789[193][194][195][196][197][198]",1+a-d*16,1)+h$:a=d:next
  37. 37 poke199,abs(abs(i/2=int(i/2))-abs(j/2=int(j/2)))
  38. 38 printh$;:next:print:print" ";:nextk,i
  39. 39 print"[155][212]he above data represents the 256"
  40. 40 print" bytes of information stored at the"
  41. 41 print" start of the directory track. [204]et's"
  42. 42 print" work through it, highlighting the"
  43. 43 print" important sections.":sysky:poke2023,32:sysl,720,960,11
  44. 44 sysl,80,720,0:print"[145][145][145][145][145][155] [212]he first two bytes of any sector are"
  45. 45 print" pointers and tell the drive which"
  46. 46 print" track and sector should be read next.":sysl,81,85,1:sysky
  47. 47 sysl,760,960,11:sysl,81,85,0:print"[145][145][145] [212]his byte is very important. [217]ou
  48. 48 [153]" should not change it because it tells
  49. 49 print" the drive that [196][207][211]1 is to be used. [193]ny
  50. 50 [153]" attempt to alter it could lead to a
  51. 51 print" [196][207][211] [205]ismatch error being generated.":sysl,85,87,1:sysky
  52. 52 sysl,85,87,0:print"[145][145][145][145][145] [212]hese are the 140 bytes known as the"
  53. 53 print" [194][193][205]. [201]t is hard to believe that such a
  54. 54 [153]" small number of bytes could hold all  "
  55. 55 [153]" the information regarding the status"
  56. 56 [153]" of each of the 683 blocks on the disk.":[158]l,89,440,1:[158]ky
  57. 57 [158]l,89,440,0:[158]l,760,960,11
  58. 58 [153]"ononononon (NULL)his is the atn(NULL)lenright$right$ representation of"
  59. 59 [153]" the disk header.":[158]l,440,480,1:[158]ky:[158]l,440,480,0
  60. 60 [153]"onon (NULL)he identification code is represented
  61. 61 print" by these five bytes, again the [193][211][195][201][201]
  62. 62 [153]" codes are used.":[158]l,485,495,1:[158]ky:[158]l,485,495,0
  63. 63 [153]"ononon (NULL)he next stage of this demonstration  "
  64. 64 [153]" deals with one track only. (NULL)sing the
  65. 65 print" cursor keys, please select any track
  66. 66 [153]" on the disk to be analysed. (NULL)ress
  67. 67 print" any other key to continue.":poke2023,32:t=1
  68. 68 print" [212]rack:             "
  69. 69 sysl,81+int(t/4)*40+(t and3)*8,89+int(t/4)*40+(t and3)*8,1:poke198,0
  70. 70 print""tab(7)t"[157] "
  71. 71 geta$:ifa$=""then71
  72. 72 ifa$<>""anda$<>"[145]"anda$<>""anda$<>"[157]"then79
  73. 73 t1=t:ifa$=""thent=t-4*(t<32):goto77
  74. 74 ifa$="[145]"thent=t+4*(t>4):goto77
  75. 75 ifa$=""thent=t-1*(t<35):goto77
  76. 76 ifa$="[157]"thent=t+1*(t>1)
  77. 77 sysl,81+int(t1/4)*40+(t1and3)*8,89+int(t1/4)*40+(t1and3)*8,0
  78. 78 goto69
  79. 79 print"[147] [212]he four bytes below are the [194][193][205]"
  80. 80 print" representation of track"t"[157]:"
  81. 81 print" ";:fori=0to3:print#15,"b-p:8"t*4+i:get#8,a$:b(i)=asc(a$+chr$(0))
  82. 82 printh$(int(b(i)/16))h$((b(i)/16-int(b(i)/16))*16);"   [144]";:next
  83. 83 print:print"[155] [210]emember, the first byte in the set of"
  84. 84 print" four is a checksum and it tells the"
  85. 85 print" drive how many free sectors there are."
  86. 86 print" [201]f there is a discrepancy between this"
  87. 87 print" figure and the number of sectors free"
  88. 88 print" according to the other three bytes a"
  89. 89 print" [196]irectory [197]rror will be generated."
  90. 90 print" [198]or now though, we shall ignore it.":sysky
  91. 91 fori=0to3:sysl,170+i*40,200+i*40,1:next
  92. 92 sysl,360,960,11:print"":fori=1to8
  93. 93 print"":forj=1to4:print" "chr$(20):nextj,i
  94. 94 print" [212]hese three bytes store all the"
  95. 95 print" necessary information about all the"
  96. 96 print" sectors in this track.":print" [194]efore you see exactly how the info is
  97. 97 [153]" interpreted into something we can"
  98. 98 [153]" understand, it is best if the values"
  99. 99 [153]" are converted into binary...":[158]ky:[158]l,240,960,11:[158]l,0,200,0
  100. 100 [153]"":[129]i[178]0[164]2:[153][163]i[172]9[170]1);:b$[178]"":b[178]b(i[170]1):[129]j[178]0[164]7:f[178]b[171][181](b[173]2)[172]2
  101. 101 b$[178]"1"[170]b$:[139]f[178]0[167]b$[178]"0"[170][202](b$,2)
  102. 102 b[178][181](b[173]2):[130]:b$(i)[178]b$:[153]b$" ";:[130]:[153]
  103. 103 [153]"list (NULL)erhaps now it is possible to see just"
  104. 104 [153]" how the records are kept but there
  105. 105 print" is still one alteration that needs to
  106. 106 [153]" be made. (NULL)he bits should be arranged
  107. 107 print" in ascending order of value. [212]hus we
  108. 108 [153]" need to create a mirror image of the
  109. 109 print" bits in each of the three bytes...":sysky:sysl,240,960,11
  110. 110 fork=0to2:a$=b$(k):b$="":fori=0to8:d$=right$(a$,1):c$=d$:a$=left$(" "+a$,8)
  111. 111 forj=7-ito0step-1:printtab(k*9+1)a$"[157]"d$"[157][157][157][157][157][157][157][157]"b$"[145][145][145]"
  112. 112 b2$(k)=left$(b$,8)
  113. 113 b$=left$(b$+"        ",i+j)+c$+"        ":d$=" ":nextj,i
  114. 114 next
  115. 115 fori=0to30:poke1224+i,peek(1304+i):poke1304+i,32:next
  116. 116 print"[155] [207][203]. [206]ow let's string together all the"
  117. 117 print" digits to form one 24 digit number. [215]e"
  118. 118 print" can also forget about the hexadecimal"
  119. 119 print" representation of the bytes.":b$=b2$(0)+b2$(1)+b2$(2):sysky
  120. 120 sysl,0,40,11:sysl,80,960,11
  121. 121 sys49152,0,200,11:sys49152,240,960,11:print"";:fori=1to4
  122. 122 print"                            [145][145]":print" "b$"[145]":forj=1to50:nextj,i
  123. 123 print"[155] [201]t might as well be revealed now that"
  124. 124 print" the computer looks at each bit (digit)
  125. 125 [153]" in turn and each one represents one"
  126. 126 [153]" sector on the disk. left$owever, you chose"
  127. 127 [153]" track"t"to be analysed and this has"
  128. 128 [153]" only";:s[178]21:[139]t[177]17[167]s[178]19
  129. 129 [139]t[177]24[167]s[178]18
  130. 130 [139]t[177]30[167]s[178]17
  131. 131 [153]s"sectors and so we need to":[153]" remove some excess digits...":[158]ky
  132. 132 [158]l,80,960,11:[129]k[178]1[164]24[171]s:[129]j[178]0[164]3:[151]55361[171]k,c(j):[129]m[178]1[164]50:[130]m,j,k
  133. 133 [153]"list (NULL)ow we have the correct number of"
  134. 134 [153]" digits to represent the sectors on the"
  135. 135 [153]" chosen track."
  136. 136 [153]" right$f right$ replace all the zeros with the   "
  137. 137 [153]" letter '(NULL)' and all the ones with a"
  138. 138 [153]" full stop then it is simple to see"
  139. 139 [153]" which sectors are free and which are"
  140. 140 [153]" used.":[158]ky:[158]l,80,960,11:[129]i[178]1[164]s:c[178]46:[139][194](1064[170]i)[178]48[167]c[178]88
  141. 141 [129]j[178]0[164]3:[151]55336[170]i,c(j):[129]m[178]1[164]20:[130]m,j:[151]1064[170]i,c:[129]j[178]3[164]0[169][171]1
  142. 142 [151]55336[170]i,c(j):[129]z[178]1[164]20:[130]z,j,i
  143. 143 [153]"list (NULL)k. (NULL)ow you see the breakdown of the"
  144. 144 [153]" sectors used on track"t"cmd. (NULL)his has":[153]" been obtained from just three";
  145. 145 [153]" bytes.":[153]" valmpty sectors are denoted by the full"
  146. 146 [153]" stops - originally the bits that were
  147. 147 print" set to one. [211]ector 0 is on the left"
  148. 148 print" and sector"s-1"on the right."
  149. 149 print" [204]et's recap quickly the steps for"
  150. 150 print" finding out which sectors of which"
  151. 151 print" blocks are free...":sysky
  152. 152 print"[147][206]ote: [212]his method is for manually"
  153. 153 print"       checking the [194][193][205]. [201]f doing it"
  154. 154 print"       from [194][193][211][201][195] then skip this page."
  155. 155 print" 1. [215]rite down the binary conversion of
  156. 156 [153]"    the three bytes.":[153]"list 2. (NULL)rite down the mirror images of"
  157. 157 [153]"    these bytes.":[153]"list 3. (NULL)tring the three sets of new digits"
  158. 158 [153]"    together to form a 24 digit number."
  159. 159 [153]"list 4. valrase excess digits - you only need"
  160. 160 [153]"    the sectors that exist in that"
  161. 161 [153]"    track to be represented. lenheck your"
  162. 162 [153]"    manual if you are unsure of the"
  163. 163 [153]"    number of sectors in each track."
  164. 164 [153]"list 5. (NULL)ow, every digit that is a one"
  165. 165 [153]"    represents a asc(NULL)valval sector and each"
  166. 166 [153]"    zero represents a (NULL)(NULL)valstr$ sector.":[158]ky
  167. 167 [153]"loadlist peekatn(NULL)right$len program for reading the peekatn(NULL):"
  168. 168 [153]"  10 (NULL)(NULL)val(NULL)15,8,15:(NULL)(NULL)val(NULL)8,8,8,"[199](34)"#"[199](34)
  169. 169 [153]"  20 (NULL)(NULL)right$(NULL)(NULL)#15,"[199](34)"(NULL)1 8 0 18 0"[199](34)
  170. 170 [153]"  30 right$(NULL)(NULL)(NULL)(NULL)"[199](34)"(NULL)left$right$lenleft$close(NULL)(NULL)atnlen(NULL)"[199](34)";(NULL)(NULL)
  171. 171 print"  40 [208][210][201][206][212]#15,"chr$(34)"[194]-[208]:8"chr$(34)"[212][210]*4+1
  172. 172 [153]"  50 asc(NULL)(NULL) peek(NULL)=0(NULL)(NULL)2:chr$val(NULL)#8,atn$:":[153]"     peek(peek(NULL))=atn(NULL)len(atn$+lenleft$(NULL)$(0))
  173. 173 print"  60 [206][197][216][212] [194][217]: [195][204][207][211][197]8:[195][204][207][211][197]15":print"  70 [211]=20:[201][198] [212][210]>17 [212][200][197][206] [211]=18"
  174. 174 print"  80 [201][198] [212][210]>24 [212][200][197][206] [211]=17":print"  90 [201][198] [212][210]>30 [212][200][197][206] [211]=16":print" 100 [211][210]=0: [196][201][205] [211][211]([211])
  175. 175 [153]" 110 asc(NULL)(NULL) peek(NULL)=0(NULL)(NULL)2:peek=peek(peek(NULL))":[153]" 120 asc(NULL)(NULL) peekright$(NULL)=0(NULL)(NULL)7"
  176. 176 [153]" 130 (NULL)= right$(NULL)(NULL)(peek/2): (NULL)(NULL)=peek-((NULL)*2)":[153]" 140 right$asc (NULL)(NULL)<=(NULL) (NULL)left$val(NULL) (NULL)(NULL)((NULL)(NULL))=1-(NULL)(NULL)"
  177. 177 [153]" 150 peek=(NULL): (NULL)(NULL)=(NULL)(NULL)+1: (NULL)val(NULL)(NULL) peekright$(NULL),peek(NULL)"
  178. 178 [153]" (NULL)he status of each sector is held in"
  179. 179 [153]" an array (NULL)(NULL)((NULL)) where 0=asc(NULL)valval,1=(NULL)(NULL)valstr$."
  180. 180 [153]"list (NULL)he above program will remain in the"
  181. 181 [153]" memory when the demo has finished.":[158]ky
  182. 182 [153]"loadright$ shall now read the peekatn(NULL) of this disk"
  183. 183 [153]" using a similar method to the above"
  184. 184 [153]" program. (NULL)o enable it to fit on the"
  185. 185 [153]" display the horizontal axis is the"
  186. 186 [153]" tracks and the vertical is the sectors"
  187. 187 [153]" (NULL)sed sectors are denoted by square"
  188. 188 [153]" blocks ( wait).":[158]ky
  189. 189 [153]"loadsys             1         2         3":[153]"    ";:[129]i[178]1[164]35
  190. 190 [153][201]([196](i),1);:[130]:[153]"def    (NULL)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  191. 191 fori=0to20:print"[158]  "right$(str$(i),1)"[150][179]"
  192. 192 ifi=10ori=20thenprint"[145][158]"i
  193. 193 next:printtab(34)"[144][145][145][145][145][142][166][166][166][166][166]":printtab(28)"[166][166][166][166][166][166][166][166][166][166][166]":fori=1to2
  194. 194 print,," [166][166][166][166][166][166][166][166][166][166][166][166][166][166][166][166][166][166]":next
  195. 195 fort=1to35:print#15,"b-p:8"t*4+1:fory=0to2:get#8,a$:b(y)=asc(a$+chr$(0))
  196. 196 next:s=20:ift>17thens=18
  197. 197 ift>24thens=17
  198. 198 ift>30thens=16
  199. 199 poke781,3:poke782,3+t:poke783,0:sys65520
  200. 200 r=0:fory=0to2:b=b(y):forbt=0to7:v=int(b/2):ss=b-v*2
  201. 201 ifr>sthen204
  202. 202 print"[146][144][214][157][155]";:ifss=0thenprint"[208][157]";:goto204
  203. 203 print" [157]";
  204. 204 b=v:r=r+1:nextbt,y,t:close8:close15:sysky
  205. 205 print"[147][146] [201]f you should ever wish to change the"
  206. 206 print" [194][193][205] manually then follow the simple"
  207. 207 print" steps below (you'll have to work out a"
  208. 208 print" program for this one - [201] can't provide"
  209. 209 print" everything for you, now can [201] ?)"
  210. 210 print" [155]1. [210]ead track 18, sector 0":print" [155]2. [199]et the appropriate three bytes
  211. 211 [153]"    that represent the desired track"
  212. 212 [153]"list 3. (NULL)o find which of the three bytes:"
  213. 213 [153]"    peek=right$(NULL)(NULL)((NULL)ector/8)  list[(NULL)ange 0-2]"
  214. 214 [153]"list 4. (NULL)o find which bit of byte peek:"
  215. 215 [153]"    peek(NULL)=(NULL)ector-right$(NULL)(NULL)((NULL)ector/8)*8  list[0-7]"
  216. 216 [153]"list 5. (NULL)o make the sector free:":[153]"    peekyte(NULL)alue=peekyte(NULL)alue (NULL)(NULL) 2^peek(NULL)
  217. 217 print"    [212]o make the sector used:":print"    [194]yte[214]alue=[194]yte[214]alue [193][206][196] (255-2^[194][212])
  218. 218 [158]ky:[153]"load str$emonstration over. (NULL)ress any key to"
  219. 219 [153]" return to peekatn(NULL)right$len with the program to"
  220. 220 [153]" read the peekatn(NULL) in memory...":[158]ky:[153]"loadpokenew"
  221. 221 [153]"10open15,8,15:open8,8,8,"[199](34)"#"[199](34)":print#15,";
  222. 222 [153][199](34)"u1 8 0 18 0"[199](34)":input"[199](34)"which track"[199](34)";tr
  223. 223 print"20 print#15,"chr$(34)"b-p:8"chr$(34)"tr*4+1:forby=0to2:get#8,a$:";
  224. 224 print"b(by)=asc(a$+chr$(0)):next:close8":print"30 close15:s=20:iftr>17thens=18
  225. 225 [153]"40 iftr>24thens=17":[153]"50 iftr>30thens=16"
  226. 226 [153]"60 sr=0:dimss(s):forby=0to2:b=b(by):forbt=0to7:v=int(b/2):ss=b-(v*2)
  227. 227 print"70 ifsr<=sthenss(sr)=1-ss":print"80 b=v:sr=sr+1:nextbt,by"
  228. 228 print"?"chr$(34)"[147][142]"chr$(34)";";:fori=0to9:poke631+i,13:next:poke198,10
  229. 229 data"[191][162][146][187][157][157][157][161][191][146][161][157][157][157][172][146] [161][157][157][157][188][162][146] ","[172][161] [157][157][157] [161] [157][157][157] [161] [157][157][157][188][162][146] "
  230. 230 data"[191][162][146][187][157][157][157] [162][190][157][157][157][191][146]  [157][157][157][162][162][146][190]","[191][162][146][187][157][157][157] [162][190][157][157][157][187] [161][157][157][157][188][162][146] "
  231. 231 data" [190][146] [157][157][157][191][161][146] [157][157][157][162][187][146][190][157][157][157] [188] ","[172][162][146][190][157][157][157][162][162][146][187][157][157][157][187] [161][157][157][157][188][162][146] "
  232. 232 data"[172][162][146][190][157][157][157][188][146][162] [157][157][157][161] [161][157][157][157][188][162][146] ","[162][162][146][161][157][157][157] [191][146] [157][157][157] [161] [157][157][157] [190] "
  233. 233 data"[191][162][146][187][157][157][157][191][162][190][157][157][157][161] [161][157][157][157][188][162][146] ","[191][162][146][187][157][157][157][191][162][161][157][157][157][187] [161][157][157][157][188][162][146] "
  234. 234 data"[172][191] [157][157][157][188][146][162][161][157][157][157][161] [161][157][157][157][190] [190]","[172][162][146][187][157][157][157][188][146][162][190][157][157][157][161] [161][157][157][157][162][162][146] "
  235. 235 data"[191][162][146][187][157][157][157][161]  [157][157][157][161] [187][157][157][157][188][162][146] ","[172][146][191] [157][157][157][161] [161][157][157][157][161][172][190][157][157][157][162][146][190] "
  236. 236 data"[172][162][146][190][157][157][157][188][146][187] [157][157][157][161]  [157][157][157][162][162][146][190]","[172][162][146][190][157][157][157][188][146][187] [157][157][157][161]  [157][157][157][190]  "
  237.