Jump to content
IGNORED

Issues with Button Input on Atari Lynx - Help with Example Code


Recommended Posts

Hi everyone, I need your help to solve a problem related to handling button input in my Atari Lynx project.

 

Current Situation:

 

    I'm developing a checkers game on an old laptop running Ubuntu.

    I'm using cc65 as the compiler to write the code, and I'm testing progress with the Mednafen and Handy emulators.

    I have an SD cartridge for the Atari Lynx, but I don't have access to the actual console right now, so I can only test on emulators.

 

The Problem:

 

    The graphics and sound parts of the game are working fine.

    I'm having difficulty implementing the joystick button controls for selecting and confirming choices. I included the joystick.h file (which is in the same directory as the other header files), but the code generates errors when trying to manage button input.

    I checked the joystick.h file to verify the button constant names, and everything seems correct.

    I also tried compiling an example .c file I found here on the forum (the Pong game), but I got similar errors.

 

Request for Help:

 

Since I'm not an experienced programmer, I could really use your help to narrow down the problem. Here's what I'm asking:

 

    Do you have a working .c file that handles basic button input for the Atari Lynx (even a very simple example will do)?

    If you're able to successfully compile this file, I can try to do the same on my setup. If I still get errors, then we can rule out coding mistakes and focus on other possible issues (like libraries or my development environment).

 

Thanks so much for your time and help!

Link to comment
Share on other sites

I tried it but it's still having problems. I'll show you the test code I wrote and the final result:
 
  File test.c:
 
   #include <lynx.h>
   #include <tgi.h>
   #include <joystick.h>
   #include <6502.h>

   int main() {
       // Inizializza lo schermo del Lynx
tgi_install(&tgi_static_stddriver);
       
       // Inizializza il joystick
joy_install(&joy_static_stddriver);
       
       // Abilita gli interrupt
       CLI();
       
       while (1) {
           unsigned char joy = joy_read(0); // Legge lo stato del joystick
           if (joy & JOY_BTN_UP) {
               // Il joystick è spostato verso l'alto
           }
           if (joy & JOY_BTN_FIRE) {
               // Il pulsante FIRE è stato premuto
           }
       }

       return 0;
   }
 
-------------
 
after writing:
 
 cl65 -t lynx test.c -o test.lnx
final result: 

test.c(8): Error: Undefined symbol: 'tgi_static_stddriver'
test.c(11): Error: Undefined symbol: 'joy_static_stddriver'
test.c(18): Error: Undefined symbol: 'JOY_BTN_UP'
test.c(21): Error: Undefined symbol: 'JOY_BTN_FIRE'
 
-------------
Thanks again for your time. Alberto
Link to comment
Share on other sites

// I never got it working either

 

 


// #include <joystick.h> // not needed

unsigned char joy = 0; // joypad register
unsigned char swt = 0; // switches register


joy = *(char*)0xFCB0; // read joypad and buttons register
swt = *(char*)0xFCB1; // get switches register

