VIC-II high resolution bit mapping mode
Today I stopped playing with the text mode and entered bit mapping mode ( or, for modern people - bitmap mode ).
VIC-II, C64's graphics chip allows for resolutions of up to 320x200. In text mode that display is divided into 40x25 ( 1000 continuous characters ), each of which is 8x8 pixels big. As I mentioned previously, the characters are stored as 8 bytes, with each bit being either or on off, and making the pixel respectively the color of the character or the color of the background.
This is all fine and dandy in text mode, but how does the high res gfx mode look like? First of all - in high res mode, each 8x8 pixel block can have only 2 colors, much like the text mode. The change is that not the color RAM governs it ( the 0xD800-0xDBE7 ), but the characters in the screen memory ( 0x400-0x7E7 ). How does it work precisely? Each byte consists of lower and higher 4 bits. Low bits are interpreted as the color for background ( off state ), high bits are interpreted as the color for foreground ( on state ). To have first char ( upper left 8x8 pixels ) have black background and white foreground, poke its position ( 1024 or 0x400 ) with 0 ( for black background ) + 16 * 1 ( for white foreground ). Green-blue would be 5 + 16 * 6. Etc. Btw, for color values refer to booklet, wiki page on VIC-II or any other source you can think of.
Ok, that's how the colors are picked. How about the bitmap itself? Well, things are bit complicated here. You designate a bitmap area, and poke it. Bitmap area is 8000 bytes long ( 8 bytes per 8x8 block, 1000 chars ), and it's stored on per-char basis. That means first 8 bytes are first character on the screen, next 8 bytes are the second character, and so forth. Makes for a really confusing plotting when you're trying to do some drawing.
It's not that bad though, and the C64 booklet is quick to help.
I converted yesterday's code to bitmap mode, and here's the result:
It took AGES to render ( minutes, even after turning emulator speed to 2500% of original C64 ). Clearly, it's because I've done it in BASIC and without any optimisations, but at a depth of 16 it looks really nice.
If anybody wants the code, here it is:
sc = 0: pc = 1 for i = 1024 to 2023 poke i,sc+16*pc next poke 53265,peek(53265)or 32 poke 53272,peek(53272)or 8 for i=8192 to 16191 poke i,0 next i REM CLEARED SCREEN WHITE offset = 8192 for x = 0 to 319 for y = 0 to 199 ch=int(x/8) ro=int(y/8) ln= y and 7 by = offset + ro*320+8*ch+ln bi = 7-( x and 7 ) x0 = ((x/320) * 3.5 - 2.5) y0 = ((y/200) * 2 - 1) iter = 0 maxiter = 2 a = 0 b = 0 if a*a + b*b < 4 then goto 27 goto 34 if iter < maxiter then goto 29 goto 34 atemp = a*a-b*b+x0 b = 2*a*b + y0 a = atemp iter = iter + 1 goto 25 if iter > maxiter then goto 36 poke by,peek(by)or(2^BI) next y next x
Just add line numbers as your text editor shows them and you're ready to go. Oh yeah, if you're typing it on VICE, ^ symbol is the upper arrow and it's bound to DEL. And remember, to quit the GFX mode, use ESC-PGUP.
See you next time, when I'll be adding more colors to the high res image!
Also, I have found a website with over 2 GiB worth of old C64 books with awesome titles like 'Artificial Intelligence projects on C64', 'DIY robotics and sensors using C64', 'Make your C64 Sing', 'Start Programming with GORTEK AND THE MICROCHIPS' or 'Will you still love me when I'm 64' :DDDD
The website is here: http://www.bombjack.org/commodore/books.htm