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