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
10 /* Standard location of the screen */
12 #if defined(__C128__) || defined(__C64__)
13 /* only 40-column screen */
14 # define SCREEN_RAM ((unsigned char*)0x0400)
15 #elif defined(__C16__) /* Plus4 also */
16 # define SCREEN_RAM ((unsigned char*)0x0C00)
17 #elif defined(__CBM510__)
18 # define SCREEN_RAM ((unsigned char*)0xF000)
19 # define COLOR_RAM ((unsigned char*)0xd400)
20 #elif defined(__CBM610__)
21 # define SCREEN_RAM ((unsigned char*)0xD000)
22 #elif defined(__PET__)
23 # define SCREEN_RAM ((unsigned char*)0x8000)
24 #elif defined(__VIC20__)
25 # define SCREEN_RAM ((unsigned char*)0x1000)
27 # error This program cannot test that target.
28 # define SCREEN_RAM ((unsigned char*)0)
31 static unsigned char width;
34 /* Move the cursor backward one char with
35 ** the recognition of a row change.
37 static void chBack (void)
39 unsigned char y = wherey ();
40 unsigned char x = wherex ();
52 /* Move the cursor forward one char with
53 ** the recognition of a row change.
55 static void chForth (void)
57 unsigned char y = wherey ();
58 unsigned char x = wherex ();
69 /* A hack to get an unmodified byte from the
70 ** screen memory at the current cursor position.
72 static unsigned char peekChWithoutTranslation (void)
74 #if defined(__CBM610__)
75 return peekbsys ((unsigned)&SCREEN_RAM[wherey () * width + wherex ()]);
77 return SCREEN_RAM[wherey () * width + wherex ()];
81 /* as above, but for color ram */
82 static unsigned char peekColWithoutTranslation (void)
84 #if defined(__CBM610__) || defined (__PET__)
86 #elif defined(__C128__) || defined(__C64__) || defined(__VIC20__) || defined(__CBM510__)
87 return COLOR_RAM[wherey () * width + wherex ()] & 0x0f;
89 return COLOR_RAM[wherey () * width + wherex ()];
94 /* A test which outputs the given char, reads it back from
95 ** screen memory, outputs the returned char at the next position,
96 ** then compares the two screen memory bytes for identity.
98 ** Note: cpeekc() must be tested indirectly because some platforms "fold" their
99 ** character code-set into a smaller screen code-set. Therefore, cpeekc() might
100 ** return an equivalent, but not equal, character to the one that was cputc().
102 static unsigned char testCPeekC (char ch)
104 unsigned char ch2_a, ch2_b, ch2_c;
106 /* Test the given char-code, but not the
107 ** special characters NEWLINE and RETURN
108 ** (they don't put anything on the screen).
110 if (('\n' == ch) || ('\r' == ch)
115 /* Output the char to the screen. */
118 /* Move the cursor pos. to the previous output. */
121 /* Get back the written char without any translation. */
122 ch2_b = peekChWithoutTranslation ();
124 /* Get back the written char,
125 ** including the translation, screen-code -> text.
129 /* Move the cursor to the following writing position. */
132 /* Output again the char which was read back by cpeekc(). */
135 /* Move the cursor pos. to the second output. */
138 /* Get back the second written char without any translation;
139 ** and, compare it to the first untranslated char.
141 ch2_c = peekChWithoutTranslation ();
142 if (ch2_c != ch2_b) {
143 /* The test was NOT succesful.
144 ** Output a diagnostic; and, return FAILURE.
147 cprintf ("\r\nError on char: %#x was %#x instead.", ch, ch2_a);
148 cprintf ("\r\nRaw screen codes: %#x, %#x.", ch2_b, ch2_c);
149 cprintf ("\r\nscreen width: %#d", width);
153 /* The test was succesful.
154 ** Move the cursor to the following writing position.
160 static unsigned char testCPeekCol (char ch)
162 unsigned char ch2_a, ch2_b, ch2_c;
164 /* Output the char to the screen. */
168 /* Move the cursor pos. to the previous output. */
171 /* Get back the written char without any translation. */
172 ch2_b = peekColWithoutTranslation ();
174 /* Get back the written char,
175 ** including the translation, screen-code -> text.
177 ch2_a = cpeekcolor ();
179 /* Move the cursor to the following writing position. */
182 /* Output again the char which was read back by cpeekc(). */
186 /* Move the cursor pos. to the second output. */
189 /* Get back the second written char without any translation;
190 ** and, compare it to the first untranslated char.
192 ch2_c = peekColWithoutTranslation ();
193 if (ch2_c != ch2_b) {
194 /* The test was NOT succesful.
195 ** Output a diagnostic; and, return FAILURE.
198 cprintf ("\r\nError on color: %#x was %#x instead.", ch, ch2_a);
199 cprintf ("\r\nRaw color codes: %#x, %#x.", ch2_b, ch2_c);
203 /* The test was succesful.
204 ** Move the cursor to the following writing position.
210 /* The main code initiates the screen for the tests, and sets the reverse flag.
211 ** Then, it calls testCPeekC() for every char within 0..255.
212 ** Then, it calls testCPeekCol() for each color
213 ** Returns zero for success, one for failure.
217 unsigned char i, c1, c2;
224 screensize (&width, &i);
226 #if defined(__VIC20__)
227 /* The VIC-20's screen is too small to hold the full test. */
233 if (!testCPeekC (i)) {
237 } while (++i != 0); /* will wrap around when finished */
242 #if defined (__CBM610__) || defined (__PET__)
243 cprintf("no COLOR_RAM\n\r");
245 cprintf("COLOR_RAM at $%04x\n\r", COLOR_RAM);
248 if (!testCPeekCol (i)) {
252 } while (++i != 16); /* max 16 colors */
255 textcolor(1); cputc('\n'); cputc('\r');
256 revers(0); cputc('*'); chBack (); c1 = cpeekrevers(); chForth();
257 revers(1); cputc('*'); chBack (); c2 = cpeekrevers(); chForth();
258 cputc('\n'); cputc('\r');
259 revers(c1); cputc('*');
260 revers(c2); cputc('*');
264 cprintf("\n\rtest1234"); gotox(0); cpeeks(s, 8); cputs("\n");
268 if (doesclrscrafterexit()) {