Skip to content

Commit d5bac9e

Browse files
committed
109.636MHz/1B00: Many minor improvements
* Initial UART settings can be set by a generic. * UART RX now only starts when there is a transition from high to low, there are still problems (a frame error does not propagate to the rest of the system, or is not detected), but this means when the UART line is driven low then we do not get a series of invalid characters. * The simulator now simulates the scrolling behavior of the VT100, along with some more of the SGR codes the hardware supports. * Some warnings have been fixed. * The 'turn of reverse video' SGR has been fixed, it was $27 when it should have been decimal 27, or $1B. * We now erase three rows of text ahead of moving the base pointer text, this prevents errant text from previous lines being displayed. * An aid for test vector generation for the VT100 has been added, which is a small GForth program that can be used to generate text with lots of ANSI escape sequences in it. NOTES: Many of the more serious bugs in the VT100 have been fixed, however there are still differences in how the simulator behaves, and how the terminal emulators on my computer behave, which will need to be fixed. Some of the bugs include: * The AT-XY command does not seem to work after issue an erase display command to the VT100, this likely due to the VT100 being too busy to respond. This only appears when the UART FIFO is enabled, or when UART output is disable (output only going to the VT100). This means it is giving commands to the VT100 much quicker. * The UART FIFO RX seems to work fine, although there are the same problems with RX as there are without the FIFO (that is, we receive invalid characters with high data rates). For the TX however, a character seems to get stuck in the FIFO, it comes out, but then the next character gets stuck, and so on. No data seems to be lost, but it is annoying. * There are some other VT100 differences between the hardware and how it should behave, the test suite should help categorize and find the issues. * Other worrying things include the fact that the board seems to need reprogramming multiple times before the system gets into a stable state. Once in that stable state is appears to be very steady and stable, but it can require multiple times before it becomes stable. Symptoms include not booting, '? -4 stack underflow' being printed, only 'eForth V' being printed, or reading from flash failing. I am not sure if the problem is with my design, however reprogramming seems to fix the issue when it does occur, with no other design changes needed.
1 parent c66e409 commit d5bac9e

13 files changed

+217
-66
lines changed

h2.c

+17-7
Original file line numberDiff line numberDiff line change
@@ -969,11 +969,15 @@ static void terminal_parse_attribute(vt100_attribute_t * const a, const unsigned
969969
a->foreground_color = WHITE;
970970
a->background_color = BLACK;
971971
return;
972-
case 1: a->bold = true; return;
973-
case 4: a->under_score = true; return;
974-
case 5: a->blink = true; return;
975-
case 7: a->reverse_video = true; return;
976-
case 8: a->conceal = true; return;
972+
case 1: a->bold = true; return;
973+
case 22: a->bold = false; return;
974+
case 4: a->under_score = true; return;
975+
case 5: a->blink = true; return;
976+
case 25: a->blink = false; return;
977+
case 7: a->reverse_video = true; return;
978+
case 39: a->reverse_video = false; return;
979+
case 8: a->conceal = true; return;
980+
case 28: a->conceal = false; return;
977981
default:
978982
if (v >= 30 && v <= 37)
979983
a->foreground_color = v - 30;
@@ -1185,8 +1189,14 @@ void vt100_update(vt100_t *t, const uint8_t c) {
11851189
t->cursor++;
11861190
}
11871191
if (t->cursor >= t->size) {
1188-
terminal_attribute_block_set(t, t->size, &vt100_default_attribute);
1189-
memset(t->m, ' ', t->size);
1192+
const vt100_attribute_t *a = &vt100_default_attribute;
1193+
t->cursor -= t->width;
1194+
memmove(t->m, t->m + t->width, t->size - t->width);
1195+
memset((t->m + t->size) - t->width, ' ', t->width);
1196+
for (size_t i = 0; i < (t->size - t->width); i++)
1197+
t->attributes[i] = t->attributes[i + t->width];
1198+
for (size_t i = t->size - t->width; i < t->size; i++)
1199+
memcpy(&t->attributes[i], a, sizeof(*a));
11901200
}
11911201
t->cursor %= t->size;
11921202
}

h2.fth

+8-6
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,12 @@ location failed "failed" ( used in start up routine )
191191
: rx? iUart uart? ; hidden ( -- c -1 | 0 : read in a character of input from UART )
192192
: ps2? iVT100 uart? ; hidden ( -- c -1 | 0 : PS/2 version of rx? )
193193

194-
\ : not-busy @ $0800 and ; hidden
194+
\ TODO: 'rx?' should be called here, and any results queued, otherwise without
195+
\ a hardware FIFO we will block for potentially quite a long time if we are
196+
\ sending a lot of characters, never having a chance to read.
195197
: uart! ( c uart-register -- )
196-
\ begin dup @ $1000 and 0= until swap $2000 or swap ! ; hidden \ check full
197-
begin dup @ $0800 and until swap $2000 or swap ! ; hidden \ check empty
198+
begin dup @ $1000 and 0= until swap $2000 or swap ! ; hidden \ check full
199+
\ begin dup @ $0800 and until swap $2000 or swap ! ; hidden \ check empty
198200

