/*
C128 Menu Example in C
File: menu.c
Author: Micha B 08/2025
Compiler: Oscar64
Compile me:
oscar64 -v -i=include -tm=c128 -O2 -dNOFLOAT -dHEAPCHECK menu.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <petscii.h>
#include <stdbool.h>
#include <ctype.h>
/* --- Global variables --- */
char c_choice = 0;
/* --- Function prototypes --- */
void draw_menu(void);
bool f_quit(void);
bool f_opt1(void);
bool f_opt2(void);
bool f_opt3(void);
bool f_opt4(void);
/* --- Draw a text menu --- */
void draw_menu(void)
{
putpch(147); // SCNCLR
printf("\x05================================\n"); // text color: White
printf(" C128 Menu Example\n");
printf(" -----------------\n");
printf(" (1) Option 1 (2) Option 2\n");
printf(" (3) Option 3 (4) Option 4\n");
printf(" (0) Quit\n");
printf("================================\n");
printf("\x1EChoice:\x05 "); // switch to text color green, than back to white
}
/* --- React on user's demand to quit --- */
bool f_quit(void)
{
char c_answer = 'n';
puts("Quit requested!\n\n");
puts("Do you realy want to quit (Y/n)? ");
c_answer = getpch();
if ( ((int) c_answer == 89) || ((int) c_answer == 217) )
return (false);
else
return(true);
}
/* --- React on option 1 --- */
bool f_opt1(void)
{
puts("Option 1 requested.\n\n");
puts(" Press a key to CONTINUE... ");
getpch(); // wait for key pressed
return(true);
}
/* --- React on option 2 --- */
bool f_opt2(void)
{
puts("Option 2 requested.\n\n");
puts(" Press a key to CONTINUE... ");
getpch(); // wait for key pressed
return(true);
}
/* --- React on option 3 --- */
bool f_opt3(void)
{
puts("Option 3 requested.\n\n");
puts(" Press a key to CONTINUE... ");
getpch(); // wait for key pressed
return(true);
}
/* --- React on option 4 --- */
bool f_opt4(void)
{
puts("Option 4 requested.\n\n");
puts(" Press a key to CONTINUE... ");
getpch(); // wait for key pressed
return(true);
}
/* --- Main program --- */
int main(void)
{
bool running = true;
/* --- Prepare the environment --- */
// Switch display mode to lower case petscii
// could also be done by iocharmap(IOCHM_PETSCII_2);
putpch(14); // switch to charmap 2
putpch(8); // lock Charmap selector key
while (running)
{
draw_menu();
c_choice = getpch();
/* --- Select options --- */
switch(c_choice)
{
case '0':
running = f_quit();
break;
case '1':
running = f_opt1();
break;
case '2':
running = f_opt2();
break;
case '3':
running = f_opt3();
break;
case '4':
running = f_opt4();
break;
default:
draw_menu();
}
}
puts("\n\nProgram terminated.\n");
putpch(9); // unlock charmap selector key
putpch(142); // switch back to charmap 1
return 0;
}