Author Topic: Passing values between programs  (Read 1016 times)

0 Members and 1 Guest are viewing this topic.

Offline Stephane Richard

  • C64 user
  • *****
  • Posts: 278
  • Location: Upstate NY
  • Activity:
    0%
  • Reputation: 1
  • With us since: 29/09/2006
    YearsYearsYearsYearsYearsYearsYears
    • View Profile
    • http://www.symbioticsoftware.net
Passing values between programs
« on: April 06, 2011, 02:41 AM »
The title says it all :).

program one is the menu.  and let's say the user selects option 3 in the menu. I ask for a file name I store in FN$ for example.   when I execute the program for option 3.  I would like that program to have access to FN$ to know which filename to load.

can this be done and may I have an example? :)

Thank you all. :)
When God created light, so too was born, the first Shadow!

MystikShadows

Offline maraud

  • VIC 20 user
  • ****
  • Posts: 152
  • Activity:
    0.6%
  • Country: 00
  • Reputation: 45
  • With us since: 16/04/2009
    YearsYearsYearsYears
    • View Profile
Re: Passing values between programs
« Reply #1 on: April 06, 2011, 02:55 AM »
While I'm sure there's a very snazzy way to do this by parking the value in a memory location not used by the subsequent program - I'm all about simple.   I'd just save the values I want from PRG1 to a SEQ file and then read that data back in on the next program.  Slow yes, but easy too.
Cheers!  -=Maraud=-
Be sure to "call" maraud.dynalias.com (port 6400)
AABBS 128 12.5c, Rear Admiral Hyperdrive (AKA LtK II)

Offline Stephane Richard

  • C64 user
  • *****
  • Posts: 278
  • Location: Upstate NY
  • Activity:
    0%
  • Reputation: 1
  • With us since: 29/09/2006
    YearsYearsYearsYearsYearsYearsYears
    • View Profile
    • http://www.symbioticsoftware.net
Re: Passing values between programs
« Reply #2 on: April 06, 2011, 09:58 AM »
I was thinking about doing that yes.  I just wanted to know if there was perhaps an easier way to do it. because the information would be a filename and possible a few other values, it would be heck to story in memory locations.  I won't mind doing the SEQ file if I have to.  it's slow but it would  be at a point where it would be expected to stop for a little bit too.  but let's see if there's a quick and easy trick. :)

thank you for answering :)
When God created light, so too was born, the first Shadow!

MystikShadows

Offline maraud

  • VIC 20 user
  • ****
  • Posts: 152
  • Activity:
    0.6%
  • Country: 00
  • Reputation: 45
  • With us since: 16/04/2009
    YearsYearsYearsYears
    • View Profile
Re: Passing values between programs
« Reply #3 on: April 07, 2011, 03:44 AM »
I would probably use a REL file instead and not close the file handle for it on PRG1, so it's still open and ready to go when PRG2 goes.  REL is pretty darn fast.
Cheers!  -=Maraud=-
Be sure to "call" maraud.dynalias.com (port 6400)
AABBS 128 12.5c, Rear Admiral Hyperdrive (AKA LtK II)

Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1214
  • Age: 41
  • Location: Earth... still!
  • Activity:
    0%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: Passing values between programs
« Reply #4 on: April 07, 2011, 04:19 AM »
We are talking about the C128 right?  In that case, all you have to do is nothing... I hope that is simple enough!
 
Example PRG1

10 INPUT"FILENAME";N$
20 DLOAD"PRG2"

 
Example PRG2

10 PRINT"YOU MUST WANT ";N$

 
Of course variables are cleared whenever you use RUN or CLR commands, so don't do that... notice PRG1 uses DLOAD command and not the RUN command.
I'm kupo for kupo nuts!

Offline Stephane Richard

  • C64 user
  • *****
  • Posts: 278
  • Location: Upstate NY
  • Activity:
    0%
  • Reputation: 1
  • With us since: 29/09/2006
    YearsYearsYearsYearsYearsYearsYears
    • View Profile
    • http://www.symbioticsoftware.net
