Jump to content

How can I get out of an INPUT loop in Basic?


saldegracia
 Share

Recommended Posts

Hi guys, thanks so much for putting this project together. I stumbled across it only a few days ago and have already had so much fun working through a C64 handbook I found on the web with the emulator. I never had one when I was a kid (started out a little later with the Amiga), so finally I can try out all the cool things I saw some of my friends doing back then 🙂

So,  I've been playing with some Basic programs and there's one thing I have not been able to figure out: How can I get out of an INPUT loop without resetting the computer and losing what's in the memory? Seems like on the C64 you had to press STOP + RESTORE but that function is not available on the X16 emulator. CTRL - C or ESC don't do it on my PC keyboard either. What do I need to do on the X16?

Any help will be much appreciated!

Lars

Link to comment
Share on other sites

Hi,

Glad to hear you've found the community and are enjoying the fun!  

 You can find the input command documented here - https://www.c64-wiki.com/wiki/INPUT

   Here's a simple example that demonstrates exiting a loop programatically.

10 CLS
20 A$=""
30 INPUT "ENTER SOME TEXT"; A$
40 IF A$ ="" THEN 70
50 PRINT "YOU TYPED " A$
60 GOTO 20
70 ? "PROGRAM END"
99 END

A feature in the X16 basic is the OLD command - which restores the last program typed in memory after a reset. That should help you if you are forced to reset the computer and works in the online emulator https://www.commanderx16.com/emulator/x16emu.html or a local one.

It appears that the ESC or Ctrl-c combinations does not exit the INPUT functions as you've discovered - https://github.com/commanderx16/x16-emulator/blob/master/README.md#functions-while-running. I don't have a real C64 to test if it works on a physical device; my VIC-20s are currently in storage. 😞

Hopefully this is the info you are looking for. If not please ask - I and others are willing to help.

 

 

 

  • Like 1
Link to comment
Share on other sites

Thanks, Edmond! That's all useful information. I was just hoping there would be some kind of key combination to do the trick but I guess I'll just make sure to include and end option in the program for now, that pretty much solves the issue. The OLD function is also very good to know!

Link to comment
Share on other sites

  • Super Administrators
On 1/3/2022 at 6:18 AM, saldegracia said:

Hi guys, thanks so much for putting this project together. I stumbled across it only a few days ago and have already had so much fun working through a C64 handbook I found on the web with the emulator. I never had one when I was a kid (started out a little later with the Amiga), so finally I can try out all the cool things I saw some of my friends doing back then 🙂

So,  I've been playing with some Basic programs and there's one thing I have not been able to figure out: How can I get out of an INPUT loop without resetting the computer and losing what's in the memory? Seems like on the C64 you had to press STOP + RESTORE but that function is not available on the X16 emulator. CTRL - C or ESC don't do it on my PC keyboard either. What do I need to do on the X16?

Any help will be much appreciated!

Lars

This is a "feature" in the BASIC interpreter. As you said, you need to press STOP+RESTORE on a CBM computer. What's happening internally is that the RESTORE key is wired to the CPU's NMI line (Non-maskable interrupt.) The Commodore responds to an NMI by running a special piece of software that checks for the STOP key being held down. If the key is not held down, the OS resumes. If it is being held down, the computer enters a warm boot state. 

The problem is that the Commander X16 emulator does not have an NMI button, and even if it did, the KERNAL can't check for the STOP key in the same way as a CBM. I believe that the CX16 board will have an NMI button, and that button *should* be wired up in software to act like STOP+RESTORE on a Commodore 64. 

For now... make sure to save before running your program, and make use of OLD if you need to do a reset during an INPUT statement. 

 

image.png

  • Like 1
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.

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.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use