35 lines
910 B
Plaintext
35 lines
910 B
Plaintext
SwitchCase:
|
|
DC.L foo,bar,baz,default ;case 0, case 1, case 2, case 3. (Case 0,1,2 are the "valid" cases.)
|
|
; D0 is the case selector variable (byte-sized)
|
|
doSwitchCase: ;this is a subroutine that gets called elsewhere.
|
|
LEA SwitchCase,A0
|
|
|
|
;this is our bounds check
|
|
CMP.B #3,D0 ;is D0 > 3?
|
|
BLS InBounds ;if not, keep going
|
|
MOVE.B #3,D0 ;if it is, set it to 3.
|
|
|
|
|
|
InBounds:
|
|
LSL.W #2,D0 ;multiply by 4 to index into a table of longs
|
|
MOVE.L (A0,D0),A0 ;deref the pointer and store the desired routine in A0
|
|
MOVE.L A0,-(SP) ;push it onto the stack
|
|
RTS ;"return" to the selected routine. If it ends in an RTS,
|
|
; that RTS will return to just after "JSR doSwitchCase"
|
|
|
|
|
|
foo:
|
|
;your code for this case goes here.
|
|
rts
|
|
|
|
bar:
|
|
;your code for this case goes here.
|
|
rts
|
|
|
|
baz:
|
|
;your code for this case goes here.
|
|
rts
|
|
|
|
default:
|
|
rts
|