Apple IIc RAM Disk Mover
Christopher J. Flynn
Last month, Part 1 of this two-part series demonstrated the RAM disk and subdirectory options with ProDOS and the Apple IIc. This month's article presents a utility program which rapidly copies a number of programs from a floppy disk to the RAM disk, greatly speeding up the preparations required for using the RAM disk.
The discussion in Part 1 was a bit on the theoretical side, but this month we tackle the practical side. "RAM Disk Mover" is a program which automates the processes described in Part 1. It adds a few little twists, however. Here is how RAM Disk Mover works:
- First it looks for the PROGRAMS subdirectory on your floppy disk. If PROGRAMS is not found, RAM Disk Mover instructs you to insert another disk.
- Next, it looks in the RAM drive for the PROGRAMS subdirectory. If PROGRAMS is not found, RAM Disk Mover creates the subdirectory. If PROGRAMS is found, it deletes all of the files in PROGRAMS. This makes room for the new programs.
- RAM Disk Mover goes back to the floppy PROGRAMS subdirectory. Then it saves the name and length (in blocks) of each BASIC program. It stops when there are no more BASIC programs or when the number of blocks exceeds the capacity of the RAM drive (118 blocks, considering the directories).
- Using this list of BASIC programs, RAM Disk Mover builds an EXEC file containing a series of LOAD and SAVE commands. The EXEC file is named TEMP.EXEC and is stored in the volume directory of the floppy with which RAM Disk Mover is currently working.
- RAM Disk Mover adds a RUN command as the last line of the EXEC file. The program specified by the variable P1$ will start automatically when the copy operation is finished. Right now, P1$ is set up for STARTUP.RAM. You can change this to whatever program name you want.
- After building the EXEC file, RAM Disk Mover clears the screen and informs you that all is well. Then the EXEC file starts up. At this point, programs are actually moved from floppy disk to RAM disk. Your startup program will run and you'll be in business.
Preparing The Mover
RAM Disk Mover requires little, if any, of your attention while it runs. Your biggest job is to organize your disks so that Mover can access them properly.
Here are some guidelines for trouble-free operation;
Format some disks so you'll always have some spares handy. Use whatever volume labels suit you.
As you format the disks, be sure to establish the PROGRAM and DATA subdirectories.
Place a copy of Mover in the volume directory of each disk. Mover does not require much space.
Place all of the BASIC programs you want Mover to copy in the PROGRAMS subdirectory. Don't forget that the RAM disk has a limit of about 61K or 120 blocks. If you think you will exceed this limit, place some of the programs on a second disk.
Putting It To Work
Now for the actual operation. It's simple:
- Always make sure your IIc is turned on, that ProDOS is ready, and that you're in Applesoft.
- Place your program disk in the internal disk drive.
- Type either RUN MOVER or -MOVER. RAM Disk Mover will take over from there. It tells you the name of each program it is copying, then starts the EXEC file. As the EXEC file runs, you will see a series of open brackets displayed. This means all is well.
- When the EXEC file is done, the STARTUP.RAM program will begin running if it is present.
- At this point, you can remove your floppy disk from the disk drive. You can insert a data disk and have the entire 140K free for data storage.
RAM Disk Mover has done its job. The BASIC programs have been moved over to the RAM disk. Now, how do you get to the programs?
If you want to run a program, you can type:
Perhaps typing all this seems a bit tedious. You can use the PREFIX command:
Now whenever you want to run a program, you can just type RUN followed by the program name. /RAM/PROGRAMS/ is automatically appended to the front of the name.
A caution is in order, however. Suppose that your program performs some file operations. If the input/output statements do not include a full path name, the prefix will also be applied to your data file commands. This will cause your program to try to read or write to the RAM disk—probably not what you intended. Remember this when using the PREFIX command.
You can also use the usual LOAD and SAVE commands, of course. But this time a warning is in order. Yes, you can recall a program from the RAM disk, work on it, test the revisions, and store it back in the RAM disk. Just don't forget it's only a RAM disk. If the power goes kaplooey, then your program goes kaplooey along with it. If you make important changes to a program, save the new version on a real live disk. The RAM disk is best for programs you just want to run.
On occasion things can go wrong—especially where computers are concerned. Here are a few gotchas. Watch out for them.
- RAM Disk Mover is designed for an Apple IIc and ProDOS. It uses the 80-column display capability of the IIc. If the display looks funny, make sure your computer is in the 80-column mode.
- Mover attempts to use all of the available RAM drive space. It will clean up /RAM/PROGRAMS, but it is not aware of anything else that you may have in the RAM drive. If you run out of room, ProDOS will tell you about it loudly and clearly.
- There can be problems writing the EXEC file. Do not remove your program disk until RAM Disk Mover is finished with it. Do not write-protect it, either. Finally, leave a few blocks free for Mover's use. That EXEC file has to go somewhere.
Programs can run other programs. If the programs are in the RAM disk, switching from program to program is almost instantaneous. Here's an example:
10 REM PROGRAM1 20 D$=CHR$(4) 30 PRINT "PROGRAM 1 IS RUNNING" 40 PRINT D$;"-RAM/PROGRAMS/PROGRAM2" 10 REM PROGRAM2 20 D$=CHR$(4) 30 PRINT "PROGRAM 2 IS RUNNING" 40 PRINT D$;"-RAM/PROGRAMS/PROGRAM1"
How about that! Keep this technique in mind when you are writing that huge program that eats all the available program space. The way out is to think small and think RAM drive. ProDOS even has a CHAIN statement that permits variables to be passed between programs.
If you would like to learn more about ProDOS, find a copy of Apple's BASIC Programming with ProDOS. It covers all the ProDOS features available from Applesoft BASIC.
Apple IIc RAM Disk Mover
100 REM MOVE /…/PROGRAMS TO / RAM/PROGRAMS (MOVER) 110 REM 120 PF$ = "/RAM/PROGRAMS/" 130 PI$ = "STARTUP.RAM" 140 RB = 118: REM /RAM BLOCKS AVAILABLE 150 MP = 50: REM MAX PROGRAMS 160 DIM PN$(MP) 170 HOME :D$ = CHR$ (4): PRINT D$;"PR#3" 180 GOSUB 330: REM TITLE 190 GOTO 400: REM OPEN DIRECTOR Y 200 GOTO 650: REM CREATE /RAM DIRECTORY 210 GOSUB 860: REM MOVE PROGRAMS 220 REM 230 REM THE EXEC PROGRAM WILL MOVE THE PROGRAMS 240 REM 250 HOME 260 VTAB 12: HTAB 1: PRINT "Running the EXEC copy program… " 270 FOR I = 1 TO 1000: NEXT 280 PRINT D$;"EXEC ";FL$ 290 HOME 300 VTAB 12: HTAB 1: PRINT "Programs are being copied to:";PF$ 310 FOR I = 1 TO 1000: NEXT 320 END 330 REM PROGRAM TITLE 340 UL$ " ": FOR I = 1 TO 80:UL$ = UL$ + "__": NEXT 350 TL$ = "DISK TO /RAM PROGRAM MOVER" 360 HOME : VTAB 1: HTAB 1: PRINT UL$ 370 VTAB 3: HTAB (80 - LEN (TL$)) / 2: PRINT TL$ 380 VTAB 4: HTAB 1: PRINT UL$ 390 RETURN 400 REM OPEN /…/PROGRAMS DIRECTORY 410 GOSUB 590: REM GET VOLUME LABEL 420 DR$ = VL$ + "PROGRAMS/" 430 VTAB 6: HTAB 1: PRINT "Moving programs from " ; DR$ 440 ONERR GOTO 480 450 PRINT D$;"OPEN"; DR$;", TDIR" 460 POKE 216, 0: REM NORMAL ERR 470 GOTO 200 480 POKE 216, 0: REM NORMAL ERR 490 CALL - 3288: REM FIX STACK 500 VTAB 8: HTAB 1: PRINT "The directory '/PROGRAMS/' is not on the diskette ";VL$ 510 VTAB 10: HTAB 1: PRINT "Insert the proper diskette." 520 VTAB 12: HTAB 1: PRINT "Press SPACE to continue. Press RETURN to stop." 530 GET C$: IF C$ < > " " AND C$ < > CHR$ (13) THEN 530 540 FOR I = 6 TO 12 STEP 2 550 VTAB I: HTAB 1: PRINT SPC(79); CHR$ (13) 560 NEXT 570 IF C$ = CHR$ (13) THEN STOP 580 GOTO 400 590 REM GET VOLUME LABEL 600 PRINT D$;"PREFIX /" 610 PRINT D$;"PREFIX" 620 INPUT VL$ 630 PRINT D$ 640 RETURN 650 REM CREATE /RAM/PROGRAMS/ 660 VTAB 8: HTAB 1: PRINT "Moving programs to ";PF$ 670 ONERR GOTO 820 680 PRINT D$;"OPEN "; PF$;",TDIR 690 PRINTD$;"READ ";PF$ 700 INPUT LI$ 710 INPUT L2$ 720 INPUT L3$ 730 INPUT L4$: IF L4$ = "" THEN 770 740 T$ = MID$ (L4$, 2, 15) 750 NP = NP + 1:PN$(NP) = T$ 760 GOTO 730 770 PRINT D$;"CLOSE ";PF$ 780 FOR I = 1 TO NP 790 PRINT D$;"DELETE ";PF$;PN$(I) 800 NEXT 810 GOTO 210 820 POKE 216,0: REM DIRECTORY NOT PRESENT 830 CALL - 3288: REM FIX STACK 840 PRINT D$;"CREATE ";PF$ 850 GOTO 210 860 REM MOVE PROGRAMS 870 NP = 0: REM NUMBER OF PROGRAMS 880 BC = 0: REM BLOCK COUNT 890 PRINT D$;"READ ";DR$ 900 INPUT L1$: REM DIRECTORY NAME 910 INPUT L2$: REM TITLE LINE 920 INPUT L3$: REM BLANK LINE 930 INPUT L4$: REM FILE ENTRY 940 IF L4$ = "" THEN 970 950 GOSUB 1000: REM SAVE PGM NAMES 960 GOTO 930 970 PRINT D$;"CLOSE" 980 GOSUB 1160: REM BUILD EXEC FILE 990 RETURN 1000 REM SAVE PGM NAMES 1010 IF MID$ (L4$, 18, 3) < > "BAS" THEN 1150 1020 NP = NP + 1 1030 IF NP > MP THEN 1150 1040 BC = BC + VAL (MID$ (L4$, 23, 6)) 1050 IF BC > RB THEN 1150 1060 T$ = MID$ (L4$, 2, 15) 1070 FOR K = 15 TO 1 STEP - 1 1080 IF MID$ (T$,K, 1) < > " " THEN 1100 1090 NEXT 1100 PN$(NP) = LEFT$ (T$,K) 1110 IF PN$(NP) = P1$ THEN SU = 1 1120 VTAB 10: HTAB 1: PRINT SPC(79); CHR$ (13) 1130 VTAB 10: HTAB 1: PRINT "Copying "$PN$(NP);" …" 1140 FOR K = 1 TO 500: NEXT 1150 RETURN 1160 REM BUILD EXEC FILE 1170 VIAB 10: HTAB 1: PRINT SPC(79)1 CHR$ (13) 1180 VTAB 10: HTAB 1: PRINT "Building EXEC copy program …" 1190 FL$ = "TEMP.EXEC" 1200 PRINT D$;"OPEN ";FL$ 1210 PRINT D$s"CLOSE ";FL$ 1220 PRINT D$;"DELETE ";FL$ 1230 PRINT D$;"OPEN ";FL$ 1240 PRINT D$;"WRITE ";FL$ 1250 FOR I = 1 TO NP 1260 PRINT "LOAD ";VL$;"PROGRAMS/";PN$(I) 1270 PRINT "SAVE ";PF$ PN$(I) 1280 NEXT 1290 IF SU = 1 THEN PRINT "-";PF$;P1$ 1300 PRINT "PRINT:PRINT" 1310 PRINT D$;"CLOSE" 1320 RETURN