shaoth Posted February 12, 2020 Share Posted February 12, 2020 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 ? Quote Link to comment Share on other sites More sharing options...
Rybags Posted February 12, 2020 Share Posted February 12, 2020 Like normal Basic - POKE 764,255 before the music loop. Inside the loop, play your music/sound. Have the end of loop condition test the key. IF PEEK(764)<>12 THEN ... 1 Quote Link to comment Share on other sites More sharing options...
shaoth Posted February 13, 2020 Author Share Posted February 13, 2020 I would hope to be able to continue using the INPUT function... But you are right, I will do like this. Thanks. Quote Link to comment Share on other sites More sharing options...
thorfdbg Posted February 13, 2020 Share Posted February 13, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
shaoth Posted February 13, 2020 Author Share Posted February 13, 2020 I will write a function to transform the KeyCode to Atascii Code according this table : https://www.atariarchives.org/c3ba/kcindex.php Quote Link to comment Share on other sites More sharing options...
dmsc Posted February 14, 2020 Share Posted February 14, 2020 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! 2 Quote Link to comment Share on other sites More sharing options...
shaoth Posted February 14, 2020 Author Share Posted February 14, 2020 Thank you very much for your sample code ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.