User Tools

Site Tools


base:opening_up_the_borders_-_a_further_explanation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
base:opening_up_the_borders_-_a_further_explanation [2016-03-13 22:07] – Standardized formatting of the main heading ftcbase:opening_up_the_borders_-_a_further_explanation [2016-03-13 22:08] (current) – Standardized headings ftc
Line 5: Line 5:
 Location: http://www.thehilander.nl Location: http://www.thehilander.nl
  
-=== Introduction ===+===== Introduction =====
 When I read articles by other writers I am always happy that they are willing to share their knowledge. However, at the end of reading some articles I am left with questions. One of those articles is Pasi ‘Albert’ Ojala's "Opening up the borders". A great article with lots of information and example code that works right out of the gate. But there's so much information besides what is necessary to open those borders, that I am left wondering what it all means. With this article I would like to add (and maybe chip away) content that will hopefully help you understand the subject even if you had little prior knowledge.  When I read articles by other writers I am always happy that they are willing to share their knowledge. However, at the end of reading some articles I am left with questions. One of those articles is Pasi ‘Albert’ Ojala's "Opening up the borders". A great article with lots of information and example code that works right out of the gate. But there's so much information besides what is necessary to open those borders, that I am left wondering what it all means. With this article I would like to add (and maybe chip away) content that will hopefully help you understand the subject even if you had little prior knowledge. 
  
 Please note that I shall use assembly language for the MOS 6502/6510 inside a PAL Commodore 64. I am using the Kick Assembler format and I shall explain as many language constructs as I think is necessary. Please note that I shall use assembly language for the MOS 6502/6510 inside a PAL Commodore 64. I am using the Kick Assembler format and I shall explain as many language constructs as I think is necessary.
  
-=== The Challenge ===+===== The Challenge =====
 When you boot up the C64 it shows a character screen of 40 columns and 25 lines surrounded by borders. To be more specific, there are border areas directly above and below the text area. There are also borders to the left and the right of the text area. This description leaves the four corners, that is the areas not directly above, below or beside the text area. This article is mostly concerned with the border areas directly below and above the text area. When you boot up the C64 it shows a character screen of 40 columns and 25 lines surrounded by borders. To be more specific, there are border areas directly above and below the text area. There are also borders to the left and the right of the text area. This description leaves the four corners, that is the areas not directly above, below or beside the text area. This article is mostly concerned with the border areas directly below and above the text area.
  
Line 17: Line 17:
 We want to be able to utilise the border areas directly above and below the text area. Right off the bat I can tell you that we won't just be able to display any text there, but we could place sprites there. All we can do is to prevent the VIC-2 from drawing the borders but we will need to apply a dirty trick to achieve it. We want to be able to utilise the border areas directly above and below the text area. Right off the bat I can tell you that we won't just be able to display any text there, but we could place sprites there. All we can do is to prevent the VIC-2 from drawing the borders but we will need to apply a dirty trick to achieve it.
  
