home *** CD-ROM | disk | FTP | other *** search
/ UpTime Volume 2 #7 / utv2n7s1.d64 / seq (.txt) < prev    next >
Encoding:
Commodore BASIC  |  1988-01-01  |  22.0 KB  |  510 lines

  1. 10 rem (c) 1988 uptime magazine
  2. 20 rem (c) 1988 softdisk publishing inc.
  3. 30 rem author: noel nyman
  4. 40 rem gray border, black screen, light green text
  5. 45 sys65409
  6. 50 poke53280,11:poke53281,0:poke646,13
  7. 60 rem q$=quotes, force upper/lower case, run/stop disabled
  8. 70 q$=chr$(34):printchr$(14)chr$(8):sp$="                   ":poke808,234
  9. 80 rem --- sys (NULL),x,y places cursor at row x, column y ---
  10. 90 q=679:forx=qto706:reada:pokex,a:next
  11. 100 data 32,253,174,32,158,173,32,170,177,132,2,32,253,174,32,158
  12. 110 data 173,32,170,177,166,2,76,240,255,56,176,250
  13. 120 rem skip sub-routines
  14. 130 goto560
  15. 140 rem *** clear screen to line 23 starting at line 'x' ***
  16. 150 x=10:gosub160:sysq,10,3:return
  17. 160 fory=xto23:sysq,y,0:sys 59903:pokey+217,peek(y+217)or128:next
  18. 170 return
  19. 180 rem *** filter keyboard input for string ***
  20. 190 rem ---returns string in xx$ length 'll' or smaller---
  21. 200 xx$="":xb=65:xe=90:goto220:rem lower case alpha only
  22. 210 xx$="":xb=48:xe=57:goto220:rem numeric only
  23. 220 gosub270:xa=asc(cg$):ifxa=13andxx$<>""thenreturn
  24. 230 if(xa=20)and(xx$<>"")thenprintcg$;:xx$=left$(xx$,len(xx$)-1):goto220
  25. 240 if(xa<xb)or(xa>xe)goto220
  26. 250 iflen(xx$)>=llgoto220
  27. 260 printcg$;:xx$=xx$+cg$:goto220
  28. 270 xl%=peek(211)
  29. 280 if(xl%>39)thenxl%=xl%-40:goto280
  30. 290 xl%=xl%+peek(214)*40+1024:xc=54272+xl%
  31. 300 pokexc,peek(646):xo%=peek(xl%):xt%=xo%:xq%=128:if(xo%>127)thenxq%=-xq%
  32. 310 xt%=xt%+xq%:pokexl%,xt%:xq%=-xq%
  33. 320 forxr=1to60
  34. 330 getcg$:if(cg$<>"")thenpokexl%,xo%:xr=61:next:return
  35. 340 next:goto310
  36. 350 rem *** delay loop ***
  37. 360 rem --- enter with delay time in x ---
  38. 370 fora=1tox:next:return
  39. 380 fory=11to16:sysq,6,y:print"[158]->[153]":x=50:gosub370:next:return
  40. 390 gosub420:sysq,5,19:printsp$:sysq,6,19:printsp$:return
  41. 400 sysq,0,0:sys59903:return
  42. 410 fory=16to11step-1:sysq,6,y:print"<*":x=50:gosub370:next:return
  43. 420 sysq,6,11:print"       ":return
  44. 430 rem *** prompt ***
  45. 440 sys679,24,1:print"[152][211][208][193][195][197] [194][193][210] to continue - [198]8 for [213][208][212][201][205][197][146][153]";
  46. 450 wait198,1:poke198,0
  47. 460 if(peek(631)=32)or(peek(631)=13)thenwait197,64:return
  48. 470 ifpeek(631)<>140goto450
  49. 480 rem re-enter uptime environment
  50. 490 printchr$(9): rem enable shift/c=
  51. 500 poke186,8: rem device #8
  52. 510 poke808,237: rem re-enable run-stop
  53. 520 load"reboot",8
  54. 530 rem ***************************
  55. 540 rem   main program starts here
  56. 550 rem ***************************
  57. 560 print"[147]"
  58. 570 print"[158]       [182][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][183][181]
  59. 580 [153]"sys       abs print(NULL)(NULL)right$(NULL)chr$ (NULL)val(NULL)(NULL)val(NULL)(NULL)right$atn(NULL) ascright$(NULL)val(NULL) sysint
  60. 590 print"       [182][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][175][181]
  61. 600 [153]"print#     published by (NULL)oftdisk (NULL)ublishing
  62. 610 print"     written for [213][208][212][201][205][197] by [206]oel [206]yman
  63. 620 [153]"print   (NULL)n many disks, you've seen files in
  64. 630 print"the disk directory with [211][197][209][153] following
  65. 640 [153]"their names.  sys(NULL)val(NULL)printuential files are often";
  66. 650 [153]"used by programmers to store data.  They";
  67. 660 [153]"can also be used for word processor and
  68. 670 print"other text files.
  69. 680 [153]"   (NULL)e're going to show you how to make
  70. 690 print"your own [158][211][197][209][153] files to hold data from
  71. 700 [153]"your programs, and how to read just
  72. 710 print"about any [158][211][197][209][153] file.":gosub440
  73. 720 print"[147]
  74. 730 [153]"lenomputer asciles          str$isk asciles
  75. 740 print"[129][163][163][163][163][163][163][163][163][163][163][163][163][163][163]          [163][163][163][163][163][163][163][163][163][163]
  76. 750 [153]"list10    8    2         1  "q$"(NULL)(NULL)(NULL)right$(NULL)val"q$"     (NULL)(NULL)chr$
  77. 760 print" 4    4    0         15 "q$"[204][197][212][212][197][210]"q$"     [211][197][209]
  78. 770 [153]"15    8   15         12 "q$"asc(NULL)(NULL)chr$chr$right$val"q$"    (NULL)(NULL)chr$
  79. 780 print"[153]   [213]nfortunately, the same word is often";
  80. 790 print"used in the computer world to mean two
  81. 800 [153]"different things.  (NULL)he word "q$"file"q$"print has
  82. 810 print"two meanings for [195]ommodore computers.
  83. 820 [153]"   (NULL)ou already know that a collection of";
  84. 830 [153]"data on a diskprint is known as a sysfileprint.
  85. 840 print"   [212]he computer[153] also uses [158]files[153], but
  86. 850 [153]"for a different purpose.":[141]440
  87. 860 [153]"loadlist(NULL)(NULL)val(NULL) 4, 4, 0: len(NULL)str$ 4: (NULL)right$(NULL)(NULL)print
  88. 870 print"   [217]ou may have used computer files
  89. 880 [153]"without knowing it.  The set of commands";
  90. 890 [153]"above (NULL)right$(NULL)(NULL)prints a peekatn(NULL)right$len program to your":[153]"printer.
  91. 900 gosub440:sysq,1,8:print "^
  92. 910 [158]q,2,6:[153]"deviceprint":[141]150
  93. 920 [153]"(NULL)his is the device numberprint. (NULL)ost
  94. 930 print"[195]ommodore printers are [158]device #4[153].
  95. 940 [141]440:[158]q,1,8:[153]"   ^
  96. 950 sysq,2,3:print"secondary address[153]":sysq,14,0
  97. 960 print"   [212]his number is called the secondary
  98. 970 [153]"addressprint.  (NULL)ome devices use this number
  99. 980 print"for special purposes.  [193] secondary
  100. 990 [153]"address of syszeroprint puts lenommodore printers
  101. 1000 print"into [213]pper [195]ase/[199]raphics mode.
  102. 1010 [141]440:[158]q,1,5:[153]"^            ^
  103. 1020 sysq,2,1:print"file number  file number[153]":sysq,21,3
  104. 1030 print"[212]his number is the file number[153].":gosub440
  105. 1040 print"[147][155][207][208][197][206][153]
  106. 1050 [158]59903:[153]"   atn computer fileprint is the reference
  107. 1060 print"used by the machine and the programmer
  108. 1070 [153]"for input/output or sysright$/(NULL)print activity.  (NULL)o
  109. 1080 print"communicate with a printer, modem, or
  110. 1090 [153]"disk drive, you must create or (NULL)(NULL)val(NULL)print a":[153]"file.
  111. 1100 print"   [212]he computer keeps track of files by
  112. 1110 [153]"using the file numberprint.  (NULL)his number
  113. 1120 print"can be any whole number from 1[153] through
  114. 1130 [153]"127print.  ((NULL)he numbers sys128print through sys255print
  115. 1140 print"are used to add an extra blank line when";
  116. 1150 print"[158][204][201][211][212][153]ing programs to a printer.)
  117. 1160 [153]"   (NULL)ow, enter a number between 1print and
  118. 1170 print"127[153] for a file number."
  119. 1180 print"---> ";:x$=""
  120. 1190 ll=3:gosub210:xx=val(xx$):if(xx>0)and(xx<128)goto1220
  121. 1200 print"[147][153][217]our number should be between [158]1[153]
  122. 1210 [153]"and sys127print.   (NULL)ry again.":[137]1180
  123. 1220 fl$[178]xx$:[153]"loadlist(NULL)(NULL)val(NULL) "fl$"
  124. 1230 print"[153]   [207]nce we set up or "q$"open"q$"[153] a file,
  125. 1240 [153]"we have to tell the computer which
  126. 1250 print"device we want to use with that file.
  127. 1260 [153]"   (NULL)ince we're going to create a sys(NULL)val(NULL)print
  128. 1270 print"disk file, we'll use device #8[153].":gosub440
  129. 1280 print"[155]"tab(5+len(fl$))",8
  130. 1290 [141]150:[153]"printstr$on't forget the sys"q$","q$"print between the
  131. 1300 print"file number and the device number.":gosub440
  132. 1310 print "[147][155][207][208][197][206] "fl$",8"
  133. 1320 print"[147][155][207][208][197][206] "fl$",8":print"[153]   [212]he [158]secondary address[153] you need to use";
  134. 1330 print"depends on the device.  [208]rinters and
  135. 1340 [153]"printer interfaces use the secondary
  136. 1350 print"address to change printing styles.
  137. 1360 [153]"   str$isk drives use the syssecondary addressprint";
  138. 1370 [153]"in the same way that the computer uses
  139. 1380 print"file numbers.  [198]or a disk drive, the
  140. 1390 [153]"secondary address is often called a":[153]"channelprint.
  141. 1400 print"   [215]hen you want to [204][207][193][196], [211][193][214][197], read
  142. 1410 [153]"from, or write to a file, the disk drive";
  143. 1420 [153]"keeps track of which file on the disk to";
  144. 1430 [153]"use by a channelprint number.":[141]440
  145. 1440 [153]"load(NULL)et's review for a moment.
  146. 1450 print"[215]hich answer is correct?
  147. 1460 [153]"   atn) (NULL)he computer and the disk drive
  148. 1470 print"      both use [158]file numbers[153] to keep
  149. 1480 [153]"      track of right$/(NULL) information.
  150. 1490 print"   [194]) [212]he computer and the disk drive
  151. 1500 [153]"      both use syschannel numbersprint to
  152. 1510 print"      keep track of [201]/[207] information.
  153. 1520 [153]"   len) (NULL)he computer uses sysfile
  154. 1530 print"      numbers[153] and the disk drive
  155. 1540 [153]"      uses syschannel numbersprint.
  156. 1550 getcg$:ifcg$=""goto1550
  157. 1560 if(cg$="c")or(cg$="[195]")goto1690
  158. 1570 if(cg$<>"a")and(cg$<>"[193]")and(cg$<>"b")and(cg$<>"[194]")goto1550
  159. 1580 print"[147][211]orry, that's not right.
  160. 1590 [153]"(NULL)hink of the computer as a filing
  161. 1600 print"cabinet[153].  [201]magine many little manila
  162. 1610 [153]"file folders inside the cabinet, and
  163. 1620 print"each one has its own [158]number[153].
  164. 1630 [153]"(NULL)here's a cableprint  connecting the disk
  165. 1640 print"drive to the computer, just like the
  166. 1650 [153]"cable connected to a tv set.  (NULL)ou
  167. 1660 print"select [158]channels[153] on the tv, and the[160]
  168. 1670 [153]"disk drive uses syschannelsprint to keep track
  169. 1680 print"of files.":gosub440:goto1440
  170. 1690 print"[147][210][201][199][200][212]!":print"[212]here are sixteen possible channels
  171. 1700 [153]"for each disk drive.  (NULL)hey are numbered
  172. 1710 print"0[153] through 15[153].
  173. 1720 [153]"   lenhannel               (NULL)urpose
  174. 1730 print"   [129][163][163][163][163][163][163][163]               [163][163][163][163][163][163][163]
  175. 1740 [153]"print      0                  sys(NULL)(NULL)atnstr$print only
  176. 1750 print"      1                  [158][211][193][214][197][153] only
  177. 1760 [153]"      2                   available
  178. 1770 print"      3                   available
  179. 1780 [153]"      :                   available
  180. 1790 print"      :                   available
  181. 1800 [153]"     14                   available
  182. 1810 print"     15                  [158]commands[153] only";
  183. 1820 print"   [206]ow, pick a channel number to use
  184. 1830 [158]q,24,0:[153]"--->        ";:[158]q,24,5
  185. 1840 ll[178]2:[141]210:[139]([197](xx$)[177]1)[175]([197](xx$)[179]15)[137]2010
  186. 1850 [139][197](xx$)[177]15[137]1830
  187. 1860 [139][197](xx$)[177]0[137]1920
  188. 1870 [153]"loadprintlenhannel 0print is used by the sysstr$(NULL)(NULL)print, (str$isk
  189. 1880 print"[207]perating [211]ystem) to [204][207][193][196] programs or
  190. 1890 [153]"the disk directory into the computer.
  191. 1900 print"[217]ou can't use it to create or read":print"[158][211][197][209][153] files.
  192. 1910 [141]440:[153]"load":[137]1690
  193. 1920 [139][197](xx$)[177]1[137]1960
  194. 1930 [153]"loadprintlenhannel 1print is used by the sysstr$(NULL)(NULL)print, (str$isk
  195. 1940 print"[207]perating [211]ystem) to [211][193][214][197] programs":print"from the computer.
  196. 1950 [153]"(NULL)ou can't use it to create or read":[153]"sys(NULL)val(NULL)print files.":[137]1910
  197. 1960 [153]"loadprintlenhannel 15print is used by the sysstr$(NULL)(NULL)print, (str$isk
  198. 1970 print"[207]perating [211]ystem) for receiving
  199. 1980 [153]"commands and sending information
  200. 1990 print"on disk drive errors to the computer.
  201. 2000 [153]"(NULL)ou can't use it to create or read":[153]"sys(NULL)val(NULL)print files.":[137]1910
  202. 2010 sa$[178]xx$:[153]"loadlist(NULL)(NULL)val(NULL) "fl$",8,"sa$
  203. 2020 [153]"print   left$ere's what the sys(NULL)(NULL)val(NULL)print command looks":[153]"like so far.
  204. 2030 print"   [215]e've told the computer to [207][208][197][206] file
  205. 2040 [153]"#"fl$"print and place in it the fact that
  206. 2050 print"we're going to use channel #"sa$"[153] on disk":print"device #8[153].
  207. 2060 [153]"   (NULL)ext, we need a name for the disk
  208. 2070 print"file we're going to create.":print"[197]nter a disk file name: ";
  209. 2080 ll=16:gosub200:df$=xx$
  210. 2090 print"[147][155][207][208][197][206]"fl$",8,"sa$","q$df$q$
  211. 2100 print"[153]   [212]o give the disk drive the  disk
  212. 2110 [153]"file name, we just add it to the (NULL)(NULL)val(NULL)
  213. 2120 print"command.  [196]on't forget the [158]"q$","q$"[153] after":print"the secondary address.
  214. 2130 [153]"   (NULL)ow we need to tell the disk drive
  215. 2140 print"that this is to be a sequential file.
  216. 2150 [141]440:[129]x[178]1029[164]1060:[139][194](x)[178]32[167]p[178]x:x[178]2000
  217. 2160 [130]:p[178]p[171]1025:[158]q,0,p:[153]"sys,s"q$
  218. 2170 [158]q,11,3:[153]"print(NULL)he sys,sprint tells the disk drive to create";
  219. 2180 [153]"a sys(NULL)val(NULL)printuential file.  (NULL)ote that the sys,s
  220. 2190 print"[205][213][211][212][153] be [201][206][211][201][196][197] the quote marks.
  221. 2200 [153]"   (NULL)ext, we have to tell the disk drive
  222. 2210 print"that we want to "q$"write to"q$"[153] the file,
  223. 2220 [153]"not "q$"read from"q$" it.
  224. 2230 gosub440:sysq,0,p:print"[155],s[158],w"q$
  225. 2240 sysq,19,3:print"[153][212]he [158],w[153] tells the disk drive to
  226. 2250 [153]"writeprint to the new file.":[141]440
  227. 2260 [153]"loadprint":[153]" thentab(tab(tab(tab(tab(tab(tab(tab(fn       thentab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(tab(fn
  228. 2270 print" [167]  [152][195]ptr[153]  [165]       [167]    [154][196]isk [196]rive[153] ( ) [165]
  229. 2280 [153]" thentotototototototofn       thentototototototototototototototototototofn
  230. 2290 print" [167]        [165]       [167]                   [165]
  231. 2300 [153]" then   - -  fn       then                   fn
  232. 2310 print" [167][164][164][164][164][164][164][164][164][165]       [167][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][180]
  233. 2320 [153]"   printleft$ere's what happens when you use the":[153]"(NULL)(NULL)val(NULL) command.":[141]440
  234. 2330 [153]"list(NULL)(NULL)val(NULL) "fl$"print
  235. 2340 sysq,13,3:print"[212]he computer looks through its list"
  236. 2350 print"of open files for one named [158]"q$fl$q$"[153].
  237. 2360 [153]"   right$f it doesn't find one, it makes one.":[141]440
  238. 2370 [158]q,6,5[171][195](fl$):[153]""fl$"print":[141]440
  239. 2380 [158]q,18,3:[153]"right$f it finds a file with that number,
  240. 2390 print"it prints [158]"q$"[198][201][204][197] [207][208][197][206] [197][210][210][207][210]"q$"[153] and your
  241. 2400 [153]"peekatn(NULL)right$len program stops.  right$f you try to open";
  242. 2410 [153]"more than 10print files, you'll get a
  243. 2420 print"[158]"q$"[212][207][207] [205][193][206][217] [198][201][204][197][211] [197][210][210][207][210]"q$"[153].":gosub440:gosub150
  244. 2430 print""tab(5+len(fl$))"[155],8,"sa$"[153]"
  245. 2440 gosub150:print"[206]ext, the device number and the
  246. 2450 [153]"secondary address are added to the file":[153]"information.
  247. 2460 gosub440:sysq,6,6:print"8"sa$"[153]":gosub440
  248. 2470 print"[155][207][208][197][206] "fl$",8,"sa$","q$df$",s,w"q$"[153]
  249. 2480 [158]q,14,3:[153]"(NULL)nce the computer file is open, the
  250. 2490 print"channel number and file name are sent":print"to the disk drive.":gosub440
  251. 2500 gosub380:sysq,5,19:print""sa$"-"df$
  252. 2510 sysq,6,25:print"[150]s,w":gosub440:print"
  253. 2520 [158]q,18,3:[153]"(NULL)he disk drive checks to see if a
  254. 2530 print"file with the same name is already on
  255. 2540 [153]"the disk.  right$t also makes sure that theclose
  256. 2550 print"channel is unused, and a [158]"q$"buffer"q$
  257. 2560 print"[153]is available to handle the file.":gosub440:gosub150
  258. 2570 print"[201]f an "q$"error"q$" occurs, the disk
  259. 2580 [153]"drive activity light begins to flash.":[141]440:[158]q,13,3
  260. 2590 [153]"right$f there's no error, the activity
  261. 2600 print"light comes on and stays on to indicate":print"an open file on the drive.
  262. 2610 [158]q,3,35:[153]"def*":[151]198,0
  263. 2620 [141]440:[141]400:[141]390:[141]150
  264. 2630 [153]"(NULL)ow we're ready to store some data
  265. 2640 print"in the sequential disk file.  [215]e'll use
  266. 2650 [153]"three stringsprint of characters.
  267. 2660 print"   [197]nter up to 12 alpha
  268. 2670 [153]"characters --->";:ll[178]12:[141]200:a$[178]xx$:[153]
  269. 2680 [153]"print   (NULL)e'll put this text in atn$print.":[141]440
  270. 2690 [141]400:[153]"atn$="a$:[141]440:[141]150
  271. 2700 [158]q,10,3:[153]"printvalnter up to 12 alpha characters
  272. 2710 print"for [194]$[153] --->";:ll=12:gosub200:b$=xx$
  273. 2720 gosub400:print"[194]$="b$:gosub440
  274. 2730 sysq,14,3:print"[153][193]nd last, enter up to 12 characters
  275. 2740 [153]"for len$print --->";:ll[178]12:[141]200:c$[178]xx$
  276. 2750 [141]400:[153]"len$="c$:[141]440:[141]150
  277. 2760 [141]400:[153]"(NULL)(NULL)right$(NULL)(NULL)#print":[158]q,10,3
  278. 2770 [153]"print(NULL)o send information to the sequential";
  279. 2780 [153]"file, we use the sys(NULL)(NULL)right$(NULL)(NULL)#print command.
  280. 2790 print"   [196]o [206][207][212][153] leave a space between the
  281. 2800 [153]"sys(NULL)(NULL)right$(NULL)(NULL)print and the sys#print!  right$t's all one "q$"word"q$".
  282. 2810 print"   [201]t will be easier to remember this
  283. 2820 [153]"command if you say "q$"(NULL)(NULL)right$(NULL)(NULL) ascright$(NULL)val"q$"print when
  284. 2830 print"you use it, because that's what it does.";
  285. 2840 print"   [201]t prints[153] to an open file[153].":gosub440
  286. 2850 sysq,0,0:sys59903:gosub150
  287. 2860 print"[198]irst, we'll send the data in [158][193]$[153] to
  288. 2870 [153]"the sequential file.":x[178]500:[141]370
  289. 2880 [153]"(NULL)(NULL)right$(NULL)(NULL)#"fl$", atn$":[141]380
  290. 2890 [158]q,5,19:[153]" "a$"print":x[178]1000:[141]370
  291. 2900 [158]q,13,3:[153]"(NULL)he disk drive places "a$
  292. 2910 [153]"printin the buffer it assigned to the file.":[141]440:[141]390
  293. 2920 [158]q,16,3:[153]"(NULL)ext, we'll send the data in syspeek$print.
  294. 2930 print"[208][210][201][206][212]#"fl$", [194]$":gosub440:gosub380
  295. 2940 sysq,5,19:print" "b$"[153]":gosub440
  296. 2950 sysq,18,3:print"[212]he data goes into the same buffer.
  297. 2960 [153]"   atn syslenleft$(NULL)$(13)print (the code for sys<(NULL)val(NULL)(NULL)(NULL)(NULL)>print) is";
  298. 2970 [153]"placed in the buffer after "a$
  299. 2980 [153]"printseparating it from "b$"print.":[141]440:[141]390
  300. 2990 [153]"(NULL)(NULL)right$(NULL)(NULL)#"fl$", len$   print":[141]150
  301. 3000 [153]"(NULL)ast, we'll send the data in syslen$print.":[141]440:[141]380
  302. 3010 [158]q,5,19:[153]" "c$"print":[141]440:[141]390:[141]400
  303. 3020 [158]q,12,3:[153]"(NULL)ow all the data has been sent to
  304. 3030 print"the disk drive.  [212]he last of the data
  305. 3040 [153]"is still in the sysbufferprint.  right$t hasn't been
  306. 3050 print"stored to disk yet.  [215]e can see that,
  307. 3060 [153]"because the activity light on the drive":[153]"is still lit.
  308. 3070 print"   [212]he [195][204][207][211][197][153] command is used to tell
  309. 3080 [153]"the computer and the disk drive that
  310. 3090 print"we're finished with the file.":gosub440:gosub150
  311. 3100 print"[195][204][207][211][197] "fl$"[153]":gosub380:sysq,10,3
  312. 3110 print"[193]ny data still in the [158]buffer[153] is":print"written to the disk.
  313. 3120 [153]"   (NULL)hen that's done, the activity light
  314. 3130 print"goes off.":gosub440:sysq,3,35:print" ":gosub390:sysq,16,3
  315. 3140 print"[204]ast, the computer [195][204][207][211][197]s[153] the file in";
  316. 3150 print"the file table, freeing the space for a":print"new file.":gosub440
  317. 3160 sysq,6,2:print"   - -  ":gosub400
  318. 3170 sysq,19,3:print"[193]nd, we're done!":gosub440:gosub150
  319. 3180 print"[217]ou can send [158]numeric[153] as well as
  320. 3190 [153]"sysstringprint variables.  ascor example:
  321. 3200 print"[208][210][201][206][212]#"fl$", [218]     [153](floating point)
  322. 3210 [153]"(NULL)(NULL)right$(NULL)(NULL)#"fl$", (NULL)%    print(integer)
  323. 3220 print"[208][210][201][206][212]#"fl$", "q$"[200]i"q$"  [153](literal)":gosub440:gosub150
  324. 3230 print"[212]he data you've stored could be names[153]";
  325. 3240 print"and addresses[153] for a database.  [201]t might
  326. 3250 [153]"be your deflocationprint in a maze game, so you
  327. 3260 print"can start from the same place again.
  328. 3270 [153]"   (NULL)r, it might be the sysnumbersprint from a
  329. 3280 print"checkbook balancing program.
  330. 3290 [153]"   right$n any case, the data is only useful
  331. 3300 print"to you if you can [158]read[153] it back into
  332. 3310 [153]"your program.":[141]440:[141]150
  333. 3320 [153]"(NULL)valatnstr$printing a sys(NULL)val(NULL)print file is almost the same";
  334. 3330 [153]"as creating one.
  335. 3340 print"   [215]e [207][208][197][206][153] a computer [158]file[153], and specify"
  336. 3350 print"the [158]device[153] and [158]secondary[153] adrress.":gosub440
  337. 3360 print"[155][207][208][197][206] "fl$",8,"sa$","q$df$q$"[157][158],s,r"q$
  338. 3370 sysq,6,5-len(fl$):print""fl$"[153]-8[153]-"sa$:sysq,16,3
  339. 3380 print"[153][215]e'll use the same file and channel"
  340. 3390 print"numbers.  [217]ou could use different ones.
  341. 3400 [153]"   (NULL)otice that this time we use a sys,rprint
  342. 3410 print"for [158][210][197][193][196][153] instead of a [158],w[153] after the":print"file name.":gosub440
  343. 3420 gosub150:print"[212]he [207][208][197][206][153] command causes the disk
  344. 3430 [153]"drive to check the directory for the
  345. 3440 print"named file.  [201]f found, it [158][207][208][197][206][153]s the
  346. 3450 [153]"file for sysreadprinting, and turns on the
  347. 3460 print"activity light.":gosub380:sysq,5,19:print""sa$"-"df$:sysq,6,25
  348. 3470 print"[150]s,r":sysq,3,35:print"[150]*":gosub440:gosub400:print"[201][206][208][213][212]#"fl$",
  349. 3480 [141]390:[158]q,16,3:[153]"print(NULL)o read the data, we use right$(NULL)(NULL)(NULL)(NULL)#print.  atns
  350. 3490 print"with [158][208][210][201][206][212]#[153], there's no space between
  351. 3500 [153]"right$(NULL)(NULL)(NULL)(NULL)print and #print.  (NULL)hinksys "q$"input file"q$"printwhen
  352. 3510 print"you use the command.":gosub440:print"[201][206][208][213][212]#"fl$", [193]$":gosub150
  353. 3520 print"[153][212]o read the data successfully, you
  354. 3530 [153]"must know the systypeprint, defsequenceprint, and sysnumberprint";
  355. 3540 [153]"of variables stored in the file.
  356. 3550 print"   [201]f you try to read a [158]string[153] into
  357. 3560 [153]"numeric variable, such as atnprint, you'll
  358. 3570 print"you'll get a [150][212][217][208][197] [205][201][211][205][193][212][195][200][153] error from
  359. 3580 [153]"peekatn(NULL)right$len.":[153]"   (NULL)ince we know that we've stored
  360. 3590 print"a [158]string[153] as the first variable, we'll
  361. 3600 [153]"use atn$print as the variable name for the
  362. 3610 print"[158][201][206][208][213][212]#[153] command.":gosub440:gosub150
  363. 3620 print"[215]hen the disk drive receives the
  364. 3630 [153]"sysright$(NULL)(NULL)(NULL)(NULL)#print command, it reads the data in the";
  365. 3640 [153]"file up to the syslenleft$(NULL)$(13)print, and sends
  366. 3650 print"it to the computer.":gosub440:gosub380:sysq,5,19:print""a$:gosub420
  367. 3660 gosub410:print"[201][206][208][213][212]#"fl$", [193]$ [158] <-- [193]$="a$:gosub440:gosub390:sysq,15,3
  368. 3670 print"[153][217]our program can now use the value
  369. 3680 [153]"in atn$print in any way you choose.":[141]440:[141]400:[141]150
  370. 3690 [153]"(NULL)e get the two remaining strings in
  371. 3700 print"the same way.  [206]ote that the [158]name[153] of
  372. 3710 [153]"the variable doesn't matter, as long as
  373. 3720 print"the type[153] is correct.":gosub440:print"[201][206][208][213][212]#"fl$", [216]$":gosub380:gosub390
  374. 3730 sysq,5,19:print""b$:gosub410:print"[201][206][208][213][212]#"fl$", [216]$ [158] <-- [216]$="b$:gosub440
  375. 3740 gosub400:print"[201][206][208][213][212]#"fl$", [209][209]$":gosub380:gosub390
  376. 3750 sysq,5,19:print""c$:gosub410:print"[201][206][208][213][212]#"fl$", [209][209]$ [158] <-- [209][209]$="c$:gosub440
  377. 3760 gosub400:gosub390:print"[195][204][207][211][197] "fl$:sysq,15,3
  378. 3770 print"[153][212]he [158][195][204][207][211][197][153] command closes the file
  379. 3780 [153]"on the disk drive and removes the
  380. 3790 print"computer file from the file table.":gosub440:gosub380:sysq,3,35:print" "
  381. 3800 x=500:gosub370:gosub390:sysq,6,2:print"   - -  ":gosub400:gosub440
  382. 3810 gosub400:gosub150:print"[153][207]ne possible problem with using
  383. 3820 [153]"sysright$(NULL)(NULL)(NULL)(NULL)#print is the deflengthprint of strings that
  384. 3830 print"may be stored on the disk.  [211]trings can
  385. 3840 [153]"be up to 255print characters long.
  386. 3850 print"   [217]ou [158]concatenate[153] or [150]add[153] strings
  387. 3860 [153]"together to get longer strings.":[153]"(NULL)$=atn$+peek$+len$+str$$: (NULL)(NULL)right$(NULL)(NULL)#"fl$", (NULL)$
  388. 3870 gosub440:sysq,20,3:print"[153][201]f [158][193]$[153], [158][194]$[153], [158][195]$[153], and [158][196]$[153] are each
  389. 3880 [153]"60print characters long, sys(NULL)$print will have a
  390. 3890 print"length of [150]240[153]!":gosub440:gosub150
  391. 3900 print"[158][201][206][208][213][212]#[153] has a limit of 80[153] characters.
  392. 3910 [153]"(NULL)hat's because the computer reads the
  393. 3920 print"data from the disk into the same memory
  394. 3930 [153]"area that's used for screenprint input.
  395. 3940 print"   [212]his memory area, or [158]buffer[153] holds
  396. 3950 [153]"only 80print characters, since that's the
  397. 3955 print"maximum size of a [150][195]64[153] screen line.
  398. 3960 [153]"((NULL)r 160print characters on a deflen128print).":[141]440:[158]q,19,3
  399. 3970 [153]"(NULL)o, how do we sysreadprint a file if we
  400. 3980 print"don't know how big the strings are, or
  401. 3990 [153]"how sysmanyprint there are?":[141]440:[153]"chr$val(NULL)#"fl$:[141]150
  402. 4000 [153]"print(NULL)e use the chr$val(NULL)#print (sysget fileprint) command.
  403. 4010 print"   [201]t's similar to [158][201][206][208][213][212]#[153] because it
  404. 4020 [153]"retrieves data from an open sysfileprint.
  405. 4030 print"   [201]t's also similar to [150][199][197][212][153], because it
  406. 4040 [153]"retrieves only defoneprint character at a time.":[141]440:[141]150
  407. 4050 [153]"chr$val(NULL)#print should only be used with a
  408. 4060 print"[158]string[153] variable name.":print"   [212]o make a [158]string[153] in computer
  409. 4070 [153]"memory using chr$val(NULL)#print, you have to defassembleprint
  410. 4080 print"the string character by character.":gosub440:gosub400
  411. 4090 sysq,6,5-len(fl$):print""fl$"8"sa$
  412. 4100 gosub150:print"[157][157][157]100 [216][216]$="q$q$": [150][210][197][205] [195][204][197][193][210] [216][216]$
  413. 4110 [153]"110 chr$val(NULL)#"fl$", atn$: (NULL)=(NULL)(NULL)
  414. 4120 print"120 [201][198] [193]$="q$q$" [212][200][197][206] [193]$=[195][200][210]$(0)
  415. 4130 [153]"130 right$asc atn$=lenleft$(NULL)$(13) chr$(NULL)(NULL)(NULL) 200
  416. 4140 print"140 [216][216]$=[216][216]$+[193]$
  417. 4150 [153]"150 right$asc (NULL)=0 chr$(NULL)(NULL)(NULL) 110
  418. 4160 print"200 [150][210][197][205] [208][210][207][199][210][193][205] [195][207][206][212][201][206][213][197][211]
  419. 4170 [153]"   printleft$ere's a program that defassembles
  420. 4180 print"[216][216]$[153] from a disk data file.  [204]et's see
  421. 4190 [153]"how it works.":[141]440:x[178]18:[141]160
  422. 4200 [153]"start -->  (NULL)(NULL)$="q$q$"  sys(null)print":[158]q,18,3
  423. 4210 [153]"   (NULL)ine 100print clears (NULL)(NULL)$print by making it
  424. 4220 print"[158]null[153], equal to nothing."
  425. 4230 print"   [212]hen we start reading the information";
  426. 4240 print"on the disk drive.":sysq,5,19:print"[213][208][212][201][205][197][158]r[146]"
  427. 4250 sysq,6,25:print"[158]^[164][164][195][200][210]$(13)":gosub440:x=18:gosub160:sysq,18,3
  428. 4260 print"[212]he string in this disk file is the
  429. 4270 [153]"name (NULL)(NULL)(NULL)right$(NULL)valprint followed by the sys<(NULL)val(NULL)(NULL)(NULL)(NULL)>print
  430. 4280 print"character.":print"   [204]ine 110[153] [150]get[153]s the first character
  431. 4290 [153]"and puts it in the variable atn$print.":[141]440:[141]380:[141]420:[141]410
  432. 4300 [153]"pass 1 ->  (NULL)(NULL)$="q$q$;:[153]"  sys(atn$=(NULL))":[158]q,5,19:[153]" ":[141]440
  433. 4310 [141]420:x[178]18:[141]160:[158]q,18,3:[153]"print(NULL)ine 110print also sets the variable sys(NULL)"
  434. 4320 [153]"printequal to the reserved variable sys(NULL)(NULL)print.
  435. 4330 print"   [215]e'll see what that does in a moment.":gosub440:x=18:gosub160
  436. 4340 sysq,18,3:print"[204]ine 120[153] checks for a [150]bug[153] in the [158][199][197][212]#[153]";
  437. 4350 print"command.  [201]f the character in the file
  438. 4360 [153]"is a defbinaryprint zero (not the sysatn(NULL)lenright$right$print
  439. 4370 print"character 0[153]), [158][199][197][212]#[153] returns a null":print"string.":gosub440:x=18:gosub160
  440. 4380 sysq,18,3:print"[211]o, we test for the null string, and
  441. 4390 [153]"if we find one, change it to syslenleft$(NULL)$(0)print.":[141]440:x[178]18:[141]160
  442. 4400 [158]q,18,3:[153]"(NULL)ine 130print checks to see if we're at
  443. 4410 print"the end of the string, [158][193]$=[195][200][210]$(13)[153].  [201]f
  444. 4420 [153]"we are, (NULL)(NULL)$print is complete, and we go on
  445. 4430 print"with the program.":gosub440:x=18:gosub160:sysq,18,3
  446. 4440 print"[204]ine 140[153] adds the value in [158][193]$[153] to
  447. 4450 [153]"(NULL)(NULL)$print.":[141]440
  448. 4460 [153]"pass 1 ->  (NULL)(NULL)$="q$"(NULL)"q$;:[153]"  sys(atn$=(NULL))":[158]q,5,19:[153]" ":[141]440
  449. 4470 x[178]18:[141]160:[158]q,18,3:[153]"(NULL)(NULL)print is a special variable reserved by
  450. 4480 print"[194][193][211][201][195] to hold information about [158][201]/[207][153] or
  451. 4490 [153]"input/output activity.   (NULL)hile we're
  452. 4500 print"successfully reading through a disk file";
  453. 4510 print"[211][212][153] will have a value of [158]zero[153].":gosub440
  454. 4520 x=18:gosub160:sysq,18,3:print"[193]s soon as we read the last character";
  455. 4530 print"in the file, [211][212][153] changes its value to
  456. 4540 [153]"sys64print.  (NULL)ine 150print checks variable (NULL)print, which
  457. 4550 print"we've set equal to [211][212][153].  [201]f it's still
  458. 4560 [153]"syszeroprint, we're not at the end of the file.":[141]440:x[178]18:[141]160
  459. 4570 [158]q,18,3:[153]"(NULL)ow we'll syschr$val(NULL)#print the rest of the":[153]"string.":[141]440
  460. 4580 [131] "(NULL)","(NULL)(NULL)","(NULL)","(NULL)(NULL)(NULL)","right$","(NULL)(NULL)(NULL)right$","(NULL)","(NULL)(NULL)(NULL)right$(NULL)","val","(NULL)(NULL)(NULL)right$(NULL)val"
  461. 4590 [129]z[178]2[164]6:[141]380:[141]420:[141]410
  462. 4600 [135]z$,zz$:[153]"pass"z"->  (NULL)(NULL)$="q$zz$q$;
  463. 4610 [153]"  sys(atn$="z$")":[158]q,5,18[170]z:[153]" ":[141]420:x[178]700:[141]370:[130]
  464. 4620 [141]380:[141]420
  465. 4630 [141]410:[153]"pass 7 ->  (NULL)(NULL)$="q$zz$q$;:[153]"  sys(atn$=lenleft$(NULL)$(13))":[141]390:[141]440
  466. 4640 [141]400:[141]150:[153]"(NULL)ou can use syschr$val(NULL)#print and sys(NULL)(NULL)print to read and
  467. 4650 print"print to the screen any sequential file:":print"250 [199][197][212]#101,[193]$
  468. 4660 [153]"260 (NULL)(NULL)right$(NULL)(NULL) atn$;  print<--don't forget the sys;
  469. 4670 print"270 [201][198] [211][212]=0 [199][207][212][207] 250":gosub440
  470. 4680 print"[147][153]   [211]o far we've assumed that there were
  471. 4690 [153]"no sysdisk errorsprint as we worked with files.
  472. 4700 print"   [201]n the real world, things won't be
  473. 4710 [153]"quite so error free.  (NULL)ou may get a
  474. 4720 print"[158][198][201][204][197] [206][207][212] [198][207][213][206][196][153] or [158][196][210][201][214][197] [206][207][212] [210][197][193][196][217][153]
  475. 4730 [153]"error.":[153]"   (NULL)he disk drive sends error messages
  476. 4740 print"in this format:":print"62  [198][201][204][197] [206][207][212] [198][207][213][206][196]  18  00"
  477. 4750 print "[153]   [212]he [158]"q$"62"q$"[153] is the [150]error number[153].  [217]ou'll";
  478. 4760 print"find the possible error numbers listed
  479. 4770 [153]"in your disk drive manual.  (NULL)he number
  480. 4780 print"is followed by a [158]string[153] that describes
  481. 4790 [153]"the error.":[153]"   (NULL)he last two numbers are the track
  482. 4800 print"and sector numbers where the [158]error[153]
  483. 4810 [153]"occured.":[141]440:[153]"load   (NULL)ou should always check for errors
  484. 4820 print"when working with disk files.  [212]o do
  485. 4830 [153]"that, sys(NULL)(NULL)val(NULL)print a file to the syscommand
  486. 4840 print"channel[153] on the disk drive [194][197][198][207][210][197][153] you
  487. 4850 [153]"(NULL)(NULL)val(NULL) defanyprint other files!":[153]"100 (NULL)(NULL)val(NULL) 15,8,15
  488. 4860 print"[153]   [208]rogrammers usually use [158]computer
  489. 4870 [153]"file #15print.  (NULL)ou mustprint use sysdisk channel
  490. 4880 print"#15[153], the command channel.":print"   [212]hen, after you [207][208][197][206] a file, read
  491. 4890 [153]"the command channel:":[153]"150 right$(NULL)(NULL)(NULL)(NULL)#15, (NULL), (NULL)$"
  492. 4900 [153]"160 right$asc (NULL)>19 (NULL)left$val(NULL) (NULL)(NULL)right$(NULL)(NULL) (NULL)$: len(NULL)(NULL)(NULL)val15: val(NULL)str$":[141]440:[158]q,18,3
  493. 4910 [153]"str$isk errors start with sys20print, so any
  494. 4920 print"number less than [158]20[153] means it's all
  495. 4930 [153]"right to continue.  (NULL)hen you end your
  496. 4940 print"program, [158][195][204][207][211][197] 15[153] last, since closing
  497. 4950 [153]"the command channel closes all others.":[141]440
  498. 4960 [153]"load   (NULL)e've just hinted at the things you
  499. 4970 print"can do creating and reading disk files.
  500. 4980 [153]"   (NULL)n this sys(NULL)p(NULL)imeprint disk, you'll find
  501. 4990 print"[198][201][204][197] [210][197][193][196][197][210][153], which uses the techniques
  502. 5000 [153]"we've looked at here.  (NULL)ou can def(NULL)right$(NULL)(NULL)print and
  503. 5010 print"change it to suit your needs.":print"   [201]f you'd like to learn more about
  504. 5020 [153]"creating and using disk files, look for
  505. 5030 print"     1541 [213][211][197][210]'[211] [199][213][201][196][197]":print"       by [196]r. [199]erald [206]eufeld":print"      ([194]rady)
  506. 5040 [153]"print   (NULL)he book should be available through
  507. 5050 print"any major bookstore.":print"   [215]e hope you've had fun seeing how to
  508. 5060 [153]"make sysdisk filesprint work for you!":[158]q,23,3
  509. 5070 [153]"list (NULL)ress atn(NULL)(NULL) key to return to (NULL)p(NULL)ime ":[146]198,1:[137]490
  510.