I've finished going through some basic tutorials and am trying to move beyond them. I've been following this tutorial for reading user input:
http://thevirtualmountain.com/nes/2017/ ... input.html
The tutorial demonstrates how to read d-pad input to move some sprites one pixel at a time. Holding down the d-pad results in continuous movement. I'm trying to make a simple puzzle game where I want the player to move their sprite 8 pixels at a time. However this causes the sprites to move way too fast using the tutorial code as-is.
I took a search through the forums and found a similar question:
viewtopic.php?f=10&t=15124&p=183044&hilit=Controller+delay#p183044
The suggestion was to check if the buttons were pressed in the previous frame, and it links to a project with some existing controller code with a "delay auto shift" mechanism. Rather than trying to copy in all this code that I don't understand, I'm trying to do some simple changes. The functionality I want is that if the user presses the D-Pad, the sprite should move exactly 8 pixels in the desired direction, but it should move no further unless the user releases the d-pad and presses it again.
The way I tried to implement this was by allocating some memory in the zero page to store a bit mask for keeping track of previous controller state. I also try to initialize it to #$00. In the subroutine that reads controller button state one by one, I add some logic to check whether the bit representing the button is set. If it is set, that means the button was already pressed and the sprite presumably moved, so I have it proceed without moving the sprite. If the bit was not set, then I set the bit and move the sprite. I haven't added any code to clear the bit once the button is released, so I would expect this code to allow me to move the sprite once in each direction, and then no longer allow me to move after that. However when I build and run, the game allows the ship to continue zooming along as I press and hold the d-pad.
I forked the original project and added a commit with my changes here:
https://github.com/buschi8282/nes-tutor ... 1b62d83bdd
It should be possible to clone the repo and run the project (relevant commit is in branch tutorial-5)
I'm pretty new to this so I'm not sure what the error is, can anybody spot if there is anything wrong with my approach?
Also, are there any tools available for debugging, preferably on Mac (or compatible with WINE)? It would be awesome if there was a way to step through the code and see exactly what is in all the registers and in memory along the way. I feel like I'd be able to figure this out by myself with some basic debugging tools. Are there any tutorials that cover how to debug?
http://thevirtualmountain.com/nes/2017/ ... input.html
The tutorial demonstrates how to read d-pad input to move some sprites one pixel at a time. Holding down the d-pad results in continuous movement. I'm trying to make a simple puzzle game where I want the player to move their sprite 8 pixels at a time. However this causes the sprites to move way too fast using the tutorial code as-is.
I took a search through the forums and found a similar question:
viewtopic.php?f=10&t=15124&p=183044&hilit=Controller+delay#p183044
The suggestion was to check if the buttons were pressed in the previous frame, and it links to a project with some existing controller code with a "delay auto shift" mechanism. Rather than trying to copy in all this code that I don't understand, I'm trying to do some simple changes. The functionality I want is that if the user presses the D-Pad, the sprite should move exactly 8 pixels in the desired direction, but it should move no further unless the user releases the d-pad and presses it again.
The way I tried to implement this was by allocating some memory in the zero page to store a bit mask for keeping track of previous controller state. I also try to initialize it to #$00. In the subroutine that reads controller button state one by one, I add some logic to check whether the bit representing the button is set. If it is set, that means the button was already pressed and the sprite presumably moved, so I have it proceed without moving the sprite. If the bit was not set, then I set the bit and move the sprite. I haven't added any code to clear the bit once the button is released, so I would expect this code to allow me to move the sprite once in each direction, and then no longer allow me to move after that. However when I build and run, the game allows the ship to continue zooming along as I press and hold the d-pad.
I forked the original project and added a commit with my changes here:
https://github.com/buschi8282/nes-tutor ... 1b62d83bdd
It should be possible to clone the repo and run the project (relevant commit is in branch tutorial-5)
I'm pretty new to this so I'm not sure what the error is, can anybody spot if there is anything wrong with my approach?
Also, are there any tools available for debugging, preferably on Mac (or compatible with WINE)? It would be awesome if there was a way to step through the code and see exactly what is in all the registers and in memory along the way. I feel like I'd be able to figure this out by myself with some basic debugging tools. Are there any tutorials that cover how to debug?