Commits

Trammell Hudson committed 8a0e529

Switching between type bars works, but teletype moves too much

Comments (0)

Files changed (1)

 }
 
 
-#define BAUDOT(a,b,c,d,e) ( \
+#define BAUDOT(a,b,c,d,e,m) ( \
 	(a << 0) | \
 	(b << 1) | \
 	(c << 2) | \
 	(d << 3) | \
 	(e << 4) | \
+	(m << 5) | \
 	0 )
 
+#define BAUDOT_LC(a,b,c,d,e) BAUDOT(a,b,c,d,e,0x1)
+#define BAUDOT_UC(a,b,c,d,e) BAUDOT(a,b,c,d,e,0x2)
+#define BAUDOT_BOTH(a,b,c,d,e) BAUDOT(a,b,c,d,e,0x3)
+
 static uint8_t baudot[] = 
 {
-	['a'] = BAUDOT(0,0,1,1,1),
-	['b'] = BAUDOT(0,1,1,0,0),
-	['c'] = BAUDOT(1,0,0,0,1),
-	['d'] = BAUDOT(0,1,1,0,1),
-	['e'] = BAUDOT(0,1,1,1,1),
-	['f'] = BAUDOT(0,1,0,0,1),
-	['g'] = BAUDOT(1,0,1,0,0),
-	['h'] = BAUDOT(1,1,0,1,0),
-	['i'] = BAUDOT(1,0,0,1,1),
-	['j'] = BAUDOT(0,0,1,0,1),
-	['k'] = BAUDOT(0,0,0,0,1),
-	['l'] = BAUDOT(1,0,1,1,0),
-	['m'] = BAUDOT(1,1,0,0,0),
-	['n'] = BAUDOT(1,1,0,0,1),
-	['o'] = BAUDOT(1,1,1,0,0),
-	['p'] = BAUDOT(1,0,0,1,0),
-	['q'] = BAUDOT(0,0,0,1,0),
-	['r'] = BAUDOT(1,0,1,0,1),
-	['s'] = BAUDOT(0,1,0,1,1),
-	['t'] = BAUDOT(1,1,1,1,0),
-	['u'] = BAUDOT(0,0,0,1,1),
-	['v'] = BAUDOT(1,0,0,0,0),
-	['w'] = BAUDOT(0,0,1,1,0),
-	['x'] = BAUDOT(0,1,0,0,0),
-	['y'] = BAUDOT(0,1,0,1,0),
-	['z'] = BAUDOT(0,1,1,1,0),
-	[' '] = BAUDOT(1,1,0,1,1),
-	['\n'] = BAUDOT(1,1,1,0,1),
-	['\r'] = BAUDOT(1,0,1,1,1),
+	[' '] = BAUDOT_BOTH(1,1,0,1,1),
+	['\n'] = BAUDOT_BOTH(1,1,1,0,1),
+	['\r'] = BAUDOT_BOTH(1,0,1,1,1),
+
+	['a'] = BAUDOT_LC(0,0,1,1,1),
+	['b'] = BAUDOT_LC(0,1,1,0,0),
+	['c'] = BAUDOT_LC(1,0,0,0,1),
+	['d'] = BAUDOT_LC(0,1,1,0,1),
+	['e'] = BAUDOT_LC(0,1,1,1,1),
+	['f'] = BAUDOT_LC(0,1,0,0,1),
+	['g'] = BAUDOT_LC(1,0,1,0,0),
+	['h'] = BAUDOT_LC(1,1,0,1,0),
+	['i'] = BAUDOT_LC(1,0,0,1,1),
+	['j'] = BAUDOT_LC(0,0,1,0,1),
+	['k'] = BAUDOT_LC(0,0,0,0,1),
+	['l'] = BAUDOT_LC(1,0,1,1,0),
+	['m'] = BAUDOT_LC(1,1,0,0,0),
+	['n'] = BAUDOT_LC(1,1,0,0,1),
+	['o'] = BAUDOT_LC(1,1,1,0,0),
+	['p'] = BAUDOT_LC(1,0,0,1,0),
+	['q'] = BAUDOT_LC(0,0,0,1,0),
+	['r'] = BAUDOT_LC(1,0,1,0,1),
+	['s'] = BAUDOT_LC(0,1,0,1,1),
+	['t'] = BAUDOT_LC(1,1,1,1,0),
+	['u'] = BAUDOT_LC(0,0,0,1,1),
+	['v'] = BAUDOT_LC(1,0,0,0,0),
+	['w'] = BAUDOT_LC(0,0,1,1,0),
+	['x'] = BAUDOT_LC(0,1,0,0,0),
+	['y'] = BAUDOT_LC(0,1,0,1,0),
+	['z'] = BAUDOT_LC(0,1,1,1,0),
+
+	['0'] = BAUDOT_UC(1,0,0,1,0),
+	['1'] = BAUDOT_UC(0,0,0,1,0),
+	['2'] = BAUDOT_UC(0,0,1,1,0),
+	['3'] = BAUDOT_UC(0,1,1,1,1),
+	['4'] = BAUDOT_UC(1,0,1,0,1),
+	['5'] = BAUDOT_UC(1,1,1,1,0),
+	['6'] = BAUDOT_UC(0,1,0,1,0),
+	['7'] = BAUDOT_UC(0,0,0,1,1),
+	['8'] = BAUDOT_UC(1,0,0,1,1),
+	['9'] = BAUDOT_UC(1,1,1,0,0),
+	['-'] = BAUDOT_UC(0,0,1,1,1),
+	['?'] = BAUDOT_UC(0,1,1,0,0),
+	[':'] = BAUDOT_UC(1,0,0,0,1),
+	['$'] = BAUDOT_UC(0,1,1,0,1),
+	['!'] = BAUDOT_UC(0,1,0,0,1),
+	['&'] = BAUDOT_UC(1,0,1,0,0),
+	['#'] = BAUDOT_UC(1,1,0,1,0),
+	['\''] = BAUDOT_UC(0,0,1,0,1),
+	['('] = BAUDOT_UC(0,0,0,0,1),
+	[')'] = BAUDOT_UC(1,0,1,1,0),
+	['.'] = BAUDOT_UC(1,1,0,0,0),
+	[','] = BAUDOT_UC(1,1,0,0,1),
+	['\a'] = BAUDOT_UC(0,1,0,1,1),
+	[';'] = BAUDOT_UC(1,0,0,0,0),
+	['/'] = BAUDOT_UC(0,1,0,0,0),
+	['"'] = BAUDOT_UC(0,1,1,1,0),
+
 };
 
+static uint8_t current_mode;
+
+static const uint8_t mode_select[] = {
+	[1] = BAUDOT_BOTH(0,0,0,0,0),
+	[2] = BAUDOT_BOTH(0,0,1,0,0),
+};
+
+
 static void
-tty_out(
-	uint8_t ch
+tty_out_raw(
+	uint8_t c
 )
 {
-	uint8_t c = ch ? baudot[ch] : 0x00;
-	if (c == 0 && ch != 0)
-		return;
-
 	// start bit
 	out(0xD7, 0);
 
 
 
 static void
+tty_out(
+	uint8_t ch
+)
+{
+	uint8_t c = ch ? baudot[ch] : 0x00;
+	if (c == 0 && ch != 0)
+		return;
+
+	const uint8_t mode = (c >> 5) & 0x3;
+
+	// If we are not in the current mode, send the special
+	// code to switch to the other typebar and record that
+	// we are in that mode.
+	if (current_mode != mode && mode != 0x3)
+	{
+		tty_out_raw(mode_select[mode]);
+		_delay_ms(BIT_CLOCK + BIT_CLOCK); // give it a few bits
+		current_mode = mode;
+	}
+
+	tty_out_raw(c);
+}
+
+
+static void
 boost_setup(void)
 {