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 > How to use the stack area?
2016-03-07 21:31
Trap

Registered: Jul 2010
Posts: 222
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 21:33
Trap

Registered: Jul 2010
Posts: 222
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 21:37
Hoogo

Registered: Jun 2002
Posts: 102
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 22:09
Trap

Registered: Jul 2010
Posts: 222
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
Falborg
eryngi
Guests online: 127
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Diskmag Editors
1 Jazzcat  (9.4)
2 Magic  (9.4)
3 hedning  (9.2)
4 Newscopy  (9.1)
5 Elwix  (9.1)

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