(Article by Phaze101)
What is C64 Bedtime Coding?
This is a series of articles related to the 6502 Assembly language programming on the Commodore C64. The intention is to learn this while having fun. We will achieve this objective by writing simple games.
For who is it
These tutorials will be mainly aimed and focused for beginners who want to learn to write assembly language. Also, it is for those that want to write games for the C64 using assembly. My aim is to show you simple things that can get you to achieve this goal of writing your own games and at the same time learn the assembly language.
If you are one of those people that always wanted to learn how to write games on the C64 and you never managed to learn assembly then this series is for you.
Please note that I will keep things simple and will not go into detail so as not to confuse beginners.
Reflect for a moment
We all like playing games, right? Have you ever wondered and thought about how games are done?
We are all fascinated with demos where coders show what they can do by pushing the hardware to the limits but how is all this possible?
Does it seem something that it is impossible for you to do? Do you think that you are not capable of doing so?
Well let me assure you that you do not need to be a genius to write simple games. All you need is patience. Writing games in Basic is simple compare to writing in Assembly but with patience and knowing small simple things you can achieve a lot.
With patience you will be able to push the hardware to the limits and achieve greater things that Basic can’t give you.
What you need to know
There are a few things that you need to know to code in assembly and write games
- Knowing the number system (Binary and Hex)
- Know and understand the 6502 Assembly instruction set and know the 6502 Status Register
- Know your assembler and its directives
- Know your hardware which in this case is the Commodore C64 and how it works
- Know the Hardware Special Registers.
- Know some gaming techniques.
All the above will be covered in the coming weeks / months.
I will try to show you all the above by writing a simple game and where possible stop and cover the above or I will cover them as a separate subject.
Before we continue
First, I want to say that I do not consider myself an expert on the subject. Like everyone I like to play games but at the same time I was always interested in how games are written (programmed/coded) and how I can achieve the same thing. It is my hobby and my passion. I did my own research on the subject. I wrote games as a hobby and never as a professional.
Also, neither English nor Italian is my first language so please excuse me for spelling mistakes, grammar mistakes or anything related to both languages. I will try to have each article in English and Italian.
If you are reading this, it is because you are interested in learning how to program in assembly or would like to know how to write games of your own and learning about this subject. I do not mind being corrected but please do it with a gentle kick.
Please note that some technical words that are used in Italian I do not know them myself so there might be instances where I use English words for the terms. This should be accepted and understood given that Italian is not my first language.
The Number System
We all know the decimal number system, however in assembly you will encounter other numbering systems.
These are the Binary System and the Hexadecimal System.
Computers like the Commodore C64 can understand +5Volts or 0Volts. These states are interpreted as 1 and 0. From now on I will be referring to +5V and 0V as 1 or 0 respectively. Therefore, all the information flow inside the computer is 0s and 1s and this is called machine code.
For humans this is impossible to understand and follow even at the speed of the Commodore C64 compared to today’s computers.
The Binary System – Base 2 (% symbol)
The decimal system is known as base 10. It is known as base 10 since it has the numbers 0 to 9. Passing 9 we use the same digits. A digit’s position within the decimal number determines the magnitude of the digit. Therefore 12 and 123 means a different thing.
Example of Base 10
|Base & Power||10^3||10^2||10^1||10^0|
^ = to the power of
Using the above decimal number of 2504 is 2×1000 + 5×100 + 0x10 + 4×1 which is equal to 2504
This is the same in binary. The positions of the 0s and 1s within a binary number determine the value of the number. A binary number %1010 is different than %1011. Please note that binary number are normally preceded by the % sign to indicate it is a binary number.
In Base 2 Binary System
|Base & Power||2^3||2^2||2^1||2^0|
^ = to the power of
Using the above binary number of %1101 is 1×8 + 1×4 + 0x2 + 1×1 which is equal to 13 or %1101
The Hexadecimal System – Base 16 ($ symbol)
The hexadecimal system uses the $ symbol and it precedes the number to indicate it is a hexadecimal number.
The hexadecimal system uses the number 0 to 9 and the letters A to F. Therefore, after the number 9 then next Number is A. A represents the number 10 in decimal, B is 11, C is 12, D is 13, E is 14 and F is 15.
Same as in the Decimal System (Base 10) and in Binary (Base 2) the positioning of the numbers and letters determines the magnitude of the digit. Therefore, the number $00C0 and $0C00 are different.
In Base 16 Hexadecimal
|Base & Power||16^3||16^2||16^1||16^0|
^ = to the power of
Using the above hexadecimal number of $C21F is 124096 + 2256 + 1*16 + 15×1 which is equal to 49695 decimal or $C21F
Expanding on the above
A Bit is a switch that is either ON (1) or OFF (0). It can only have these two values of 1 or 0.
A byte is a series of 8 bits.
As you can see from the above binary number of %00001111 if we had to divide the byte (8 bits) in half we get a nibble. A nibble is 4 bits and it can hold a number between 0 and 15 or 0 to F. Therefore, thinking in hex can be easier if we had to divide a binary number in 4 bits and vice versa.
A hex number of $F0 is %11110000 in binary.
Although it might seem odd in the beginning starting to think in Hexadecimal (Hex in short) it has its advantages and it is easier to convert to binary. Same is true converting binary in to hex.
The next diagram should help you better understand what we covered.