home *** CD-ROM | disk | FTP | other *** search
- u THE REST OF THE BIBLE
- By Dave Moorman
-
- OPEN lf,dv,ch(com) Here is how you
- access the disk drive. LF is the
- Logical File number, which you pick.
- You can open more than one file, but
- each must have its own Logical File
- number.
-
- DV is the device number (8 or higher
- for disk drive). CH is the Channel,
- again a unique number for each open
- file (we often just use the LF number,
- unless the OPEN is for a DISK
- COMMAND).
-
- DISK COMMANDS
-
- We can send commands to the disk to
- Scratch a file, Format (New) a disk,
- Rename a file, or Copy a file. Each
- is sent over the Command Channel --
- 15. Here are some examples.
-
- OPEN 1,8,15,"S0:FILE":CLOSE1 This
- will Scratch the file named FILE from
- the disk.
-
- OPEN 1,8,15,"N0:DISK NAME,ID":CLOSE1
- This will format a new disk,
- preparing it to accept data.
-
- OPEN 1,8,15,"N0:NEW NAME":CLOSE1
- NOTE: no ID characters. This will
- wipe a formatted disk clean and give
- it a new name.
-
- OPEN 1,8,15,"C0:NEW FILENAME=OLD
- FILENAME":CLOSE1 This copies the file
- OLD FILENAME to another file called
- NEW FILENAME.
-
- OPEN
- 1,8,15,"R0:NEWNAME=OLDNAME":CLOSE1
- This changes the name of the file
- OLDNAME to NEWNAME.
-
- Channel 15 also lets the disk
- communicate with the computer. Here
- is a trick we use all the time to
- find out whether a certain filename
- is on the disk.
-
- 10 F$ = "FILENAME"
- 20 OPEN 1,8,15,"R0:"+F$+"="+F$
- 30 INPUT#1,EN
- 40 CLOSE1
-
- When this is done, EN will
- contain either 62 or 63. If EN=62
- then the filename is not on the disk.
- If EN=63, the file name IS on the
- disk.
-
- Once the command channel is open, we
- can use PRINT#lf to send further
- commands to the drive. We do this in
- our Scratch and Save routine:
-
- 60000 D=PEEK(186):IFD<8THEND=8
- 60001 OPEN1,D,15,"I0":N$="PROGNAME"
- 60002 PRINT#1,"S0:"+N$:CLOSE1
- 60003 SAVEN$,D:VERIFYN$,D:END
-
- OPEN1,D,15,"IO" (should be "I"
- zero) makes sure the disk drive is
- awake and aware. Then the program
- name is put into N$. Line 60002
- scratches the program name, and
- CLOSEs the logical file. Finally, we
- SAVE N$,D, then VERIFY N$,D to make
- sure we got a good save.
-
- We also use OPEN to open a file for
- reading or writing. Here is code that
- will save three variables to a file,
- followed by the routine to get those
- three variables.
-
- 10 DV=PEEK(186):IFDV<8THENDV=8
- :
- 1000 OPEN
- 1,DV,15,"S0:DATAFILE":CLOSE1
- 1005 OPEN4,DV,4,"DATAFILE,W,S"
- 1010 PRINT#4,A$
- 1011 PRINT#4,B$
- 1012 PRINT#4,C$
- 1013 CLOSE4
- 1014 RETURN
- :
- 2000 OPEN4,DV,4,"DATAFILE,R,S"
- 2001 INPUT#4,A$
- 2002 INPUT#4,B$
- 2003 INPUT#4,C$
- 2004 CLOSE4
- 2005 RETURN
-
- When we OPEN a file, we need to tell
- it the filename, whether we will be
- Writing it or Reading it (W or R),
- and what kind of file it is. We have
- two normal kinds of files: Program
- and Sequential. For short data
- information, use a Sequential file.
-
- So, after scratching the file, we
- open it to Write, Sequential (,W,S).
- Then we use PRINT#lf to print the
- data to the file. The best way is
- shown above, with each variable
- printed separately. We CLOSElf and
- RETURN when finished.
-
- To get the data back into the
- variables, we open the file to Read,
- Sequential. (You can leave off the
- ",R,S" when opening a file to Read.)
- Then we INPUT#lf each variable
- exactly the same order as we did the
- PRINT#lf, CLOSElf, and RETURN to the
- main program.
-
- OPEN is also our way to get data
- to the printer.
-
- 100 OPEN4,4,7
- 110 FOR X = 0 TO 50
- 120 PRINT#4,A$(X)
- 130 NEXT
- 140 CLOSE4
-
- Here we assume that each element of
- the A$ array has one line of text for
- the printer. You will have to
- experiment with your printer on this
- -- and read the manual for special
- characters and effects. At LOADSTAR,
- we assume a 66 line page with 80
- characters to a line -- and don't do
- much that is fancy.
-
- [NICKEL GAMES has a built in function
- to turn a C-64 print-out into a PC
- TXT file. After doing a print-out in
- VICE, press <Alt-Tab>, and click on
- File>Print. In a moment, your
- print-out will be displayed. You can
- copy and past it to a word processor,
- save it as a TXT file, or send it to
- your printer.]
-
- NOTE: Always CLOSE the logical file
- after use. Getting proficient with
- OPEN takes a lot of practice! See
- SECRETS for other stuff about disk
- access.
-
- PEEK(loc) (fun) Returns the contents
- of the memory byte at LOC. We use
- PEEK(186) to discover which disk
- drive device was last used. You will
- use it a lot for advanced tricks.
-
- 10 DV = PEEK(186)
-
- POKE loc,byte Puts BYTE value into
- memory location LOC. Especially
- important for controlling C-64
- features not included in BASIC 2.0.
-
- 10 POKE 53280, 0:POKE 53281, 0 (Turns
- screen border and background black)
-
- POS(0) (fun) Returns the current
- position of the cursor on the screen
- row (0 - 39). I have no idea what
- this would be good for!
-
- PRINT (com) Probably the most
- important and versatile command in
- BASIC 2.0. It puts characters,
- strings, and values on the screen.
-
- End the PRINT with a semicolon to
- keep the cursor from automatically
- dropping down to the first column of
- the next row (called a carriage
- return). Use a comma to move the
- cursor to the next pre-set tab
- location on the line.
-
- Semicolons and commas can separate
- data in a PRINT command. This is a
- command you will have to play with!
-
- READ (com) Reads values or strings in
- DATA statements into variables.
-
- Make sure the number of data items
- in the DATA statements match up with
- what you are expecting! For string
- data, enclose each string in
- double-quote marks.
-
- 100 FOR X=1TO4
- 110 READ A$(X)
- 120 ? A$(X)
- 130 NEXT
- 140 END
- 20000 DATA"DADDY","MOMMY"
- 20001 DATA"JUNIOR","SIS"
-
- REM (com) Short for REMark.
- Everything on the program line after
- REM is ignored by the computer. Good
- for commenting on what the program is
- doing at a particular point.
-
- 10 REM BEGINNING OF PROGRAM
- :
- 199 REM MAIN LOOP AT 200
- :
- 60100 REM (C)2005 DAVE MOORMAN
- 60110 REM COPYING THIS PROGRAM BY
- 60111 REM ANY MEANS WILL GET YOU
- 60112 REM A SLAP ON THE HAND!
-
- RESTORE (com) Resets data point so
- that the next READ receives the first
- data element from the first DATA
- statement. Not very useful, really,
- since we usually READ data into
- arrays, which are a lot easier to
- handle.
-
- RETURN (com) Ends a subroutine and
- sends the program back to the GOSUB
- that jumped to this place.
-
- RND(n) (fun) Returns a random number
- between (but not including) 0 and 1.
- If N is a negative value, the value
- is used to seed the random number
- generator. The result will always be
- the same for each negative number. If
- N is 0 or positive, a new random
- number is generated. Most say using 1
- is best.
-
- Actually, computers cannot do truly
- random numbers. Everything inside a
- computer is far too logical. However,
- with a bit of math, it can generate a
- list of unknown numbers. When you use
- a negative argument, you reset the
- generator.
-
- I have heard some arguments about how
- an argument of 0 is not as random as
- a positive argument. Who knows?
-
- To get a useable number, you might
- use this custom function:
-
- 10 DEF FNR(X)=INT(RND(1)*X)+1
-
- If you want values from 0 to X-1,
- leave off the last +1. Now any time
- you need a random number, just use
- the function. Here is a routine to
- shuffle 52 "cards".
-
- 10 DIM CD(52)
- 15 DEF FNR(X)=INT(RND(1)*X)+1
- 20 FOR X = 1 TO 52: CD(X)=X:NEXT
- 30 FOR X = 1 TO 52: R=FNR(52)
- 40 C=CD(R): CD(R)=CD(X): CD(X)=C
- 50 NEXT
-
- Please do NOT do this:
-
- 10 DIMCD(52)
- :
- 200 DEF FNR(X)=INT(RND(1)*X)+1
- 210 CD=FNR(X):IFCD(CD)<>0THEN210
- 220 CD(CD)=1
- 230 RETURN
-
- You will be able to quickly "pick a
- card" at first, but as the cards are
- taken, each pick will take longer. To
- find the last card, you are likely to
- look at about 52 taken cards!
-
- RUN [ln] (com) Runs a program. You
- can begin a program at a given line
- number. You can also use RUN in a
- program to start all over from the
- beginning.
-
- RIGHT$(s,n) (fun) Return the
- rightmost N characters from string S.
-
- 10 A$ = "THIS IS A TEST"
- 20 ? RIGHT$(A$,4)
- (This will print "TEST".)
-
- SAVE (com) We have already covered
- the correct way to put a Scratch and
- Save routine in every program. In a
- pinch, you can simply
-
- SAVE"FILENAME",8
-
- SGN(n) (fun) Returns -1 if N is
- negative, 0 if N is 0, and 1 if N is
- positive.
-
- SIN(n) (fun) Returns the sine of N in
- radians.
-
- 10 A = SIN(1)
- (A contains the value
- 0.841470985.
-
- SQR(n) (fun)
- Returns the SQuare Root of N.
-
- 10 A = SQR(9)
- (A contains 3)
-
- STOP (com) Causes a break in the
- program. Line number is reported.
- Useful for debugging.
-
- STR$(n) (fun) Returns a string of the
- value N.
-
- 10 A$ = STR$(123)
- (A$ contains " 123")
- 15 V = 4
- 20 B$ =
- RIGHT$("0"+MID$(STR$(V),2),2)
- (B$ will contain "04")
-
- SYS loc (com) Executes an ML routine
- at memory LOCation. SYSie commands
- are often used with ML Modules just
- like BASIC commands, complete with
- parameters. Be sure to read the
- documentation that comes with
- modules.
-
- TAB(n) (print com) Moves cursor to N
- column when printing.
-
- 10 PRINT TAB(17)"CENTER"
- (The word "CENTER" is printed in
- the center of the line.)
-
- TAN(n) (fun) Returns the tangent of N
- in radians
-
- 10 A = TAN(1)
- (A contains 1.55740772.)
-
- USR(n) (fun) Executes ML routine in
- memory pointed to by locations
- 784/785. N is placed in the Floating
- Point Accumulator. Returns the value
- in the Floating Point Accumulator.
- This is a function, not a command, so
- you must either PRINT USR(N), or put
- the result into a variable -- A =
- USR(N).
-
- VAL(s) (fun) Returns the value of
- string S. Non-numeric characters
- return 0.
-
- 10 ? VAL("12A7")
- 20 ? VAL("NAME")
- (Prints 12 and 0.)
-
- VERIFY (com) Like LOAD, except VERIFY
- compares the program in memory with
- that on disk without changing either.
- If the memory matches the disk file,
- OK is printed.
-
- WAIT loc,v [,eor] (com) Causes the
- program to pause while waiting for
- the byte at memory LOCation ANDed
- with V and EORed with C is not zero.
- C is optional. This is a great
- command for waiting for a keystroke.
-
- 10 POKE 198,0
- 20 WAIT 198,1
- 30 GETZ$ The program pauses while
- WAIT watches location 198 (which
- holds the number of keystrokes
- currently in the keyboard buffer).
- When a key is pressed, the program
- continues, GETting Z$.
-
- SECRETS
-
- Here are some "secret" routines that
- do useful things.
-
- BLOAD To load a binary file or block
- of data to any place in memory
- (except between 53248 and 57343).
-
- 1 DV=PEEK(186):IF DV<8 THEN DV=8
- 5 DEF FNH(X) = INT(X/256)
- 6 DEF FNL(X) = X - FNH(X)*256
- 9 ADDR = 49152: REM ADDRESS WHERE
- FILE WILL BE LOADED
- 10
- SYS57812"FILENAME",DV,0:POKE780,0
- 20 POKE781,FNL(ADDR)
- 25 POKE782,FNH(ADDR)
- 30 SYS65493
-
- BSAVE To save memory to a file.
- Cannot save from 40960-49151, or
- above 53248.
-
- 35 B = 49152:REM BEGIN ADDRESS
- 36 E = 53248: REM END ADDRESS + 1
- 40 SYS57812"FILENAME",DV
- 50 POKE 193,FNL(B):POKE
- 194,FNH(B)
- 60 POKE 174,FNL(E):POKE
- 175,FNH(E)
- 70 SYS62954
-
- POSITION CURSOR ON SCREEN his handy
- routine will put the cursor anywhere
- on the screen, where X = 0 through 39
- and Y = 0 through 24.
-
- 1000 IF Y=0 THEN
- ?"<Shift-HOME>";:GOTO1020
- 1010 POKE214, Y-1:?
- 1020 ? TAB(X)"WHATEVER!"
-
- Note: If the printing wraps around,
- an extra screen line may be inserted.
- Avoid printing to column 39 if
- possible!
-
- Read through these commands and
- functions again! Try the code. Try
- experiments. Programming requires a
- broad knowledge of possible commands
- and functions and ways they can go
- together.
-
- Dave Moorman Editor, LOADSTAR
- September 12, 2005
-
- ...end...
-
-