if (joy != 0) {//anything was pressed}

if ((joy & 0b00000001) != 0) {A button was pressed}

if ((joy & 0b00010000) != 0) {D-Pad Right was pressed}

if ((swt & 0b00000001) !- 0) {// pause was pressed}

 

Link to comment
Share on other sites

Where am I going wrong?

 

#include <lynx.h>
#include <tgi.h>

unsigned char joy = 0; // Registra lo stato del joystick
unsigned char swt = 0; // Registra lo stato dei pulsanti

void draw_text(char* text, int x, int y) {
    tgi_setcolor(1); // Seleziona il colore bianco
    tgi_outtextxy(x, y, text); // Disegna la scritta
}

int main() {
    tgi_install(&tgi_static_stddriver); // Inizializza la grafica
    tgi_clear(); // Pulisce lo schermo inizialmente

    while (1) {
        joy = *(char*)0xFCB0; // Leggi lo stato del joystick
        swt = *(char*)0xFCB1; // Leggi lo stato dei pulsanti

        tgi_setcolor(0); // Imposta il colore di sfondo
        tgi_clear(); // Pulisce lo schermo

        if (joy & 0b00000001) { // Pulsante A premuto
            draw_text("Pulsante A premuto!", 20, 20);
        }
        
        if (joy & 0b00000010) { // Pulsante B premuto
            draw_text("Pulsante B premuto!", 20, 40);
        }

        if (swt & 0b00000001) { // Supponiamo che il pulsante 1 esca dal loop
            break;
        }

        tgi_flip(); // Aggiorna lo schermo
        delay(100); // Ritardo di 100 millisecondi
    }

    return 0;
}
 

Link to comment
Share on other sites

I managed to generate the .lnx file with this code:
 
#include <lynx.h>
#include <tgi.h>
 
unsigned char joy = 0; // Registra lo stato del joystick
unsigned char swt = 0; // Registra lo stato dei pulsanti
 
void draw_text(char* text, int x, int y) {
    tgi_setcolor(0x0F); // Seleziona il colore bianco
    tgi_outtextxy(x, y, text); // Disegna la scritta
}
 
// Funzione di ritardo personalizzata
void delay(unsigned int milliseconds) {
    unsigned int i, j;
    for (i = 0; i < milliseconds; i++) {
        for (j = 0; j < 1000; j++) {
            // Ciclo vuoto per creare il ritardo
        }
    }
}
 
int main() {
    tgi_install(tgi_stddrv); // Inizializza la grafica con il driver predefinito
    tgi_clear(); // Pulisce lo schermo inizialmente
 
    while (1) {
        joy = *(char*)0xFCB0; // Leggi lo stato del joystick
        swt = *(char*)0xFCB1; // Leggi lo stato dei pulsanti
 
        tgi_setcolor(0); // Imposta il colore di sfondo (trasparente)
        tgi_clear(); // Pulisce lo schermo
 
        if (joy & 0b00000001) { // Pulsante A premuto
            draw_text("Pulsante A premuto!", 20, 20);
        }
        
        if (joy & 0b00000010) { // Pulsante B premuto
            draw_text("Pulsante B premuto!", 20, 40);
        }
 
        if (swt & 0b00000001) { // Supponiamo che il pulsante 1 esca dal loop
            break;
        }
 
        tgi_flip(); // Aggiorna lo schermo
        delay(100); // Ritardo di 100 millisecondi
    }
 
    return 0;
}
 
With the Mednaffe emulator I see a black screen. With Handy the error is generated at startup.
 
Link to comment
Share on other sites

Hi @Alberto_G, don't know what version of CC65 you are using, the preferred version in this community isn't the official one on github but the one maintained by Karri (hosted on bitbucket).

 

Some hints, but consider that I'm using a version of the compiler 5 years old:

 

- after tgi_install call tgi_init()

- to read the joystick use joy = joy_read(JOY_1);

- to check the keypressed there are some useful macros defined in CC65, e.g. for checking the A button you can use if(JOY_BTN_FIRE(joy)) ...

 

On the forum you can find a program template from Karri with all the basic code you need.

 

If you need more help you can write me a PM. (Puoi scrivere in italiano se preferisci 😉)

Link to comment
Share on other sites

Ahhh... I see no tgi_init().... Just assumed it was a modification of a sample Hello World.

I haven't had a compiler installed for a month, so it's just me reading it.

 

The joypad defines won't work, and he'll have issues defining sprites as well, until he changes compiler, or finds the right way to do it.

 

Edited by Brek Martin
Link to comment
Share on other sites

I checked now. The version is:
 
cc65 V2.18 - Ubuntu 2.19-1
 
Today I tried to run the code following your advice. But it doesn't work. The C++ version of the same game works fine. But I have an advantage because I don't have to use the joystick! 😅
 

I hope to find a solution soon. I am trying to make a code that only involves the keys work. If it works, I will have to adapt it to the game code.

Link to comment
Share on other sites

Hi! Here's some stuff about CC65 "Remake" / "Karri's CC65" if you wanna try that one out.

 

 
One of the great things about this version are the template(s) and make files that exist for this version, they pretty much make it a quite easy to use small game development framework for the Lynx in C thanks to Karri and nop90.
 

 

 

- Newest working karri/nop90 template here as far as I know:
https://forums.atariage.com/topic/346438-atari-lynx-programming-template-working-as-of-january-11-2023/

I've set up a page with all kinds of known Lynx tools. It should be pretty comprehensive and pretty much up to date. Just updated some stuff there today: https://forums.atariage.com/topic/256753-atari-lynx-game-development-tools-and-tutorials-wip/

"Karri's cc65" also supports Chipper, abcmusic and Handymusic for sound.
Link to comment
Share on other sites

OldAtAtaris Readme comments about the template here are quite helpful too:
https://github.com/OldAtAtari/template

Also I wanted to mention that the "resident" part is always in RAM even if you would be swapping CC65 segments in and out of RAM, so it might make sense to not put too much stuff in there.

Edited by Turbo Laser Lynx
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...