When testing a new target, you only need to define MODE_GRAPHICS and MODE_TEXT (unless the standard values can be used), and DO_NOT_USE_CLG where necessary.
The test results are as follows:
Galaksija Plus: all ok
Laser 500: broken screen after switching back to text mode
MC-1000: all ok
NEC PC-6001 Mk2: all ok
Samsung SPC-1000: broken screen after switching back to text mode
Tiki-100: all ok
Could you please check the Laser 500 and the SPC-1000?
Are there more targets that use console_ioctl() screen mode switching? Please list them here, or try them out yourself.
Code: Select all
/*
smt.c - Screen Mode Test
Test program for screen mode switching using console_ioctl()
Author: RobertK, 2019-01-19
Compile with:
zcc +gal -subtype=galaxyp -create-app -pragma-redirect:fputc_cons=fputc_cons_generic -pragma-redirect:CRT_FONT=_font_8x8_bbc_system -o smtgalplus smt.c -D__GALPLUSHIRES__
zcc +laser500 -pragma-redirect:CRT_FONT=_font_8x8_bbc_system smt.c -o smt -create-app -Cz--audio -Cz--fast
zcc +mc1000 -pragma-redirect:fputc_cons=fputc_cons_generic -pragma-redirect:CRT_FONT=_font_8x8_bbc_system -create-app -Cz--audio smt.c -o smt_mc1000
zcc +pc6001 -subtype=rom -pragma-redirect:fputc_cons=fputc_cons_generic -pragma-redirect:CRT_FONT=_font_8x8_bbc_system -create-app -o smt_pc6001Mk2 smt.c
zcc +spc1000 -create-app -pragma-redirect:CRT_FONT=_font_8x8_bbc_system smt.c -o smt
zcc +cpm -subtype=tiki100 -ltiki100 -create-app -pragma-redirect:fputc_cons=fputc_cons_generic -o SMT.COM smt.c
*/
#include <stdio.h>
#include <graphics.h>
#include <sys/ioctl.h> // required for switching the screen mode
// Define graphics mode number
#if defined(__LASER500__)
#define MODE_GRAPHICS 2
#else
#define MODE_GRAPHICS 1 // Standard value if not defined otherwise
#endif
// Define text mode number
#if defined(__TIKI100__) // Tiki-100 (also known as "Kontiki-100")
#define MODE_TEXT 2
#else
#define MODE_TEXT 0 // Standard value if not defined otherwise
#endif
// Some systems do not support clg()
#if defined(__SPC1000__) || defined(__GAL__) || defined(__LASER500__)
#define DO_NOT_USE_CLG 1
#endif
void myCls() // Clear the screen (generic or VT100 console)
{
printf("%c",12);
printf("\x0c"); // the "\x0c" (0x0c character) resets the cursor position to the top left corner
}
void main()
{
int XScreenSize,YScreenSize; // dimensions of the text screen
int xMax,yMax; // dimensions of the graphics screen
int mode; // for screen mode switching
int x,y;
char c; // for keyboard input
int exitProgram=0;
// determine text screen size
screensize(&XScreenSize, &YScreenSize);
/* main loop */
while(exitProgram<1)
{
// Text screen
myCls(); // Clear the screen
// Draw a screen border using the character "x"
for (x = 0; x <XScreenSize; ++x)
{
gotoxy(x,YScreenSize-1);
printf("x");
gotoxy(x,0);
printf("x");
}
for (y = 1; y <YScreenSize; ++y)
{
gotoxy(0,y);
printf("x");
gotoxy(XScreenSize-1,y);
printf("x");
}
gotoxy(2,2);
printf("text screen test");
gotoxy(2,4);
printf("screen size: x=%d, y=%d\n",XScreenSize,YScreenSize);
gotoxy(2,6);
printf("press x to exit, any");
gotoxy(2,7);
printf("other key to switch");
gotoxy(2,8);
printf("to graphics mode...");
c = fgetc_cons(); // wait for keypress
if (c=='x' || c=='X')
exitProgram=1;
else
{
// Graphics Screen
// switch to graphics mode
mode = MODE_GRAPHICS;
console_ioctl(IOCTL_GENCON_SET_MODE, &mode);
#if !defined(DO_NOT_USE_CLG)
clg();
#endif
myCls(); // Clear the screen
// determine the screen dimensions for this system
// coordinates go from 0 to this max value
xMax=getmaxx();
yMax=getmaxy();
// Draw a screen border
for (x = 0; x <=xMax; ++x)
{
plot(x,yMax);
plot(x,0);
}
for (y = 1; y <=yMax; ++y)
{
plot(0,y);
plot(xMax,y);
}
gotoxy(2,2);
printf("graphics screen test");
gotoxy(2,4);
printf("screen size: x=%d, y=%d\n",xMax+1,yMax+1);
gotoxy(2,6);
printf("press x to exit, any");
gotoxy(2,7);
printf("other key to switch");
gotoxy(2,8);
printf("to text mode...");
c = fgetc_cons(); // wait for keypress
if (c=='x' || c=='X') exitProgram=1;
// switch back to text mode
mode = MODE_TEXT;
console_ioctl(IOCTL_GENCON_SET_MODE, &mode);
}
}
myCls(); // Clear the screen
return;
}