VIC-20 Part 3 - Drawing the horizontal line
I thought that drawing a horizontal line is a good next step and would be an easy job, but it turns out that it is a pretty complex task and after completion, I am not sure there is any use for it in a game (shooting maybe?). I can only say it was a nice exercise and I learn a lot about the VIC-20.
Few words about the screen
On the PAL version of the VIC-20, when the screen is rendered the raster beam scans it from top to down and right to left 50 times per second (50 Hz frequency), and every time it draws 312 lines of which 284 are visible and 28 are rendered above the screen outside of the visible area. It means that drawing a single line takes about 71 CPU cycles (1108405 Hz/50 Hz/312 lines = 71 cycles).
The screen is split into two parts:
- The inner part, which has 176x184 pixels resolution, where 22 columns and 23 rows of characters, each of 8x8 pixels size can be displayed (22*8=176, 23*8=184).
- I will be drawing the horizontal line inside the inner screen part.
- The fixed-color (the color can be changed) border on the edges of the screen.
When you see the VIC-20 screen you notice immediately that displayed pixels are not square, but rectangular - they are wider than they are high. The inner part of the screen (with the resolution of 176x184px) has an aspect ratio of 22:23 (it is slightly narrower than wider), while the PAL image has a ratio of 4:3, hence is landscape oriented. When the screen is rendered it must be stretched as shown below:
How to draw the line?
The chip responsible for handling everything related to the graphics rendered on the screen and the video output is called VIC (Video Interface Chip) and it is the second most important chip besides the 6502 soldered on the VIC-20 mainboard. The NTSC version of the chip is numbered 6560 and the PAL version number is 6561.
The chip was so important that the Commodore VIC-20 was named after it. You might be wondering from where the number 20 come. It could be the ROM size, which is 20 KB, but other reasons can be found on the internet:
Regarding the name, Michael Tomczyk, (manager of the VIC project) recalls: "VIC sounded like a truck driver, so I insisted on attaching a number. I picked '20' and when Jack Tramiel asked, 'Why 20?' I replied, 'because it's a friendly number and this has to be a friendly computer. ' He agreed. The number 20 has no relation to any technical feature - just my idea of a friendly-sounding number. That sounds a bit bizarre looking back on it, but we did a lot of things by instinct in those days."
VIC-20 has memory mapped architecture, which means it uses the same address space to address both memory and I/O devices including the VIC chip. The VIC has assigned the addressable block of RAM of 16 locations $9000- $900F.
There are three memory locations we need to use:
- $9004: It identifies the upper 8 bits of the TV raster counter, where is the index of the line that is being drawn on the TV screen.
- $9003: Bit 7 holds the lowest bit of the TV raster counter and therefore its value alternates between 0 and 1 depending on if the even or odd line is being drawn.
- When values of $9004 and bit 7 of $9003 are put together they make the complete nine-bit long address of actual the TV screen line.
- $900F: It controls the background color:
- Bits 0-2 are used to hold the border color
- Bits 4-7 hold the background color of the inner part of the screen
The algorithm works so that it constantly checks the values $9004 and $9003 to determine the index of the drawn line and, once the line is found, cit changes the background color in $900F. Subsequently, it is necessary to wait until the whole line is drawn, then change the color again and wait again for the whole line to be drawn. The result is:
Escape From Rexal (VIC-20)
An attempt to create a game on the VIC-20 without any knowledge
Status | In development |
Author | 8bitsten |
Genre | Platformer |
Tags | VIC-20 |
More posts
- VIC-20 Part 5 - Moving a text: How to wait?Jan 01, 2022
- VIC-20 Part 4 - Inside the cartridgeDec 31, 2021
- VIC-20 Part 2 - Finally somethingDec 12, 2021
- VIC-20 Part 1 - Meet the 8bit beastDec 11, 2021
Leave a comment
Log in with itch.io to leave a comment.