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
|
/* Menu Thing for RVController - Screensaver
* A product of Advanced Mesecons Devices, a Cheapie Systems company
* This is free and unencumbered software released into the public domain.
* See http://unlicense.org/ for more information */
#include <stdbool.h>
#include <stdint.h>
#include "rvcontroller-ecalls.h"
char screensaverbuf[] = "\n \n \n \n \n \n ";
int strlen(char *string) {
int i;
for (i = 0;string[i] != 0;i++) {}
return i;
}
void screensaverWriteText(char *text, int column, int row, bool erase) {
int textlen = strlen(text);
if (column < 0) {
// Cut the left side off of the text and change the start position to the left side of the screen
text = text + (0 - column);
textlen = textlen + column;
column = 0;
} else if (column + textlen > 19) {
// Cut the right side off of the text
textlen = 20 - column;
}
for (int i=0;i < textlen;i++) {
if (erase) {
screensaverbuf[(row*21)+column+i+1] = 0x20;
} else {
screensaverbuf[(row*21)+column+i+1] = text[i];
}
}
}
void doMarquee(void) {
char text[] = "RVController ";
int col = 19;
int row = randomint(0,5);
console_clearbuffer();
while (console_readchar() == 0) {
col--;
if (col < (0 - strlen(text))) {
col = 20;
row = randomint(0,5);
}
screensaverWriteText(text,col,row,false);
printstr(screensaverbuf);
}
screensaverWriteText(text,col,row,true);
}
void doBouncingText(void) {
char text[] = "RVController";
int col = 0;
int row = 0;
int xdir = 1;
int ydir = 1;
console_clearbuffer();
while (console_readchar() == 0) {
screensaverWriteText(text,col,row,true);
col = col + xdir;
row = row + ydir;
if (col <= 0) { xdir = 1; }
if (col >= (19 - strlen(text))) { xdir = -1; }
if (row <= 0) { ydir = 1; }
if (row >= 5) { ydir = -1; }
screensaverWriteText(text,col,row,false);
printstr(screensaverbuf);
}
screensaverWriteText(text,col,row,true);
}
void doMatrix(void) {
int row[] = {-8,-4,-1,-5,-2}; // "Random" positions off the top of the screen to give "random" start delays
int col[] = {1,18,2,12,9};
int len[] = {3,4,5,6,7};
char textscratch[] = " ";
console_clearbuffer();
while (console_readchar() == 0) {
for (int i=0;i<=4;i++) {
row[i]++;
textscratch[0] = randomint(0x21,0x7a);
if (row[i] <= 5 && row[i] >= 0) {
screensaverWriteText(textscratch,col[i],row[i],false);
}
if ((row[i] - len[i]) <= 5 && (row[i] - len[i]) >= 0) {
screensaverWriteText(textscratch,col[i],(row[i] - len[i]),true);
} else if ((row[i] - len[i]) > 5 && randomint(0,1) == 1) {
row[i] = 0 - randomint(1,3);
col[i] = randomint(0,19);
len[i] = randomint(2,8);
}
}
printstr(screensaverbuf);
}
for (int i=0;i <= 5;i++) {
screensaverWriteText(" ",0,i,true);
}
}
void runScreensaver(void) {
char inputbuf[9];
bool quit = false;
while (!quit) {
printstr("\n\n\n\n\n\n\n");
printstr("SCREENSAVER\n");
printstr("1: Marquee\n");
printstr("2: Bouncing Text\n");
printstr("3: Matrix\n");
printstr("\n");
printstr("0: Exit");
readstr(inputbuf,2);
switch (inputbuf[0]) {
case '0':
quit = true;
break;
case '1':
doMarquee();
quit = true;
break;
case '2':
doBouncingText();
quit = true;
break;
case '3':
doMatrix();
quit = true;
break;
default:
printstr("\nInvalid option\n\nPress any key\n\n\n");
readstr(inputbuf,1);
}
}
}
|