Posted By
bubis on 2018-10-29 08:31:55
| Re: Starting off again
Good progress Doug! Yeah, you should also treat changes to $fffe-ffff as atomic. I think a good practice is to change some flag (eg. by inc-in some mem) and have some code running in an interrupt to watch that flag and do the appropriate changes. You can also do your changes between sei/cli but in that case you run the risk of missing/delaying time critical interrupts for example when you have multiple raster interrupts "building" your screen.
I often use this pattern: I have newValueA, newValueB, ... and the flag updateValues. I check in an interrupt if updateValues is zero and if not I copy newValueA, ... to the right place and set updateValues zero again. When I want a change I set newValueA, ... first and inc updateValues. It is also important that this method is only OK is updateValues never goes above one. That could also cause inconsistent changes when a interrupt happents while your are updating newValues... and updateValues is already non-zero.
|