cores/video/VideoTerminal: Write CSI interpreter color to term_mem (\e[92;1m\e[0m decoding working).

This commit is contained in:
Florent Kermarrec 2021-03-26 11:15:27 +01:00
parent 18f77ef378
commit 714903e65b
1 changed files with 22 additions and 26 deletions

View File

@ -330,10 +330,7 @@ class CSIInterpreter(Module):
self.sink = sink = stream.Endpoint([("data", 8)]) self.sink = sink = stream.Endpoint([("data", 8)])
self.source = source = stream.Endpoint([("data", 8)]) self.source = source = stream.Endpoint([("data", 8)])
self.color = Record([("r", 8), ("g", 8), ("b", 8)]) self.color = Signal(4)
self.color.r.reset = 0xff
self.color.g.reset = 0xff
self.color.b.reset = 0xff
# # # # # #
@ -379,15 +376,10 @@ class CSIInterpreter(Module):
) )
fsm.act("DECODE-CSI", fsm.act("DECODE-CSI",
If(csi_final == ord("m"), If(csi_final == ord("m"),
# FIXME: Write color in Terminal Mem.
If((csi_bytes[0] == ord("9")) and (csi_bytes[1] == ord("2")), If((csi_bytes[0] == ord("9")) and (csi_bytes[1] == ord("2")),
NextValue(self.color.r, 0x89), NextValue(self.color, 1), # FIXME: Add Palette.
NextValue(self.color.g, 0xe2),
NextValue(self.color.b, 0x34),
).Else( ).Else(
NextValue(self.color.r, self.color.r.reset), NextValue(self.color, 0), # FIXME: Add Palette.
NextValue(self.color.g, self.color.g.reset),
NextValue(self.color.b, self.color.b.reset),
), ),
), ),
NextState("RECOPY") NextState("RECOPY")
@ -402,6 +394,8 @@ class VideoTerminal(Module):
# # # # # #
csi_width = 8 if with_csi_interpreter else 0
# Font Mem. # Font Mem.
# --------- # ---------
os.system("wget https://github.com/enjoy-digital/litex/files/6076336/ter-u16b.txt") # FIXME: Store Font in LiteX? os.system("wget https://github.com/enjoy-digital/litex/files/6076336/ter-u16b.txt") # FIXME: Store Font in LiteX?
@ -419,7 +413,7 @@ class VideoTerminal(Module):
term_lines = math.floor(vres/font_heigth) term_lines = math.floor(vres/font_heigth)
term_depth = term_colums * term_lines term_depth = term_colums * term_lines
term_init = [ord(c) for c in [" "]*term_colums*term_lines] term_init = [ord(c) for c in [" "]*term_colums*term_lines]
term_mem = Memory(width=font_width, depth=term_depth, init=term_init) term_mem = Memory(width=font_width + csi_width, depth=term_depth, init=term_init)
term_wrport = term_mem.get_port(write_capable=True) term_wrport = term_mem.get_port(write_capable=True)
term_rdport = term_mem.get_port(has_re=True) term_rdport = term_mem.get_port(has_re=True)
self.specials += term_mem, term_wrport, term_rdport self.specials += term_mem, term_wrport, term_rdport
@ -432,6 +426,7 @@ class VideoTerminal(Module):
self.submodules.csi_interpreter = CSIInterpreter() self.submodules.csi_interpreter = CSIInterpreter()
self.comb += uart_sink.connect(self.csi_interpreter.sink) self.comb += uart_sink.connect(self.csi_interpreter.sink)
uart_sink = self.csi_interpreter.source uart_sink = self.csi_interpreter.source
self.comb += term_wrport.dat_w[font_width:].eq(self.csi_interpreter.color)
self.submodules.uart_fifo = stream.SyncFIFO([("data", 8)], 8) self.submodules.uart_fifo = stream.SyncFIFO([("data", 8)], 8)
self.comb += uart_sink.connect(self.uart_fifo.sink) self.comb += uart_sink.connect(self.uart_fifo.sink)
@ -449,7 +444,7 @@ class VideoTerminal(Module):
) )
uart_fsm.act("CLEAR-XY", uart_fsm.act("CLEAR-XY",
term_wrport.we.eq(1), term_wrport.we.eq(1),
term_wrport.dat_w.eq(ord(" ")), term_wrport.dat_w[:font_width].eq(ord(" ")),
NextValue(x_term, x_term + 1), NextValue(x_term, x_term + 1),
If(x_term == (term_colums - 1), If(x_term == (term_colums - 1),
NextValue(x_term, 0), NextValue(x_term, 0),
@ -476,7 +471,7 @@ class VideoTerminal(Module):
uart_fsm.act("WRITE", uart_fsm.act("WRITE",
uart_sink.ready.eq(1), uart_sink.ready.eq(1),
term_wrport.we.eq(1), term_wrport.we.eq(1),
term_wrport.dat_w.eq(uart_sink.data), term_wrport.dat_w[:font_width].eq(uart_sink.data),
NextState("INCR-X") NextState("INCR-X")
) )
uart_fsm.act("RST-X", uart_fsm.act("RST-X",
@ -506,7 +501,7 @@ class VideoTerminal(Module):
uart_fsm.act("CLEAR-X", uart_fsm.act("CLEAR-X",
NextValue(x_term, x_term + 1), NextValue(x_term, x_term + 1),
term_wrport.we.eq(1), term_wrport.we.eq(1),
term_wrport.dat_w.eq(ord(" ")), term_wrport.dat_w[:font_width].eq(ord(" ")),
If(x_term == (term_colums - 1), If(x_term == (term_colums - 1),
NextValue(x_term, 0), NextValue(x_term, 0),
NextState("IDLE") NextState("IDLE")
@ -548,7 +543,7 @@ class VideoTerminal(Module):
self.comb += term_rdport.re.eq(ce) self.comb += term_rdport.re.eq(ce)
self.comb += term_rdport.adr.eq(x + y_rollover*term_colums) self.comb += term_rdport.adr.eq(x + y_rollover*term_colums)
self.comb += [ self.comb += [
term_dat_r.eq(term_rdport.dat_r), term_dat_r.eq(term_rdport.dat_r[:font_width]),
If((x >= 80) | (y >= term_lines), If((x >= 80) | (y >= term_lines),
term_dat_r.eq(ord(" ")), # Out of range, generate space. term_dat_r.eq(ord(" ")), # Out of range, generate space.
) )
@ -562,16 +557,17 @@ class VideoTerminal(Module):
for i in range(font_width): for i in range(font_width):
cases[i] = [bit.eq(font_rdport.dat_r[font_width-1-i])] cases[i] = [bit.eq(font_rdport.dat_r[font_width-1-i])]
self.comb += Case(timing_bufs[1].source.hcount[:int(math.log2(font_width))], cases) self.comb += Case(timing_bufs[1].source.hcount[:int(math.log2(font_width))], cases)
# FIXME: Allow static/dynamic Font color. # FIXME: Add Palette.
self.comb += If(bit, self.comb += [
source.r.eq(0xff), If(bit,
source.g.eq(0xff), Case(term_rdport.dat_r[font_width:], {
source.b.eq(0xff), 0: [Cat(source.r, source.g, source.b).eq(0xffffff)],
1: [Cat(source.r, source.g, source.b).eq(0x34e289)],
})
).Else( ).Else(
source.r.eq(0x00), Cat(source.r, source.g, source.b).eq(0x000000),
source.g.eq(0x00),
source.b.eq(0x00)
) )
]
# Video FrameBuffer -------------------------------------------------------------------------------- # Video FrameBuffer --------------------------------------------------------------------------------