/* SliMP3 emulator - an emulator for the SliMP3 network MP3 player. Copyright (C) 2001 Jacob Potter This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include char line1[41], line2[41]; int xpos, ypos; /* xpos is 0 - 39, ypos is 0 or 1. */ int movemode, cursdisp; #define MODE_INC 1 #define MODE_DEC -1 #define MODE_CURSOR 4 #define MODE_DISPLAY 5 /* Clear display - - - COMPLETE Go to home position - - COMPLETE Mode: decrement address, shift cursor COMPLETE Mode: decrement address, shift display COMPLETE Mode: increment address, shift cursor COMPLETE Mode: increment address, shift display COMPLETE Display off - - - TODO Display on, with cursor - - TODO Display on, with blinking - TODO Display on, cursor and blinking - TODO Move cursor left - - COMPLETE Move cursor right - - COMPLETE Shift display left - - TODO Shift display right - - TODO Set 8-bit mode - - - TODO Set 4-bit mode - - - TODO */ void parseMessage(char *buffer, int blen) { int i, c; char commandByte; for (i=0; i < blen; i += 2) { if (buffer[i] == 0) { /* Wait for (buffer[i+1]) ms. */ } else if (buffer[i] == 2) { commandByte = buffer[i+1]; if (commandByte == 1) { /* Clear display */ for (i = 0; i < 40; i++) line1[i] = ' '; for (i = 0; i < 40; i++) line2[i] = ' '; line1[40] = 0; line2[40] = 0; xpos = 0; ypos = 0; } else if ((commandByte & 254) == 2) { /* Go to home position. */ xpos = 0; ypos = 0; } else if (commandByte == 4) { /* Mode: decrement address, shift cursor */ movemode = MODE_DEC; cursdisp = MODE_CURSOR; } else if (commandByte == 5) { /* Mode: decrement address, shift display */ movemode = MODE_DEC; cursdisp = MODE_DISPLAY; } else if (commandByte == 6) { /* Mode: increment address, shift cursor */ movemode = MODE_INC; cursdisp = MODE_CURSOR; } else if (commandByte == 7) { /* Mode: increment address, shift display */ movemode = MODE_INC; cursdisp = MODE_DISPLAY; } else if ((commandByte & 252) == 8) { /* Display off */ } else if (commandByte == 14) { /* Display on, with cursor */ } else if (commandByte == 13) { /* Display on, with blinking */ } else if (commandByte == 15) { /* Display on, cursor and blinking */ } else if ((commandByte & 252) == 16) { /* Move cursor left */ xpos--; if (xpos < 0) { if (ypos == 0) xpos = 0; else { xpos = 39; ypos--; } } } else if ((commandByte & 252) == 20) { /* Move cursor right */ xpos++; if (xpos > 39) { xpos = 0; if (ypos == 0) ypos = 1; } } else if ((commandByte & 252) == 24) { /* Shift display left */ } else if ((commandByte & 252) == 28) { /* Shift display right */ } else if ((commandByte & 240) == 48) { /* Set 8-bit mode */ } else if ((commandByte & 240) == 32) { /* Set 4-bit mode */ } else if (commandByte & 128) { c = ((unsigned char)commandByte) & 127; if (c < 40) { xpos = c; ypos = 0; } else if ((c > 63) && (c < 104)) { xpos = (c - 64); ypos = 1; } else { printf("Bad address %u!\n", c); } } else { c = (unsigned char)buffer[i+1]; printf("-- Unknown VFD command %u --\n", (unsigned)c); /* Whoa! Unknown command! */ } } else if (buffer[i] == 3) { /* Put buffer[i+1] in to the display RAM and shift accordingly. */ if (!ypos) line1[xpos] = buffer[i+1]; else line2[xpos] = buffer[i+1]; xpos += movemode; if (cursdisp == MODE_CURSOR) { if (xpos < 0) { if (ypos == 1) xpos = 39; else xpos = 0; ypos = 0; } else if (xpos > 39) { if (ypos == 0) xpos = 0; else xpos = 39; ypos = 1; } } else { /* I don't know what to do here... */ } } else { c = (unsigned char)buffer[i+1]; printf("-- Unknown VFD mode %u --\n", (unsigned)c); } } printf(" ,--------------------------------------.\n"); printf("|%s|\n", line1); printf("|%s|\n", line2); printf(" `--------------------------------------'\n"); } void initDisplay() { char dispClear[2] = { 2, 1 }; parseMessage(dispClear, 2); movemode = 1; cursdisp = MODE_CURSOR; }