====== Multi-Adapter Support ====== By Sokrates Several joystick/joypad adapters were available for the C64 (see also here: https://en.wikipedia.org/wiki/Commodore_64_joystick_adapters). Some are even available factory-new today. In the following it is described how to apply an automatic detection and query for three specific adapters in order to avoid manual configuration, as used in the game "RACE+". The adapters are: * SuperPad64 * Inception * 4-player adapter (protovision/icomp) Since the 4-player adapter is also supported in the VICE emulator, the multi-adapter code can be used for up to 8 players directly on the C64, and for up to 4 player on the PC. I don't know a way to detect the 4-player adapter. But fortunately this is not necessary in this constellation, because on the one hand the other two adapters can be detected. On the other hand, the query of the additional two ports of the 4-player adapter does not generate any input for these additional ports in the absence of the adapter. This means that the 4-player adapter query routine can also be used for the two joysticks in the standard control ports if there is no adapter connected at all. Detection is done in the following steps: - SuperPad64 detected? If yes, initialize and use it. If not, continue with 2. - Inception detected? If yes, initialize and use it. If not, continue with 3. - Initialize and use the 4-player adapter The detection routine of the first two adapters works correctly if no adapter is connected. The other way around, it could theoretically happen that another connected device is mistakenly recognized as an adapter (no case known so far). The prioritization from a player's perspective: - SuperPad64 - Inception - 4-player adapter and standard control ports - Only standard control ports If more than one adapter are connected, the adapter with the higher priority is taken (for example if SuperPad64 and the Inception adapter are both connected, then only the SuperPad64 can be used). If no adapter is connected, the standard control ports can be used. Source Code: ;; multi-adapter handling test code DETECTION = $0400 ; so you can see, if something happens OUTLINE0 = $0450 OUTLINE1 = OUTLINE0 + $28 OUTLINE2 = OUTLINE1 + $28 OUTLINE3 = OUTLINE2 + $28 OUTLINE4 = OUTLINE3 + $28 OUTLINE5 = OUTLINE4 + $28 OUTLINE6 = OUTLINE5 + $28 OUTLINE7 = OUTLINE6 + $28 ZEROPAGE_TMP_LO = $FB ZEROPAGE_TMP_HI = $FC ;; generate BASIC Header BASIC_START = $0801 CODE_START = $080d * = BASIC_START !byte 12,8,0,0,158 !if CODE_START >= 10000 {!byte 48+((CODE_START/10000)%10)} !if CODE_START >= 1000 {!byte 48+((CODE_START/1000)%10)} !if CODE_START >= 100 {!byte 48+((CODE_START/100)%10)} !if CODE_START >= 10 {!byte 48+((CODE_START/10)%10)} !byte 48+(CODE_START % 10),0,0,0 * = CODE_START main jsr Screen_init jsr Adapter_init jsr Draw_detection main_loop jsr Inception_wait jsr Adapter_read jsr Draw_lines jmp main_loop ;; some time must pass by until the inception adapter can be read again ;; otherwise there might be wrong results Inception_wait: lda joystickAdapter cmp #JOYSTICK_ADAPTER_INCEPTION bne Inception_waitIsNoInception ldy #$20 ldx #$00 Inception_waitLoop: nop dex bne Inception_waitLoop dey bne Inception_waitLoop Inception_waitIsNoInception: rts outLineHi !byte >OUTLINE0, >OUTLINE1, >OUTLINE2, >OUTLINE3, >OUTLINE4, >OUTLINE5, >OUTLINE6, >OUTLINE7 outLineLo !byte