2017-12-11 18:49:14 +00:00
|
|
|
/* Test that the cpeek...() functions are the inverses of cputc(),
|
|
|
|
** revers(), and textcolor() for the full range of character codes.
|
|
|
|
**
|
|
|
|
** 2017-07-15, Greg King
|
2017-12-12 16:05:52 +00:00
|
|
|
** 2017-12-12, Groepaz
|
2017-12-11 18:49:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <conio.h>
|
|
|
|
#include <cc65.h>
|
|
|
|
|
|
|
|
/* Standard location of the screen */
|
|
|
|
|
|
|
|
#if defined(__C128__) || defined(__C64__)
|
|
|
|
/* only 40-column screen */
|
|
|
|
# define SCREEN_RAM ((unsigned char*)0x0400)
|
|
|
|
#elif defined(__C16__) /* Plus4 also */
|
|
|
|
# define SCREEN_RAM ((unsigned char*)0x0C00)
|
|
|
|
#elif defined(__CBM510__)
|
|
|
|
# define SCREEN_RAM ((unsigned char*)0xF000)
|
2017-12-12 02:49:07 +00:00
|
|
|
# define COLOR_RAM ((unsigned char*)0xd400)
|
2017-12-11 18:49:14 +00:00
|
|
|
#elif defined(__CBM610__)
|
|
|
|
# define SCREEN_RAM ((unsigned char*)0xD000)
|
|
|
|
#elif defined(__PET__)
|
2017-12-11 20:15:29 +00:00
|
|
|
# define SCREEN_RAM ((unsigned char*)0x8000)
|
2017-12-11 18:49:14 +00:00
|
|
|
#elif defined(__VIC20__)
|
|
|
|
# define SCREEN_RAM ((unsigned char*)0x1000)
|
|
|
|
#else
|
|
|
|
# error This program cannot test that target.
|
|
|
|
# define SCREEN_RAM ((unsigned char*)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned char width;
|
|
|
|
|
|
|
|
|
|
|
|
/* Move the cursor backward one char with
|
|
|
|
** the recognition of a row change.
|
|
|
|
*/
|
|
|
|
static void chBack (void)
|
|
|
|
{
|
|
|
|
unsigned char y = wherey ();
|
|
|
|
unsigned char x = wherex ();
|
|
|
|
|
|
|
|
if (x == 0) {
|
|
|
|
x = width;
|
|
|
|
--y;
|
|
|
|
}
|
|
|
|
--x;
|
|
|
|
|
|
|
|
gotoxy (x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Move the cursor forward one char with
|
|
|
|
** the recognition of a row change.
|
|
|
|
*/
|
|
|
|
static void chForth (void)
|
|
|
|
{
|
|
|
|
unsigned char y = wherey ();
|
|
|
|
unsigned char x = wherex ();
|
|
|
|
|
|
|
|
if (++x >= width) {
|
|
|
|
x = 0;
|
|
|
|
++y;
|
|
|
|
}
|
|
|
|
|
|
|
|
gotoxy (x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* A hack to get an unmodified byte from the
|
|
|
|
** screen memory at the current cursor position.
|
|
|
|
*/
|
|
|
|
static unsigned char peekChWithoutTranslation (void)
|
|
|
|
{
|
|
|
|
#if defined(__CBM610__)
|
|
|
|
return peekbsys ((unsigned)&SCREEN_RAM[wherey () * width + wherex ()]);
|
|
|
|
#else
|
|
|
|
return SCREEN_RAM[wherey () * width + wherex ()];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-12-12 02:49:07 +00:00
|
|
|
/* as above, but for color ram */
|
|
|
|
static unsigned char peekColWithoutTranslation (void)
|
|
|
|
{
|
|
|
|
#if defined(__CBM610__) || defined (__PET__)
|
|
|
|
return COLOR_WHITE;
|
|
|
|
#elif defined(__C128__) || defined(__C64__) || defined(__VIC20__) || defined(__CBM510__)
|
|
|
|
return COLOR_RAM[wherey () * width + wherex ()] & 0x0f;
|
|
|
|
#else
|
|
|
|
return COLOR_RAM[wherey () * width + wherex ()];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:49:14 +00:00
|
|
|
|
|
|
|
/* A test which outputs the given char, reads it back from
|
|
|
|
** screen memory, outputs the returned char at the next position,
|
|
|
|
** then compares the two screen memory bytes for identity.
|
|
|
|
**
|
|
|
|
** Note: cpeekc() must be tested indirectly because some platforms "fold" their
|
|
|
|
** character code-set into a smaller screen code-set. Therefore, cpeekc() might
|
|
|
|
** return an equivalent, but not equal, character to the one that was cputc().
|
|
|
|
*/
|
|
|
|
static unsigned char testCPeekC (char ch)
|
|
|
|
{
|
|
|
|
unsigned char ch2_a, ch2_b, ch2_c;
|
|
|
|
|
|
|
|
/* Test the given char-code, but not the
|
|
|
|
** special characters NEWLINE and RETURN
|
|
|
|
** (they don't put anything on the screen).
|
|
|
|
*/
|
|
|
|
if (('\n' == ch) || ('\r' == ch)
|
|
|
|
) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-12-28 00:58:58 +00:00
|
|
|
/* toggle revers mode every few chars so cpeekc gets tested for both */
|
|
|
|
revers ((ch >> 3) & 1);
|
|
|
|
|
|
|
|
/* output additional space every now and then, that way not only even or only
|
|
|
|
odd half of the character cell will be tested */
|
|
|
|
#if defined(__C64__)
|
|
|
|
if ((width == 80) && ((ch % 17) == 0)) {
|
|
|
|
cputc(' ');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-12-11 18:49:14 +00:00
|
|
|
/* Output the char to the screen. */
|
|
|
|
cputc (ch);
|
|
|
|
|
|
|
|
/* Move the cursor pos. to the previous output. */
|
|
|
|
chBack ();
|
|
|
|
|
|
|
|
/* Get back the written char without any translation. */
|
|
|
|
ch2_b = peekChWithoutTranslation ();
|
|
|
|
|
|
|
|
/* Get back the written char,
|
|
|
|
** including the translation, screen-code -> text.
|
|
|
|
*/
|
|
|
|
ch2_a = cpeekc ();
|
|
|
|
|
|
|
|
/* Move the cursor to the following writing position. */
|
|
|
|
chForth ();
|
|
|
|
|
|
|
|
/* Output again the char which was read back by cpeekc(). */
|
|
|
|
cputc (ch2_a);
|
|
|
|
|
|
|
|
/* Move the cursor pos. to the second output. */
|
|
|
|
chBack ();
|
|
|
|
|
|
|
|
/* Get back the second written char without any translation;
|
|
|
|
** and, compare it to the first untranslated char.
|
|
|
|
*/
|
|
|
|
ch2_c = peekChWithoutTranslation ();
|
2017-12-12 16:05:52 +00:00
|
|
|
if ((ch2_c != ch2_b)
|
2017-12-28 00:58:58 +00:00
|
|
|
#if defined(__C128__) || defined(__C64__)
|
2018-01-01 13:01:25 +00:00
|
|
|
/* VDC memory is not accessible, soft80 has no "videoram" */
|
2017-12-12 16:05:52 +00:00
|
|
|
&& (width == 40)
|
|
|
|
#endif
|
|
|
|
){
|
2017-12-11 18:49:14 +00:00
|
|
|
/* The test was NOT succesful.
|
|
|
|
** Output a diagnostic; and, return FAILURE.
|
|
|
|
*/
|
|
|
|
revers(0);
|
|
|
|
cprintf ("\r\nError on char: %#x was %#x instead.", ch, ch2_a);
|
|
|
|
cprintf ("\r\nRaw screen codes: %#x, %#x.", ch2_b, ch2_c);
|
2017-12-12 02:49:07 +00:00
|
|
|
cprintf ("\r\nscreen width: %#d", width);
|
2017-12-11 18:49:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The test was succesful.
|
|
|
|
** Move the cursor to the following writing position.
|
|
|
|
*/
|
|
|
|
chForth ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-12-12 02:49:07 +00:00
|
|
|
static unsigned char testCPeekCol (char ch)
|
|
|
|
{
|
|
|
|
unsigned char ch2_a, ch2_b, ch2_c;
|
|
|
|
|
|
|
|
/* Output the char to the screen. */
|
|
|
|
textcolor (ch);
|
|
|
|
cputc ('*');
|
|
|
|
|
|
|
|
/* Move the cursor pos. to the previous output. */
|
|
|
|
chBack ();
|
|
|
|
|
|
|
|
/* Get back the written char without any translation. */
|
|
|
|
ch2_b = peekColWithoutTranslation ();
|
|
|
|
|
|
|
|
/* Get back the written char,
|
|
|
|
** including the translation, screen-code -> text.
|
|
|
|
*/
|
|
|
|
ch2_a = cpeekcolor ();
|
|
|
|
|
|
|
|
/* Move the cursor to the following writing position. */
|
|
|
|
chForth ();
|
|
|
|
|
|
|
|
/* Output again the char which was read back by cpeekc(). */
|
|
|
|
textcolor (ch2_a);
|
|
|
|
cputc ('x');
|
|
|
|
|
|
|
|
/* Move the cursor pos. to the second output. */
|
|
|
|
chBack ();
|
|
|
|
|
|
|
|
/* Get back the second written char without any translation;
|
|
|
|
** and, compare it to the first untranslated char.
|
|
|
|
*/
|
|
|
|
ch2_c = peekColWithoutTranslation ();
|
2017-12-12 16:05:52 +00:00
|
|
|
if ((ch2_c != ch2_b)
|
|
|
|
#if defined(__C128__)
|
2018-01-02 12:48:30 +00:00
|
|
|
/* VDC memory is not accessible */
|
2017-12-12 16:05:52 +00:00
|
|
|
&& (width == 40)
|
|
|
|
#endif
|
|
|
|
){
|
2017-12-12 02:49:07 +00:00
|
|
|
/* The test was NOT succesful.
|
|
|
|
** Output a diagnostic; and, return FAILURE.
|
|
|
|
*/
|
|
|
|
revers(0);
|
|
|
|
cprintf ("\r\nError on color: %#x was %#x instead.", ch, ch2_a);
|
|
|
|
cprintf ("\r\nRaw color codes: %#x, %#x.", ch2_b, ch2_c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The test was succesful.
|
|
|
|
** Move the cursor to the following writing position.
|
|
|
|
*/
|
|
|
|
chForth ();
|
|
|
|
return 1;
|
|
|
|
}
|
2017-12-11 18:49:14 +00:00
|
|
|
|
|
|
|
/* The main code initiates the screen for the tests, and sets the reverse flag.
|
|
|
|
** Then, it calls testCPeekC() for every char within 0..255.
|
2017-12-12 02:49:07 +00:00
|
|
|
** Then, it calls testCPeekCol() for each color
|
2017-12-11 18:49:14 +00:00
|
|
|
** Returns zero for success, one for failure.
|
|
|
|
*/
|
|
|
|
int main (void)
|
|
|
|
{
|
2017-12-12 02:49:07 +00:00
|
|
|
unsigned char i, c1, c2;
|
|
|
|
char s[10];
|
2017-12-11 18:49:14 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
clrscr ();
|
2017-12-28 00:58:58 +00:00
|
|
|
revers (0);
|
2017-12-12 02:49:07 +00:00
|
|
|
textcolor(1);
|
2017-12-12 16:05:52 +00:00
|
|
|
bgcolor(0);
|
2017-12-11 18:49:14 +00:00
|
|
|
screensize (&width, &i);
|
|
|
|
|
|
|
|
#if defined(__VIC20__)
|
|
|
|
/* The VIC-20's screen is too small to hold the full test. */
|
|
|
|
i = 2;
|
|
|
|
#else
|
|
|
|
i = 0;
|
|
|
|
#endif
|
|
|
|
do {
|
|
|
|
if (!testCPeekC (i)) {
|
|
|
|
ret = 1;
|
2017-12-12 02:49:07 +00:00
|
|
|
goto exiterror;
|
2017-12-11 18:49:14 +00:00
|
|
|
}
|
|
|
|
} while (++i != 0); /* will wrap around when finished */
|
|
|
|
|
2017-12-12 16:05:52 +00:00
|
|
|
#if defined(__VIC20__)
|
|
|
|
cgetc();
|
|
|
|
#endif
|
|
|
|
|
2017-12-12 02:49:07 +00:00
|
|
|
/* test colors */
|
2017-12-12 16:05:52 +00:00
|
|
|
#if defined(__VIC20__)
|
2017-12-12 02:49:07 +00:00
|
|
|
clrscr ();
|
2017-12-12 16:05:52 +00:00
|
|
|
#endif
|
2017-12-12 02:49:07 +00:00
|
|
|
revers (0);
|
2017-12-12 16:05:52 +00:00
|
|
|
textcolor(1);
|
|
|
|
|
2017-12-12 02:49:07 +00:00
|
|
|
#if defined (__CBM610__) || defined (__PET__)
|
2017-12-12 16:05:52 +00:00
|
|
|
cprintf("\n\rno COLOR_RAM\n\r");
|
2017-12-28 00:58:58 +00:00
|
|
|
#elif defined (__C128__) || defined (__C64__)
|
2017-12-12 16:05:52 +00:00
|
|
|
if (width == 40) {
|
|
|
|
cprintf("\n\rCOLOR_RAM at $%04x\n\r", COLOR_RAM);
|
|
|
|
} else {
|
|
|
|
cprintf("\n\rno COLOR_RAM\n\r");
|
|
|
|
}
|
2017-12-12 02:49:07 +00:00
|
|
|
#else
|
2017-12-12 16:05:52 +00:00
|
|
|
cprintf("\n\rCOLOR_RAM at $%04x\n\r", COLOR_RAM);
|
2017-12-12 02:49:07 +00:00
|
|
|
#endif
|
2017-12-12 16:05:52 +00:00
|
|
|
|
2017-12-12 02:49:07 +00:00
|
|
|
do {
|
|
|
|
if (!testCPeekCol (i)) {
|
|
|
|
ret = 1;
|
|
|
|
goto exiterror;
|
|
|
|
}
|
|
|
|
} while (++i != 16); /* max 16 colors */
|
|
|
|
|
|
|
|
/* test revers */
|
|
|
|
textcolor(1); cputc('\n'); cputc('\r');
|
2017-12-12 16:05:52 +00:00
|
|
|
revers(0); cputc('x'); chBack (); c1 = cpeekrevers(); chForth();
|
|
|
|
revers(1); cputc('X'); chBack (); c2 = cpeekrevers(); chForth();
|
2017-12-12 02:49:07 +00:00
|
|
|
cputc('\n'); cputc('\r');
|
2022-04-17 14:07:20 +00:00
|
|
|
revers(c1); cputc('o');
|
|
|
|
revers(c2); cputc('O');
|
2017-12-12 02:49:07 +00:00
|
|
|
|
|
|
|
/* test cpeeks() */
|
|
|
|
revers(0);
|
|
|
|
cprintf("\n\rtest1234"); gotox(0); cpeeks(s, 8); cputs("\n");
|
|
|
|
cputs(s);
|
|
|
|
|
|
|
|
exiterror:
|
2017-12-11 18:49:14 +00:00
|
|
|
if (doesclrscrafterexit()) {
|
|
|
|
cgetc();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|