Thursday, May 21, 2015

A2 Video Streamer - Colour


Just before OzKFest 2015 I had a quick go at adding colour to the A2 Video Streamer. It was obvious that it needed some work. So began my investigation. I started with double high resolution graphics because once this was working all the other graphics modes would work as well. This is an exercise  in TV/monitor emulation and the TV/monitor does not know anything about the Apple II's video modes. It just processes the signals as it sees them. Get the lowest common denominator right and the rest will follow.


A. Monochrome.                            B. Colour block per four pixels.     C. Cross A with B.


D. AppleWin version.

The above pictures show my first attempts at colour and the AppleWin version to aim for. Actually when using the IIc with a colour adapter and watching it on my 14inch Sony monitor I get a picture that is somewhere in between screen shots C and D. However for an LCD solution the AppleWin version should be adequate for now. The video signal clock is approximately 14MHz. It's different for PAL than for NTSC but the important thing is that the colour reference is always a quarter of the video signal clock. This gives us four pixels per colour (0000 for Black, 0001 for Red, 0010 for Brown etc.) which equates to 16 colours. Now if we cut up the monochrome picture, screen shot A, into four pixels per block and apply the colours to each block we end up with screen shot B. If we do the same except displaying the colour only where the signal is white we end up with screen shot C. The double high resolution of 560x192 in monochrome mode is reduced to 140x192 when colour is introduced. The Apple IIc and IIe reference manuals call this the effective resolution but they just leave it at that. However when you look at screen shot B you can see that it's very blocky and comparing that to the actual display, screen shot D, you see that there is more to it.



If we zoom into the bottom left corner of these screens. We can see how different they are. I have drawn circles showing how the AppleWin version is made up. In the middle circle we can see that the green and yellow colour is filled in as in screen shot B. The right circle shows how the blue is left thin like in screen shot C. The left circle shows how some colours can be transformed into other colours, which is unlike B or C. This evaluation does not show a clear relationship between the colours so more investigation was needed. Generation of these displays is a common problem among computer emulator developers so where better to start than the emulator developer forums. https://github.com/AppleWin/AppleWin/issues/254

From the information read I still did not have get a clear picture of how I was going to work out the colour relationship. Without having to trawl through emulator code or work out mathematical equations from first principles I wondered if there was a simpler way.



From Issue 89 of the Compute magazine, October 1987, I was able to get an article about Chrome which is "Double Hi-Res Graphics Commands For Applesoft" and subsequently the disk image from ASIMOV which relates to this article. This allowed me to generate a few test patterns in AppleWin. The test pattern for two consecutive blocks is inadequate in explaining the colour relationship but the test pattern for three consecutive blocks is spot on. Bingo. Every block of four pixels can be determined by looking at the previous block and looking at the next block. I was able to extract this information and place it into an array of 4096 elements. This is our lookup table. In the application I have optimised this lookup table for storage but I expand it to 4096 elements during the initialization routine. This allows simple and fast processing.



The above example is taken from screen shot B and how it is used to produce the colour as shown by the left most circle in screen shot D. In step 1 we lookup the colour blocks Black, Black and Magenta. This gives us 0000 (this is a hexadecimal number ranging from 0000 to FFFF. It represents the 16 Apple II colours for each of the four pixels) which we then colour in as Black, Black, Black and Black. In step two we lookup the value for Black, Magenta and White which returns 000D and we colour the next four pixels as Black, Black, Black and Light Blue. In step 3 we lookup Magenta, White and Dark Green which returns FFF7 and results in White, White, White and Yellow. The process goes on to complete the line and page. The result is a picture as follows.



Therefore with one extra lookup table and a bit more code we get colour output. I'm happy with the result and stoked with having achieved it with such a small amount of effort. Emulation of analog equipment such as monitors or televisions can get quite complex and requires a lot of computational power to pull off. Just check out the video rendering section of this Apple II emulator - OpenEmulator https://web.archive.org/web/20120320154930/http://www.openemulator.org/screenshots.html I may have to revisit rendering when it comes to optimizing a full screen display but that's something to worry about for another day.

4 comments:

Alex Lee said...

Awesome! Congrats after finding an even more refined solution after OzKFest 2015!

Unknown said...

Hi, I've just made a little PCB with your design, uploaded the firmware to the FX2LP and it worked first try.

So happy to see colours coming from my little PAL //c, great project! Thanks a lot!

Lukazi said...

Hi Ben,

Great to hear that the information is actually being used. It's a pity hobby time is limiting as I really wanted to take this project so much further. Got a few other projects I need to knock over first.

Cheers,
Alex.

eu4 console commands said...

Make some DIY projects please do not. Make these kits