Code:
// RP6 sendet VT100/Ansi-Steuerzeichen 24.4.10 mic
// http://www.termsys.demon.co.uk/vtansi.htm // vt100 Steuercodes
// https://www.roboternetz.de/phpBB2/ze...ag.php?t=48052 // farbige Ausgabe mit RP6
// https://www.roboternetz.de/phpBB2/viewtopic.php?t=53963 // Dialog über USART
// https://www.roboternetz.de/phpBB2/ze...rag.php?t=6793 // Bascom Terminal
// http://www.emtec.com/download.htm?what=zoc-d#zocfiles // ZOC-Download
#include "RP6RobotBaseLib.h"
#define vt100_Black 0
#define vt100_Red 1
#define vt100_Green 2
#define vt100_Yellow 3
#define vt100_Blue 4
#define vt100_Magenta 5
#define vt100_Cyan 6
#define vt100_White 7
#define vt100_Reset 0
#define vt100_Bright 1
#define vt100_Dim 2
#define vt100_Underscore 4
#define vt100_Blink 5
#define vt100_Reverse 7
#define vt100_Hidden 8
uint8_t c, r=1, p=1; // freies Char, Richtung und Position der *
uint16_t x, y;
uint8_t std, min, sec;
void vt100_cls(void)
{
writeString_P("\x1B[2J"); // clear screen ESC [ 2 J
writeString_P("\x1B[H"); // cursor home ESC [ H
}
void vt100_set_cursor(uint8_t line, uint8_t column)
{
writeString_P("\x1B["); // set cursor position ESC [ Pl ; Pc H
writeInteger(line, 10);
writeString_P(";");
writeInteger(column, 10);
writeString_P("H");
}
void vt100_set_color(uint8_t foreground, uint8_t background)
{
writeString_P("\x1b[");
writeInteger(30+foreground, 10);
writeString_P(";");
writeInteger(40+background, 10);
writeString_P("m");
}
void vt100_set_attrib(uint8_t attrib)
{
writeString_P("\x1b[");
writeInteger(0, 10);
writeString_P(";");
writeInteger(attrib, 10);
writeString_P("m");
}
void vt100_writeGrafic(uint8_t *string)
{
while(*string)
writeChar(128|*string++); // Grafikzeichen mit gesetztem Bit7 senden
}
void vt100_writeGraficAt(uint8_t line, uint8_t column, uint8_t *string)
{
vt100_set_cursor(line, column); // Cursor postionieren
while(*string)
writeChar(128|*string++); // Grafikzeichen mit gesetztem Bit7 senden
}
int main(void)
{
initRobotBase();
vt100_cls();
writeString_P(" Kleines VT100/Ansi-Demo mit dem RP6 2.5.10 mic");
vt100_set_color(7,0); // Fahne
vt100_set_cursor(1,73);
writeString(" ");
vt100_set_color(7,1);
vt100_set_cursor(2,73);
writeString(" ");
vt100_set_color(7,3);
vt100_set_cursor(3,73);
writeString(" ");
vt100_set_color(7,0);
vt100_set_cursor(4,73);
writeString("Fussball");
vt100_set_cursor(5,73);
writeString(" WM 2010");
for(x=0; x<8; x++) // Farbtabelle
{
for(y=0; y<8; y++)
{
vt100_set_color(x,y);
vt100_set_cursor(17+y, 2+x);
writeChar(0xb1);
}
}
vt100_set_color(7, 0); // Grafikzeichen
vt100_set_cursor(16, 33);
writeString_P("0 1 2 3 4 5 6 7 8 9 a b c d e f");
for(y=0x8; y<0x10; y++)
{
vt100_set_cursor(y+9, 31);
writeIntegerLength(y, 16, 1);
writeChar(' ');
for(x=0x0; x<0x10; x++)
{
writeChar(y*0x10+x);
if(y*0x10+x-128 > 31)
{
vt100_set_attrib(vt100_Bright);
writeChar(y*0x10+x-128);
vt100_set_attrib(vt100_Reset);
}
else writeChar(' ');
writeChar(' ');
}
}
vt100_set_cursor(4,2); // ADC-Werte ausgeben für Rabenauge
uint16_t GanzeVolt=10*737/1023;
writeChar(GanzeVolt+'0');
writeChar(',');
writeChar(10*737/102-10*GanzeVolt+'0');
writeChar('V');
vt100_set_cursor(5,2);
GanzeVolt=10*859/1023;
writeChar(GanzeVolt+'0');
writeChar(',');
writeChar(10*859/102-10*GanzeVolt+'0');
writeChar('V');
y=3; x=7;
vt100_writeGraficAt(y+0,x,"ZooBooBoo?"); // dünne Box
vt100_writeGraficAt(y+1,x,"3__3__3__3");
vt100_writeGraficAt(y+2,x,"CooEooEoo4");
vt100_writeGraficAt(y+3,x,"3__3__3__3");
vt100_writeGraficAt(y+4,x,"@ooAooAooY");
y=3; x+=10;
vt100_writeGraficAt(y+0,x,"VooRooRoo7"); // doppelte Box1
vt100_writeGraficAt(y+1,x,":__:__:__:");
vt100_writeGraficAt(y+2,x,"GooWooWoo6");
vt100_writeGraficAt(y+3,x,":__:__:__:");
vt100_writeGraficAt(y+4,x,"SooPooPoo=");
y=3; x+=10;
vt100_writeGraficAt(y+0,x,"UMMQMMQMM8"); // doppelte Box2
vt100_writeGraficAt(y+1,x,"3__3__3__3");
vt100_writeGraficAt(y+2,x,"FMMXMMXMM5");
vt100_writeGraficAt(y+3,x,"3__3__3__3");
vt100_writeGraficAt(y+4,x,"TMMOMMOMM>");
y=3; x+=10;
vt100_writeGraficAt(y+0,x,"IMMKMMKMM;"); // doppelte Box3
vt100_writeGraficAt(y+1,x,":__:__:__:");
vt100_writeGraficAt(y+2,x,"LMMNMMNMM9");
vt100_writeGraficAt(y+3,x,":__:__:__:");
vt100_writeGraficAt(y+4,x,"HMMJMMJMM<");
y=3; x+=12;
vt100_set_cursor(y+0,x); // Attribute
vt100_set_attrib(vt100_Bright);
writeString_P("Bright");
vt100_set_cursor(y+1,x);
vt100_set_attrib(vt100_Dim);
writeString_P("Dim");
vt100_set_cursor(y+2,x);
vt100_set_attrib(vt100_Underscore);
writeString_P("Underscore");
vt100_set_cursor(y+3,x);
vt100_set_attrib(vt100_Blink);
writeString_P("Blink");
vt100_set_cursor(y+4,x);
vt100_set_attrib(vt100_Reverse);
writeString_P("Reverse");
vt100_set_cursor(y+5,x);
vt100_set_attrib(vt100_Hidden);
writeString_P("Hidden");
vt100_set_attrib(vt100_Reset); // ;)
y=17; x=12;
vt100_set_cursor(y+0,x); // Farben
vt100_set_color(vt100_Black,0);
writeString_P("Black");
vt100_set_cursor(y+1,x);
vt100_set_color(vt100_Red,0);
writeString_P("Red");
vt100_set_cursor(y+2,x);
vt100_set_color(vt100_Green,0);
writeString_P("Green");
vt100_set_cursor(y+3,x);
vt100_set_color(vt100_Yellow,0);
writeString_P("Yellow");
vt100_set_cursor(y+4,x);
vt100_set_color(vt100_Blue,0);
writeString_P("Blue");
vt100_set_cursor(y+5,x);
vt100_set_color(vt100_Magenta,0);
writeString_P("Magenta");
vt100_set_cursor(y+6,x);
vt100_set_color(vt100_Cyan,0);
writeString_P("Cyan");
vt100_set_cursor(y+7,x);
vt100_set_color(vt100_White,0);
writeString_P("White");
vt100_set_color(7,0); // ;)
y=17; x=20;
for(c=0; c<8; c++)
{
vt100_set_cursor(y+c,x); // Bereich löschen mit weisem Hintergrund
vt100_set_color(vt100_Black,7);
writeString_P(" ");
}
x=21;
vt100_set_cursor(y+0,x); // Farben invers
vt100_set_color(vt100_Black,7);
writeString_P("Black");
vt100_set_cursor(y+1,x);
vt100_set_color(vt100_Red,7);
writeString_P("Red");
vt100_set_cursor(y+2,x);
vt100_set_color(vt100_Green,7);
writeString_P("Green");
vt100_set_cursor(y+3,x);
vt100_set_color(vt100_Yellow,7);
writeString_P("Yellow");
vt100_set_cursor(y+4,x);
vt100_set_color(vt100_Blue,7);
writeString_P("Blue");
vt100_set_cursor(y+5,x);
vt100_set_color(vt100_Magenta,7);
writeString_P("Magenta");
vt100_set_cursor(y+6,x);
vt100_set_color(vt100_Cyan,7);
writeString_P("Cyan");
vt100_set_cursor(y+7,x);
vt100_set_color(vt100_White,7);
writeString_P("White");
vt100_set_color(7,0); // ;)
writeString_P("\x1B["); // set cursor position ESC [ start ; end r
writeInteger(9, 10);
writeString_P(";");
writeInteger(14, 10);
writeString_P("r");
vt100_set_cursor(9,1);
for(c=0; c<43; c++) writeString_P("Scrolling ");
setStopwatch1(0);
setStopwatch2(0);
startStopwatch1();
startStopwatch2();
vt100_set_cursor(26,p);
writeString("*");
while(1)
{
if(getStopwatch1() >1000) // Uhr
{
setStopwatch1(0);
sec++;
if(sec>59) {sec=0; min++;}
if(min>59) {min=0; std++;}
if(std>23) std=0;
vt100_set_cursor(26,72);
writeIntegerLength(std,10,2);
writeChar(':');
writeIntegerLength(min,10,2);
writeChar(':');
writeIntegerLength(sec,10,2);
}
if(getStopwatch2() >111) // Wandersternchen
{
setStopwatch2(0);
c=p; // alte Position
if(r)
{
if(p<70) p++; else {p=69; r=0;}
}
else
{
if(p>1) p--; else {p=2; r=1;}
}
vt100_set_cursor(26,c); // altes * löschen
writeString(" ");
vt100_set_cursor(26,p); // neues * anzeigen
writeString("*");
vt100_set_cursor(14,1); // Cursor in unterste Zeile des Bereichs setzen
writeString("\n"); // Bereich scrollen
writeIntegerLength(getStopwatch1(),10,4);
vt100_set_cursor(14,77-p); // *** in Scrollbereich schreiben
writeString("***");
}
}
return(0);
}
Viel Spaß damit ;)
Lesezeichen