80 READ ft, B, C, D, E, F, G, H, I, J, K, L, M, N, 0, P 90 REftD ft*,B*, C*, D*

100 F0RX=lT012sft<X)=X5MEXT

110 DftTft 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 120 DftTft "THIS IS ft*","THIS IS B*","THIS IS C*","THIS IS 130 POKEC&HF000), PEEK«'.&H40F9) s POKE( &HF001), PEEK(&H40FR) 140 POKE(&HF002),PEEK(&H40FB):POKE(&HF003),PEEK C&H40FC) 150 POKE < &HF004),PEEK C&H40FD):POKE C&HF005),PEEK <&H40FE) 160 LOGO"TESTB",R

10 REM *** THIS IS "TESTB" *** 20 POKE (. &H40F9) , PEEK C &HF000) : POKE C&H40FA) 30 POKE (. &H40FB ) , PEEK C &HF002) s POKE < &H40FC) 40 POKE <&H40FD),PEEK C &HF004):POKE C&H40FE) 50 PRINTft, B, C, D, E, F, G, H, I, J, K, L, M, N, 0, P 60 PRINT«*, B*,C*,D* 70 F0RX=lT012s PRINTft(X), :NEXT 80 L0ftD"TESTft",R

PEEK C&HF001> PEEK (. &HF003) PEEK (. &HF005)

could pass variables from one program to another.

Programs "TESTA" and "TESTB" demonstrate how this can be done. Lines 80 through 120 of "TESTA" assign values to various variables. Lines 130 through 150 POKE the contents of the pointers into high memory and line 160 loads and runs "TESTB". Of course, in Level II it will be necessary to change all hexidecimal numbers to decimal, line 160 should read "CLOAD 'TESTB'", and the RUN command must be entered.

The first thing that "TESTB" does is PEEK into high memory and POKE the saved values located there back into the pointers. This is done in lines 2,0 through 40. Lines 50 through 70 then print the values that were assigned to the variables in "TESTA". Line 80then chains back to "TESTA" to start over.

So that's it. It's as easy as 1,2,3. Well at least almost that easy. There are a couple of gotchas.

Look at lines 20 through 40 of "TESTA". These lines are not necessary if the first program is longer than the second program. However this is not always the case.

When you run a basic program, the variables are stored on top of the program (check your memory map). It is easy to see that if your second program is longer than the first, it will over-write the area where the variables are stored.

Lines 20 through 40 of "TESTA" are used to initialize your own area for storing the variables. You simply chose some area in memory that is above your longest program and POKE that location into the pointers. By using these lines at the beginning of your first program, you guarantee that your variables will not be over-written by other programs.

Now the other gotcha. And there's no easy answer to this one.

String variables that are defined within the program are stored within the program. For example, in "TESTA" the strings are defined by a DATA statement in line 120. Wherever line 120 is stored in RAM is where the string variables are stored. If the next program uses the same space that line 120 uses, then the string values will be lost. Two ways to avoid this would be to either define the strings in a DATA statement at the end of the longest program, or else define them with INPUT statements.

Well, that's it. It might be a little tricky at first, but once you get use to it, it should make programming a whole lot easier. ^


0 0

Post a comment