By Don Williams
One of the minor deficiencies in Apple Integer BASIC is the omission of the Data statement. In search of a remedy for this, I wrote a program to save memory in a BASIC string assignment. This is listed as program lines 1020 through 1190.
Upon embarking on the first routine, I quickly found a second omission in the language; a way to store a non-string variable into a string, the remedy for which is shown as program lines 1250 through 1300. Finally, in the interest of completeness, a third routine, given as lines 1200 to 1240, stores the data back into memory.
Running the program that saves memory is fairly straightforward, and is self-prompting. The data to be saved is displayed on the screen, and after the prompt returns, just press the cursor right and repeat keys until you pass the end of the generated statement(s}, then hit return. That one is now a part of your Basic program; repeat the procedure for subsequent lines.
Wherever logically in your program you want the same data loaded back into Memory, place a call to the first line generated by the program, and a return after the last one generated. After storing the program, if memory space is at a premium, just delete those lines.
The second routine, (lines 1250-1300), locates any predefined variable in memory, and can readily be interfaced with a tape read /write run-time where data needs to move from program to program. (See Apple ][ Reference Manual, pages 34-43)
I have been able to use this program to locate variables for use in an Integer BASIC floating point routine, a very fast floating point which will be published in the June issue.
The program listing for Save Memory is included below:
1020 REM SAVE MEMORY ON A STRING BY DON WILLIAMS, APRIL 1978
1030 DIM S$(255), V$(10)
1040 PRINT “ENTER STARTING ADDRESS, ENDING ADDRESS AND LINE NUMBER”
1050 INPUT IST, IND,STMT
1060 CALL-936: PRINT “ENTER LINES BELOW INTO PROGRAM”
1070 PRINT ” “;STMT;” L= “;IST
1080 V$=”S$=”: GOSUB 1260:SL=L
1090 POKE SL,162
1100 K=1:FOR I=IST TO IND:N=PEEK(I):M=N/16:N=N-16*M
1110 IF M>9 THEN M=M+7:M=M+176
1120 IF N>9 THEN N=N+7:N=N+176
1130 POKE SL+K, M: POKE SL+K+1,N
1140 K=K+2: IF K<100 THEN 1170
1150 GOSUB 1190
1160 K=1
1170 NEXT I
1180 IF K#1 THEN GOSUB 1190: VTAB 1:TAB 1:END
1190 POKE SL+K,162: POKE SL+K+1,0: STMT=STMT+10:PRINT ” “;STMT;” S$= “;S$;”: GOSUB 120:RETURN
1200 REM SUBROUTINE TO STORE THE HEX DATA IN STRING S$ INTO MEMORY AT LOCATION L
1210 FOR I=1 TO LEN (S$) STEP 2
1220 J=ASC(S$(I))-176: IF J>9 THEN J=J-7
1230 K=ASC(S$(I+1))-176: IF K>9 THEN K=K-7
1240 POKE L,J*16+K:L=L+1:NEXT I RETURN
1250 REM SUBROUTINE TO FIND STARTING ADDRESS FOR VARIABLE WHOSE NAME IS IN V$. L=ADDRESS OR -1 IF UNDEFINED
1260 L=PEEK(74)+PEEK(75)*256-1:K=LEN(V$)-1:J=PEEK(204)+PEEK(205)+256-1
1270 FOR I=1 TO K: IF ASC(V$(I))#PEEK(L+I) THEN 1290
1280 IF PEEK(L+K+1)>1 THEN 1290:L=L+K+4:RETURN
1290 FOR I=1 TO 100:IF PEEK(I+L)>1 THEN ENXT I:I=L+I+1:L=PEEK(I)+PEEK(I+1)*256-1
1300 IF L<1 THEN 1270:L=L-1:RETURN