Classic Computer Magazine Archive COMPUTE! ISSUE 48 / MAY 1984 / PAGE 147

VIC/64 Memdata

Michael M. Milligan

"Memdata" converts a machine language routine into DATA statements and then erases itself, allowing you to save the DATA to disk or tape for later use.

Transferring a machine language routine into DATA statements involves a lot of work. To simplify the job, "Memdata" takes memory bytes between two addresses, inclusively, and returns DATA statements complete with BASIC line numbers. Once the program has generated those statements, it automatically erases itself, leaving only the DATA—as you will see by typing LIST after the program is run.

The first part of Memdata is a modified version of Jim Wilcox's "Automatic Line Numbers" (COMPUTER!'s First Book of VIC). The line numbers are the decimal value for the address of the first byte in each line. This serves as a marker to be sure that every location is accounted for. Also, because many machine language subroutines are located at the top of RAM, it makes the data line numbers high enough to be appended to an existing BASIC program. The appending can be done with the Datassette or disk files, thus eliminating a lot of typing.

Once you save the DATA statements you have created, enter NEW and PRINT PEEK (43), PEEK(44). Write down these two numbers. LOAD the program to which you wish to append the DATA. Next, enter POKE 43, PEEK(45)-2:POKE 44,PEEK(46). Then, LOAD the DATA statements right in there with the first program. When it is loaded, POKE 43 and 44 with the numbers you wrote down after the earlier PEEK(43) and PEEK(44). This will merge the two programs if the DATA statement line numbers are higher than the highest line numbers in the original program.

Memdata erases itself in a novel way. Because line numbers used in Memdata are so high, the DATA statements will be the first lines in the BASIC program area. After the DATA statements are created, Memdata searches memory for DATA (token 131) following a line number. When it finds something besides a DATA token, it POKEs zeros into the high and low bytes of the link address for that line. These two zeros, plus the zero byte that Signals end-of-line, make up the three zero bytes that convince the LIST and SAVE functions that the end of the BASIC program has been reached. Because of this, it's important to save the program before you run it for the first time.

Memdata

Refer to the "Automatic Proofreader" article before typing this program in.

63720 PRINT"{CLR}[<21 I>]" : PRINT"{RVS}TO {SPACE}CONVERT MEMORY TO {OFF}" :rem 159
63723 PRINT"{RVS}DATA STATEMENTS ENTER {0FF}" : PRINT" [<21 U>]" : rem 61
63730 PRINT"INCLUSIVE DECIMAL" : PRINT"MEMORY LOCATIONS" : PRINT : INPUT"FROM";A :rem 138
63733 PRINT : INPUT"TO"C : PRINT : INPUT"BYTES PER LINE";B : rem 170
63735 C = C/256 : POKE251,(C - INT(C)) * 256 : POKE 252, C : rem 60
63740 POKE2, B : PRINT"{CLR}" : rem 172
63750 B = A/256 : POKE253, (B - INT(B)) * 256 : POKE 254, B : rein 55
63755 PRINT : PRINTMID$(STR$(A), 2, LEN(STR$(A))-1);"DATA" : rem 247
63760 FORI = 0TOPEEK(2)-1 : rem 76
63763 A$ = STRS(PEEK(A + I)) + "," : rem 223
63765 IFA + I>PEEK(251) + 256 * PEEK(252)GOTO63 780 : rem 221
63768 PRINTMID$(A$, 2, LEN(A$) - l);   : rem 7
63770 IFA + I = PEEK(251) + 256 * PEEK(252)GOTO63 830 : rem 212
63775 NEXTI : GOTO63830 : rem 11
63780 PRINT"{LEFT} " : GOTO 63870  : rem 241
63830 PRINT"{LEFT} " : POKE631 + PEEK(198), 13 : rem 72
63840 PRINT"GO63850" : FORA = 631 TO634 : POKEA, 145 : NEXT : POKEA, 13 : POKE636, 13 : POKE19 8, 6 : rem 147
63841 END : rem 221
63850 PRINT"{2 UP}" : FORA = 1TO3 : PRINT" {8 SPACES}" : NEXT : PRINT"{3 UP}" : rem 28
63860 A = PEEK(253) + 256 * PEEK(254) + PEEK(2) : GOTO63750 : rem 227
63870 Q = PEEK(43) : U = PEEK(44) : rem 29
63880 IFPEEK(Q + 4 + 256 * U)<>131GOTO63900 : rem 79
63890 Q1 = PEEK(Q + 256 * U) : U1 = PEEK(Q + 1 + 256 * U) : Q = Q1 : U = U1 : GOTO63880 : rem 86
63900 P = Q + 256 * U : POKEP, 0 : POKEP + l, 0 : rem 173
63910 PRINT"{CLR}[<21 I>]" : rem 177
63920 PRINT"{RVS}TYPE LIST TO SEE DATA {OFF}" : rem 145
63930 PRINT"[<21 U>]" : rem 238