GGLABS Terminal V0.18

Submitted by GG on Mon, 12/30/2019 - 13:53

GTERMGTERM is a newly developed VT100 terminal emulator for the Commodore 64. GTERM supports the GLINK232T/Turbo232 and the GLINK232/swiftlink UART cartridges. It features a custom monochrome software 80 columns display and supports serial speeds up to 115200 bauds on a stock c64.

Design Goals

  • Support for the GGLABS GLINK232 and GLINK232T cartridges
  • compact code that can fit in a standard 16K cartridge
  • reasonably large subset of VT100 features to be useful
  • optimized for speed (mixed C and assembly)

VT100 Emulation

GTERM VT100 emulation aims to be as complete as possible in order to be useful. Version 0.18 is an updated release that fixes minor issues with vttest and corrects all known bugs with common programs (nano, emacs, dselect).
A few features are not implemented because of the hardware limitations or the rare use of the features.
The known missing features are listed below:

  • Missing 132 column support (the C64 hardware is not capable of a legible 132 column display)
  • Missing support for double wide and double height characters. This could be implemented but I have not seen any software that uses this feature. (MATE term also seems to not implement this feature)
  • VT52 emulation
  • Request Terminal Parameters Feature (planned for a future version)
  • bold is ignored (not possible with 3 pixel wide characters)
  • blink is also ignored (possible but requires a character attributes buffer which is not implemented by design)
  • UK charset is not implemented (planned for a future version)

The GTERM VT100 emulation has been extensively tested using vttest 2.7.
All 80 columns test pass without any issues, 132 columns tests produce incorrect screens.

Test Program Rating Notes
vttest 2.7 A All 80 Columns test pass.
nano A  
emacs A  
dselect A  
top A  
htop A  
mc A  

Terminal Settings

Currently GTERM supports only 8N1. Several baud rates are available 2400,9600,19200,38400,57600 and 115200.
The function keys F1 (baud up) and F3 (baud down) can be used to change the baud rate.

Keyboard Mapping

The differences between the Commodore keyboard and the VT100 keyboard makes necessary to translate some keys. The following table has a summary of the mappings:

VT100 Commodore Notes
CTRL Commodore Key Easier to reach and similar location as a PC keyboard
F1-F10 CTRL + number Can't use the Commdore function keys as most linux software expects 10 of them
ESC  
TAB RUN STOP  
\ £  
SHIFT + '@'  
¦ SHIFT + '+'  
} SHIFT + '*'  
_ SHIFT + '-'  
~ π  
` SHIFT + '£'  

Soft-80 Implementation

To maximize speed the GTERM soft-80 implementation is monochrome only. There is no ASCII screen buffer. The character set was drawn using vchar64 exported as a bin file and then reordered with a custom utility to improve the character drawing performance.
GTERM Font
A few important functions have special case implementation for common cases. I.e. character drawing in pairs, scrolling and clearing the entire screen.

For more information about various soft-80 implementations check out the article on pagetable.com and the cc65 soft-80 driver source.

Support for 115200 baud

Receiving data with a Turbo232 at 115200 is quite challenging on a stock c64. The 6551 ACIA has only a one byte receive buffer (no FIFO). The CPU must respond and complete the ISR within one byte time (~86uS which on the c64 is 1MHz is approximately 86 cycles). The ISR is 69 cycles + the NMI entry latency. This is just enough to receive the characters during a normal scanline. Unfortunately when a bad line occurs the CPU is stopped for 40 cycles and there is a high probability to overrun the single byte buffer of the 6551.

pha ; 3
tya ; 2
pha ; 3
ldy _put ; 3
lda ACIA_STATUS ; 4
;; receive a char
lda ACIA_DATA ; 4
sta _SER_BUF,y ; 4
iny ; 2
sty _put ; 3
;; check for buffer full
;; clc ; 2 - this is not exact as it might be 1 off but it's 2 cycles faster
tya ; 2
sbc _get ; 3
cmp #$F0 ; 2
bpl end_nmi ; 2-4
;; clear RTS
lda #$01 ; 2
sta ACIA_COMMAND ; 4
lda #$05 ; 2
sta _SCR_BASE-$400+38 ; 4
end_nmi:
pla ; 4
tay ; 2
pla ; 4
rti ; 6

The interrupt code above is used for all speeds up to 57600. At 115200 the ACIA interrupt is disabled and a the incoming characters are received using a very tight polling loop.
;; read loop
;; 23-24 cycles for 1 char receive
loop:
lda ACIA_STATUS ; 4
and #$08 ; 2
beq no_recv ; 2-4
;; receive a char
recv:
lda ACIA_DATA ; 4
sta _SER_BUF,y ; 4
iny ; 2
no_recv:
dex ; 2
bne loop ; 2-4

To keep the loop as short as possible the buffer check is done outside the loop. Using this code GTERM can reliably receive at 115200. Actual speed however is usually limited by the speed of screen updates.

Older Version

GTERM 0.12f is still available here

Attachment Size
gterm-0.18_src.tar.gz 52.08 KB
gterm-0.18_bin.tar.gz 58.57 KB
Filed under

The original VT100 only supports 7-bit ASCII characters.
Adding code to support for 8-bit is possible and not very difficult.
The main issue is drawing legible accented characters in the very limited 6x3 character matrix.