Generating VGA Color Alphanumeric Video using the "Official" Solution

My first objective in studying video generation with the RP2040 is to construct a serial terminal to use with my retro microprocessor projects (based on Z80, 6502, etc). For this I want an alphanumeric color video with at least 24 rows of 80 characters.

I tried to make something alike the CGA/EGA/VGA alphanumeric mode, storing in the video memory the characters code and an attribute byte and generating in real-time the corresponding pixels. This looked something viable with the official solution, but I ended up having a hard time making the basic scheme work and had to settle on 40 columns.

It works - in 40 columns


Like I mentioned in the previous post, the routines for video generation are in the "pico extras" repository and the examples are in "pico playground". The documentation is in the source ("Use the source, Luke!), the code is complex and scattered  in a few source files. The examples are varied but not particularly instructive.

I selected a 8x16 character font, aiming for 30 lines of 80 columns using the VGA 640x480 mode. I successfully wrote code to generate the pixels from characters and attributes, but that was not enough to get it working. 

To write this code I had to take into account the way the routines expect the pixel data. To support the use of color runs (a compact way to store sequences of same color pixels), a sequence of N arbitrary pixels (with N even and greater than three) must be encoded as:

 | RAW_RUN | COLOR(1) | N-3 | COLOR(2) | COLOR(3) ... | COLOR(N) | EOL_SKIP_ALIGN

Each item is a 16 bit value. The binary code for each color is

    b b b b b g g g g g 0 r r r r r

Where bbbbb, ggggg amd rrrrr are the intensities (between 0 and 31) for blue, green and red. RAW_RUN and EOL_SKIP_ALIGN are special values.

Initially the 640x480 totally refused to work, so I tried the 320x240 mode. It kind of worked, but the colors were wrong.  After sometime I noticed a comment saying that the last pixel in a line had to be black. Forcing this I got 15 lines of 40 columns! I don't know why the lack of this pixel generated the strange effects I saw. By the way, the 320x240 mode is just 640x480 mode with duplicated pixels in horizontal and duplicated lines in vertical.

Going back to the 640x480 mode, after a few hours of panic, I found out that there is a define (PICO_SCANVIDEO_MAX_SCANLINE_BUFFER_WORDS) that sets the maximum number of 32 bit words in the pixel data passed to the video routines. The default is 180; that is more than enough for 320 pixels but not enough for 640. I could not find any documentation about this. Changing the define the program worked... for the first few lines in the screen. The problem is that my code is too slow, I cannot generate the pixels in the time available.

I believe I cannot make my code four times faster, so this is not the way to implement 80 column video. The final code for 15 lines of 40 characters is available at https://github.com/dquadros/pico-vgatext40.

Comments

Popular posts from this blog