2 ; Ullrich von Bassewitz, 17.08.1998
4 ; CC65 runtime: switch statement with long selector
7 ; Subroutine to handle a switch statement with an int selector. The table
8 ; is located at the return address from the function. It contains the negative
9 ; of the case label count as first word, followed by three words for each case
10 ; label, the first two being the value, and the second one the label to jump
11 ; to in case of a match. The default case is located at the end of the table.
14 .importzp sreg, ptr1, ptr2, ptr3
25 sta ptr2+1 ; Get pointer to table
32 sta ptr3+1 ; Remember the count of labels
35 clc ; Skip the label count
41 bne L2 ; Branch always
43 ; Search for the label
62 adc #6 ; Skip table entry
67 ; Check if there are any labels left
80 L3: ldy #4 ; Jump label offset