Jump to content



Photo
* * * * * 1 votes

Request: Compilation of fx-CG50 Program

help

  • Please log in to reply
No replies to this topic

#1 stefano.Bailo

stefano.Bailo

    Newbie

  • Members
  • Pip
  • 1 posts

  • Calculators:
    casio fx cg50

Posted 05 October 2025 - 11:36 AM

Hi everyone,

I wrote a C program for the Casio fx-CG50 but I'm unable to compile it (toolchain issues on Mac M1). Could someone kindly compile it for me and provide the .g3m file?

Program Description

It's a surface area unit converter (in Italian language) that converts between:

  • Square meters (m²)
  • Ares (a)
  • Hectares (ha)
  • Milanese pertiche (pm) - historical Italian unit

With all possible conversions between these units.

Conversion Factors
  • 1 are = 100 m²
  • 1 hectare = 10,000 m²
  • 1 Milanese pertica = 654.5 m²
Codice sorgente
c
#include <fxcg/display.h>
#include <fxcg/keyboard.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// Fattori di conversione in metri quadrati
#define ARA_TO_M2 100.0
#define ETTARO_TO_M2 10000.0
#define PERTICA_TO_M2 654.5

// Funzione per pulire lo schermo
void clearScreen() {
Bdisp_AllClr_DDVRAM();
}

// Funzione per stampare testo centrato
void printCentered(int y, const char* text, int color) {
int x = (LCD_WIDTH_PX - strlen(text) * 6) / 2;
PrintXY(x/6, y, text, 0, color);
}

// Funzione per mostrare il menu principale
int showMainMenu() {
clearScreen();
printCentered(1, "CONVERTITORE", TEXT_COLOR_BLACK);
printCentered(2, "SUPERFICI", TEXT_COLOR_BLACK);
PrintXY(1, 4, "Da quale unita'?", 0, TEXT_COLOR_BLUE);
PrintXY(1, 6, "1 Metri quadri (m2)", 0, TEXT_COLOR_BLACK);
PrintXY(1, 7, "2 Are (a)", 0, TEXT_COLOR_BLACK);
PrintXY(1, 8, "3 Ettari (ha)", 0, TEXT_COLOR_BLACK);
PrintXY(1, 9, "4 Pertiche milanesi", 0, TEXT_COLOR_BLACK);
PrintXY(1, 11, "EXIT Esci", 0, TEXT_COLOR_RED);

int key;
while(1) {
GetKey(&key);
if(key >= KEY_CHAR_1 && key <= KEY_CHAR_4) {
return key - KEY_CHAR_1 + 1;
}
if(key == KEY_CTRL_EXIT) {
return 0;
}
}
}

// Funzione per mostrare il menu di destinazione
int showDestMenu(int source) {
clearScreen();
const char* units[] = {"m2", "Are", "Ettari", "Pertiche"};

char title[50];
sprintf(title, "Da %s a:", units[source-1]);
printCentered(1, title, TEXT_COLOR_BLUE);

int option = 1;
for(int i = 1; i <= 4; i++) {
if(i != source) {
char line[50];
sprintf(line, "[%d] %s", option, units[i-1]);
PrintXY(1, 3 + option, line, 0, TEXT_COLOR_BLACK);
option++;
}
}
PrintXY(1, 8, "EXIT Torna indietro", 0, TEXT_COLOR_RED);

int key;
while(1) {
GetKey(&key);
if(key >= KEY_CHAR_1 && key <= KEY_CHAR_3) {
int selected = key - KEY_CHAR_1 + 1;
// Mappa la selezione all'unità corretta saltando la sorgente
int dest = 0;
for(int i = 1; i <= 4; i++) {
if(i != source) {
dest++;
if(dest == selected) return i;
}
}
}
if(key == KEY_CTRL_EXIT) {
return 0;
}
}
}

