Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading keyboard/joystick input
#1
Hi all

In order to control a 8x16 sprite, I'm using the MultiKeys function to read keyboard/Sinclair II input in a form of a subroutine inside the program. Problem is, the control experience is abrupt at its best, because keyboard is only read each time the subroutine is called. I'm trying to adjust it calling the subroutine in several places of the program, but it's not enough good to have a steady sprite control performance.
Any advice regards keyboard/sprite control, or it's just about to detect good places in the program to call the keyboard subroutine?

Thanks and regards
Reply
#2
Couple of ideas.

If your main loop is fairly short, you could have it call a keyscan routing and update a global variable as to what it found - and then reference this variable each time, rather than scanning each time.

If it's not short, or doesn't do scanning often enough, then you could do what sinclair did - have an interrupt routing that scans the keyboard 50 times a second and updates a variable with the result.

If you are running with standard ROM and interrupts on, you can of course always read the last keypress from the system variables. I did that with Berksman, so the last direction you chose is the one you move when you get to the corner. Even if you don't get there for a couple of seconds - press up, and let go of the keys, and you'll still turn upwards. Lastkey is a system variable described in the sinclair manual.
Reply
#3
Thanks again britlion. Main loop is kind short (six subroutines are called only) so then I'll start to work with the keyscan. I'm working on a clone of Tetris Attack/Puzzle League and so far the main game it's working but I'm still trying to speed up things equally, because right now the blocks detection and keyboard reading are mutually exclusive (the better the block detection is, the worse is the keyboard reading, and the other way around)

I'm attaching the source code so you can compile it and check what I'm trying to achieve. Keys are the usual Q-A-O-P-SPACE

Cheers


Attached Files
.zip   o-puzzattack_v005.zip (Size: 4.68 KB / Downloads: 454)
Reply
#4
britlion Wrote:If you are running with standard ROM and interrupts on, you can of course always read the last keypress from the system variables. I did that with Berksman, so the last direction you chose is the one you move when you get to the corner. Even if you don't get there for a couple of seconds - press up, and let go of the keys, and you'll still turn upwards. Lastkey is a system variable described in the sinclair manual.

That's did the trick. Well, that and reorganizing when and how much times subroutines are called. I'm leaving a beta attached to this post: Q-A-O-P-SPACE use LAST K system variable and SInclair II (6-7-8-9-0) use MultiKeys, so both keyscan methods can be compared.

Cheers


Attached Files
.tap   o-puzzattack_v007.tap (Size: 11.59 KB / Downloads: 55)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)