Re: Passing values between programs
« Reply #5 on: April 07, 2011, 04:33 AM »
LOL Hydrophilic.  I put my 36 years in computing behind it, and I can't make it simpler than your "nothing" solution. LOL  thank you for that answer.  cause I would have probably had fun with the run command and bring down all the saints from the sky. :)
When God created light, so too was born, the first Shadow!

MystikShadows

Offline BigDumbDinosaur

  • C128 user
  • ******
  • Posts: 757
  • Age: 67
  • Location: Midwest USA
  • Activity:
    0%
  • Country: us
  • Reputation: 64
  • Gender: Male
  • Yuh think donkeys are dumb, try a politician!
  • With us since: 02/01/1970
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
    • View Profile
    • BCS Technology Limited
Re: Passing values between programs
« Reply #6 on: April 07, 2011, 09:48 AM »
We are talking about the C128 right?  In that case, all you have to do is nothing... I hope that is simple enough!
Example PRG1
10 INPUT"FILENAME";N$
20 DLOAD"PRG2"
Example PRG2
10 PRINT"YOU MUST WANT ";N$
Of course variables are cleared whenever you use RUN or CLR commands, so don't do that... notice PRG1 uses DLOAD command and not the RUN command.
In the minicomputer world, this technique is referred to as program chaining.  Variables and open files are preserved across programs.  Chaining was devised early on to get around memory limitations in the minis of the 1970s (the first version of the DEC PDP-11 had only 8K available per user) and is still comon practice on modern systems, even though RAM limitations have been largely effaced.  You can also use LOAD "program",D if you wish to load from device D.  Same effect.

Program chaining is a good practice in an application with many features.  Rather than writing a huge monolithic program that does everything that is offered, you can logically separate tasks into individual programs that will be smaller and load faster.  Something else you should do to speed up things is to use a "loader" program to declare all variables that will be used in all programs, and then have the loader run the first (main) menu program.  This will cost a little extra execution time at startup but will greatly speed up variable usage later on.  Also, declare numeric variables and arrays prior to declaring string variables.  If the numerics are declared after the strings, all of the string descriptors have to be shifted to make room for the numerics.
x86?  We don't got no x86.  We don't NEED no stinking x86!

Offline wte

  • C64 user
  • *****
  • Posts: 342
  • Location: Frankfurt
  • Activity:
    0%
  • Country: de
  • Reputation: 10
  • Gender: Male
  • With us since: 18/03/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • http://blog.c128.net
Re: Passing values between programs
« Reply #7 on: April 12, 2011, 08:34 AM »
Quote
this technique is referred to as program chaining
I's also known as "overlay programing". It works for all commodore machines but for the older one's the first program has to be the biggest one (because of the integrity of the variables). The C128 does not have this limitation (thanks to bank 1) - it is the better computer 

Regards WTE

Offline BigDumbDinosaur

  • C128 user
  • ******
  • Posts: 757
  • Age: 67
  • Location: Midwest USA
  • Activity:
    0%
  • Country: us
  • Reputation: 64
  • Gender: Male
  • Yuh think donkeys are dumb, try a politician!
  • With us since: 02/01/1970
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
    • View Profile
    • BCS Technology Limited
Re: Passing values between programs
« Reply #8 on: April 12, 2011, 02:35 PM »
Quote
this technique is referred to as program chaining

I's also known as "overlay programing".

Not true.  In computer science, chaining refers to the sequential execution of programs without disturbing the environment in any way.  All timesharing BASICs support this feature, allowing any number of programs of arbitrary size to execute in any order without variables being cleared or files being closed.  Each program inherits the environment of the previous one, which means if one program creates some variables or opens some files, those new variables and open files will be accessible in the next program, and so forth.  Of all the Commodore 8 bit machines, only the C-128 is capable of doing such a thing.  However, in timesharing systems that support chaining, the statement to run the next program is RUN, not LOADLOAD is only used to copy BASIC text into program space for editing.

Overlaying overwrites the execution environment, which is what happens if you use RUN on the 128 instead of DLOAD or LOAD.