// Funzione per ottenere input numerico
double getNumericInput() {
clearScreen();
PrintXY(1, 1, "Inserisci valore:", 0, TEXT_COLOR_BLUE);
PrintXY(1, 2, "(usa EXE per confermare)", 0, TEXT_COLOR_BLACK);

char buffer[50] = "";
int pos = 0;
int cursor_y = 4;

while(1) {
PrintXY(1, cursor_y, buffer, 0, TEXT_COLOR_BLACK);
PrintXY(1 + pos, cursor_y, "_", 0, TEXT_COLOR_RED);

int key;
GetKey(&key);

// Numeri
if(key >= KEY_CHAR_0 && key <= KEY_CHAR_9) {
if(pos < 45) {
buffer[pos++] = '0' + (key - KEY_CHAR_0);
buffer[pos] = '\0';
}
}
// Punto decimale
else if(key == KEY_CHAR_DP && strchr(buffer, '.') == NULL) {
if(pos < 45) {
buffer[pos++] = '.';
buffer[pos] = '\0';
}
}
// Cancella
else if(key == KEY_CTRL_DEL && pos > 0) {
buffer[--pos] = '\0';
}
// Conferma
else if(key == KEY_CTRL_EXE) {
if(pos > 0) {
return atof(buffer);
}
}
// Esci
else if(key == KEY_CTRL_EXIT) {
return -1;
}

clearScreen();
PrintXY(1, 1, "Inserisci valore:", 0, TEXT_COLOR_BLUE);
PrintXY(1, 2, "(usa EXE per confermare)", 0, TEXT_COLOR_BLACK);
}
}

// Funzione di conversione
double convert(double value, int source, int dest) {
// Prima converti tutto in m2
double m2;
switch(source) {
case 1: m2 = value; break;
case 2: m2 = value * ARA_TO_M2; break;
case 3: m2 = value * ETTARO_TO_M2; break;
case 4: m2 = value * PERTICA_TO_M2; break;
default: return 0;
}

// Poi converti da m2 alla destinazione
switch(dest) {
case 1: return m2;
case 2: return m2 / ARA_TO_M2;
case 3: return m2 / ETTARO_TO_M2;
case 4: return m2 / PERTICA_TO_M2;
default: return 0;
}
}

// Funzione per mostrare il risultato
void showResult(double input, double output, int source, int dest) {
clearScreen();
const char* units[] = {"m2", "a", "ha", "pm"};

printCentered(1, "RISULTATO", TEXT_COLOR_BLUE);

char line1[50], line2[50];
sprintf(line1, "%.6f %s", input, units[source-1]);
sprintf(line2, "%.6f %s", output, units[dest-1]);

PrintXY(1, 4, "Valore inserito:", 0, TEXT_COLOR_BLACK);
PrintXY(1, 5, line1, 0, TEXT_COLOR_GREEN);

PrintXY(1, 7, "Valore convertito:", 0, TEXT_COLOR_BLACK);
PrintXY(1, 8, line2, 0, TEXT_COLOR_GREEN);

PrintXY(1, 11, "EXIT Continua", 0, TEXT_COLOR_RED);

int key;
while(1) {
GetKey(&key);
if(key == KEY_CTRL_EXIT || key == KEY_CTRL_EXE) {
return;
}
}
}

// Funzione principale
int AddIn_main(int isAppli, unsigned short OptionNum) {
Bdisp_EnableColor(1);

while(1) {
int source = showMainMenu();
if(source == 0) break;

int dest = showDestMenu(source);
if(dest == 0) continue;

double value = getNumericInput();
if(value < 0) continue;

double result = convert(value, source, dest);
showResult(value, result, source, dest);
}

return 1;
}

#pragma section _BR_Size
unsigned long BR_Size;
#pragma section

#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum) {
return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section
Technical Details
  • Program name: ConvSup
  • Platform: Casio fx-CG50 / fx-CG20
  • Required format: .g3m
  • Maximum size: 2 MB
  • Icon: If possible, a simple 30x19 pixel icon (otherwise default is fine)
Thanks

Thank you so much in advance to anyone who can help! I really appreciate it.





Also tagged with one or more of these keywords: help

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users