As I am continuing to develop my first game, I ran into an issue that I couldn't find any information on. I would like to have the system detect the controllers on startup. This way, I can support multiple controllers in the game without using the difficulty switches or some other U/I system to select controller types, simply plug-and-play.
I first had the idea of using the fire button to get past the splash screen of the game. However, moving the joystick instead could put the game into paddle mode, which wouldn't be good. So instead, I discovered that you can simply dump the capacitors for the paddles, wait long enough (512 scanlines works), and then read INPT0 (and INPT2).
And that's it.
Here's the code I wrote, which works perfectly. If a paddle is connected to the left I/O port at startup, the screen will be red. Otherwise, the screen is black.
CLEAN_START sta WSYNC ; ensure a whole scanline is spent dumping capacitors lda #$80 sta VBLANK ; dump paddle capacitors to ground WaitLoop sta WSYNC stx VBLANK ; (X=0) stop dumping capacitors sta WSYNC ; waste 2 scanlines per iteration dey ; Y starts and ends as 0 bne WaitLoop ; wait 512 scanlines in loop (511 after grounding caps) lda INPT0 ; D7 set if left paddle is connected, clear otherwise bpl Joystick lda #$46 ; set bg color to red to signify a paddle, else black sta COLUBK ; in a game, you would set a bit in RAM, instead Joystick
I attached a .bin and the source code. Obviously, try it on a real system if you can, but it works in Stella, as well.
Edited by JeremiahK, Fri Jun 8, 2018 8:18 PM.