[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 6502 Multitasking OS announce
[crossposted because I'm suggesting a technique useable on all 6502 machines]
In article <4iml11$s69@narses.hrz.tu-chemnitz.de>,
Andre Fachat <fachat@physik.tu-chemnitz.de> wrote:
>They disable Multitasking during their critical sections. The problem
>with the C64 is, that is doesn't have atomic test&set operations. So all
>task switches have to be disabled to test a semaphore, or when you enter
>a critical region.
Sure the 6502 has an atomic test-and-set style operation; my preferred
implementation [for example, to ensure that MyRoutine can only be called
once] is...
MyFlag:
.db $FF
MyRoutine:
inc MyFlag
bne MyRtnEnd
.. do my routine
MyRtnEnd:
dec MyFlag
rts
If MyFlag is $FF when I start MyRoutine, then either the inc will happen
before another instance of MyRoutine is started [in which case, I'll be
able to enter] or else it won't [in which case, the second instance will
get in]. Other variations include shift or rotate instructions but I
don't remember the flag semantics for those; if ROR set the overflow flag
with the old value of bit 7, that would be nice but I don't think it does.
--
-------------------------------------------------------------------------------
supercat@mcs.com | "Je crois que je ne vais jamais voir... | J\_/L
John Payson | Un animal aussi beau qu'un chat." | ( o o )