home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 10 / Commodore_Free_Issue_10_2007_Commodore_Computer_Club.d64 / t.programming < prev    next >
Text File  |  2023-02-26  |  18KB  |  609 lines

  1. u             Programming
  2. The Great Adventure of Creativity
  3.               and Logic
  4.            by Dave Moorman
  5.  
  6. Come with us as we enter a strange
  7. world of symbolic logic. Process
  8. Logic, to be exact. If you do those
  9. logic problems found in puzzle
  10. magazines, you know Classic Logic. If
  11. you found Geometry enjoyable in high
  12. school, you know Proof Logic. And if
  13. you studied philosophic logic in
  14. college, you are aquainted with
  15. Symbolic Logic.
  16.  
  17. Process Logic is a combination of
  18. Proof Logic and Symbolic Logic -- plus
  19. three wonderful additional features.
  20. Like Proof Logic, you will be
  21. arranging statements and commands in a
  22. particular order -- not to prove some
  23. truth, but to affect some action in
  24. the computer. In the process, you will
  25. use Symbolic Logic to manipulate
  26. values.
  27.  
  28. The three additional features are
  29.  
  30. 1. symbolic value holders(called
  31. variables and arrays) 2. loops 3.
  32. conditional commands. It is the
  33. ability to make conditional changes in
  34. the flow of logic that gives a
  35. computer its ability to "think."
  36.  
  37. The C-64 includes a built in BASIC
  38. interpreter. Computers are controlled
  39. with three types of language. At its
  40. very heart, the computer processor
  41. recognizes certain values as
  42. "instructions." This is built into the
  43. machine itself, and is called Machine
  44. Language. EVERYTHING the computer does
  45. is really done by means of ML.
  46.  
  47. ML is nothing but numbers, that is,
  48. numeric values. Remembering such
  49. values and the tasks they perform can
  50. be extremely difficult for humans. We
  51. need at least some easily recognizable
  52. code "words" to remind us about what
  53. is going on. The ML programmer writes
  54. these "words" and the computer uses a
  55. program to ASSEMBLE that code into ML
  56. -- which is what the computer actually
  57. understands. The code the programmer
  58. writes is called ML, or more
  59. correctly, Assembly Source Code.
  60.  
  61. But a computer can be smarter than
  62. that. Assembly ML source code has a
  63. one-to one relationship with the code
  64. the computer understands. Each
  65. instruction does one and only one very
  66. small task. Keeping it all straight
  67. can be quite frustrating.
  68.  
  69. However, the computer can be
  70. programmed to read words, numbers, and
  71. other characters and translate them
  72. into complex groups of ML
  73. instructions. Such alanguage is called
  74. Compiled. The program that translates
  75. Compiler Code into ML Code is called a
  76. Compiler. A compiler compiles an
  77. entire program or routine at a time.
  78. If the programmer has made a mistake
  79. the compiler cannot understand, it
  80. reports errors -- but only after
  81. chugging through the whole source
  82. code. So the programmer writes,
  83. compiles, debugs, recompiles,
  84. executes, rewrites, recompiles, etc,
  85. etc. This is an arduous task, to say
  86. the least. It was even more
  87. frustrating back in the 1960's when
  88. the programmer had to punch cards with
  89. each line of the program and take the
  90. "batch" to the computer room. The
  91. operator would run the batch and
  92. return a paper print-out to the
  93. programmer in a few hours. Or days!
  94.  
  95. At that time, computers (big
  96. mainframes) were finally becoming
  97. fairly fast and powerful. A terminal
  98. could be directly connected to the
  99. computer so the programmer did not
  100. have to wait. But the computer then
  101. did a lot of waiting for the
  102. programmer's input. The concept of
  103. time-sharing was developed, where the
  104. computer could switch between many
  105. different terminals, running different
  106. programs at apparently the same time.
  107.  
  108.  To take advantage of time sharing and
  109. to provide a language that was easy
  110. for students to learn and use, BASIC
  111. (standing for Beginner's All Purpose
  112. Symbolic Instruction Code) was written
  113. (invented) in 1963, at Dartmouth
  114. College, by mathematicians John George
  115. Kemeny and Tom Kurtzas. The commands
  116. and math the programmer typed looked
  117. enough like English, making reading
  118. the code relatively easy.
  119.  
  120. But the big advantage of BASIC was
  121. that it was -- and is -- an
  122. Interpreted Language. During the
  123. user's tiny slice of processor time, a
  124. single BASIC statement would be read,
  125. turned into the ML Code necessary to
  126. execute the command, and processed.
  127. Then the processor turned to another
  128. terminal and program to process. On
  129. the BASIC program's next turn, the
  130. next BASIC statement would be
  131. interpreted and executed.
  132.  
  133. The great thing about an interpreted
  134. language like BASIC is that the
  135. program runs until an error occurs.
  136. Then it stops and delivers an error
  137. message. The programmer can fix the
  138. error and rerun the program. This made
  139. BASIC very interactive. The programmer
  140. did not have to get everything right
  141. before seeing how at least SOME of the
  142. program performed. In December of
  143. 1974, the January issue of Popular
  144. Electronics published news about the
  145. first home computer -- the Altair
  146. 8800. Two Harvard students, Paul Allen
  147. and Bill Gates saw the magazine -- and
  148. their future. They dropped out of
  149. college and rushed to Albuquerque, NM,
  150. where the Altair was being built.
  151.  
  152. They realized that these home
  153. computers needed an "operating system"
  154. -- a simple way for users to interact
  155. with the machine. Bill Gates wrote
  156. Altair BASIC using a mainframe
  157. computer with an emulator that made it
  158. act like the Intel 8008 microprocessor
  159. used by the Altair. His BASIC included
  160. ML code to read the keystrokes and put
  161. the BASIC program into memory. Other
  162. code would read BASIC commands and
  163. jump to ML routines that performed
  164. them. The whole thing fit in just 4
  165. kilobytes of memory (which doesn't
  166. seem like much today, but was rather
  167. expensive at the time) .
  168.  
  169. Gates and his newly founded company --
  170. MicroSoft -- went on to write BASIC
  171. for nearly every home computer. BASIC
  172. 2 used about 16K of memory, but was
  173. remarkably powerful. Most anything a
  174. programmer wanted to do could be done
  175. in BASIC. True -- it was slower than
  176. straight ML. But is was easy to learn,
  177. faster to write, and more-or-less
  178. portable between different makes of
  179. computers.
  180.  
  181. When in 1978 Commodore Business
  182. Machines produced the Personal
  183. Electronic Transactor -- the PET --
  184. they turned to Microsoft for BASIC.
  185. Commodore CEO Jack Tramiel bought
  186. BASIC 2.0 outright for $10,000 from
  187. cash-strapped Microsoft.
  188.  
  189. So, in the fall of 1981 when Commodore
  190. designed the C-64, they already owned
  191. the BASIC 2.0 operating system. The
  192. C-64 has color video and other
  193. features for which BASIC 2.0 had no
  194. commands. But that was OK. Game
  195. designers would certainly use fast ML
  196. for their code. And BASIC 2.0 has
  197. commands which can directly read or
  198. write information to places in memory
  199. that will control these features.
  200.  
  201. On the up side, the C-64 was designed
  202. to be modified with ML code. Though
  203. BASIC 2.0 was in Read Only Memory
  204. (ROM) and could not be changed,
  205. certain critical jump locations were
  206. in Random Access Memory (RAM -- which
  207. can be altered). By changing the jump
  208. addresses, a programmer could add new
  209. commands to BASIC and perform all
  210. sorts of miracles the designers never
  211. dreamed of. The designers did include
  212. "paddle controls" for then-popular
  213. games like Break Out. These controls
  214. proved perfect for adding a mouse. All
  215. in all, a C-64 was a fantastic machine
  216. in 1982 when it was unveiled at the
  217. January Consumer Electronics Show in
  218. Las Vegas. Its capabilities --
  219. especially as a "game machine," and
  220. its incredible price that dropped to
  221. less than $200 in 1994, kept it in
  222. production through 1992. Over its
  223. decade of manufacture, some 27 million
  224. units were sold, making the C-64 the
  225. "Best Selling Computer of the 20th
  226. Century," according to the revered
  227. Guinness Book of World Records (2000
  228. 2001) .
  229.  
  230. In the late 1990's, PC programmers who
  231. loved the C-64 began writing emulators
  232. to allow a PC to run C-64 programs.
  233. The best of these, the Versatile
  234. Commodore Emulator, continued to be
  235. improved until it brings an almost
  236. perfect C-64 to the world of Windows.
  237. With VICE, all the great games
  238. published over the years on LOADSTAR
  239. are now at your finger tips. And to
  240. top of a remarkable (if often ignored)
  241. history, a C-64 Direct-to-TV game
  242. joystick was marked in 2004 through
  243. QVC, the shopping channel. Over
  244. 200,000 unites were sold between
  245. Thanksgiving and Christmas.
  246.  
  247. Thanks to the designer -- Jeri
  248. Ellsworth -- the computer inside the
  249. joystick is a real, honest-to-goodness
  250. C-64. With nine wires soldered to the
  251. credit-card sized board, a user can
  252. connect a PS2 keyboard, Commodore disk
  253. drive, and an external power
  254. supply.The Commodore 64 - more than
  255. any other first-generation, 8-bit
  256. computer -- has proved itself as THE
  257. computer for gamesters and hobbyist
  258. programmers all over the world.
  259.  
  260. INSIDE the C-64 Every computer has
  261. three essential parts
  262.  
  263. 1. A processor which executes ML
  264. instructions and does math and logic
  265. operations. 2. Input/Output
  266. capabilities -- for keyboard, mouse,
  267. joystick, printers, and disk drives.
  268. 3. Memory -- "itty-bitty boxes" called
  269. bytes which can each hold a value of 0
  270. through 255.
  271.  
  272. Today's computers can handle up to 8
  273. bytes at a time, making them
  274. incredibly fast. Such speed is
  275. necessary for processing sound
  276. recording, photo-quality images, and
  277. real-time videos.
  278.  
  279. The first generation computers (such
  280. as the C-64) had processors that could
  281. handle only one byte at a time. A byte
  282. is composed of eight bits -- little
  283. switches which are on or off, 1 or 0
  284. -- hence these are called "8-bit
  285. computers." A two-byte value is used
  286. to point to a particular byte in
  287. memory, which means that an 8-bit
  288. computer is limited to 256 x 256 or
  289. 65536 bytes of memory. One kilobyte is
  290. actually 1024 bytes, so 65536/1024
  291. equals 64. Thus the name Commodore 64.
  292. But the C-64 has more than 64K of
  293. memory. The ROM which holds all the ML
  294. code to make BASIC wois "banked" on
  295. top of RAM. By "flipping" certain bits
  296. in the computer, an ML programmer can
  297. set ROM aside and use the RAM
  298. "underneath. "
  299.  
  300. As mentioned before, even though BASIC
  301. 2.0 is powerful, ML programmers have
  302. created a number of BASIC extensions
  303. and ML modules to add features for
  304. BASIC programmers. In 2004, LOADSTAR
  305. featured DotBASIC which adds 72
  306. commands to BASIC
  307.  
  308. 2.0 -- including full mouse control
  309. and Event Driven programming. Other
  310. modules play music and sound effects
  311. in the background, enable easy access
  312. to bitmap graphics, and even let
  313. ordinary BASIC programmers operate
  314. sprites (movable screen objects) and
  315. do split screen effects. THE
  316. LIMITATIONS The 6510 microprocessor in
  317. the C-64 operates at 1 megahertz
  318. (millions of cycles per second) --
  319. which is slow compared to the 8+
  320. Gigahertz (billions of cycles per
  321. second) Pentiums now on the market.
  322. However, 1Mhz is still 1,000,000 clock
  323. cycles per second (not slow, really)
  324. and 6510 ML instructions are quite
  325. efficient compared to Pentium
  326. instructions. The screen is comprised
  327. of 60,000 pixels -- 320 x 200. In
  328. multi-color mode, two bits determine
  329. which of four colors will be displayed
  330. as double-wide pixels (160 x 200). The
  331. result is a bit grainy.
  332.  
  333. Text characters are all 8 x 8 pixels
  334. in size, and can display the character
  335. "cell" color or the background color.
  336. In multi-color text mode, double-wide
  337. pixels can present the character color
  338. or one of three "universal" colors.
  339. The font includes 256 characters, but
  340. the programmer is not limited to the
  341. two built-in fonts. With a font
  342. editor, one can design characters as
  343. any 8 x 8 combination of pixels.
  344. Moreover, the programmer has eight 24
  345. x 21 pixel sprites -- movable objects
  346. -- that can be designed and displayed
  347. anywhere without disrupting the
  348. screen. The whole screen can be
  349. nudged, pixel by pixel, in any
  350. direction, enabling smooth scrolling
  351. effects -- especially when combined
  352. with split screen capabilities.
  353.  
  354. Sound is limited to three synthesized
  355. voices. The synthesizer has only
  356. Attack, Decay, Sustain, and Release
  357. envelope parameters, but does include
  358. various filters and resonance
  359. settings. Waveforms include noise,
  360. sawtooth, triangle, and adjustable
  361. pulse. And, with some cleverness,
  362. 4-bit recorded sound can be recorded
  363. and played by the computer.
  364.  
  365. So while the C-64 has certain limits,
  366. it is crafted in such a way that truly
  367. capable programmers can accomplish
  368. most anything computational. I have
  369. seen real-time three-dimensional
  370. displays (like DOOM, only very low
  371. resolution), the MGM Lion roar, and
  372. hundreds of other truly amazing sound
  373. and video effects. But most important,
  374. anything one can do on any computer
  375. can be at least MODELED on the C-64.
  376. The model may be rough, but the
  377. concepts, skills, and personal
  378. satisfaction in accomplishing effects
  379. are the same as with a big computer.
  380.  
  381. The day may come when you will want to
  382. tackle C, C++, C#, Java, Java Script,
  383. Perl, or Visual Basic on a PC.
  384. EVERYTHING conceptual and logical
  385. learned on the C-64 will apply to any
  386. other computer or language.
  387.  
  388. The C-64 is where one starts -- as did
  389. thousands of today's professional
  390. software designers. And hundreds of
  391. hobbyist programmers still find enough
  392. challenge to sit up all hours of the
  393. night hunching over their C-64s,
  394. fixing just one more thing!
  395.  
  396. ON TO BASIC 2.0
  397.  
  398.  When you turn on the C-64 (or launch
  399. VICE), the screen displays some title
  400. information, then presents the word
  401. READY.
  402.  
  403.  READY? Ready for what?
  404.  
  405.  Ready for anything you want to do!
  406. Type:
  407.  
  408.  PRINT "HELLO"
  409.  
  410. and press <RETURN>. (On VICE, the
  411. double-quotes are <Shift-2>, and
  412. <RETURN> is the <ENTER> key. )
  413.  
  414. The computer immediately complies --
  415. printing to the screen:
  416.  
  417.  HELLO
  418.  
  419.  Type: ? 5 + 7 * 10
  420.  
  421. (VICE: the plus is the <=> key, the
  422. asterisk is the <]> key.) (Remember to
  423. press the <RETURN> which tells the
  424. C-64 to go ahead and do it. )
  425.  
  426.  75 The question mark is short for
  427. PRINT. In the first example, you
  428. printed a STRING, a group of
  429. characters in order. You marked off
  430. the beginning and end of the string
  431. with double-quotes.
  432.  
  433. In the second example, you printed
  434. numeric values, multiplied and added
  435. according to mathematic rules
  436. (multiply and divide are performed
  437. first, followed by addition and
  438. subtraction). Both of these examples
  439. are examples of Immediate Mode. The
  440. C-64 immediately responded to your
  441. commands when the <RETURN> was
  442. pressed.
  443.  
  444.  Now Type:
  445.  
  446. 10 ? "HELLO"
  447.  
  448.  20 ? 5 + 7 * 10
  449.  
  450. (pressing <RETURN> at the end of each
  451. line) .
  452.  
  453. Nothing happened -- at least not
  454. obviously. But inside the C-64 a lot
  455. has taken place. Type:
  456.  
  457.  LIST
  458.  
  459. and the lines appear again. You have
  460. written these lines in Program Mode.
  461. The difference between Immediate Mode
  462. and Program Mode is very simple - If
  463. a NUMBER comes first in the line, the
  464. line is put in Program Memory. You
  465. can look at the program with LIST. If
  466. a command comes first, the line is in
  467. Immediate Mode and processed
  468. immediately.
  469.  
  470.  To run your program, Type:
  471.  
  472.  RUN
  473.  
  474. Wonderful! You have written your first
  475. program! The number you use at the
  476. beginning of a Program line determines
  477. where that line occurs in the program.
  478. Type:
  479.  
  480.  15 ? "WORLD"
  481.  
  482. and LIST
  483.  
  484.  10 PRINT "HELLO"
  485. 15 PRINT "WORLD"
  486. 20 PRINT 5 + 7 * 10
  487.  
  488. Since every program line must have a
  489. number and will be ordered by its
  490. number, it is a good idea to use 10's
  491. as you start writing your program.
  492. Then, if you want to tuck something in
  493. between two existing lines, you can --
  494. just like you just did.
  495.  
  496. VARIABLES A variable is a "box" that
  497. contains something. Each variable has
  498. a name, comprised of one or two
  499. letters or a letter and a number.
  500. Longer variable names are OK (unless
  501. they contain a BASIC command word),
  502. but the computer will not "see" more
  503. than the first two characters.
  504.  
  505.  Let's wipe out your first program.
  506. Type:
  507.  
  508.  NEW and LIST
  509.  
  510.  It's gone. Now Type:
  511.  
  512. 10 A1$ = "HELLO"
  513. 20 A2$ = "WORLD"
  514. 30 A1 = 5
  515. 40 A2 = 7
  516. 50 A3 = 10
  517. 100 ? A1$ + A2$
  518. 110 ? A1 + A2 * A3
  519. 120 END
  520.  
  521.  We have two types of data -- string
  522. and numeric. So we have two types of
  523. variables -- string and numeric. A
  524. string variable has a dollar sign
  525. after the one or two characters. A
  526. numeric variable doesn't. String
  527. variables cannot be part of a math
  528. formula -- but a plus sign will string
  529. two or more strings together. A
  530. numeric variable cannot be strung onto
  531. a string -- but they can be part of a
  532. math formula.
  533.  
  534.  The C-64 has the greatest programming
  535. interface ever put on an 8-bit
  536. computer. If you want to change a
  537. program line, all you have to do is
  538. put the line on the screen (with
  539. LIST), move your cursor up to it, type
  540. your changes onto the line, and press
  541. <RETURN>. To list one line, include
  542. the line number after the LIST
  543. command:
  544.  
  545.  LIST 100
  546.  
  547. Other list possibilities include:
  548.  
  549.  LIST -100 list everything up to line
  550. 100 LIST 100-list line 100 and
  551. everything after LIST 30-50 list all
  552. line from 30 to 50  As a list is
  553. scrolling, you can slow it down by
  554. pressing the <CTRL> key (<TAB> for
  555. VICE), or stop it by pressing <STOP>
  556. (<ESC> for VICE) .
  557.  List line 100:
  558. 100 PRINT A1$ + A2$
  559.  
  560. and change it to
  561. 100 PRINT A1$ + ", " + A2$
  562.  
  563. Press <RETURN> then RUN the program.
  564.  
  565.  Play around with this program for a
  566. while! Try all sorts fo things. You
  567. can print strings and numerics
  568. together on the same line:
  569.  
  570.  100 PRINT A1$ + ", " + A2$; A1 + A2,
  571. A3
  572.  
  573.  Use a semicolon to separate stuff
  574. you print. Use a comma to tab items
  575. to columns.
  576.  
  577.  Try this:
  578. 90 T = A1 + A2 * A3 95 ? T;
  579.  
  580. and run the program. Or do this: 80
  581. A1$ = A1$ + A1$ 85 A2$ = A2$ + A1$
  582.  
  583.  Try every combination of variables
  584. and print you can think of. It is YOUR
  585. program. And there is nothing you can
  586. do from the keyboard that will hurt a
  587. C64! NOTHING!
  588.  
  589. ABOUT ERRORS You have surely seen
  590. some errors by now. Two things about
  591. errors:
  592.  
  593. 1. The program stops short at any
  594. error, and 2. The C-64 always says
  595. READY. after an error. List the line
  596. and try to figure out what is wrong.
  597. SYNTAX means that something you typed
  598. is incomprehensible to the stupid
  599. machine. Fix it! Then try again.
  600.  
  601. [This is just the beginning! Do take
  602. time to play with all the concepts
  603. presented. Only with play will you
  604. learn how to apply the commands to
  605. your program.
  606.  
  607.  
  608. ...end...
  609.  
  610.