Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user ckoba ! (Registered 2016-09-24) 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: 138
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: 138
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: 76
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: 138
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
Ant
Mike
Hein
E$G/Hokuto Force
Impetigo/Crescent
Stainless Steel
ChristopherJam
The Dark Judge/Focus
Guests online: 23
Top Demos
1 Uncensored  (9.7)
2 Edge of Disgrace  (9.7)
3 Coma Light 13  (9.7)
4 Comaland  (9.6)
5 Comaland 100%  (9.6)
6 Wonderland XII  (9.5)
7 Fantasmolytic  (9.5)
8 Rocketry  (9.4)
9 GoatLight  (9.4)
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.3)
4 Led Board  (9.3)
5 One-Der  (9.2)
6 Hardware Accelerated..  (9.2)
7 Safe VSP  (9.1)
8 Ächzzeit  (9.1)
9 Goatbeard  (9.1)
10 Black Magic  (9.0)
Top Groups
1 Censor Design  (9.4)
2 Booze Design  (9.4)
3 Oxyron  (9.3)
4 Crest  (9.3)
5 Nostalgia  (9.2)
Top Mega Swappers
1 Nightshade  (9.4)
2 Aslive  (9.3)
3 Calypso  (9.2)
4 Dishy  (9.0)
5 R.C.S.  (8.9)

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