199201
: tx! iUart uart! ; hidden
200202
: vga! iVT100 uart! ; hidden ( n a -- : output character to VT100 display )
@@ -536,7 +538,7 @@ location search-previous 0
536538
: , here dup cell+ ?dictionary cp! ! ; ( u -- )
537539
: doLit 0x8000 or , ; hidden
538540
: ?compile state @ 0= if 14 -throw exit then ; hidden ( fail if not compiling )
539-
\ @todo vector literal, amongst other words
541+
\ TODO vector literal, amongst other words
540542
: literal ( n -- : write a literal into the dictionary )
541543
?compile
542544
dup 0x8000 and ( n > $7fff ? )
@@ -811,7 +813,7 @@ in which the problem could be solved. )
811813
( ==================== Strings ======================================= )
812814

813815
( ==================== Block Word Set ================================ )
814-
\ @todo 'blk' being set to zero should indicate an invalid block number, not -1
816+
\ TODO 'blk' being set to zero should indicate an invalid block number, not -1
815817
\ The usage of 'blk' is incorrect, it should be set to the block number
816818
\ most recently LOAD'ed, not the one most recently BLOCK'ed
817819
\
@@ -906,7 +908,7 @@ location tbl-2 $4143
906908
[char] L = if $7fff and . exit then
907909
drop ; hidden
908910

909-
\ @todo print out immediate status, prettify output, ...
911+
\ TODO print out immediate status, prettify output, ...
910912
: see
911913
token find 0= if 13 -throw exit then
912914
cr

nvram.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,18 @@ red green blue + + constant white
385385
\ ==== Screen Saver ============================================
386386
\ An incredibly simple screen saver using ANSI Escape codes
387387
\ for placement and coloring of random characters
388-
388+
base @ decimal
389389
: screen-saver ( -- )
390390
page
391391
begin
392-
random 80 mod
393-
random 40 mod at-xy
392+
random 79 mod
393+
random 38 mod at-xy
394394
random >char emit
395395
random 8 mod
396-
( random 1 and if background then )
397-
color
396+
random 1 and if background then
397+
random 256 and ms color
398398
again ;
399-
399+
base !
400400

401401
; ==== Game: YOU ARE DEAD (HELP) ===============================
402402
This is a clone of the one dimensional rogue like game

ram.vhd

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ entity ram_interface is
3838
clk: in std_ulogic;
3939
rst: in std_ulogic;
4040

