/* -*-c-*-
*
- * $Id: bascat.c,v 1.4 1999/10/28 10:42:23 mdw Exp $
+ * $Id: bascat.c,v 1.5 1999/11/25 01:08:57 mdw Exp $
*
* Display BBC BASIC programs more or less anywhere
*
/*----- Revision history --------------------------------------------------*
*
* $Log: bascat.c,v $
+ * Revision 1.5 1999/11/25 01:08:57 mdw
+ * Fix decoding of line numbers.
+ *
* Revision 1.4 1999/10/28 10:42:23 mdw
* More minor twiddling.
*
* Use: Decodes multibyte tokens.
*/
-static int mbtok(int byte, const char *t[], int n, FILE * fp)
+static int mbtok(int byte, const char *t[], int n, FILE *fp)
{
byte -= 0x8E;
if (byte >= n)
* Use: Decodes a byte, changing states as necessary.
*/
-static int decode(int byte, FILE * fp)
+static int decode(int byte, FILE *fp)
{
switch (state) {
/* --- Encoded line number states --- */
case s_linex:
- lineno = ((((byte << 2) | (byte << 12)) & 0xc0c0u) ^ 0x4040u);
+ byte ^= 0x54;
+ lineno = (((byte & 0x30) << 2) |
+ ((byte & 0x0c) << 12) |
+ ((byte & 0x03) << 16));
state++;
break;
case s_liney:
- lineno |= byte & 0x3fu;
+ lineno |= byte & 0x3f;
state++;
break;
case s_linez:
- lineno |= (byte << 8) & 0x3fu;
+ lineno |= (byte & 0x3f) << 8;
fprintf(fp, "%u", lineno);
state = s_normal;
break;
goto eof;
len -= 4;
- state = s_normal;
+ state = s_keyword;
while (len) {
byte = getc(in);
D( fprintf(stderr, "state == %i, byte == %i\n",