Page 1 of 1

How to detect what MPI slot the CoCoPSG is plugged into

PostPosted: Sun Dec 10, 2017 12:34 am
by nowhereman999
Hi All,

If you need your assembly program to figure out what slot the CoCoPSG is plugged into so you can turn off the autostart and access it without the user having to tell your program where it is you can use the little bit of code I wrote up based on Ed Snider's idea. Ed's idea is to write the value 255 to the address $FF5E which is the channel register of the YM chip inside the CoCoPSG. The idea is to write the value 255 to channels 0 through to channel 6. Since Channels 1,3,5 are only 4 bit registers they will only output a value of 15 and channel 6 is a 5 bit register which will output a value of 31. After writing to the registers and reading back the values the sum should be 255+15+255+15+255+15+31=841. If it is not 841 then it's not a CoCoPSG.

I needed this information in my MIDI to CoCoPSG player and I wanted the code to be pretty tight since one of the features is to have the CoCo play music in the background while BASIC is running. This code only uses 63 bytes.

The routine returns the value of which slot the CoCoPSG is in the B Accumulator. If B=$FF then it didn't find the CoCoPSG in the MPI. Otherwise B=the slot # -1 (0 to 3) where 0 = Slot 1,1 = Slot 2,2 = Slot 3,3 = Slot 4

Thanks Ed for the idea. :)

Have fun...

Code: Select all
* Detect what slot the CoCoPSG is in the Multi-Pak Interface
* Using Ed Snider's idea to detect which slot the CoCoPSG is plugged into in the Multi-Pak Interface
* All registers are preserved except B
* Result is in the B accumulator
* If B=$FF then no CoCoPSG is in any slot of the MPI
* otherwise B = the slot where the CoCoPSG is in -1 (0 to 3) where 0 = Slot 1,1 = Slot 2,2 = Slot 3,3 = Slot 4
        PSHS    A,X,CC
        ORCC    #$50
        LDA     $FF7F           * Get the original MPI_Register value (MPI Register)
        PSHS    A               * Save it for restore later
        LDB     #%11111100      * We will AND this value to select through the different MPI slots SCS selector
        STB     $FF7F           * Select Slot (MPI Register)
        PSHS    B               * Save B
        LDD     #$06FF          * Store $FF in registers 6 to 0 of the YM2149
        STD     $FF5E           * To see if the sum is 841 since Registers 0,2,4 store 8 bit values, 1,3,5 store 4 bit values (YM_Register Select)(YM_DATA)
        DECA                    * and register 6 stores a 5 bit value
        BPL     CS1             * Keep adding 255 to each byte
        LDA     #06
        LDX     #$0000
        STA     $FF5E           * Select the different registers (6 ot 0) (YM_Register Select)
        LDB     $FF5F           * Get the stored value of this register (YM_DATA)
        ABX                     * Add B to X to keep a running total
        DECA                    * Total stored on the CoCoPSG will be 255+15+255+15+255+15+31 = 841
        BPL     CS2             * Count down A from 6 to 0
        PULS    B               * Restore B
        CMPX    #841            * If the sum is 841 then this is the CoCo PSG slot
        BEQ     FoundCoCoPSG    * If X=841 then we found the slot with CoCo PSG :)
        CMPB    #$FF            * Check if we just checked slot 4
        BEQ     ExitPSGCheck    * If so then no CoCo PSG is detected exit with B=$FF :(
        INCB                    * Else, load next slot value
        BRA     CheckSlot       * Go check next slot
        ANDB    #%00000011      * B now has the slot # (0 to 3) value
        PULS    A               * Get the original MPI_Register value
        STA     $FF7F           * Restore the original value (MPI Register)
        PULS    A,X,CC,PC       * B = slot # -1 or $FF if not found