by Fred Van Eijk
This core implements a VT52-compatible terminal emulator for the MiSTer FPGA platform. It provides a terminal interface with keyboard input and UART communication capabilities.
- 80x24 character display
- Basic VT52 control sequences
- Hardware scrolling buffer (25 rows total)
- PS/2 keyboard interface
- UART communication (115200 baud, 8N1)
- Configurable text color (White, Red, Green, Blue)
- Multiple aspect ratio options
The UART interface is available through the User port on the MiSTer:
- User port pin 1 (D-/TX): Connect to RX of your USB-to-Serial adapter
- User port pin 0 (D+/RX): Connect to TX of your USB-to-Serial adapter
- User port GND: Connect to GND of your USB-to-Serial adapter
Most USB-to-Serial adapters should work. Tested adapters include:
- FTDI FT232RL
- CH340
- CP2102
Note: Make sure your adapter supports 115200 baud and is configured for 8N1 operation.
Access the On-Screen Display (OSD) menu using the Menu button on your MiSTer setup.
Available options:
-
Aspect Ratio
- Original (4:3)
- Full Screen
- [Custom ratio 1]
- [Custom ratio 2]
-
Text Color
- White (default)
- Red
- Green
- Blue
- Soft Reset: Available through OSD menu
- Hard Reset: Use the MiSTer reset button or OSD reset option
Ctrl+H
orBackspace
: Move cursor leftTab
: Move to next tab stop (every 8 columns)LF
(Line Feed): Move cursor down one lineCR
(Carriage Return): Move cursor to start of current line
All escape sequences start with the ESC character (0x1B):
ESC A
: Cursor upESC B
: Cursor downESC C
: Cursor rightESC D
: Cursor leftESC H
: Cursor home (upper left corner)ESC I
: Reverse line feedESC J
: Erase screen from cursor and home cursorESC K
: Erase to end of current lineESC Y row col
: Direct cursor addressing- Row and column are sent as ASCII codes: space (0x20) + row/column number
- Example: To move to row 5, column 10:
ESC Y % *
(% = 0x20 + 5, * = 0x20 + 10)
- Character Set: Standard ASCII (32-126)
- Cursor: Blinking block cursor
- Hardware scrolling using 25-row buffer (24 visible + 1 scroll buffer)
A Python test server script (vt52-test-server.py
) is included to verify terminal functionality. The server supports both serial and telnet connections.
pip install pyserial
Serial mode (default):
python vt52-test-server.py --port COM9 --baudrate 115200
Telnet mode:
python vt52-test-server.py --mode telnet --port 2323
The server tests the following implemented features:
-
Control Characters
- Backspace behavior
- Line Feed/Carriage Return
- Tab spacing (8-column stops)
-
Cursor Positioning
- Absolute positioning using ESC Y sequences
- Relative movement (up, down, left, right)
- Pattern drawing demonstration
-
Erase Functions
- Erase to end of line (ESC K)
- Erase screen (ESC J)
- Cursor positioning after erase
-
Scroll Behavior
- Forward scrolling using hardware scroll buffer
- Reverse scrolling with ESC I
- Line wrapping at screen boundaries
-
Box Drawing Demo
- Demonstrates cursor movement with visual pattern
- Tests cursor positioning accuracy
Note: The test suite includes proper timing delays to account for hardware scrolling operations.
A sample game application is included (vt52-guess-the-animal-game.py
) that demonstrates interactive terminal usage. The game implements a word-guessing game similar to Hangman, specifically themed around animals.
- Visual ASCII art display of game progress
- 15 different animals to guess
- 6 attempts allowed per round
- Hardware-synchronized screen updates
- Proper handling of terminal scroll operations
- Support for both serial and telnet connections
+---+
| | Title and game status at top
O |
/|\ | Word display in center
/ \ |
| Input prompts at bottom
=========
Serial mode (default):
python vt52-guess-the-animal-game.py --mode serial --port COM9 --baudrate 115200
Telnet mode:
python vt52-guess-the-animal-game.py --mode telnet --port 2323
--mode : Connection mode (serial or telnet)
--port : Serial port or telnet port number
--baudrate : Serial baudrate (default: 115200)
--host : Telnet server host (default: 0.0.0.0)
ESC H
: Clear screen and home cursorESC J
: Erase screenESC Y
: Direct cursor addressing for UI elements- Character output with proper timing
- Hardware scroll consideration
- Synchronous screen updates accounting for VT52 timing
- Proper handling of hardware scroll operations
- Clean connection handling for both serial and telnet modes
- Error detection and graceful disconnection handling
- Configurable timing delays for hardware operations
- Supports multiple simultaneous telnet clients
- Automatic connection cleanup on client disconnect
- Proper serial port release on program exit
- Error handling for connection loss during gameplay
pip install pyserial
The game serves as both a practical example of terminal usage and a test tool for various VT52 features including cursor positioning, screen clearing, and character I/O timing considerations.
--mode : Connection mode (serial or telnet)
--port : Serial port or telnet port number
--baudrate : Serial baudrate (default: 115200)
--host : Telnet server host (default: 0.0.0.0)
The LED indicates various system states:
- Cursor blink
- UART errors (overrun, framing, parity)
- Keyboard activity
- PS/2 errors
- Scroll operation in progress
- No graphics character set support
- No alternate keypad mode
- Fixed character set (ASCII 32-126)
- Fixed UART parameters
- Hardware scrolling operations require timing considerations
The terminal provides visual feedback through the LED for:
- UART overrun errors
- UART framing errors
- UART parity errors
- PS/2 keyboard frame errors
- Scroll buffer busy states
- Core Clock: 25MHz
- Video output compatible with standard VGA/HDMI displays
- Full hardware implementation with no CPU requirements
- 25-row buffer implementation (24 visible + 1 scroll)
- Synchronous scroll operations with busy/done signaling [Previous sections remain unchanged until Technical Notes]
- Terminal Control Modules
- VT52_terminal: Top-level module integrating all components
- Command Handler: Processes VT52 commands and screen operations
- 8251 like UART: Serial communication at 115200 baud, 8N1
- Display Modules
-
Character Buffer: 25-row display buffer with hardware scrolling
- 24 visible rows + 1 scroll buffer row
- Synchronous read/write operations
- Hardware-accelerated scroll operations
-
Character ROM: Font storage and rendering
- 4K x 8 ROM using Terminus Font 8x16
- Latin-1 character subset
- Synchronous font data access
-
Video Generator: Display timing and rendering
- VGA/HDMI signal generation
- Character and cursor rendering
- Blanking signal control
- Input Processing Modules
-
Input Multiplexer: Input stream arbitration
- Prioritizes keyboard input over UART
- Handshaked data transfer
- Source tracking (keyboard/UART)
-
Keyboard Controller: PS/2 keyboard interface
- Full PS/2 protocol implementation
- Keycode to ASCII conversion
- Modifier key handling (Shift, Control, Meta)
- Error detection and reporting
- Special key sequence processing
-
Keymap ROM: Key translation tables
- 2KB ROM for keycode mapping
- Multiple keyboard planes (normal, shifted, caps)
- Extended keycode support
- Cursor Management
-
Cursor: Position and state tracking
- X/Y coordinate management
- Synchronous position updates
- Integration with command handler
-
Cursor Blinker: Visual cursor control
- ~1Hz blink rate using 6-bit counter
- vblank-synchronized timing
- Reset on cursor movement
- Support Modules
- Simple Register: Generic storage element
- Parameterized width
- Synchronous operation
- Reset support
Input Stage:
PS/2 Keyboard → Keyboard Controller →\
Input Multiplexer → Command Handler
UART RX ───────→ UART Controller ───/ ↑ ↓
↑ | Character Buffer
| | ↓
Keyboard Data ←── Command Handler ←── UART TX ───┘ Character ROM
↓
Video Generator
↓
VGA/HDMI Output
This diagram shows:
- Both keyboard and UART inputs being arbitrated by the Input Multiplexer
- Bidirectional UART communication (keyboard data is echoed to UART TX)
- Character ROM providing font data to the Video Generator
- Character Buffer storing the screen contents
- Command Handler coordinating all operations
- Video Generator producing the final display output
- Synchronous Design
- Single 25MHz clock domain
- Clean handshaking between modules
- Proper reset propagation
- Input Processing
- PS/2 protocol with error detection
- Priority-based input arbitration
- Special key sequence handling
- Full modifier key support
- Display System
- Hardware scroll buffer
- Efficient character rendering
- Smooth cursor management
- VGA/HDMI output generation
- Error Management
- PS/2 frame error detection
- UART error detection
- Input overflow prevention
- LED status indication
[Remaining sections continue as before...]
If you encounter issues:
- Check the LED status for error conditions and scroll operations
- Verify UART connections and settings
- Ensure PS/2 keyboard is properly connected
- Allow sufficient time for scroll operations to complete
- Try resetting the core through the OSD menu
Planned features:
- Graphics character set support
- Alternate keypad mode
- Configurable UART parameters
- Extended character set support
- Save/restore terminal state