·Commodore 64
Total Page:16
File Type:pdf, Size:1020Kb
~ -. :_l_j_ . -_ I ~ ' - ~-.!'L'" ·COMMODORE 64 BRUCE BAYLEY COMMODORE 14 EXPOSED COMMODORE 64 E POSED BRUCE BAYLEY _._,- _lWj_ "-"L~ MELBOURNE HOUSE Published in the United Kingdom by: Melbourne House (Publishers) Ltd., Melbourne House, Church Yard, Tring, Hertfordshire HP23 5LU, ISBN 0 - 86161 -133 - 0 Published in Australia by: Melbourne House (Australia) Pty. Ltd., Suite 4, 75 Palmerston Crescent, South Melbourne, Victoria, 3205, National Library of Australia Card Number and ISBN 0 - 86759 -144 - 7 Published in the United States of America by: Melbourne House Software Inc., 347 Reedwood Drive, Nashville TN 37217. Copyright (c) 1983 Beam Software Contributions by: Andrew Paulomanolakos Peter Falconer Goodwin Yuen All rights reserved. This book is copyright. No part of this book may be copied or stored by any means whatsoever whether mechanical or electronic, except for private or study use as defined in the Copyright Act. All enquiries should be addressed to the publishers Printed in Hong Kong by Colorcraft Ltd. 1st Edition Contents Chapter 1 Programming in Basic ........................................................... Immediate and Program Modes ........ .................. .............. ... ... 1 Control Structures ................................................................... 2 Data Structures ........................................................................ 6 Bits and Bytes..................................................................... 6 Characters.......................................................................... 6 Variables ................... .................................................. ....... 6 Arrays ................................................................................ 10 Operators ................................................................................. 11 Arithmetic Operators .......................................................... 11 String Operators................................................................. 12 Relational Operators .......................................................... 12 Binary and Hexadecimal Number Systems ........................ 14 Masks ................................................................................ 16 Chapter 2 Commodore 64 BASIC Commands.... ................. ................... 17 Chapter 3 Advanced BASIC Techniques ...... ... ... ................ .................... 42 Compressing BASIC Programs .......................................... 42 Abbreviations for BASIC Keywords .................................... 43 Appending BASIC Programs..... ............... ... ............... ........ 44 BASIC Program Storage Format .............. ... .............. ..... .... 45 Commodore 64 BASIC Keyword Codes.... ............. .... ........ 46 Clearing the Keyboard Buffer ............................................. 47 Merge Routine ................................................................... 49 Block Delete Routine .......................................................... 50 Chapter 4 Sound ....................................................................................... 51 Waveforms ......................................................................... 51 The ADSR Envelope ... ........ ....... ................... .......... .... ....... 52 Controlling the Sound Chip ..... ....... ............... .......... .... ... .... 54 Playing Tunes ..... .......... ............... ................. ................. .... 54 Using Multiple Voices ......................................................... 55 Using Filters and Resonance ............................................. 58 Putting it All Together ......................................................... 60 Special Sound Effects ........................................................ 67 The Sound Chip Registers .. ........ ................................ ....... 70 Music Note Values .................... .............................. ........... 75 ChapterS Graphics .................................................................................. 79 Graphics Memory .................................................................... 79 Low Resolution Graphics ...... .......... ...... .............. ........ ........... 79 Screen Background and Border Colours ............................ 79 Character Colour................................................................ 80 Screen Memory ....................................................................... 80 Character Memory................................................................... 82 Designing Your Own Characters .................. .............. ........... 83 Where to Put the New Character Set.................................. 85 High Resolution Graphics ........ ............ .............. .................... 86 Multicolour Characters ....................................................... 89 Extended Background Colour Mode ..................................... 90 Multicolour Bit Map Mode...... .......... .................. ..................... 91 Sprites ...................................................................................... 91 Sprite Pointers ................................................................... 91 Turning Sprites On ............ ................ .............. ........ ........... 92 Sprite Colour ...................................................................... 93 Multicolour Sprites ............................................................. 93 Expanding Sprites .............................................................. 93 Sprite Movement ................................................................ 94 Sprite Display Priorities ...................................................... 96 Sprite Collisions ................................................................. 98 Selecting a Video Bank............................................................ 98 VIC-II Chip Register Map............................ .......... ................. 100 Chapter 6 Machine Language Programming on the Commodore 64 ... 101 Introduction .. ........................................................................... 101 Binary and Hexadecimal Numbering System ....................... 102 Registers and Addressing Modes .......................................... 104 Machine Code and Instruction Mnemonics ........................... 109 6510 Microprocessor Set ........................................................ 111 Simple Machine Language Programs .................................... 113 MON - Simple Machine Code Monitor .............................. 114 Commodore 64 Memory Map and Management ................... 118 Program Entry ......................................................................... 124 BASIC Statements ............................................................. 124 Machine Language Monitor ................................................ 125 Editor/Assembler Package ................................................ 125 Program Execution ................................................................. 126 BASIC Control Program ..................................................... 126 Machine Language Monitor ................................................ 127 Substitution of System Handling Routines ......................... 127 Some Commodore 64 Useful Routines ................................. 128 Commodore 64 Kernal ............................................................ 133 Concepts of Kernal and Operating System ........................ 133 Power Up Initialisations ...................................................... 134 Using Kernal Routines ....................................................... 134 Some Useful Kernal Routines ............................................ 135 Simple Programs That Call Kernal Routines ...................... 136 Graphics Using Machine Code ............................................... 140 Raster Interrupts ..................................................................... 145 Chapter 7 External Devices ..................................................................... 152 Datasette ........................................................................... 152 Floppy-Disk Draves ............................................................ 152 Disc Drive Memory Manipulation ........................................ 158 The 1515 Graphic Printer ................................................... 161 Games Controls ................................................................. 162 Keyboard ........................................................................... 163 Joystick .............................................................................. 164 Paddles .............................................................................. 165 Appendices A: CHR$ Value Codes ............................................................ 167 B: Memory (Complete Map) ................................................... 175 C: Keyboard Graphics and How to Get Them ...................... 181 D: Useful ROM Routines ........................................................ 183 E: BASIC Error Messages ...................................................... 191 F: Current Key Pressed ......................................................... 193 CHAPTER 1 PROGRAMMING IN BASIC BASIC is only one of the many languages used to communicate with computers. It is however, the most common language in the microcomputer world, so it's a good one to know. BASIC varies from computer to computer,