On the 64, LOAD"FILENAME",8,1 will preserve variables and open files, as you pointed out, but only if the first program run is the largest of all of them, since the start of variable descriptors is right above the end of the BASIC text.  However, the fact that the end of text dictates the start of variables means you are constrained in creating new variables, since start of variables was defined by the first program, not the current one.  Also, if you are using a lot of strings, garbage collection will come early and often.  However, you still are chaining, not overlaying, as the environment (in theory) remains intact from program to program.  You just can't run any programs larger than the first in the chain.

An alternative on the 64 is to twiddle the zero page locations that define the start of variables to some artificially high location in RAM, which will allow succeeding programs to be larger than the first one (within reason).  Of course, "real programmers" would do this in assembly language and work out how to protect memory regions from being stepped on by different size programs.  :)  After all, Commodore's BASIC is much too slow for serious work.  That and the math functions leave a bit to be desired in accuracy.
x86?  We don't got no x86.  We don't NEED no stinking x86!

Offline wte

  • C64 user
  • *****
  • Posts: 342
  • Location: Frankfurt
  • Activity:
    0%
  • Country: de
  • Reputation: 10
  • Gender: Male
  • With us since: 18/03/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • http://blog.c128.net
Re: Passing values between programs
« Reply #9 on: August 04, 2011, 05:45 AM »
1. for overlay / chaining the command on the c64 is
Code: [Select]
LOAD"FILENAME",8That
Code: [Select]
LOAD"FILENAME",8,1 works too, is a (horrible) bug or a special feature (that depends on).

2. I don't know who defined the differences between
"overlay" and "chaining" but I'm familiar with "overlay" as the correct term for this programming technique since more than 30 years (but that must mean nothing). I also have a basic compiler (BASIC 128) who is asking for overlay files ... (but that must mean nothing, too).

Regards WTE

PS: yes BASIC is slow, but if it is too slow, compile it and/or set it under fire (with a SuperCPU)
;)
« Last Edit: August 04, 2011, 05:49 AM by wte »

Offline RCtech

  • VIC 20 user
  • ****
  • Posts: 101
  • Age: 37
  • Activity:
    5.6%
  • Country: de
  • Reputation: 2
  • With us since: 26/03/2008
    YearsYearsYearsYearsYears
    • View Profile
Re: Passing values between programs
« Reply #10 on: August 04, 2011, 06:19 AM »
Isn't 'overlaying' a method where certain parts of program code are overwritten by another, while other parts are kept? A real overlay does GEOS using the VLIR file format, but it does heavy use of disk access to save data. The MSSIAH sequencer cardrigde also uses overlaying, it works even while playing a stereo SID tune. The new program parts (Sequencer, MIDI editor, SID settings) are loaded from cardridge, and it takes several seconds every time. So real overlay in Basic...? Should this work...?

At least on the C64 a BASIC program is started with the first line after loading an file with absolute address, but it keeps the variable conents. So on a C64 the a loading routine should start like this:

10 A=A+1:IF A=1 THEN LOAD"FILE",PEEK(186),1
20 go on...

I'm using PEEK(186) instead of a fixed number because this address that stores the actual drive number, both in C64 and C128 mode. So a program could be loaded from another device and it still works.

Offline wte

  • C64 user
  • *****
  • Posts: 342
  • Location: Frankfurt
  • Activity:
    0%
  • Country: de
  • Reputation: 10
  • Gender: Male
  • With us since: 18/03/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • http://blog.c128.net
Re: Passing values between programs
« Reply #11 on: August 08, 2011, 07:04 AM »
The "overlay" in BASIC is always a "full" overlay = replacement. You only can use the same variables. I use this technique in my C128 MySoft programs. The start program loads all necessary data and initializes all variables and constants. That fills BANK 1. Then it starts the "real" program. That saves me 20 Kb of memory in BANK 0.

At least on the C64 a BASIC program is started with the first line after loading an file with absolute address
That's what I call a bug. And your code is needed to overcome the consequences. Who wants to restart the BASIC program after loading a fontfile or some ML?

Regards WTE

 



Back to top