Commits

Trammell Hudson committed 17468a4

figure mode works

  • Participants
  • Parent commits 72c8f5e

Comments (0)

Files changed (1)

 
 };
 
-static uint8_t current_mode;
+static uint8_t output_mode;
+static uint8_t input_mode = 1;
 
 static const uint8_t mode_select[] = {
 	[1] = BAUDOT_BOTH(0,0,0,0,0),
 	// 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)
+	if (output_mode != mode && mode != 0x3)
 	{
 		tty_out_raw(mode_select[mode]);
 		_delay_us(BIT_CLOCK); // give it a few bits
 		_delay_us(BIT_CLOCK); // give it a few bits
 		_delay_us(BIT_CLOCK); // give it a few bits
 		_delay_us(BIT_CLOCK); // give it a few bits
-		current_mode = mode;
+		output_mode = mode;
 	}
 
 	tty_out_raw(c);
 		{
 			uint8_t ch = UDR1;
 			uint8_t c;
-			for (c = 'a' ; c < 128 ; c++)
+
+			// check for letters (mode 1) or figures (mode 2)
+			if (ch == (mode_select[1] & 0x1F))
 			{
-				if ((baudot[c] & 0x1F) == ch)
-					break;
+				input_mode = 1;
+				continue;
+			} else
+			if (ch == (mode_select[2] & 0x1F))
+			{
+				input_mode = 2;
+				continue;
 			}
-			if (c == 128)
-			for (c = 0 ; c < 'a'-1 ; c++)
+
+			for (c = 0 ; c < 128 ; c++)
 			{
-				if ((baudot[c] & 0x1F) == ch)
-					break;
+				const uint8_t b = baudot[c];
+				if ((b & 0x1F) != ch)
+					continue;
+
+				// Are we in the correct mode to match this?
+				if (((b >> 5) & input_mode) == 0)
+					continue;
+
+				// Yes!  We match.
+				break;
 			}
-#if 0
+
+			if (c != 128)
+			{
+				usb_serial_write(&c, 1);
+				continue;
+			}
+
+			// unknown; dump it
 			char buf[] = {
-				hexdigit(ch >> 4),
-				hexdigit(ch >> 0),
-				' ',
 				bit_is_set(ch, 0) ? '0' : '1',
 				bit_is_set(ch, 1) ? '0' : '1',
 				bit_is_set(ch, 3) ? '0' : '1',
 				bit_is_set(ch, 2) ? '0' : '1',
 				bit_is_set(ch, 4) ? '0' : '1',
 				' ',
-				c != 128 ? c : '@',
+				hexdigit(input_mode),
 				'\r',
 				'\n',
 			};
-#else
-			char buf[] = {
-				c == 'a'-1 ? '@' : c
-			};
-#endif
-			
 			usb_serial_write(buf, sizeof(buf));
 		}