Jump to content
  • entries
  • comments
  • views

DPC+ARM - Part 12, Gamepad Support



NOTE: This blog series is obsolete.  Head on over to the Harmony/Melody Club where you'll find information on the new Linaro compiler and the new CDFJ coprocessor/bankswitch scheme that has many improvements over DPC+.


NOTE: This is an advanced Atari 2600 programming series. It will not cover basic things like triggering a Vertical Sync, what a Kernel is, why a timer is used in Vertical Blank, etc. If you need to learn that, check out with the following:

  • Collect - detailed development of a 2K game
  • 2600 Programming for Newbies - use the Sorted Table of Contents topic that's pinned at the top in order to easily access the tutorial topics in order.

Gamepad Support


I'm sure some of you are going "Say what?!?! But Collect didn't even use the firebutton.", and you'd be correct!


As you may or may not be aware, at the end of January I was approached by the author of one of AtariAge's top-ten 2600 homebrew games on how to use DPC+ with ARM support for a new project he's working on. I figured if he needed help to get up to speed on it, then others would as well - so a few days later I started up this series.


In a recent conversation I suggested that his project was an ideal candidate for multi-button gamepad support. He agreed, so I'm taking a minor detour to show how to implement support for gamepads.


Secondary Firebutton


As you know, the primary joystick firebutton is read via INT4 (left controller) and INTP5 (right).


The secondary firebutton on a gamepad is read via INPT1 (left) and INPT3 (right). Normally these are used to read the state of two of the paddles, but by a happy coincidence the secondary firebutton of some gamepads1 are wired to them.


Sadly the tertiary firebuttons are not wired to INPT0 or INPT2, though RevEng did figure out how to rewire a controller so its tertiary and quaternary buttons could be read, though the controller would no longer work as expected on its original console.




By another happy coincidence, if we check the state of INPT1 and INPT3 when the Atari is first powered on, we can determine if a joystick or a gamepad is plugged in.


Note: The test will fail if the player is pressing the secondary firebutton when the auto-detection code is run.


6507 Revisions

  • CallArmCode saves the state of INPT1 and INPT3 for the ARM to access
  • New characters U, L, and R added to font
  • Added new menu entry MENU_CONTROLLERS_ID used to show detected controllers
  • echo'd defines updated to output new information for the ARM code

C Revisions

  • Initialize() updated to auto-detect the controllers
  • MenuVerticalBlank() updated to display detected controllers
  • MenuProcessJoystick() changed to skip over new menu entry (it's not a user changeable setting)
  • PrepScoreDatastream() changed to use the scores to display controller state if both difficulty switches are set to A

what's it look like?


For these screenshots, Stella was configured to have a Joystick plugged into the left port and a Sega Genesis controller plugged into the right port.


detected controllers


If both difficulty switches are set to A the scores will show the state of the controllers:


controller states2


  • First digit - F if fire held on a joystick, or B if primary is held on gamepad
  • Second digit - C if secondary held on gamepad
  • Third digit - U, D, B3 or blank for up/down state
  • Fourth digit - L, R, B3 or blank for left/right state

Task for you


No task for you.


Blog series on hiatus


I've picked up a project with a hard deadline, so this series will be on hiatus until the project is finished.










1 gamepads known to work:

  • Amiga CD32 - red = Primary, blue = Secondary
  • Sega Genesis 3 & 6 button - B = Primary, C = Secondary

2 due to limited rollover ability of keyboards, this Stella screenshot is actually a composite of three screenshots.


3 B means both directions were held, which could happen when using a Starplex controller.





Recommended Comments

Not knowing who prompted you to make this series and what game is being coded with DPC+ ARM is maddening.

However, everyone single person on the top ten list is a brilliant coder!

I know games take years of hobby time, and not announcing can be a good thing for the coder as it lets them focus on coding rather than discussing a million questions and comments.

Link to comment
Add a comment...

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

  • Recently Browsing   0 members

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