As I have said before, I am working on a program to create a simple Symbolic-Manipulation engine. I have created some code that runs an intro loop and I am working on the input loop. When I run the code, all I see is a black screen until I press "Enter", and then "Clear". Could someone please explain to me what is going on, or even better, help me rewrite my code so that it works?\
I am writing this project in C using SourceCoder 3.

Code:


// Program Name: Csymb
// Author(s): claculator
// License: GPL 3
// Description: expression simplifier written in C
#include <tice.h>
#include <graphx.h>
#include <keypadc.h>
#include <stdbool.h>
#define InputMax 50

int main(void) {
    gfx_Begin();
    gfx_SetDrawBuffer();
    int x = 0;
    int y = 30;
    int px = 160;
    int py = 200;
    int flashCounter = 0;
    while (!kb_IsDown(kb_KeyEnter)) {
        kb_Scan();
        gfx_FillScreen(0);
        gfx_SetTextXY(x, y);
        gfx_PrintString("Csymb Pre-Alpha");
        // Flash every 30 frames (~0.5 seconds at 60fps)
        if (flashCounter % 30 < 15) {
            gfx_SetTextXY(px, py);
            gfx_PrintString("Press ENTER");
        }
        flashCounter++;
        gfx_SwapDraw();
        x += 2;
        if (x > LCD_WIDTH) {
            x = -gfx_GetStringWidth("Csymb Pre-Alpha");
        }
    }
    do {
        kb_Scan();
    } while (kb_IsDown(kb_KeyEnter));
    gfx_FillScreen(0);
    gfx_SetTextFGColor(255);
    gfx_SetTextXY(10, 10);
    gfx_PrintString("Expression:");
    char input[InputMax + 1];
    input[0] = '\0';
    int length = 0;
    bool needsRedraw = true;
    while (true) {
        kb_Scan();
        if (kb_IsDown(kb_KeyClear)) {
            gfx_End();
            return 0;
        }
        if (kb_IsDown(kb_KeyEnter) && length > 0) {
            // TODO: Process the expression
            gfx_SetTextXY(10, 50);
            gfx_PrintString("Processing...");
            gfx_SwapDraw();
            break;
        }
        if (kb_IsDown(kb_KeyDel) && length > 0) {
            length--;
            input[length] = '\0';
            needsRedraw = true;
            delay(100); // Debounce
        }
        if (needsRedraw) {
         gfx_SetColor(0);
            gfx_FillRectangle(10, 30, LCD_WIDTH - 20, 20);
            gfx_SetTextXY(10, 30);
            gfx_SetTextFGColor(255);
            gfx_PrintString(input);
            gfx_SetTextXY(10 + gfx_GetStringWidth(input), 30);
            gfx_PrintString("_"); // Cursor
            gfx_SwapDraw();
            needsRedraw = false;
        }
    }
    gfx_End();
    return 0;
}

I'm not absolutely certain this is the only issue, but text foreground color defaults to index 0. Since you're filling the screen with 0 (black on the default palette), I'm guessing it is just printing black text on a black background. Try changing either your FillScreen to a different color (255 for white) or adding a gfx_SetTextFGColor before the first while loop and set the text to any color other than 0.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement