2009-12-02 15:15:49 +00:00
|
|
|
/* mul-test.c -- Test the multiplication operator. */
|
|
|
|
|
2009-08-17 20:37:36 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
|
2009-12-02 15:15:49 +00:00
|
|
|
/* Number of elements in the progress bar. Use a power of 2, to avoid the
|
2009-08-17 20:37:36 +00:00
|
|
|
* multiplication (which is about to be tested).
|
|
|
|
*/
|
|
|
|
#define BAR_ELEMENTS 32U
|
|
|
|
|
2009-12-02 15:15:49 +00:00
|
|
|
#if defined(__CBM__)
|
|
|
|
static const unsigned char revers_bar[8] = {
|
|
|
|
0, 0, 0, 0, 0, 1, 1, 1
|
|
|
|
};
|
|
|
|
static const unsigned char small_bar[8] = {
|
|
|
|
' ', 0xa5, 0xb4, 0xb5, 0xa1, 0xb6, 0xaa, 0xa7
|
|
|
|
};
|
|
|
|
|
|
|
|
#elif defined(__ATARI__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Screen co-ordinates for the progress meter */
|
2009-08-17 20:37:36 +00:00
|
|
|
static unsigned char Width, Height;
|
|
|
|
static unsigned char X, Y;
|
|
|
|
|
|
|
|
static void ProgressMeter (unsigned Val)
|
2009-12-02 15:15:49 +00:00
|
|
|
/* Print the progress bar. */
|
2009-08-17 20:37:36 +00:00
|
|
|
{
|
|
|
|
gotoxy (X, Y);
|
2009-12-02 15:15:49 +00:00
|
|
|
cprintf (" %5lu/65536\r\n", (unsigned long) Val);
|
|
|
|
revers (1);
|
|
|
|
cclear (Val / (unsigned)(65536U / BAR_ELEMENTS));
|
|
|
|
|
|
|
|
/* Commodore and Atari computers can show eight times greater precision. */
|
|
|
|
#if defined(__CBM__)
|
|
|
|
Val = (Val / (unsigned)(65536U / BAR_ELEMENTS / 8)) % 8;
|
|
|
|
revers (revers_bar[Val]);
|
|
|
|
cputc (small_bar[Val]);
|
|
|
|
|
|
|
|
#elif defined(__ATARI__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
revers (0);
|
2009-08-17 20:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
char C;
|
|
|
|
|
2009-12-02 15:15:49 +00:00
|
|
|
/* Clock variables */
|
2009-08-17 20:37:36 +00:00
|
|
|
clock_t Ticks;
|
2009-12-02 15:15:49 +00:00
|
|
|
clock_t Wait;
|
|
|
|
unsigned Days;
|
|
|
|
unsigned Hours;
|
|
|
|
unsigned Minu;
|
2009-08-17 20:37:36 +00:00
|
|
|
unsigned Sec;
|
|
|
|
unsigned Milli;
|
|
|
|
|
|
|
|
/* Actual test variables */
|
|
|
|
register unsigned lhs = 0;
|
|
|
|
register unsigned rhs = 0;
|
|
|
|
register unsigned res;
|
|
|
|
|
2009-12-02 15:15:49 +00:00
|
|
|
/* Clear the screen, and output an informational message. */
|
2009-08-17 20:37:36 +00:00
|
|
|
clrscr ();
|
|
|
|
screensize (&Width, &Height);
|
|
|
|
cprintf ("This program does an exhaustive test of\r\n"
|
2009-12-02 15:15:49 +00:00
|
|
|
"the multiplication routine. It runs for\r\n"
|
|
|
|
"several days; so, please wait very\r\n"
|
|
|
|
"patiently (or, speed up your emulator).\r\n"
|
|
|
|
"\n"
|
|
|
|
"Progress: ");
|
2009-08-17 20:37:36 +00:00
|
|
|
|
|
|
|
/* Remember the current position for the progress bar */
|
|
|
|
X = wherex ();
|
|
|
|
Y = wherey ();
|
|
|
|
|
2009-12-02 15:15:49 +00:00
|
|
|
/* Mark the maximum limit of the bar. */
|
|
|
|
revers (1);
|
|
|
|
cputcxy (BAR_ELEMENTS, Y, ' ');
|
|
|
|
cputcxy (BAR_ELEMENTS, Y + 1, ' ');
|
|
|
|
revers (0);
|
2009-08-17 20:37:36 +00:00
|
|
|
|
2009-12-02 15:15:49 +00:00
|
|
|
/* [Targets that have clock() will define CLOCKS_PER_SEC.] */
|
|
|
|
#ifdef CLOCKS_PER_SEC
|
2009-08-17 20:37:36 +00:00
|
|
|
|
2009-12-02 15:15:49 +00:00
|
|
|
/* Start timing the test. */
|
|
|
|
Ticks = clock();
|
|
|
|
#endif
|
2009-08-17 20:37:36 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
/* Update the progress bar */
|
|
|
|
ProgressMeter (lhs);
|
|
|
|
|
2009-12-02 15:15:49 +00:00
|
|
|
/* Enable this to test the progress-meter code.
|
|
|
|
** (And, run emulators at their maximun speed.)
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
2009-08-17 20:37:36 +00:00
|
|
|
/* Do one row of tests */
|
|
|
|
res = 0;
|
|
|
|
do {
|
|
|
|
if (lhs * rhs != res) {
|
2009-12-02 15:15:49 +00:00
|
|
|
#ifdef CLOCKS_PER_SEC
|
|
|
|
Wait = clock ();
|
|
|
|
#endif
|
|
|
|
gotoxy (0, Y+3);
|
2009-08-17 20:37:36 +00:00
|
|
|
cprintf ("Error on %u * %u: %u != %u\r\n", lhs, rhs, lhs * rhs, res);
|
2009-12-02 15:15:49 +00:00
|
|
|
cprintf ("Press a key -- 'Q' to quit. ");
|
|
|
|
cursor (1);
|
2009-08-17 20:37:36 +00:00
|
|
|
C = toupper (cgetc ());
|
2009-12-02 15:15:49 +00:00
|
|
|
cclearxy (0, Y+3, Width);
|
|
|
|
cclearxy (0, Y+4, Width);
|
|
|
|
|
|
|
|
#ifdef CLOCKS_PER_SEC
|
|
|
|
|
|
|
|
/* Don't time the user's interaction. */
|
|
|
|
Ticks += clock () - Wait;
|
|
|
|
#endif
|
|
|
|
|
2009-08-17 20:37:36 +00:00
|
|
|
if (C == 'Q') {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
2009-12-02 15:15:49 +00:00
|
|
|
|
|
|
|
if (kbhit () && toupper (cgetc ()) == 'Q') {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2009-08-17 20:37:36 +00:00
|
|
|
res += lhs;
|
|
|
|
} while (++rhs != 0);
|
|
|
|
|
|
|
|
} while (++lhs != 0);
|
|
|
|
|
|
|
|
Done:
|
2009-12-02 15:15:49 +00:00
|
|
|
#ifdef CLOCKS_PER_SEC
|
|
|
|
|
2009-08-17 20:37:36 +00:00
|
|
|
/* Calculate the time used */
|
|
|
|
Ticks = clock() - Ticks;
|
|
|
|
Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
|
2009-12-02 15:15:49 +00:00
|
|
|
Sec = (unsigned) (Ticks / CLOCKS_PER_SEC);
|
|
|
|
Minu = Sec / 60;
|
|
|
|
Hours = Minu / 60;
|
|
|
|
Days = Hours / 24;
|
|
|
|
Hours %= 24;
|
|
|
|
Minu %= 60;
|
|
|
|
Sec %= 60;
|
2009-08-17 20:37:36 +00:00
|
|
|
|
|
|
|
/* Print the time used */
|
2009-12-02 15:15:49 +00:00
|
|
|
gotoxy (0, Y+3);
|
|
|
|
cprintf ("Time used:\r\n"
|
|
|
|
" %u days,\r\n"
|
|
|
|
" %u hours,\r\n"
|
|
|
|
" %u minutes,\r\n"
|
|
|
|
" %u.%03u seconds.\n", Days, Hours, Minu, Sec, Milli);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __ATARI__
|
|
|
|
if (_dos_type != SPARTADOS && _dos_type != OSADOS) {
|
|
|
|
cprintf ("\rTap a key, to exit. ");
|
|
|
|
cgetc();
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-17 20:37:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|