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


Forums > C64 Coding > How to use the stack area?
2016-03-07 22:31
Trap

Registered: Jul 2010
Posts: 132
How to use the stack area?

Hi,

I'm having some problems here that I need your help with.

I need to put some graphics in the area of the stack, $0100-$01ff. I can easily store data up to $01f0, but when I go beyond that, my code crashes.
So, I'm guessing here ... any branch or jump will store the PC on the stack or what? So, in order to make this work I would have to eliminate all loops in my initialization code? Would a simple TSX and TXS in my interrupt fix the remaining problem?

Am I on the right path here or have I strayed off it? ;)

Cheers
Trap
2016-03-07 22:33
Trap

Registered: Jul 2010
Posts: 132
Ah ok. Found that only JSR, PLA, PLP, RTS, PHA, PHP and RTI use the stack.

So, branches are ok I guess.
2016-03-07 22:37
Hoogo

Registered: Jun 2002
Posts: 75
Quoting Trap
Would a simple TSX and TXS in my interrupt fix the remaining problem?
I guess your interrupt is also your problem. You can't prevent that 3 bytes are pushed to the stack, and more if you're using the usual interrupt handler.
If you do not want to mess the stack, you have to avoid pha, pla, php, plp, jsr, rts, rti, brk. Turn off IRQs, and lock NMIs too if you want protection from the restore key.

EDIT: At least make sure that no IRQ appears in areas where your graphic is shown. An own IRQ handler can pick flags and return address from the stack, repair the graphic bug and return to the main loop without RTI. But handling the flags could be tricky enough that you will easily find a way without interrupts.
2016-03-07 23:09
Trap

Registered: Jul 2010
Posts: 132
Thanks Hoogo.

I managed to fix it. I just moved the SP to a safe spot and replaced the RTS I had at the end of my init code with a jmp back to main code. Viola!

Happy coder :)
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
bugjam
iceout/Avatar
Fred/Channel Four
No-XS
Guests online: 28
Top Demos
1 Uncensored  (9.7)
2 Coma Light 13  (9.7)
3 Edge of Disgrace  (9.7)
4 Comaland  (9.6)
5 Comaland 100%  (9.6)
6 Wonderland XII  (9.5)
7 Fantasmolytic  (9.5)
8 Rocketry  (9.5)
9 GoatLight  (9.5)
10 We Are Demo  (9.4)
Top onefile Demos
1 Treu Love [reu]  (9.5)
2 Daah, Those Acid Pil..  (9.4)
3 Dawnfall  (9.4)
4 One-Der  (9.3)
5 Hardware Accelerated..  (9.2)
6 Safe VSP  (9.1)
7 Black Magic  (9.0)
8 Goatbeard  (9.0)
9 Te-Te-Te-TechTech It..  (9.0)
10 Rainy Days  (9.0)
Top Groups
1 Censor Design  (9.5)
2 Booze Design  (9.4)
3 Oxyron  (9.4)
4 Crest  (9.4)
5 Nostalgia  (9.2)
Top Swappers
1 Zyron  (10)
2 Derbyshire Ram  (10)
3 Splatterhead  (9.8)
4 Walker  (9.7)
5 Acidchild  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2016
Page generated in: 0.58 sec.