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 /* Output the char to the screen. */
119 /* Move the cursor pos. to the previous output. */
122 /* Get back the written char without any translation. */
123 ch2_b = peekChWithoutTranslation ();
125 /* Get back the written char,
126 ** including the translation, screen-code -> text.
130 /* Move the cursor to the following writing position. */
133 /* Output again the char which was read back by cpeekc(). */
136 /* Move the cursor pos. to the second output. */
139 /* Get back the second written char without any translation;
140 ** and, compare it to the first untranslated char.
142 ch2_c = peekChWithoutTranslation ();
144 #if defined(__C128__)
145 /* VDC memory is not accessable */
149 /* The test was NOT succesful.
150 ** Output a diagnostic; and, return FAILURE.
153 cprintf ("\r\nError on char: %#x was %#x instead.", ch, ch2_a);
154 cprintf ("\r\nRaw screen codes: %#x, %#x.", ch2_b, ch2_c);
155 cprintf ("\r\nscreen width: %#d", width);
159 /* The test was succesful.
160 ** Move the cursor to the following writing position.
166 static unsigned char testCPeekCol (char ch)
168 unsigned char ch2_a, ch2_b, ch2_c;
170 /* Output the char to the screen. */
174 /* Move the cursor pos. to the previous output. */
177 /* Get back the written char without any translation. */
178 ch2_b = peekColWithoutTranslation ();
180 /* Get back the written char,
181 ** including the translation, screen-code -> text.
183 ch2_a = cpeekcolor ();
185 /* Move the cursor to the following writing position. */
188 /* Output again the char which was read back by cpeekc(). */
192 /* Move the cursor pos. to the second output. */
195 /* Get back the second written char without any translation;
196 ** and, compare it to the first untranslated char.
198 ch2_c = peekColWithoutTranslation ();
200 #if defined(__C128__)
201 /* VDC memory is not accessable */
205 /* The test was NOT succesful.
206 ** Output a diagnostic; and, return FAILURE.
209 cprintf ("\r\nError on color: %#x was %#x instead.", ch, ch2_a);
210 cprintf ("\r\nRaw color codes: %#x, %#x.", ch2_b, ch2_c);
214 /* The test was succesful.
215 ** Move the cursor to the following writing position.
221 /* The main code initiates the screen for the tests, and sets the reverse flag.
222 ** Then, it calls testCPeekC() for every char within 0..255.
223 ** Then, it calls testCPeekCol() for each color
224 ** Returns zero for success, one for failure.
228 unsigned char i, c1, c2;
236 screensize (&width, &i);
238 #if defined(__VIC20__)
239 /* The VIC-20's screen is too small to hold the full test. */
245 if (!testCPeekC (i)) {
249 } while (++i != 0); /* will wrap around when finished */
251 #if defined(__VIC20__)
256 #if defined(__VIC20__)
262 #if defined (__CBM610__) || defined (__PET__)
263 cprintf("\n\rno COLOR_RAM\n\r");
264 #elif defined (__C128__)
266 cprintf("\n\rCOLOR_RAM at $%04x\n\r", COLOR_RAM);
268 cprintf("\n\rno COLOR_RAM\n\r");
271 cprintf("\n\rCOLOR_RAM at $%04x\n\r", COLOR_RAM);
275 if (!testCPeekCol (i)) {
279 } while (++i != 16); /* max 16 colors */
282 textcolor(1); cputc('\n'); cputc('\r');
283 revers(0); cputc('x'); chBack (); c1 = cpeekrevers(); chForth();
284 revers(1); cputc('X'); chBack (); c2 = cpeekrevers(); chForth();
285 cputc('\n'); cputc('\r');
286 revers(c1); cputc('o');
287 revers(c2); cputc('O');
291 cprintf("\n\rtest1234"); gotox(0); cpeeks(s, 8); cputs("\n");
295 if (doesclrscrafterexit()) {