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

buttoncode

        ; D(ie)

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

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

        lda die
        ora #%00000001  ;set D
        sta die
        lda #$81
        sta dielight1
but2
        ; d(I)e

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

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

        lda die
        ora #%00000010  ;set I
        sta die
        lda #$81
        sta dielight2
but3
        ; W(arp)

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

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

        lda die
        ora #%00000100  ;set E
        sta die
        lda #$81
        sta dielight3
but4
die=*+1
        lda #0                 ;if all DIE lights are lit, turn them off and flash them
        cmp #%00000111
        bne dienotlit
        lda #0
        sta die
        lda #50
        sta dieflash
dienotlit

        lda leftflipperbut
        cmp #2
        bne but5

        jsr diecycle
but5
        lda rightflipperbut
        cmp #2
        bne but6

        jsr diecycle
but6
dieflash=*+1
        lda #0
        beq enddieflash
        sec
        ror
        and #$81
        sta dielight1
        sta dielight2
        sta dielight3
        dec dieflash
        bne enddieflash
        lda DIE
        jsr updatedielights
enddieflash

        rts

diecycle
        lda DIE
        lsr
        bcc *+4
        ora #%00000100
        sta DIE
updatedielights
        lsr
        ldx #$80
        bcc *+3
        inx
        stx dielight1

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

        ldx #$80
        bcc *+3
        inx
        stx dielight3
        rts

