** New Frontiers in VIC-Hires-Graphics, Part 12

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
tokra
Vic 20 Scientist
Posts: 1120
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

** New Frontiers in VIC-Hires-Graphics, Part 12

Post by tokra »

This will explain how the graphic mode used in the VIC can again-demo came about.

After last years release of the MFLI-mode for the PAL VIC-20, I was looking for new frontiers on the VIC. I knew the NTSC VIC-20 had an interlace feature, however apart from a small font-demo by Marko Mäkelä I could not find any other software using this.

With the things I learned in the MFLI-mode I thought about what might be possible on an NTSC-machine, but first I had to get the hardware AND make sure I could display it on my monitor. eslapion was kind enough to sell me a working VIC-20 and ship it over to Germany. This one being the CR-model I could use a european standard VIC20/C64 power supply on it. To be able to actually display a picture I found a cheap analogue converter that translates NTSC to PAL60, thus not messing with the picture digitally, which was essential in checking the interlace-effect worked.

Some weeks after I got the machine I had a simple display routine running. This was actually simpler to code than last years MFLI-mode for PAL, because much of the knowledge could be applied, and the actual graphic layout was a little simpler as well, see here:

Code: Select all

Picture for even lines:
d0 = dynamic line 0 ($0158-$01ff)
d1 = dynamic line 1 ($00b0-$0157)
nx = non dynamic lines (n1-n22)

             Update d0
             Update d0
             Update d1
Line 01e:d0  Update d1 char  63- 43 ($01ff-$0158) video $1000-$1014 charmem at $0000 $c8
Line 02e:d1  Update d0 char  42- 22 ($0157-$00b0) video $1015-$102b charmem at $0000 $c8
Line 03e:n1  Update d0 char  66- 86 ($1210-$12b7) video $102a-$103e charmem at $1000 $cc
Line 04e:d0  Update d1 char  63- 43 ($01ff-$0158) video $103f-$1053 charmem at $0000 $c8
Line 05e:n2  Update d1 char  87-107 ($12b8-$135f) video $1054-$1068 charmem at $1000 $cc
Line 06e:d1  Update d0 char  42- 22 ($0157-$00b0) video $1069-$107d charmem at $0000 $c8
Line 07e:n3  Update d0 char 108-128 ($1360-$1407) video $107e-$1092 charmem at $1000 $cc
Line 08e:d0  Update d1 char  63- 43 ($01ff-$0158) video $1093-$10a7 charmem at $0000 $c8
Line 09e:n4  Update d1 char 129-149 ($1408-$14af) video $10a8-$10bc charmem at $1000 $cc
Line 10e:d1  Update d0 char  42- 22 ($0157-$00b0) video $10bd-$10d1 charmem at $0000 $c8
Line 11e:n5  Update d0 char 150-170 ($14b0-$1557) video $10d2-$10e6 charmem at $1000 $cc
Line 12e:d0  Update d1 char  63- 43 ($01ff-$0158) video $10e7-$11fb charmem at $0000 $c8
Line 13e:n6  Update d1 char 171-191 ($1558-$15ff) video $10fc-$1110 charmem at $1000 $cc
Line 14e:d1  Update d0 char  42- 22 ($0157-$00b0) video $1111-$1125 charmem at $0000 $c8
Line 15e:n7  Update d0 char 192-212 ($1600-$16a7) video $1126-$113a charmem at $1000 $cc
Line 16e:d0  Update d1 char  63- 43 ($01ff-$0158) video $113b-$114f charmem at $0000 $c8
Line 17e:n8  Update d1 char 213-233 ($16a8-$174f) video $1150-$1164 charmem at $1000 $cc
Line 18e:d1  Update d0 char  42- 22 ($0157-$00b0) video $1165-$1179 charmem at $0000 $c8
Line 19e:n9  Update d0 char 234-254 ($1750-$17f7) video $117a-$118e charmem at $1000 $cc
Line 20e:d0  Update d1 char  63- 43 ($01ff-$0158) video $118f-$11a3 charmem at $0000 $c8
Line 21e:n10 Update d1 char   0- 20 ($0000-$00a7) video $11a4-$11b8 charmem at $0000 $c8 -> here ldx for switch to $1800 and nop
Line 22e:d1  Update d0 char  42- 22 ($0157-$00b0) video $11b9-$11cd charmem at $0000 $c8
Line 23e:n11 Update d0 char   0- 20 ($1800-$18a7) video $11ce-$11e2 charmem at $1800 $ce
Line 24e:d0            char  63- 43 ($01ff-$0158) video $11e3-$11f7 charmem at $0000 $c8

