-------------------------------------------------------------------------------
                 Classical Games 4-Player Adapter Specs v0.1
-------------------------------------------------------------------------------

contents
--------

- prelude
- vague shematics
- sample code
- credits

v0.1 prelude
------------

In Bombmania this adapter is (or was, since it seems its no more available)
more used as a dongle than for its original purpose - and not only for this
reason it had to be documented by someone ;=P However, since i dont even have
the thing (yet), a whole lot of this is here is still guesswork... hope to be
able to take a look at the adapter some time.

Vague shematics
---------------

I haven't looked closely at the original adapter yet, this is just what i
figured from looking at the code... no warranties or anything, i didnt bother
building one myself either :P

DON'T PANIC! :P the -->-- /  --<-- symbols do JUST mark the direction the data
is flowing! =)

User Port                                      Joysticks
---------                                      ---------

GND     1 ---------------+----------------- 8  JOY 3  GND
                         +----------------- 8  JOY 4  GND
                         +-------------+
5VDC    2 -------------------------+   |
                                   |   |
                                  +-----+
                                  |     +-- 1  JOY 3  A0
PB0     C ---------<-----JOY-A0---|     +-- 2  JOY 3  A1
                                  |  ?  +-- 3  JOY 3  A2
PB1     D ---------<-----JOY-A1---|  ?  +-- 4  JOY 3  A3
                                  |  ?  |
PB2     E ---------<-----JOY-A2---|  ?  +-- 1  JOY 4  A0
                                  |     +-- 2  JOY 4  A1
PB3     F ---------<-----JOY-A3---|     +-- 3  JOY 4  A2
                                  |     +---4  JOY 4  A3
                                  +--+--+
PB7     L --------->-----SWITCH------+

PB4     H ---------<----------------------- 1  JOY 3  BUTTON
PB5     J ---------<----------------------- 2  JOY 4  BUTTON

note: one should be able to find some IC that can switch two times four digital
      lines like this (someone who got the thing... bother looking inside? 8=)
      its prolly just some 74xx thingy (and maybe we need some inverters as
      well?))

sample code in Turbo-Ass syntax (skip this if you can't code *GRIN*)
--------------------------------------------------------------------

note: since i dont have the actual adapter i couldnt really test this, but i am
      pretty sure it will work though 8=) let me know if you have the adapter
      and got any problems with this code.

;---------------------------------------
;4 player adapter sample code by gpz/hit
;---------------------------------------

joy3reg  = $02  ; example joy-regs
joy4reg  = $03

btemp    = $04  ; temp for display

;---------------------------------------
; main
;---------------------------------------

         *= $1000

         ;
         ; usual irq setup
         ;

         sei
         lda #>irq
         sta $0315
         lda #<irq
         sta $0314
         lda #$1b
         sta $d011
         lda #$7f
         sta $dc0d
         lda #$ff
         sta $d012
         lda #$01
         sta $d01a

         ;
         ; print info
         ;

         ldx #$00
loop     .var *
         lda screen,x
         jsr $ffd2
         inx
         cpx #22
         bne loop

         jsr setup    ; cia setup for adapter

         cli

         jmp *

;---------------------------------------
; interupt calls other routines
;---------------------------------------
irq

         inc $d020

         jsr read   ; read adapter

         inc $d020

         ldx #(40*1)+4
         lda $dc00
         jsr displaybits

         ldx #(40*2)+4
         lda $dc01
         jsr displaybits

         ldx #(40*3)+4
         lda joy3reg
         jsr displaybits

         ldx #(40*4)+4
         lda joy4reg
         jsr displaybits

         lda #$00
         sta $d020

         inc $d019
         jmp $febc

;---------------------------------------
; displays 5 lowest bits of joystick-reg
;---------------------------------------
displaybits

         rol a
         rol a
         rol a

         sta btemp

         ldy #$00
loop     .var *

         rol btemp
         bcc skip1

         lda #"-"
         sta $0400,x
         jmp skip2
skip1
         lda #"*"
         sta $0400,x
skip2
         inx
         iny
         cpy #$05
         bne loop

         rts

;---------------------------------------
screen
         .text "{clr/home}joy brldu"
         .text " 1{return}"
         .text " 2{return}"
         .text " 3{return}"
         .text " 4{return}"

;---------------------------------------

;---------------------------------------
read
;---------------------------------------
; reads adapter and composes the
; additional virtual joystick-registers
;---------------------------------------
;this code demonstrates how to read the
;additional 2 joysticks and how to com-
;pose 2 'virtual' joystick-registers
;that can be processed exactly like the
;usual ($dc00/$dc01) ones.
;---------------------------------------

        lda $dd01       ; cia 2 port B read/write
        and #$1f        ; get bit 4-0 (PB4-PB0)
        sta joy3reg     ; joy 3 complete
        lda #$00        ; cia 2 port B read/write
        sta $dd01       ; (output zero at PB7)
        nop             ; no idea if this delay is needed
        nop
        nop
        lda $dd01       ; cia 2 port B read/write
        and #$0f        ; get bit 3-0 (PB3-PB0)
        sta joy4reg     ; joy 4 directions
        lda $dd01       ; cia 2 port B read/write
        and #%00100000  ; get bit 5 (PB5)
        lsr
        ora joy4reg
        sta joy4reg     ; joy 4 button
        rts

;---------------------------------------
setup
;---------------------------------------
;warning: do not mess around with this
;         unless you really know what
;         you are doing! wrong cia setup
;         may toast your cia's !
;---------------------------------------

        lda #%10000000  ; cia 2 port B Data-Direction
        sta $dd03       ; bit 7: out    bit 6-0: in
        nop             ; no idea if this delay is needed
        nop
        nop
        lda $dd01       ; cia 2 port B read/write
        sta $dd01       ; (output zero at PB7 ?)
        rts

;------------------------------------------------------------------------------

credits:
--------

reverse enginering, this document :            Groepaz/Hitmen (groepaz@gmx.net)

the original adapter was developed+sold by Classical games
