Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Playing around with the return pointer ;)
2005-10-15 21:59
Bastet

Registered: Jul 2005
Posts: 88
Playing around with the return pointer ;)

Just some snippet.
;This little snippet demonstrates how to fool around with the RTS command
;Usefull for fast coding, if you know what you are doing
;
;Most "Pros" will say: Ohh, we did that onemillion years before you told us
;this, but this snippet is not for you, its for the beginners.
;Like me they are hunting down interesting speed up snippets but wont find any.
;So this is for all the beginners that search for them, if i have the time i
;will code more and collect them somewhere for you to find.
;If you happen to be one of the pros and want to add your snippets, do it.
;
;
;So what is this usefull for... you have more parts of a programm seperated into
;different files that all share the same start address. (maybe they should be
;runnable on their own) and you are simply loading with the kernel.
;With this you wont need looking after your loading routine, you can simply 
;overwrite it as it is not used anymore.
;You might come up with other uses, but thats what i use it for.
;
;Consider this snippet public domain
;BastetFurry of Dienstagstreff

!to "fakedjsr.prg",cbm
!convtab scr
*=$0800
!byte $00,$0c,$08,$0a,$00,$9e,$32,$31,$32,$38,$00,$00,$00,$00


*=$0850

;Clear the screen first.
lda #$20
ldx #$00

clearscreenloop:
sta $0400,x
sta $0500,x
sta $0600,x
sta $06e7,x
dex
bne clearscreenloop

;Output the first text
;I dont think i need to explain a text output routine
ldx #$ff
loop1:
inx
lda textstart,x
beq exitloop1
sta $0400,x
jmp loop1
exitloop1:

;We manipulate the return pointer by making our own.
;Just push the address, highbyte first, of the return address onto the stack,
;decrement the lowbyte as the return address is saved minus one and do a jump to
;your subroutine. The RTS will send the PC into the right direction.
;If you happen to have a page wrap remember that you need to manipulate the
;high byte too!

;Explained step by step
lda #>alteredreturnpointer ;We load the high byte of the return adress
pha                        ;Into the stack with it
lda #<alteredreturnpointer ;We load the low byte of the return adress
tax                        ;Substract one as it is saved in return address minus
dex                        ;one on the stack
txa                        ;SBC runs in BCD mode so we cant use it here or we 
                           ;would need to set the decimal flag accordingly
pha                        ;Into the stack with it
jmp subroutine             ;We jump to our subroutine

subroutine:
;Output the second text
ldx #$ff
loop2:
inx
lda textsub,x
beq exitloop2
sta $0428,x
jmp loop2
exitloop2:
rts                        ;This will retrive our modified return pointer from
                           ;the stack, add one to it and jumps to that address.

alteredreturnpointer:
;Output the third text
ldx #$ff
loop3:
inx
lda textalt,x
beq exitloop3
sta $0450,x
jmp loop3
exitloop3:

endless2:
inc $d020
jmp endless2

textstart:
!text "hello from start!"
!byte $00

textsub:
!text "hello from subroutine!"
!byte $00

textalt:
!text "hello from altered entrypoint!"
!byte $00

Hope some newbee, like me, will find this usefull
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
Devil/Clique
psenough
kbs/Pht/Lxt
LDX#40
Knut Clausen/SHAPE/F..
csabanw
Alakran_64
Luca/FIRE
Ghost/Quantum
ciccior2003/HF
Guests online: 103
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 No Listen  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (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 Crackers
1 Mr. Z  (9.9)
2 Antitrack  (9.8)
3 OTD  (9.8)
4 Fungus  (9.8)
5 S!R  (9.8)

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