Jump to content
IGNORED

Hunt a bug in 5200 game source code - no controls


Recommended Posts

I am looking for help with the Atari 5200 version of the TRAIN game.

 

I have never tested the game with real hardware, only with the Altirra emulator, where the game works. However, real hardware users report that the game doesn't respond to any controls.

Can a subject matter expert review the code and identify what is wrong?

 

I suspect something can be wrong with cartridge initialization code (beginning of the main() function),

or with the joystick initialization jsInit(), or reading of the joystick - jsGet().

 

I've tried an alternate emulator (kat5200), but the cartridge wouldn't even start (just black screen).

 

https://github.com/baktragh/train_5200_ose/blob/master/train.c

 

Thank you.

Link to comment
Share on other sites

jsInit() does not initialise the joystick, it just pokes 4 into the console speaker, strange thing to do, essentially does nothing.

I was expecting this routine to set some direction variables.

 

/* Initialize joystick */
  void jsInit() {
  GTIA_WRITE.consol = 0x04;
  }

 

Don't think that's the problem, having a further look.

Link to comment
Share on other sites

Ok, looking at the code, looks like it's using keyboard in jsGet() not the joystick.

It calls kpdGet to apparently read the joystick to get the direction, but kpdGet

really does nothing, it's using an external variable kpdLastKey , so maybe there's some other code you've not

included that is setting this variable, in this code, there's only the external declaration and in the kpdGet routine

nowhere else. 

 

/*Get joystick direction*/
unsigned char jsGet(unsigned char flags) {

    unsigned char jx;
    unsigned char jy;
    unsigned char jk;
    
    /*First read keypad*/
    jk=kpdGet();
    if (jk!=0xFF) {
        
        if (jk==0x04) return JS_LEFT;
        if (jk==0x06) return JS_RIGHT;
        if (jk==0x02) return JS_UP;
        if (jk==0x05 || jk==0x08) return JS_DOWN;
        
        /*Start and reset only if requested by flags*/
        if (flags & JS_FLAG_RESET) {
            if (jk==0x0E) return JS_RESET;
        }
        if (flags & JS_FLAG_START) {
            if (jk==0x0C) return JS_START;
        }
        
    }
unsigned char kpdGet() {
    unsigned char k;
    k=kpdLastKey;
    kpdLastKey=0xFF;
    return k;
}

Link to comment
Share on other sites

It looks like you are double scanning the pots. Stage 2 VBI already writes POTGO to start the pot scan and it takes up to 228 scanlines to complete. Writing POTGO again truncates and restarts the pot scan, which can distort the returned values since the capacitors won't have been dumped.

 

Link to comment
Share on other sites

13 hours ago, TGB1718 said:

jsInit() does not initialise the joystick, it just pokes 4 into the console speaker, strange thing to do, essentially does nothing.

I was expecting this routine to set some direction variables.

 

/* Initialize joystick */
  void jsInit() {
  GTIA_WRITE.consol = 0x04;
  }

 

Don't think that's the problem, having a further look.

This is switching on power to the potentiometers of the analog stick. Without that, there would be no reading of the potentiometers at all.

Link to comment
Share on other sites

5 hours ago, phaeron said:

It looks like you are double scanning the pots. Stage 2 VBI already writes POTGO to start the pot scan and it takes up to 228 scanlines to complete. Writing POTGO again truncates and restarts the pot scan, which can distort the returned values since the capacitors won't have been dumped.

 

Thank you, I will remove the POTGO write and see what happens.

Link to comment
Share on other sites

4 hours ago, baktra said:

This is switching on power to the potentiometers of the analog stick. Without that, there would be no reading of the potentiometers at all.

Thanks, not got a 5200, not needed on the 800/XL/XE series, you learn something new every day :)

 

Link to comment
Share on other sites

It would appear that my whole approach to reading the potentiometers was wrong.

I have switched to using the the shadow registers, and at least under the atari800 and Altirra emulators, all seems OK.

 

I would be grateful, if there is someone who would try the attached cartridge image with a real machine to confirm that the problem was fixed.

The game should be controllable with both keypad and the analog stick. If this is confirmed to be working, I will release the updated source code, of course.

 

 

train1_5200_testfix.bin

  • Like 1
Link to comment
Share on other sites

I just tried this on a real 5200.  Even though I only played a couple of games getting to level four, it seems to work OK. I was able to reset the game with the reset key as well as using the fire button and the keypad to change the speed.  Fun game by the way.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

34 minutes ago, Allan said:

I just tried this on a real 5200.  Even though I only played a couple of games getting to level four, it seems to work OK. I was able to reset the game with the reset key as well as using the fire button and the keypad to change the speed.  Fun game by the way.

Thank you so much for trying.

I will commit, push, and release updated binaries.

 

The fixed games are downloadable from the github repository or from its home page.

If you are downloading from the home page, ensure you are not getting the old, cached copy. The date of the .bin files inside the .zip archive must indicate year 2023.

 

 

Edited by baktra
  • Like 2
Link to comment
Share on other sites

To conclude this bug fix

  1. I've made one more update to the game - the title screen now shows "v1.1", so it can be easily distinguished from the buggy version. Both repository and the project page were updated.
  2. The latest development version of Altirra updates the POKEY emulation, so that the buggy code results in no controls, like with the real hardware.
  3. A fun fact. My previous conversions to Atari 5200 had the controls right 🙂

So, in the end, we have one bug fixed, more precise POKEY emulation in Altirra, and one programmer's ego bruised. Not bad.

  • Like 2
Link to comment
Share on other sites

32 minutes ago, Aking said:

The attachments are .html pages, not cartridge images.

 

I believe it is a result of incorrect download procedure. It was probably as follows:

1. In the list of files in the repository, right-click the file

2. Select the “Save linked content as …” menu item

3. The linked content (which is actually a webpage) is downloaded

 

The correct procedure is the following:

1. In the list of the files in the repository, left-click the desired file

2. A new page displaying content of the file and details appears

3. Click the “Download” button to download the desired file.

  • Like 1
Link to comment
Share on other sites

yea, ppl have problems with downloading from github. the best solution I have is to make a release. it is quite simple. you can drag binary files to a release and then they got downloaded easier for uninitiated heathens.

  • Like 1
  • Haha 1
Link to comment
Share on other sites

10 hours ago, pirx said:

yea, ppl have problems with downloading from github. the best solution I have is to make a release. it is quite simple. you can drag binary files to a release and then they got downloaded easier for uninitiated heathens.

That could help to a certain extent, still doesn't fully prevent making the mistake with downloading webpages. Unless… I remove the binaries from the source code repository and publish them only as a release.

Link to comment
Share on other sites

That's purely a matter of preference. Distributing binaries with the source gives people the chance to try things out without having to install and configure the 5000 tools the repository needs. So personally I do add binaries to my repositories and also make releases when/if needed.

  • Like 2
Link to comment
Share on other sites

I believe the answer is… it depends. For projects that have a rather small binaries, having them in the repo is acceptable. If a release is nothing less than a huge docker image, then I wouldn't include it.

 

In any case, back to the primary topic.

The train arrives in Releaseville: https://github.com/baktragh/train_5200_ose/releases/tag/v1.1

 

 

 

Edited by baktra
  • Like 2
Link to comment
Share on other sites

1 hour ago, ggn said:

That's purely a matter of preference. Distributing binaries with the source gives people the chance to try things out without having to install and configure the 5000 tools the repository needs. So personally I do add binaries to my repositories and also make releases when/if needed.

You can distribute binary files, of course, but not in the repo. The repo shouldn't contain anything that can be and is generated.

 

My opinion, of course

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...