SpecBAS problem with manual

Y'know, other stuff, Sinclair related.
Post Reply
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS problem with manual

Post by llewelyn »

Is it possible that my version is corrupted, maybe just a few bytes somewhere? When I downloaded the file it got interrupted by the modem losing signal and then restarted only a minute or two later...

Because that listing I provided still causes the program to lockup and ESC still wont BREAK into it so I have to pull the plug on the program SpecBAS and reload it. The old file still comes up as a listing but as long as I dont RUN it I can erase it and start again.

Since you couldn't duplicate the error it seems to me the only possible answer is a corrupted file somewhere. I won't give up but I must find a foolproof way to stop an endless loop. Last time I had to pull the battery on my laptop because I couldnt escape to Windows either.

I have just nuked my SpecBAS being almost certain its corrupted. Please point me to a source for a new one.

PS:- I just got the version from 2015 that your SpecBAS forum provides. So far, so good!
AND the ESC key works like you said. Therefore a corrupted file it must have been.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS working

Post by llewelyn »

PROG sublander.bas
20 REM PROGRAM LANDER
30 REM set up variables first
40 REM x and y = start position of blob
100 LET x=10: LET y=50
120 PRINT AT x,y;"O"
130 IF x=50 THEN STOP
135 GO SUB 510
500 REM subroutine DESCEND
510 PAUSE 30
520 PRINT AT x,y;" "
530 LET x=x+1
535 GO TO 120
540 RETURN

Hey it all works! Check it out my SpecBAS first module but it all works as meant to. Please note the daring first time use of a subroutine and setting up the variables first. Laugh as much as you like experts, this for me is a major hooray. Now I have to figure out how to do the Left/Right control options and its that which caused me problems before and the manual info about INPUT is a bit scant so thats why I'm doing it one module at a time to see what works best and then hopefully I can MERGE or if necessary type it all in finally as one long listing.
ASH-II
Drutt
Posts: 11
Joined: Sun Jun 16, 2019 11:48 am

Re: SpecBAS problem with manual

Post by ASH-II »

20 REM PROGRAM LANDER
30 REM set up variables first
40 REM x and y = start position of blob
100 LET x=10: LET y=50
120 PRINT AT x,y;SCALE 4,4;"O"
130 IF x=50 THEN STOP
135 GO SUB 510
500 REM subroutine DESCEND
510 WAIT 300
520 PRINT AT x,y;SCALE 4,4;" "
525 IF KEYST KEY_LEFT THEN DEC y,1
526 IF KEYST KEY_RIGHT THEN INC y,1
530 LET x=x+1
535 GO TO 120
540 RETURN

changed the two prints by adding scale (bigger) :)
changed lines 510 pause will cancel with a key press wait wont
added lines 525 and 526 you can use the left and right key of you pc and incrementing or decrementing Y by 1

ps LINE 535 is not needed as the return will jump back to line 135 I would change line 535 to line 140 GOTO 120
you are just adding to the stack (and after about 4 days you will run out of memory :)
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS problem with manual

Post by llewelyn »

Thanks o faithful SpecBAS fan - is it just you and me? Paul's post at Wos made it sound like that!

I will try out your suggestion and see how it goes but why such a big WAIT? I thought PAUSE 30 was almost too long but I'll see what happens when I run it. Is there a way to cut and paste? I know you can't do that from SpecBAS you have to save the program and load it into Notepad, well, I guess the reverse is true then. I'll try that.

TRIED IT! Wow! Thanks ASH2. That's very cool, I like that, much more elegant than my approach.
I assume DEC=DECREMENT (-) and INC=INCREMENT (+) those are new commands to me. So is the KEYSTROKE command. Anyway its a good tutorial!
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS problem with manual

Post by ZXDunny »

llewelyn wrote: Mon Aug 19, 2019 6:59 pm Thanks o faithful SpecBAS fan - is it just you and me? Paul's post at Wos made it sound like that!
The problem with the "lock up" is that you're running three threads here:

1. The main window thread which handles the general upkeep of the window (also called a "VCL" thread) - this is the one that waits for keystrokes and mouse movements.