41-
mem_addr_16_1: in std_ulogic_vector(16 downto 1);
41+
mem_addr_16_1: in std_ulogic_vector(16 downto 2);
4242
mem_addr_16_1_we: in std_ulogic;
4343
mem_addr_26_17: in std_ulogic_vector(26 downto 17);
4444
mem_addr_26_17_we: in std_ulogic;
@@ -70,7 +70,7 @@ architecture rtl of ram_interface is
7070
signal mem_addr_low: std_ulogic_vector(mem_addr_16_1'range) := (others => '0');
7171
signal mem_addr_high: std_ulogic_vector(mem_addr_26_17'range) := (others => '0');
7272
begin
73-
mem_addr <= '0' & mem_addr_high & mem_addr_low(mem_addr_low'high downto mem_addr_low'low + 1);
73+
mem_addr <= '0' & mem_addr_high & mem_addr_low;
7474

7575
mem_addr_16_1_reg: entity work.reg
7676
generic map(g => g, N => mem_addr_16_1'length)

t/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.ansi

t/ansi.fth

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
\ RJH - ANSI TERMINAL TESTS / 2019. TESTED IN GFORTH
2+
\ Based around the definition for 'F' found here:
3+
\ https://www.forth.com/starting-forth/1-forth-stacks-dictionary/
4+
\
5+
\ This file is used to prepare test vectors for the VT-100 terminal emulator,
6+
\ a mini-language is make for drawing text and displaying colors.
7+
\
8+
ONLY FORTH DEFINITIONS DECIMAL
9+
10+
WORDLIST CONSTANT COOL-TEXT ( <_< - way cool )
11+
COOL-TEXT >ORDER DEFINITIONS
12+
VARIABLE COOL-CHARACTER CHAR * COOL-CHARACTER !
13+
: BYE BYE ;
14+
: CR CR ;
15+
: {{ CR COOL-TEXT >ORDER DUP ;
16+
: >_> CHAR COOL-CHARACTER ! ;
17+
: <_< [CHAR] * COOL-CHARACTER ! ;
18+
: \ POSTPONE \ ;
19+
: .( POSTPONE .( ;
20+
21+
: CSI $1B EMIT [CHAR] [ EMIT ;
22+
: 10U. BASE @ >R DECIMAL 0 <# #S #> TYPE R> BASE ! ;
23+
: ANSI SWAP CSI 10U. EMIT ; ( N C -- )
24+
: AT-XY CSI 10U. $3B EMIT 10U. [CHAR] H EMIT ;
25+
: PAGE 2 [CHAR] J ANSI 1 1 AT-XY ;
26+
: SGR [CHAR] m ANSI ;
27+
28+
: UP [CHAR] A ANSI ;
29+
: DOWN [CHAR] B ANSI ;
30+
: RIGHT [CHAR] C ANSI ;
31+
: LEFT [CHAR] D ANSI ;
32+
33+
0 CONSTANT BLACK 1 CONSTANT RED 2 CONSTANT GREEN 4 CONSTANT BLUE
34+
RED GREEN + CONSTANT YELLOW
35+
GREEN BLUE + CONSTANT CYAN
36+
RED BLUE + CONSTANT MAGENTA
37+
RED GREEN BLUE + + CONSTANT WHITE
38+
: BACKGROUND $A + ;
39+
: COLOR $1E + SGR ;
40+
41+
: BLINKY $5 SGR ;
42+
: UNBLINK $19 SGR ;
43+
: BOLD $1 SGR ;
44+
: NORMAL $16 SGR ;
45+
: REVERSE $7 SGR ;
46+
: ESREVER $1B SGR ;
47+
48+
: DOT COOL-CHARACTER @ EMIT ;
49+
: DOTS 0 DO DOT LOOP ;
50+
: BLIP 1 DOWN DUP RIGHT DOT DUP 2 * LEFT ;
51+
: BAR 1 DOWN DUP RIGHT 5 DOTS DUP 2 * LEFT ;
52+
: F BAR BLIP BAR BLIP BLIP DROP 5 UP ;
53+
: C BAR BLIP BLIP BLIP BAR DROP 5 UP ;
54+
: E DUP F C ;
55+
: I BLIP BLIP BLIP BLIP BLIP DROP 5 UP ;
56+
: O DUP C 4 + I ;
57+
: A DUP F 4 + I ;
58+
: _ 4 DOWN BAR DROP 5 UP ;
59+
: TOP BAR DROP 1 UP ;
60+
: U DUP I DUP _ 4 + I ;
61+
: J DUP _ 4 + I ;
62+
: L DUP I _ ;
63+
: W DUP L DUP 2 + I 4 + I ;
64+
: M DUP I DUP 2 + I DUP 4 + I TOP ;
65+
: - 2 DOWN BAR DROP 3 UP ;
66+
: H DUP I DUP - 4 + I ;
67+
: T DUP TOP 2 + I ;
68+
: D DUP I DROP ;
69+
70+
: | 7 + DUP ;
71+
: }} DROP 6 DOWN PREVIOUS ;
72+
SEAL

t/eforth.fth

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\ Test setup code for eForth interpreter on the target
2+
: echos begin key emit switches until ;
3+
echos

t/hello.tst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
PAGE
2+
CR
3+
CR
4+
5+
RED COLOR
6+
>_> . 5 {{ H | E | L | L | O }}
7+
BLUE COLOR
8+
>_> | 5 {{ H | E | L | L | O }}
9+
\ >_> / 5 {{ H | E | L | L | O }}
10+
CR CR
11+
12+
0 SGR
13+
14+
BLINKY .( BLINK ) UNBLINK BOLD .( BOLD ) NORMAL REVERSE .( REVERSE ) ESREVER CR
15+
CR
16+
MAGENTA BACKGROUND COLOR .( MAGENTA )
17+
YELLOW BACKGROUND COLOR .( YELLOW )
18+
BLUE BACKGROUND COLOR .( BLUE )
19+
20+
0 SGR
21+
CR BYE

t/makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SOURCES:=$(wildcard *.tst)
2+
OBJFILES=$(SOURCES:%.tst=%.ansi)
3+
4+
.PHONY: all clean
5+
6+
all: ${OBJFILES}
7+
8+
%.ansi: %.tst ansi.fth eforth.fth
9+
cat eforth.fth > $@
10+
gforth ansi.fth $< >> $@
11+
12+
clean:
13+
rm -fv *.ansi
14+

t/readme.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# t/
2+
3+
This folder is for tests. At the moment the tests are for the ANSI terminal
4+
emulator, but code that exercises the eForth interpreter on the running system
5+
could be added.
6+
7+
The file [ansi.fth][] contains a framework for generated text files that
8+
contain ANSI Escape Sequences, which can be used to test that the VT100 module
9+
is working correctly.
10+
11+
[eforth.fth][] contains code that should run on the target.
12+
13+
All of this should be transmitted to the target over a UART.
14+
15+
[ansi.fth]: ansi.fth
16+
[eforth.fth]: eforth.fth

top.vhd

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ begin
520520
port map (
521521
clk => clk,
522522
rst => rst,
523-
mem_addr_16_1 => io_dout,
523+
mem_addr_16_1 => io_dout(io_dout'high downto 1),
524524
mem_addr_16_1_we => mem_addr_16_1_we,
525525
mem_addr_26_17 => io_dout(9 downto 0),
526526
mem_addr_26_17_we => mem_addr_26_17_we,

0 commit comments

Comments
 (0)