Skip to content

alankrantas/TinyBasicPlus-Mega-VGA-Keyboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tiny BASIC 8-bit Home Computer on Arduino with VGA and PS/2 Support

IMG_3193

My version of remaking Rob Cai's Arduino Basic PC With VGA Output, which is to use two Arduino AVR boards to create a 8-bit home computer running the TinyBasic runtime with VGA video output and PS/2 keyboard input.

Unlike Rob uses one Nano as the "VGA chip" and another as the TinyBasic runtime/keyboard controller, I run the VGA driver together with the TinyBasic on a Mega 2560 and use a Uno as the "keyboard adapter". I also tried to write a cleaner code and have the VGA driver to print characters according to their actual width (Rob set all of them with the same size of 5 VGA pixels).

The libraries I used includes:

Hardware

  • An Arduino Mega 2560 (script: TinyBasicPlusMegaVGA)
  • An Arduino Uno or Arduino Nano (script: TinyBasicPlusUnoKeyboard)
  • VGA and PS/2 connector breakout (optional)

There's many ways to connect VGA and PS/2 (see the driver repos for details) but personally I use a Waveshare VGA PS2 Board which already have resistors on pins.

VGA-PS2-Board_l

Wiring

Mega 2560

Pin VGA D-SUB 15 Resistor
GND GND
9 H-SYNC 680 Ω
11 V-SYNC 680 Ω
30 GREEN 470 Ω
31 BLUE 470 Ω

vga

Note: The VGAX driver only uses two colors (you can change them to the combination you like, even connecting multiple colors to one pin).

Uno

Pin PS/2 mini-DIN
5V VCC
GND GND
2 (data) +DATA
3 (irq) +CLK

ps2-pinout-by-rones

Between Mega and Uno

Pin Mega Uno
Serial port 0 (Rx) 1 (Tx)
GNE GND GND

I also power the Uno directly using Mega's 5V pin (while the Mega can be powered by the USB cable) via the Waveshare VGA PS2 Board itself. So actually both the Uno and the PS/2 keyboard are powered from the Mega.

Explanation for the Two-Board Combination

It is simply not possible to run both VGAX and PS/2 drivers together on the same board without rewritting them, for both rely on the same interrupt timers despite not using the same pins. On AVR boards timer0 by default is used by built-in functions like delay and millis, and VGAX uses timer0, timer1 and timer2. While VGAX does provide alternative functions like vga.millis() to avoid issues, and the MEGA does have extra timers, the PS/2 drivers (Rob uses PS2Keyboard which is the predecessor of PS2KeyAdvanced) still calls the original millis and thus break timings for both drivers.

VGA Pixel Offset

The MEGA script has X and Y offset settings you can adjust. As the author of the VGAX driver stated, the "screen" may not align properly to the VGA monitor. Also the only way to change the "resolution" is to modify the value in the VGAX header file.

TinyBasic Memory Usage

By default the TinyBasic script use up all available memories on the board. I change it to use 6K so a little less than 5K would be available for TinyBasic code and variables.

I haven't test if other functionalities (buzzers, SD card, etc) will work. Later I'll try to remove checks for ESP boards since they are not necessary on MEGA.

Supported Input Keys

I have the Uno's keyboard script and the VGAX printing function to only accept the following characters:

  • Enter (ASCII code 13)
  • Space (ASCII code 32)
  • Characters of ASCII code 33~126

The TinyBasic script did support backspace, although it does not appear to work properly. Rob also implemented to use ESC to clear the screen, but I'll have to figure out how to reset the TinyBasic prompt at the same time.

VGAX Colors

The VGAX, in order to save memory on Uno, only uses two colors so there are four colors available:

Color value Binary value Effect
0 00 Black
1 01 Color 1 (pin 30)
2 10 Color 2 (pin 31)
3 11 Both colors

vga.clear and vga.printPROGMEM alike use these color values despite they are in byte type.

The VGAXUA displays only one color but use up significantly more memory due to the resolution is set higher.

Releases

No releases published

Packages

No packages published

Languages