-=== The Theory ===+===== The Theory =====
 Alright, here's how it's supposed to work. After the VIC-2 has finished drawing all the characters on screen it starts drawing the border. Basically this process consists of repeatedly drawing something out of a fixed memory location (I'll come back to this later) and in a set color, namely the border color. Where the VIC-2 normally busies itself with reading information from RAM for every character, it behaves differently while drawing the borders. This border drawing is not an active process; it stops reading bytes from RAM for every location. But rather the VIC-2 draws a single character until it reaches the top of the screen again. Once there it draws more border color (which is the top border) until the text area is to be drawn again. What we want to do is to tell the VIC-2 to not draw border. But there's no feature built in to handle that. So we have to create a situation where the VIC-2 is tricked in a way so that the color switch from text area color to border color is skipped. That way the VIC-2 will simply keep drawing text area color, which is exactly what we want. This is where our trickery starts! Alright, here's how it's supposed to work. After the VIC-2 has finished drawing all the characters on screen it starts drawing the border. Basically this process consists of repeatedly drawing something out of a fixed memory location (I'll come back to this later) and in a set color, namely the border color. Where the VIC-2 normally busies itself with reading information from RAM for every character, it behaves differently while drawing the borders. This border drawing is not an active process; it stops reading bytes from RAM for every location. But rather the VIC-2 draws a single character until it reaches the top of the screen again. Once there it draws more border color (which is the top border) until the text area is to be drawn again. What we want to do is to tell the VIC-2 to not draw border. But there's no feature built in to handle that. So we have to create a situation where the VIC-2 is tricked in a way so that the color switch from text area color to border color is skipped. That way the VIC-2 will simply keep drawing text area color, which is exactly what we want. This is where our trickery starts!
  
Line 26: Line 26:
 Granted, this is a nasty trick and definitely not a feature intended by the C64 designers. Which means we will have to live with whatever the VIC-2 leaves, which isn't much as you will see. Granted, this is a nasty trick and definitely not a feature intended by the C64 designers. Which means we will have to live with whatever the VIC-2 leaves, which isn't much as you will see.
  
-=== Garbage ===+===== Garbage =====
 We haven't coded a single line yet, but imagine we have. Imagine we've opened up the borders by setting the VIC-2 from 25 to 24 lines at the end of drawing the last scan line of the last character line using a raster interrupt. Imagine the clear dark blue area the VIC-2 draws in what would normally be the border area. Well, don't attach too much to that image because there will be garbage. Black garbage to be precise.  We haven't coded a single line yet, but imagine we have. Imagine we've opened up the borders by setting the VIC-2 from 25 to 24 lines at the end of drawing the last scan line of the last character line using a raster interrupt. Imagine the clear dark blue area the VIC-2 draws in what would normally be the border area. Well, don't attach too much to that image because there will be garbage. Black garbage to be precise. 
  
Line 33: Line 33:
 So whatever is there, the VIC-2 will draw to the screen, using a character color of 0, being black. And that's what we have to deal with. So if we simply cleared $3FFF, the VIC-2 would just draw nothing. But this is where Pasi shows what he can do and introduces us to some more advanced stuff that I'll talk about as well. So whatever is there, the VIC-2 will draw to the screen, using a character color of 0, being black. And that's what we have to deal with. So if we simply cleared $3FFF, the VIC-2 would just draw nothing. But this is where Pasi shows what he can do and introduces us to some more advanced stuff that I'll talk about as well.
  
-=== Side note on fancy wobbling ===+===== Side note on fancy wobbling =====
 Naturally dear old Albert wasn't satisfied with just printing garbage or spaces in the borders. He does a little trick. I won't explain it completely here but it comes down to this. He copies character shapes from the character ROM area to RAM and then switches the ROM out of the memory map. Next he copies the values from RAM to $3FFF. All of it? Yes. Naturally the CPU will overwrite whatever is in $3FFF, but remember that the VIC-2 is 8 times faster than the CPU and will draw whatever it finds in $3FFF each time it looks. So when the CPU is ready to change the value of $3FFF, the VIC-2 has already drawn the character that was there completely.  Naturally dear old Albert wasn't satisfied with just printing garbage or spaces in the borders. He does a little trick. I won't explain it completely here but it comes down to this. He copies character shapes from the character ROM area to RAM and then switches the ROM out of the memory map. Next he copies the values from RAM to $3FFF. All of it? Yes. Naturally the CPU will overwrite whatever is in $3FFF, but remember that the VIC-2 is 8 times faster than the CPU and will draw whatever it finds in $3FFF each time it looks. So when the CPU is ready to change the value of $3FFF, the VIC-2 has already drawn the character that was there completely. 
 Now if that wasn't enough Albert also wants to show off is programming prowess by making the text wobble. He does so by defining the mathematical equivalent of a sinus wave in memory and changing the horizontal scrolling according to those values. This makes the text do its fancy wobble which looks great. But it has nothing to do with opening up the borders so I'll just leave it for what it is. Now if that wasn't enough Albert also wants to show off is programming prowess by making the text wobble. He does so by defining the mathematical equivalent of a sinus wave in memory and changing the horizontal scrolling according to those values. This makes the text do its fancy wobble which looks great. But it has nothing to do with opening up the borders so I'll just leave it for what it is.
  
-=== Side note on side borders ===+===== Side note on side borders =====
 In this article I've chosen to write about the areas directly above and below the text area because our trick only affects those areas. There are however other areas we call 'border', like the areas to the left and right of the screen. We can make those areas disappear as well! Quite magically the same trick works here, but we need to switch between 38 and 40 column modes at the right moment. A tad more difficult and beyond the scope of this article so we'll just forget about that one for now. In this article I've chosen to write about the areas directly above and below the text area because our trick only affects those areas. There are however other areas we call 'border', like the areas to the left and right of the screen. We can make those areas disappear as well! Quite magically the same trick works here, but we need to switch between 38 and 40 column modes at the right moment. A tad more difficult and beyond the scope of this article so we'll just forget about that one for now.
  
-=== Side note on scrolling lines ===+===== Side note on scrolling lines =====
 At this point in the article I'd like to say a few words about Pasi ‘Albert’ Ojala's article. In it he goes into a technique called "scrolling". While the term is the same used in soft scrolling characters (either vertically or horizontally), this scrolling is an entirely different thing which has to do with so called bad lines. So here goes: the C64 was designed primarily to draw character screens. Let's get our terminology correct here: there's scan lines and character lines. Each character line is 8 scan lines high. At the start of every character line the VIC-2 retrieves image and color information that it requires to draw be able to draw the next line. The VIC-2 needs the data and address bus to do that. There's only so much time to achieve this. You should know that each clock tick in the system is divided into two phases: the first phase is for the VIC-2 chip, the second for the CPU. Each gets equal time to use the data and address bus. But when the VIC-2 needs to fetch data it claims more time. The CPU gets much less time consequently. The scan lines at which this happens are called bad lines because of this reduction of CPU time.  At this point in the article I'd like to say a few words about Pasi ‘Albert’ Ojala's article. In it he goes into a technique called "scrolling". While the term is the same used in soft scrolling characters (either vertically or horizontally), this scrolling is an entirely different thing which has to do with so called bad lines. So here goes: the C64 was designed primarily to draw character screens. Let's get our terminology correct here: there's scan lines and character lines. Each character line is 8 scan lines high. At the start of every character line the VIC-2 retrieves image and color information that it requires to draw be able to draw the next line. The VIC-2 needs the data and address bus to do that. There's only so much time to achieve this. You should know that each clock tick in the system is divided into two phases: the first phase is for the VIC-2 chip, the second for the CPU. Each gets equal time to use the data and address bus. But when the VIC-2 needs to fetch data it claims more time. The CPU gets much less time consequently. The scan lines at which this happens are called bad lines because of this reduction of CPU time. 
  
Line 48: Line 48:
 Please remember that these are just side notes. They have nothing to do with opening up the borders but I am mentioning them because they appear in Pasi's article and I thought they deserved some extra attention. Now let's put all the side notes aside and go back to opening up them borders. Please remember that these are just side notes. They have nothing to do with opening up the borders but I am mentioning them because they appear in Pasi's article and I thought they deserved some extra attention. Now let's put all the side notes aside and go back to opening up them borders.
   
-=== The Code ===+===== The Code =====
 Some notes on the code. In Kick Assembler the ".pc" directive sets the program counter. There is a macro called "BasicUpstart()" which generates a basic program which starts the machine language program.  Some notes on the code. In Kick Assembler the ".pc" directive sets the program counter. There is a macro called "BasicUpstart()" which generates a basic program which starts the machine language program. 
 Using constructs like <irq and >irq resolves into the least significant byte and most significant byte of a 16 bit address respectively. Using constructs like <irq and >irq resolves into the least significant byte and most significant byte of a 16 bit address respectively.
Line 262: Line 262:
  
 </code> </code>
- 
  
base/opening_up_the_borders_-_a_further_explanation.txt · Last modified: 2016-03-13 22:08 by ftc