Hey...just a guick update with a couple of links...
PALpable Interest
I found some helpful Dragon folks that were interested in this project. One of them ran the code on his PAL Dragon and posted the results on this thread. Surprisingly enough, the code seems to more-or-less work "as is".
I know that the PAL CoCo's and Dragons use the same (NTSC-only) 6847 VDG chip as the NTSC machines. They have added circuitry that basically puts the VDG to sleep while extra lines are added to drive the PAL display. I had presumed that those extra horizontal lines would be visible to the software, but apparently that isn't true.
I guess the lack of visibility for those extra lines is good news for this project. OTOH, I had thought that the horizontal sync signal could be a good timing source for sound/music playback. Now I would guess that those extra "invisible" lines would break any code using the horizontal sync signal for music playback. So, if I ever want to support PAL machines in some future music-enhanced version of Fahrfall then I will have to find another way to make it work...
Show Me, Show Me, Show Me!
I posted a few more examples of pics displayed using the 44-color technique on my CoCo. They are available in an album on my Facebook page. Have a look!
Wednesday, February 13, 2013
Saturday, February 9, 2013
Back At It
Hey...anyone still there? Oh, yeah? Awesome...
CoCo Coding Contest
There is a coding contest in progress for CoCo enthusiasts, with the winner to be picked at this year's CoCoFEST! in Chicagoland. You know that I can't sit that out! But what to do?
After a little thought, I decided to use my 44-color display mode as the basis for a sliding puzzle game. I doubt if that will be the most amazing CoCo game ever, but at least it should earn me a ribbon for participation... :-)
Prep and Clean-up
I left the code for this project a bit undone last Summer. It would load in my local environment, where I use a monitor program over a serial port. But it wouldn't load under a normal Color BASIC-based environment on the CoCo or Dragon. I took a little time today to relocate the code and generate the necessary images for loading the code in such an environment.
http://www.tuxdriver.com/download/vdgtricks/
Want to PAL around?
The code for my 44-color display mode counts display lines in order to coordinate VDG register changes with which lines are currently being displayed. This counting requires the code to know how many lines are displayed in each frame, and that number is different between NTSC and PAL video modes. I only have NTSC CoCo machines, including my Tano Dragon. So, I don't have any way to test PAL-aware code.
If you are using PAL hardware and you are interested in seeing my 44-color mode in action, then maybe you can help me? It should be as easy as increasing the number of non-displayed lines to count, but that number might need to be tweaked a bit depending upon exact cycle counts and such. If you want to help me figure that out, then let me know!
For everyone else, watch this space while I roll-out my 44-color sliding puzzle game!
CoCo Coding Contest
There is a coding contest in progress for CoCo enthusiasts, with the winner to be picked at this year's CoCoFEST! in Chicagoland. You know that I can't sit that out! But what to do?
After a little thought, I decided to use my 44-color display mode as the basis for a sliding puzzle game. I doubt if that will be the most amazing CoCo game ever, but at least it should earn me a ribbon for participation... :-)
Prep and Clean-up
I left the code for this project a bit undone last Summer. It would load in my local environment, where I use a monitor program over a serial port. But it wouldn't load under a normal Color BASIC-based environment on the CoCo or Dragon. I took a little time today to relocate the code and generate the necessary images for loading the code in such an environment.
http://www.tuxdriver.com/download/vdgtricks/
Want to PAL around?
The code for my 44-color display mode counts display lines in order to coordinate VDG register changes with which lines are currently being displayed. This counting requires the code to know how many lines are displayed in each frame, and that number is different between NTSC and PAL video modes. I only have NTSC CoCo machines, including my Tano Dragon. So, I don't have any way to test PAL-aware code.
If you are using PAL hardware and you are interested in seeing my 44-color mode in action, then maybe you can help me? It should be as easy as increasing the number of non-displayed lines to count, but that number might need to be tweaked a bit depending upon exact cycle counts and such. If you want to help me figure that out, then let me know!
For everyone else, watch this space while I roll-out my 44-color sliding puzzle game!
Wednesday, August 1, 2012
Retrochallenge Wrap-up
Well, the Retrochallenge is over for this Summer. I'm sure there is now much rejoicing! In all seriousness, if you have an interest in retro-computing then you should consider taking part in next year's competitions.
I pushed-out a git tree containing the code I used to produce the images covered earlier. Much thanks go to my pal David Woodhouse for hosting my silly stuff!
git://git.infradead.org/users/linville/vdgtricks.git
If you don't know how to use git, then find a tutorial -- there are plenty out there that are at least good enough to walk you through the cloning process. If you want to know more, then buy a book!
Unfortunately for me, I can guarantee that I won't be winning the Retrochallenge this time. That is because I have been asked to help-out with the judging! Feel free to find my wishlist on Amazon if you want special consideration given to your project...just kiddin', of course... :-)
Anyway, I think this project has turned-out alright. I certainly never expected to see such good (YMMV!) output from an original CoCo. I hope others are equally impressed!
Let me know where you think I should go with this. If nothing else, I probably can produce a simple "picture compiler" that will allow for simple conversions of images to display on a CoCo in the 44-color mode. It shouldn't be too hard to make sure that it runs on Windows as well, but I might need someone willing to send some patches to support non-Linux platforms.
Beyond that, I was thinking that a "sliding puzzle" game might be a possibility. Perhaps this method could produce backdrop images for conversions of traditional games (i.e. checkers, backgammon, connect-four, etc) as well? What other ideas do you have?
Also, I have a couple more ideas that might squeeze-out a few more colors. I'm not sure when I'll get to experimenting with those ideas, but if you want to hear more about them when they happen then you'll have to stay tuned...
Come And Git It
I pushed-out a git tree containing the code I used to produce the images covered earlier. Much thanks go to my pal David Woodhouse for hosting my silly stuff!
git://git.infradead.org/users/linville/vdgtricks.git
If you don't know how to use git, then find a tutorial -- there are plenty out there that are at least good enough to walk you through the cloning process. If you want to know more, then buy a book!
Judge For Yourself
Unfortunately for me, I can guarantee that I won't be winning the Retrochallenge this time. That is because I have been asked to help-out with the judging! Feel free to find my wishlist on Amazon if you want special consideration given to your project...just kiddin', of course... :-)
Moving Forward
Anyway, I think this project has turned-out alright. I certainly never expected to see such good (YMMV!) output from an original CoCo. I hope others are equally impressed!
Let me know where you think I should go with this. If nothing else, I probably can produce a simple "picture compiler" that will allow for simple conversions of images to display on a CoCo in the 44-color mode. It shouldn't be too hard to make sure that it runs on Windows as well, but I might need someone willing to send some patches to support non-Linux platforms.
Beyond that, I was thinking that a "sliding puzzle" game might be a possibility. Perhaps this method could produce backdrop images for conversions of traditional games (i.e. checkers, backgammon, connect-four, etc) as well? What other ideas do you have?
Also, I have a couple more ideas that might squeeze-out a few more colors. I'm not sure when I'll get to experimenting with those ideas, but if you want to hear more about them when they happen then you'll have to stay tuned...
Sunday, July 29, 2012
Big Reveal
I think we have had enough background now. Let's move on to see what our efforts have brought!
The basic idea is to use two video modes to display somewhat different versions of the same original image. By alternating between these two images, we should produce an image that our eyes will blend into something that better represents the original than either does by itself.
The first implementation of this idea involved simply taking the output from my earlier efforts and modifying the code a bit to implement the continuous mode switching. The modifications were simple: relocate the data so that both screens could be resident in memory at once; and, chain the code sections together so that each mode would be displayed in turn for 1/60th of a second for each mode. In this implementation, none of the image data generation was changed at all -- both modes were still independent attempts to reproduce the original image.
The combination of the two "best effort" images does yield an improved result. But what we really want is to use the second image to compensate for quantization error in the first image. As it stands, the combined color for any given pixel is often limited to being only as good as the best match for that pixel in either of the two "best effort" images. Only if the original pixel's color was between the colors in the "best effort" images will the combined image's pixel actually be an improvement. Conversely, in most cases the resulting color for that pixel will be worse than that of the same pixel in the better of the "best effort" images!
To improve this, I decided to make one of the mode's generated image data depend on the image data generated for the other mode. The first mode's image is still generated in a "best effort" fashion. Once that image is generated, the color error for each pixel is calculated, doubled, and applied to the input for the generation of the second image. This distorts the second image in a way that brings the combined image closer to the original than either "best effort" image would be likely to achieve.
Given the above, one must wonder which mode's image is generated first? The "semi-graphics" mode is both lower resolution and less flexible with its color placement. To me, it seems like a good bet to let that remain in the role of "best effort" image. The "color graphics" mode's higher resolution and it's somewhat greater flexibility in placing colors should make it more effective at matching the distorted second image. The above is conjecture, so YMMV -- I am pleased with the results I have gotten so far.
Flicker is going to be an inevitable by-product of this technique. Nevertheless, it is a distraction. Even if we can't avoid it, we should attempt to minimize it.
AFAICT, flicker is more prominent when the luminance (aka "brightness") of the color on one screen differs significantly from the luminance of the color in the same position on the other screen. Obviously, large areas of such combinations produce more noticeable flicker as well.
As I mentioned previously, I am already using the YIQ color space for matching colors. The 'Y' part corresponds to luminance, and it is the biggest factor for matching colors in that space. Hopefully this is already helping to reduce luminance differences between the two screens. In any case, I don't have any other ideas to address this part of the problem...
It is notable that the VDG uses different border colors for "semi-graphics" (black border) and "color graphics" (black or buff, depending on CSS value) modes. By default, switching between these modes produces a large flickery mess around the border of the screen. Fortunately, clever timing allows for reconfiguring the VDG so that a single mode is always selected while the border is being drawn. The images above use this technique to minimize flicker on the screen.
The end of July is approaching, and with it will come the end of the Retrochallenge event. I'm fairly happy with where things stand, so I probably won't be adding much more to this project between now and then. I probably will try to clean-up some code, push-out a git tree, and maybe write a little "wrap-up" post...stay tuned!
Mixing It Up
The basic idea is to use two video modes to display somewhat different versions of the same original image. By alternating between these two images, we should produce an image that our eyes will blend into something that better represents the original than either does by itself.
The first implementation of this idea involved simply taking the output from my earlier efforts and modifying the code a bit to implement the continuous mode switching. The modifications were simple: relocate the data so that both screens could be resident in memory at once; and, chain the code sections together so that each mode would be displayed in turn for 1/60th of a second for each mode. In this implementation, none of the image data generation was changed at all -- both modes were still independent attempts to reproduce the original image.
| Mode Swapping w/ Independent Images |
The combination of the two "best effort" images does yield an improved result. But what we really want is to use the second image to compensate for quantization error in the first image. As it stands, the combined color for any given pixel is often limited to being only as good as the best match for that pixel in either of the two "best effort" images. Only if the original pixel's color was between the colors in the "best effort" images will the combined image's pixel actually be an improvement. Conversely, in most cases the resulting color for that pixel will be worse than that of the same pixel in the better of the "best effort" images!
To improve this, I decided to make one of the mode's generated image data depend on the image data generated for the other mode. The first mode's image is still generated in a "best effort" fashion. Once that image is generated, the color error for each pixel is calculated, doubled, and applied to the input for the generation of the second image. This distorts the second image in a way that brings the combined image closer to the original than either "best effort" image would be likely to achieve.
Given the above, one must wonder which mode's image is generated first? The "semi-graphics" mode is both lower resolution and less flexible with its color placement. To me, it seems like a good bet to let that remain in the role of "best effort" image. The "color graphics" mode's higher resolution and it's somewhat greater flexibility in placing colors should make it more effective at matching the distorted second image. The above is conjecture, so YMMV -- I am pleased with the results I have gotten so far.
| Mode Swapping w/ Error Redistribution |
Fighting Flicker
Flicker is going to be an inevitable by-product of this technique. Nevertheless, it is a distraction. Even if we can't avoid it, we should attempt to minimize it.
AFAICT, flicker is more prominent when the luminance (aka "brightness") of the color on one screen differs significantly from the luminance of the color in the same position on the other screen. Obviously, large areas of such combinations produce more noticeable flicker as well.
As I mentioned previously, I am already using the YIQ color space for matching colors. The 'Y' part corresponds to luminance, and it is the biggest factor for matching colors in that space. Hopefully this is already helping to reduce luminance differences between the two screens. In any case, I don't have any other ideas to address this part of the problem...
It is notable that the VDG uses different border colors for "semi-graphics" (black border) and "color graphics" (black or buff, depending on CSS value) modes. By default, switching between these modes produces a large flickery mess around the border of the screen. Fortunately, clever timing allows for reconfiguring the VDG so that a single mode is always selected while the border is being drawn. The images above use this technique to minimize flicker on the screen.
Winding Down
The end of July is approaching, and with it will come the end of the Retrochallenge event. I'm fairly happy with where things stand, so I probably won't be adding much more to this project between now and then. I probably will try to clean-up some code, push-out a git tree, and maybe write a little "wrap-up" post...stay tuned!
Friday, July 27, 2012
Palette Redux
In the previous couple of posts, we have discussed how to drive the CoCo's VDG to display 8 on-screen colors even when using the VDG's 4-color graphics mode. This has yielded a substantial improvement in the quality of "real life" images converted for display on the CoCo, but the results are still lackluster. In particular, the lack of black is a glaring problem in the display of many images. I think we can do better.
So, lets review our best performing options....
The "color graphics" mode with the dynamic CSS configuration gives us 8 colors on the screen at once. The palette remains a bit limited, and any given segment of 16 pixels must share the same 4-color palette. But, dithering and the ability to select different palette combinations for each row on the screen combine to enable generating images on the CoCo that well represent their source images. The biggest drawback of this mode is the lack of black in the display.
The "semi-graphics" mode provides for 8 colors on the screen and includes the ability to add black into the mix as well. But, this mode is restricted to half the horizontal resolution of the "color graphics" mode. Further, any given pair of these lower-resolution pixels is restricted to either sharing the same color or to using one color and black between the two of them. Obviously, these limitations produce more "blocky" results than one gets with the "color graphics" mode.
So, we have two mediocre options. It would be nice if we could find a way to combine the advantages of each of these modes...
It seems like the biggest problem with the CoCo's graphics is the lack of available colors. One tricky technique that can be used to increase available colors is to draw different colors on alternating screens. When those screens are alternated quickly enough (e.g. every 1/60th of a second), the eye tends to blend those colors, forming a new set of colors. Perhaps we could alternate between the "semi-graphics" mode and the 8-color "color graphics" mode, producing a larger suite of combined colors? The lack of black in the "color graphics" mode will still prevent us from having a true black for our converted images, but hopefully a gray or even a darker blue will at least be a more suitable replacement for black than the bright blue we have now.
We are already changing the VDG configuration mid-screen and even mid-line. It is, of course, also possible to change the VDG configuration between screens. In fact, this basic technique has often been used to facilitate "page flip" animations. So, let's use this technique to produce a new combined graphics mode.
I started with the earlier palette test application. To that, I added initialization of a "semi-graphics" screen buffer with a series of horizontal lines in all 8 colors plus a 9th area on the bottom right of the screen that is all black. Then, I changed the code so that after displaying the "color graphics" screen it would then reinitialize the VDG for "semi-graphics" mode. After that screen finishes, the VDG is reinitialized for the "color graphics" mode again and the whole process is repeated. The result is a display of all the available colors in the combined mode.
If my math is correct, that should give us 44 colors to use -- I counted just to be sure! That should lead to quite an improvement in our image conversions. On the downside, there is some noticeable "flicker" on the screen when using this technique. There may be ways to minimize that effect, but it is probably not completely avoidable. Hopefully the bounty of new colors will more than compensate!
Stay tuned to hear about how I'm using this combined mode for image conversions...
Ingredients
So, lets review our best performing options....
The "color graphics" mode with the dynamic CSS configuration gives us 8 colors on the screen at once. The palette remains a bit limited, and any given segment of 16 pixels must share the same 4-color palette. But, dithering and the ability to select different palette combinations for each row on the screen combine to enable generating images on the CoCo that well represent their source images. The biggest drawback of this mode is the lack of black in the display.
The "semi-graphics" mode provides for 8 colors on the screen and includes the ability to add black into the mix as well. But, this mode is restricted to half the horizontal resolution of the "color graphics" mode. Further, any given pair of these lower-resolution pixels is restricted to either sharing the same color or to using one color and black between the two of them. Obviously, these limitations produce more "blocky" results than one gets with the "color graphics" mode.
So, we have two mediocre options. It would be nice if we could find a way to combine the advantages of each of these modes...
Flip Flop
It seems like the biggest problem with the CoCo's graphics is the lack of available colors. One tricky technique that can be used to increase available colors is to draw different colors on alternating screens. When those screens are alternated quickly enough (e.g. every 1/60th of a second), the eye tends to blend those colors, forming a new set of colors. Perhaps we could alternate between the "semi-graphics" mode and the 8-color "color graphics" mode, producing a larger suite of combined colors? The lack of black in the "color graphics" mode will still prevent us from having a true black for our converted images, but hopefully a gray or even a darker blue will at least be a more suitable replacement for black than the bright blue we have now.
We are already changing the VDG configuration mid-screen and even mid-line. It is, of course, also possible to change the VDG configuration between screens. In fact, this basic technique has often been used to facilitate "page flip" animations. So, let's use this technique to produce a new combined graphics mode.
Proof Of Concept
I started with the earlier palette test application. To that, I added initialization of a "semi-graphics" screen buffer with a series of horizontal lines in all 8 colors plus a 9th area on the bottom right of the screen that is all black. Then, I changed the code so that after displaying the "color graphics" screen it would then reinitialize the VDG for "semi-graphics" mode. After that screen finishes, the VDG is reinitialized for the "color graphics" mode again and the whole process is repeated. The result is a display of all the available colors in the combined mode.
| Mode-Flipping Palette of 44 colors! |
If my math is correct, that should give us 44 colors to use -- I counted just to be sure! That should lead to quite an improvement in our image conversions. On the downside, there is some noticeable "flicker" on the screen when using this technique. There may be ways to minimize that effect, but it is probably not completely avoidable. Hopefully the bounty of new colors will more than compensate!
Stay tuned to hear about how I'm using this combined mode for image conversions...
Thursday, July 26, 2012
Pick A Color
Putting more colors on the screen is great, but it should be clear to the reader that there are certain rules that must be followed in order to make it possible to use those extra colors. If we were to draw a cartoon image, then we could allocate the colors ourselves while applying the rules manually. That seems likely to have been the process used by the Dragonfire creators. But what about converting a real-life image (i.e. a digital photograph) for display on the CoCo in eight on-screen colors?
Anyone that has ever matched paint colors knows that color matching can be a tedious and subjective process. Performing that task for the 24,576 pixels on the CoCo screen will require some automation. The first step towards automating that selection is to obtain a mathematical definition for each available color, thereby transforming the subjective process of color matching into an objective process instead.
In lieu of better information, it would be tempting simply to "guess"-timate the RGB values for the colors generated by the VDG. One might presume that each color is relatively close to an easily defined position in the RGB color space, and such a definition might even be close enough to achieve reasonable mappings. Fortunately, such a slipshod process is unnecessary -- some MESS folks figured-out a more refined palette definition based on mathematics and the VDG's datasheet.
The math required to compare two colors might not be obvious to everyone -- it wasn't originally obvious to me. After all, is "red" closer to "purple"? Or "orange"??
The RGB mapping of each color can be treated as a 3-dimensional coordinate in the RGB "color space". Once you wrap your head around that, the solution becomes more clear -- colors located nearest to one another in a color space are the colors that match each other best. The Euclidean distance between the RGB values for each color is used to determine which of the colors in the CoCo's palette is the best match for a color in the image being converted.
Now, get this -- there is more than one color space available to model color. This seems like an odd curiousity until one realizes that each color space emphasizes different aspects of color. This means that for any given pair of colors, the relative distances between those colors will differ depending on which color space is used to model them. I find that the emphasis on luminance in the YIQ color space gives it the best color matching results on the CoCo, so I convert my RGB color values to YIQ values before doing color matching comparisons.
I mentioned dithering in an earlier post. Dithering can be messy and distracting, and for old folks it looks a bit like fuzzy analog television reception. But, it can be very effective at improving color perception for a given image. So, I tend to dither my images while converting them for the CoCo.
The discussion above is just as applicable to a statically configured VDG mode as it is to the 8-color mode we have been describing. But the 8-color mode has one more wrinkle -- the palette must be set correctly for each block of pixels. I don't know of any clever way to predict which palette option is going to be the best for a given set of pixels. So, I simply do two sets of color matches for each group of pixels!
Since I can do 8 palette change for each line, I divide each line into 8 groups of 16 pixels each. I then do the color matches and calculate the accumulated color error for each set. After that, I choose the palette that produces the least total color error for each set of pixels. Finally, I record which palette I choose for each set and store the corresponding image data to the output. I later emit assembly code to perform the palette switching at the appropriate times for each line of the display. In effect, I compile the image into a binary program for the CoCo.
Initially I was concerned that the 16-pixel groups on each line would result in obvious blocks of colors from each palette on different parts of the screen. But, I think that the ability to choose different palette combinations on each line combines with the dithering to mitigate any tendency to group colors on the screen.
Well, things are looking a bit better. But I think that we can still improve upon these results -- eight colors is still a bit paltry. Next time we will look at a way to combine a couple of CoCo video modes to extend the CoCo palette even further.
Palette Definition
Anyone that has ever matched paint colors knows that color matching can be a tedious and subjective process. Performing that task for the 24,576 pixels on the CoCo screen will require some automation. The first step towards automating that selection is to obtain a mathematical definition for each available color, thereby transforming the subjective process of color matching into an objective process instead.
In lieu of better information, it would be tempting simply to "guess"-timate the RGB values for the colors generated by the VDG. One might presume that each color is relatively close to an easily defined position in the RGB color space, and such a definition might even be close enough to achieve reasonable mappings. Fortunately, such a slipshod process is unnecessary -- some MESS folks figured-out a more refined palette definition based on mathematics and the VDG's datasheet.
Matching Colors
The math required to compare two colors might not be obvious to everyone -- it wasn't originally obvious to me. After all, is "red" closer to "purple"? Or "orange"??
The RGB mapping of each color can be treated as a 3-dimensional coordinate in the RGB "color space". Once you wrap your head around that, the solution becomes more clear -- colors located nearest to one another in a color space are the colors that match each other best. The Euclidean distance between the RGB values for each color is used to determine which of the colors in the CoCo's palette is the best match for a color in the image being converted.
Now, get this -- there is more than one color space available to model color. This seems like an odd curiousity until one realizes that each color space emphasizes different aspects of color. This means that for any given pair of colors, the relative distances between those colors will differ depending on which color space is used to model them. I find that the emphasis on luminance in the YIQ color space gives it the best color matching results on the CoCo, so I convert my RGB color values to YIQ values before doing color matching comparisons.
I mentioned dithering in an earlier post. Dithering can be messy and distracting, and for old folks it looks a bit like fuzzy analog television reception. But, it can be very effective at improving color perception for a given image. So, I tend to dither my images while converting them for the CoCo.
Making Choices
The discussion above is just as applicable to a statically configured VDG mode as it is to the 8-color mode we have been describing. But the 8-color mode has one more wrinkle -- the palette must be set correctly for each block of pixels. I don't know of any clever way to predict which palette option is going to be the best for a given set of pixels. So, I simply do two sets of color matches for each group of pixels!
Since I can do 8 palette change for each line, I divide each line into 8 groups of 16 pixels each. I then do the color matches and calculate the accumulated color error for each set. After that, I choose the palette that produces the least total color error for each set of pixels. Finally, I record which palette I choose for each set and store the corresponding image data to the output. I later emit assembly code to perform the palette switching at the appropriate times for each line of the display. In effect, I compile the image into a binary program for the CoCo.
| Test Image In 8 On-Screen Colors |
Initially I was concerned that the 16-pixel groups on each line would result in obvious blocks of colors from each palette on different parts of the screen. But, I think that the ability to choose different palette combinations on each line combines with the dithering to mitigate any tendency to group colors on the screen.
Well, things are looking a bit better. But I think that we can still improve upon these results -- eight colors is still a bit paltry. Next time we will look at a way to combine a couple of CoCo video modes to extend the CoCo palette even further.
Wednesday, July 25, 2012
Palette Expansion
The graphics output options for the original CoCo are a bit sad when using a static VDG configuration. We are forced either to give-up half of our available colors (and black) to maximize resolution, or we must give-up half of our available resolution and accept some odd color placement rules to maximize our available colors. Neither option provides particularly satisfactory results.
The VDG uses the inputs on a number of pins to determine its current video mode. On the CoCo, this is used to switch between alphanumeric and semi-graphjcs modes automatically. The highest-order bit of each byte of screen data is fed back into the pin that selects between those modes, allowing each character to be displayed as intended. The selection between inverted and non-inverted characters is handled similarly.
In fact, there are other VDG-equipped machines that extend this same technique to control the pin that selects between the available palettes (i.e. the CSS pin). But for better or for worse, the CoCo has to use software to control the CSS value. So that begs the question of whether or not the CoCo can change the CSS value quickly enough to produce more colorful displays. In fact, the CoCo game Dragonfire does exactly this. While the Dragonfire display is a bit cartoon-ish, it suggests that more colorful displays are possible on the CoCo.
Knowing that we can switch the active palettes "on the fly", we are now faced with the task of doing so in time to display what we want when we want it. To do that, we have to figure-out how often we can change the CSS value, and when to do so.
Let's start with the 'when' part... The CoCo hardware can generate an interrupt for each line of the (almost-)NTSC display, or 262 times for every frame. Processing these interrupts through the IRQ vector would take a lot of cycles -- enough to miss the beginning of the actively displayed portion of the next line! Fortunately, the 6809 provides a SYNC instruction that basically halts the processor until the next interrupt is signalled. This allows us to synchronize with the interrupt timing at a minimal cost of CPU time. A little extra processing lets us skip the 70 lines during the vertical blanking period (i.e. the non-active portion of the display at the top and bottom of the screen). After that, some judicious use of NOP instructions and cycle counting allows us to time our CSS updates as necessary.
Each VDG clock cycle corresponds to one "color clock" cycle on the NTSC display, or one color pixel on the screen. The CoCo CPU clock is the VDG clock divided by 4, so one CPU clock corresponds to 4 color pixels on the screen. The fastest way I have found to update the CSS value is to preset the A and B registers and then use STA or STB to store the appropriate CSS value to the register that controls the VDG mode (including the CSS input of the VDG). With the 6809's Direct Page register set appropriately, those STA/STB instructions each take 4 CPU cycles. That corresponds to 16 color pixels on the screen during each CSS update, allowing for 8 CSS updates per 128-pixel line. Presetting the CSS value could allow for up to 9 CSS values (the preset CSS value and 8 updates) per line, with each CSS value corresponding to a different palette selection.
With all that figured-out, it seems prudent to write something to prove that this all works! So, I wrote some boilerplate code to properly time the CSS updates and to divide each line into eight 16-pixel sections. I added some code that initialized the screen buffer to include the appropriate pixel data for a rainbow of colors, accounting for the changing palettes in each section.
Keep in mind that for any given byte of screen data, only four colors are available. Yet, there are eight colors displayed on each line. Now we are getting somewhere! Stay tuned to hear about how I use this to improve the display of a real-life image... :-)
CoCo Chameleon
The VDG uses the inputs on a number of pins to determine its current video mode. On the CoCo, this is used to switch between alphanumeric and semi-graphjcs modes automatically. The highest-order bit of each byte of screen data is fed back into the pin that selects between those modes, allowing each character to be displayed as intended. The selection between inverted and non-inverted characters is handled similarly.
In fact, there are other VDG-equipped machines that extend this same technique to control the pin that selects between the available palettes (i.e. the CSS pin). But for better or for worse, the CoCo has to use software to control the CSS value. So that begs the question of whether or not the CoCo can change the CSS value quickly enough to produce more colorful displays. In fact, the CoCo game Dragonfire does exactly this. While the Dragonfire display is a bit cartoon-ish, it suggests that more colorful displays are possible on the CoCo.
Timing Is Everything
Knowing that we can switch the active palettes "on the fly", we are now faced with the task of doing so in time to display what we want when we want it. To do that, we have to figure-out how often we can change the CSS value, and when to do so.
Let's start with the 'when' part... The CoCo hardware can generate an interrupt for each line of the (almost-)NTSC display, or 262 times for every frame. Processing these interrupts through the IRQ vector would take a lot of cycles -- enough to miss the beginning of the actively displayed portion of the next line! Fortunately, the 6809 provides a SYNC instruction that basically halts the processor until the next interrupt is signalled. This allows us to synchronize with the interrupt timing at a minimal cost of CPU time. A little extra processing lets us skip the 70 lines during the vertical blanking period (i.e. the non-active portion of the display at the top and bottom of the screen). After that, some judicious use of NOP instructions and cycle counting allows us to time our CSS updates as necessary.
Each VDG clock cycle corresponds to one "color clock" cycle on the NTSC display, or one color pixel on the screen. The CoCo CPU clock is the VDG clock divided by 4, so one CPU clock corresponds to 4 color pixels on the screen. The fastest way I have found to update the CSS value is to preset the A and B registers and then use STA or STB to store the appropriate CSS value to the register that controls the VDG mode (including the CSS input of the VDG). With the 6809's Direct Page register set appropriately, those STA/STB instructions each take 4 CPU cycles. That corresponds to 16 color pixels on the screen during each CSS update, allowing for 8 CSS updates per 128-pixel line. Presetting the CSS value could allow for up to 9 CSS values (the preset CSS value and 8 updates) per line, with each CSS value corresponding to a different palette selection.
Putting Things Together
With all that figured-out, it seems prudent to write something to prove that this all works! So, I wrote some boilerplate code to properly time the CSS updates and to divide each line into eight 16-pixel sections. I added some code that initialized the screen buffer to include the appropriate pixel data for a rainbow of colors, accounting for the changing palettes in each section.
| 8 On-Screen Colors from VDG |
Keep in mind that for any given byte of screen data, only four colors are available. Yet, there are eight colors displayed on each line. Now we are getting somewhere! Stay tuned to hear about how I use this to improve the display of a real-life image... :-)
Subscribe to:
Posts (Atom)