2. The Interpreter thread - this runs constantly executing your code

3. The graphics thread - this prepares what you have done on the screen for display.

The graphics thread can be ignored for this particular instance. What is happening is that the interpreter thread is completely taking over your CPU - so the first (VCL) thread cannot get to the keyboard messages that are coming through from Windows. When you WAIT, the interpreter thread goes to sleep for the specified time and the VCL thread gets to chomp through any waiting messages. Without it, the interpreter never sleeps and so doesn't let anyone else do anything.

This is advantageous in that you can run BASIC very, very fast. But when it comes to either listen to the user or present information to the user, you should let it sleep. This is achieved by the YIELD command (which on its own will simply sleep for 1 millisecond), WAIT n which will sleep for "n" milliseconds, PAUSE n which will sleep for "n" frames or WAIT SCREEN which will wait for the next Vertical Blank (or screen refresh, in english!).

The upshot is that you must force the interpreter to wait in some circumstances or it will just take over the whole system. The Spectrum didn't have this issue because it didn't multi-thread.

I could have the interpreter automatically sleep at set times, but it would drastically slow things down - the smallest resolution you can sleep for in Windows can be as high as 10 milliseconds! And you can't guarantee when it will stop sleeping.

To sum up, if you put a WAIT SCREEN in before you loop around to start again - you'll have no trouble with keystrokes.
I will try out your suggestion and see how it goes but why such a big WAIT? I thought PAUSE 30 was almost too long but I'll see what happens when I run it. Is there a way to cut and paste? I know you can't do that from SpecBAS you have to save the program and load it into Notepad, well, I guess the reverse is true then. I'll try that.
SpecBAS has full clipboard support with CTRL+X for cut, CTRL+C for copy and CTRL+V for paste.
WAIT takes a time in milliseconds, and PAUSE in frames (a frame is roughly 20ms).
TRIED IT! Wow! Thanks ASH2. That's very cool, I like that, much more elegant than my approach.
I assume DEC=DECREMENT (-) and INC=INCREMENT (+) those are new commands to me. So is the KEYSTROKE command. Anyway its a good tutorial!
Yes, INC and DEC are exactly that. the KEYST command is a function - it returns a value. You supply a key to check, and it returns its state (hence KEYSTate) - 1 for pressed, 0 for not pressed. In ASH-II's example he checks the keys KEY_LEFT and KEY_RIGHT which are the left/right cursor keys.

KEY_A is the A key, KEY_B is the B key etc etc.

The line :

525 IF KEYST KEY_LEFT THEN DEC y,1

Is broken down thusly:

1. An IF command. This takes the form IF <expression> THEN <statement>

"expression" must be numeric; that is it must evaluate to a number. If the number is zero, then the IF fails and the statement is ignored. If the number is non-zero then the statement is executed. As you probably already know, the relational operators "=", "<>", "<", ">", "<=" and ">=" work like any other math operators such as "+", "-" etc - they compare both sides of the expression and return a value. for "=" such as "a=b" it will return 0 if a is not equal to b, and 1 if a is equal to b. This is important - you can plug that value (1 or 0) into the IF and treat it like a comparison with

IF a=b THEN...

I hope this all makes sense.

2. The KEYST KEY_LEFT section is the "expression" in the IF command. If the left key is held down, it will return a "1" otherwise it will return "0" - and as with the "a=b" above, we plug that into the IF command.

3. The DEC simply decrements a variable - by 1 if there is no other argument (DEC a) and by n if we have a second argument (DEC a,n).

Hope this is all a bit clearer now.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: SpecBAS problem with manual

Post by ZXDunny »

Give this new one a try:

https://drive.google.com/open?id=0B6gXs ... WhUZ1Rxc0k

It has new binaries that (hopefully!) address the issues you've been having with keystrokes not triggering in tight loops on slow PCs.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: SpecBAS problem with manual

Post by llewelyn »

Thanks Paul. I've downloaded it and will see how it works out a bit later. I'm in the throes of writing at the moment to keep my readership (all 2 of them) happy! I have to mentally change gears to switch projects.
Post Reply