;the code for all the buttons is hardcoded and therefor part of the data..

buttoncode
        ; W(arp)

        lda warp1
        beq but2          ;0->0
        asl               ;1->2  2->4 3->6
        cmp #3            ;carry clear if warp1 is 1
        and #2
        sta warp1
        bcs but2

        ;if we got here, the button went from released -> pressed status
        ;so we do something

        lda warp
        ora #%00000001  ;set W
        sta warp
        lda #$81
        sta warplight1
but2
        ; (w)A(rp)

        lda warp2
        beq but3          ;0->0
        asl               ;1->2  2->4 3->6
        cmp #3            ;carry clear if warp1 is 1
        and #2
        sta warp2
        bcs but3

        ;if we got here, the button went from released -> pressed status
        ;so we do something

        lda warp
        ora #%00000010  ;set A
        sta warp
        lda #$81
        sta warplight2
but3
        ; (wa)R(p)

        lda warp3
        beq but4          ;0->0
        asl               ;1->2  2->4 3->6
        cmp #3            ;carry clear if warp1 is 1
        and #2
        sta warp3
        bcs but4

        ;if we got here, the button went from released -> pressed status
        ;so we do something

        lda warp
        ora #%00000100  ;set R
        sta warp
        lda #$81
        sta warplight3
but4
        ; (war)P

        lda warp4
        beq but5          ;0->0
        asl               ;1->2  2->4 3->6
        cmp #3            ;carry clear if warp1 is 1
        and #2
        sta warp4
        bcs but5

        ;if we got here, the button went from released -> pressed status
        ;so we do something

        lda warp
        ora #%00001000  ;set P
        sta warp
        lda #$81
        sta warplight4

but5
warp=*+1
        lda #0                 ;if all WARP lights lit, turn lights off and flash them
        cmp #%00001111
        bne warpnotlit
        lda #0
        sta warp
        lda #50
        sta warpflash
warpnotlit
        lda leftflipperbut
        cmp #2
        bne but6

        jsr warpcycle
but6
        lda rightflipperbut
        cmp #2
        bne but7

        jsr warpcycle
but7
        ;here we check if we need to flash the WARP lights :)

warpflash=*+1
        lda #0
        beq endwarpflash
        sec
        ror               ;turn lights on/off every 2 frames
        and #$81
        sta warplight1
        sta warplight2
        sta warplight3
        sta warplight4
        dec warpflash
        bne endwarpflash
        lda warp
        jsr updatewarplights
endwarpflash



endwarp ;warplights completely handled

        rts

warpcycle
        lda warp          ;cycle the lights
        lsr
        bcc *+4
        ora #%00001000
        sta warp
updatewarplights
        lsr
        ldx #$80
        bcc *+3
        inx
        stx warplight1

        lsr
        ldx #$80
        bcc *+3
        inx
        stx warplight2

        lsr
        ldx #$80
        bcc *+3
        inx
        stx warplight3

        lsr
        ldx #$80
        bcc *+3
        inx
        stx warplight4

        rts

