Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: how can we read the whole keymap simultaneously on Amos?  (Read 4721 times)

0 Members and 1 Guest are viewing this topic.

nitrofurano

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
  • Generic Amiga User
    • website
how can we read the whole keymap simultaneously on Amos?
« on: March 10, 2014, 08:49:57 PM »

hi!
i'm struggling a lot on how can we read several simultaneous keys on Amos
the idea is being able to develop games like this: http://nitrofurano.altervista.org/retrocoding/zxspectrum/misc/bacaball.html (is a game that i submitted to csscgc (zx-spectrum) contest years ago: http://www.mojontwins.com/csscgc2011/nitrofurano-bacaball/ ) - on that game, 4 players uses 1 keyboard (guess how fun can be this?)
so, i wanted to do similar thing on Amos! how easy/possible will be this?
(btw, i were trying to get useful information from webpages like http://mamedev.org/source/src/mess/machine/amigakbd.c.html , but i really can't get any clue from it... :S )
« Last Edit: March 10, 2014, 08:53:51 PM by nitrofurano »
Logged

bruceuncle

  • AMOS Dev
  • A500
  • *****
  • Karma: 6
  • Offline Offline
  • Gender: Male
  • Posts: 425
  • WINUAE Amiga User
Re: how can we read the whole keymap simultaneously on Amos?
« Reply #1 on: March 12, 2014, 02:53:16 AM »

Unfortunately, the AMOS =Inkey$ function only reads whatever key was pressed last.  Which is no good for your purposes.

What you need is the =Key State(Scancode) function.  That checks an individual key to see if it was pressed.  It also, thankfully, handles the multiple-keys-pressed-together situation.  But you need to check each key involved.  You also need to know the Scancode for the keys involved.

If your program is the traditional game loop format:

  • Check the inputs.
  • Action the inputs.
  • Wait for the next vertical blank.

you would do this checking in the "Check the inputs." section.

This sample code just checks for the [J], [K] and [L] keys.  The Chr$(7) character in the Print line just clears to end of line.

Code: [Select]
Default
Locate 0,2
Print "Press [Esc] to exit."
Do
   Locate 0,5
   K$=""
   If Key State($26) Then K$=K$+"J"
   If Key State($27) Then K$=K$+"K"
   If Key State($28) Then K$=K$+"L"
   Print K$;Chr$(7);
   '  Scancode $45 is the [Esc] key!
   If Key State($45) Then Exit
   Wait Vbl
Loop
Edit


When you have determined the Scancodes for the keys you want to use (see the last page of the attached PDF file extracted from the Amiga System Programmers Guide) you would then check each key individually in your code.  In my example, I just add them to the variable K$ and print the result.  For a game, you would be best to check all the keys first and store the results, maybe in an array.  Then use the results to action each key press.  That ensures that the "action" is as close to real time as possible.

I attached the full description of how the Amiga handles the keyboard because there is an important "gotcha" in handling multiple key presses on an Amiga keyboard.  Read the section on "ghost" keys!  :o  The only way around this is to choose keys that don't conflict as "ghosts".  I haven't worked out how to determine what will "ghost" with what key combination, so you may need a little trial and error  ;) .  Maybe modify the sample code to check out key combinations to see what works.  Also note that the keyboard only buffers up to 10 keys.  So too many people on the keyboard at once may miss a few!   ;D

Hope this helps.
Logged
Repeat after me ...  "The AMOS Pro architecture is complex but it is not complicated."

nitrofurano

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
  • Generic Amiga User
    • website
Re: how can we read the whole keymap simultaneously on Amos?
« Reply #2 on: March 13, 2014, 08:59:57 AM »

it works! thanks! :)
Logged

nitrofurano

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
  • Generic Amiga User
    • website
Re: how can we read the whole keymap simultaneously on Amos?
« Reply #3 on: March 14, 2014, 09:50:45 AM »

i'm trying this code now
Code: [Select]
xed=40:yed=28:plntc=0
Screen Open 0,xed*8,yed*8,64,0 : Curs Off : Flash Off:hide
screen display 0,((368-(xed*8))/2)+88,((288-(yed*8))/2)+29-(plntc*24),,
Load Iff "sprites4pl.ilbm",1 : Screen Hide 1
Screen 0 : Get Palette 1 :
For k=0 To 3
Screen 1 : Get Bob 1+K,k*16,0 To k*16+15,24 : Next k
Screen 0 : Cls 10
x1=100:y1=70
x2=120:y2=70
x3=100:y3=90
x4=120:y4=90
do
  'print Key State($11)
  ee1= (Key State($11)*-1)+(Key State($21)*-2)+(Key State($20)*-4)+(Key State($22)*-8)
  ee2= (Key State($14)*-1)+(Key State($24)*-2)+(Key State($23)*-4)+(Key State($25)*-8)
  ee3= (Key State($17)*-1)+(Key State($27)*-2)+(Key State($26)*-4)+(Key State($28)*-8)
  ee4= (Key State($76)*-1)+(Key State($77)*-2)+(Key State($79)*-4)+(Key State($78)*-8)
  locate 2,3: print ee1;ee2;ee3;ee4;"   "
  Bob 1,X1,Y1,1
  Bob 2,X2,Y2,2
  Bob 3,X3,Y3,3
  Bob 4,X4,Y4,4
  if (ee1 and 1)<>0 : y1=y1-1:end if
  if (ee1 and 2)<>0 : y1=y1+1:end if
  if (ee1 and 4)<>0 : x1=x1-1:end if
  if (ee1 and 8)<>0 : x1=x1+1:end if
  if (ee2 and 1)<>0 : y2=y2-1:end if
  if (ee2 and 2)<>0 : y2=y2+1:end if
  if (ee2 and 4)<>0 : x2=x2-1:end if
  if (ee2 and 8)<>0 : x2=x2+1:end if
  if (ee3 and 1)<>0 : y3=y3-1:end if
  if (ee3 and 2)<>0 : y3=y3+1:end if
  if (ee3 and 4)<>0 : x3=x3-1:end if
  if (ee3 and 8)<>0 : x3=x3+1:end if
  if (ee4 and 1)<>0 : y2=y4-1:end if
  if (ee4 and 2)<>0 : y2=y4+1:end if
  if (ee4 and 4)<>0 : x2=x4-1:end if
  if (ee4 and 8)<>0 : x2=x4+1:end if
  waitvbl
  loop
[code]

the picture i used was sprites4pl.png from  https://drive.google.com/#folders/0B7Iw8X7IB4-ndUlLa2h1YTk2bkk - converted to ilbm/iff
Logged

bruceuncle

  • AMOS Dev
  • A500
  • *****
  • Karma: 6
  • Offline Offline
  • Gender: Male
  • Posts: 425
  • WINUAE Amiga User
Re: how can we read the whole keymap simultaneously on Amos?
« Reply #4 on: March 15, 2014, 01:13:41 AM »

Good to see it's working for you.  I won't have anything to do with a Google account so I can't get the sprite you mention.  You could always attach a ZIP of your program as the sprite bank will be embedded in it...  ;)
Logged
Repeat after me ...  "The AMOS Pro architecture is complex but it is not complicated."

Lonewolf10

  • AMOS Extensions Developer
  • AMOS Dev
  • A2000
  • *****
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 618
    • http://www.aliensrcooluk.com
Re: how can we read the whole keymap simultaneously on Amos?
« Reply #5 on: April 17, 2014, 05:34:39 PM »


Are the End If's really necessary at the end of every If statement??
End If's should be reserved only for code like this:

Code: [Select]
  if (ee1 and 1)<>0
    y1=y1-1
  end if
Logged
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022