|
 |
 |
Preface
Something amazing lies beneath BASIC.
Several years ago I decided to learn to program in machine
language, the computer's own language. I understood BASIC fairly
well and I realized that it was simply not possible to accomplish
all that I wanted to do with my computer using BASIC alone. BASIC is
sometimes just too slow. I faced the daunting
(and exhilarating) prospect of learning to go below the surface of
my computer, of finding out how to talk directly to a computer in
its language, not the imitation-English of BASIC. I bought four
books on 6502 machine language programming and spent several months
practicing with them and puzzling out opcodes and hexadecimal
arithmetic, and putting together small machine language
programs. Few events in learning to use a
personal computer have had more impact on me than the moment that I
could instantly fill the TV screen with any picture I wanted because
of a machine language program I had written. I was amazed at its
speed, but more than that, I realized that any time large amounts of
information were needed on screen in the future - it could be done
via machine language. I had, in effect, created a new BASIC
"command" which could be added to any of my programs. This command -
using a SYS or USR instruction to send the computer to my
custom-designed machine language routine - allowed me to have
previously impossible control over the computer.
BASIC might be compared to a reliable, comfortable car. It
will get you where you want to go. Machine language is like a sleek
racing car - you get there with lots of time to spare. When
programming involves large amounts of data, music, graphics, or
games - speed can become the single most important factor.
After becoming accustomed to machine language, I
decided to write an arcade game entirely without benefit of BASIC.
It was to be in machine language from start to finish. I predicted
that it would take about twenty to thirty hours. It was a space
invaders game with mother ships, rows of aliens, sound ... the
works. It took closer to 80 hours, but I am probably more proud of
that program than of any other I've written.
After I'd finished it, I realized that the next games would be
easier and could be programmed more quickly. The modules handling
scoring, sound, screen framing, delay, and player/enemy shapes were
all written. I only had to write new sound effects, change details
about the scoring, create new shapes. The essential routines were,
for the most part, already written for a variety of new arcade-type
games. When creating machine language programs you build up a
collection of reusable subroutines. For example, once you find out
how to make sounds on your machine, you change the details, but not
the underlying procedures, for any new songs.
The great majority of books about machine language assume a
considerable familiarity with both the details of microprocessor
chips and with programming technique. This book only assumes a
working knowledge of BASIC. It was designed to speak directly to the
amateur programmer, the part-time computerist. It should help you
make the transition from BASIC to machine language with relative
ease. This book is dedicated to Florence,
Jim, and Larry. I would also like to express my gratitude to Lou
Cargile for his many helpful suggestions; to Tom R. Halfhill and
Charles Brannon of the COMPUTE! Magazine editorial staff for
their contributions - both direct and indirect - to this book; and
to Robert Lock and Kathleen Martinek for their encouragement,
comments, and moral support. And special thanks to Jim Butterfield
for his maps, programs, and constant encouragement to everyone who
decides to learn 6502 machine language programming.
Return to Table
of Contents | Previous
Chapter | Next
Chapter |
| |
|