140 Next X
This routine reads the 63 data values and POKEs them into memory. This form of sprite storage requires quite a lot of space. Another less space-consuming method of storage involves writing the sprite data to disk or cassette in a sequential file. By doing this, you can save program memory at the expense of having to read the sprite pattern back from disk or cassette.
When first creating a sprite definition file, we still need the DATA statements. With the help of the following program, the individual values can be read from the DATA statements and placed on the disk as a sequential file:
10 OPEN 1,8,2,"SPRITE, S, W" : OPEN FILE FOR WRITING
30 READ DT : REM READ 63 DATA
40 PRINTtl, CHR$(DT) : REM WRITE TO DISKETTE
50 NEXT X : REM (ASCII FORMAT)
60 CLOSE 1 : REM CLOSE FILE
The name of the file in this example is "SPRITE". The fol lowing program will read these data in again and POKB them directly into the appropriate memory locations:
20 OPEN 1,8,2,"SPRITE,S,R" : REM OPEN SEQ. FILE FOR READING 30 FOR X=0 TO 62
40 INPUT#1, DT$ : REM READ DATA (ASCII FORMAT) 50 POKE AD+X, ASC(DT$+CHR$(0)) : REM AND POKE 60 NEXT X
70 CLOSE 1 : REM CLOSE FILE
It is also possible to save a sprite as a program file and read it back in the same manner.
As you can see, this whole thing is rather complicated. Following is a program which simplifies working with sprites. This sprite editor, written partly in BASIC and partly in machine language, makes it easy to create a highresolution sprite that you may use in your own programs. The sprite editor creates program files which can be read in the same way as demonstrated in the last routine, if you first replace line 20 with the following line:
20 OPEN 1,8,2,"SPRITE,P,R" : REM OPEN PROGRAM FILE FOR READING
Although the program is quite lengthy, it is also very useful. After typing it in, but before you execute it, be sure to save it because it alters various BASIC pointers.
180 GOSUB2730:REM READ MACHINE LANGUAGE ROUTINES
190 POKE 53280,0:POKE 53281,0:REM BACKGROUND/BORDER COLOR
200 POKE650,255:REM REPEAT ALL CHARACTERS
210 POKE 45,0:POKE 46,80:RUN 220:REM BASIC END=$5000
Post a comment