home *** CD-ROM | disk | FTP | other *** search
- u
- P R O G R A M M I N G
-
- The Great Adventure of
- Creativity and Logic
- by Dave Moorman
-
-
- We are entering into a strange
- world of symbolic logic. Process
- Logic, to be exact. If you do those
- logic problems found in puzzle
- magazines, you know Classic Logic. If
- you found Geometry enjoyable in hight
- school, you know Proof Logic. And if
- you studied philosophic logic in
- college, you are aquainted with
- Symbolic Logic.
-
- Process Logic is a combination of
- Proof Logic and Symbolic Logic --
- plus three wonderful additional
- features. Like Proof Logic, you will
- be arranging statements and commands
- in a particular order -- not to prove
- some truth, but to affect some action
- in the computer. In the process, you
- will use Symbolic Logic to manipulate
- values.
-
- The three additional features are
- symbolic value holders (called
- variables and arrays), loops, and
- conditional commands. It is the
- ability to make conditional changes
- in the flow of logic that gives a
- computer its ability to "think."
-
- The C-64 includes a built in
- BASIC interpreter. Computers are
- controlled with three types of
- language. At its very heart, the
- computer processor recognizes certain
- values as "instructions." This is
- built into the machine itself, and is
- called Machine Language. EVERYTHING
- the computer does is done by means of
- ML.
-
- ML is nothing but numbers, that
- is, numeric values. Remembering such
- values and the tasks they perform is
- difficult for humans. We need at
- least some easily recognizable code
- words to remind us about what is
- going on. The ML programmer writes
- this code and the computer uses a
- program to ASSEMBLE that code into ML
- -- which is what the computer
- actually understands. The code the
- programmer writes is called ML, or
- more correctly, Assembly Source Code.
-
- But a computer can be smarter
- than that. Assembly ML source code
- has a one-to-one relationship with
- the code the computer understands.
- However, the computer can be
- programmed to read words, numbers,
- and other characters and translate
- them into complex groups of ML
- instructions. Such a language is
- called Compiled. The program that
- translates Compiler Code into ML Code
- is called a Compiler.
-
- A compiler compiles an entire
- program or routine at a time. If the
- programmer has made a mistake the
- compiler cannot understand, it
- reports errors -- but only after
- chugging through the whole source
- code. So the programmer writes,
- compiles, debugs, recompiles,
- executes, rewrites, recompiles, etc,
- etc. This is an arduous task, to say
- the least. It was even mor frustrating
- back in the 1960's when the programmer
- had to punch cards with each line of
- the program and take the "batch" to
- the computer room. The operator would
- run the batch and return a paper
- print-out to the programmer in a few
- hours. Or days!
-
- At that time, computers were
- finally becoming fairly fast and
- powerful. A terminal could be
- directly connected to the computer so
- the programmer did not have to wait.
- But the computer then did a lot of
- waiting -- for the programmer's
- input. The concept of time-sharing
- was developed, where the computer
- could switch between many different
- terminals, running different programs
- at apparently the same time.
-
- To take advantage of time sharing
- and to provide a language that was
- easy for students to learn and use,
- BASIC (standing for Beginner's All
- Purpose Symbolic Instruction Code)
- was written (invented) in 1963, at
- Dartmouth College, by mathematicians
- John George Kemeny and Tom Kurtzas.
- The commands and math the programmer
- typed looked enough like English to
- make reading the code relatively
- easy.
-
- But the big advantage of BASIC was
- that it was -- and is -- an
- Interpreted Language. During the
- user's tiny slice of processor time, a
- single BASIC statement would be read,
- turned into the ML Code necessary to
- execute the command, and processed.
- Then the processor turned to another
- terminal and program to process. On
- the BASIC program's next turn, the
- next BASIC statement would be
- interpreted and executed.
-
- The great thing about an
- interpreted language like BASIC is
- that the program runs until an error
- occurs. Then it stops and delivers
- an error message. The programmer can
- fix the error and rerun the program.
- This made BASIC very interactive. The
- programmer did not have to get
- everything right before seeing how at
- least SOME of the program performed.
-
- In December of 1974, the January
- issue of Popular Electronics
- published news about the first home
- computer -- the Altair 8800. Two
- Harvard students, Paul Allen and Bill
- Gates saw the magazine -- and their
- future. They dropped out of college
- and rushed to Albuquerque, NM, where
- the Altair was being built.
-
- They realized that these home
- computers needed an "operating
- system" -- a simple way for users to
- interact with the machine. Bill Gates
- wrote Altair BASIC using a mainframe
- computer with an emulator that made
- it act like the Intel 8008
- microprocessor used by the Altair.
- His BASIC included ML code to read
- the keystrokes and put the BASIC
- program into memory. Other code would
- read BASIC commands and jump to ML
- routines that performed them. The
- whole thing fit in just 4 kilobytes
- of memory (which was rather expensive
- at the time).
-
- Gates and his newly founded
- company -- MicroSoft -- went on to
- write BASIC for nearly every home
- computer. BASIC 2 used about 16K of
- memory, but was remarkably powerful.
- Most anything a programmer wanted to
- do could be done in BASIC. True -- it
- was slower than straight ML. But it
- was easy to learn, faster to write,
- and more-or-less portable between
- different makes of computers.
-
- When Commodore produced the
- Personal Electronic Transactor -- the
- PET -- they turned to MicroSoft for
- BASIC. Legend has it that Commodore
- CEO Jack Tramiel bought BASIC 2.0
- outright for $7,000 from cash-
- strapped MicroSoft.
-
- So, in the fall of 1981 when
- Commodore designed the C-64, they
- already owned the BASIC 2.0 operating
- system. The C-64 has color video and
- other features for which BASIC 2.0
- had no commands. But that was OK.
- Game designers would certainly use
- fast ML for their code. And BASIC 2.0
- has commands which can directly read
- or write information to places in
- memory that can control these
- features.
-
- On the up side, the C-64 was
- designed to be modified with ML code.
- Though BASIC 2.0 was in Read Only
- Memory (ROM) and could not be
- changed, certain critical jump
- locations were in Random Access
- Memory (RAM). By changing the jump
- addresses, a programmer could add new
- commands to BASIC and perform all
- sorts of miracles the designers never
- dreamed of. The designers did include
- "paddle controls" for then popular
- games like Break Out. These controls
- proved perfect for adding a mouse.
-
- All in all, a C-64 was a
- fantastic machine in 1982 when it was
- unveiled at the January Consumer
- Electronics Show in Las Vegas. Its
- capabilities -- especially as a "game
- machine" -- and its incredible price
- (that dropped below $200 in 1984) kept
- it in production through 1992. Over
- its decade of manufacture, some 27
- million units were sold, making the
- C-64 the "Best Selling Computer of the
- 20th Century," according to the
- revered Guinness Book of World Records
- (2000-2001).
-
- And to top of a remarkable (if
- often ignored) history, a C-64
- Direct-to-TV game joystick was
- marketed in 2004 through QVC shopping
- channel. Some 200,000 units were sold
- between Thanksgiving and Christmas.
-
- Thanks to the designer -- Jeri
- Ellsworth -- the computer inside the
- joystick is a real, honest-to-
- goodness C-64. With nine wires
- soldered to the credit-card-sized
- board, a user can connect a PS2
- keyboard, Commodore disk drive, and an
- external power supply.
-
- The Commodore 64 -- more than any
- other first-generation, 8-bit
- computer -- has proved itself as THE
- computer for gamesters and hobbyist
- programmers all over the world.
-
-
- INSIDE the C-64
-
- Every computer has three
- essential parts --
-
- 1. A processor which executes ML
- instructions and does math and
- logic operations.
-
- 2. Input/Output capabilities -- for
- keyboard, mouse, joystick,
- printers, and disk drives.
-
- 3. Memory -- "itty-bitty boxes"
- called bytes which can each hold a
- value of 0 through 255.
-
- Today's computers can handle up
- to 8 bytes at a time, making them
- incredibly fast. Such speed is
- necessary for processing sound
- recording, photo-quality images, and
- real-time videos.
-
- The first generation computers
- (such as the C-64) had processors
- that could handle only one byte at a
- time. A byte is composed of eight
- bits -- little switches which are on
- or off, 1 or 0 -- hence these are
- called 8-bit computers.
-
- A two-byte value is used to point
- to a particular byte in memory, which
- means that an 8-bit computer is
- limited to 256 x 256 or 65536 bytes of
- memory. One kilobyte is actually 1024
- bytes, so 65536/1024 equals 64. Thus
- the name Commodore 64.
-
- But the C-64 has more than 64K of
- memory. The ROM which holds all the ML
- code to make BASIC work is "banked" on
- top of RAM. By "flipping" certain bits
- in the computer, an ML programmer can
- set ROM aside and use the RAM
- "underneath." Indeed, most everything
- about the built-in operating system
- can be ignored, giving the expert
- programmer a full 64K of memory with
- which to work.
-
- As mentioned before, even though
- BASIC 2.0 is powerful, ML programmers
- have created a number of BASIC
- extensions and ML modules to add
- features for BASIC programmers. In
- 2004, LOADSTAR featured DotBASIC
- which adds 72 commands to BASIC 2.0
- -- including full mouse control and
- Event Driven programming. Other
- modules play music and sound effects
- in the background, enable easy access
- to bitmap graphics, and even let
- ordinary BASIC programmers operate
- sprites (movable screen objects) and
- do split screen effects.
-
-
- THE LIMITATIONS
-
- The 6510 microprocessor in the
- C-64 operates at 1 Megahertz -- which
- is terribly slow when compared to the
- 2-3 Gigahertz Pentiums now on the
- market. However, 1 Mhz is 1,000,000
- clock cycles per second (which is
- really pretty quick!) and the 6510's
- instructions are quite efficient
- compared to Pentium instructions.
-
- The screen is comprised of 64,000
- pixels -- 320 x 200. In multi-color
- mode, two bits determine which of
- four colors will be displayed as
- double-wide pixels (160 x 200). The
- result is a bit grainy.
-
- Text characters are all 8 x 8
- pixels in size, and can display the
- character "cell" color or the
- background color. In multi-color text
- mode, 4x8 double-wide pixels can
- present the character color or one of
- three "universal" colors.
-
- The font includes 256 characters,
- but the programmer is not limited to
- the two built-in 256 character fonts.
- With a font editor, each of the 256
- characters can show any 8 x 8
- combination of pixels. Moreover, the
- programmer has eight 24 x 21 pixel
- sprites -- movable objects -- that can
- be designed and displayed anywhere
- without disrupting the screen.
-
- Sprites are easily used for things
- like pointer and video game characters
- because they can freely move on top of
- on-screen characters.
-
- The whole screen can be nudged,
- pixel by pixel, in any direction,
- enabling smooth scrolling effects --
- especially when combined with split
- screen capabilities.
-
- Sound is remarkable for a one-chip
- device, including three synthesized
- voices. The synthesizer's envelope has
- Attack, Decay, Sustain, and
- Release parameters, and include
- various filters and resonance
- settings. Waveforms include noise,
- sawtooth, triangle, and adjustable
- pulse. And, with extreme cleverness,
- 4-bit recorded sound can be recorded
- and played by the computer.
-
- [ROBIN'S BETA NOTE:] "Extreme
- cleverness" is a bit of an
- exaggeration! Playing 4-bit digis is
- actually about the easiest thing you
- can do with the SID (just one poke,
- repeatedly!) as long as you can handle
- CIA coding to make an IRQ or NMI
- happen over and over again at a steady
- pace.
-
- [DAVE'S BETA RESPONSE:] Right, Robin!
- the CIA is the Complex Interface
- Adaptor, which does all the timing for
- the C-64 (IRQ and NMI are the two
- forms of forced timing). So the
- "cleverness" is to get the timing
- smooth.
-
- So while the C-64 has certain
- limitations, it was crafted in such a
- way that truly capable programmers can
- create most anything computational. I
- have seen real-time three-dimensional
- displays (like DOOM, only very low
- resolution), the MGM Lion roar, and
- hundreds of other truly amazing sound
- and video effects.
-
- But most important, anything one
- can do on any computer can be at
- least MODELED on the C-64. The model
- may be rough, but the concepts,
- skills, and personal satisfaction in
- accomplishing effects are the same as
- with a big computer.
-
- The day may come when you will
- want to tackle C, C++, C#, Java, Java
- Script, Perl, or Visual Basic on a
- PC. EVERYTHING conceptual and logical
- learned on the C-64 will apply to any
- other computer or language.
-
- The C-64 is where one starts --
- as did thousands of today's software
- design professionals. And hundreds of
- hobbyist programmers still find more
- than enough challenge to sit up all
- hours of the night hunching over their
- C-64s, fixing just one more thing!
-
-
- ON TO BASIC 2.0
-
- When you turn on the C-64 (or
- launch VICE), the screen displays
- some title information, then presents
- the word READY.
-
- READY? Ready for what?
-
- Ready for anything you want to
- do!
-
-
- Type:
-
- PRINT "HELLO"
-
- and press <RETURN>. (On VICE, the
- double-quotes are <Shift-2>, and
- <RETURN> is the <ENTER> key.)
-
- The computer immediately complies
- -- printing to the screen:
-
- HELLO
-
- Type:
-
- ? 5 + 7 * 10
-
- (VICE: the plus is the <-> key
- (next to the <0> key), the asterisk is
- the <CLOSE BRACKET> key.) (Remember
- to press the <RETURN> which tells the
- C-64 to go ahead and do it.)
-
- 75
-
- The question mark is short for
- PRINT.
-
- In the first example, you printed
- a STRING, a group of characters in
- order. You marked off the beginning
- and end of the string with
- double-quotes.
-
- In the second example, you
- printed numeric values, multiplied
- and added according to mathematic
- rules (multiply and divide are
- performed first, followed by addition
- and subtraction).
-
- Both of these are examples of
- Immediate Mode. The C-64 immediately
- responded to your commands when the
- <RETURN> was pressed.
-
- Now Type:
-
- 10 ? "HELLO"
- 20 ? 5 + 7 * 10
-
- (pressing <RETURN> at the end of each
- line).
-
- Nothing happened -- at least not
- obviously. But inside the C-64 a lot
- has taken place. Type:
-
- LIST
-
- and the lines appear again. You have
- written these lines in Program Mode.
-
- The difference between Immediate
- Mode and Program Mode is very simple:
-
-
- If a NUMBER comes first in the
- line, the line is put in Program
- Memory. You can look at the
- program with LIST.
-
- If a command comes first, the
- line is in Immediate Mode and
- processed immediately.
-
- To run your program, Type:
-
- RUN
-
- Wonderful! You have written your
- first program!
-
- The number you use at the
- beginning of a Program line will
- determine where that line occurs in
- the program. Type:
-
- 15 ? "WORLD"
-
- and LIST
-
- 10 PRINT "HELLO"
- 15 PRINT "WORLD"
- 20 PRINT 5 + 7 * 10
-
- Since every program line must
- have a number and will be ordered by
- its number, it is a good idea to use
- 10's as you start writing your
- program. Then, if you want to tuck
- something in between two existing
- lines, you can -- just like you just
- did.
-
-
- VARIABLES
-
- A variable is a "box" that
- contains something. Each variable has
- a name, comprised of one or two
- letters or a letter and a number.
- Longer variable names are OK (unless
- they contain a BASIC command word),
- but the computer will not "see" more
- than the first two characters.
-
- Let's wipe out your first
- program. Type:
-
- NEW
-
- and LIST
-
- It's gone. Now Type:
-
- 10 A1$ = "HELLO"
- 20 A2$ = "WORLD"
- 30 A1 = 5
- 40 A2 = 7
- 50 A3 = 10
- 100 ? A1$ + A2$
- 110 ? A1 + A2 * A3
- 120 END
-
- We have two types of data --
- string and numeric. So we have two
- types of variables -- string and
- numeric. A string variable has a
- dollar sign after the one or two
- characters. A numeric variable
- doesn't.
-
- String variables cannot be part
- of a math formula -- but a plus sign
- will string two or more strings
- together. A numeric variable cannot
- be strung onto a string -- but they
- can be part of a math formula.
-
- The C-64 has the greatest
- programming interface ever put on an
- 8-bit computer. If you want to change
- a program line, all you have to do is
-
- * put the line on the screen,
-
- * move your cursor up to it,
-
- * type your changes onto the line,
-
- * and press <RETURN>.
-
-
- To list one line, include the line
- number after the LIST command:
-
- LIST 100
-
- Other list possibilities include:
-
- LIST -100 list up to line 100
- LIST 100- list line 100 and after
- LIST 30-50 list from 30 to 50
-
- As a list is scrolling, you can
- slow it down by pressing the <CTRL>
- key (<TAB> for VICE), or stop it by
- pressing <STOP> (<ESC> for VICE).
-
- List line 100:
-
- 100 PRINT A1$ + A2$
-
- and change it to
-
- 100 PRINT A1$ + ", " + A2$
-
- Press <RETURN> then RUN the program.
-
- Play around with this program for
- a while! Try all sorts of things. You
- can print strings and numerics
- together on the same line:
-
- 100 PRINT A1$ + ", " + A2$; A1
-
- Use a semicolon to separate stuff
- you print. Use a comma to tab items
- to columns.
-
- Try this:
-
- 90 T = A1 + A2 * A3
- 95 ? T;
-
- and run the program. Or do this:
-
- 80 A1$ = A1$ + A1$
- 85 A2$ = A2$ + A1$
-
- Try every combination of
- variables and print you can think of.
- It is YOUR program. And there is
- nothing you can do from the keyboard
- that will hurt a C-64! NOTHING!
-
-
- ABOUT ERRORS
-
- You have surely seen some errors
- by now. Two things about errors:
-
- 1. The program stops short at any
- error, and
-
- 2. The C-64 always says READY. after
- an error.
-
-
- When you get an error, just list
- the line and try to figure out what is
- wrong. SYNTAX means that something you
- typed is incomprehensible to the
- stupid machine. Fix it! Then try
- again.
-
-
- This is just the beginning.
- Everything you really need
- to become a C-64 programmer
- will be revealed in Part II!
-
-
-