Classic Computer Magazine Archive COMPUTE! ISSUE 64 / SEPTEMBER 1985 / PAGE 66

Commodore 64
Memory Manager

Robert Lee

If you find yourself using several BASIC programs repeatedly, here's a way you can load them all into your computer at once, and run them independently. "Memory Manager" keeps track of up to eight programs in your Commodore 64 and lets you switch between them with the special function keys.


The Commodore 64 has 38K of Random Access Memory (RAM) available for BASIC programs. However, unless you're using a very large program, most of that memory is sitting empty, wasted.
    "Memory Manager" is a utility which takes advantage of the left-over memory by using it to store other BASIC programs. It also uses 8K of additional RAM which is hidden beneath the Read Only Memory (ROM). Normally, this ROM prevents you from using the additional RAM, but Memory Manager collects every available byte of RAM (49.5K total) and partitions it into eight sections. You can load, list, run, and save up to eight BASIC programs in your computer with Memory Manager.
    To use Memory Manager, type in and run the accompanying program. It asks you for the maximum amount of memory (in kilobytes) to be reserved for BASIC. The default response printed on the screen for you is 9K; simply press RETURN, or enter another value if you like. You can't change this value later without restarting the computer, so your response defines the maximum size of the BASIC program you can run. If you aren't sure how long your programs are, you can make a close estimate if you have a disk drive. Load a disk directory and note the number of blocks the program consumes on the disk. Since each block equals 256 bytes, four blocks equal one kilobyte. Simply divide the number of blocks by four to estimate the length. (For instance, a program that is 25 blocks long on the directory takes about 6.25K of RAM.) However, keep in mind that some programs require additional RAM when they run.
    After you enter your answer, the cursor reappears and Memory Manager is ready to run. Activate it by typing SYS 53128 and pressing RETURN.

