1 /* Test that the cpeek...() functions are the inverses of cputc(),
2 ** revers(), and textcolor() for the full range of character codes.
4 ** 2017-07-15, Greg King
11 /* Standard location of the screen */
13 #if defined(__C128__) || defined(__C64__)
14 /* only 40-column screen */
15 # define SCREEN_RAM ((unsigned char*)0x0400)
16 #elif defined(__C16__) /* Plus4 also */
17 # define SCREEN_RAM ((unsigned char*)0x0C00)
18 #elif defined(__CBM510__)
19 # define SCREEN_RAM ((unsigned char*)0xF000)
20 # define COLOR_RAM ((unsigned char*)0xd400)
21 #elif defined(__CBM610__)
22 # define SCREEN_RAM ((unsigned char*)0xD000)
23 #elif defined(__PET__)
24 # define SCREEN_RAM ((unsigned char*)0x8000)
25 #elif defined(__VIC20__)
26 # define SCREEN_RAM ((unsigned char*)0x1000)
28 # error This program cannot test that target.
29 # define SCREEN_RAM ((unsigned char*)0)
32 static unsigned char width;
35 /* Move the cursor backward one char with
36 ** the recognition of a row change.
38 static void chBack (void)
40 unsigned char y = wherey ();
41 unsigned char x = wherex ();
53 /* Move the cursor forward one char with
54 ** the recognition of a row change.
56 static void chForth (void)
58 unsigned char y = wherey ();
59 unsigned char x = wherex ();
70 /* A hack to get an unmodified byte from the
71 ** screen memory at the current cursor position.
73 static unsigned char peekChWithoutTranslation (void)
75 #if defined(__CBM610__)
76 return peekbsys ((unsigned)&SCREEN_RAM[wherey () * width + wherex ()]);
78 return SCREEN_RAM[wherey () * width + wherex ()];
82 /* as above, but for color ram */
83 static unsigned char peekColWithoutTranslation (void)
85 #if defined(__CBM610__) || defined (__PET__)
87 #elif defined(__C128__) || defined(__C64__) || defined(__VIC20__) || defined(__CBM510__)
88 return COLOR_RAM[wherey () * width + wherex ()] & 0x0f;
90 return COLOR_RAM[wherey () * width + wherex ()];
95 /* A test which outputs the given char, reads it back from
96 ** screen memory, outputs the returned char at the next position,
97 ** then compares the two screen memory bytes for identity.
99 ** Note: cpeekc() must be tested indirectly because some platforms "fold" their
100 ** character code-set into a smaller screen code-set. Therefore, cpeekc() might
101 ** return an equivalent, but not equal, character to the one that was cputc().
103 static unsigned char testCPeekC (char ch)
105 unsigned char ch2_a, ch2_b, ch2_c;
107 /* Test the given char-code, but not the
108 ** special characters NEWLINE and RETURN
109 ** (they don't put anything on the screen).
111 if (('\n' == ch) || ('\r' == ch)
116 /* toggle revers mode every few chars so cpeekc gets tested for both */
117 revers ((ch >> 3) & 1);
119 /* output additional space every now and then, that way not only even or only
120 odd half of the character cell will be tested */
122 if ((width == 80) && ((ch % 17) == 0)) {
127 /* Output the char to the screen. */
130 /* Move the cursor pos. to the previous output. */
133 /* Get back the written char without any translation. */
134 ch2_b = peekChWithoutTranslation ();
136 /* Get back the written char,
137 ** including the translation, screen-code -> text.
141 /* Move the cursor to the following writing position. */
144 /* Output again the char which was read back by cpeekc(). */
147 /* Move the cursor pos. to the second output. */
150 /* Get back the second written char without any translation;
151 ** and, compare it to the first untranslated char.
153 ch2_c = peekChWithoutTranslation ();
155 #if defined(__C128__) || defined(__C64__)
156 /* VDC memory is not accessible, soft80 has no "videoram" */
160 /* The test was NOT succesful.
161 ** Output a diagnostic; and, return FAILURE.
164 cprintf ("\r\nError on char: %#x was %#x instead.", ch, ch2_a);
165 cprintf ("\r\nRaw screen codes: %#x, %#x.", ch2_b, ch2_c);
166 cprintf ("\r\nscreen width: %#d", width);
170 /* The test was succesful.
171 ** Move the cursor to the following writing position.
177 static unsigned char testCPeekCol (char ch)
179 unsigned char ch2_a, ch2_b, ch2_c;
181 /* Output the char to the screen. */
185 /* Move the cursor pos. to the previous output. */
188 /* Get back the written char without any translation. */
189 ch2_b = peekColWithoutTranslation ();
191 /* Get back the written char,
192 ** including the translation, screen-code -> text.
194 ch2_a = cpeekcolor ();
196 /* Move the cursor to the following writing position. */
199 /* Output again the char which was read back by cpeekc(). */
203 /* Move the cursor pos. to the second output. */
206 /* Get back the second written char without any translation;
207 ** and, compare it to the first untranslated char.
209 ch2_c = peekColWithoutTranslation ();
211 #if defined(__C128__)
212 /* VDC memory is not accessable */
216 /* The test was NOT succesful.
217 ** Output a diagnostic; and, return FAILURE.
220 cprintf ("\r\nError on color: %#x was %#x instead.", ch, ch2_a);
221 cprintf ("\r\nRaw color codes: %#x, %#x.", ch2_b, ch2_c);
225 /* The test was succesful.
226 ** Move the cursor to the following writing position.
232 /* The main code initiates the screen for the tests, and sets the reverse flag.
233 ** Then, it calls testCPeekC() for every char within 0..255.
234 ** Then, it calls testCPeekCol() for each color
235 ** Returns zero for success, one for failure.
239 unsigned char i, c1, c2;
247 screensize (&width, &i);
249 #if defined(__VIC20__)
250 /* The VIC-20's screen is too small to hold the full test. */
256 if (!testCPeekC (i)) {
260 } while (++i != 0); /* will wrap around when finished */
262 #if defined(__VIC20__)
267 #if defined(__VIC20__)
273 #if defined (__CBM610__) || defined (__PET__)
274 cprintf("\n\rno COLOR_RAM\n\r");
275 #elif defined (__C128__) || defined (__C64__)
277 cprintf("\n\rCOLOR_RAM at $%04x\n\r", COLOR_RAM);
279 cprintf("\n\rno COLOR_RAM\n\r");
282 cprintf("\n\rCOLOR_RAM at $%04x\n\r", COLOR_RAM);
286 if (!testCPeekCol (i)) {
290 } while (++i != 16); /* max 16 colors */
293 textcolor(1); cputc('\n'); cputc('\r');
294 revers(0); cputc('x'); chBack (); c1 = cpeekrevers(); chForth();
295 revers(1); cputc('X'); chBack (); c2 = cpeekrevers(); chForth();
296 cputc('\n'); cputc('\r');
297 revers(c1); cputc('o');
298 revers(c2); cputc('O');
302 cprintf("\n\rtest1234"); gotox(0); cpeeks(s, 8); cputs("\n");
306 if (doesclrscrafterexit()) {