Traditionallythese 8bit personal computers were programmed in BASIC. Apple IIs were provided with AppleSoft, a quite powerful (for that time) BASIC from Microsoft. But BASICs are interpreted languages, thus are quite slow. So if you wanted to do something serious, you had no choice but programming in assembly.
I know that the 6502 in my Apple is a 8 bit CPU running at a paltry 1 MHz. But the most demanding part of my code is the following function, called 798 times per screen (or 38 times per line).
I read the coding hints of the CC65 documentation, but it appears that I did nothing too wrong. Plus, the CC65 compilation suite is praised, and is considered more effective than some C compiler of the 80s.
First, its small instruction set (only 56!) can be seen as a strength. Decoding them is fast and cheap. Furthermore, the execution time is small compared to the other architectures of the time : almost always one cycle (excluding memory access). Some kind of primitive pipelining is also possible when combining some addressing mode with some operations: the next instruction can be fetched before the completion of the current one!
And the chip itself was cheap. Cheap to produce, thus cheap to buy. It is composed of only 3510 transistors!!! As a matter of fact, the 6502 is considered by many as the precursor of the RISC architectures. And it is well known that it has inspired the designers of one of the most well known RISC CPU: ARM!
Quite recently, a few readers stated that the code given in example was not properly written to suit the 6502 limitations and that I could achieve better performance. One of them pointed me to a recent article: CC65-Advanced-Optimizations. For the most part, they are right. If you are motivated to code in C for the 6502, I urge you to read it. It will help you to avoid pitfalls.
Again, I have nothing against CC65 and its maintainers. On the contrary, they did a wonderful job. If it democratizes homebrew development for 6502-based machines, with good enough performance, we all win at the end! ?
This course is a complete immersion into the world of the Nintendo Entertainment System. We will learn how to program games for the NES using 6502 assembly while exploring the building blocks of computer architecture. The rudimentary hardware of the NES is a perfect sandbox for us to learn important concepts of low-level programming.
At the end of the course, you'll have a working knowledge of 6502 assembly language, a comprehensive understanding of the NES hardware, and a toy homebrew game project that we'll code together from scratch. We'll start with small examples and proceed to glue everything together in a final project that demonstrates how a simple NES game works.
The 6502 processor is an extremely important part of computing history, powering many popular game consoles and microcomputers of the past, like the NES, the Commodore 64, the Apple II, and even the Tamagotchi.
Differently than other online resources about retro game programming, this course is not simply a documentation of assembly mnemonics that only experienced developers can digest. This course tries to be as beginner-friendly as possible, giving you the chance to learn assembly in a fun way.
Trying to understand how modern computers work under the hood can be overwhelming. The small architecture of the NES is our chance to take a step back and look at the fundamental building blocks of computing. So, if you want to really learn how digital machines work and finally lose your fear of the expression "assembly programming", then get ready and buckle up! We are about to go on a super cool nerd trip together.
If you stick to the legal opcodes e.g. those specified in the datasheets of the day you'll be fine. Once you get familiar with the instruction set you might want to start using the stable illegal opcodes. Illegal opcodes are more useful in 2600 programming because cycles are at a premium in your display kernel and space may also be tight if you are targeting 2K or 4K games.
Many 6502 books have mistakes (so aren't ideal for beginners in my opinion) but a good general purpose one in the "6502 Reference Guide" by Alan Tully. It covers all the opcodes, their cycle timing, flags affected and available addressing modes. For good routines "Assembler Routines for the 6502" from the "Best of PCW" series and "6502 Software Gourmet Guide and Cookbook" by Robert Hindley are both good. All these books are long out of print but you might be able to snag a copy on ebay if/when they come up.
I'm not familiar with that book. I just had a quick look and at first glance it looks like there is a ton of stuff you don't need to know thrown in like BASIC and its not too good on giving you building blocks to work along with. But... its a long time since I first learnt 6502 so take that opinion with a pinch of salt.
The best way to learn in my opinion is to set yourself little tasks and then build your knowledge and experience on them. Start with something simple like adding 2 numbers together in the accumulator, then add numbers stored in memory locations then work out how to make loops and the equivalent of if/then/else statements and as you learn make the tasks more and more complex. Then when you've got the basics down look at getting a sprite on screen (C64 is probably easiest for that), then learn how to move it around, then get a backdrop up, get the sprite to interact with it in some way and so on.
You might find it easier going with the CPU instructions if you find a pure windows based 6502 simulator (I know nothing of Linux or Mac) then you don't have to worry about setting up hardware to get you in a good state. Plus you can single step with ease and check out memory and CPU flags easily.
As always, I recommend this awesome simulator to all 6502 beginners. Write some code, assemble it and debug it to your heart's content. Back when I started learning assembly I would read online documents about how the instructions worked, and then I would go to this simulator and try to do something using what I learned (or thought I learned!). I paid a lot of attention to how the status flags were affected by each instruction, how the stack behaved and how the different addressing modes worked, which IMO are essential things for the understanding of ASM. I made lots of little routines in this simulator, such as multiplication, division, square roots, just to practice and get the hang of how the instructions work.
Regarding the differences between 6502 and 6507, there aren't many. The difference between one machine and the other (i.e. 2600 vs C64 vs NES, etc.) is much more significant and has much more impact on the structure of your programs than the subtle differences between the 6502 and 6507. Each machine has different video, audio and input hardware, and the CPU interacts with them through registers mapped to different memory areas. Each machine has RAM and ROM mapped to different places. Those are the things that make any difference.
Don't worry too much about this right now, just play around with some pure 6502 in the simulator, testing everything you read in books/documents. Once you get the hang of doing arithmetic and controlling the program flow, you can try making something for a specific machine of your choice, taking its peculiarities into consideration.
3a8082e126