IN command and keyboard scanning - Is this a bug in BASin?

edited July 2011 in Sinclair Basic
Hi Folks,

Still reading Dilwyn Jones book on the Spectrum and I have got to the section on IN and keyboard scanning. I wrote the following wee program to test this out:
100 CLS 
110 PRINT AT 0,0;"IN 63486 (1-5)    =";IN 63486;"  "
120 PRINT AT 1,0;"IN 64510 (Q-T)    =";IN 64510;"  "
130 PRINT AT 2,0;"IN 65022 (A-G)    =";IN 65022;"  "
140 PRINT AT 3,0;"IN 65278 (CAPS-V) =";IN 65278;"  "
150 PRINT AT 4,0;"IN 61438 (6-0)    =";IN 61438;"  "
160 PRINT AT 5,0;"IN 57342 (Y-P)    =";IN 57342;"  "
170 PRINT AT 6,0;"IN 49150 (H-ENTER)=";IN 49150;"  "
180 PRINT AT 7,0;"IN 32766 (B-SPACE)=";IN 32766;"  "
200 GO TO 110

The book states that the IN commands should display 255 unless I press one of the keys on the row they are mapped to. When I run the above in BASin I get 191 displayed.

Is this a problem with BASin or is the book wrong?

Many thanks

Paddy
Post edited by Paddy Coleman on

Comments

  • edited July 2011
    The value can be either 191 or 255. Neither the book or BASin are wrong. Just an idiosyncrasy of the speccy. To know more, consult the CSS FAQ.
  • edited July 2011
    Excellent, thanks Arjun. What a great document.

    Paddy
  • edited July 2011
    The top 3 bits should be masked off ( AND 00011111b ) and they do not provide anything meaningful. After doing so, no keys pressed will result in 00011111b = 31d = 0x1F and for every key you press (in the half row you have sampled) one of the bits will go to zero.

    This little program I threw together shows the affect of multiple key presses. Spectrum emulators show different behaviour compared to a real spectrum when certain keys combination of three or more are pressed simultaneously.

    Keyboard Scanner (tzx)
    Keyboard Scanner (z80)
  • edited July 2011
    If you are coding games, which just need a handful of keys to work, you can explicitly do the two compares (assumming 111 or 000 for the topmost bits) using an OR in your IF. It saves time.

    As for the other matter, PC keyboards were initially designed to type, not to play games. How many and which keys can be pressed together varies from keyboard to keyboard and from keyboard handler to keyboard handler. There's really nothing an emulator coder can do about it.

    There's a cheat in Phantomas 2 which takes you to the last stage if you press the whole two first rows of keys (1-0 and Q-P) which can't be achieved on a PC emulator due to keyboard restrictions.
  • edited July 2011
    na_th_an wrote: »
    There's a cheat in Phantomas 2 which takes you to the last stage if you press the whole two first rows of keys (1-0 and Q-P) which can't be achieved on a PC emulator due to keyboard restrictions.

    and due to the ZX Spectrum keyboard bug this can be reached by pressing just 12 keys. An example:
    press 1-5 and Q and 6-0 and P or any key on the second row per port will do.
  • edited July 2011
    That makes sense :D Never thought of it!
Sign In or Register to comment.