My first Commodore 64 Scrolling Game
The following examples utilize the CBM Prg Studio editor to create a scrolling simulation environment. The editor also uses Win VICE C64 emulator to run the application in a display window. For those who are new to emulators, just know that an "emulator" is sort of a copy of the original ROMS for the Commodore 64 that allows you to write programs for your Commodore 64. The CBM Prg Studio is used to compile the object code into machine language so it can be executed.
C64 Smooth Scrolling Display Hack
This video first inspired me on my quest to learn how to scroll the Commodore 64 screen. In this example the author shows a perfect scroll that flips the display from left to right in either direction.
You can view the CBM Prg Studio example by clicking here.
Horizontal Scrolling Game Demo 1
Late last year in 2015 I began construction on my first scrolling Commodore 64 game. This was a major breakthrough as everything before this was single screens only. The scrolling works by moving data on the screen and setting bit registers 53270 (horizontal) and 53265 (vertical). I was able to learn this by utilzing some assembly language PDF manuals I found at Bombjack.org. Here is the first video I posted after I discovered how to scroll the screen.
This first example only allowed the game to scroll to the right. I just wanted to post a video once I had it working.
Horizontal Scrolling Game Demo 2
The second example allowed the screen to scroll both to the right and the left. This was a little challenging to get it working accurately. The screen scrolling was still kind of jittery at this stage however. It also seemed to repeat screen data if I scrolled too far.
Vertical Scrolling Game Demo
Once I had the horizontal scrolling working, I moved onto accomplishing the vertical scroll. Now this is even more devastating since the screen creates garbage at the top line when moving up. This is because register 53265 can only blank one vertical line at a time according to Mapping the Commodore 64. After this it resets the register to 0 and shifts the blanking for each scan line as the bit values are incremented.
Scrolling Game and Raster Interrupts
Much later after I refined the scrolling some more, I move onto adding some raster interrupts to control alien sprites in the game. So for my first time I just allowed the alien to move to the right based on how far the screen has scrolled. This also allowed my player to move without interrupting the alien movement much.
Scrolling Game and Animation
The next step was to work on adding animation to the alien character in the game. I also provided him the ability to walk to the right and turn back to the left after reaching a specific distance. I also added some screen status displays to alert the player what action was taking place in the game. In addition to the first alien, after the player scrolls the screen a specific length of time, a new alien appears on the bottom. I decided to recycle the aliens to give the game an illusion of meeting up with newer enemies along the journey.
Another animation sequence was added for the player's laser pistol. I created some simple frames to show the lasers. There is also a little bit of sound for the effect.
Scrolling Game and Background Collisions
The next stage was to work on some collision detection. My first try at this involved tracking specific locations of the sprite character and calling a subroutine once that position was found. That is demonstrated below.
Commodore 64 Collision Test
After this I planned to further refine the collision detection. To accomplish this, I decided to start with a Commodore 64 Basic example and matched some screen mathematical formulas to figure out where the moving sprite was in relation to the background text on the screen. So what you are seeing is the sprite moving over the text and calculating the positions between 0-40 by dividing this by the total length of the sprite. There are actually two variables for this. Please watch the video to learn more.
Commodore 64 Collision 16-bit Math Logic
Later I made several posts on Lemon64.com asking how this could be accomplished. Finally I was contacted by an experienced assembly language developer who provided some tips for me. Eventually I was able to implement this logic into the game.
Now this was no easy task and involved a new learning curve. I literally had to spend a lot time learning how to use 16-bit math, which requires ROR (rotating bits) to extract the high bit values. The more complicated part was keeping track of the calculations, which must be accurate. I'll admit it still needs a lot of work.
I also decided to display the background characters on the bottom display so I could detect what character the sprite had passed over. This is very similar to the above Basic example. It is still not perfect as I mentioned, but pretty close to accurate.
Commodore 64 Scrolling Explained
It was later I realized that some viewers were still confused on how the scrolling works. So I spent some time and put together the video below in hopes of providing a more detailed explanation. This is done by showing how the screen memory is laid out in relation to the game map. Then I walked through some code examples to show where the scrolling was taking place and how it was being implemented into the logic.
Commodore 64 Vertical Scroll Refined
Before surrending defeat, I was able to get some of the scrolling map working when moving to the left, right, and down. This has become quite a challenge and still is not working. For example after I move down past a few levels and try to scroll to the right, it will work the first time. However when I begin scrolling up again the game loses focuses I get garbage on the screen. This is because the memory map is not pointing to the correct bytes in memory for the correct data to appear.
Commodore 64 Game Repository
By request of several YouTube subscribers, I created a repository so that the code could be downloaded via Github.
Questions? Ask Here