;from <http://www.lemon64.com//forum/viewtopic.php?t=5839>
;DanPhillips
;Posted: Sun Dec 29, 2002 5:30 pm   Post subject: Armalyte Multiplexor source
;Hiya,
;Just for people to have a look at enjoy...
;Its not optimal...and could have been alot faster...20/20 hindsight
;Some of the spacing is messed up....
;CS is the current hardware sprite
;CO is the current sprite from the y sorted table

IRQSET  STA ASTORE
        STX XSTORE
        STY YSTORE
        LDA #1
        STA $D019
VECTOR  JMP VECTOR

INTO    EOR #255
        ADC $D012
        STA $D012
INTEND  LDA ASTORE ; maybe is this? INTOVER was not referenced
        LDX XSTORE
        LDY YSTORE
        RTI

PLEXOR  LDX #19
        STX CO
        STX FOREGROUND
        LDA #0
        STA CS
        LDA #<SPLIT
        STA VECTOR+1
        LDA #>SPLIT
        STA VECTOR+2
SPLIT   LDY CO












;---------------------------
SPR0    LDX CS
        BNE SPR1
        SEC
TE0     LDA $D012
        SBC #22
        SBC $D005
        BCS IT0
        CMP #253
        BCS TE0
        JMP INTO

IT0     LDX YORDER,Y
        LDA ALTYPE,X
        CMP #2
        BCS VS0
        DEY
        BPL IT0
        JMP INTEND

VS0     LDA YTAB,X
        STA $D005
        LDA XTAB,X
        STA $D004
        LDA DEF,X
        STA POINT+2
        STA POINT2+2
        LDA MSB,X
        BEQ MO0
        LDA #4
        ORA $D010
        JMP BA0

MO0     LDA #251
        AND $D010
BA0     STA $D010
        LDA COL,X
        STA $D029
        INC CS
        DEY
        STY CO
        BPL TE1
        JMP INTEND




;---------------------------
SPR1    CPX #1
        BNE SPR2

TE1     LDA $D012
        SBC #22
        SBC $D007
        BCS IT1
        CMP #253
        BCS TE1
        JMP INTO

IT1     LDX YORDER,Y
        LDA ALTYPE,X
        CMP #2
        BCS VS1
        DEY
        BPL IT1
        JMP INTEND

VS1     LDA YTAB,X
        STA $D007
        LDA XTAB,X
        STA $D006
        LDA DEF,X
        STA POINT+3
        STA POINT2+3
        LDA MSB,X
        BEQ MO1
        LDA #8
        ORA $D010
        JMP BA1

MO1     LDA #247
        AND $D010
BA1     STA $D010
        LDA COL,X
        STA $D02A
        INC CS
        DEY
        STY CO
        BPL TE2
        JMP INTEND




;---------------------------
SPR2    CPX #2
        BNE SPR3

TE2     LDA $D012
        SBC #22
        SBC $D009
        BCS IT2
        CMP #253
        BCS TE2
        JMP INTO

IT2     LDX YORDER,Y
        LDA ALTYPE,X
        CMP #2
        BCS VS2
        DEY
        BPL IT2
        JMP INTEND

VS2     LDA YTAB,X
        STA $D009
        LDA XTAB,X
        STA $D008
        LDA DEF,X
        STA POINT+4
        STA POINT2+4
        LDA MSB,X
        BEQ MO2
        LDA #16
        ORA $D010
        JMP BA2

MO2     LDA #239
        AND $D010
BA2     STA $D010
        LDA COL,X
        STA $D02B
        INC CS
        DEY
        STY CO
        BPL TE3
        JMP INTEND




;---------------------------
SPR3    CPX#3
        BNE SPR4

TE3     LDA $D012
        SBC #22
        SBC $D00B
        BCS IT3
        CMP #253
        BCS TE3
        JMP INTO

IT3     LDX YORDER,Y
        LDA ALTYPE,X
        CMP #2
        BCS VS3
        DEY
        BPL IT3
        JMP INTEND

VS3     LDA YTAB,X
        STA $D00B
        LDA XTAB,X
        STA $D00A
        LDA DEF,X
        STA POINT+5
        STA POINT2+5
        LDA MSB,X
        BEQ MO3
        LDA #32
        ORA $D010
        JMP BA3

MO3     LDA #223
        AND $D010
BA3     STA $D010
        LDA COL,X
        STA $D02C
        INC CS
        DEY
        STY CO
        BPL TE4
        JMP INTEND




;---------------------------
SPR4    CPX#4
        BNE TE5

TE4     LDA $D012
        SBC #22
        SBC $D00D
        BCS IT4
        CMP #253
        BCS TE4
        JMP INTO

IT4     LDX YORDER,Y
        LDA ALTYPE,X
        CMP #2
        BCS VS4
        DEY
        BPL IT4
        JMP INTEND

VS4     LDA YTAB,X
        STA $D00D
        LDA XTAB,X
        STA $D00C
        LDA DEF,X
        STA POINT+6
        STA POINT2+6
        LDA MSB,X
        BEQ MO4
        LDA #64
        ORA $D010
        JMP BA4

MO4     LDA #191
        AND $D010
BA4     STA $D010
        LDA COL,X
        STA $D02D
        INC CS
        DEY
        STY CO
        BPL TE5
        JMP INTEND




;---------------------------



TE5     LDA $D012
        SBC #22
        SBC $D00F
        BCS IT5
        CMP #253
        BCS TE5
        JMP INTO

IT5     LDX YORDER,Y
        LDA ALTYPE,X
        CMP #2
        BCS VS5
        DEY
        BPL IT5
        JMP INTEND

VS5     LDA YTAB,X
        STA $D00F
        LDA XTAB,X
        STA $D00E
        LDA DEF,X
        STA POINT+7
        STA POINT2+7
        LDA MSB,X
        BEQ MO5
        LDA #128
        ORA $D010
        JMP BA5

MO5     LDA #127
        AND $D010
BA5     STA $D010
        LDA COL,X
        STA $D02E
        LDA #0
        STA CS
        DEY
        STY CO
        BMI SPR6
        JMP TE0

SPR6    JMP INTEND
;---------------------------
;Stick $80 in the stack for the first $80 positions
;--------------------------
YSORT   TSX
        STX TEMP
;--------------------------
CNT     SET 19
        REPEAT 20

        LDA YTAB+CNT
        LSR A
        TAX
        TXS
        PLA
        BPL *-1
        LDA #CNT
        PHA

CNT     SET CNT-1
        REPEND
;--------------------------
        LDX #24
        TXS
        LDY #$FF

CNT     SET 19
        REPEAT 19

        PLA
        BMI *-1
        STA YORDER+CNT
        TYA
        PHA
        PLA

CNT     SET CNT-1
        REPEND

YT0     PLA
        BMI YT0
        STA YORDER
        TYA
        PHA
;--------------------------
        LDX TEMP
        TXS
        RTS
;--------------------------
