How to use STOP key as PAUSE in MSX BASIC?

By ray2day

Champion (489)

ray2day's picture

28-06-2020, 19:38

Hello,

Maybe the answer is already here somewhere, but I can seem to find it. So I am sorry if this one is a double thread;

How to detect STOP key pressed / use it as PAUSE function (activating a pause-routine, like for example the sleeping sprite in Knightmare) in MSX BASIC?

Login or register to post comments

By Thom

Hero (617)

Thom's picture

28-06-2020, 19:54

POKE &HFBB1,1

By ray2day

Champion (489)

ray2day's picture

28-06-2020, 20:11

I don't get it.. Don't know how to use this poke. Can you give me an example of the poke used in a example program/gosub routine? Thx in advance!

By ray2day

Champion (489)

ray2day's picture

28-06-2020, 22:35

Quote:

POKE &HFBB1,1

Better examination tells me this is the 'disable CTRL'-poke, but I don't see a relation to my question about the STOP(/PAUSE) routine.

Can any body help me with an example of MSX BASIC code? (kind of a gosub routine?) - Thx in advance!

By djh1697

Paragon (1457)

djh1697's picture

28-06-2020, 22:43

if you press CTRL+STOP as far as i remember.....
10 on stop gosub 1000
20 stop on
30 rest of program

999 end
1000 what ever you want to do when CTRL STOP is pressed
1010 return

I don't recall that you can use CTRL STOP to return you to the program, but you could wait for the space key to be pressed, which will return you to your program

Always save your program before running it, otherwise you find your self in a loop you cannot get out of!

By ericb59

Paladin (957)

ericb59's picture

29-06-2020, 08:54

Hello,

I don't think you can recover the state of the STOP key from Basic, because pressing this key pauses the basic program which is supposed to detect the state of the key !

Otherwise, in theory you can read line 7 of the keyboard matrix, with : A = PEEK (&HFBEC)
Each bit of A corresponds to the state of a key.
0: Key pressed
1: Key not pressed

bit:  7      6     5       4        3       2     1     0
      RET   SEL   BS      STOP    TAB     ESC    F5     F4

By pgimeno

Master (169)

pgimeno's picture

29-06-2020, 14:43

I've tried the POKE &HFBB1,1 that Thom said, and it works. It disables the pausing of BASIC, letting you read it with the method that ericb59 said. It has the unfortunate side effect of also disabling CTRL+STOP.

Example:

10 POKE &HFBB1,1:CB%=&H10
20 LB%=CB%:CB%=PEEK(&HFBEC)AND&H10:IF CB%=0 AND LB% THEN GOSUB 5000
30 PRINT "Running...";
40 IF INKEY$=CHR$(27) THEN POKE &HFBB1,0:END 'Exit with ESC
50 GOTO 20
5000 PRINT "Stopped...";
5010 LB%=CB%:CB%=PEEK(&HFBEC)AND&H10:IF CB%=0 AND LB% THEN RETURN
5020 GOTO 5000

(edited to remove the release key waits)

By JohnHassink

Ambassador (5451)

JohnHassink's picture

29-06-2020, 16:10

djh1697 wrote:

Always save your program before running it, otherwise you find your self in a loop you cannot get out of!

Big Boss wrote:

The nightmares? They never go away, Snake.

By ray2day

Champion (489)

ray2day's picture

29-06-2020, 19:38

Ah great pgimeno!
Your routine based up Thom and ericb's contribution works indeed. It works perfect!

I am sorry I ask myself;
Is this wise to use in my program? Are there no other hick-ups -we didn't thought about- using this routine? Will it give no other problems? On the other hand, the code is clear. And it works. What do you think?

By pgimeno

Master (169)

pgimeno's picture

29-06-2020, 23:34

ray2day wrote:

Is this wise to use in my program? Are there no other hick-ups -we didn't thought about- using this routine? Will it give no other problems? On the other hand, the code is clear. And it works. What do you think?

Well, it's always possible to have unforeseen problems. For example I forgot to add a check for ESC to the pause subroutine, meaning you can't quit while paused; however, if you had pressed ESC during the pause, the key was buffered and will trigger an immediate exit when you unpause.

But if it's something you really want for your program, as long as you're aware that you can't use CTRL+STOP, I'd say go for it.

I'm thinking, the pause routine could maybe check if CTRL was pressed on entry, and stop in that case. That might let you press CTRL+STOP during development.

By ray2day

Champion (489)

ray2day's picture

30-06-2020, 10:45

Thanks for your response again. I have implemented it in the code and it works perfect! I already built in the ‘ESC during the pause’ myself to have an ESCape there, eventually it will be removed out of the code. Probably you will see the result in the near future. Smile