Commodore 64 Programmer's Reference Manual

(It commodore
COMPUTER
==-
FIRST EDITION THIRD PRINTING-1983
This manual is copyrighted and contains proprietary information. No part of this publica-
tion may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, eledronic, mechanical, photocopying, recording, or otherwise, without the prior
written permission of COMMODORE BUSINESS MACHINES, Inc.
ii
TABLE OF CONTENTS
INTRODUCTION. . ... . . .. . . ... . ... . . ... . . .. . . .. . . .. . .. .. ix
. What's Included? . .. . . .. . .. . . .. .. . .. . . .. . . ... . ... . . .. x
. How to Use This Reference Guide...................." xi
. Commodore 64 ApplicationsGuide. . .. . . .. . .. . . ... . . ... xii
. Commodore Information Network. . . . . . . . . . . . . . . . . . . . . .. xvii
1. BASIC PROGRAMMING RULES 1
. Introduction 2
. ScreenDisplay Codes (BASIC Character Set) ............. 2
The Operating System(OS) 2
. Programming Numbers and Variables 4
Integer, Floating-Point and String Constants.. . . . . . . . . . 4
Integer, Floating-Point and String Variables. . . . . . . . . . . 7
Integer, Floating-Point and String Arrays 8
. Expressionsand Operators... . . .. . . ... . . .. . . .. . .. . . .. . 9
Arithmetic Expressions.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Arithmetic Operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Relational Operators 12
Logical Operators .. ... . ... . . .. . . .. . .. .. . . .. . .. . . .. ~3
Hierarchy of Operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Stri ng Operations 16
String Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 17
. Programming Techniques 18
Data Conversions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Using the INPUT Statement 18
Using the GETStatement. . . . . . . . . . . . . . . . . . . . . . . . . .. 22
How to Crunch BASIC Programs 24
2. BASIC LANGUAGE VOCABULARY... . . .. . . . .. . . .. .. 29
. Introduction 30
. BASIC Keywords,Abbreviations, and Function Types 31
. Description of BASIC Keywords (Alphabetical) 35
. The Commodore 64 Keyboard and Features 93
. Screen Editor.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 94
iii
3. PROGRAMMING GRAPHICS ON THE
COMMODORE64 ... 99
· Graphics Overview 100
Character Display Modes
.. ... ... .. .. . .. ... ... ... ... 100
Bit Map Modes 100 Sprites 100
· GraphicsLocations 101
VideoBankSelection... ... . .. ... ..... ... .. ... ... .. 101
Screen Memory 102
ColorMemory .1.. . ... . . .. . . .. 103
Character Memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 103
. Standard CharacterMode. .. . . . .. . . . . . . . . . . . . . . .. . . .. 107
Character Definitions 107
· Programmable Characters 108 . Multi-Color Mode Graphics 115
Multi-Color Mode Bit 115
. Extended Background Color Mode 120
. BitMappedGraphics... .... .... ... ..... ..... .'" .... 121
Standard High-Resolution Bit Map Mode. . ... . ... . 122
HowItWorks. . . .. .. ... ... .... .... ..... .... . .. 122
. Multi-ColorBitMap Mode. ... . .. . . . . . . . .. . .. . . .. . . ... 127
. SmoothScrolling 128 . Sprites 131
Defining a Sprite 131 Sprite Poi nters
. . . ... . . . .. . . . ... . .. .. . . . .. . . . ... . .. 133
Turning Sprites On 134 Turning Sprites Off
. . . . . . . . . .. . . . .. . . . . . . . . . . . . . . .. 135
Colors.. . . .. . . . .. .. . . . .. . . .. . . . . . . . . . . . . . . . .. . . .. 135
Multi-Color Mode 135
Setting a Sprite to Multi-ColorMode. . . . . . .. . . ... . ... 136
Expanded Sprites 136 Sprite Positioning 137
Sprite PositioningSummary.. . . . . . . . . . . . . . . . . . . .. . .. 143
SpriteDisplayPriorities.... .. ... .. . .. ... .. ... . . .... 144
Collision Detects 144
. Other Graphics Features 150
Screen Blanking 150 Raster Reg ister
..... ... ... .. ... ..... ... ... .. ... .. .. 150
Interrupt Status Register. . . . . . . . . . . . . . . . . . . . . . . . . . .. 151
Suggested Screen and Character Color Combinations... 152
iv
. Programming Sprites-Another Look 153
Making Sprites in BASIC-A Short Program. ... . .. . . .. 153
Crunching Your Sprite Programs 156 Positioning Sprites on the Screen 157
Sprite Priorities .. ..... . . .... . . ... . . ... . . . .. . . . .. .. 161
Drawing a Sprite 162 Creating a Sprite
. . . Step by Step 163
Moving YourSprite on the Screen. . .. . . .. . . .. . ... . . .. 165
VerticalScrolling... .. . . . . . . . . . . . . . . .. . . . .. . . . . . . .. 166
The Dancing Mouse-A Sprite Program Example. . . . . .. 166
EasySpritemakingChart.. . ... . ... .. .. . ... . . ... 176
SpritemakingNotes.. . .. . . .. . ... .. .. . ... . . .. . ... . .. 177
4. PROGRAMMING SOUND AND MUSIC
ON YOUR COMMODORE 64 183
. Introduction 184
Volume Control 186
Frequencies of Sound Waves. . . ..... ..... ..... ...... 186
. UsingMultipleVoices... . .. . . ... . ... .. ... . .. . 187
Controlling Multiple Voices 191
. Changing Waveforms . ... . . ... . . . ... . . ... . . ... . . . .. .. 192
UnderstandingWaveforms..... .... . . ... .... 194
. TheEnvelopeGenerator. . . . . .. . . . .. . . . . . .. . . .. . . . . . .. 196
. Filtering 199
. Advanced Techniques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 202
. Synchronization and Ring Modulation 207
5. BASICTOMACHINELANGUAGE 209
. What is Machine Language? ... ... ..... .... ..... ... ... 210
What Does Machine Code Look Like? . . . ... . . ... . . . ... 211
Simple Memory Map of the Commodore 64 ...... .. .... 212
The Registers Inside the 6510 Microprocessor 213
. How Do You Write Machine Language Programs? 214
64MON 215
. HexadecimalNotation.. ... ... .... ..... .... .... .. 215
Your First Machine Language Instruction 218 Writing Your First Program 220
. Addressing Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 221
Zero Page 221
The Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 222
v
Loading...
+ 12 hidden pages