Remember, you can't branch to a subroutine, ever. This was a very serious mistake in your first attempts to make a NES ROM. The only way to call a subroutine is by using the JSR instruction. You may use the branch instructions to decide if the subroutine will be called or not, but never directly branch to it. The JSR instruction is the only one that puts the current value of the program counter in the stack, so that the subroutine can return to the place where it was called after it finishes.electro wrote:Maybe BEQ to a subroutine that clears the $4015 register?
I know you have no previous programming experience, but keep in mind that computers do not give a damn about english, and it really doesn't know what a subroutine is. This is a word, made up by humans, to make the commands easier to understand and remember. But as far as the CPU is concerned, what each command does is what matters, not what they are called.
For example, when you look at this page, you can see that there is a description of what the JSR instruction actually does, and you can see that "Jump to Subroutine" is just there to help us remember that instruction. By reading that description, you can see that I lied about JSR being the only way to call a subroutine. For some crazy reason, you may want to place a fake return address on the stack, and then simply JMP or branch to the subroutine. When the subroutine ends, it will fetch that address you placed on the stack before, even though it isn't the location where the routine was called. This kind of trick is a bit too advanced for you right now (you don't need to worry about tricking the CPU yet), but this is just an example.
Well, I'm saying all that because, with no programming background, you may end up relying too much on the name of the instructions. So this is just a heads uo, to let you know that computers are much more dumb than you think, and if you master the exact meaning of the instructions you give to them, you'll write better, more reliable, and faster code.