Picture for odd lines:

             Update d0
             Update d0
             Update d1
Line 01o:d0  Update d1 char  63- 43 ($01ff-$0158) video $0200-$0214 charmem at $0000 $88
Line 02o:d1  Update d0 char  42- 22 ($0157-$00b0) video $0215-$022b charmem at $0000 $88
Line 03o:n12 Update d0 char  21- 41 ($18a8-$194f) video $022a-$023e charmem at $1800 $8e
Line 04o:d0  Update d1 char  63- 43 ($01ff-$0158) video $023f-$0253 charmem at $0000 $88
Line 05o:n13 Update d1 char  42- 62 ($1950-$19f7) video $0254-$0268 charmem at $1800 $8e
Line 06o:d1  Update d0 char  42- 22 ($0157-$00b0) video $0269-$027d charmem at $0000 $88
Line 07o:n14 Update d0 char  66- 86 ($1a10-$1ab7) video $027e-0$292 charmem at $1800 $8e
Line 08o:d0  Update d1 char  63- 43 ($01ff-$0158) video $0293-$02a7 charmem at $0000 $88
Line 09o:n15 Update d1 char  87-107 ($1ab8-$1b5f) video $02a8-$02bc charmem at $1800 $8e
Line 10o:d1  Update d0 char  42- 22 ($0157-$00b0) video $02bd-$02d1 charmem at $0000 $88
Line 11o:n16 Update d0 char 108-128 ($1b60-$1c07) video $02d2-$02e6 charmem at $1800 $8e
Line 12o:d0  Update d1 char  63- 43 ($01ff-$0158) video $02e7-$02fb charmem at $0000 $88
Line 13o:n17 Update d1 char 129-149 ($1c08-$1caf) video $02fc-$0310 charmem at $1800 $8e
Line 14o:d1  Update d0 char  42- 22 ($0157-$00b0) video $0311-$0325 charmem at $0000 $88
Line 15o:n18 Update d0 char 150-170 ($1cb0-$1d57) video $0326-$033a charmem at $1800 $8e
Line 16o:d0  Update d1 char  63- 43 ($01ff-$0158) video $033b-$034f charmem at $0000 $88
Line 17o:n19 Update d1 char 171-191 ($1d58-$1dff) video $0350-$0364 charmem at $1800 $8e
Line 18o:d1  Update d0 char  42- 22 ($0157-$00b0) video $0365-$0379 charmem at $0000 $88
Line 19o:n20 Update d0 char 192-212 ($1e00-$1ea7) video $037a-$038e charmem at $1800 $8e
Line 20o:d0  Update d1 char  63- 43 ($01ff-$0158) video $038f-$03a3 charmem at $0000 $88
Line 21o:n21 Update d1 char 213-233 ($1ea8-$1f4f) video $03a4-$03b8 charmem at $1800 $8e
Line 22o:d1  Update d0 char  42- 22 ($0157-$00b0) video $03b9-$03cd charmem at $0000 $88
Line 23o:n22 Update d0 char 234-254 ($1f50-$1ff7) video $03ce-$03e2 charmem at $1800 $8e
Line 24o:d0            char  63- 43 ($01ff-$0158) video $03e3-$03f7 charmem at $0000 $88
Essentially 2 displayed lines update one dynamic line (the process is a lot more complicated for the original PAL-MFLI-mode). This made addressing the bitmap-bytes simpler later on. It was a little more tricky to find out how the interlace-mode worked, especially since I could not test this in VICE. In the end I found out that a standard NTSC-VIC picture has 261 lines while a full-interlace picture has 263 Odd-Lines and 262 Even-Lines. The Odd-lines come first (=top). To sync the picture you just have to wait for the raster-counter ($9004) to reach 131 - it only does so in interlace-mode on the odd-picture. That's why in VICE the viewer will just keep hanging, it can never reach that number. To make testing in VICE possible I just used conditional assembly and some shorter waiting loops by initializing wait-counters differently.

