1 /* mul-test.c -- Test the multiplication operator. */
\r
8 /* Number of elements in the progress bar. Use a power of 2, to avoid the
\r
9 * multiplication (which is about to be tested).
\r
11 #define BAR_ELEMENTS 32U
\r
13 #if defined(__CBM__)
\r
14 static const unsigned char revers_bar[8] = {
\r
15 0, 0, 0, 0, 0, 1, 1, 1
\r
17 static const unsigned char small_bar[8] = {
\r
18 ' ', 0xa5, 0xb4, 0xb5, 0xa1, 0xb6, 0xaa, 0xa7
\r
21 #elif defined(__ATARI__)
\r
24 /* Screen co-ordinates for the progress meter */
\r
25 static unsigned char Width, Height;
\r
26 static unsigned char X, Y;
\r
28 static void ProgressMeter (unsigned Val)
\r
29 /* Print the progress bar. */
\r
32 cprintf (" %5lu/65536\r\n", (unsigned long) Val);
\r
34 cclear (Val / (unsigned)(65536U / BAR_ELEMENTS));
\r
36 /* Commodore and Atari computers can show eight times greater precision. */
\r
37 #if defined(__CBM__)
\r
38 Val = (Val / (unsigned)(65536U / BAR_ELEMENTS / 8)) % 8;
\r
39 revers (revers_bar[Val]);
\r
40 cputc (small_bar[Val]);
\r
42 #elif defined(__ATARI__)
\r
54 /* Clock variables */
\r
63 /* Actual test variables */
\r
64 register unsigned lhs = 0;
\r
65 register unsigned rhs = 0;
\r
66 register unsigned res;
\r
68 /* Clear the screen, and output an informational message. */
\r
70 screensize (&Width, &Height);
\r
71 cprintf ("This program does an exhaustive test of\r\n"
\r
72 "the multiplication routine. It runs for\r\n"
\r
73 "several days; so, please wait very\r\n"
\r
74 "patiently (or, speed up your emulator).\r\n"
\r
78 /* Remember the current position for the progress bar */
\r
82 /* Mark the maximum limit of the bar. */
\r
84 cputcxy (BAR_ELEMENTS, Y, ' ');
\r
85 cputcxy (BAR_ELEMENTS, Y + 1, ' ');
\r
88 /* [Targets that have clock() will define CLOCKS_PER_SEC.] */
\r
89 #ifdef CLOCKS_PER_SEC
\r
91 /* Start timing the test. */
\r
97 /* Update the progress bar */
\r
98 ProgressMeter (lhs);
\r
100 /* Enable this to test the progress-meter code.
\r
101 ** (And, run emulators at their maximun speed.)
\r
107 /* Do one row of tests */
\r
110 if (lhs * rhs != res) {
\r
111 #ifdef CLOCKS_PER_SEC
\r
115 cprintf ("Error on %u * %u: %u != %u\r\n", lhs, rhs, lhs * rhs, res);
\r
116 cprintf ("Press a key -- 'Q' to quit. ");
\r
118 C = toupper (cgetc ());
\r
119 cclearxy (0, Y+3, Width);
\r
120 cclearxy (0, Y+4, Width);
\r
122 #ifdef CLOCKS_PER_SEC
\r
124 /* Don't time the user's interaction. */
\r
125 Ticks += clock () - Wait;
\r
133 if (kbhit () && toupper (cgetc ()) == 'Q') {
\r
138 } while (++rhs != 0);
\r
140 } while (++lhs != 0);
\r
143 #ifdef CLOCKS_PER_SEC
\r
145 /* Calculate the time used */
\r
146 Ticks = clock() - Ticks;
\r
147 Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
\r
148 Sec = (unsigned) (Ticks / CLOCKS_PER_SEC);
\r
156 /* Print the time used */
\r
158 cprintf ("Time used:\r\n"
\r
162 " %u.%03u seconds.\n", Days, Hours, Minu, Sec, Milli);
\r
165 cprintf ("\rTap a key, to exit. ");
\r