Author Topic: Hey developers... RUN!  (Read 3876 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Hey developers... RUN!
« on: February 07, 2020, 07:03:43 pm »
I mean what's up with RUN?

Do you guys remember some of the problems with RUN and CLEAR in QB64?

I had a recent run in with RUN, which I forgot about, and had to fix today. I did so by adding VIEW PRINT and b$ = INKEY$ before the RUN statement. Why? Because in QB64, RUN sometimes does not clear the keyboard buffer, and never resets the VIEW PRINT to the default value. Here is an example of the VIEW PRINT problem but it doesn't demonstrate the keyboard buffer problem. My 1500 line app does, but not this itty-bitty one, oh well..

Code: QB64: [Select]
  1. LOCATE 1, 1: PRINT "Press Enter to continue..."
  2.     _LIMIT 30
  3.     b$ = INKEY$
  4.     IF b$ = CHR$(13) THEN
  5.         PRINT "You pressed a key!"
  6.         EXIT DO
  7.     END IF
  8.  
  9. PRINT "Re-running program in 1-sec..."
  10. _DELAY 1.5: CLS: _DELAY .5
  11. b$ = INKEY$
  12. ' Unremark the line below to fix the RUN issue.
  13.  
  14. trap:
  15. PRINT "Error"; ERR; "Press Backspace to resume...";
  16.     _LIMIT 30
  17.     b$ = INKEY$
  18.     IF b$ = CHR$(8) THEN EXIT DO
  19. LOCATE , 1: PRINT SPACE$(80);
  20. VIEW PRINT ' Just to allow the next run to print to the top again.

Now can anyone remember if QBasic RUN ignored the resetting of VIEW PRINT, too? Maybe it did, in which case this is a compatibility "feature."

Anyway, the WIKI should mention the VIEW PRINT problem.

What the WIKI does reference is this...

Note: RUN causes a stack leak in QB64 if it is called from within a SUB or FUNCTION. Avoid when possible!

Has that been addressed since the WIKI article was published? If not, that's a bummer. I used to exit nested subs to re-run a program but I'm getting lazier with age, so now I due use RUN in my SUBs.

Sorry this code doesn't replicate the keyboard buffer issue, but it is involved too. The fix, again is to just add something to clear the buffer, as simple as nul$ = INKEY$, before executing the RUN command. Again, if not to be fixed, this stuff should be included in the WIKI, when time permits.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Hey developers... RUN!
« Reply #1 on: February 07, 2020, 07:11:26 pm »
Instead of using RUN, I like this 2 command replacement:

SHELL _DONTWAIT “thisprogram”
SYSTEM

Fixes all those issues of yours.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Hey developers... RUN!
« Reply #2 on: February 07, 2020, 07:40:19 pm »
Quote
Has that been addressed since the WIKI article was published? If not, that's a bummer.

No work has been done on RUN recently that I know of.

Instead of using RUN, I like this 2 command replacement

Even better, in case the user renames the exe:
Code: QB64: [Select]

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Hey developers... RUN!
« Reply #3 on: February 07, 2020, 07:45:40 pm »
Well is that the position you developers want to take on this? If so, why not code that SHELL into the RUN command and be done with it in a future release? If it solves the stack problem, assuming there is one, like the WIKI states, that might be the best way to go; but I recall CLEAR has some similar problems that Rob didn't clear up, either. Remember this one?

Code: QB64: [Select]
  1. 101
  2. CALL testsub
  3.  
  4. PRINT "Hello World"
  5. GOTO 101
  6.  
  7. SUB testsub
  8.     STATIC testarray(1 TO 100)
  9.     FOR i = 1 TO 100
  10.         testarray(i) = i
  11.     NEXT

CLEAR does not "clear" the array, so the second loop causes an error.

I mean the SHELL thing, if used, presents a problem while in the developing (build) stages. For instance, right now I'm using untitled(5).exe, but if that gets changed, then I have to remember to change the SHELL call, accordingly. The same problem every time a build is changed myprog1.baas, myprog2.bas, etc. So it's really only viable on the finished product, but if you ever change the name of that program in a utility like Explorer, you're screwed!

Pete

PS I just saw Fell replied while I was typing this. I'll have a look see at: COMMAND$(0). I haven't tried that before. Thanks...
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Hey developers... RUN!
« Reply #4 on: February 07, 2020, 09:26:37 pm »
I never thought of using run within a program.  It was always a thing to do after loading, typing in a program and to restart an interrupted run.

The best theatrical use of "RUN" was in the movie Colossus the Forbin project.  After telling the computer to load a program designed to overload colossus.  He said: "Run".  To which the computer almost broke down.  Came back from almost dead and said: "You fool".  Then ordered a couple of executions.  Thank god QB64 has a potential memory leak and would crash.  I dread the though of being killed for  bad programming.  I have seen some bad programming in my time, they deserved to be hurt someway.  If only for the mental damage I suffered.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Hey developers... RUN!
« Reply #5 on: February 07, 2020, 10:30:09 pm »
I never thought of using run within a program.  It was always a thing to do after loading, typing in a program and to restart an interrupted run.

The best theatrical use of "RUN" was in the movie Colossus the Forbin project.  After telling the computer to load a program designed to overload colossus.  He said: "Run".  To which the computer almost broke down.  Came back from almost dead and said: "You fool".  Then ordered a couple of executions.  Thank god QB64 has a potential memory leak and would crash.  I dread the though of being killed for  bad programming.  I have seen some bad programming in my time, they deserved to be hurt someway.  If only for the mental damage I suffered.

But what if you want to make a repeating Hello program, and you're keyboard is missing the D F, and T keys, so you can't code it with a DO:LOOP,  FOR:NEXT, or GOTO statement? Simple...

PRINT "Hello!"
RUN

:D :D :D

The thing is RUN is a coding tool, and like any other coding tool it should work properly within the coding language. Buggy is not a "feature" unless there's a horse involved. Cool, I managed to trash FreeBASIC in the process!

Back in QBasic days, RUN was the only way you could get giant programs to repeat, due to memory constraints. With QB64, it is more of a shortcut to zeroing all variables, clearing all view ports, closing all files, etc. At my advancing age, I'll take all the shortcuts I can find.

Pete
« Last Edit: February 08, 2020, 03:32:55 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Hey developers... RUN!
« Reply #6 on: February 08, 2020, 03:24:21 pm »
Both VIEW PRINT and the keyboard buffer will be cleared in the upcoming version (I'll be pushing the fix today).

Also, that nasty ERROR 5 that kept being trapped after RUN was called is due to the recent changes to WIDTH to work with the $CONSOLE. I fixed that too (WIDTH is called internally when RUN is called).

Since I got my feet wet already (or my hands dirty, if you will), can you name anything else that needs resetting after RUN is called, Pete?
« Last Edit: February 08, 2020, 04:19:23 pm by FellippeHeitor »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Hey developers... RUN!
« Reply #7 on: February 08, 2020, 04:18:02 pm »
Let's see, for RUN and CLEAR we have so far...

------------------------------------------------------------------------------------------------------------------------------------------------------
STATIC variables and arrays need to be cleared.
VIEW PRINT needs to be restored to default full height.
Keyboard buffer needs to be cleared, including any key pressed after a SLEEP statement to RUN or CLEAR program.
Memory leak needs to be addressed when using either within a sub or function.
LOCATE needs to be restored to DEFAULT values CSRLIN = 1 POS(0) = 1
------------------------------------------------------------------------------------------------------------------------------------------------------

Things I haven't tested or tried before...

MOUSE positions
MOUSE buffer
PALETTE (Probably OK, as COLOR is reset just fine with RUN

------------------------------------------------------------------------------------------------------------------------------------------------------

Things that appear to be reset OK using RUN are...

COLOR
ON ERROR

------------------------------------------------------------------------------------------------------------------------------------------------------

OK, now here's a weird one you guys will need to decide how to tackle, just for continuity sake...

Code: QB64: [Select]
  1. LOCATE 30, 1
  2. COLOR 14, 1
  3. PRINT "OK"
  4.  

On the INITIAL run, QB64 determines, for whatever insane reason, not to use the default 80 x 25 screen, so it can accommodate what should be the out-of-bounds LOCATE statement. In other words, it doesn't throw the suspected error 5. QBasic compatibility maybe? Anyway, I think it should open the default screen and throw the error message. So run the program snippet above and initially it will set up a different screen, with enough rows to handle the LOCATE 30 statement, but when you press a key, it encounters RUN and it not use that increased row screen, meaning it will go back to using the default 80 x 25 one, which will throw an error at the LOCATE statement.

IMPORTANT: Guys, don't mess with CLS! In other words, don't make RUN clear the screen. A neat feature using RUN is to pass a foreground color matching background color character or line off characters, and have them read at the start of the program to seed variable(s). That saves the bother of using a data collection file.

Pete

That's all I can remember at the moment, but if I'm missing anything, it's because I haven't coded with it using RUN or it's been too long to figure out what program I had encountered the problem.

Pete


------------------------------------------------------------------------------------------------------------------------------------------------------



Mouse
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Hey developers... RUN!
« Reply #8 on: February 08, 2020, 04:41:46 pm »
Current state:
- STATIC variables and arrays already get cleared (arrays even get deinitialized).
- VIEW PRINT will be restored. (fixed today)
- Keyboard buffer will be cleared. (fixed today)
- It's not a memory leak, it's a stack issue. To restart the program, QB64 needs to call its MAIN() function in C++ again, so you'd better watch for millions of calls to RUN from within SUBs, as that "issue" remains.
- LOCATE actually gets restored to DEFAULT values in QB64, although it didn't in QuickBASIC 4.5, I just tested.
- Palette does get reset.

There's no talking about restoring mouse positions or buffer as that wasn't something native to QuickBASIC, so it works as it does in QB64 (whatever behaviour you come to notice).

Quote
OK, now here's a weird one you guys will need to decide how to tackle, just for continuity sake...

It has been a design decision to enlarge the screen if the user tries to locate outside boundaries, so that has already been decided on since early versions of QB64. A program from back in the days wouldn't locate outside boundaries and a new program wouldn't want to use RUN (as people in the forums usually recommend not to, see above), so there you have it.

In conclusion, I'm pushing changes :-)
« Last Edit: February 08, 2020, 04:51:59 pm by FellippeHeitor »

FellippeHeitor

  • Guest
Re: Hey developers... RUN!
« Reply #9 on: February 08, 2020, 04:49:12 pm »
New builds available at https://www.qb64.org/portal/development-build/ if you can give it a try.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Hey developers... RUN!
« Reply #10 on: February 08, 2020, 06:11:16 pm »
Current state:
- STATIC variables and arrays already get cleared (arrays even get deinitialized).

It has been a design decision to enlarge the screen if the user tries to locate outside boundaries, so that has already been decided on since early versions of QB64. A program from back in the days wouldn't locate outside boundaries and a new program wouldn't want to use RUN (as people in the forums usually recommend not to, see above), so there you have it.

- STATIC variables and arrays already get cleared (arrays even get deinitialized).

Now I'm confused. This doesn't work in 1.3. Are you saying it was fixed sometime after 1.3, now, or actually wasn't fixed...

Code: QB64: [Select]
  1. testsub
  2.  
  3. PRINT "Hello World"
  4.  
  5. SUB testsub
  6.     STATIC testarray(20)
  7.     FOR i = 1 TO 20
  8.         PRINT i
  9.         testarray(i) = i
  10.     NEXT

In 1.3, it errors out after RUN. Error 9 at line 13.... the STATIC array. YOu can use CLEAR in place of RUN and put it in a LOOP, and it still errors out.

Now for fun, let's MOVE that RUN statement INTO the SUB... You know, that bad programming method. Well in this one case, bad wins because now it works without RUN interfering with the STATIC array...

Code: QB64: [Select]
  1. 101
  2. testsub
  3.  
  4. SUB testsub
  5.     STATIC testarray(20)
  6.     FOR i = 1 TO 20
  7.         testarray(i) = i
  8.         PRINT i, testarray(i)
  9.     NEXT
  10.     SLEEP
  11.     CLS
  12.     _DELAY .5
  13.     RUN
  14.  

Go figure? Well, it makes me glad that the only thing I was responsible for developing were x-rays... and at least they're are pretty black and white. :D I don't envy what you guys have to go through.

------------------------------------

It has been a design decision to enlarge the screen... Well, if that's the way you guys want it to work, all that is needed is a WIKI inclusion to explain it for LOCATE and SCREEN.

I look forward to trying out the new release, soon.

Thanks for improving RUN. Have a look at my comments, and tell me what you think.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Hey developers... RUN!
« Reply #11 on: February 08, 2020, 06:56:33 pm »
Well, if that's the way you guys want it to work,

Nah, it was already like that, by Galleon, when any of us came around I believe.

all that is needed is a WIKI inclusion to explain it for LOCATE and SCREEN.

So much needs attention on our poor wiki... wink wink... https://www.qb64.org/forum/index.php?topic=1539.0 ❤️