How to change the SCNKEY kernel operating mode in Commodore 64

I am trying to implement game controls using kernel routines in Commodore 64.

Below code works with one exception. Each key move is considered a single input. For example: the effect is held at the touch of a button. You had to free and press again for each move. How can I change this behavior? I just want to re-execute the action while the key is pressed.

GETIN = $FFE4 SCNKEY = $FF9F keyScan: jsr SCNKEY ;get key jsr GETIN ;put key in A cmp #65 beq left cmp #68 beq right jmp keyScan 
+6
source share
2 answers

SCNKEY not suitable for games that require several simultaneous key entries. He is stateless and simply returns the "key" that is now pressed, i.e. If two are pressed, he will tell you only one and does not officially give any guarantees as to which one. The best thing you could do is to consider pressing a key until SCNKEY reports that something has not been pressed yet, or that nothing is happening, but there would also be a chance that the second simultaneous keystroke is ignored or replaces the first.

If your program doesnโ€™t correspond to orthodoxy there just by pressing the "the" key, you will have to hit the hardware yourself. Codebase64 offers sample code ; my consolidated version (the CIA is correctly configured, although it is likely to be configured accordingly):

  • write a byte to DC00 that contains 0 for each line that you want to scan at the same time;
  • read the byte from DC01 and check the upper four bits to find out which keys were pressed on the selected lines.

The general procedure is to check each line separately to avoid shadowing - suppose you asked to read lines 4 and 5 at the same time, storing 0s to DC00 in bits 3 and 4, and the result you got back had the upper bit, you don't know whether v or n or both were pressed, only at least one of them.

Look at the very bottom of the same link as above, the table of rows and columns on the English keyboard; they are the result of the physical layout of the keys, so other languages โ€‹โ€‹will change as much as their keyboard. If you are writing a game and you are more interested in the layout of the keys than their characters, you do not need to worry about the language.

+10
source

Yes, C64 does not have a key repeat (for example, this editor, which I am typing right now).

A typical way to solve this problem is to poll the memory 197, which stores the current keyboard scan code. To try it, run this: 10 printpeek (197): goto10

You can see that the value of 197 changes and actually stores its value. Of course, the key value is not ascii or even petscii, but you can experiment to find the scan code for the keys whose values โ€‹โ€‹you are interested in.

+1
source

Source: https://habr.com/ru/post/1013385/


All Articles