Good way to do Jump table in PASM2?
Rayman
Posts: 14,646
in Propeller 2
While translating the P1 graphics.spin into P2, I ran into this:
Is there a good way to do this in P2?
What I did was just jump into hubexec and do a series of CMP and IF_Z JMP.
This is a lot less efficient by a large factor though....
I think there use to be a special P2 instruction for doing this a long time ago, but I think it got cut...
ror t1,#16+2 'lookup command address add t1,#jumps movs :table,t1 rol t1,#2 shl t1,#3 :table mov t2,0 shr t2,t1 and t2,#$FF jmp t2 'jump to command jumps byte 0 '0 byte setup_ '1 byte color_ '2 byte width_ '3 byte plot_ '4 byte line_ '5 byte arc_ '6 byte vec_ '7 byte vecarc_ '8 byte pix_ '9 byte pixarc_ 'A byte text_ 'B byte textarc_ 'C byte textmode_ 'D byte fill_ 'E byte loop 'F
Is there a good way to do this in P2?
What I did was just jump into hubexec and do a series of CMP and IF_Z JMP.
This is a lot less efficient by a large factor though....
I think there use to be a special P2 instruction for doing this a long time ago, but I think it got cut...
Comments
That would help a bit, but probably still not as compact as original.
I'll think about Wuerfel_21's idea...
If I'm seeing it right, can use byte jump table, just like the original.
ALTGB D, S will select byte #D from table starting at S
Getbyte D brings that byte into D
JMP to that D (and not #D) takes you where you need to go.
I'll have to try this out...
Of course, I remember from before that this only works when your are jumping to the lower 256 longs.
If your cog code is longer, you need to switch to a word table...
eg.
where vector contains
(value << 24) + COG address
Here's the new jump table code. It's actually much simpler than the original...