Jump to content
IGNORED

FB : Playing sound while waiting user command key


shaoth

Recommended Posts

Still testing Fast Basic !

This time it is an adventure text game POC.

I would like to play a music or any sound while waiting user typing a command.

For example, I'd like to play the sound of an alarm until the player type the command to stop it, "stop alarm", "turn off alarm"...

with FB, I use INPUT ">"; str$

But I can not execute anything until the player press the Enter key...

So no bip bip bip bip bip as alarm...

Is there a way to pass trought this little problem with FB ?

 

Link to comment
Share on other sites

11 hours ago, shaoth said:

I would hope to be able to continue using the INPUT function...

INPUT blocks until the RETURN key is pressed, there is no way around it. You can do two things, however: Either, play sound or music with a short machine language program in the VBI or one of the timer interrupts, or write your own INPUT function that tests for the availability of a keypress before retrieving the key from the operating system.

  • Like 1
Link to comment
Share on other sites

Hi!

2 hours ago, shaoth said:

I will write a function to transform the KeyCode to Atascii Code according this table :

https://www.atariarchives.org/c3ba/kcindex.php

This is a sample code that changes colors while inputting a string. To filter which keys are valid it uses a table of "non ATASCII" keys from your link:

 

data invalidKeys() byte = 67,74,76,77,79,88,89,98,100,101,103,131,152,195,216
readKey = 0

' Print prompt
pos. 0,4 : print "Input? ";
repeat
  pause 0
  exec inkey
  ' Only process "printable" keys
  if readKey > 31 and readKey < 127 and readKey <> 125
   print chr$(readKey);
  endif
  setcolor 2,0,TIME
  ' End on RETURN key
until readKey = 155

setcolor 2,0,4
' Simulate pressing RETURN again
poke 764,12
pos. 6,4: input message$

print "Message was: "; message$
pause 120

' Returns the ATASCII code of any key pressed
' or -1 if no key was pressed.
proc inkey
  ' Initialize result
  readKey = -1
  ' Read keycode to variable
  currentKey = key()
  ' Return if no key was pressed or key is CONTROL+SHIFT
  if currentKey < 64 then exit
  ' Check if the key is invalid
  invalidKey = -1
  do
    ' Go to next position in array, if keycode is
    ' in list, exit
    inc invalidKey
    if currentKey = invalidKeys(invalidKey) then exit
    ' If we are at end of array, just get the key
    if invalidKey = 14
      get readKey
      exit
    endif
  loop
endproc

 

The "proc inkey" probably could be added as a new FastBasic function, "INKEY$"... perhaps in the future!

 

Have Fun!

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...