Coder Social home page Coder Social logo

hagl_pico_vgaboard's Introduction

HAGL Pico VGA Board

BIG FAT WARNING
THIS PROJECT IS NOT PRODUCTION READY!
SOME VGA MODES IMPLY OVERCLOCKING AND OVERVOLTING RP2040!
USE AT YOUR OWN RISK!

Introduction

This is an HAGL HAL for the Raspberry Pi Pico demo VGA board, based on scanvideo from the pico-extras repository that comes alongside SDK.

This follows discussions on Raspberry Pi Pico's SDK forum Understanding Pico VGA Code and CMakelists? dating back from 2021.

The following projects are either bases for this one or sources of inspiration:

To manage this project, I use Github's project board to be able to organize myself between ideas, TODOs, WIPs & done items.

Features

As of February 2024, this project has the following features:

  • Framebuffer, statically allocated at compile time (see below for corruption using malloc()),
  • 1/2/4/8/16 bits per pixel modes, leading to 2/4/16/256/32768 colors at once,
  • 8 bits or 16 bits mode choosed at compile time, too,
  • Double buffering for smooth animation at lower resolutions, as it uses twice the memory
  • VGA modes from 640x400 to 1280x1024, with 1x/2x/4x/8x scale in X and Y directions (not using scanvideo's yscale_denominator)
  • Letterbox mode to handle for example MSX / ZX Spectrum 256x192 inside 320x240 standard VGA
  • Handling of A/B/C buttons (with clever? use in example allows going to next/reset demo, cycling through palettes & changing borders ramdomly)
  • Native execution with Pico Host SDL using PICO_NO_HARDWARE, allowing to debug display algorithms before using real hardware
  • Serial console on GPIO20/GPIO21 with cutted tracks

There is an example project with some demos.

BUGS

  • Find why allocating framebuffer dynamically with malloc() leads to corrupted display (memory alignment problems?)

TODO

  • VGA mode change at runtime, either:
    • only color depth and resolution (for example to implement modes 0=160x200/16, 1=320x200/4, 2=640x200/2 of Amstrad CPC)
    • other VGA modes, only being limited by the amount of statically allocated memory
  • Using multiplane capabilities of scanvideo:
    • Framebuffer with its own palette
    • Text mode layer, using another palette if desired
    • Tilemap and tileset (with pixel scrolling, window or full screen,...)
    • Sprites, as many as possible, eventually with scaling / rotation
    • only 3 will be available at the same time
  • Optimizations:
    • Blitting operations either in C or assembly to speed up rendering and capabilities
    • Packing of HAGL's bitmaps when in 1/2/4 bits per pixel modes, or implement them as VGA board only
  • Replacement of buttons with Pico Host SDL target

Build Instructions

CMakeLists.txt is inspired by:

pico-sdk and pico-extras from Raspberry Pi Foundation are obviously required.

VGA modes

Most VGA timings come from:

N.B.:

  • Most modes are intended to be stretched by 2 (or more) in horizontal and/or vertical directions to reduce memory usage
  • Wider modes have higher pixel clocks that limit system overclocking coefficient to 3, 2 or even 1, that's why I'm trying to provide "halved" versions which are tricky to achieve
  • For h_sync_polarity and v_sync_polarity, 1 means NEGATIVE, and 0 means POSITIVE

Working modes

These modes should work on any reasonable LCD display, I don't own any CRT monitor anymore so I can't make any tests.

A/R VGA Mode PC^1 PC^2 Notes
16:10 640x400 25.175 25.200 Only mode using 70Hz refresh rate, all other use something very near of 60 Hz
4:3 640x480 25.175 25.200 Most standard, if only one can work, that must be this one
4:3 768x576 34.960 35.000 Divisible by 3, fast system clock (280 MHz at 1.20V^3 on my Pico B0 & B1)
4:3 800x600 40.000 40.000 I think 768x756 is better ;-)
4:3 1024x768 65.000 65.000 Even my 15" LCD from 2001 or 2002 has this as native resolution!
16:9 1280x720 74.250 74.000 Only 16:9 mode for now
5:4 1280x1024 108.000 108.000 I own an 19" LCD with this native resolution, too...
16:10 1680x1050 147.140 147.000 Divisible by 3 or 5^4, fastest system clock (294 MHz at 1.30V^3 on my Pico B1)
  • ^[1] Specifications Pixel Clock in MHz
  • ^[2] Rounded Pixel Clock in MHz as achievable by RPi Pico (as given by vcocalc tool)
  • ^[3] Be aware that these values may either not work on specific Picos, shorten their lifespan or even destroy them!, see ALLOW_VREG_VOLTAGE_OVERRIDE
  • ^[4] That Makes a very good fit at 336x210 with 320x200 letterbox, very tight margins at native resolution on my LG L204WT monitor ;-)

Experimental modes

These modes are flaky on my own monitors or even do not work at all.

A/R VGA Mode PC^1 PC^2 Notes
5:4 640x512 56.000 56.000 Half of 1280x1024, rounding v_pulse to 1 or 2 does not seem good...
16:10 840x525 73.125 73.500 Half of 1680x1050, should satisfy my LG L204WT monitor but is "out of range"
16:9 1024x576 46.500 46.500
16:9 1600x900 108.000 108.000 Native resolution of my 17" laptop: good for fullscreen tests, KO on my LG monitor
16:10 1280x800 83.460 83.200 Double of 640x400, can be used to make 640x400@60

License

The MIT License (MIT).

See LICENSE for more information.

There's a mix with BSD 3 Clause license between HAGL and Pico SDK / extras that should be fine, but IANAL.

CHiPs44.

EOF

hagl_pico_vgaboard's People

Contributors

chips44 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hagl_pico_vgaboard's Issues

Add a 16 colors text mode over framebuffer, with NUL being transparent

NUL chars in the text buffer should not be rendered at all, others will render with background and foreground colors instead of framebuffer content, without transparency.

Palette can be different from the framebuffer's one.

This does not need to use multiplane capability of scanvideo, unless it is easier or faster than "naive" rendering.

Text "cells" could be 2 to 4 bytes:

  • 8 bits for char to display
  • 4 or 8 bits for background color
  • 4 or 8 bits for foreground color
  • 4 or 8 bits for font (index) to use

Text mode could have these attributes:

  • (array of) font to use (TODO, only 8x8?)
  • lines as framebuffer pixel width / font width (or just 8?)
  • columns as framebuffer pixel height / font height (or just 8?)
  • cursor:
    • shape: horizontal line or block (and/or reverse block and/or vertical line?),
    • animation: off, fixed, flashing slowly or flashing quickly,
    • current line,
    • current column

This could be the base for a "dumb" terminal understanding a subset of ANSI/VT100 sequences.

Make 48K 1024x768 based modes work

All these modes share the same 48K (49152 bytes) of memory for framebuffer:

  • 1024x384x2 (1bpp)
  • 512x384x4 (2bpp)
  • 512x192x16 (4bpp)
  • 256x192x256 (8bpp)

"Weird" modes:

  • 512x768x2 (1bpp)
  • 256x384x16 (4bpp)

Use the VGA board A, B & C buttons

Short:

  • A go to next demo
  • B go to next palette
  • C change letterbox borders randomly

Medium:

  • A go to first demo
  • B go to first palette
  • C change letterbox borders to black

NB: no use of Repeat feature for now!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.