-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMinitel1B_Soft.cpp
1246 lines (1149 loc) · 46.1 KB
/
Minitel1B_Soft.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
////////////////////////////////////////////////////////////////////////
/*
Minitel1B_Soft - Fichier source - Version du 12 mars 2023 à 04h55
Copyright 2016-2023 - Eric Sérandour
https://entropie.org/3615/
Remerciements à :
BorisFR, iodeo
Documentation utilisée :
Spécifications Techniques d'Utilisation du Minitel 1B
http://543210.free.fr/TV/stum1b.pdf
////////////////////////////////////////////////////////////////////////
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////
#include "Minitel1B_Soft.h"
////////////////////////////////////////////////////////////////////////
/*
Public
*/
////////////////////////////////////////////////////////////////////////
Minitel::Minitel(int rx, int tx) : SoftwareSerial(rx,tx) {
// A la mise sous tension du Minitel, la vitesse des échanges entre
// le Minitel et le périphérique est de 1200 bauds par défaut.
begin(1200);
}
/*--------------------------------------------------------------------*/
void Minitel::writeByte(byte b) {
// Le bit de parité est mis à 0 si la somme des autres bits est paire
// et à 1 si elle est impaire.
boolean parite = 0;
for (int i=0; i<7; i++) {
if (bitRead(b,i) == 1) {
parite = !parite;
}
}
if (parite) {
bitWrite(b,7,1); // Ecriture du bit de parité
}
else {
bitWrite(b,7,0); // Ecriture du bit de parité
}
write(b); // Envoi de l'octet sur le port série
}
/*--------------------------------------------------------------------*/
void Minitel::writeWord(word w) {
writeByte(highByte(w));
writeByte(lowByte(w));
}
/*--------------------------------------------------------------------*/
void Minitel::writeCode(unsigned long code) {
// Fonction proposée par iodeo sur GitHub en février 2023
// Initialement, cette fonction se nommait write, mais j'ai dû changer
// son nom car avec ce nom un problème est apparu dans l'usage de la
// bibliothèque Minitel1B_Soft : le Minitel se bloquait. Il s'agissait
// probablement d'un conflit avec la fonction write de la bibliothèque
// SoftwareSerial. Par souci de cohérence entre les bibliothèques
// Minitel1B_Hard et Minitel1B_Soft, j'ai renommé write en writeCode.
if (code > 0x00FFFFFF) writeByte((byte) (code >> 24));
if (code > 0x0000FFFF) writeByte((byte) (code >> 16));
if (code > 0x000000FF) writeByte((byte) (code >> 8));
writeByte((byte) code);
}
/*--------------------------------------------------------------------*/
byte Minitel::readByte() {
byte b = read();
// Le bit de parité est à 0 si la somme des autres bits est paire
// et à 1 si elle est impaire.
boolean parite = 0;
for (int i=0; i<7; i++) {
if (bitRead(b,i) == 1) {
parite = !parite;
}
}
if (bitRead(b,7) == parite) { // La transmission est bonne, on peut récupérer la donnée.
if (bitRead(b,7) == 1) { // Cas où le bit de parité vaut 1.
b = b ^ 0b10000000; // OU exclusif pour mettre le bit de parité à 0 afin de récupérer la donnée.
}
return b;
}
else {
return 0xFF; // Pour indiquer une erreur de parité.
}
}
/*--------------------------------------------------------------------*/
unsigned long Minitel::identifyDevice() { // Voir p.139
// Fonction proposée par iodeo sur GitHub en février 2023
// Demande
writeBytesPRO(1); // 0x1B 0x39
writeByte(ENQROM); // 0x7B
// Réponse
return identificationBytes(); // 3 octets
// octet définissant le constructeur du Minitel
// octet définissant le type du Minitel
// octet définissant la version du logiciel
// Codes d'identification de l'octet de poids fort :
/*
Philips : 0x42
Telic-Alcatel : 0x43
à compléter...
*/
// Codes d'identification de l'octet du milieu (voir p.103 du Guide STU du Minitel 2) :
/*
Minitel 1 : 0x62, 0x63 ou 0x72 suivant les modèles
Minitel 1 Couleur : 0x73
Minitel 1 Dialogue : 0x72
Minitel 10 : 0x64 ou 0x66 suivant les modèles
Minitel 1 Bistandard : 0x75
Minitel 10 Bistandard : 0x77
Minitel 2 : 0x76
Minitel 12 : 0x7A
Minitel 5 : 0x79
*/
}
/*--------------------------------------------------------------------*/
int Minitel::changeSpeed(int bauds) { // Voir p.141
// Fonction modifiée par iodeo sur GitHub en octobre 2021
// Format de la commande
writeBytesPRO(2); // 0x1B 0x3A
writeByte(PROG); // 0x6B
switch (bauds) {
case 300 : writeByte(0b1010010); break; // 0x52
case 1200 : writeByte(0b1100100); break; // 0x64
case 4800 : writeByte(0b1110110); break; // 0x76
case 9600 : writeByte(0b1111111); break; // 0x7F (pour le Minitel 2 seulement)
}
#if defined(ESP32) || defined(ARDUINO_ARCH_ESP32)
flush(false); // Patch pour Arduino-ESP32 core v1.0.6 https://github.com/espressif/arduino-esp32
#endif
end();
begin(bauds);
// Acquittement
return workingSpeed(); // En bauds (voir section Private ci-dessous)
}
/*--------------------------------------------------------------------*/
int Minitel::currentSpeed() { // Voir p.141
// Demande
writeBytesPRO(1);
writeByte(STATUS_VITESSE);
// Réponse
return workingSpeed(); // En bauds (voir section Private ci-dessous)
}
/*--------------------------------------------------------------------*/
int Minitel::searchSpeed() {
const int SPEED[4] = { 1200, 4800, 300, 9600 }; // 9600 bauds pour le Minitel 2 seulement
int i = 0;
int speed;
do {
begin(SPEED[i]);
if (i++ > 3) { i = 0; }
speed = currentSpeed();
} while (speed < 0);
return speed; // En bauds
}
/*--------------------------------------------------------------------*/
void Minitel::newScreen() {
writeByte(FF);
currentSize = GRANDEUR_NORMALE;
}
/*--------------------------------------------------------------------*/
void Minitel::newXY(int x, int y) {
if (x==1 && y==1) {
writeByte(RS);
}
else {
// Le code US est suivi de deux caractères non visualisés. Si les
// octets correspondants à ces deux caractères appartiennent tous deux
// aux colonnes 4 à 7, ils représentent respectivement (sous forme
// binaire avec 6 bits utiles) le numéro de rangée et le numéro de
// colonne du premier caractère du sous-article (voir p.96).
writeByte(US);
writeByte(0x40 + y); // Numéro de rangée
writeByte(0x40 + x); // Numéro de colonne
}
currentSize = GRANDEUR_NORMALE;
}
/*--------------------------------------------------------------------*/
void Minitel::cursor() {
writeByte(CON);
}
/*--------------------------------------------------------------------*/
void Minitel::noCursor() {
writeByte(COFF);
}
/*--------------------------------------------------------------------*/
void Minitel::moveCursorXY(int x, int y) { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeBytesP(y); // Pr : Voir section Private ci-dessous
writeByte(0x3B);
writeBytesP(x); // Pc : Voir section Private ci-dessous
writeByte(0x48);
}
/*--------------------------------------------------------------------*/
void Minitel::moveCursorLeft(int n) { // Voir p.94 et 95
if (n==1) { writeByte(BS); }
else if (n>1) {
// Curseur vers la gauche de n colonnes. Arrêt au bord gauche de l'écran.
writeWord(CSI); // 0x1B 0x5B
writeBytesP(n); // Pn : Voir section Private ci-dessous
writeByte(0x44);
}
}
/*--------------------------------------------------------------------*/
void Minitel::moveCursorRight(int n) { // Voir p.94
if (n==1) { writeByte(HT); }
else if (n>1) {
// Curseur vers la droite de n colonnes. Arrêt au bord droit de l'écran.
writeWord(CSI); // 0x1B 0x5B
writeBytesP(n); // Pn : Voir section Private ci-dessous
writeByte(0x43);
}
}
/*--------------------------------------------------------------------*/
void Minitel::moveCursorDown(int n) { // Voir p.94
if (n==1) { writeByte(LF); }
else if (n>1) {
// Curseur vers le bas de n rangées. Arrêt en bas de l'écran.
writeWord(CSI); // 0x1B 0x5B
writeBytesP(n); // Pn : Voir section Private ci-dessous
writeByte(0x42);
}
}
/*--------------------------------------------------------------------*/
void Minitel::moveCursorUp(int n) { // Voir p.94
if (n==1) { writeByte(VT); }
else if (n>1) {
// Curseur vers le haut de n rangées. Arrêt en haut de l'écran.
writeWord(CSI); // 0x1B 0x5B
writeBytesP(n); // Pn : Voir section Private ci-dessous
writeByte(0x41);
}
}
/*--------------------------------------------------------------------*/
void Minitel::moveCursorReturn(int n) { // Voir p.94
writeByte(CR);
moveCursorDown(n); // Pour davantage de souplesse
}
/*--------------------------------------------------------------------*/
int Minitel::getCursorX() {
return (getCursorXY() & 0x0000FF) - 0x40;
}
/*--------------------------------------------------------------------*/
int Minitel::getCursorY() {
return ((getCursorXY() & 0x00FF00) >> 8) - 0x40;
}
/*--------------------------------------------------------------------*/
void Minitel::cancel() { // Voir p.95
writeByte(CAN);
}
/*--------------------------------------------------------------------*/
void Minitel::clearScreenFromCursor() { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
// writeByte(0x30); Inutile
writeByte(0x4A);
}
/*--------------------------------------------------------------------*/
void Minitel::clearScreenToCursor() { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeByte(0x31);
writeByte(0x4A);
}
/*--------------------------------------------------------------------*/
void Minitel::clearScreen() { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeByte(0x32);
writeByte(0x4A);
}
/*--------------------------------------------------------------------*/
void Minitel::clearLineFromCursor() { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
// writeByte(0x30); Inutile
writeByte(0x4B);
}
/*--------------------------------------------------------------------*/
void Minitel::clearLineToCursor() { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeByte(0x31);
writeByte(0x4B);
}
/*--------------------------------------------------------------------*/
void Minitel::clearLine() { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeByte(0x32);
writeByte(0x4B);
}
/*--------------------------------------------------------------------*/
void Minitel::deleteChars(int n) { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeBytesP(n); // Voir section Private ci-dessous
writeByte(0x50);
}
/*--------------------------------------------------------------------*/
void Minitel::insertChars(int n) { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeBytesP(n); // Voir section Private ci-dessous
writeByte(0x40);
}
/*--------------------------------------------------------------------*/
void Minitel::startInsert() { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeByte(0x34);
writeByte(0x68);
}
/*--------------------------------------------------------------------*/
void Minitel::stopInsert() { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeByte(0x34);
writeByte(0x6C);
}
/*--------------------------------------------------------------------*/
void Minitel::deleteLines(int n) { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeBytesP(n); // Voir section Private ci-dessous
writeByte(0x4D);
}
/*--------------------------------------------------------------------*/
void Minitel::insertLines(int n) { // Voir p.95
writeWord(CSI); // 0x1B 0x5B
writeBytesP(n); // Voir section Private ci-dessous
writeByte(0x4C);
}
/*--------------------------------------------------------------------*/
void Minitel::textMode() {
writeByte(SI); // Accès au jeu G0 (voir p.100)
}
/*--------------------------------------------------------------------*/
void Minitel::graphicMode() {
writeByte(SO); // Accès au jeu G1 (voir p.101 & 102)
}
/*--------------------------------------------------------------------*/
byte Minitel::pageMode() {
// Commande
writeBytesPRO(2); // 0x1B 0x3A
writeByte(STOP); // 0x6A
writeByte(ROULEAU); // 0x43
// Acquittement
return workingMode(); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::scrollMode() {
// Commande
writeBytesPRO(2); // 0x1B 0x3A
writeByte(START); // 0x69
writeByte(ROULEAU); // 0x43
// Acquittement
return workingMode(); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::modeMixte() { // Voir p.144
// Passage du standard Télétel mode Vidéotex au standard Télétel mode Mixte
// Commande
writeBytesPRO(2); // 0x1B 0x3A
writeWord(MIXTE1); // 0x32 0x7D
// Acquittement
return workingStandard(0x1370); // SEP (0x13), 0x70
}
/*--------------------------------------------------------------------*/
byte Minitel::modeVideotex() { // Voir p.144
// Passage du standard Télétel mode Mixte au standard Télétel mode Vidéotex
// Commande
writeBytesPRO(2); // 0x1B 0x3A
writeWord(MIXTE2); // 0x32 0x7E
// Acquittement
return workingStandard(0x1371); // SEP (0x13), 0x71
}
/*--------------------------------------------------------------------*/
byte Minitel::standardTeleinformatique() { // Voir p.144
// Passage du standard Télétel au standard Téléinformatique
// Commande
writeBytesPRO(2); // 0x1B 0x3A
writeWord(TELINFO); // 0x31 0x7D
// Acquittement
return workingStandard(0x1B5B3F7A); // CSI (0x1B,0x5B), 0x3F, 0x7A
}
/*--------------------------------------------------------------------*/
byte Minitel::standardTeletel() { // Voir p.144
// Passage du standard Téléinformatique au standard Télétel
// Commande
writeWord(CSI); // 0x1B Ox5B
writeByte(0x3F);
writeByte(0x7B);
// Acquittement
return workingStandard(0x135E); // SEP (0x13), 0x5E
}
/*--------------------------------------------------------------------*/
void Minitel::attributs(byte attribut) {
writeByte(ESC); // Accès à la grille C1 (voir p.92)
writeByte(attribut);
if (attribut == DOUBLE_HAUTEUR || attribut == DOUBLE_GRANDEUR) {
moveCursorDown(1);
currentSize = attribut;
}
else if (attribut == GRANDEUR_NORMALE || attribut == DOUBLE_LARGEUR) {
currentSize = attribut;
}
}
/*--------------------------------------------------------------------*/
void Minitel::print(String chaine) {
// Fonction modifiée par iodeo sur GitHub en février 2023
/*
// Fonction initiale (pour mémoire) // Obsolète depuis le 26/02/2023
for (int i=0; i<chaine.length(); i++) {
unsigned char caractere = chaine.charAt(i);
if (!isDiacritic(caractere)) {
printChar(caractere);
}
else {
i+=1; // Un caractère accentué prend la place de 2 caractères
caractere = chaine.charAt(i);
printDiacriticChar(caractere);
}
}
*/
// codes UTF-8 vers codes Minitel
unsigned int i = 0;
while (i < chaine.length()) {
unsigned long code = (byte) chaine.charAt(i++);
if (code < SP) code = 0;
else if (code >= SP && code <= DEL) {
switch (code) {
case 0x5E: code = 0; break; // ^ non visualisable seul
case 0x60: code = 0; break; // ` non visualisable seul
}
}
else if (code == 0xC2 || code == 0xC3 || code == 0xC5 || code == 0xCE) {
// Caractères sur 2 octets
code = (code << 8) + (byte) chaine.charAt(i++);
switch (code) { // Voir p.90 pour VGP5 ou VGP2
// 0x19 => SS2 (Accès au jeu G2)
// 0x0F => SI (Accès au jeu G0)
case 0xC2A3: code = 0x1923; break; // £ (VGP5 et VGP2)
case 0xC2A7: code = 0x1927; break; // § (VGP5 seulement)
case 0xC2B0: code = 0x1930; break; // ° (VGP5 et VGP2)
case 0xC2B1: code = 0x1931; break; // ± (VGP5 et VGP2)
case 0xC2BC: code = 0x193C; break; // ¼ (VGP5 et VGP2)
case 0xC2BD: code = 0x193D; break; // ½ (VGP5 et VGP2)
case 0xC2BE: code = 0x193E; break; // ¾ (VGP5 et VGP2)
case 0xC380: code = 0x0F41; break; // À (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC382: code = 0x0F41; break; // Â (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC384: code = 0x0F41; break; // Ä (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC387: code = 0x0F43; break; // Ç (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC388: code = 0x0F45; break; // È (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC389: code = 0x0F45; break; // É (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC38A: code = 0x0F45; break; // Ê (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC38B: code = 0x0F45; break; // Ë (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC38E: code = 0x0F49; break; // Î (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC38F: code = 0x0F49; break; // Ï (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC394: code = 0x0F4F; break; // Ô (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC396: code = 0x0F4F; break; // Ö (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC399: code = 0x0F55; break; // Ù (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC39B: code = 0x0F55; break; // Û (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC39C: code = 0x0F55; break; // Ü (Aucune lettre accentuée majuscule n'est disponible - voir p.90)
case 0xC3A0: code = 0x194161; break; // à (VGP5 et VGP2)
case 0xC3A2: code = 0x194361; break; // â (VGP5 et VGP2)
case 0xC3A4: code = 0x194861; break; // ä (VGP5 seulement)
case 0xC3A7: code = 0x194B63; break; // ç (VGP5 et VGP2)
case 0xC3A8: code = 0x194165; break; // è (VGP5 et VGP2)
case 0xC3A9: code = 0x194265; break; // é (VGP5 et VGP2)
case 0xC3AA: code = 0x194365; break; // ê (VGP5 et VGP2)
case 0xC3AB: code = 0x194865; break; // ë (VGP5 et VGP2)
case 0xC3AE: code = 0x194369; break; // î (VGP5 et VGP2)
case 0xC3AF: code = 0x194869; break; // ï (VGP5 et VGP2)
case 0xC3B4: code = 0x19436F; break; // ô (VGP5 et VGP2)
case 0xC3B6: code = 0x19486F; break; // ö (VGP5 seulement)
case 0xC3B7: code = 0x1938; break; // ÷ (VGP5 et VGP2)
case 0xC3B9: code = 0x194175; break; // ù (VGP5 et VGP2)
case 0xC3BB: code = 0x194375; break; // û (VGP5 et VGP2)
case 0xC3BC: code = 0x194875; break; // ü (VGP5 seulement)
case 0xC592: code = 0x196A; break; // Œ (VGP5 et VGP2)
case 0xC593: code = 0x197A; break; // œ (VGP5 et VGP2)
case 0xCEB2: code = 0x197B; break; // β (VGP5 seulement)
default: code = 0; // supposé non-visualisable
}
}
else if (code == 0xE2) {
// Caractères sur 3 octets
code = (code << 8) + (byte) chaine.charAt(i++);
code = (code << 8) + (byte) chaine.charAt(i++);
switch (code) {
case 0xE28094: code = 0x60; break; // —
case 0xE28690: code = 0x192C; break; // ←
case 0xE28691: code = 0x5E; break; // ↑
case 0xE28692: code = 0x192E; break; // →
case 0xE28693: code = 0x192F; break; // ↓
default: code = 0; // supposé non-visualisable
}
}
if (code != 0) writeCode(code);
}
}
/*--------------------------------------------------------------------*/
void Minitel::println(String chaine) {
print(chaine);
if (currentSize == DOUBLE_HAUTEUR || currentSize == DOUBLE_GRANDEUR) {
moveCursorReturn(2);
}
else {
moveCursorReturn(1);
}
}
/*--------------------------------------------------------------------*/
void Minitel::println() {
if (currentSize == DOUBLE_HAUTEUR || currentSize == DOUBLE_GRANDEUR) {
moveCursorReturn(2);
}
else {
moveCursorReturn(1);
}
}
/*--------------------------------------------------------------------*/
void Minitel::printChar(char caractere) {
// Peut s'utiliser de 2 manières : printChar('A') ou printChar(0x41) par exemple
// printChar("A") ne fonctionne pas
byte charByte = getCharByte(caractere);
if (isValidChar(charByte)) {
writeByte(charByte);
}
}
/*--------------------------------------------------------------------*/
/*
void Minitel::printDiacriticChar(unsigned char caractere) { // Obsolète depuis le 26/02/2023
writeByte(SS2); // Accès au jeu G2 (voir p.103)
String diacritics = "àâäèéêëîïôöùûüçÀÂÄÈÉÊËÎÏÔÖÙÛÜÇ";
// Dans une chaine de caractères, un caractère diacritique prend la
// place de 2 caractères simples, ce qui explique le /2.
int index = (diacritics.indexOf(caractere)-1)/2;
char car;
switch (index) {
case( 0): car = 'a'; writeByte(ACCENT_GRAVE); break;
case( 1): car = 'a'; writeByte(ACCENT_CIRCONFLEXE); break;
case( 2): car = 'a'; writeByte(TREMA); break;
case( 3): car = 'e'; writeByte(ACCENT_GRAVE); break;
case( 4): car = 'e'; writeByte(ACCENT_AIGU); break;
case( 5): car = 'e'; writeByte(ACCENT_CIRCONFLEXE); break;
case( 6): car = 'e'; writeByte(TREMA); break;
case( 7): car = 'i'; writeByte(ACCENT_CIRCONFLEXE); break;
case( 8): car = 'i'; writeByte(TREMA); break;
case( 9): car = 'o'; writeByte(ACCENT_CIRCONFLEXE); break;
case(10): car = 'o'; writeByte(TREMA); break;
case(11): car = 'u'; writeByte(ACCENT_GRAVE); break;
case(12): car = 'u'; writeByte(ACCENT_CIRCONFLEXE); break;
case(13): car = 'u'; writeByte(TREMA); break;
case(14): car = 'c'; writeByte(CEDILLE); break;
// Pour les cas où on essaye d'afficher un caractère diacritique majuscule,
// ce que ne peut pas faire le Minitel.
case(15): car = 'A'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(16): car = 'A'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(17): car = 'A'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(18): car = 'E'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(19): car = 'E'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(20): car = 'E'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(21): car = 'E'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(22): car = 'I'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(23): car = 'I'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(24): car = 'O'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(25): car = 'O'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(26): car = 'U'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(27): car = 'U'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(28): car = 'U'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
case(29): car = 'C'; writeByte(SI); break; // Accès au jeu G0 (voir p.100)
}
printChar(car);
}
*/
/*--------------------------------------------------------------------*/
void Minitel::printSpecialChar(byte b) {
// N'est pas fonctionnelle pour les diacritiques (accents, tréma et cédille)
writeByte(SS2); // Accès au jeu G2 (voir p.103)
writeByte(b);
}
/*--------------------------------------------------------------------*/
byte Minitel::getCharByte(char caractere) {
// Voir les codes et séquences émis en mode Vidéotex (Jeu G0 p.100).
// Dans la chaine ci-dessous, on utilise l'échappement (\) :
// \" rend au guillemet sa signification littérale.
// \\ donne à l'antislash sa signification littérale .
String caracteres = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_xabcdefghijklmnopqrstuvwxyz{|}";
return (byte) caracteres.lastIndexOf(caractere);
}
/*--------------------------------------------------------------------*/
String Minitel::getString(unsigned long code) {
// Fonction proposée par iodeo sur GitHub en février 2023
// Convertit un caractère Unicode en String UTF-8
// Renvoie "" si le code ne correspond pas à un caractère visualisable
String str = "";
// Pour test
/*
Serial.print("isVisual ");
Serial.print(code);
Serial.print("\t : ");
Serial.println(isVisualisable(code));
*/
if (isVisualisable(code)) {
if (code < 0x80) { // U+0000 à U+007F
str += char(code);
} else if (code < 0x800) { // U+0080 à U+07FF
str += char((0b110 << 5) | (code >> 6));
str += char((0b10 << 6) | (code & 0x3F));
} else if(code < 0x10000) { // U+0800 à U+FFFF
str += char((0b1110 << 4) | (code >> 12));
str += char((0b10 << 6) | ((code >> 6) & 0x3F));
str += char((0b10 << 6) | (code & 0x3F));
}
}
return str;
}
/*--------------------------------------------------------------------*/
int Minitel::getNbBytes(unsigned long code) {
// Cette fonction est à utiliser en association avec getString(unsigned long code) juste ci-dessus
// Elle renvoie le nombre d'octets d'un caractère codé en String UTF-8
int nbBytes = 0;
if (isVisualisable(code)) {
if (code < 0x80) { // U+0000 à U+007F
nbBytes = 1; // 1 octet
} else if (code < 0x800) { // U+0080 à U+07FF
nbBytes = 2; // 2 octets
} else if(code < 0x10000) { // U+0800 à U+FFFF
nbBytes = 3; // 3 octets
}
}
return nbBytes;
}
/*--------------------------------------------------------------------*/
void Minitel::graphic(byte b, int x, int y) {
moveCursorXY(x,y);
graphic(b);
}
/*--------------------------------------------------------------------*/
void Minitel::graphic(byte b) {
// Voir Jeu G1 page 101.
if (b <= 0b111111) {
b = 0x20
+ bitRead(b,5)
+ bitRead(b,4) * 2
+ bitRead(b,3) * 4
+ bitRead(b,2) * 8
+ bitRead(b,1) * 16
+ bitRead(b,0) * 64;
if (b == 0x7F) { // 0b1111111
b= 0x5F;
}
writeByte(b);
}
}
/*--------------------------------------------------------------------*/
void Minitel::repeat(int n) { // Voir p.98
writeByte(REP);
writeByte(0x40 + n);
}
/*--------------------------------------------------------------------*/
void Minitel::bip() { // Voir p.98
writeByte(BEL);
}
/*--------------------------------------------------------------------*/
void Minitel::rect(int x1, int y1, int x2, int y2) {
hLine(x1,y1,x2,BOTTOM);
vLine(x2,y1+1,y2,RIGHT,DOWN);
hLine(x1,y2,x2,TOP);
vLine(x1,y1,y2-1,LEFT,UP);
}
/*--------------------------------------------------------------------*/
void Minitel::hLine(int x1, int y, int x2, int position) {
textMode();
moveCursorXY(x1,y);
switch (position) {
case TOP : writeByte(0x7E); break;
case CENTER : writeByte(0x60); break;
case BOTTOM : writeByte(0x5F); break;
}
repeat(x2-x1);
}
/*--------------------------------------------------------------------*/
void Minitel::vLine(int x, int y1, int y2, int position, int sens) {
textMode();
switch (sens) {
case DOWN : moveCursorXY(x,y1); break;
case UP : moveCursorXY(x,y2); break;
}
for (int i=0; i<y2-y1; i++) {
switch (position) {
case LEFT : writeByte(0x7B); break;
case CENTER : writeByte(0x7C); break;
case RIGHT : writeByte(0x7D); break;
}
switch (sens) {
case DOWN : moveCursorLeft(1); moveCursorDown(1); break;
case UP : moveCursorLeft(1); moveCursorUp(1); break;
}
}
}
/*--------------------------------------------------------------------*/
unsigned long Minitel::getKeyCode(bool unicode) {
// Renvoie le code brut émis par le clavier (unicode = false)
// ou sa conversion unicode si applicable (unicode = true, choix par défaut)
unsigned long code = 0;
// Code unique
if (available()>0) {
code = readByte();
}
// Séquences de deux ou trois codes (voir p.118)
if (code == 0x19) { // SS2
while (!available()>0); // Indispensable
code = (code << 8) + readByte();
// Les diacritiques (3 codes)
if ((code == 0x1941) || (code == 0x1942) || (code == 0x1943) || (code == 0x1948) || (code == 0x194B)) { // Accents, tréma, cédille
// Bug 1 : Pour éviter de compter un caractère lorsqu'on appuie plusieurs fois de suite sur une touche avec accent ou tréma
byte caractere = 0x19;
while (caractere == 0x19) {
while (!available()>0); // Indispensable
caractere = readByte();
if (caractere == 0x19) {
while (!available()>0); // Indispensable
caractere = readByte();
caractere = 0x19;
}
}
// Bug 2 : Pour éviter de compter un caractère lorsqu'on appuie sur les touches de fonction après avoir appuyé sur une touche avec accent ou tréma
if (caractere == 0x13) { // Les touches RETOUR REPETITION GUIDE ANNULATION SOMMAIRE CORRECTION SUITE CONNEXION_FIN ont un code qui commence par 0x13
while (!available()>0); // Indispensable
caractere = readByte(); // Les touches de fonction sont codées sur 2 octets (0x13..)
caractere = 0;
code = 0;
}
code = (code << 8) + caractere;
if (unicode) {
switch (code) { // On convertit le code reçu en unicode
case 0x194161 : code = 0xE0; break; // à
case 0x194165 : code = 0xE8; break; // è
case 0x194175 : code = 0xF9; break; // ù
case 0x194265 : code = 0xE9; break; // é
case 0x194361 : code = 0xE2; break; // â
case 0x194365 : code = 0xEA; break; // ê
case 0x194369 : code = 0xEE; break; // î
case 0x19436F : code = 0xF4; break; // ô
case 0x194375 : code = 0xFB; break; // û
case 0x194861 : code = 0xE4; break; // ä
case 0x194865 : code = 0xEB; break; // ë
case 0x194869 : code = 0xEF; break; // ï
case 0x19486F : code = 0xF6; break; // ö
case 0x194875 : code = 0xFC; break; // ü
case 0x194B63 : code = 0xE7; break; // ç
default : code = caractere; break;
}
}
}
// Les autres caractères spéciaux disponibles sous Arduino (2 codes)
else {
if (unicode) {
switch (code) { // On convertit le code reçu en unicode
case 0x1923 : code = 0xA3; break; // Livre
case 0x1927 : code = 0xA7; break; // Paragraphe
case 0x192C : code = 0x2190; break; // Flèche gauche
case 0x192E : code = 0x2192; break; // Flèche droite
case 0x192F : code = 0x2193; break; // Flèche bas
case 0x1930 : code = 0xB0; break; // Degré
case 0x1931 : code = 0xB1; break; // Plus ou moins
case 0x1938 : code = 0xF7; break; // Division
case 0x196A : code = 0x0152; break; // Ligature OE
case 0x197A : code = 0x0153; break; // Ligature oe
case 0x197B : code = 0x03B2; break; // Bêta
}
}
}
}
// Touches de fonction (voir p.123)
else if (code == 0x13) {
while (!available()>0); // Indispensable
code = (code << 8) + readByte();
}
// Touches de gestion du curseur lorsque le clavier est en mode étendu (voir p.124)
// Pour passer au clavier étendu manuellement : Fnct C + E
// Pour revenir au clavier vidéotex standard : Fnct C + V
else if (code == 0x1B) {
delay(20); // Indispensable. 0x1B seul correspond à la touche Esc,
// on ne peut donc pas utiliser la boucle while (!available()>0).
if (available()>0) {
code = (code << 8) + readByte();
if (code == 0x1B5B) {
while (!available()>0); // Indispensable
code = (code << 8) + readByte();
if ((code == 0x1B5B34) || (code == 0x1B5B32)) {
while (!available()>0); // Indispensable
code = (code << 8) + readByte();
}
}
}
}
else {
if (unicode) { // On convertit les codes uniques en unicode
switch (code) {
case 0x5E : code = 0x2191; break; // Flèche haut
case 0x60 : code = 0x2014; break; // Tiret cadratin
}
}
}
// Pour test
/*
if (code != 0) {
Serial.print(code,HEX);
Serial.print(" ");
Serial.write(code);
Serial.println("");
}
*/
return code;
}
/*--------------------------------------------------------------------*/
byte Minitel::smallMode() {
// Commande
writeBytesPRO(2); // 0x1B 0x3A
writeByte(START); // 0x69
writeByte(MINUSCULES); // 0x45
// Acquittement
return workingMode(); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::capitalMode() {
// Commande
writeBytesPRO(2); // 0x1B 0x3A
writeByte(STOP); // 0x6A
writeByte(MINUSCULES); // 0x45
// Acquittement
return workingMode(); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::extendedKeyboard() {
// Commande
writeBytesPRO(3); // 0x1B 0x3B
writeByte(START); // 0x69
writeByte(CODE_RECEPTION_CLAVIER); // 0x59
writeByte(ETEN); // 0x41
// Acquittement
return workingKeyboard(); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::standardKeyboard() {
// Commande
writeBytesPRO(3); // 0x1B 0x3B
writeByte(STOP); // 0x6A
writeByte(CODE_RECEPTION_CLAVIER); // 0x59
writeByte(ETEN); // 0x41
// Acquittement
return workingKeyboard(); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::echo(boolean commande) { // Voir p.81, p.135 et p.156
// Fonction modifiée par iodeo sur GitHub en octobre 2021
// commande peut prendre comme valeur :
// true, false
return aiguillage(commande, CODE_EMISSION_CLAVIER, CODE_RECEPTION_MODEM);
}
/*--------------------------------------------------------------------*/
byte Minitel::aiguillage(boolean commande, byte emetteur, byte recepteur) { // Voir p.135
// commande peut prendre comme valeur :
// true, false
// emetteur peut prendre comme valeur :
// CODE_EMISSION_ECRAN, CODE_EMISSION_CLAVIER, CODE_EMISSION_MODEM, CODE_EMISSION_PRISE
// recepteur peut prendre comme valeur :
// CODE_RECEPTION_ECRAN, CODE_RECEPTION_CLAVIER, CODE_RECEPTION_MODEM, CODE_RECEPTION_PRISE
// Commande
writeBytesPRO(3); // 0x1B 0x3B
writeByte(commande ? AIGUILLAGE_ON : AIGUILLAGE_OFF); // 0x61 ou 0x60
writeByte(recepteur);
writeByte(emetteur);
// Acquittement
return workingAiguillage(recepteur); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::statusAiguillage(byte module) { // Voir p. 136
// module peut prendre comme valeur :
// CODE_EMISSION_ECRAN, CODE_EMISSION_CLAVIER, CODE_EMISSION_MODEM, CODE_EMISSION_PRISE
// CODE_RECEPTION_ECRAN, CODE_RECEPTION_CLAVIER, CODE_RECEPTION_MODEM, CODE_RECEPTION_PRISE
// Commande
writeBytesPRO(2); // 0x1B 0x3A
writeByte(TO); // 0x62
writeByte(module);
// Acquittement
return workingAiguillage(module); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::connexion(boolean commande) { // Voir p.139
// Fonction proposée par iodeo sur GitHub en octobre 2021
// commande peut prendre comme valeur :
// true, false
// Commande
writeBytesPRO(1); // 0x1B 0x39
writeByte(commande ? CONNEXION : DECONNEXION); // 0x68 ou 0x67
// Acquittement
return workingModem(); // Renvoie un octet
}
/*--------------------------------------------------------------------*/
byte Minitel::reset() { // Voir p.145
// Commande
writeBytesPRO(1); // 0x1B 0x39
writeByte(RESET); // 0x7F
// Acquittement
return workingStandard(0x135E); // SEP (0x13), 0x5E
}
/*--------------------------------------------------------------------*/
////////////////////////////////////////////////////////////////////////
/*
Private
*/
////////////////////////////////////////////////////////////////////////
boolean Minitel::isValidChar(byte index) {
// On vérifie que le caractère appartient au jeu G0 (voir p.100).
// SP (0x20) correspond à un espace et DEL (0x7F) à un pavé plein.
if (index >= SP && index <= DEL) {