melder fejl i __min
HejVi har borland c++ 3.11 & 5.01, og vi prøver at compile denne source, men den melder fejl i __min, med at den skal havde en prototype..
Her er sourcen:
/*
* cppdemo.cpp - Last updated 4 November 2000, 4:33am
*
* This is a quickie console program for showing how to interface with the
* display using C/C++. (To make this a C program, just replace the input
* routines. LCDriver's core code, both driver routines and GUI, are written
* in C, but since many CS students learn C++ first I've used it here.)
*
* It also has a handy routine for doing custom characters correctly in a
* pixel-size independent manner.
*/
#include <iostream.h>
#include <lcdriver.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
typedef struct _menu
{
int iLength;
char *szTexts[6];
int iLinks[6];
} menu;
/*
* Custom characters!
*
* Custom characters are formed by sending eight bytes to a display, one for
* each of the eight lines of a character. The display takes the N least
* significant bits of the byte (N = 6 for CrystalFontz units, 5 for all
* others) and uses them as pixels.
*
* If you know the characters before hand, you can hardcode the bytes into
* the program - for the sake of example, though, I've demonstrated how to
* generate bytes from a matrix of numbers such as a bitmap below.
*
*/
#define TOTAL_CUSTS 8
static int custs[][8][8] = {
{
{0, 0, 1, 1, 1, 1, 1, 1}, // ##########
{0, 0, 1, 1, 1, 0, 1, 1}, // #### ####
{0, 0, 1, 1, 0, 0, 1, 1}, // ## ####
{0, 0, 1, 1, 1, 0, 1, 1}, // #### ####
{0, 0, 1, 1, 1, 0, 1, 1}, // #### ####
{0, 0, 1, 1, 1, 0, 1, 1}, // #### ####
{0, 0, 1, 1, 0, 0, 0, 1}, // ## ##
{0, 0, 1, 1, 1, 1, 1, 1} // ##########
},
{
{0, 0, 1, 1, 1, 1, 1, 1}, // ##########
{0, 0, 1, 1, 1, 0, 1, 1}, // #### ####
{0, 0, 1, 1, 0, 1, 0, 1}, // ## ## ##
{0, 0, 1, 1, 1, 1, 0, 1}, // ###### ##
{0, 0, 1, 1, 1, 0, 1, 1}, // #### ####
{0, 0, 1, 1, 0, 1, 1, 1}, // ## ######
{0, 0, 1, 1, 0, 0, 0, 1}, // ## ##
{0, 0, 1, 1, 1, 1, 1, 1} // ##########
},
{
{0, 0, 1, 1, 1, 1, 1, 1}, // ##########
{0, 0, 1, 1, 0, 0, 1, 1}, // ## ####
{0, 0, 1, 1, 1, 1, 0, 1}, // ###### ##
{0, 0, 1, 1, 0, 0, 1, 1}, // ## ####
{0, 0, 1, 1, 1, 1, 0, 1}, // ###### ##
{0, 0, 1, 1, 1, 1, 0, 1}, // ###### ##
{0, 0, 1, 1, 0, 0, 1, 1}, // ## ####
{0, 0, 1, 1, 1, 1, 1, 1}, // ##########
},
{
{0, 0, 1, 1, 1, 1, 1, 1}, // ##########
{0, 0, 1, 1, 0, 1, 0, 1}, // ## ## ##
{0, 0, 1, 1, 0, 1, 0, 1}, // ## ## ##
{0, 0, 1, 1, 0, 1, 0, 1}, // ## ## ##
{0, 0, 1, 1, 0, 0, 0, 1}, // ## ##
{0, 0, 1, 1, 1, 1, 0, 1}, // ###### ##
{0, 0, 1, 1, 1, 1, 0, 1}, // ###### ##
{0, 0, 1, 1, 1, 1, 1, 1} // ##########
},
{
{0, 0, 1, 1, 1, 1, 1, 1}, // ##########
{0, 0, 1, 1, 0, 0, 0, 1}, // ## ##
{0, 0, 1, 1, 0, 1, 1, 1}, // ## ######
{0, 0, 1, 1, 0, 0, 0, 1}, // ## ##
{0, 0, 1, 1, 1, 1, 0, 1}, // ###### ##
{0, 0, 1, 1, 1, 1, 0, 1}, // ###### ##
{0, 0, 1, 1, 0, 0, 1, 1}, // ## ####
{0, 0, 1, 1, 1, 1, 1, 1} // ##########
},
{
{0, 0, 1, 1, 1, 1, 1, 1}, // ##########
{0, 0, 1, 1, 1, 0, 1, 1}, // #### ####
{0, 0, 1, 1, 0, 1, 0, 1}, // ## ## ##
{0, 0, 1, 1, 0, 1, 1, 1}, // ## ######
{0, 0, 1, 1, 0, 0, 0, 1}, // ## ##
{0, 0, 1, 1, 0, 1, 0, 1}, // ## ## ##
{0, 0, 1, 1, 1, 0, 1, 1}, // #### ####
{0, 0, 1, 1, 1, 1, 1, 1} // ##########
},
{
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 1, 0, 1, 0, 1}, // ## ## ##
{0, 0, 1, 0, 1, 1, 1, 0}, // ######
{0, 0, 1, 0, 0, 1, 0, 0} // ##
},
{
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 1, 1, 1, 0}, // ######
{0, 0, 1, 1, 0, 1, 0, 1}, // ## ## ##
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 0, 1, 0, 0}, // ##
{0, 0, 1, 0, 0, 1, 0, 0} // ##
}
};
/*
* This is menu code, might be useful if you intend to set up a system
* like this, but not horribly general.
*/
#define TOTAL_MENUS 12
static menu menus[] = {
{2, {"Submenu 1", "Exit Demo", NULL, NULL, NULL, NULL}, {1, -1, 0, 0, 0, 0}},
{6, {"Entry 1", "Entry 2", "Entry 3", "Entry 4", "Entry 5", "Back"}, {2, 3, 4, 5, 6, 0}},
{4, {"Selection 1", "Selection 2", "Selection 3", "Return", NULL, NULL}, {7, 8, 9, 1, 0, 0}},
{3, {"Choice 1", "Choice 2", "Up One Level", NULL, NULL, NULL}, {10, 11, 1, 0, 0, 0}},
{1, {"Back", NULL, NULL, NULL, NULL, NULL}, {1, 0, 0, 0, 0, 0}},
{1, {"Return", NULL, NULL, NULL, NULL, NULL}, {1, 0, 0, 0, 0, 0}},
{1, {"Up", NULL, NULL, NULL, NULL, NULL}, {1, 0, 0, 0, 0, 0}},
{1, {"Back", NULL, NULL, NULL, NULL, NULL}, {2, 0, 0, 0, 0, 0}},
{1, {"Return", NULL, NULL, NULL, NULL, NULL}, {2, 0, 0, 0, 0, 0}},
{1, {"Up", NULL, NULL, NULL, NULL, NULL}, {2, 0, 0, 0, 0, 0}},
{1, {"Back", NULL, NULL, NULL, NULL, NULL}, {3, 0, 0, 0, 0, 0}},
{1, {"Return", NULL, NULL, NULL, NULL, NULL}, {3, 0, 0, 0, 0, 0}}
};
/*
* Here's the custom character generation code. Note that all the characters
* in the matrices above are 5x8 so they'll fit in normal displays. CFontz
* displays have a sixth column of pixels where other displays have hardwired
* spaces - neat for putting together contiguous blocks of pixels like I do
* in the Winamp plugin, but in this case, you need to put a space on the
* right to make it line up with regular characters, which means shifting
* everything left one bit.
*/
void create_customs(void)
{
char cData[8];
int i, j;
for (i = 0; i < TOTAL_CUSTS; i++)
{
for (j = 0; j < 8; j++) // The if statement gives a space on the
{ // side for CrystalFontz displays.
cData[j] = (char) ((32 * custs[i][j][2]) + (16 * custs[i][j][3]) + (8 * custs[i][j][4]) + (4 * custs[i][j][5]) + (2 * custs[i][j][6]) + custs[i][j][7]);
if (lcdGetCharWidth() == 6) { cData[j] = (char) (cData[j] << 1); }
}
if (LCD_RESULT_NOERROR != lcdSetCustomChar(i, cData))
{
cerr << "ERROR: LCDriver error while uploading custom character " << i << "!" << endl;
lcdFree();
exit(1);
}
}
}
void display_menu(int index, int start)
{
char szString[40];
int i, j;
menu m;
if ((index > TOTAL_MENUS - 1) || (index < 0))
{
cerr << "ERROR: Index out of bounds in display_menu." << endl;
lcdFree();
exit(1);
}
m = menus[index];
if (LCD_RESULT_NOERROR != lcdClearDisplay())
{
cerr << "ERROR: LCDriver error while clearing screen." << endl;
lcdFree();
exit(1);
}
for (i = 0; i < lcdGetHeight(); i++)
{
if ((i + start) > (m.iLength - 1)) { break; }
// Build that line of the display.
for (j = 0; j < 40; j++) { szString[j] = ' '; }
memmove(&(szString[2]), m.szTexts[i + start], __min(38, strlen(m.szTexts[i + start])) * sizeof(char));
szString[0] = (unsigned char) (i + start);
// If there's more above or below, and we're the first or last lines
// of the display, put the arrows on it.
if ((0 == i) && (start > 0))
{
szString[lcdGetWidth() - 1] = 7;
}
if ((lcdGetHeight() - 1 == i) && (m.iLength - start > lcdGetHeight()))
{
szString[lcdGetWidth() - 1] = 6;
}
if (LCD_RESULT_NOERROR != lcdSetCursorPos(0, i))
{
cerr << "ERROR: LCDriver error while setting position." << endl;
lcdFree();
exit(1);
}
if (LCD_RESULT_NOERROR != lcdSendString(szString, lcdGetWidth()))
{
cerr << "ERROR: LCDriver error while sending string." << endl;
lcdFree();
exit(1);
}
}
}
void handle_input(int &index, int &start, char choice)
{
switch(choice)
{
case 'a': case 'A':
if (start == 0) break;
start--;
break;
case 'z': case 'Z':
if (start >= (menus[index].iLength - lcdGetHeight())) break;
start++;
break;
case '1': case '2': case '3': case '4': case '5': case '6':
if (menus[index].iLength <= (choice - '1'))
break;
index = menus[index].iLinks[choice - '1'];
start = 0;
break;
}
}
int main(int argc, char **argv)
{
char c = ' ';
int index = 0;
int start = 0;
if (LCD_RESULT_NOERROR != lcdRequest())
{
cerr << "ERROR: Display is in use by another application." << endl;
return 1;
}
if (LCD_RESULT_NOERROR != lcdSetWrapMode(0, 0))
{
cerr << "ERROR: LCDriver error while setting wrap mode." << endl;
lcdFree();
return 1;
}
if (LCD_RESULT_NOERROR != lcdSetCursor(0))
{
cerr << "ERROR: LCDriver error while setting cursor appearance." << endl;
lcdFree();
return 1;
}
create_customs();
cerr << "A and Z keys scroll up and down." << endl;
cerr << "Number keys open a menu item." << endl;
cerr << "Hit enter after each keypress (this is a console app!)" << endl;
while (1)
{
display_menu(index, start);
cin.get(c);
handle_input(index, start, c);
if (-1 == index)
break;
}
lcdFree();
return 0;
}