matiancai74 wrote
I think that there was some kind of conflict going on in the program where I was writing to the SCREEN + 8192 th word, which is actually 24576, the Keyboard word. I also think that that I wasn't terminating the loops that 'painted' white/black pixels on the screen correctly by looking at the variable that counted the screen words.
You are correct. Excellent job analyzing the bug. I was just about to send you mail that said exactly that when I noticed your latest post.
There appears to be a bug in the Hardware Simulator. Writing to the Keyboard address corrupts the value that will be returned. The value remains bad until the next time a key is pressed or released.
So, by having the off-by-one bug that writes -1 to 24576 at the end of the black loop, the Keyboard read at the top of the program reads -1 even though the key has been released, and the program enters the black loop again.
Side note: Unless special circumstances require that you end a loop with an = or != comparison, it is safer to use <, <=, > or >= so that if something goes wrong with the loop index, to loop will still exit. The program may not do what it is supposed to, but at least it doesn't hang.
--Mark