hn.today

JIT bitmap text rendering for microcontrollers

linebender.org5 points1 comments
Screenshot of JIT bitmap text rendering for microcontrollers

A retro-inspired RP2350 home-computer project needs crisp bitmap text with proportional spacing and kerning, but the microcontroller has little memory and must generate video in real time. Rather than reserve RAM for a full framebuffer or use fixed-width character cells, the renderer “races the beam,” drawing one scanline at a time under a budget of roughly six processor cycles per pixel. Text is stored compactly in a double-buffered display list; when an object becomes active, its setup routine allocates scratch space and compiles its string into machine code. That just-in-time code draws glyphs into a one-bit-per-pixel buffer, which is then expanded to RGB565 color at a reported 1.75 cycles per pixel.

The method makes proportional bitmap text practical by optimizing both the font and the rendering code. Glyph ink is packed into a shared bitmap so each row can be read with a single 32-bit load; glyphs may overlap or reuse one another’s shapes, reducing the example font from 1,140 to 960 bytes. Compact metadata stores each glyph’s ink position and width, side bearing, and advance. The JIT emits ARM instructions tailored to the actual string, placing glyph bits into the output and handling word boundaries. Instruction scheduling hides a load-use delay, cutting a key operation from four cycles to three. The basic loop costs 23 cycles per glyph, illustrating how code generation and low-level tuning address the tight timing budget.

Read on linebender.org1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Hardware

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.