Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Autres questions


Index du Forum » Autres questions » blank screen on program startup
Simnon Hors ligne Membre Points: 19 Défis: 0 Message

blank screen on program startup

Posté le 09/04/2025 16:26

code:
#include <gint/display.h>
#include <gint/keyboard.h>
#include <stdio.h>
#include <gint/gdb.h>

int main(void)
{
    char dir[2] = {1,0};
    unsigned char length = 0;
    unsigned char snake[256][2]  = {{8,8}};
    gdb_start_on_exception();
    dclear(C_WHITE);
    while(1){
        if(keydown(0x84)){
            break;
        }
        if(keydown(0x86)){
            dir[0] = 0;
            dir[1] = 1;
        }
        for(int pos=254; pos>=0; pos--){
            snake[pos+1][0] = snake[pos][0];
            snake[pos+1][1] = snake[pos][1];
        }
        drect_border(snake[length][0]*8, snake[length][1]*8, snake[length][0]*8+8, snake[length][1]*8+8,1,0, C_WHITE);
        snake[0][0] = snake[1][0]+dir[0];
        snake[0][1] = snake[1][1]+dir[1];
        drect_border(snake[0][0]*8, snake[0][1]*8, snake[0][0]*8+8, snake[0][1]*8+8, 1,0,C_BLACK);
        dupdate();
    }
    

    getkey();
    return 1;
}


When i run this program on my calculator (9860giii) it just shows a blank screen and i have to manually restart the calculator
I suppose im doing something wrong in the loop but i dont know what


Lephenixnoir Hors ligne Administrateur Points: 24993 Défis: 174 Message

Citer : Posté le 09/04/2025 17:40 | #


I suspect this is a combination of two issues.

First I'm suspecting that the screen isn't "blank", the program does work but since the snake starts in the center and moves 8 pixels per frame it only takes 8 frames for it to go out-of-bounds. Depending on the contrast setting on your calculator this might simply be happening too fast for you to see.

The second part is that you can only use keydown() to check for pressed keys after you've processed events. This confuses a lot of people but it's essential to keep the keyboard API running properly. You can process and discard events by calling clearevents() before starting to check keys:

while(1) {
    clearevents();
    if(keydown(KEY_MENU)) // ...
}

I would advise to use key names instead of raw numbers. You have all the names in <gint/keycodes.h>.

Also, you're using 1 as the fill color for rectangles, which is weird. This is the light gray color that is only available when the gray mode is enabled. If you don't want to fill the rectangle, use C_NONE.
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Simnon Hors ligne Membre Points: 19 Défis: 0 Message

Citer : Posté le 09/04/2025 18:02 | #


ok i used the key names instead of the numbers and now i can quit to menu but then i cant get back to the program after that, it just quits immediately, should i be quitting the program in a different way?
Lephenixnoir Hors ligne Administrateur Points: 24993 Défis: 174 Message

Citer : Posté le 09/04/2025 18:05 | #


Yes, if you want to be able to go back, you should call gint_osmenu() instead.

#include <gint/gint.h>

if(keydown(KEY_MENU)) gint_osmenu();

This will send you back to the main menu (on models where it's supported—the G-III is one of them) and allows coming back to resume execution where you left off. If you leave main(), then you obviously can't continue. You can call gint_setrestart(1) which will allow the add-in to be selected again in this situation, but then you'll start again from the beginning of the program.
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Simnon Hors ligne Membre Points: 19 Défis: 0 Message

Citer : Posté le 09/04/2025 18:07 | #


okay thanks, gint_setrestart(1) is by default 0?
Lephenixnoir Hors ligne Administrateur Points: 24993 Défis: 174 Message

Citer : Posté le 09/04/2025 18:09 | #


Yes, it's disabled by default because it's a bit of a hack.
Mon graphe (28 Janvier): (MPM ; serial gint ; (Rogue Life || HH2) ; PythonExtra ; ? ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Simnon Hors ligne Membre Points: 19 Défis: 0 Message

Citer : Posté le 09/04/2025 18:13 | #


i have another problem, when i quit the program (with gint_osmenu();) once, and come back to it any button i press quits it again
Simnon Hors ligne Membre Points: 19 Défis: 0 Message

Citer : Posté le 09/04/2025 20:16 | #


ill try changing the clearevent thing to different places

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2025 | Il y a 105 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd