Skip to content

Commit f9f850e

Browse files
committed
Version 1.0.0
1 parent a44b4a6 commit f9f850e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+33378
-0
lines changed

Doxyfile

Lines changed: 2579 additions & 0 deletions
Large diffs are not rendered by default.

examples/examples.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef EXAMPLES_H
2+
#define EXAMPLES_H
3+
4+
void textmode();
5+
void g1text();
6+
void g2text();
7+
void sprites();
8+
void g2image();
9+
10+
#endif

examples/examples.ino

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
#include "examples.h"
3+
4+
//Uncomment the example you want to run
5+
void setup()
6+
{
7+
textmode();
8+
//g1text();
9+
//g2text();
10+
//sprites();
11+
//g2image();
12+
}
13+
14+
void loop()
15+
{
16+
}

examples/g1text.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <tms9918.h>
2+
3+
4+
void g1text()
5+
{
6+
vdp_init_textmode(VDP_BLACK, VDP_WHITE);
7+
//vdp_init_textmode();
8+
9+
//vdp_textcolor(VDP_DARK_BLUE, VDP_WHITE);
10+
vdp_print("Character set in graphic mode 1:\r\n\r\n");
11+
vdp_print(" !\"#$%&'()*+,-./\r\r");
12+
vdp_print("0123456789:;<=>?@\r\n");
13+
vdp_print("ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'\r\n");
14+
vdp_print("abcdefghijklmnopqrstuvwxyz{>}+~\r\n");
15+
return;
16+
while (1)
17+
{
18+
for (uint8_t i = 1; i <= 15; i++)
19+
for (uint8_t j = 1; j <= 15; j++)
20+
{
21+
vdp_textcolor(j, i);
22+
delay(1000);
23+
}
24+
}
25+
}

examples/g2image.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <tms9918.h>
2+
3+
bool loaded = false;
4+
5+
void serialEvent()
6+
{
7+
uint16_t y = 0, n_cols, n_lines;
8+
uint8_t line[256];
9+
delay(10);
10+
n_cols = Serial.read();
11+
n_lines = Serial.read();
12+
n_cols == 0 ? n_cols = 256 : n_cols;
13+
if (n_cols == 256) //Hi-res
14+
{
15+
vdp_init_g2();
16+
vdp_set_bdcolor(VDP_BLACK);
17+
while (y < 192)
18+
{
19+
Serial.readBytes(line, 256);
20+
uint8_t color1 = 0, color2 = 0;
21+
for (int x = 0; x < n_cols; x++)
22+
{
23+
if(x%8 == 0)
24+
color1 = color2 = line[x];
25+
else if(line[x] != color1)
26+
color2 = line[x];
27+
28+
if(line[x] == color1)
29+
vdp_plot_hires(x, y, color1+1);
30+
else
31+
vdp_plot_hires(x, y, NULL, color2+1);
32+
}
33+
y++;
34+
Serial.write('@');
35+
}
36+
//sprites();
37+
}
38+
else if(n_cols == 64)
39+
{
40+
vdp_init_multicolor();
41+
while (y < 64)
42+
{
43+
Serial.readBytes(line, 64);
44+
for (int x = 0; x < 64; x++)
45+
{
46+
vdp_plot_color(x, y, 1+line[x]);
47+
}
48+
y++;
49+
Serial.write('@');
50+
}
51+
}
52+
else
53+
{
54+
vdp_print("Unknown format");
55+
56+
}
57+
}
58+
59+
void g2image()
60+
{
61+
Serial.begin(115200);
62+
vdp_init_textmode();
63+
vdp_print("Start the imgserial tool on PC to \r\nsend a picture");
64+
//Serial.write('@');
65+
66+
}

examples/g2text.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <tms9918.h>
2+
3+
void g2text()
4+
{
5+
if (vdp_init_g2())
6+
Serial.println("VDP Error");
7+
8+
vdp_textcolor(VDP_GRAY, VDP_BLACK);
9+
vdp_print("BLACK (1) ");
10+
vdp_textcolor(VDP_BLACK, VDP_GRAY);
11+
vdp_print("GRAY (14) ");
12+
vdp_textcolor(VDP_BLACK, VDP_WHITE);
13+
vdp_print("WHITE (15) ");
14+
vdp_textcolor(VDP_GRAY, VDP_MAGENTA);
15+
vdp_print("MAGENTA (13) ");
16+
vdp_textcolor(VDP_GRAY, VDP_DARK_BLUE);
17+
vdp_print("DARK BLUE (4) ");
18+
vdp_textcolor(VDP_GRAY, VDP_LIGHT_BLUE);
19+
vdp_print("LIGHT BLUE (5) ");
20+
vdp_textcolor(VDP_BLACK, VDP_CYAN);
21+
vdp_print("CYAN (7) ");
22+
vdp_textcolor(VDP_GRAY, VDP_DARK_GREEN);
23+
vdp_print("DARK GREEN (12) ");
24+
vdp_textcolor(VDP_GRAY, VDP_MED_GREEN);
25+
vdp_print("MEDIUM GREEN (2) ");
26+
vdp_textcolor(VDP_BLACK, VDP_LIGHT_GREEN);
27+
vdp_print("LIGHT GREEN (3) ");
28+
vdp_textcolor(VDP_BLACK, VDP_DARK_YELLOW);
29+
vdp_print("DARK YELLOW (10) ");
30+
vdp_textcolor(VDP_BLACK, VDP_LIGHT_YELLOW);
31+
vdp_print("LIGHT YELLOW (11) ");
32+
vdp_textcolor(VDP_GRAY, VDP_DARK_RED);
33+
vdp_print("DARK RED (6) ");
34+
vdp_textcolor(VDP_GRAY, VDP_MED_RED);
35+
vdp_print("MEDIUM RED (8) ");
36+
vdp_textcolor(VDP_BLACK, VDP_LIGHT_RED);
37+
vdp_print("LIGHT RED (9) ");
38+
vdp_print("\033[0;1m ------------------------------ ");
39+
vdp_print("!\033[1;0m \033[0;1m!");
40+
vdp_print("!\033[1;0m \033[0;1m!");
41+
vdp_print("!\033[1;0m \033[0;1m!");
42+
vdp_print("!\033[1m TRANSPARENT (0) \033[0;1m!");
43+
vdp_print("!\033[1;0m \033[0;1m!");
44+
vdp_print("!\033[1;0m \033[0;1m!");
45+
vdp_print("!\033[1;0m \033[0;1m!");
46+
vdp_print(" ------------------------------ ");
47+
48+
uint8_t j;
49+
while(1)
50+
{
51+
vdp_set_bdcolor(j++);
52+
delay(2000);
53+
}
54+
}

examples/imgserial/cygwin1.dll

3.39 MB
Binary file not shown.

examples/imgserial/disney.data

48 KB
Binary file not shown.

examples/imgserial/images/disney.png

110 KB
Loading
24 KB
Loading

examples/imgserial/images/example.xcf

570 KB
Binary file not shown.

examples/imgserial/images/monet.png

104 KB
Loading
21.2 KB
Loading

examples/imgserial/images/nature.png

117 KB
Loading
20.6 KB
Loading

examples/imgserial/images/parrot.png

93.7 KB
Loading
30.2 KB
Loading
61 KB
Loading
11.6 KB
Loading
19.8 KB
Loading

examples/imgserial/images/tms9918.gpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
GIMP Palette
2+
Name: TMS9918
3+
Columns: 16
4+
#
5+
0 0 0 Untitled
6+
33 200 66 Untitled
7+
94 220 120 Untitled
8+
84 85 237 Untitled
9+
125 118 252 Untitled
10+
212 82 77 Untitled
11+
66 235 245 Untitled
12+
252 85 84 Untitled
13+
255 121 120 Untitled
14+
212 193 84 Untitled
15+
230 206 128 Untitled
16+
33 176 59 Untitled
17+
201 91 186 Untitled
18+
204 204 204 Untitled (occurs 4769)
19+
255 255 255 Untitled (occurs 855)
20+
0 0 0 Untitled

