2 ; Ullrich von Bassewitz, 17.08.1998
4 ; CC65 runtime: switch statement with int 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 two words for each case
10 ; label, the first one 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 ptr1, ptr2, ptr3
24 sta ptr2+1 ; Get pointer to table
31 sta ptr3+1 ; Remember the count of labels
34 clc ; Skip the label count
40 bne L2 ; Branch always
42 ; Search for the label
50 iny ; Overflow only here
52 inc ptr2+1 ; Bump high byte
54 ; Check if there are any labels left