Eight Partitions
Depending on the amount of memory space available, up to eight programs can be handled by Memory Manager. The partitions are accessed by pressing one of the four special function keys. Press fl to access partition 1, f2 for partition 2, and so on. When you flip to a different partition, Memory Manager displays the partition number on the screen.
    For example, try typing or loading a program into the computer. This is partition 1. Type LIST to confirm that it's in memory. Now press one of the function keys-say, f5. When you type LIST again, nothing's there. To fill partition 5, just type or load another program. You can switch from partition to partition as often as you like. (If you press f5 when you're already in partition 5, nothing happens.)
    Memory Manager uses only the space required to store a program, so none is wasted. If there is not enough room to store a certain program, Memory Manager delivers an error message.
    If you wish to deactivate Memory Manager for some reason, type SYS 53144 and press RETURN. Pressing the RUN/ STOP-RESTORE combination also disables Memory Manager. You can turn it on again by entering SYS 53128. All the programs in memory will remain intact-although they may be damaged if you perform other tasks while Memory Manager is deactivated.
    Remember that Memory Manager works only with BASIC programs; machine language programs are almost sure to cause memory conflicts. (The machine language portion of Memory Manager is stored above address 52736, $CE00 hex. It frees up RAM from $0800 to $CDFF minus the memory space assigned to BASIC.) Even with BASIC, keeping the programs from interfering with each other in every instance is practically impossible. BASIC programs with machine language subroutines, custom character sets, or POKEs into memory locations beyond the top of BASIC memory can mess up the programs stored in other partitions.
    Variables set to certain values by a program in one partition will retain those values when you switch to another partition (although they'll be reset when you type RUN). For these reasons, we don't recommend using Memory Manager for critical applications such as software development. Instead, it's more suitable for keeping frequently used programs in memory rather than constantly accessing the cassette or disk drive, or for loading up a series of programs for a young person who cannot handle tapes or disks.


Commodore 64 Memory Manager

For instructions on entering this listing, please refer to "CQMPUTE!'s Guide to Typing In Programs" published bimonthly in COMPUTE!.

10 PRINT"{CLR}{6 DOWN}
   {11 RIGHT}MEMORY MANAGER"
                       :rem 62
20 PRINT"{3 DOWN}{11 RIGHT}
   {3 SPACES}FOR THE ":rem 109
30 PRINT"{3 DOWN}{12 RIGHT}COM
   MODORE 64{2 SPACES}"
                      :rem 210
100 FORX=52736TO53215 :rem 183
110 READA:CK=CK+A:POKEX,A
                       :rem 28
120 NEXT              :rem 210
130 IF CK<>68936 THEN PRINT"
    {RVS}{2 DOWN} ERROR IN DAT
    A STATEMENTS":STOP :rem 50
140 INPUT"{5 DOWN}HOW MANY K F
    OR PROGRAM (6 TO 24)
    {2 RIGHT}9{3 LEFT}";M
                      :rem 141
145 IFM<60RM>25THENPRINT"{CLR}
    NUMBER SHOULD BE FROM 6 TO
     24":GOTO140      :rem 168
150 POKE55,0:POKE56,M*4+8
                      :rem 153
160 FORX=53224TO53231:POKEX,M*
    4+8:POKER+16,M*4+8:NEXT
                      :rem 181
170 FORX=0TO6:POKER+53217,X*3+
    1:POKEX+53233,X*3+4:NEXT
                      :rem 237
180 POKE53214,X*3+1:POKE53215,
    M*4+8             :rem 167
190 FORX=(M*4+8)*256t1TO(M*4+8
    )*256+24:POKEX,0:NEXT
                      :rem 136
200 PRINT"{CLR}{5 DOWN}
    {7 RIGHT}SYS 53128 TO ACTI
    VATE"              :rem 12
210 PRINT"{3 DOWN}{7 RIGHT}SYS
     53144 TO DEACTIVATE"
                      :rem 223
220 PRINT"{3 DOWN}{9 RIGHT}PRO
    GRAM #1 IN USE"   :rem 141
230 PRINT"{4 DOWN}SYS 53128
    {3 UP}"            :rem 95
52736 DATA 169,255,141,180,207
      ,162            :rem 154
52742 DATA 19,189,181,207,32,2
      10               :rem 49
52748 DATA 255,202,16,247,88,7
      6                :rem 17
52754 DATA 49,234,162,255,165,
      157             :rem 113
52760 DATA 240,247,165,203,201
      ,64              :rem 91
52766 DATA 208,5,141,180,207,2
      40               :rem 45
52772 DATA 236,172,180,207,192
      ,64             :rem 106
52778 DATA 208,229,201,3,208,2
                      :rem 204
52784 DATA 162,6,201,4,208,2
                       :rem 98
52790 DATA 162,0,201,5,208,2
                       :rem 90
52796 DATA 162,2,201,6,208,2
                       :rem 99
52802 DATA 162,4,224,255,240,2
      01               :rem 33
52808 DATA 173,141,2,240,1,232
                      :rem 190
52814 DATA 236,221,207,240,190
      ,120            :rem 134
52820 DATA 160,8,132,88,160,0
                      :rem 147
52826 DATA 132,87,173,222,207,
      133              :rem 99
52832 DATA 89,173,223,207,133,
      90               :rem 54
52838 DATA 134,91,162,3,165,90
                      :rem 211
52844 DATA 201,206,240,144,177
      ,87             :rem 101
52850 DATA 145,89,230,87,208,2
                      :rem 213
52856 DATA 230,88,230,89,208,2
                      :rem 215
52862 DATA 230,90,201,0,208,22
      8               :rem 244
52868 DATA 202,208,227,165,1,4
      1               :rem 254
52874 DATA 254,133,1,166 91,18
      9                :;em 12
52880 DATA 240,207,56,253,224,
      207              :rem 98
52886 DATA 133,-87,189,248,207,
      253             :rem 124
52892 DATA 232,207,133,88,172,
      221             :rem 102
52898 DATA 207,173,222,207,153
      ,224            :rem 154
52904 DATA 207,173,223,207,153
      ,232            :rem 142
52910 DATA 207,165,89,153,240,
      207             :rem 101
52916 DATA 165,90,153,248,207,
      160             :rem 105
52922 DATA 7,185,232,207,221,2
      48               :rem 50
52928 DATA 207,144,44,208,8,18
      5                :rem 10
52934 DATA 224,207,221,240,207
      ,144            :rem 139
52940 DATA 34,185,224,207,56,2
      29               :rem 56
52946 DATA 87,153,224,207,185,
      232             :rem 110
52952 DATA 207,229,86,153,232,
      207             :rem 108
52958 DATA 185,240,207,56,229,
      87               :rem 71
52964 DATA 153,240,207,185,248
      ,207            :rem 157
52970 DATA 229,88,153,248,207,
      136             :rem 116
52976 DATA 16,201,189,224,207,
      133             :rem 103
52982 DATA 94,189,232,207,133,
      95               :rem 68
52988 DATA 169,0,133,87,169,8
                      :rem 180
52994 DATA 133,88,189,240,207,
      133             :rem 114
53000 DATA 92,189,248,207,133,
      93               :rem 53
53006 DATA 160,0,177,94,145,87
                      :rem 208
53012 DATA 230,87,208,2,230,88
                      :rem 198
53018 DATA 230,94,208,2,230,95
                      :rem 200
53024 DATA 165,95,197,93,208,2
      34               :rem 62
53030 DATA 165,94,197,92,208,2
      28               :rem 60
53036 DATA 189,224,207,133,87,
      189             :rem 114
53042 DATA 232,207,133,88,177,
      94               :rem 55
53048 DATA 145,87,230,87,208,2
                      :rem 211
53054 DATA 230,88,230,94,208,2
                      :rem 202
53060 DATA 230,95,165,95,197,9
      0                :rem 11
53066 DATA 208,234,165,94,197,
      89               :rem 72
53072 DATA 208,228,172,221,207
      ,185            :rem 147
53078 DATA 240,207,141,222,207
      ,185            :rem 143
53084 DATA 248,207,141,223,207
      ,142            :rem 142
53090 DATA 221,207,165,1,9,1
                       :rem 92
53096 DATA 133,1,173,221,207,2
      4               :rem 244
53102 DATA 105,49,141,209,207,
      162              :rem 87
53108 DATA 19,189,201,207,32,2
      10               :rem 39
53114 DATA 255,202,16,247,169,
      255             :rem 100
53120 DATA 141,180,207,88,76,4
      9                 :rem 3
53126 DATA 234,0,120,169,20,14
      1               :rem 235
53132 DATA 20,3,169,206,141,21
                      :rem 186
53138 DATA 3,88,96,0,0,0
                      :rem 156
53144 DATA 120,169,49,141,20,3
                      :rem 194
53150 DATA 169,234,141,21,3,88
                      :rem 201
53156 DATA 96,0,0,0,0,255
                      :rem 197
53162 DATA 0,255,0,255,0,255
                       :rem 91
53168 DATA 0,255,0,255,64,141
                      :rem 149
53174 DATA 89,82,79,77,69,77
                      :rem 144
53180 DATA 32,72,71,85,79,78
                      :rem 121
53186 DATA 69,32,84,79,78,141
                      :rem 178
53192 DATA 147,141,69,83,85,32
                      :rem 216
53198 DATA 78,73,32,49,35,32
                      :rem 120
53204 DATA 77,65,82,71,79,82
                      :rem 121
53210 DATA 80,141,147,0,21,204
                      :rem 180