Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user eightbitswide ! (Registered 2024-12-24) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > address for changing pointers for rts?
2006-02-11 01:23
midiland
Account closed

Registered: Nov 2004
Posts: 4
address for changing pointers for rts?

Hey guys

I need a reminder of the addresses used for when I need to change an address for a "rts" so it returns to a new location rather than the old

eg

jsr blah
rts
blah rts

but instead of returning to the jsr'd address to go to a new address

Thanks!!

I cant remember the mem locations to change it :(
 
... 11 posts hidden. Click here to view all posts....
 
2006-02-14 23:02
Bastet

Registered: Jul 2005
Posts: 88
Look over here, i wrote a nice snippet some time ago about that one: Playing around with the return pointer ;)
2006-02-15 17:48
Cruzer

Registered: Dec 2001
Posts: 1048
@Frantic: Yes I do, for calling speedcode generated by the main code.
2006-02-15 19:21
hannenz
Account closed

Registered: Nov 2002
Posts: 24
well, i think this is a very smart coding style. Espoecially if you want to jump to different routines depending on some value (similar to ON... GOTO):
let's say you want to jump to routine0,routine1,routine2...,routinen depending on the accus's value:

asl                     ;*2
tax                     ;to .X
lda adresstab+1,x       ;push hi byte of adress
pha                     ;on stack
lda adresstab,x         ;and lo-byte...
pha
rts                     ;now RTS will get the adress from the stack and jump to it
adresstab .word routine0-1,routine1-1,routine2-2,routine3-1... ;you'll need the adresses MINUS 1 here...!

btw: tmp/style (turbo macro pro assembler) features a handy pseudo-op for this, called ".rta" which assembles the given adresses as "adresses-1" as needed for this technique...

e.g.:

.rta routine0,routine1,routine2,routine3...

i like this technique!


2006-02-15 20:38
TNT
Account closed

Registered: Oct 2004
Posts: 189
Using rts to branch to different routines is worth the trouble only if you can't spare two memory locations to do "jmp ($nnnn)"...

I've used return address changing for passing arguments to routines, similar to Primm in C128 ROM. Printing strings becomes easy when you can do just
    jsr Primm
    dc.b "Text to print",0
    blah blah ;code continues here

instead of first loading the star address to registers and then calling the routine. It's bitch to disassemble, tho.

If you really want to get creative with it, use BRK interrupt followed with function ID and have functions with different number of data bytes following BRK+ID ;)
2006-02-16 06:01
chatGPZ

Registered: Dec 2001
Posts: 11386
also using the stack is slooow
2006-02-16 13:26
Ninja

Registered: Jan 2002
Posts: 411
and it destroys the table put there :)
2006-02-16 14:14
Monte Carlos

Registered: Jun 2004
Posts: 359
Stack is sometimes like local variables.
So doing a lda desttablo,x pha lda desttabhi,x pha rts
is a far better style than lda desttab,x sta jumpdest lda desttab,x sta jumpdest+1 jmp(jumpdest).
2006-02-16 22:07
Oswald

Registered: Apr 2002
Posts: 5094
unreadable style is a good style ? dont think so
2006-02-17 10:49
Monte Carlos

Registered: Jun 2004
Posts: 359
If you introduce a variable jumpdest and than do a jmp(jumpdest) you need the 2 bytes as long as your program is running. if you use the stack like in the example above, you only reserve memory as long as you need to, the code is shorter and it is faster.

lda #0..51
jsr mul5
....
mul5:
tsx
pha
asl
asl
adc $0100,x
txs
rts

Monte
2006-02-17 10:50
Monte Carlos

Registered: Jun 2004
Posts: 359
Just another example for locals. ;)

monte
Previous - 1 | 2 | 3 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Six/G★P
Ricky/Bonzai
Sulevi/Virtual Dreams
MCM/ONSLAUGHT
Jazzcat/Onslaught
Guests online: 72
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 X-Mas Demo 2024  (9.5)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Mutetus  (9.7)
3 Jeroen Tel  (9.7)
4 Linus  (9.6)
5 Stinsen  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.058 sec.