Language
Saver
John O. Battle
Here is an easy way to save machine language programs to tape or disk from your VIC-20 or Commodore 64.
You've just written the ultimate character movement routine for your latest video game, and, of course, it's written in machine language for speed. Now you want to save it for future use. (You certainly don't want to type the routine in and debug it again!) But how do you get it onto tape or disk? The BASIC command SAVE works only for programs written in BASIC. You could load in a machine language monitor program and use its SAVE feature, but suppose you don't have a monitor, or that loading the monitor would overwrite the routine you want to save.
Here's the solution. ML Saver is a BASIC program which loads in a short machine language routine of its own. This routine allows you to easily save other machine language programs to tape or disk. And, since it is in machine language itself, it is very fast.
To use the program, simply type in and RUN the BASIC program. Since the numbers in the DATA statement in lines .1000-1300 make up a machine language program, they must be typed in exactly, no errors allowed. The program is selfprompting - simply press the letter T (for save to tape) or D (for disk) when asked. Then enter the beginning address for the save and press RETURN.
The program will next ask for the final address in the block of memory to be saved. If you press RETURN without entering an ending address, the program will ask instead for the total number of bytes you wish to save (beginning with the byte at the starting address). If your final address is not greater than your starting address, you will be asked to enter both addresses again.
Finally, the program will allow you to specify a filename for the saved program. This name can be no more than ten characters long.
In order to LOAD a machine language routine that was put on tape or disk by ML Saver, you use the standard BASIC command LOAD, but you must follow the device number with a comma and a one. For example:
TAPE
LOAD "filename",1,1
DISK LOAD "filename",8,1
DISK LOAD "filename",8,1
The one at the end of the LOAD command tells the computer to load the routine into the same memory locations from which it was saved. Without it, the auto-relocating feature of the VIC and 64 LOAD command would cause the routine to be stored beginning at the normal start-of-BASIC location.
40 POKE 52,29:POKE 56,29: REM USE THIS LI
NE FOR THE VIC-20 ONLY
50 PRINT "{CLEAR}{09 DOWN}{RIGHT}{REV}MAC
HINE LANGUAGE SAVE{REV}"
60 FOR I=7424 TO 7489
70 READ X
80 POKE I,X :NEXT I
90 FOR I=1 TO 3000:NEXT I
100 PRINT"{CLEAR}{10 DOWN}{06 RIGHT}"
110 PRINT "{REV)T(OFF)APE OR {REV}D{OFF}IS
K"
120 GET D$:IF D$="" THEN 120
130 IF D$="T" THEN PRINT"{UP}TAPE SELECTED
":LF=1:DN=1:SA=2
140 IF D$="D" THEN PRINT"{UP}DISK SELECTED
":LF=15:DN=8:SA=15
150 IF D$<>"T" AND D$<>"D" THEN PRINT"{UP)
":GOTO 120
160 POKE 7661,LF
170 POKE 7662,DN
180 POKE 7663,SA
200 PRINT"{DOWN}STARTING ADDRESS FOR":INPU
T"SAVE";S
210 Sl=INT(S/256)
220 S2=S-Sl*256
230 POKE 251,52
240 POKE 252,51
245 A$=""
250 PRINT"{DOWN}FINAL ADDRESS OF":INPUT"SA
VE"; A$
260 IF A$="" THEN 300
270 F=VAL(A$)
280 GOTO 320
300 PRINT "{02 UP}NUMBER OF BYTES TO BE":I
NPUT"SAVED";N
310 F=S+N-1
320 Fl=INT(F/256)
330 F2=F-Fl*256
335 IF F<S THEN PRINT"{07 UP}":GOTO 200
340 POKE 7659,F2
350 POKE 7660,Fl
400 INPUT"{DOWN}PROGRAM NAME";N$
410 NL=LEN(N$)
420 IF NL<10 THEN 460
430 PRINT"{DOWN}NAME TOO LONG"
440 GOTO 400
460 POKE 7648,NL
470 FOR I=1 TO NL
480 POKE 7648+I,ASC(MID$(N$,I,1))
490 NEXT I
500 IF D$="D" THEN PRINT "{DOWN}PRESS ANY
KEY TO SAVE"
505 IF D$="T" THEN PRINT"{DOWN}REWIND TAPE
AND PRESS ANY KEY{DOWN}"
510 GET A$
520 IF A$="" THEN 510
530 SYS 7472
560 END
1000 DATA 169,192,32,144,255,173,237,29,174
,238,29,172,239,29,32,186,255,173
1100 DATA 224,29,162,225,160,29,32,189,255,
96,234,234,234,234
1200 DATA 169,0,32,144,255,96,234,234,234,2
34,234,234,234,234,234,234
1300 DATA 32,0,29,169,251,174,235,29,172,23
6,29,32,216,255,32,32,29,0