Jump to content
IGNORED

5200 Trak-ball Support


Recommended Posts

I'm wrapping up my new game, Magical Fairy Force, which supports the mighty 5200 trak-ball controller.

 

I had a bit of an adventure getting this thing to work, so I'd like to post everything I figured out about this controller in order help anyone else that might be considering a project that supports it.  I will disclaim that my methods may not be the best, but they seem to be working for me and are giving consistent results for the two trak-balls that I own.

 

First, I'd like to highlight this thread:

The information in this thread pointed me in the right direction, but some of the details were not quite right.  Building on what I found here, I came up with the following procedure:

 

First, it must be stated that in general you cannot uniformly handle the joystick and the trak-ball.  You first need to figure out which controller you're looking at so you know how to interpret the POT values later on.  Here is the procedure I used for this:

 

  1. Disable pot scanning by writing 0 to CONSOL.
  2. Wait for the POT shadows to update.  You might also be able to manually trigger a pot scan and read the values straight from POKEY, but I opted to use the shadows.
  3. Read one of the POT values and compare it to $e4.  When scanning is disabled, the joysticks report $e4 when read.  I believe this same value is also produced by an empty controller jack and I'm not aware of any way to discern between a joystick and no controller at all.
  4. If the value is not $e4, this is a trak-ball.  The value that was read is the rest value for that axis on the trak-ball.  Save this value somewhere, you'll need it.
  5. Read the POT for the other axis.  This is the rest value for that axis, the two axes can have different rest values.  Again, save this value.
  6. Repeat for each controller that you're interested in.
  7. Re-enable POT scanning by writing 4 to CONSOL.

 

When it comes time to handle input, you need to check each POT on the ball and compare the value to the rest value for that axis.  The difference from the rest value indicates the speed and direction of the ball's spin on that axis.  Values lower than the rest value are left/up, greater are right/down.  The values that you get tend to be in a very small range.  My game handles values +/-10 from the rest values.

 

Once my game is finalized, which should be within a couple of weeks, I'll release the complete source so any interested people can examine how I did this in detail.

  • Like 1
Link to comment
Share on other sites

I don't have a 5200 so can only speculate:

 

Joystick detection - maybe there's different behaviour of empty vs populated port for the keyboard code using different values in SKCTL?

On the computer you normally want 3 in there but with the 5200 it's 2 isn't it?

Maybe values 1 and 3 produce different keycode reporting if the port is empty or not.

 

Alternately - an inserted joystick would only produce value 228 on both POTs if pushed to a diagonal limit.

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
  • 4 weeks later...
On 5/29/2020 at 6:29 PM, Ryan Witmer said:

I'm wrapping up my new game, Magical Fairy Force, which supports the mighty 5200 trak-ball controller.

 

I had a bit of an adventure getting this thing to work, so I'd like to post everything I figured out about this controller in order help anyone else that might be considering a project that supports it.  I will disclaim that my methods may not be the best, but they seem to be working for me and are giving consistent results for the two trak-balls that I own.

 

First, I'd like to highlight this thread:

The information in this thread pointed me in the right direction, but some of the details were not quite right.  Building on what I found here, I came up with the following procedure:

 

First, it must be stated that in general you cannot uniformly handle the joystick and the trak-ball.  You first need to figure out which controller you're looking at so you know how to interpret the POT values later on.  Here is the procedure I used for this:

 

  1. Disable pot scanning by writing 0 to CONSOL.
  2. Wait for the POT shadows to update.  You might also be able to manually trigger a pot scan and read the values straight from POKEY, but I opted to use the shadows.
  3. Read one of the POT values and compare it to $e4.  When scanning is disabled, the joysticks report $e4 when read.  I believe this same value is also produced by an empty controller jack and I'm not aware of any way to discern between a joystick and no controller at all.
  4. If the value is not $e4, this is a trak-ball.  The value that was read is the rest value for that axis on the trak-ball.  Save this value somewhere, you'll need it.
  5. Read the POT for the other axis.  This is the rest value for that axis, the two axes can have different rest values.  Again, save this value.
  6. Repeat for each controller that you're interested in.
  7. Re-enable POT scanning by writing 4 to CONSOL.

 

When it comes time to handle input, you need to check each POT on the ball and compare the value to the rest value for that axis.  The difference from the rest value indicates the speed and direction of the ball's spin on that axis.  Values lower than the rest value are left/up, greater are right/down.  The values that you get tend to be in a very small range.  My game handles values +/-10 from the rest values.

 

Once my game is finalized, which should be within a couple of weeks, I'll release the complete source so any interested people can examine how I did this in detail.

I'm curious about how Centipede & Missile Command know if only one or two trak-balls are plugged in. With only one trak-ball plugged in, you can play a two player game passing the controller back and forth. 

Link to comment
Share on other sites

1 hour ago, SoundGammon said:

I'm curious about how Centipede & Missile Command know if only one or two trak-balls are plugged in. With only one trak-ball plugged in, you can play a two player game passing the controller back and forth. 

You can detect the trak-ball on a per-port basis using the method I listed.  My game does this, since it allows two players.  Those games probably just switch to two-player-one-ball mode if they detect the ball in port 1 but not port 2.  Only a disassembly can tell for sure.

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