GoSub within a GoSub (Lang "qb")

General FreeBASIC programming questions.
Post Reply
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

GoSub within a GoSub (Lang "qb")

Post by bcohio2001 »

Have an old book containing BASIC code.
Trying to preserve the essence of the code.

The program prints the line "Press any key to continue.". The cursor blinks once or twice and then fails. Does not print the "TEST PRINT!!!!"
Freebasic 1.05 (64 bit)

Code: Select all

#Lang "qb"

'Source code has line numbers, so any reference "GoSub 3760" will be "GoSub L3760"
'Yes, I know that line numbers are supported ...
'All comments with a '*' are mine, author's is regular

'* the "KEY OFF" command is no longer used/needed.
Cls ':KEY OFF
Locate 10,1 : X$="The Journey of Marco Polo, 1271" : GoSub L3760
Locate 13,1 : X$="(c) David H. Ahl, 1986" : GoSub L3760
Locate 14,1 : X$="Adapted by bcohio2001, 2017" : GoSub L3760 '* My credit line on screen
Locate 23,1 : GoSub L3720 : Cls
Dim EP(20)
Dim MO$(6) '* Not in source. QBasic, I think, automaticly Dimmed arrays at 10.
JL=300 : C=2 : W=30 : M=5 : FP=5 : BSK=99 'Initial quanities
GoSub L360 : GoSub L3560 'Display scenario
'* old way
'While RN > 32767 : RN -= 65535 : Wend : Randomize RN
Randomize Timer

Sleep
End

L360:
X$="The Journey of Marco Polo, 1271" : GoSub L3760 : Print : Print
Print "     Starting from Venice in 1271 you travel by sailing ship to the"
Print "port of Armenia.  Upon arrival, you prepare for a 6000 mile trek to"
Print "the court of the Great Kublai Khan in Shag-tu, Cathay.  Having set"
Print "aside"; JL; " precious jewels to finance your planned 3 year trip, you"
Print "must barter for the following supplies in Armenia."
Print " * Camels (Sturdier animals will cost more. You will probably"
Print "           want 8 to 10 camels to carry your many supplies.)"
Print " * Food (You must barter for food as you travel along.  However,"
Print "         prices tend to be lower in port cities, so you should pack"
Print "         in a good supply at the start."
Print " * Oil for lamps and cooking (Over much of the trip you will be"
Print "        able to use wood to build fires. However, in the Persian,"
Print "        Lop, and Gobi deserts you will need oil.)"
Print
Print "     From Venice you have also packed clothing, weapons (crossbows),"
Print "and medicines (balms and unguents); however, your provisions will be"
Print "depleted as you go along and you must replenish them. The selection"
Print "and price of supplies is quite different in various regions, so you"
Print "must barter wisely. As a merchant, you are not skilled in fishing"
Print "or hunting, although occasionally you might be able to to try to get"
Print "some food in this way."
GoSub L3720 : Print : Return

L3560:
'read events
For I = 1 To 14 : Read A : EPT += A : EP(I) = EPT : Next I
Data 6, 4, 4, 6, 6, 6, 6, 4, 4, 1, 6, 8, 18, 10 'totals 89
For I = 1 To 6 : Read MO$(I) : Next I : Return
Data "March", "May", "July", "September", "November", "January"

L3720:
'hit any key
X$="Press any key to continue." : GoSub L3760
Print "TEST PRINT!!!!"
'While Len(InKey$) = 0 : RN += 1 : Wend : Return
While InKey$ = "" : RN += 1 : Wend : Return

L3760:
'print centered line
'* Source had 70 - ....
Print Tab((80 - Len(X$))\2); X$; : Return
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: GoSub within a GoSub (Lang "qb")

Post by sancho3 »

It worked for me but I think it may be a while loop not allowing the system to breath.
Insert a sleep 1 command in line 61:

Code: Select all

While InKey$ = "" : sleep 1: RN += 1 : Wend : Return

I think RN in that line is going to be a problem as it will keep increasing very fast. You could remove the entire while loop and just use the sleep command.
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: GoSub within a GoSub (Lang "qb")

Post by bcohio2001 »

sancho3 wrote:It worked for me but I think it may be a while loop not allowing the system to breath.
Insert a sleep 1 command in line 61:

Code: Select all

While InKey$ = "" : sleep 1: RN += 1 : Wend : Return

I think RN in that line is going to be a problem as it will keep increasing very fast. You could remove the entire while loop and just use the sleep command.
Thanks for the confirmation that it worked for someone.
As I said, trying to preserve the essence of the code. And also that did not print the test. So never got to the while loop.

Seeing that it did work, dug around in my system and found V1.04 (32 bit). IT WORKED!
So the 64 bit version does not handle GoSub's correctly?????
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: GoSub within a GoSub (Lang "qb")

Post by fxm »

Yes, that works in Win32 (gas and gcc) but crashes in Win64 (versions 1.05 and 1.06): Nested GoSubs (and Returns) unsupported for 64-bit?
Last edited by fxm on Oct 15, 2017 8:47, edited 1 time in total.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: GoSub within a GoSub (Lang "qb")

Post by srvaldez »

fxm wrote:Nested GoSubs (and Returns) unsupported for 64-bit?
it works ok with fb v1.06, on Mac and Linux, have not tried version 1.05
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: GoSub within a GoSub (Lang "qb")

Post by fxm »

Indeed, on a very simple code, the nested "GoSub" crashes (on its "Return" execution) with Win64.
Post Reply