jubber
Vector Runner
Posts: 12
|
Post by jubber on Jul 26, 2018 9:49:34 GMT -5
hi there - having a spot of bother getting a jump table to work (as09 assembler). I assume these are possible on 6809, but I might be wrong.
ldx #JUMPS ldb room ; a value that is known to be good lslb abx stx temp_wide ; two consecutive bytes in ram jmp [temp_wide] ; jump to the value stored in temp_wide (is this right?)
Maze_Room_0 jsr Do_Something bra End Maze_Room_1 jsr Do_Something_Else bra End JUMPS fcw Maze_Room_0, Maze_Room_1, etc
End ; code carries on from here
Any advice much appreciated. I've not tried a jump table before and I'm getting constant crashes. Before I wrote the above code, I was using a pile of simple cmpa #N, beq place_N instructions - so I know the values coming in for room are correct.
Cheers,
Robin
|
|
jubber
Vector Runner
Posts: 12
|
Post by jubber on Jul 26, 2018 10:30:43 GMT -5
A chap called Eric Barwell has kindly pointed out that I should use
ldx #JUMPS ldb room lslb jmp [b,x]
great to know about that syntax, though I'm still curious why the original didn't work. Presumably jumping to the contents of a memory location doesn't work, or doesn't work like I hoped it might
|
|
|
Post by Malban on Jul 26, 2018 12:33:49 GMT -5
Hi
The [] denotes an indirect jump. What you are trying to achieve is in indirect indirect jump - no such thing exists in 6809 assembler.
Example: Lets assume your "tmp_wide" is at location $c880.
A "normal" jump to tmp_wide:
jmp tmp_wide
sets the program counter to $c880 and continues there.
Lets now assume in $c880 (word pointer) the address of your jump table is located, lets assume JUMPS is located at address $2000.
JUMPS: $ 2000 dw subroutinePointer1, subroutinePointer2, ...
Than an indirect jump using "tmp_wide":
jmp [tmp_wide]
sets the program counter to the contents of tmp_wide the program counter than is $2000 and starts running within your pointer table - and crashes. It doesn't really matter if you add 2 or 4 before it - the program counter is still in the middle of the pointer table.
I usually do what Eric suggested. But if you want to keep it complicated, you could also do:
ldx #JUMPS ldb room ; a value that is known to be good lslb abx !!! ldx ,x stx temp_wide ; two consecutive bytes in ram jmp [temp_wide] ; jump to the value stored in temp_wide (is this right?) Regards
Malban
|
|
jubber
Vector Runner
Posts: 12
|
Post by jubber on Jul 26, 2018 13:00:07 GMT -5
Thanks very much - that clears things right up.
|
|
|
Post by gtoal on Jul 26, 2018 23:48:34 GMT -5
if all your switch entries are a single jsr as in
Maze_Room_0 jsr Do_Something bra End Maze_Room_1 jsr Do_Something_Else bra End
then make your table from Do_Something, Do_Something_Else etc and avoid the extra indirection. Make your dispatch code the subroutine, ie
... ldb table_index jsr dispatch ...
and dispatch is then just something like:
dispatch ldx #jumptable jmp [b,x]
it gets slightly more complex if you write relocatable code, but who does that on the vectrex?
|
|
|
Post by gauze on Jul 26, 2018 23:54:05 GMT -5
jsr is for scrubs anyway (macro the world)
|
|
jubber
Vector Runner
Posts: 12
|
Post by jubber on Jul 27, 2018 1:32:16 GMT -5
Hi Mr. Battlezoned - thanks for the reply. As it happens the jsr bits in my code there were just for illustration - each room has variable amounts of code otherwise your suggestion would be the natural route to take.
Mr SpaceWar(ped) - I'd use macros more often but I'm always scrabbling around for rom space! So far my cartridge looks as if it will use up the entire available 64K and even then I'm going to need to replace a fair bit of code with subroutines. It's the age-old ram/speed trade-off
|
|
bfox
Asteroid
Posts: 1
|
Post by bfox on Oct 19, 2018 11:51:18 GMT -5
well, maybe such a thing?
ldx #JUMPS ldb room ; a value that is known to be good lslb ldx b,x tfr x,pc
|
|