Authors
Publication
Pub Details
Date
Pages
The following utility really should be in the EXTRA MEMORY section, because it is so useful be able to MOVE a BASIC program to a specific STARTING MEMORY ADDRESS. It is a take off from the “MOVE” utilities issue of UP-DATE given in the January issue of UP-DATE. But, we are discussing the use of SYSTEM VARIABLES, and this utility does a good job of demonstrating the use of system variables PROG, and VARS. PROG, of course, is the starting address of the first byte of the first line of the BASIC PROGRAM. VARS is the starting address of the first byte of the variables area. To get a good mind’s picture of these two system refer to page 254, left block. The Basic program normally is arranged so that it’s first byte starts at address 26710. Then PROG is 26710. The Variables area (VARS) is ever moving as the basic program Is added to by line numbers or changes of programming within the lines.
So, the system variable VARS is a very important tool. We can use it to find out the “LAST BYTE” of a BASIC PROGRAM. Since VARS begins with the “next byte after” the basic program ends, then all we have to do is to subtract “1” from VARS (when we find VARS). Now look at page 263 and about 1/3 down we see that address 23627, and it Is a 2 byte variable. So ‹PRINT PEEK 23627 + 256 * PEEK 23628> will return the memory address where the variables area starts. Then subtract 1 and that will be the TOP address of the BASIC program. Next, we look on page 263 and find that PROG is given as a 2 byte variable starting at address 23635. Then will return the address of the the Basic program. STARTING byte of the Basic program. Subtract the product of the two formulas and you have the TOTAL Number of BYTES of the Basic Program.
It is useful to be able to re-arrange the Memory Map of the computer when you want to. One need is to place a Basic program at the “starting address of a chunk of memory” when we want to MOVE the program Into the dock bank. A good discussion on this subject is in the EXTRA MEMORY section of the January issue. Another useful purpose is to place the Basic program UP in memory to make space for machine code utilities “under the basic program”. This would be useful if operating a program in the dock bank, because there would be about 4K of wasted space down there when PROG is moved to Chunk 3. But sometimes the rationale is more complex than the act of doing it, so let us get to the action. Since the program Itself is a shortie, I’ll make notes at the side. I’!! call the program “mov” in a REM line so you’ll know what I’m referring to.
Works AS IS with All Disk and Cassette Systems
- Line 10 PEEKS SYS VAR PROG and assigns the address to var a.
- Line 20 PEEKS the SYS VAR VARS and subtracts 1 to get the last byte address of the basic program.
- Line 30 assigns the address of the last byte of ram to var c.
- Line 40 waits for your decision.
- Line 50 will be explained by steps.
- First an Input is requested for the START Address where you want to move the program. Your input address is assigned to the var pg.
- Next, var a3 is assigned “pg-a” which is the total bytes of the move- UP In memory. The number assigned to a3 will next be broken into the two numbers to use as POKE addresses for a “two byte” number storage.
- Next var a2 will be the “poke number for the high address”. Var al will be the number to poke to the low address.
- Next is the RESTORE to initialize the DATA group later in the same line.
- Next is a counter to place a MC routine in the Print Buffer area. Note that vars a1 (low adr poke) and a2 (high address poke) are placed in the data group. This MC program MOVES PROG up in memory to the address that was INPUT at the beginning of line 50.
- The MC program is a variation of “MOVE PROG” given in the January issue. It can be used repeatedly to step a program up in the memory map. Try inputs of 30000 first, then 35000, 40000, etc. SAVE it to auto run at line 10.
Products
Media
Image Gallery
Source Code
5 REM "mov" Basic & Vars Memory Management
10 INK 7: BORDER 1: PAPER 1: CLEAR : LET a=PEEK 23635+256*PEEK 23636: PRINT "This Basic Program begins at theMemory adr of: "; a
20 LET b=PEEK 23627+256*PEEK 23628: PRINT '"The last byte of this Program isat adr: ";b
30 LET c=b-a: PRINT '"The program length is: ";c
40 PRINT '"To Move the Program UP in MemoryType CONT ENTER": STOP
50 INK 7: BORDER 1: PAPER 1: CLS : INPUT "Input PROG ADR?";pg: LET a3=pg-a: LET a2=INT (a3/256 ): LET a 1=a3-(a2*256): RESTORE 5O: FOR x=23296 TO 23304: READ y: POKE x,y: NEXT x: RANDOMIZE USR 23296: DATA 33,85,104,1,a1,a2,195,187,18
60 CLEAR