You might wonder how the resolution 168x384 came about. Well, the horizontal 168 is the resolution that allowed for updating the 3 colors in $900f and $900e per line while still being able to do the updates for the dynamic lines fast enough. 384 was just the natural limit because of multiple memory constraints, not the least of which was the 1K color-RAM. 168x384 uses 1008 of those 1024 bytes. I wanted to have a separate color-RAM for each interlace-half-picture.

Once the mode was set up, I needed pictures. I converted an old .PGM-converter from Mike for hires-pictures and Mike himself provided an improved version of his converter. Maybe he can tell you more about this. I provide both the old and color-conversion-improved version of his converter in my archive, since I found playing around a little with the pictures and its gamma values will sometimes provide a better result.

That's about it. Of course I still have some ideas left for possible graphic modes for the NTSC and PAL VIC-20, but I'll keep those ideas for another post in this series.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: ** New Frontiers in VIC-Hires-Graphics, Part 12

Post by Mike »

tokra wrote:Mike himself provided an improved version of his converter [...] he can tell you more about this.
The converter for MIFLI was derived from the one for MFLI pictures, that I wrote last year - with a twist:

There are two half-pictures, 'fields', interleaved. Each field has a colour resolution of 8x8 pixels in hi-res, or 4x8 pixels in multi-colour, these are corresponding to the 'attribute cells' of single height characters. The converter only uses the multi-colour mode.

A heuristic first determines the dominant colour for each attribute cell. This can be any one of the first 8 colours. But now, interlace allows to mix two different of these 8 colours, in principle, for the resulting interleaved 4x16 pixel attribute cell. However, in most cases both colours come out identical (it would require a 'striped' structure of strictly different colours for a different outcome). I then had the idea to simply enforce such a mixing - the heuristic should not work separately on the odd and even fields then, rather it now takes the 4x16 attribute cell as whole, and compares against the 8 standard foreground colours and a set of mix-colours derived from allowed colour combinations of similar luminances (white-yellow, cyan-green, red-purple, etc.) This helps a lot to minimize block artifacts, which were slightly more visible with MFLI (for example yellow or cyan blocks in bright areas, blue blocks in dark areas).

As with MFLI, once the foreground colours are determined, Floyd-Steinberg Dithering is applied. For each line, the combination of background, border and auxiliary colours is chosen to minimize the quantization error.

Finally, I improved the colour metric by taking the gamma exponent into account. For most combinations of image data and intensity input or output, this is in the range 1.8 ... 2.2, and not 1.0. Earlier versions of the converter didn't take this into account, and so darker areas of the pictures were brightened up with too many stray dither pixels. The newer versions now use a gamma of 2.0. This should be a good compromise (and was the easiest to implement - just squaring both image data and palette data. ;))

Unfortunately, the VIC chip does not display enough darker colours to cover the lower 50% of intensity range adequately, so the new converter now produces results which are - in a sense strictly mathematic - more correct, but use a lot of black and for this reason may appear too dark and lose detail in darker areas. For images, which exhibit these problems, it might be more sensible to use the older version of the MIFLI converter.

Both versions of the converter can be re-built from the source files included in the archive. You however also need the files 'image.c', 'image.h' and 'matrix.h', which are part of the MFLI converter archive.

Greetings,

Michael
Post Reply