Hi Carl,
Thanks for the feedback and the video :-)
How does the key input work on FIGnition PONG, why no dup ... if ... then?
The FIGnition keypad uses 6 signals to read 8 keys. The limitation is that it can't properly see every combination of more than 2 keys - and for a two player PONG game you need to handle up to 4 key presses (in case they both momentarily press up & down at the same time).
So PONG must read the keypad directly. This is done by defining sysvars 11 + const joy
And later reading it using joy ic@ which reads the raw, debounced keypad state from internal AVR memory. It's possible to read up to 4 buttons at the same time if they're all on different columns, so I picked SW1 and SW6 for the left player, and SW4 and SW7 for the right player. That way all the keys are on different columns and player keys are as far apart as I can make it. But note also, the up keys are both on the top row and the down keys are on the bottom row.
So bat handling is done using 2 commands: bats and mvBat. When we call bats we read the keypad (an 8-bit value) and supply it along with a mask (e.g. $21) along with a player's bat y variable address to mvBat.
MvBat ands its key input with the mask. So, if you take the FIGgypad keypad state and and with $21, only 1 bit will be set on the upper nybble (if SW6 is pressed) and/or 1 bit on the lower nybble (if SW1 is pressed).
MvBat then takes the mask value and compares each nybble. The 15 > test results in -1 if SW6 is pressed (or 0 otherwise). Since SW6 is for moving the bat down, which increments the y-coordinate the result is negated. The 16<test results in -1 if SW1 is presssed (or 0 otherwise), which is the correct value to add to the y coordinate to move the bat up. Simply by adding these two test results together gives the correct change to the bat's y coordinate.
So, deciding whether to move a bat up or down can be done with a pure calculation rather than if's and then's. It works because comparisons return results which are just numbers like any other calculation. The technique was very popular with BASIC games in the 80s because IF THEN and GOTO were much slower than doing it by calculation. Typically we'd do things like LET key=CODE INKEY$: LET y=y+(key=10)-(key=11). In Sinclair BASIC comparisons returned 1 for true and 0 for false (in Microsoft, commodore and BBC BASIC it was -1 for true).
Does this help?
-cheers julz
--
You received this message because you are subscribed to the Google Groups "FIGnition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fignition+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.