From 5decf201f3dffb2ec055a499744eb8f8e74d4771 Mon Sep 17 00:00:00 2001 From: PhMajerus Date: Tue, 21 Jan 2025 09:27:23 +0100 Subject: [PATCH] Improved matrix softfont DECDLD and optimized charsets changes. Split the softfont string into more readable header and characters chunks. Keep track of currently active charset so we can output font changes only when necessary. --- bsd/screensavers/matrix.c | 98 ++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 11 deletions(-) diff --git a/bsd/screensavers/matrix.c b/bsd/screensavers/matrix.c index ff445f7..784132b 100644 --- a/bsd/screensavers/matrix.c +++ b/bsd/screensavers/matrix.c @@ -24,14 +24,6 @@ #define SCREEN_HEIGHT 24 -/* -** Strings to load a VT220 softfont providing the extra Matrix characters, select it and unselect it. -** This softfont contains 46 mirrored katakana as ASCII !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN -** The real term is a Dynamically Replaceable Character Sets (DRCS) loaded into the terminal's -** memory using a Down-Line-Loading DRCS (DECDLD) control string. The font is built using Sixels. -** Font design by Philippe Majerus, January 2025 -*/ -#define LOAD_MATRIX_SOFTFONT "\033P1;1;2{ MMQAyAAA\?/\?\?\?\?@A\?\?;\?ACwGOO\?/\?\?\?B\?\?\?\?;{CCECC[\?/\?@AAA\?\?\?;\?CC{CC\?\?/AAABAAA\?;CC}ScCC\?/\?\?B\?\?@A\?;{CCC}CC\?/@AAA\?@A\?;_gg}gg_\?/\?\?\?B\?\?\?\?;{CCCCMO\?/\?@AAA\?\?\?;CC{CCMO\?/\?\?\?@AA\?\?;{CCCCCC\?/BAAAAAA\?;C}CCC]C\?/\?\?@AAA\?\?;]_\?\?SSS\?/\?\?@AAAA\?;EIqaAAA\?/A@\?\?@AA\?;KSCCC}C\?/AAAAA@\?\?;Mo\?\?\?WE\?/\?\?@AAAA\?;{csSCMO\?/\?@AAAA\?\?;OQQ{SSO\?/\?\?\?@A\?\?\?;]_\?M\?\?M\?/\?\?@AAAA\?;GIIyIIG\?/\?\?\?@A\?\?\?;OOGG}\?\?\?/\?\?\?\?B\?\?\?;GGG}GGG\?/\?\?\?@AA\?\?;\?CCCCC\?\?/AAAAAAA\?;MQaQAAA\?/A@\?@AA\?\?;CkSecCC\?/@\?\?B\?@@\?;Mo\?\?\?\?\?\?/\?\?@@AAA\?;\?wC\?[_\?\?/B\?\?\?\?@A\?;CCCGGG}\?/AAAAAA@\?;]aAAAAA\?/\?\?@AAA\?\?;\?_OGCGO\?/@\?\?\?\?\?\?\?;CsC}CsC\?/@\?\?BA\?@\?;EIQaaQA\?/\?\?A@\?\?\?\?;CSQIII\?\?/AAA@@@@\?;\?o\?EW_\?\?/B@@AABA\?;MO_OG\?\?\?/A@\?@AAA\?;OQQQ}QO\?/AAAA@\?\?\?;WgGG}GG\?/\?\?@\?B\?\?\?;\?\?{CCC\?\?/AABAAAA\?;}QQQQQQ\?/BAAAAAA\?;WiIIIIG\?/\?\?@AAA\?\?;}\?\?\?\?\?]\?/\?@AAAA\?\?;_\?}\?\?}\?\?/\?@B\?\?@A\?;O_\?\?\?\?}\?/\?\?@@AAB\?;}AAAAA}\?/BAAAAAB\?;]aAAAAM\?/\?\?@AAA\?\?;]iIIIII\?/\?\?@AAA\?\?;]_\?\?CCC\?/\?\?@AAAA\?\033\\" #define SELECT_MATRIX_SOFTFONT "\033( M" #define UNSELECT_SOFTFONT "\033(B" @@ -47,10 +39,86 @@ struct Trail { struct Trail trails[MAX_TRAILS]; int trail_timer = 0; +/* Keep track of whether the Matrix softfont or the default ASCII ROM font is selected */ +int softfontCharsetSelected = 0; + + +void loadMatrixSoftfont() +{ + int i; + + /* + ** Strings to load a VT220 softfont providing the extra Matrix characters, select it and unselect it. + ** This softfont contains 46 mirrored katakana as ASCII !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN + ** The real term is a Dynamically Replaceable Character Sets (DRCS) loaded into the terminal's + ** memory using a Down-Line-Loading DRCS (DECDLD) control string. The font is built using Sixels. + ** Font design by Philippe Majerus, January 2025 + */ + const char* softfont[] = { + // DECDLD parameters + "\033P1;1;2{ M", + // Characters sixels: + /* ! */ "MQAyAAA\?/\?\?\?\?@A\?\?" ";", + /* " */ "\?ACwGOO\?/\?\?\?B\?\?\?\?" ";", + /* # */ "{CCECC[\?/\?@AAA\?\?\?" ";", + /* $ */ "\?CC{CC\?\?/AAABAAA\?" ";", + /* % */ "CC}ScCC\?/\?\?B\?\?@A\?" ";", + /* & */ "{CCC}CC\?/@AAA\?@A\?" ";", + /* ' */ "_gg}gg_\?/\?\?\?B\?\?\?\?" ";", + /* ( */ "{CCCCMO\?/\?@AAA\?\?\?" ";", + /* ) */ "CC{CCMO\?/\?\?\?@AA\?\?" ";", + /* * */ "{CCCCCC\?/BAAAAAA\?" ";", + /* + */ "C}CCC]C\?/\?\?@AAA\?\?" ";", + /* , */ "]_\?\?SSS\?/\?\?@AAAA\?" ";", + /* - */ "EIqaAAA\?/A@\?\?@AA\?" ";", + /* . */ "KSCCC}C\?/AAAAA@\?\?" ";", + /* / */ "Mo\?\?\?WE\?/\?\?@AAAA\?" ";", + /* 0 */ "{csSCMO\?/\?@AAAA\?\?" ";", + /* 1 */ "OQQ{SSO\?/\?\?\?@A\?\?\?" ";", + /* 2 */ "]_\?M\?\?M\?/\?\?@AAAA\?" ";", + /* 3 */ "GIIyIIG\?/\?\?\?@A\?\?\?" ";", + /* 4 */ "OOGG}\?\?\?/\?\?\?\?B\?\?\?" ";", + /* 5 */ "GGG}GGG\?/\?\?\?@AA\?\?" ";", + /* 6 */ "\?CCCCC\?\?/AAAAAAA\?" ";", + /* 7 */ "MQaQAAA\?/A@\?@AA\?\?" ";", + /* 8 */ "CkSecCC\?/@\?\?B\?@@\?" ";", + /* 9 */ "Mo\?\?\?\?\?\?/\?\?@@AAA\?" ";", + /* : */ "\?wC\?[_\?\?/B\?\?\?\?@A\?" ";", + /* ; */ "CCCGGG}\?/AAAAAA@\?" ";", + /* < */ "]aAAAAA\?/\?\?@AAA\?\?" ";", + /* = */ "\?_OGCGO\?/@\?\?\?\?\?\?\?" ";", + /* > */ "CsC}CsC\?/@\?\?BA\?@\?" ";", + /* ? */ "EIQaaQA\?/\?\?A@\?\?\?\?" ";", + /* @ */ "CSQIII\?\?/AAA@@@@\?" ";", + /* A */ "\?o\?EW_\?\?/B@@AABA\?" ";", + /* B */ "MO_OG\?\?\?/A@\?@AAA\?" ";", + /* C */ "OQQQ}QO\?/AAAA@\?\?\?" ";", + /* D */ "WgGG}GG\?/\?\?@\?B\?\?\?" ";", + /* E */ "\?\?{CCC\?\?/AABAAAA\?" ";", + /* F */ "}QQQQQQ\?/BAAAAAA\?" ";", + /* G */ "WiIIIIG\?/\?\?@AAA\?\?" ";", + /* H */ "}\?\?\?\?\?]\?/\?@AAAA\?\?" ";", + /* I */ "_\?}\?\?}\?\?/\?@B\?\?@A\?" ";", + /* J */ "O_\?\?\?\?}\?/\?\?@@AAB\?" ";", + /* K */ "}AAAAA}\?/BAAAAAB\?" ";", + /* L */ "]aAAAAM\?/\?\?@AAA\?\?" ";", + /* M */ "]iIIIII\?/\?\?@AAA\?\?" ";", + /* N */ "]_\?\?CCC\?/\?\?@AAAA\?" "\033\\" + // Other characters are not defined in this softfont + }; + + for (i=0;i