examples/imgserial/imgserial.cpp

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/* Tool to send for Gimp raw data files an Arduino running the g2image example
2+
Copyright (C) 2022 Doctor Volt
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
#include <stdio.h>
18+
#include <stdint.h>
19+
#include <cstring>
20+
#include <string>
21+
#include <fcntl.h>
22+
#include <termios.h>
23+
#include <unistd.h>
24+
#include <sys/stat.h>
25+
26+
using namespace std;
27+
28+
int main(int argc, const char *argv[])
29+
{
30+
termios tty;
31+
tty.c_iflag = 0;
32+
tty.c_oflag = 0;
33+
tty.c_cflag = CS8 | CREAD | CLOCAL; // 8 Bit, No parity, one stop bit, no flow control, disable signal lines, Read enabled
34+
tty.c_lflag = 0;
35+
tty.c_cc[VMIN] = 5; // Block until at least one byte received
36+
tty.c_cc[VTIME] = 0;
37+
cfsetspeed(&tty, B115200);
38+
39+
if (argc != 3)
40+
{
41+
printf("This program sends GIMP raw data files to an Arduino running the \"g2image\" example over serial(USB) interface\r\n");
42+
printf("\r\nUsage: imgserial filename.data port \r\n");
43+
#ifdef __CYGWIN__
44+
printf("Example: imgserial parrot.data /dev/ttyS0 where /dev/ttyS0 is COM1, /dev/ttyS1 COM2 etc. \r\n");
45+
#else
46+
printf("Example: imgserial parrot.data /dev/ttyUSB0 \r\n");
47+
#endif
48+
return -1;
49+
}
50+
#ifdef __CYGWIN__
51+
printf("IMPORTANT: Put a 10µF cap between the RST pin of your Arduino and Ground to prevent a reboot.\r\n");
52+
#endif
53+
54+
55+
string fname_in = argv[1];
56+
if (fname_in.rfind(".data", string::npos) == -1)
57+
{
58+
printf("Invalid filename. Must be a *.data file\r\n");
59+
return -1;
60+
}
61+
62+
// FILE *infile = fopen(fname_in.c_str(), "r");
63+
int infile = open(fname_in.c_str(), O_RDONLY);
64+
if (errno)
65+
{
66+
printf("Error opening file: %s\r\n", strerror(errno));
67+
return -1;
68+
}
69+
70+
// Opening serial port
71+
// int port = open("/dev/ttyUSB0", O_RDWR);
72+
int port = open(argv[2], O_RDWR);
73+
if (errno)
74+
{
75+
printf("Error opening serial Port: %s\n", strerror(errno));
76+
return -1;
77+
}
78+
79+
// Setting port attributes
80+
if (tcsetattr(port, TCSANOW, &tty) != 0)
81+
{
82+
printf("Error setting serial port: %s\n", strerror(errno));
83+
return -1;
84+
}
85+
86+
// Determine filesize
87+
struct stat buf;
88+
fstat(infile, &buf);
89+
size_t filesize = buf.st_size;
90+
91+
uint16_t n_cols, n_lines;
92+
switch (filesize)
93+
{
94+
case 64 * 48:
95+
printf("\r\n64x48 Multicolor Mode\r\n");
96+
n_cols = 64;
97+
n_lines = 48;
98+
break;
99+
case 256 * 192:
100+
printf("\r\n256x192 Graphic Mode 2 high resolution\r\n");
101+
n_cols = 256;
102+
n_lines = 192;
103+
break;
104+
default:
105+
printf("\r\nInvalid file format. Size: %d \r\n", (int)filesize);
106+
return -1;
107+
}
108+
uint8_t ack;
109+
// read(port, &ack, 1); //Block until Arduino is ready
110+
printf("Transfer started: %s to %s...\r\n", argv[1], argv[2]);
111+
write(port, (uint8_t *)&n_cols, 1); // Send resolution
112+
write(port, (uint8_t *)&n_lines, 1);
113+
uint8_t *inbuf = (uint8_t *)calloc(1, filesize);
114+
if (read(infile, inbuf, filesize) < 1)
115+
{
116+
printf("Error reading file: %s\r\n", strerror(errno));
117+
return -1;
118+
}
119+
120+
for (int i = 0; i < n_lines; i++)
121+
{
122+
write(port, (const void *)(inbuf + n_cols * i), n_cols);
123+
read(port, &ack, 1); // Block until Arduino acknowledged that he processed the packet
124+
}
125+
126+
close(port);
127+
close(infile);
128+
printf("\r\nFile sent\r\n");
129+
130+
return 0;
131+
}

examples/imgserial/imgserial.exe

1.79 MB
Binary file not shown.

examples/imgserial/imgserial.linux

67.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)