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: 223
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: 223
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: 105
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: 223
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
Smasher/F4CG
algorithm
acrouzet/G★P
csabanw
Bitbreaker/Performers
theK/ATL
CopAss/Leader
Guests online: 104
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
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 Triad  (9.3)
5 Censor Design  (9.3)
Top Original Suppliers
1 Derbyshire Ram  (9.7)
2 Fungus  (9.3)
3 Black Beard  (9.2)
4 Baracuda  (9.2)
5 hedning  (9.1)

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