Rx interrupt routine for Elite Deathmatch

BIT a_status1
BPL exit
LDA #%00000001
BIT a_status2            ; Check if the Address Present flag is set
BEQ exit                 ; If not, exit
LDA a_receive
CMP #&E0                 ; Is it an Elite Deathmatch server-to-client packet?
BNE discontinue          ; If not, then discontinue receive
BIT a_status2            ; Check if next received byte is available in the Rx FIFO
BPL exit                 ; If not, exit
LDA a_receive
CMP #&01                 ; Is it an Elite Deathmatch protocol version &01?
BNE discontinue          ; If not, then discontinue receive
BIT a_status2            ; Check if next received byte is available in the Rx FIFO
BPL exit                 ; If not, exit
LDA a_receive            ; Someone launched an ECM?
BEQ rx_energybomb        ; If not, then continue
STA &30                  ; Set someone's ECM in Elite's workspace

.rx_energybomb
BIT a_status2            ; Check if next received byte is available in the Rx FIFO
BPL exit                 ; If not, exit
LDA a_receive            ; Someone launched an energy bomb?
BEQ rx_playercount       ; If not, then continue
LDA #&00                 ; Energy bomb means instant death, so...
STA &0365                ; Front shield = 0
STA &0366                ; Aft shield = 0
STA &0367                ; Energy = 0

.rx_playercount
BIT a_status2            ; Check if next received byte is available in the Rx FIFO
BPL exit                 ; If not, exit
LDY a_receive            ; Get number of players in this packet
STY ...

.rx_players
BIT a_status2            ; Check if next received byte is available in the Rx FIFO
BPL exit                 ; If not, exit
LDA a_receive            ; Get ship type
STA &0311,Y              ; Store it in Elite's workspace area
LDA a_receive            ; Has the ship fired it's laser at us?
BMI rx_players1
STA ...

.rx_players1
DEY
BPL rx_players
RTS

.discontinue             ; Discontinue frame reception
LDA #%10100010
STA a_control1           ; CR1: Reset transmitter, Rx frame discontinue (ignore rest of the frame), TDSR=off, RDSR=off, Tx interrupts=off, Rx interrupts=on, Select CR2/Tx FIFO

.exit
RTS
