Crate vga_framebuffer

source ·
Expand description

VGA Frame Buffer for Embedded Microcontrollers

Generates an 800 x 600 @ 60 Hz SVGA signal from a 48 column x 36 row monochrome text buffer. The image has a border.

TODO: Implement smooth scrolling in the vertical direction with an extra text row.

Width = 400 double width pixels => 400 = 8 + (48 x 8) + 8

Height = 600 pixels => 600 = 12 + (36 x 16) + 12

<-------------- 400 px, pixel doubled to 800 px ------------->
+------------------------------------------------------------+
|<--> 8 pixel border     ^                8 pixel border <-->|
|                        | 12 px border                      |
|                        v                                   |
|    +--------------------------------------------------+    |
|    | <--^------ 48 chars x 8 px = 384  px ----------->|    |
|    |    |                                             |    |
|    |    |                                             |    |
|    |    | 36 rows x 16 px = 576 px                    |    |
|    |    |                                             |    |
|    |    |                                             |    |
|    |    v                                             |    |
|    +--------------------------------------------------+    |
|                          ^                                 |
|                          | 12 px border                    |
|                          v                                 |
+------------------------------------------------------------+

Requires pixels to be emitted with a 20 MHz pixel clock (against a nominal 40 MHz pixel clock, in order to acheive the horizontal doubling).

In order to maintain performance, only one font size is supported: 8x16 pixels. But you can substitute your own font if required (e.g. for Teletext support).

There is optional cursor support. Rather than try and check each text cell at render time to see if it is in the cursor position, we swap chars in and out of the text buffer as the cursor moves. It’s a little more expensive, but the cost is at text write time, not at render time (and so it won’t break sync).

See https://github.com/thejpster/monotron for an example.

Modules

Structs

This structure describes the attributes for a Char. They’re all packed into 8 bits to save RAM.
Describes a vertical column on the screen. Zero is on the left.
This structure represents the framebuffer - a 2D array of monochome pixels.
Represents Mode2 1-bpp graphics
A point on the screen. The arguments are X (column), Y (row)
Describes a place on the screen. (0, 0) is the top left.
Identifies a horizontal row on the screen. Zero is at the top.

Enums

This MS-DOS CodePage 850. It offers a compromise between the box characters of CodePage 437 and the accents of ISO 8859-1 / Latin-1.
How to handle Control Characters
You can set this on a row to make the text double-height. This was common on the BBC Micro in Mode 7/Teletext mode.
Special types of character we need to interpret

Constants

How many words in a line (including the border)
Highest X co-ord
Highest Y co-ord
Highest X co-ord for text
Highest Y co-ord for text
How many characters in a row
How many rows of characters on the screen
Top/bottom border height
Number of columns in frame buffer
How many words in a line (excluding the border)
Number of lines in frame buffer
Number of lines in the mode2 frame buffer (which is line-doubled)

Traits

Refinement of BaseConsole which supports 8-bit characters. Use this is you are implementing an old-fashioned ASCII console (including extended ASCII, like Code Page 850, or ISO 8859-1).
Abstraction for our console. We can move the cursor around and write text to it. You should use either UnicodeConsole or AsciiConsole depending on whether you want full Unicode support (&str, char, etc), or just 8-bit characters (&[u8] and u8).
Implement this on your microcontroller’s timer object.
Refinement of BaseConsole which supports Unicode characters. Use this is you are implementing a modern console with Unicode support.