Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Agnostic ! (Registered 2019-10-20) You are not logged in 
CSDb User Forums


Forums > C64 Coding > How to flags?
2019-09-27 09:52
mankeli

Registered: Oct 2010
Posts: 55
How to flags?

I want to set a flag in NMI, basically
lda flags
ora #setbits
sta flags


then I want to check & clear the flag in main routine, and branch if the flag was not set. But since it's not possible to suppress nmi by SEI, I can't make a critical section around the handler. There will be always several instructions.

It's preferrable that the checking code would be only in one place. Currently i have
lda flags
and #testbits
php
eor flags
sta flags
plp
beq skip
 .. 
skip:

I suspect there's a way to do this without the critical section but just wondering if someone knows already.
 
... 7 posts hidden. Click here to view all posts....
 
2019-09-28 10:03
mankeli

Registered: Oct 2010
Posts: 55
original problem was to set flags in nmi (only once), check them in main prog and clear them after checking and pack several of them to a byte to conserve memory.

But yeah, in this particular case it can be worked around by having byte per flag. But this was a bit of "code golf" type question if this be possible to do at all without disabling the nmi. ("lockless" way)
2019-09-28 14:07
Oswald

Registered: Apr 2002
Posts: 4442
thats the same problem again, what is the problem that you want to solve with the flagging ?
2019-09-28 14:38
Zirias

Registered: Jan 2014
Posts: 40
Often enough in such situations, you can get away with a "don't care" approach, because your code will always pick up the flag way before the next NMI that would potentially set it is triggered. Did you check that, is there an *actual* (not only potential) race condition?
2019-09-28 15:15
mankeli

Registered: Oct 2010
Posts: 55
yeah,
lda flags    
             # if nmi sets the tested flag here, it will be
             # overwritten by zero, others get eor'red in
eor flags
             # if nmi sets any flag here it's forgotten
sta flags
2019-09-28 19:59
Hoogo

Registered: Jun 2002
Posts: 89
The NMI should access and set a flag anytime, and the main loop will process a flag when it has time. It does not matter if the NMI has set the flag already twice before it is processed?

Maybe you can duplicate all flags and make it an array of 2 elements? One element is read by the mainloop, the other is written by NMI, and the main loop switches the index when done.

But using single bits of a byte as flags creates quite some overhead in code. If you don't have a "real" array of flags... maybe it is not worth it at all?

I would prefer CJs first solution.
--------------------
Here's a real lock, but it's of no use here. Here it does nothing more than a flag that denies NMI access to the flags.

lda#$4d ; eor abs
lock sta *
beq locked
....
lda#8d ;sta abs
sta lock
2019-09-29 08:05
oziphantom

Registered: Oct 2014
Posts: 350
your main code never touches the flags, only the NMI does..

so you have
MainLastState .byte ?
NMIFlags .byte ?

the NMI toggles the flags rather than set and forget.

and then you do

lda MainLastState
-
cmp NMIFlags
beq -
lda NMIFlags
sta MainLastState

and thus your main code looks for a state change, rather than a value.
2019-09-29 13:09
mankeli

Registered: Oct 2010
Posts: 55
I like your idea oziphantom! Downside of this is that if nmi can't "set" the flag twice, but it shouldn't be a problem.

And hoogo, I already settled on cj's idea. (it's true it creates overhead in code too) But just wanted to see if it's possible.
2019-09-29 17:23
oziphantom

Registered: Oct 2014
Posts: 350
then get the NMI it set it to the opposite of last flags, thus if it "sets it again" it will still be read as "set" by the main routine.
2019-09-30 19:58
mankeli

Registered: Oct 2010
Posts: 55
Also one suggestion from TNT/BF (his account is deleted):

This method has a byte per flag, but allows it to queue max 255 sets.

NMI:
INC flag

test:
LDA oldstate
CMP flag
BEQ noflagset
INC oldstate
JSR do_something
noflagset:
2019-10-02 21:25
Hoogo

Registered: Jun 2002
Posts: 89
For that, a DEC should do, too.

NMI:
INC flag

test:
LDA flag
BEQ noflagset
DEC flag
JSR do_something
noflagset:
Previous - 1 | 2 - Next
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
Skylab/The Movers
proton_FIG
Didi/Laxity
Trap/Bonzai
Randall
MisBug
tlr
Visage/Lethargy
MCM
iAN CooG/HVSC
A3/AFL
E$G/HoKuTo FOrCE
Mclane
Guests online: 71
Top Demos
1 Uncensored  (9.7)
2 Unboxed  (9.7)
3 Edge of Disgrace  (9.7)
4 Coma Light 13  (9.7)
5 Comaland 100%  (9.6)
6 Lunatico  (9.6)
7 The Shores of Reflec..  (9.6)
8 Rivalry  (9.5)
9 C=Bit 18  (9.5)
10 X Marks the Spot  (9.5)
Top onefile Demos
1 The Tuneful Eight (U..  (10)
2 Sprite Font Compo Re..  (9.8)
3 The Tuneful Eight [u..  (9.8)
4 Instinct  (9.6)
5 LSR 64 V0.31  (9.6)
6 Dawnfall V1.1  (9.5)
7 Smile to the Sky  (9.5)
8 Space Demo  (9.5)
9 Crystal Gazer  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 PriorArt  (9.7)
2 Fossil  (9.6)
3 Performers  (9.6)
4 Oxyron  (9.5)
5 Booze Design  (9.4)
Top Webmasters
1 Morpheus  (9.6)
2 Perff  (9.6)
3 Slaygon  (9.5)
4 Sabbi  (9.2)
5 CreaMD  (9.2)

Home - Disclaimer
Copyright © No Name 2001-2019
Page generated in: 0.043 sec.