![]() |
Basic Commands and Statements - continued17.22 DATADefine data to be used by a program. DATA list of constants This statement is followed by a list of data items to be input into the computer's memory by READ statements. The items may be numeric or string and are seperated by commas. String data need not be inside quote marks, unless they contain any of the following characters: {space}, {colon}, or {comma}. If two commas have nothing between them, the value is READ as a zero if numeric or as an empty string. Also see the RESTORE statement, in paragraph 17.75, which allows the Commodore 128 to reREAD data. EXAMPLE:DATA 100,200, FRED, "HELLO MUM", , 3, 14, ABC123 17.23
|
color source: |
0 = | Background color |
|
---|---|---|---|
1 = | Foreground color |
||
2 = | Multicolor 1 | } Only in Graphics |
|
3 = | Multicolor 2 | } modes 3 and 4 | |
x1, y1 |
Starting coordinate, scaled. | ||
x2, y2 |
Ending coordinate, scaled. |
Also see the LOCATE command, in paragraph 17.28, for information on the pixel cursor.
DRAW 1,100,50Draw a dot
DRAW ,10,10 TO 100,60Draw a line
DRAW ,10,10 TO 10,60 TO 100,60 TO 10,10Draw a triangle
You may omit a parameter but you still must include the comma that would have followed the unspecified parameter.
Save a BASIC program file to disk.
DSAVE "filename" [,Ddrive number] [<ON | ,>Udevice number]
This command stores (SAVEs) a BASIC program on disk. (See SAVE, in paragraph 17.80, to store programs on tape.) A filename up to 16 characters long must be supplied. The default device number is 8, while the default drive number is 0.
DSAVE "BANKRECS"SAVEs the program "BANKRECS" to disk.
DSAVE (A$)SAVEs the disk program named in the variable A$.
DSAVE "PROG 3",D1,U9SAVEs the program "PROG 3" to disk on unit 9, drive 1 (on a dual drive unit).
Verify the program in memory against the one on disk.
DVERIFY "filename" [,Ddrive number] [<ON | ,>Udevice number]
This command causes the Commodore 128 to check the program on the specified drive against the program in memory. The default drive number is 0 and the default device number is 8.
NOTE: If graphic area is allocated or deallocated after a SAVE, an error occurs. Technically this is correct. Because BASIC text is moved from its original (SAVEd) location when a bit mapped graphics area is allocated or deallocated, the original location where the C128 verified the SAVEd program changes. Hence, VERIFY, which performs byte-to-byte comparisons, fails, even though the program is valid.
To verify binary data, see VERIFY "filename",8,1 format, under VERIFY command description, in paragraph 17.100.
DVERIFY "C128"Verifies program "C128" on drive 0, unit 8.
DVERIFY "SPRITES",D0,U9Verifies program "SPRITES" on drive 0, device 9.
Define the end of program execution.
END
When the program encounters the END statement, it stops RUNning immediately. The CONT command can be used to restart the program at the next statement (if any) following the END statement.
Define a musical instrument envelope.
ENVELOPE n [,atk] [,dec] [,sus] [,rel] [,wf] [,pw]where:
n |
Envelope number (0-9) | ||
---|---|---|---|
atk |
Attack rate (0-15) | ||
dec |
Decay rate (0-15) | ||
sus |
Sustain level (0-15) | ||
rel |
Release rate (0-15) | ||
wf |
Waveform: |
0 = | triangle |
1 = | sawtooth |
||
2 = | variable pulse (square) |
||
3 = | noise |
||
4 = | ring modulation | ||
pw |
Pulse width (0-4095) |
A parameter that is not specified will retain its predefined or currently redefined value. Pulse width applies to the width of the variable pulse waveform (wf=2) only and is determined by the formula: pwout = pw/40.95, so that pw=2048 produces a square wave and values 0 and 4095 produce constant DC output. The Commodore 128 has initialized the following 10 envelopes:
n, A, D, S, R, wf, pw instrument ENVELOPE 0, 0, 9, 0, 0, 2, 1536 piano ENVELOPE 1, 12, 0, 12, 0, 1 accordion ENVELOPE 2, 0, 0, 15, 0, 0 calliope ENVELOPE 3, 0, 5, 5, 0, 3 drum ENVELOPE 4, 9, 4, 4, 0, 0 flute ENVELOPE 5, 0, 9, 2, 1, 1 guitar ENVELOPE 6, 0, 9, 0, 0, 2, 512 harpsicord ENVELOPE 7, 0, 9, 9, 0, 2, 2048 organ ENVELOPE 8, 8, 9, 4, 1, 2, 512 trumpet ENVELOPE 9, 0, 9, 0, 0, 0 xylophone
To play predefined musical instrument envelopes, you simply specify the envelope number in the PLAY command (see PLAY, in paragraph 17.64). You do not need to use the ENVELOPE command. The ENVELOPE command is used only when you need to change the envelope.
Put machine in 2 Mhz mode of operation.
FAST
This command initiates 2 Mhz mode, causing VIC's 40 column screen to be turned off. All operartions (except I/O) are speeded up considerably. Graphics may be used, but will not be visible until a SLOW command is issued.
Get data from expansion (RAM module) memory.
FETCH #bytes, intsa, expsa, expbwhere:
Define sound (SID chip) filter parameters.
FILTER [freq] [,lp] [,bp] [,hp] [,res]where:
Unspecified parameters result in no change to the current value.
You can use more than one type of filter at a time. For example, both low-pass and high-pass filters can be used together to produce a notch (or band-reject) filter response. For the filter to have an audible effect, at least one type of filter must be selected and at least one voice must be routed through the filter.
FILTER 1024,0,1,0,2Set the cutoff frequency at 1024, select the band pass filter and a resonance level of 2.
FILTER 2000,1,0,1,10Set the cutoff frequency at 2000, select both the low pass and high pass filters (to form a notch-reject) and set the resonance level at 10.
Define a repetitive program loop structure.
FOR variable = start value TO end value [STEP increment] NEXT [variable]
The FOR statement works with the NEXT statement to set up a section of the program that repeats for a set number of times (i.e. a loop). This is useful when something needs to be counted or something must be done a certain number of times (such as printing).
This statement executes all the commands enclosed between the FOR and NEXT statements repetitively, according to the start and end values. The start value and end value are the beginning and ending counts for the loop variable. The loop variable is added to or subtracted from during the FOR... NEXT loop.
The logic of the FOR... NEXT statement is as follows. First, the loop variable is set to the start value. When the program reaches a program line containing the NEXT statement, it adds the STEP increment (default = 1) to the value of the loop variable and checks to see if it is higher than the end value of the loop. If the loop variable is less than or equal to the end value, the loop is executed again, starting with the statement immediately following the FOR statement. If the loop variable is greater than the end value, the loop terminates and the program resumes immediately following the NEXT statement. The opposite is true if the step size is negative.
EXAMPLE A10 FOR L=1 TO 10 20 PRINT L 30 NEXT L 40 PRINT "I'M DONE! L =";L |
EXAMPLE B10 FOR L=10 TO 1 STEP-1 20 PRINT L 30 NEXT L 40 PRINT "I'M DONE! L =";L |
Program A prints the number from one to 10, followed by the message I'M DONE! L = 11. Program B prints the numbers down to one and them I'M DONE! L = 0.
The end value of the loop may be followed by the word STEP and another number or variable. In this case, the value following the word STEP is added each time, instead of the default value one. This allows counting backwards, by fractions, or increments other than one.
The user can set up loops inside one another. These are known as nested loops. Care must be taken when nesting loops so, that the last loop to start is the first one to end.
10 FOR L = 1 TO 100 20 FOR A = 5 TO 11 STEP .5 30 NEXT A 40 NEXT LThe FOR... NEXT loop in lines 20 and 30 are nested inside the one in line 10 and 40. The STEP increment of .5 is used to illustrate the fact that floating point indices are valid.
Receive input data from the keyboard, one character at a time without waiting for a key to be pressed.
GET variable list
The GET statement reads each key typed by the user. As the user types, the characters are stored in the computer's memory (in an area called the keyboard buffer). Up to 10 characters can be stored here1, any characters typed after the 10th character are lost. The GET statement reads the first character from the buffer and moves the rest up, allowing room for more. If there are no characters in the buffer a null (empty) character is returned. The word GET is followed by a variable name, either numeric or string. GET will not pause the program if no characters are in the buffer (see GETKEY, in paragraph 17.42).
If the C128 intends to GET a numeric key and a key other than a number is pressed, the program stops and a TYPE MISMATCH error message is displayed. The GET statement may also be put into a loop, checking for an empty result. The GETKEY statement could also be used in this case. See GETKEY, in paragraph 17.42, for more information. The GET and GETKEY statements can be executed only within a program.
10 DO:GET A$:LOOP UNTIL A$="A"This line waits for the A key to be pressed to continue.
20 GET B, C, DGet numeric variables B, C and D from the keyboard without waiting for a key to be pressed.
Receive input data from the keyboard, one character at a time and wait for a key to be pressed.
GETKEY variable list
The GETKEY statement is very similar to the GET statement. Unlike the GET statement, GETKEY, if there is no character in the keyboard buffer, will wait for the user to type a character on the keyboard. This lets the computer wait for a single character to be typed. This statement can be executed only within a program.
10 GETKEY A$This line waits for a key to be pressed. Typing any key continues the program.
10 GETKEY A$,B$,C$This line waits for three alphanumeric characters to be entered from the keyboard. GETKEY can also be used to READ numeric keys.
NOTE: GETKEY cannot return a null (empty) character.
Receive input data from a tape, disk or RS232.
GET#file number, variable list
This statement inputs one character at a time from a previously opened file. Otherwise, it works like the GET statement. This statement can be executed only within a program.
GET#1,A$ This example receives one character, which is stored in the variable A$, from file number 1. This example assumes that file 1 was previously opened. See the OPEN and DOPEN statements, in paragraphs 17.62 and 17.3, respectively.
Switch to C64 mode.
GO64
This statement switches from C128 mode to C64 mode. The question "Are You Sure?" is displayed in response to the GO64 statement. If {y} is typed, then the currently loaded program is lost and control is given to the C64 mode; otherwise, if any other key is pressed, the computer remains in C128 mode. This statement can be used in direct mode or within a program. The prompt is not displayed in program mode.
Call a subroutine from the specified line number.
GOSUB line number
This statement is similar to the GOTO statement, except the Commodore 128 returns from where it came when the subroutine is finished. When a line with a RETURN statement is encountered, the program jumps back to the statement immediately following the GOSUB statement.
The target of a GOSUB statement is called a subroutine. A subroutine is useful if a task is repeated several times within a program. Instead of duplicating the section of program over and over, set up a subroutine, and GOSUB to it at the appropriate time in the program. See also the RETURN statement, in paragraph 17.77.
20 GOSUB 800 : : 799 END 800 PRINT "HI THERE": RETURNThis example calls the subroutine beginning at line 800 and executes it. All subroutines terminate with a RETURN statement.
Line 799 stops the program accidentally falling into the subroutine.
Transfer program execution to the specified line number.
GOTO line number
After a GOTO statement is encountered in a program, the computer executes the statement specified by the line number in the GOTO statement. When used in direct mode, GOTO executes (RUNs) the program starting at the specified line number, without clearing the variables. This is the same as the RUN command except it does not clear variable values.
10 PRINT"COMMODORE" 20 GOTO 10The GOTO in line 20 makes line 10 repeat continuously until {run/stop} is pressed.
GOTO 100Starts (RUNs) the program starting at line 100, without clearing the variable storage area.
Select a graphic mode.
GRAPHIC mode [,clear] [,s] GRAPHIC CLR
This statement puts the Commodore 128 in one of the six graphic modes:
Mode |
Description |
---|---|
0 |
40-column (VIC) standard text |
1 |
Standard bit map |
2 |
Standard bit map (split screen) |
3 |
Multicolor bit map |
4 |
Multicolor bit map (split screen) |
5 |
80-column text |
The clear parameter specifies whether the bit mapped screen is cleared (equal to 1) upon running the program, or left intact (equal to 0). The s parameter indicates the starting line number of the split screen when in graphic mode 2 or 4 (standard or multicolor bit map split screen modes). The default starting line number of the split screen is 19.
When executed, GRAPHIC 1-4 allocated a 9K bit mapped area. The start of BASIC text area is moved above the bit map area, and any BASIC program is automatically relocated. This area remains allocated even if the user returns to TEXT mode (GRAPHIC 0). If the clear option is specified as 1, the screen is cleared. The GRAPHIC CLR command deallocates the 9K bit mapped area, making it available again for BASIC text. Any BASIC program is relocated.
GRAPHIC 1,1Select standard bit map mode and clear the bit map.
GRAPHIC 4,0,10Select split screen multicolor bit map mode, do not clear the bit map and start the split screen at line 10.
GRAPHIC 0Select 40 column text.
GRAPHIC 5Select 80 column text.
GRAPHIC CLRClear and deallocate the bit map screen.
page URL: www.bigfoot.com/~c128page/c128sg/sect-17b.htm
contact: c128page@bigfoot.com