Zbasic_4ed_Apr87 Zbasic 4ed Apr87

Zbasic_4ed_Apr87 Zbasic_4ed_Apr87

User Manual: Zbasic_4ed_Apr87

Open the PDF directly: View PDF PDF.
Page Count: 772

DownloadZbasic_4ed_Apr87 Zbasic 4ed Apr87
Open PDF In BrowserView PDF
Interactive BASIC Compiler
by

Andrew R. Gariepy,
Scott Terry. David Overton.
Greg Branche and Halbert Uang

Documentation by
Michael A. Gariepy

©Copyright1985. 1986. 1987

fA M.m.) ,j
All Rights Reserved

ZBasic'" is a Trademark of Zedcor. Inc.

Fourth Edition: 4/87
First edition: 8/85
Seoond edition: 10185
Third edition: 5/86

TECHNICAL SUPPORT:
1-(602) 795-3996
Support hours: Monday-Friday, Noon to 5PM, Mountain Standard Time
Zedcor provides free phone support. Be sure to have your invoice number and license agreement number ready. You
may need them to get support. Also be sure you understand the problem dearly and describe ~ is simply as possible.
His usually a good idea to test the problem a few times before calling. Sometimes it's just a syntax problem. Collect
or toll free calls will not be accepted for technical support.
In addition, you may contact us on the GEnie Information Service by sending electronic mail (EMAIL) to;
ZBASIC. We check our mailbox semi-regularly and will respond to you via electronic mail. We also have topics set up
on the various Round-Table Bulletin Boards for general information.
Notes on the Fourth Edition
This ed~ion of the ZBasic'" manual contains all the computer appendices. This includes the appendix for MS-DOS"',
APPLE'" lie, IIc (DOS 3.3 and ProDOS), MACINTOSH"', CP/M'" and TRS-80'" Model 1, 3 and TRS-80 Model 4.
The appendices are at the back of the manual and the new index includes entries for both the reference section and
the appendices. His important to study the appendix for the computer you are using since there are usually
enhancements and variations that are important to note.
Acknowledgements
Special thanks to John Kemeny and Thomas Kurtz for creating BASIC, the easiest and most powerful of all the
general purpose languages. To Joanne Gariepy for many late hours of ed~ing. An extra special thanks to the
programming teams that have meant so much to the success of the product; Scott Terry, Dave Overton, Greg
Branche and Hal Liang and to Thomas Dim~ri and David Cooper for their help with the MSDOS version. Special
thanks to Karen Moesh and Leyla Blisard for making sure ZBasic gets mailed as fast as it does and to Apple
Computer, Inc. for the Macintosh"', Laserwr~er"', MacDraw, and MacPaint graphic software and to Microsoft for
Word"'; on which this entire manual was composed and printed (both text and graphics).
Many thanks to the multitudes of ZBasic'" users who provided helpful suggestions for this fourth edition.
Copyright Notice
The ZBasic software and manual are © Copyright 1985,1986,1987, Zedcor Inc., All Rights Reserved. It is against
the law to copy the ZBasic software or Documentation on cassette, diskette, tape, listing or any other medium for
any purpose other than the purchaser's archival use without the express written permission of Zedcor Inc.
Trademarks
Because ZBasic™ runs on so many different products, this manual makes reference to many manufacturers and products that are trademarks of their
respective owners. We acknowledge these companies and thank those that have been so helpful In making ZBasicTM a success: ZBasic™ is a
trademark of Zedcor Inc. Apple, IIGS, lie, 11+, lie, Macintosh Plus, MAC XL, LISA and Macintosh'" are registered or licensed trademarks of Apple
Computer. IBM PC, IBM PC jr., IBM PC-XT, PC·AT and PC-OOS are registered tredemarks of International Business Machines Corporation.
MSBASIC, MS, Xeni. and M5-DOS are registered trademarks of Microsoft Corporation. CP/M is a registered trademark of Digital Research. Turbo
Pascal is a registered trademark of Borland International. TR5-80, Radio Shack, Tandy 2000. Tandy and Tandy 1000, 1200, 3000 are registered
trademarks of Tandy Corporation. Kaypro II, 4, 10, 16 and 286i are registered trademarks of Kay pro Corporation. Amiga, Commodore 64 and 128 are
trademarks of Commodore Intemational. Franklin Ace 1000 Is a trademark of Franklin Corporatio=Osborne is a trademark of Osborne Corporation.
Compaq and Deskpro are trademarks of Compaq Computers. Panasonic Senior and Executive rtners are trademarks of Panasonic Industrial
Corporation. Data General One Is a trademark of Data General Corporation. Quadram is a tradem
of Quadram Corporation. VAX is a trademark of
Digital Equipment Corporation. Unix is a trademark of AT&T Corporation. We apologize for any unintentional omissions.
Zedcor Incorporated reserves the right to make changes to the specifications of Z8asic'Rl and to the ZBasic"" documentation without obligation to notify
any persons or organization of such changes.

ZEDCOR, INC.
4500 East Speedway Blvd., Suite 22
Tucson, Arizona 85712-5305
(602) 795-3996
(602) 881-8101

Orders: 800· 482·4567

TABLE OF CONTENTS

Introduction

5

Getting Started

7

Configuration

11

Standard Line Editor
Adding, Inserting and Deleting Lines
The Line Editor
Renumber, Calculator, SAVE, LOAD, DIRectory

14
14
15
18

Running ZBaslc Programs
RUN, RUN+, RUN"
Breaking Out of Executing Programs

22
23
24

Chaining Programs

26

Compile and Runtime Errors

28

Terms and Definitions

32

Math

36
36
37
40
41
42
44

Operators
Expression Evaluation types
Other Math Functions
Derived Math Functions
Order of Precedence
Conditional and Logical Operators
Numeric Conversions

46

Constants

48

Variables
Integer Variables
Floating Point Variables (REAL)
Configuring Accuracy
String Variables
Defining String Lengths with DIM and DEFLEN
INDEX$
Arrays
Shell and Quick Sort examples
Graphics

50

53
54

57
61
64

67
72

76
110
Table of Contents

2

TABLE OF CONTENTS
98

Flies
Terms
File Structure
Sequential Method
Random Method
Mixing File Methods
Disk Errors

100
106
108
115
120
122

Screen and Printer

126

Keyboard Input

130

Loops FOR-NEXT, WHILE-WEND, DO-UNTIL

135

Functions and Subroutines
DEFFN
LONGFN

140
140
141

Machine Language

143

program Structure

147

Debugging Tools

153

Porting Programs

156

Converting Old Programs

161

Keywords

168

Glossary
170
The reference section contains a complete alphabetical list of all
Standard ZBasic commands, statements, functions and operators
with cross reference to other commands and sections of the
manual.
Also see the appropriate appendix for special commands or
enhancements for a particular computer model.

3

Table of Contents

TABLE OF CONTENTS
Computer Appendices
VERSION NOTES
Throughout this manual are notes to different versions of ZBasic.
An Icon representing the various computer type is used.

Remember the icon for your computer type. If you see the icon
in the standard reference manual, a note will follow it describing
something of importance for that version.

I___IB_M_®_~:_~·_I:a_D_O_S_TM_"P_C_-_D_O_S_TM_a_n_d_co_m_pa_ti_b_le_S
I

__
A

ja'!l

= ______Z_8_0™__;T_R_S_-_8_0TM__M_O_d_e_I_1,_3_a_n_d_4_a_n_d_C_P_/M_TM__-8_0_____B

I

II

Apple® lie, IIc, Laser 128™ and IIGS: DOS 3.3
Apple® 11+, lie, IIc, Laser 128™ and IIGS, ProDOS

C
D

---------------------------------------------

!b

Macintosh™, Macintosh Plus™, MAC XLTM,
Macintosh SETM, Macintosh IITM and
LlSATM with Macworks™

INDEX

E

End

Table of Contents

4

INTRODUCTION

As the orginal developer of ZBasic and the head of the programming
team I want to thank you for your support.
I've been involved in writing ZBasic for eigth years now and am very
proud of what we've accomplished. It hasn't been easy but it's sure
been fun. How many times does a complex product like ZBasic ever
make it to market?
Over the years I have received thousands of suggestions from
programmers. I've tried to implement as many of these suggestions as I
could. I still need your feedback and comments so I can make ZBasic
the most powerful programming tool available. Send your suggestions
to the "ZBasic Wish-List Department" or to my attention.
Special thanks to my wife Janis for putting up with my programming late
into the night and to the many ZBasic users that have taken the time to
send letters of encouragement.
Andrew R. Gariepy
April, 1987

5

Introduction

INTRODUCTION

ZBasic has come a long way since it was introduced in 1985. Many
thousands of copies, on many different computers, have been distributed
all over the planet.
We have accomplished what we set out out to do; to provide a powerful,
fast, interactive, simple-to-use, inexpensive BASIC compiler that works
the same way on many different computers so you only have to learn a
language once.
I've worked hard to make the manual simple to follow and easy to
understand.
I highly recommend that you subscribe to the ZBasic newsletter; "Z".
It
covers all sorts of topics about ZBasic and has listings for public domain
ZBasic subroutines on diskette you can get cheap. It's jammed with hints
and tricks from other ZBasic users all over the world and from the ZBasic
programmers themselves. Call 800-482-4567 to order.
Thank you for your support of ZBasic. Please let us know if you have any
ideas of how to improve the product.
Michael A. Gariepy
April,1987

Introduction

6

GETTING STARTED

7

Getting Started

GETTING STARTED

ASIC
GETTING STARTED
ZBasic is provided on a diskette for your computer. Before loading ZBasic do the following:
1.

Read, sign and return the License agreement in the front of this manual.
Keep track of your serial number, you may need it for support.

2.

Read the Appendix for your computer. It will explain any variations or
enhancements for your version of ZBasic and also has important
information about hardware requirements or limitations.

3.

MAKE A BACKUP COPY OF THE ORIGINAL ZBasic™ DISKETTE. Never
use the original diskette. If you do not know how to make backups,
refer to your DOS or User Manual.

4.

Using the BACKUP, load ZBasic™ according to the instructions for your
computer below:

MS-DOS
CP/M-SO
TRS-80
Apple DOS 3.3
Apple ProDOS
Macintosh

From A> :
From A> :
From DOS READY:
From FP prompt:
From FP prompt:
Using the mouse:

ZBASIC
ZBASIC
ZBASIC
BRUN ZBASIC
-/ZBASIC/ZBASIC.SYSTEM
Double Click ZBasic Icon

HOW TO BE A ZBASIC EXPERT IN TEN MINUTES OR LESS
The following is a quick-and-dirty course that teaches you how to TYPE, RUN, SAVE, QUIT
and LOAD a program using ZBasic.
First LOAD ZBasic according to the instructions for your computer above or in your
computer appendix. Some versions require that you press  to enter the editor. If a
prompt appears asking for input, press . See CONFIGURE for more information about
the options being offered.

!l

Macintosh users note that the following lessons are done in the COMMAND window.

Getting Started

8

GETTING STARTED
LESSON ONE: TYPING IN A SIMPLE PROGRAM

When you see the message; ZBasic Ready, you may begin entering programs. So
we may demonstrate the simplicity of Z8asic, please type in the following program exactly as
shown. Always type COMMANDS in UPPERCASE and remember to press  or
 at the end of each line.
10
20
30

=

FOR Count
PRINT "Hi,
NEXT Count

1 TO 10
I'm ZBasic! ---"

Congratulations, you've just entered your first ZBasic program. To see a listing of the
program type: LIST. To find out more about entering and editing programs,
see: STANDARD LINE EDITOR. Also see your computer appendix for information about
using a full screen editor (if your version has one).
LESSON TWO: RUNNING THE PROGRAM

To run the program you just entered type:
RUN

The program will print the message; Hi, I'm ZBasic! --- ten times. ZBasic
actually compiles the program but does it so fast that you'll barely notice. When the program
is finished you're back in the editor. That's the beauty of interactive compiling.
LESSON THREE: SAVING THE PROGRAM

To SAVE your program, make sure you have an unprotected diskette in the drive and type:
SAVE

MYPROG

The program will be saved to disk for future use.
LESSON FOUR: EXITING ZBASIC

To exit ZBasic type:
QUIT

You will now be back in the operating system. It's a good idea to save your programs before
doing this.
LESSON FIVE: HOW TO LOAD EXISTING PROGRAMS

To load the previously saved program, first re-Ioad Z8asic then type:
LOAD

MYPROG

The program you saved is now back in memory. To see it, type LIST:
10 FOR Count = 1 TO 10
20
PRINT "Hi, lim ZBasic!--_n
30 NEXT Count

9

Getting Started

GETTING STARTED

A NOTE TO EXPERIENCED BASIC PROGRAMMERS:
Since the ZBasic Compiler is very similar to the BASIC interpreters found on most
microcomputers (except for graphic commands and file I/O), use the Reference Section
and your Computer Appendix to check syntax differences from other BASIC's. Use the
Index to find more in-depth answers. The appendices in the back of this manual contain the
commands and enhancements for specific computers. These appendices are also very
useful for converting programs from one machine to another.
If you have been frustrated with incredibly slow interpreters and awkward, complicated
compilers, you will be pleased with the power and ease of ZBasic.

A NOTE TO INEXPERIENCED BASIC PROGRAMMERS
This manual is llQ1 intended to teach you BASIC programming from scratch. If you lack
programming experience we suggest picking up some of the BASIC tutorials for the IBM
PC, CP/M systems or the TRS-SO, available from most major bookstores and libraries.
Once you leam the beginning concepts of BASIC programming, like GOSUB, FOR/NEXT
and that type of thing, this manual should be all you need.
ZBasic is very similar to the IBM PC, TRS-SO, MSBASIC and GW BASIC interpreters;
however, most Graphic commands and Random File commands are different (sequential file
commands are very similar).
For those with some experience, this section and the section "Standard Line Editor" are
written in a tutorial format.
Be sure to examine the appendix in the back of this manual for your computer. It will tell you
about any differences and enhancements that are important to know ~ you start.

Getting Started

10

CONFIGURATION

11

Configuration

CONFIGURATION

TM

ASIC
CONFIGURATION

OPTIONS

Since no two programmers are alike, we allow you to configure your version of ZBasic. Most
versions start with a screen something like this:

As you can see below, configuring your version of ZBasic is simple. Simply set the
parameters the way you want, then save the reconfigured ZBasic:

dit

Type "E" to enter the Standard Line Editor. Once in the editor, you may
LOAD, TYPE, RUN, EDIT, SAVE or DEBUG your programs.

onfigure

Typing "e" allows you to configure certain parts of ZBasic. Note that in most
cases you will not have to change parameters. See next page for options.

ave

Typing "S" allows you to save ZBasic with the configuration defaults set to your
options. This way you don't have to reconfigure ZBasic every time you load it.

atch Typing "P" allows you to make patches to ZBasic. If we make minor changes you won1 have to return you disk to us for an upgrade. Not available on all versions. Configuration 12 CONFIGURATION CHANGING CONFIGURATION It is simple to change configurations. If the defauH value is not to your liking simply type in the value you want. Press to skip inputs, Press or to go back to the main menu. STANDARD CONFIGURE QUESTIONS 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. HEX Double Precision Accuracy 6-54 000E Single Precision Accuracy 2-52 0006 Scientific Precision 2-Double Prec. 0006 Maximum File Buffers Open 0 - 99 0002 Array Base o or 1 0000 Rounding Number 0031 o - 99 Default Variable Type: ingle, oub1e, nteger Test Array Bounds Convert to uppercase *Optimize expressions as Integer? yiN *Space required after Keywords? yiN Decimal INPUT 00014 00006 00006 00002 00000 00049 ? ? ? ? ? ? I N N ? Y N - ? ? ? • Not all versions. DEFINITIONS OF THE STANDARD CONFIGURE QUESTIONS Set from six to 54 digits of precision for Double Precision math. Defaults to 14. 1. 2. Set from four up to two digits less than Double Precision. Defaults to 6. Digits of math precision for Scientific functions (ATN, COS etc.) 3. 4. Set the number of files you want OPEN at one time. Up to 99. Two is the default. Array Base 0 or 1. Set zero or one as ARRAY start. Zero is default. 5. Rounding Factor. Sets rounding for PRINT USING and other things. 6. 7. Set variable default to Integer, Single or Double precision. Press I, S or D key. Same as DEFDBL, DEFSNG, DEFINT A-Z. Check the runtime program (object code) for array values going out of DIM bounds. S. (Slows the program down but is very good for debugging purposes) Tells ZBasic to convert all lowercase entries to UPPERCASE. 9. The variable "FRED" is the same as the variable "Fred" if this is done. 10. Two ways to evaluate expressions. Integer or Floating Point. Defaults to integer for speed and size. Set to NO if you want defaults as real. Forcing a space after keywords allows you to embed keywords in variables. 11. IMPORTANT NOTE: If you change configuration, make sure all CHAINED programs have EXACTLY THE SAME CONFIGURATION. Otherwise unpredictable results may occur. Macintosh: Select the "Configure" menu item to change or save configuration options. MSDOS and ProDOS versions of ZBasic have a CON FIG command that allows resetting the options from the Standard line editor. 'CP/M, Apple DOS 3.3 and TRS-SO versions may not have the last two options offered. Check the appropriate appendix for specifics. 13 Configuration STANDARD LINE EDITOR ASIC STANDARD EDITOR ZBasic comes with a Standard Editor that works the same way on all computers. While most versions of ZBasic now come with a full screen editor which is easier and faster to use, the Standard Editor allows you to do quick-and-dirty editing and direct commands like an interpreter. Learning the Standard Editor will allow you to jump from one version of ZBasic to another without having to re-Iearn the full screen editor for that particular machine. ENTERING THE EDITOR Load ZBasic. When the screen says: ZBasic Ready you have entered the ZBasic Interactive Programming Environment (a fancy name for the Standard Editor) and may enter programs and type direct commands. The Standard Line Editor requires each line of a program to have a line number for editing and reference purposes (labels are available too.) Line numbers may range from 0-65534. Each line can be up to 250 characters long. To add a line, type a line number and the text, or use the AUTO command to have ZBasic assign line numbers automatically (some versions of ZBasic will allow you to enter programs without using line numbers. Check your appendix). If you are loading a program without line numbers, they will be added automatically. Line numbers are used for editing in the Standard Line Editor only. Important Note: Always type keywords and commands in uppercase. Select "Convert to Uppercase" under Configure if you don't want to worry about it. Important Note: This entire section deals with commands that are to be executed from the Standard Line Editor. If you are in the full screen editor you will need to switch to the Standard Editor. See your computer appendix for Specifics. l!b This section of the manual refers to the COMMAND window. Switching between the COMMAND and EDIT windows is accomplished with COMMAND E. Interactive Programming Environment 14 STANDARD LINE EDITOR ENTERING AND DELETING LINES Type in the following example. Enter it exactly as shown, as we will use this text to illustrate the use of the line editor. Remember to use at the end of each line. This is how ZBasic recognizes a line and stores it in memory: 10 THIS IS AN EXAMPLE OF ADDING A LINE 20 THIS IS THE SECOND LINE 30 THIS IS THE THIRD LINE If you make a mistake, use or to delete it. If you a line incorrectly just type it over again. To see the complete program type LIST: LISTING A PROGRAM To list a line, or range of lines, use LIST or just L: you TYPE LIST or L LIST "SUBROUTINE" LIST "FRED"LIST 100-200 LLIST-100 LIST 100- or L100 L+ LLIST+ L+-100 LIST' DELETING ZBASIC RESPONDS Lists complete program to the screen Lists the line with that label List all lines after and including the line with the label "FRED" Lists lines from 100-200 Lists lines up to 100 to printer Lists lines from 100 on Lists the last line listed or edited Lists previous line (or plus <+> key) Lists next line (or minus <-> key) Lists program without line numbers Lists to printer without line numbers Lists up to line 100 without showing line numbers Single steps long listings. continues listing Lists PAGE of lines (10 lines) to screen Some systems: Highlights keywords on screen while listing. LINES Deleting lines is accomplished in a number of ways. Examples: YOU TYPE 1000 DEL 1000 DEL 10-50 DELETE 50 DELETE 50NEW ZBASIC RESPONDS Deletes line 1 000 Delete line 1000 Delete lines 10 through 50 Delete line 50 Delete line 50 and all lines after Delete the entire program Careful! NOTE: Labels may be used in place of line numbers (except first example). ADDING OR INSERTING A NEW PROGRAM LINE Add or insert a line by typing in a new line number followed by text (be careful not to use the number of a line already being used unless you want to replace it). To insert a line between line 10 and line 20, assign a number such as 15 to the new line (or another number between 10 and 20). To add a line at the end of the program, assign the line a number greater than the largest line in the program. 15 Interactive Programming Environment STANDARD LINE EDITOR HOW TO EDIT TEXT ON A LINE The Standard Line editor is used to edit lines in a program and to give commands directly to the compiler. Deleting, inserting, changing or adding new text is easy and fast. EDIT ANYTHING ON A LlNE. .. EVEN LINE NUMBERS! Unlike most BASICs, ZBasic allows you to edit anything on a line, even the line number. When a line number is edited, ZBasic creates a new line with that line number. The old line will not be deleted or changed. Very handy for avoiding redundant typing. The ZBasic line edttorfunctions the same way on all versions of ZBasic. Here are & line edit keys you need to remember: the STANDARD LINE EDITOR KEYS INSERT TEXT nsert characters etend line ape Insert mode CURSOR MOVEMENT Move RIGHT Move LEFT earch for ist the line you are editing DELETE TEXT elete one character ill, Delete upto ack to end of line ape Kill and Hack OTHER bort changes Keep changes hange character under the cursor Abort changes (CTRL C on some systems) CURSOR ARROW keys are often used instead of and . _ . J-"l... Macintosh: =, =. MSDOS and Apple II: Cursor keys= and . Delete key also works as . =. MSDOS: Insert key = . CP/M: =. TRS·SO: =. USING THE LINE EDITOR The command to edit a line is "EDIT" (or just "E") followed by a line number (or label). If no line number is used, the last line LlST(ed) or EDIT(ed) will be assumed «COMMA> without will also edit the current line). "EDIT 20" and "E20" do the same thing. The following page describes the simple commands used to edit the characters on the line. Interactive Programming Environment 16 STANDARD LINE EDITOR LEARNING THE COMPLETE STANDARD LINE EDITOR IN 10 MINUTES OR LESS LISTING THE LINE YOU ARE EDITING To see the complete line you are editing, and put the cursor at the beginning of the line, press the key. Remember: Line editor commands do not require . MOVING THE CURSOR ON THE LINE n To move the cursor back and forth on a line, use or «DEl> some systems) (don1 use To move the cursor to a specific character on a line quickly, use the key, (SEARCH), followed by the character to find. To move the cursor from the "1" in "THIS" to the "L" in "EXAMPLE", just type and . 00010 THIS IS AN EXAMPLE OF ADDING A LINE 00010 THIS IS AN EXAMP_ CHANGE CHARACTER UNDER CURSOR To change the character under the cursor, press followed by the new character. To change five characters, press the <5> key first, the key, then the five keys to replace the old characters. ABORT (UNDO) CHANGES To undo changes press the key. All changes, additions and deletions will be aborted. DELETE CHARACTERS To delete characters in a line use the key. Pressing will delete the character under the cursor. To delete five characters press 5 times or press the <5> key and the key. ESCAPE PRESENT MODE To escape from INSERT, SEARCH, CHANGE, EXTEND or KILL modes, press . DELETE UP TO A SPECIFIC CHARACTER n To delete, or KILL, a range of characters from the cursor to a specified character, use the key. INSERT CHARACTERS To insert text in a line, position the cursor where insertion is desired. Press the d> key. Type in text or to erase tex!. Almost any key may be typed except , or . ape exits the INSERT mode. DELETE TO END OF LINE To delete all the characters from the cursor position to the end of the line, press the key (Hacks off the remainder of the line). MOVE TO END OF LINE AND ADD To move the Cursor to the end of the line and enter the INSERT MODE, press the "X" key (For eXtend). will return to the regular line editor mode. EXIT THE LINE EDITOR : : or Exit the line edit mode and ACCEPT all changes and additions, To exit the line edit mode and IGNORE all changes and additions • n is a number. If you type 4D, four characters are deleted. n=nth occurrence or n times. 17 Interactive Programming Environment STANDARD LINE EDITOR USING OTHER EDITORS OR WORD PROCESSORS Most versions of ZBasic now come with a Full Screen Editor. Check your computer appendix to see if you have one for your version. If you choose, you may also edit ZBasic programs with a word processor or some other editor. You will need to save the ZBasic program in ASCII using the SAVE" or SAVE+ commands before editing. In order for ZBasic to load a text file it requires that: Line lengths must be less than 250 characters Every line must be followed by a Carriage Return If the text file does not contain line numbers, ZBasic will assign line numbers to the program starting with one, in increments of one. Use RENUM to renumber a program. ASCII text takes longer to LOAD and SAVE. RENUMBER PROGRAM LINES ZBASIC renumbers lines in a program using the RENUM command. Formal: RENUM [[NEW LINE NUMBER][[. OLD START,][ INCREMEN7]]] YOU TYPE RENUM RENUM 100,,5 RENUM 100,20,5 RENUM,,100 THE CALCULATOR ZBASIC RESPONDS Lines start with 10, Increments of 10 Lines start with 100, Increments of 5 Renumber From line 20, Start with 100, Increments of 5 Renumbers all lines by 100 (DIRECT MODE) ZBasic has a built in calculator. Use "?" or "PRINT" in front of a calculation to see the results. You may also convert number bases like HEX, Binary, Octal and Unsigned Integer. (See BASE CONVERSIONS) Examples: you TYPE PRINT 123.2*51.3 ?SQR(92.1) PRINT 3/2*6 ?3./2*6 ?320/.0001 ZBASIC RESPONPS 6320.16 9.5968745 6 (Calculated in INTEGER) 9 (Calculated in FLOATING POINT) 3200000 NOTE: Unless you have configured ZBasic to default to floating pOint, integer is assumed. If configured for "Optimize expressions as Integer", use a decimal pOint in an expression to force the result of a calculation to be floating pOint (see CONFIGURE). Interactive Programming Environment 18 STANDARD LINE EDITOR SAVE, LOAD, APPEND and MERGE ZBASIC uses the LOAD and SAVE commands to load and save programs. Subroutines saved in ASCII without line numbers may be inserted in your program with APPEND. To SAVE in ASCII use ...... To SAVE in ASCII without line numbers use "+". Examples: SAVE MYPROG SAVE CHECKERS 2 SAVE* MYPROG SAVE+ TEST LOAD CHECKERS LOAD* CHECKERS MERGE MYPROG MERGE* MYPROG APPEND 2000 MYSUB APPEND* 50 SORT Saves in tokenized format. Saves tokenized to TRS-aO drive 2. Saves MYPROG in ASCII. Saves TEST without line#'s in ASCII. Loads Checkers. Loads Checkers but strips REMarks and Spaces. Merges program MYPROG. Merges ASCII program, strips REM's and Spaces. Loads non-line# ASCII subroutine, MYSUB, to line 2000. Loads SORT to line 50 in increments of 1, strips all REM's and Spaces from the routine. NOTE: Only non-line numbered ASCII programs may be APPENDED (SAVE+). Only line numbered programs may be merged (SAVE or SAVE"). When LOAD(ing) programs without line numbers, ZBasic assumes the end-of-line is terminated with , or 250 characters, whichever comes first. Lines are assigned line numbers starting with one, in increments of one. FILE DIRECTORY or CATALOG To see the names of files on the current storage device type DIR. Examples: MS-DOS (also see PATH and CHOIR) Apple DOS 3.3 and CP/M: DIR Lists all the files on the present drive DIR B: Lists the files on drive B DIR A: Lists all the files on drive A DIR C: Lists all the files on drive C NOTE: The Apple DOS 3.3 version of ZBasie uses A, B, C... for drive spees instead of D 1, D2 ... APPLE ProDOS: (also see PATH) DIR Lists all files in current directory DIR FRED Lists all files in subdirectory FRED DIR FRED/TOM Lists all files in subdirectory TOM TRSDOS: DIR 0 DIR 2 DIR 1 Lists the files on drive zero Lists the files on drive two Lists the files on drive one MaCintosh: (also see FILES$) DIR HD30: Fred Lists files in folder called "Fred" on root directory called HD30 LDIR HD30: Fred Lists all files to the printer Be sure to see your COMPUTER APPENDIX for variations. 19 Interactive Programming Environment STANDARD LINE EDITOR THE MINI-COMPILER (Direct mode similar to an Interpreter) The Mini-compiler permits compilation of one line programs while in the standard editor. This is very convenient for testing logic or math without having to run the entire program. You are limited to one line but may use a colon ":" to divide a line into muHiple statements. Remember to use? or PRINT to see the resuHs. Examples: YOU TYPE PRINT LEFT$("HELLO",2) PRINT CHR$ (65) PRINT ASC("A") FOR X=l TO 500:? X;:NEXT ? ABS( TAN(l)* EXP(2)+ LOG(9)) : LPRINT "HELLO" PLOT 0,0 TO 1024, 767 ? &AB ZBASIC RESPONDS HE A 65 1 2 3 4 5 ... 500 13.704997622614 Prints "HELLO" to the printer Plots a line across the screen 171 (HEX to decimal) "Note: A Mini-Compiler line may not start with an "E" or "L" since these are used for abbreviations for EDIT and LIST. To do a command that starts with "E" or "L". use a colon ":" first; : LPRINT THE FIND COMMAND ZBASIC will FIND variables. quoted strings. labels. line numbers and commands within a program quickly and easily. In most cases simply type FIND followed by the text you want to find. The only two exceptions are: 1. To find quoted strings. use one leading quote; Note 1: Note 2: 2. Use "#" in front of a line number reference; YOU TYPE FIND "HELLO FIND A$ or." " 99 #12345 (line number) 100 (not a line number) X(C) or." " FIND PRINT FIND "SUBS or." " FIND OPEN FIND X=X+2 FIND <;> (semi-colon key) FIND FIND . FIND FIND FIND "HELLO First characters in quoted string are signtlicant. "A" and "a" are considered different characters. FIND #1000 ZBASIC FINDS 01010 A=20:PRINT"HELLO THERE" 01022 Z=l:A$=B$:PRINTA$+B$ 01333 ABA$="goodbye" 05122 F=2:X=X+2+F/999 08000 GOTO 12345 02000 X=100 03050 A=1:T=ABS(X(C)/9-293+F) 03044 ZX(C)=4 00230 A=92:PRINTA 00345 "SUBSOO": CLS 03744 GOSUB "SUB500" 034000PEN"R",l,"FILE54",23 09922 F=2:X=X+2+F/999 Finds next occurrence Finds next occurrence To FIND data in remarKs or DATA statements use FIND REM ...• FIND DATA ... Note: If your version of ZBasic comes with a full screen editor. you may have other FIND or REPLACE options. See your computer appendix for specifics. Interactive Programming Environment 20 STANDARD LINE EDITOR SETTING CHARACTER WIDTH AND MARGINS FOR PROGRAM LISTINGS ZBasic has powerful formatting commands for making program listings to the screen or printer easier to read. WIDTH, WIDTH LPRINT and PAGE Since screen and printer widths vary depending on the hardware, the user may set the width of listing to either the printer or the screen. COMMAND WIDTH=O THROUGH 255 WIDTH LPRINT=O THROUGH 255 PAGE 0-255 (1), 0-255 (2), 0-255 (3) RESULT Sets Screen width for listings. Sets the printer width for listings. Formats LINES PER PAGE for printer. (1) Desired lines printed per page (2) Actual lines per page (3) Top Margin An example of using these commands for printer listings: To set the top and bottom margins to 3 tines each (to skip perforations) and the printer width to 132, type. WIDTH LPRINT=132: PAGE 60,66,3 NOTE: WIDTH, WIDTH LPRINT and PAGE may also be used from wHhin a program. Check the reference section for specifics. (In a program, the PAGE function returns the last line printed. The PAGE statement will send a form feed to the printer. A ZERO value disables all the functions above. AUTOMATIC LOOP AND STRUCTURE INDENTING For readabilHy, loops are automatically indented two spaces. When WIDTH is set, lines that wrap around will be aligned for readability as in line 10. Completed loops on the same line will show an asterisk at the beginning of the line as in line 120: lJ1il±...(without line numbers) CLS: REM THIS IS A LONG STATEMENT THAT CONTINUES ... FOR X~ 1 TO 10 GOSUB "Graphics" UNTIL G~3 NEXT "MENU n CLS END "Graphics": X=O DO X~X+16 PLOT X, 0 TO X, 767 UNTIL X>1023 *FOR X~ 1 TO 100: NEXT RETURN ~ IJSL (with tine numbers) 00010 CLS: REM THIS IS A LONG STATEMENT THAT CONTINUES ... 00020 FOR X~ 1 TO 10 00025 DO G~G+l 00030 GOSUB "Graphics" 00035 UNTIL G~3 00040 NEXT 00050 "MENU" 00060 CLS 00070 END 00080 "Graphics": X=O 00090 DO X~X+l6 00100 PLOT X, 0 TO X, 767 00115 UNTIL X>1023 00120*FOR X~ 1 TO 100: NEXT 00125 RETURN Note: LLlST*+ may also be used to do program listings to the Imagewriter or Laserwriter without linenumbers and with keywords highlighted as above. 21 Interactive Programming Environment ~,.,....~ . TM ASIC RUNNING ZBASIC PROGRAMS There are a number 01 ways to compile your programs with ZBasic. The most commonly used is a simple RUN. This lets you compile and debug interactively. Definitions: RUN COMPILE PROGRAM IN MEMORY AND EXECUTE The interactive mode is the easiest and fastest way to write and debug your programs. In many ways it is similar to a BASIC interpreter since you may: 1. RUN a program to check for errors 2. "BREAK out of a running program by pressing . 3. Return to ZBaslc to re-edlt the program. Interactive compiling is limited to available memory. II a program gets too large you will have to use one of the methods below. ZBasic will tell you when this is necessary with an "Out of Memory" message. "Most computers require TRON, TRONS, TRONB or TRONX to enable the key. Otherwise pressing may have no affect. RUN filename COMPILE PROGRAM FROM DISK AND RUN If a program gets too large for interactive compiling using just RUN, the program text may be saved (not in ASCII), compiled, and executed. This is possible because the text to be compiled is no longer resident and frees up memory for the compiled program. RUN" COMPILE PROGRAM IN MEMORY AND SAVE TO DISK RUN" filename COMPILE FROM DISK AND SAVE TO DISK Compiles the program Irom memory (RUN*) or disk (RUN'''filename'') and saves it to disk. A few moments later ZBasic will request the filename of the resulting compiled program to be saved (For IBM or CP/M use a .COM suffix. For TRS-80 use a /CMD suffix). This method frees up the most memory for the final program because the source code and ZBasic are no longer resident in memory. Compiled programs saved to disk are machine language programs and should be executed from the operating system like any other machine language program. See column three of the COMPILE MEMORY CHART. RUN+ COMPILE PROGRAM IN MEMORY AND SAVE AS CHAIN PROGRAM RUN+ filename COMPILE FROM DISK AND SAVE AS CHAIN See CHAINING PROGRAMS lor details. Running ZBasic Programs 22 RUNNING ZBASIC PROGRAMS DETERMINING MEMORY REQUIRMENTS MEM returns the available memory. (The table may vary on some versions). TYPE MEM: 00123 Text 49021 Memory 00000 Object 00000 Variable MEANING Program text memory used (source code). Free memory. Compiled program size of object code: Memory required for variables: "Type MEM immediately after compiling to get the correct totals. At other times the results of "Object and Variable" may be invalid. TYPICAL MEMORY USAGE BY "RUN" TYPE RUN RUN Program text is resident in memory with ZBasic, the compiled program, and the variables used by that program. The user may press when running the program, re-enter the edHor and debug any mistakes and re-compile. filename The program text is saved to disk and compiled from the disk to memory and RUN. Larger programs may be compiled this way because the program to be compiled is not in memory. COMPILE AND RUN A PROGRAM ~ IN MEMORY RUN* [filename RUN A COMPILED PROGRAM FROM DISK WWW ZBasic™ ZBasic™ Compiler Compiler Operating System Operating System "See your Computer Appendix to determine actual memory usage. 23 Running ZBasic Programs I The program is compiled from memory or disk and the resuning machine language program is saved to disk. The program is executed as a machine language program. When this program is executed the program text and ZBasic are no longer resident, leaving more memory for the program. RUNNING ZBASIC PROGRAMS ING OUT OF RUNNING PROGRAMS To make a program STOP when the key is pressed, use TRON, TRaNS, TRONB or TRONX. TRONB Checks at the start of every line to see if the key has been pressed. If pressed ZBasic returns control to DOS or to the Standard line editor (if in interactive mode). To disable TRONB use the TROFF command. TRONS Single step trace. CNTR Z to engage/disengage any other key to single step through the program a statement at a time. TRON Displays line numbers during runtime. TRONX Checks for the key at the beginning of that line only. NOTE: TRONX, TRON, TRaNS and TRONB may cause INKEY$ to miss keys. TROFF turns all the TRON functions off. All TRaNs will slow down programs AND increase size. USING INKEY$ TO SET BREAK POINTS You may also use INKEY$ to break out of a program. Put the following line in a program loop or wherever you may want to escape: IF INKEY$="S" THEN STOP Program will stop if the "S" key is pressed (any key could have been used). CASES WHERE BREAK WILL NOT FUNCTION Since ZBasic compiles your programs into machine language, there occurs certain situations where the key will be ignored. Remember; the key is checked only at the beginning of a line. The following example will not break: TRONB *FOR X~ 1 TO 10: X~l: NEXT This is obviously an endless loop (X never gets to 10). One obvious way around this is to avoid putting the entire loop construct on one line. Examples of other cases where the key is ignored; INPUT, LINE INPUT, DELAY and SOUND statements. Macintosh: = . =< COMMAND means: . may be preferable. MSDOS: means: . CP/M: means: : TRS-BO: means the key. Running ZBasic Programs 24 CHAINING 25 Chaining CHAINING ASIC CHAINING PROGRAMS TOGETHER Chaining is convenient when programs are too large for memory and must be broken into smaller programs. There are three ways to chain programs: • CHAIN WITH SHARED VARIABLES (GLOBAL or COMMON VARIABLES) • CHAIN WITH INDEPENDENT VARIABLES • CHAIN WITH SOME VARIABLES COMMON AND OTHERS NOT !l Macintosh CHAIN programs are limited to 28K. See "SEGMENT" and "SEGMENT RETURN" in the appendix for instructions on using the Macintosh memory manager. EXAMPLES OF CHAINING PROGRAMS WITH SHARED VARIABLES Programs that will share variables must have those variables defined in exactly the same order in all the programs being chained. ZBasic allows common or shared variables to be DEFINED within DIM statements (even if they are not arrays). CLEAR or CLEAR END should always be used to clear variables that are not shared. Examples: "STARTB" DIM A(10),100A$(100),Z,F5,W99 OPEN"I", 1, "PROGl lf RUN 1 : REM : REM Always execute this program 1st This is just a starter program "CHAIN1" REM THIS IS PROG1 TRONB: REM ENABLE KEY DIM A(10),100A$(100),Z,F5,W99 CLEAR END TV=23: PR=4 CLS: PRINT"THIS IS PROGRAM *1" "CHAIN2" REM THIS IS PROG2 TRONB DIM A(10),100A$(100),Z,F5,W99 CLEAR END ZZ=99: MYVAR=9191 PRINT "THIS IS PROGRAM *2" PRINT"Z=tl i Z, "F5= 1T iF5 PRINT"Z=lI;Z,"FS=":FS z=RND(10) :F5=RND(10) Z=RND (10) :F5=RND (10) PRINT"Z=";Z;" F5=";F5 PRINT"JUMPING TO PROGRAM *1" DELAY 2000 OPEN"I",1,"PROG1" RUN l:REM RUNs Prog1 PRINT"Z="iZi" FS=";F5 PRINT"JUMPING TO PROGRAM*2" DELAY 2000 OPEN"I",l,uPROG2 11 RUN 1: REM RUNs Prog2 Chaining 26 CHAINING COMPILING THE EXAMPLE PROGRAMS 1. RUN" STARTB and save as START Always RUN" a START program. This is a dummy program and is used only to get the chained programs started and contains the runtime routines. Any filename will do. 2. 3. RUN+ CHAIN1 and save as PROG1 RUN+ CHAIN2 and save as PROG2 NOTE: Always compile a START program using the RUN- command so that the chained programs have a runtime package. All chained programs must be compiled using RUN+. USE "DIM" TO DEFINE SHARED OR COMMON VARIABLES When chained together, both PROG1 and PROG2 will share variables defined on line 10 after the DIM. If F5 equals10 in PROG1, nwill still equal 10 when you RUN PROG2. Because variables "TV" and "PR" are unique to PROG1 and the variables "ll." and "MYVAR" are unique to PROG2, CLEAR END must be used to initialize them (they must be assigned values). Otherwise false values will be passed from other CHAIN programs. The example programs (PROG1 and PROG2) will chain back and forth until you press . Lines 80 and 90 are where the programs branch off to the other program. CLEARING NON-SHARED VARIABLES WHEN CHAINING Always use CLEAR END to clear variables that are not common between the programs. All variables that follow a CLEAR END will be unique to that program and will start out as null values. (1 ) 10 DIM 200A$ (100), 20 CLEAR END 30 DIM FR(900) 65B$ (300) (2) 10 DIM 200A$ (100), 20 CLEAR END 30 A9=10: Z=33 65B$ (300) In the above examples, the array variables A$ and B$ are shared and will contain the same values, while all other variables in the program following the CLEAR END statement will be null or zero and unique to that program. FR(n) is unique to program (1) and A9 and Z are unique to program (2). This statement may be used in non-chained programs as well. It is a handy way to null or zero out selected variables (the variables still exist, they are just set to zero or nUll). CHAINING PROGRAMS WITHOUT SHARING VARIABLES This is done exactly as the same as the previous examples for shared variables, except CLEAR is used on the first line of each chained program. In the example programs CHAIN1 and CHAIN2, add a line: 3 CLEAR Variables are not shared and CLEAR clears all variables (sets them to zero or nUll) each time a program is entered or chained. To selectively share some variables and not others use the CLEAR END statement described on the previous page and in the reference section. 27 Chaining ERRORS ASIC ERRORS There are different types of error messages. When errors are encountered during compilation, compiling is stopped and the offending line is displayed. This is a Compile Time error. Errors encountered during execution of a program are called Runtime Errors. COMPILE TIME ERRORS After typing RUN, ZBASIC compiles the program. If errors are encountered, ZBASIC will stop compiling and display the error on the screen along with the offending line (when compiling from disk using RUN "Filename" or RUN", ZBasic will stop compiling, load the Source Code, and LIST the line where the error occurred.) The Statement within the line and the line number will be displayed. The following program would cause ZBASIC to print an error during compile: 00010 00020 00030 00040 CLS PRINT "HELLO THERE MR. COMPUTER USER!" PRINT "I AM A COMPUTER" Z=Z+1: X=X+Z: PWINTX RUN Syntax Error in Stmt 03 at Line 00040 00040 Z=Z+1: X=X=Z: PW~ X NOTE: The error will be marked in some way depending on the computer system being used. The error marker indicates the general error location on the line where compilation stopped. To edit line 40 above type; EDIT 40 (or just comma). Fix the spelling of PRINT. ZBasic will often display the missing character H expected. 00010 INPUT"Enter a number" A$ RUN ";" expected error in Stmt 01 00010 INPUT"Enter a number"_A$ 00010 DIM A(10,10} 00020 A(X}=100 RUN "," expected error 00020 A(X_} in Stmt 01 at line 00010 at line 00020 Error Messages 28 ERRORS COMPILE TIME ERROR MESSAGES A compile time error is one that ZBasic encounters after you type RUN (while it is compiling your program). More often than not, the error is a syntax error. Edit the line to fix the error and type RUN again until all the errors have been deleted. COMPILE TIME ERROR MESSAGE DIM Error In Stmt... DEFINITIONS and POSSIBLE REMEDIES Only constants may be used in DIM statements: DIM A ( X) or Z ( A+4 ) are not allowed. If you have a need to erase and reuse dynamic string arrays see; INDEX$, CLEAR INDEX$, MEM. No DIM Error In .... Array variable being used was not Dimmed. Make sure variable is Dimmed correctly. Most interpreters allow ten elements of an array before a DIM is required. A compiler requires a DIM for every array. Overflow Error In ... DEF LEN or DIM string length is less than one or greater than 255. Also ij CLEAR =zero or CLEAR is too large. Check and adjust range. Syntax Error In •... Anything ZBasic does not understand. Check for spelling, formatting errors and syntax. The offending part of the line is often highlighted. Too Complex Error.•. String function is too complex to compile. Break up complex strings. Re·DEF Error ... An FN or LONG FN was defined twice. Variable Error In •.. String assignment problem: A$=123: Change to A$=STR$(123) Out of Memory Error In... Program is getting too large. Check large DIM statements and defined string lengths, or compile using RUN*. For very large programs you may wish to CHAIN programs together. Line # Error In... GOTO, GOSUB, ON GOTO, ON GOSUB, THEN or some other branching command can't find line number or a label. Mismatch error In... The assignment to a variable is the wrong type. Structure Error In .•. FOR wHhout NEXT, DO without UNTIL, WHILE wHhout WEND, LONG IF without END IF or LONG FN wHhout an END FN. Structure Error In 65535* Missing NEXT, WEND, END IF, END FN or UNTIL. If unable to find error quickly, LLiST the program. Structures are indented two spaces. Backtrack from the end of the program until the extra indentation is located. "?" Expected error In •.. ZBasic expected some form of punctuation that was not provided. Check cursor position in displayed line for error. *NOTE: Each ZBasic loop command must have one, and only one matching partner. Each FOR needs a NEXT, each WHILE needs a WEND, each LONG FN needs an END FN, each LONG IF needs an END IF and each DO needs an UNTIL. 29 Error Messages ERRORS RUN TIME ERRORS A Run Time (execution) error is an error that occurs when the compiled program is running (Object Code). The only Run Time error messages produced are: DISK ERRORS (Unless trapped by the user). See Disk Errors in the FILES section of this manual. OUT OF MEMORY ERROR when loading a compiled program saved to disk that is too large to execute in memory. ARRAY BOUNDS ERROR will be shown if the user configures ZBasic to check for this. This will slow down a program execution but is extremely handy during the debug phase of programming. You may turn this off after the program is completely tested. If access to an array element out of bounds is made, the program is stopped and the line number with the error is printed. STRING LENGTH ERROR. Some versions of ZBasic have a configure option that tells ZBasic to check for string assignments greater than the length allowed. This does slow execution speed and add memory overhead, so you may want to remove this error checking after the program is debugged. See your appendix for specifics. If an attempt is made to assign a string a value longer than its length, the program is stopped and the line number with the error is printed. RECOVERING FROM FATAL RUNTIME ERRORS Since ZBasic is a compiler and converts your code into machine language, there is always a risk that you may unintentionally enter an endless loop or hang up the system (the computer will not respond to anything) . In these instances you may not be able to get a response from the computer or be able to out of the program. The system may have to be reset or turned off, and back on again to regain control. To avoid losing valuable time, it is very important that you SAVE PROGRAMS and MAKE BACKUPS FREQUENTLY. See your computer appendix for possible alternatives. USING SINGLE STEP DEBUGGING TO FIND THE SOURCE OF "CRASHES" Should you encounter a situation where your program goes so far and then the system hangs-up or you get a system error of some kind that you just can' locate, there is a simple way to find the problem. First put a TRaNS and TRON in the program somewhere before the crash occurs. The TRON is added so that you can see a listing of the line numbers as the program executes. Press the space bar a statement at a time, keeping track of the line numbers as they go by. When the system crashes, make a note of the line number where the crash occurred and fix the problem in your program. Error Messages 30 ~ TERMS AND DEFINITIONS 31 Terms and Definitions TERMS AND DEFINITIONS ASIC TERMS and DEFINITIONS I use terms throughout this manual that may be unknown to you. The following terms are used to make reading the technical information easier. IMPORTANT NOTE "The Hand" is pointing out something of importance for that section. Read it! OPTIONAL Items [enclosed in brackets] are OPTIONAL. You mayor may not include that part of a command, function or statement. REPETITION Three periods (ellipsis) mean repetition ... when they appear after the second occurrence of something. PUNCTUATION Any punctuation such as commas, periods, colons and semi-colons included in definitions, other than brackets or periods described above, must be included as shown. Any text in Courier font, like this: COURIER FONT TEXT, means it is something for you to type in or a simulation of the way it will look on your screen like a program listing. COMPUTER APPENDIX Refers to the appendix in the back of this manual, ABOUT YOUR COMPUTER. SPECIAL32 The superscripted 32 means this command, function or statement only works on 32 bit computers. See your COMPUTER APPENDIX to see if your computer supports 32 bits. In this edition of the manual it refers to the Macintosh computer only. ABBREVIATIONS Frequently used line editor commands have convenient abbreviations: USE WITH ? PRINT DEL DELETE E EDIT L LIST USE WITHOUT , comma EDIT present line . period LIST present line / slash LIST next 10 lines ; (semi-colon) FIND next occurrence Terms and Definitions 32 TERMS AND DEFINITIONS DIFFERENT (KEY) STROKES FOR DIFFERENT FOLKS Since ZBASIC operates on many different computers, reference is made to the same keys throughout this manual. MANUAL USES YOUR COMPUTER MAY USE SPACE BAR BACKSPACE, DELETE, lEFT ARROW CONTROL C, COMMAND PERIOD RETURN, CARRIAGE RETURN ESCAPE, CNTRl UP ARROW, TAB CURSOR UP, PLUS KEY<+> CURSOR DOWN, MINUS KEY<-> Press the Key with that leller See your COMPUTER APPENDIX for variations or enhancements. LABELS ON LINES A line may have a label directly following the line number consisting of upper or lowercase, alphanumeric characters, or symbols in any order enclosed in quotes. The length of a label is limited to the length of a line. ZBasic recognizes only the first occurence of a label Line numbers are essential only for line EDIT(ing), MERGE, and APPEND. Statements like; LIST, EDIT, APPEND, GOTO, ON GOTO, GOSUB, ON GOSUB, DEL, etc., may use either labels or line numbers. List programs without line numbers by using LIST+ . SIMPLE STRINGS Quoted strIngs: "Hello", "This is within quotes" Any StrIng variables: A$, NAME$, FF$, BF$(23). Any of the following string functions: MKI$, MKB$, CHR$, HEX$, OCT$, BIN$, UNS$, STR$, ERRMSG$, INKEY$, INDEX$(9). COMPLEX STRINGS Complex strings are any combination of SIMPLE STRINGS. Any string operations containing one of the following commands: simple string + Simple string, lEFT$, R1GHT$, MID$, STRING$, SPACE$, UCASE$ ZBasic allows only one level of COMPLEX STRING expression. Complex strings MAY NOT be used with IF THEN statements. Convert all multi-level complex strings to simple strings: CHANGE COMPLEX STRINGS B$=RIGHT$(A$+C$,2) B$=UCASE$(LEFT$(A$,3» IF LEFT$(B$,2)="IT"THEN 99 !l TO SIMPLE STRINGS B$=A$+C$: B$=RIGHT$(B$,2) B$=LEFT$(A$,3): B$=UCASE$(B$) D$=LEFT$(B$,2): IFD$="IT"THEN 99 The Macintosh version allows much deeper levels of complex strings. 33 Terms and Definitions TERMS AND DEFINITIONS VARIABLE TYPES A$, A#, AI, A%, and A%(n,n) represent different variables. If no type is given, integer is assumed (unless configured differently by the user or changed with DEF DBL, DEF SNG or DEF STR). A and A% would be the same variable. Types: Integer variable 4 byte Integer (32 bit machines only) Single precision variable Double precision variable String variable % & I # $ EXPRESSIONS Throughout this manual reference is made to expressions. There are different types of expressions and the following words will be used to refer to specific expressions. DEFINITION OF EXPRESSION EXPRESSION refers to a combination of constants, variables, relational operators or math operators in either integer, floating point or string used to yield a numeric result. The following UNDERLINEP examples are EXPRESSIONS. CLEAR 2000 A= ~ TEST= XA 2 23* 5+1 IF X*3 4 <= Y*98 3 THEN IF A$>B$ AND B$<>C$ Z= 45*84 A R THEN GOTO 1000 Terms and Definitions 34 TERMS AND DEFINITIONS BYTE EXPRESSION A BYTE EXPRESSION always results in a number from 0 to 255. The expression may be floating point, integer or string, but if the actual result is more than 255 or less than 0, the final result will retum the posnive one byte remainder. ZBasic will not return an error if the calculation result is out of this range. INTEGER EXPRESSION An INTEGER EXPRESSION results in an integer number from -32768 to 32767. The expression may be floating point, integer or string, but if the actual result is more than 32767 or less than -32768, the final result will return the integer remainder which is incorrect. ZBasic will not return an error if the calculation result is out of integer range. Note: 32 bit computers have a Longlnteger range of ± 2,147,483,647. UNSIGNED INTEGER EXPRESSION An UNSIGNED INTEGER EXPRESSION always results in an unsigned integer number from 0 to 65535. The expression may be floating point or integer but if the actual result is more than 65535 or less than 0 the final result will return the remainder which will be incorrect. See UNS$ for displaying Signed integers as unsigned. Note: 32 bit computers have an unsigned Longlnteger range of 0 to 4,294,967,300. CONDITIONAL EXPRESSION Conditional expressions like A=B, A>B, A 65,535. The following examples will give you an idea how ZBasic evaluates expressions as Integer or floating pOint. (B=10) EXPRESSION B* .123 B* 23 B *23# B* 32000 B" 32000. SIN(B) B*0+65535 B*4800 RESULT 1.23 230 230 -11264 320000 -.54402111 -1 -17536 EXPRESSION EVALUATED AS FLOATING POINT (Decimal point force REAL) INTEGER FLOATING POINT (# forces Double Precision) INTEGER (Overflow error) FLOATING POINT (Decimal point) FLOATING POINT (Scientific Function) INTEGER (UNS$(-1)=65535) INTEGER (UNS$(-17536)=48000) "Note: You may configure ZBasic to assume floating point by setting "Optimize expressions for integer math" to "NO". See "Configure" in the beginning of this manual. PARENTHESES IN OPTIMIZED INTEGER EXPRESSION EVALUATION Parentheses are used to force an expression to be evaluated in a certain order. (See ORDER OF PRECEDENCE) ZBasic evaluates an expression by examining the outermost portions. In the expression: X*(2*(4.03+4))*5, the innermost portion of 4.03+4 is floating point, but since the outermost portions of X* and *5 are integer, the whole expression is returned as an integer. (B=10 in examples) EXPRESSION B*(32000+1) B*(32000.+ 1)+O! B+(.23)+1200 B+(.23)+ 1200. B+(200*(.001 A2)) B+200* .001 A2 B+ATN(2) RESULT -7670 320010 1210 1210.23 10 10.0002 11.107149 EXPRESSION EVALUATED AS INTEGER (Out of range error) FLOATING POINT (! forces REAL) INTEGER FLOATING POINT (period forces REAL) INTEGER FLOATING POINT FLOATING POINT (Scientific Function) The expression within each level of parentheses is still evaluated according to the precision in that level. NOTE: Newer versions of ZBasic may be configured to expression evaluation you are more used to. See "OPTIMIZE EXPRESSIONS FOR INTEGER MATH" above. Math Functions and Operators 38 MATH INTEGER AND FLOATING POINT DIVIDE SYMBOLS It should be noted that the Divide symbols I and \ take on different meanings depending on the type of expression evaluation being used: Optimized for Integer "YES" I = Integer Divide \ =Floating Point divide Optimized for Integer "NO" I =Floating Point Divide \ =Integer Divide SCIENTIFIC FUNCTIONS ZBasic offers several scientific and trigonometric math functions for making many calculations easier. SQR(expression) SQUARE ROOT of expression. Returns the number multiplied by itseH that equals expression. SQR(9)=3 LOG( expression) Natural LOGARITHM of expression (sometimes refered to as LN(n». Common LOG10 =LOG(n)/LOG(10) EXP( expression) Natural logarithm base value: e=2.7182818284590452356028747135266249775724 TO THE POWER of EXPRESSION. Inverse of LOG. LOG and EXP may speed up calculations dramatically in certain situations. Some comparative equalities using LOG and EXP: X'Y X/Y X"Y = = EXP (LOG(X) + LOG(Y» EXP (LOG(X) • LOG(Y» EXP (LOG(X) • Y) CONFIGURING SCIENTIFIC ACCURACY Scientific function accuracy may be configured up to 54 digits of accuracy (32 bit machines may be higher). DefauH accuracy is 6 digits. Scientific accuracy may be configured from two digits of accuracy, up to Double Precision accuracy (not necessarily the same as Single or Double precision). Precision is set when loading ZBasic under onfigure. Scientific math functions are complicated; the more digits of precision used, the longer the processing time required. See "Setting Accuracy" in the floating point section of this manual for information about accuracy, speed charts and memory requirements. SCIENTIFIC MATH SPEED When speed is more important than accuracy, configure DIGITS OF PRECISION (under configure at start-up) to 6 digits for DOUBLE, 4 digits for SINGLE and 6 digits for SCIENTIFIC. 39 Math Functions and Operators MATH TRIGONOMETRIC FUNCTIONS TAN(expr) TANGENT of expression in radians. TAN(A)=Y/X, X=YITAN(A), Y=TAN(A)*X ATN(expr) ARCTANGENT of the expression in radians. A=ATN (Y/X), Pi=ATN(1)«2 COS(expr) COSINE of the expression in radians. COS(A)=XlH, H*COS(A)=X, XlCOS(A)=H SIN(expr) SINE of the expression in radians. SIN(A)=Y/H, Y=H'SIN(A), H=Y/SIN(A) SQR(expr) SQUARE ROOT of expression. H= SQR(X'X+Y'Y) TAN, ATN, COS AND SIN return results in Radians. OTHER ZBASIC MATH FUNCTIONS FRAC(expr) Returns FRACTIONAL portion of an expression FRAC(23.232)=.232, FRAC(-1.23)=-.23 INT(expr) Returns expression as a whole number INT(3.5)=3, INT(99231.2)+.0=99231 SGN(expr) Returns the SIGN of an expression SGN(-23)=-1, SGN(990)=1, SGN(0)=0 ABS(expr) Returns the ABSOLUTE VALUE of an expression ABS(-15)=15, ABS(152)=152, ABS(0)=0 FIX(expr) Returns the whole number of an expression FIX(99999.23)=99999, FIX(122.6231 )=122 (Like INT but forces floating point mode) expr MOD expr Returns the remainder of an integer divide (MODulo) 9 MOD 2=1, 10 MOD 2=0, 20 MOD 6=2 RND(expr) Returns a random number between 1 and expr RND(10) randomly returns:1 ,2,3,4 ... 10 MAYBE Randomly returns -1 or 0. (50-50 chance) IF MAYBE PRINT "HEADS" ELSE PRINT "TAILS" Math Functions and Operators 40 MATH DERIVED MATH FUNCTIONS MATH FUNCTION TERM PI (ll)PI ZBaslc EQUIVALENT EQUATION ATN(l) «2 (accurate to double precision) EXP (1) LOG(X)/LOG(10) e e Common LOG 10 LOG Area of a CIRCLE Area of a SQUARE Volume of a RECTANGLE Volume of a CUBE Volume of a CYLINDER Volume of a CONE Volume of a SPHERE II R2 Y#=(ATN(l )<<2 )'Radius*Radius Y#=Length*Width Y#=Length*Width*Height Y#=Length*Length*Length Y#=(ATN(l )«2) *Height*Radius*Radius Y#=(ATN(l )«2) *Height*Radius*Radius/3 Y#=(ATN(l )<<2) *Radius*Radius*Radius*413 SECANT COSECANT COTANGENT SEC(X) CSC(X) COT(X) Y#=l/COS(X) Y#=l/SIN(X) Y#=lITAN(X) Inverse SINE Inverse COSINE Inverse COSECANT Inverse COTANGENT ARCSIN(X) ARCCOS(X) ARCCSC(X) ARCCOT(X) Y#=ATN(XlSQR(l-X*X» Y#=ATN(l )*2-ATN(XlSQR(1-X*X» Y#=ATN(l /SQR(X*X-l »+(X< 0)*(ATN(1 )«2) Y#=ATN(l )*2-ATN(X) Hyperbolic Sine Hyperbolic Cosine Hyperbolic Tangent Hyperbolic Secant Hyperbolic Cosecant Hyperbolic Cotangent SINH(X) COSH(X) TANH (X) SECH(X) CSCH(X) COTH(X) Y#=(EXP(X)-EXP(-X»/2. Y#=(EXP(X)+EXP( -X»/2. Y#=(EXP(X)-EXP(-X»/(EXP(X)+EXP(-X» Y#=2.1(EXP(X)+EXP(-X» Y#=2.1(EXP(X)-EXP(-X» Y#=(EXP(X)+EXP(-X»/(EXP(X)-EXP(-X» Inverse Hyperbolic Sine Inverse Hyperbolic Cosine Inverse Hyperbolic Tangent Inverse Hyperbolic Secant Inverse Hyperbolic Cosecant Inverse Hyperbolic Cotangent ARCSINH(X) ARCCOSH(X) ARCTANH(X) ARCSECH(X) ARCCSCH(X) ARCCOTH(X) Y#=LOG(X+SQR(X*X+ 1» Y#=LOG(X+SQR(X*X-l » Y#=LOG«1+X)/(1-X»/2 Y#=LOG«l +SQR(l-X*X»/X) Y#=LOG«l-SGN(X)'SQR(l +X*X»IX) Y#=LOG«X+ 1)/(X-l »/2 Derivative of LN(X) (Natural LOG) Derivative of SIN(X) Derivative of TAN(X) Derivative of COT (X) Derivative of ARCSIN(X) Derivative of ARCCOS(X) Derivative of ARCTAN(X) Derivative ofARCCOT(X) Derivative of ARCSEC(X) Derivative of ARCCSC(X) Derivative of ARCSINH(X) Derivative of ARCCOSH(X) Derivative of ARCTANH(X) Derivative of ARCCOTH(X) Derivative of ARCSECH(X) Derivative of ARCCOSECH(X) Y#=llX Y#=COS(X) Y#=1+TAN(X)A2 Y#=-(1+(1ITAN(X)A2))) Y#=SQR(l-X*X) Y#=-SQR(l-X*X) Y#=l/(l+X*X) Y#= lI(X*X+ 1) Y#= l/(X*SQR(X*X-l» Y#=-l/(X*SQR(X*X-l » Y#= l/SQR(l +X*X) Y#=-l/SQR(X*X-l) Y#=l/(l-X*X) Y#=-l/(X*X-l ) Y#=-l/(X*SQR(l-X*X» Y#=-l/(X* SQR(l +X'X» See DEF FN and LONG FN for adding these math functions to your programs. 41 Math Functions and Operators MATH ORDER OF PRECEDENCE In order to determine which part of a math expression is done first an order of precedence is used. The following math operators are performed in the this order. 1. ((1 st)2nd)3rd) Innermost expressions within parentheses always performed lirst 2 .• Negation (not subtraction) 3. NOT Logical operator 4. 1\ orr Exponential 5. ',I,\,MOD Multiply, Divide, Floating point Divide, MODulo 6. +,. Addition, Subtraction 7. =,>=,=>,<=,=<, >,<,<>,>< Conditional operators », « Shilts 8. AND, OR, XOR Logical operator ZBasic will calculate each operation of an expression in order 01 precedence, as delined by the table above. The linal result 01 an expression depends on the order of operations. II there are items 01 equal precedence in an expression, ZBasic will perform those operations from left to right. A#=2+5-3"6+1/4. This expression is performed in the following order; 3"6 2. 1/4. 3. 2+5 4. (2+5) - (3*6) 5. (2+5-(3*6}) + (1/4.) 1. A#=-10.75 Important Note: II expressions are optimized lor Integer Math, the decimal point alter the 410rces the result of the expression to be lIoating point. If the decimal point had been omitted, the result would be -11. See CONFIGURE. Math Functions and Operators 42 MATH USING PARENTHESES TO FORCE PRECEDENCE Parentheses are used in math expressions to force ZBasic to calculate that part of an expression first. If a math operation is enclosed in parentheses, which in turn is enclosed within parentheses, the innermost expression will be calculated first. A#=2+5-3*6+1/4. To force the 2+5-3 part of the above equation to be calculated first, and then muliply that by 6 and add 1 second, with division by 4 last, you would express the equation like this: A#=«2+5-3)*6+1)/4. The order of operations in this expression would be: 1. 2. 3. (2+5-3) (2+5-3) *6+1 «2+5-3)*6+1)/4. A#=6.25 Note: If Expressions are optimized for Integer Math; the outermost expression is used by ZBasic to determine whether the final result will be returned as integer or floating point. The decimal pOint after the 4 forces the expression to be calculated as floating point (although each expression within parentheses is evaluated as floating pOint or integer depending on the rules of expressions). If the decimal point had been omitted the result would have been 6. To use the standard rules of expression evaluation, set "Optimize Expression evaluation to Integer" to NO under configure. Math expressions will be done in the usual manner if this is done. 43 Math Functions and Operators MATH CONDITIONAL OPERATORS The conditional operators return: o (zero) (negative one) -1 If the Comparison Is FALSE If the Comparison Is TRUE A non-zero expression A zero expression Is always TRUE Is always FALSE These symbols are used for comparing expressions and conditions. <>,>< < > >=, <=, => =< Equal To Not Equal To Less Than Greater Than Greater Than OR Equal To Less Than OR Equal To Examples: (A$="HELLO" and A%=2000) CONDITIONAL EXPRESSION X=12<20 PRINT 23=45 IF 10>5 THEN PRINT "SURE IS" IF A%-2000>100-99 PRINT A% IF VAL(A$)=O THEN PRINT A$ PRINT 2>5, 3<5, 5>5 IF A%>120 THEN PRINT "OK" IF A%*5>=10000 THEN STOP IF A% PRINT "YES" PRINT 50>50 PRINT 50>=50 IF A%>30000 THEN PRINT "OK" X=l: IF X THEN PRINT "YEP" X=O: IF X THEN PRINT "YEP" X=77.321>77.320+1 X= "HELLO"="HELLO" IF IF IF IF IF A$="HELLO" PRINT "YES" A$="HELLLO" PRINT "YES" A$>"HEL" THEN PRINT A$ A$<>"GOON" THEN PRINT "NO" STR$(A%)=" 2000" PRINT "YES" RESULT X=-1 o SURE IS Nothing HELLO o -1 0 OK Program STOPs YES (Non zero is True) o -1 Nothing YEP Nothing o X=-1 YES Nothing HELLO NO YES Math Functions and Operators 44 MATH LOGICAL OPERATORS Zbasic makes use of the logical operators AND, OR, NOT, SHIFTS and XOR. These operators are used for comparing two 16 bit conditions and binary operations (except on 32 bit computers which can compare 32 bits). When used in comparative operations a negative one (-1) is returned for TRUE, and a zero (0) is returned for FALSE. Logical Operators condition AND condition condition OR condition condition XOR condition condition SHIFT condition NOT condition RETURNS TRUE(-1) if both conditions TRUE, else FALSE(0) TRUE(-1) if either or both is TRUE, else FALSE(0) TRUE(-1) if only one condnion is TRUE, else FALSE(0) TRUE(-1) if any non-zero value returned, else FALSE(0) TRUE(-1) if condition FALSE, else FALSE(0) if TRUE EQV (ernulate with) NOT (condition XOR condition) TRUE(-1) if both conditions FALSE or both conditions TRUE, else FALSE(0) IMP (emulate with) (NOT condition) OR condition FALSE(0) if first condition TRUE and second condition FALSE, else TRUE(-1) A~D eOOI.EAM "1 G ell" LOGIC 1 AND 1 o AND 1 1 AND 0 o AND 0 OB 1 OR 0 OR 1 OR o OR 1 0 0 0 1 1 1 = 1 1 0 0 0 AND 00000001 1Il1ll1ll1ll1111 00000001 AND 00000111 1Illlllllllll11l 00000111 OR 00000001 1Il1ll1ll1ll1111 00001111 OR 10000101 111l1ll1ll1ll111 10000111 XOR 00000001 1Illlllll1ll1ll1 00001110 XOR 10000101 llllllllllllllll 00000010 » 11111111 1Il1ll1ll1ll1ll1ll 1 III 00111111 « 00010111 1Illllllllllllllllll 10111000 XOB 1 XOR 1 = 0 o XOR 1 = 1 1 XOR 0 = 1 XOR 0 = 0 o StllEI », 255 » 23 « NOT NOT NOT 2 3 « 63 = 184 1 = 0 0 = 1 ~ NOT llllllllllllllll 00110011 NOT 1Il11111ll11 10000100 With the Macintosh, 32 bit integers may also be used with logical operators (Longlnteger&). 45 Math Functions and Operators NUMERIC CONVERSIONS INTEGER BASE and SIGN CONVERSIONS ZBasic has functions for converting integer constants to hexadecimal (BASE 16), octal (BASE 8), binary (BASE 2), unsigned integer and back to decimal (BASE 10). UNS$, HEX$, OCT$ and BIN$ are the functions used to convert an integer to the string representation of that SIGN or BASE. DECIMAL TO BASE CONVERSION OCT$(54386) ="152162" BINARY BIN$(255) ="0000000011111111" OCT$ (8) ="000010" BIN$ (512) ="0000000100000000" VAL (" &0030") =48 OCTAL VAL (" &0000011") =9 BINARY VAL ("&X0000000001100011") 99 VAL ("&HFFFF") =-1 (65535) VAL ("&0000030") =24 VAL("&X1111111111111111") =-1 (65535) HEX$(48964) ="BF44 U HEX$(32) ="0020" Q..CIAL. BASE TO DECIMAL CONVERSION HEX DISPLAYING UNSIGNED INTEGERS To display or print an unsigned integer number use UNS$. UNS$ returns the unsigned value of the number by not using the lellmost bit as a sign indicator: UNS$(-1)=65,535, UNS$(-2311 )=63,225 ZBasic interprets the integers, -1 and 65,535 as the same value. In BINARY format they are both 1111111111111111. The lell-most bit sets the sign of the number to positive or negative. This is the same unsigned integer format used by many other languages. !b The same holds true with Longlntegers, only 32 bits are used instead of 16 bits. The signed range is ± 2,147,483,647. The unsigned range is 0 to 4,294,967,293. See DEFSTR LONG in the appendix for ways of using 32 bit HEX$, OCT$, UNS$ and BIN$. Numeric Conversions 46 NUMERIC CONVERSIONS CONVERSION BETWEEN DIFFERENT VARIABLE TYPES ZBasic will convert variables from one type to another as long as the conversion is within the range of the target variable. DOUBLE or SINGLE PRECISION VARIABLE =INTEGER VARIABLE will convert exactly (unless single precision is set less then 6 digits). INTEGER VARIABLE=DOUBLE or SINGLE PRECISION VARIABLE will convert correctly if the double or single precision variables are within the integer range of -32,768 to 32,767 (unsigned 0 to 65,535). Any fractional part of the number will be truncated. Results outside integer range will be the rounded integer resuH, which is incorrect, and no error will be generated .. SINGLE PRECISION VARIABLE=DOUBLE PRECISION VARIABLE conversions will be exact to the number of significant digits set for single precision since the calculations are done in double precision. If the single precision defauH is 6 digits and double precision is 14 digits, the 14 digit number would be rounded down to 6 digits in this example (precision is configurable by the user). STRING VARIABLE=STR$(INTEGER, DOUBLE OR SINGLE PRECISION VARIABLE) will convert exactly. The first character of the string produced is used for holding the sign. If the number is positive or zero, the first character of the string produced will be a SPACE, otherwise the first character of the string will be a minus (-). INTEGER VARIABLE=VAL(STRING VARIABLE) will convert correctly, up to the first non-numeric character, if the string variable represents a number in integer range. Fractional portions will be ignored. Zero will be returned if not convertable. DOUBLE OR SINGLE PRECISION VARIABLE=VAL(STRING VARIABLE) will convert correctly within the range of floating point precision set by the user (rounding will occur if it is more digits than the set precision). a LonglNTEGER conversions are the same as regular integers with the exception that the range is much larger. Since all internal integer calculations are done in Longlnteger, conversions are simple. See DEFSTR LONG in the Macintosh appendix. 47 Numeric Conversions CONSTANTS ASIC CONSTANTS Constants are values used in expressions, variable assignments, or conditionals. In the following underlined program lines, the constants values remain constant, while values of A$, Z and T are variable. 10 PRINT"HELLO THERE": PRINT A$: z=z+T+2322 12 ZBasic uses both string (alphanumeric) and numeric constants. INTEGER CONSTANTS An integer constant is in the range of -32,768 to 32,767 (or unsigned integer in the range of 0 to 65,535). The BASE of an integer may be represented in Decimal, Hexadecimal, Octal or Binary. See "Numeric Conversions" for information about converting integers to and from HEX, OCTAL, BINARY and DECIMAL. MEMORY REQUIRED FOR INTEGER CONSTANTS Two bytes each in the same format as integer variables. ~ The Macintosh also has Longlnteger constants with a range of ±2,147,483,647. Longlnteger constants require four bytes memory each. Macintosh format of integer is the opposite of other versions. i.e. MSB is first and LSB is last. Constants 48 CONSTANTS FLOATING POINT CONSTANTS The range of floating point constants is ±1.0E-64 to ±9.999E+63". Constants may be expressed in scientific notation and/or up to 54 digits of significant accuracy. Floating point constants are significant up to the double precision accuracy set by the user. If the number of digits is greater than the accuracy of double precision, it will be rounded to that precision. If the double precision default of 14 digits is assumed, a constant of 1234567890.123456 will be rounded to 1234567890.1235. Constants may be forced as double or single precision by including a decimal point in the constant or by using # for double precision or ! for single precision. MEMORY REQUIRED FOR FLOATING POINT CONSTANTS ZBasic will store floating point constants in Binary Coded Decimal format (See Floating point variables memory requirements). This is based on the actual memory requirement of each constant, with a minimum memory requirement of 3 bytes per constant. To calculate the memory requirements of a specific constant use the formula: NUMBER of DIGITS In the constantl2+1=Bytes neededMinimum of 3 bytes required per Floating pOint constant. !l "The range of Double precision contants is E±16,383 (single precision remains the same for compatibility). To calculate the memory required use the following equation; Number of Digits/2+2=bytes needed (single precision is the same as above). Important Note: Some versions of ZBasic offer an optional high speed binary-floatingpoint option. While the speed of binary math packages is superior, the accuracy, range and memory requirements of binary math are much different from the standard BCD math described above. See the manual provided with the binary math package for details. STRING CONSTANTS String constants are alphanumeric information enclosed in double quotes with the number of characters limited by line length (255 characters maximum). "This is a string of characters" "12345 etc." "Hello there Fred" Any character except quotes may be included between the quotes. To include quotes in string constants use CHR$ (34). PRINT CHR$ (34) ; "HELLO" ;CHR$ (34) would print: "HELLO". To conserve memory when using many string constants see PSTR$. MEMORY REQUIRED FOR STRING CONSTANTS One byte plus the number of characters, including spaces, within the string constant. See PSTR$ for ways of conserving memory with string constants. 49 Constants VARIABLES TM ASIC VARIABLES The word VARIABLE describes the label used to represent alterable values. differentiates between four types of variables. VARIABLE TYPE STRING INTEGER SINGLE PRECISION DOUBLE PRECISION TYPE OF STORAGE ALPHANUMERIC INTEGER NUMBERS FLOATING POINT NUMBERS FLOATING POINT NUMBERS ZBasic ~ o TO 255 CHARACTERS ±32,767 E± 63 E± 63 !b In addition to the variable types described above this version also supports Longlnteger and an extended double precision range (single precision is the same as above). LONG INTEGER FOUR BYTE INTEGER ± 2 ,147,483,647 DOUBLE PRECISION FLOATING POINT NUMBERS E±16,383 Important Note: Some versions of ZBasic offer an optional high speed binary-floatingpoint option. While the speed of binary math packages is superior, the accuracy, range and memory requirements of binary math are much different from the standard BCD math described above. See the manual provided with the binary math package for details. VARIABLE TYPE DECLARATION Variable names may be followed by a type symbol: $ % ! # STRING VARIABLE INTEGER VARIABLE SINGLE PRECISION VARIABLE DOUBLE PRECISION VARIABLE If type is not given, integer is assumed (unless configured differently). A, A!, A$, A#, A(2,2), A#(2,2), A!(2,2) and A$(2,2) are considered different variables. Note: A and A% are the same variable if ZBasic is configured to Integer. & Type declaration for Longlnteger is; & Variables 50 VARIABLES DEFINING VARIABLE TYPES If you want to define variables beginning with a specific letter to be a specific type, use the DEF statement at the beginning of a program. DEFSTR A-M, Z DEFSNG A-C DEFDBL F, W DEFINT A, G, T-W Defines all variables starting with A thru M and Z as string variables. M and M$ are the same variable. Defines all variables starting with A thruC as single precision variables. C and C! are the same variable. Defines all variables starting with F and Was Double precision variables. F and F# are the same. Defines all variables starting with A,G and T thru W as integer variables. No % needed. A and A% are considered the same variable. Note: Even if a range of letters is defined as a certain type, a declaration symbol will still force it to be 1l:J.al type. For instance, if A-Z are defined as integer using DEFINT, A$ is still considered a string, and A# is still considered a double precision variable. a DEFDBL INT A-M Defines variables starting with A thru M as Longlntegers. No & needed. A and A& are the same variable. VARIABLE NAMES Variable names must have the following characteristics: Variable names may be up to 240 characters in length but only the first 15 characters are recognized as a unique variable. First character must be in the alpha range of A-Z, or a-z. Additional characters are optional and may be alphanumeric or underline. Symbols not allowed: ",~/+->=.~~< ~ .'{ -" -:;. ;,.'l Important Note: Some versions of ZBasic offer an optional high speed binary-floatingpoint option. While the speed of binary math packages is superior, the accuracy, range and memory requirements of binary math are much different from the standard BCD math described above, See the manual provided with the binary math package for details. DEFINING VARIABLES AS SINGLE OR DOUBLE PRECISION To force the preCision of a specific variable to be single precision, follow every occurrence of that variable with an exclamation point (!), To force a variable to be double precision, follow the variable name with a pound sign (#). To force ZBasic to define a range of variables as double or single precision, use the DEFDBL or DEFSNG statement: DEFDBL A-G Makes all variables beginning with A-G as Double precision. A# and A would be the same variable in this case DEFSNG C Makes all variables beginning with C as Single precision. C! and C would be the same variable. Note: Some verions of BASIC default to single preCision variables instead of integer. Use DEFSNG A-Z in programs being converted or configure to assume Floating Point. Also see "Optimize Expression Evaluation as Integer" under "Configure". Variables 54 VARIABLES SCIENTIFIC - EXPONENTIAL NOTATION ZBasic expresses large numbers like: 5121,121121121,121121121,121121121 like this: 5E+1I2I or 5E1I2I The plus sign (+) after the "E" indicates the decimal point moves to the right of the number. Ten places in this example. Technically: 5*10*10*10*10*10*10*10*10*10*10 or 5*10 Al0. ZBasic expresses very small numbers like: .1211211211211215 like this: 5E-12I6 A minus sign after the "E" indicates the decimal point is moved to the left of the number that many places, six in this example. Technically: 5/10/10/10/10/10/10 or 5*10 A (-6) . STANDARD NOTATION 9,123,000,000,000,000 -3,400,002,000,000,000,000 .000,000,000,000,000,000,011 -.000,012 SCIENTIFIC NOTATION 9.123E+15 (or E15) -3.400002E18 (or E+18) 1.1E-20 -1.2E-05 Note: Some BASICs use scientific notation wtth a "0" instead of an "En. (like 4.230+12 instead of 4.23E+12) ZBasic will read old format values correctly but will use the more common "E" when printing scientific notation. WHEN SCIENTIFIC NOTATION IS EXPRESSED Constants and variables will be expressed in scientific notation when the value is less than .01 or exceeds 10 digits to the left of the decimal point. You can force ZBasic to print all significant digits in regular notation with: PRINT USING See PRINT USING in the Reference Section of this manual. RANGE OF ZBASIC FLOATING POINT VARIABLES The range of floating point numbers, regardless of the accuracy configured is: ±1E-64 to ±9.9E+63.* The digits of accuracy are 14 digits for double and 6 digits for single (this is the default for most systems and may be set by the user). !l Double Precision exponent may range from E-16,384 to E+16,383. Single Precision exponent is the same for compatibility with 8 and 16 bit machines. 55 Variables VARIABLES OVERFLOW RESULTS If an expression results in a number greater then ±9.999E+63, a result of 9.999 ... E+63 will be returned. If the number is less then ±1.0E-64 the result will be zero. ZBaslc will not give an or underflow error. Check program logic so that numbers do not exceed floating point range. overflow BCD FLOATING POINT SPEED To obtain maximum speed out of BCD floating point math be sure to configure the digits of accuracy to: DOUBLE PRECISION SINGLE PRECISION SCIENTIFIC PRECISION = = = 6 4 4 Normally these setting are fine at 14 and 6 digits. The should only be changed when speed is extremely important. Converting equations to integer will greatly increase speed as well. These settings are important because ZBasic does all calculations in Double precision. Single precision is used for saving memory only. Important Note: Some versions of ZBasic offer an optional high speed binary-floatingpoint option. While the speed of binary math packages is superior, the accuracy, range and memory requirements of binary math are much different from the standard BCD math described above. See the manual provided with the binary math package for details. SINGLE AND DOUBLE PRECISION DIGITS OF ACCURACY The only difference between Single and Double Precision is that Single Precision holds fewer significant digits than Double Precision. ALL ZBASIC FLOATING POINT CALCULATIONS ARE PERFORMED IN DOUBLE PRECISION. The default digits of accuracy are 6 digits for Single Precision and 14 digits for Double Precision. The accuracy is configurable from 6 to 54 digits for Double and 2 to 52 digits for Single Precision.' ACTUAL NUMBER 12,000,023 .009,235,897,4 988,888 .235,023,912,323,436,129 9,999,999 .999,900,001,2 88.000,000,912,001,51 12.34147 SINGLE PRECISION" 12000000 9.2359E-03 988,888 .235024 10000000 88 12.3415 DOUBLE PRECISION" 12000023 9.2358974E-03 988,888 .23502391232344 9999999.9999 88.000000912002 12.34147 !b 'Defaults are 8 and 12 digits for the Macintosh. Both are configurable up to 240 digits. Variables 56 VARIABLES ROUNDING If the dign just to the right of the least significant digit is greater than 5, n will round up, adding one to the least significant digit. In the example for .009,235, 898,4 above, the last significant 6 dign number is nine, but since the digit after 9 is 7, the 9 is rounded up by one to 10 (and subsequently the 8 is rounded up to 9 to give us 9.2359E-03, which more accurately represents the single precision value. See "Configure" for ways of selting the rounding factor. NUMBER ####49 ####50 ####51 ####52 PEFAULT ROUNDING FACTOR IS; 49 .49+.49 = .98 which is less than one No Rounding .50+.49 = .99 which is less than one No Rounding .51+.49 = 1 which is equal to one Rounds up .52+.49 = 1.1 which is greater than one Rounds up This rounding option will not be available for optional binary floating point packages. CONFIGURING ACCURACY ZBasic allows the user to configure the digns of accuracy for Single, double or scientific precision functions (like LOG, TAN, SIN, etc). LIMITATIONS: Double precision must be at least 2 digits more significant than single. Digits of Accuracy must be In multiples of two (four with Macintosh). TYPE PRECISION SINGLE DOUBLE SCIENTIFIC MINIMUM DIGITS OF ACCURACY 2 DIGITS 6 DIGITS 2 DIGITS MAXIMUM DIGITS OF ACCURACY· 2 DIGITS less than Dbl. 54 DIGITS 54 DIGITS "Note: All floating point calculations are done In DOUBLE PRECISION. For programs where floating point speed is important be sure to set the digits of accuracy to: DOUBLE PRECISION SINGLE PRECISION SCIENTIFIC PRECISION =6 =4 =4 Important Note: Some versions of ZBasic offer an optional high speed binary-floatingpoint option. While the speed of binary math packages is superior, the accuracy, range and memory requirements of binary math are much different from the standard BCD math described above. See the manual provided with the binary math package for details. WARNING: Programs sharing disk files and CHAINED programs with single or double preCision variables must have the same accuracy configuration. If one program is set for 6 and 14 digits, and another program is set for 10 and 20 digits, the programs will not be able to read and write each othe~s files. ~ Configurable up to 240 digits. For hi-speed set Double to 8, single and scientific to 6. 57 Variables VARIABLES ACCURACY AND MEMORY REQUIREMENTS The number of bytes of memory or disk space required for storing single and double precison variables is dependent on the digits of accuracy. If you do not change the accuracy, ZBasic will assume 6 digits for single precision (which requires 4 bytes), and 14 digits for double precision (which requires 8 bytes)" When you change accuracy, disk files, variables, and constants memory requirements will change as well. The equation to calculate memory or disk file space required for single or double precision variables is: Digits of Accuracy I 2+1=Bytes required per Floating Point variable DIGITS of ACCURACY 2 digits 4 digits 5 digits 6 digits DISK FILE AND VARIABLE MEMORY REQUIREMENTS 2 bytes 3 bytes Will round odd digits UP to the next even number, 6 here 4 bytes (Single precision default if not configured by user) 14 digits 8 bytes (Double precision default if not configured by user) 52 digits 54 digits 27 bytes 28 bytes ~ • The Macintosh defaults to 8 digits for single (four bytes) and 12 digits for double (eight bytes). Digits of accuracy are configurable in multiples of four (instead of two as above). To figure memory: Digits of Accuracy 12+2=bytes required. ~ WARNING: Different ZBasic programs sharing files and CHAINED programs MUST be set to the same accuracy. Failure to do this will result in program errors, faulty data reads or program crashes. Important Note: Some versions of ZBasic offer an optional high speed binary-f1oatingpOint option. While the speed of binary math packages is superior, the accuracy, range and memory requirements of binary math are much different from the standard BCD math described above. See the manual provided with the binary math package for details. Variables 58 VARIABLES HOW BCD FLOATING POINT VARIABLES ARE STORED IN MEMORY Single precision default is 6 digits (4 bytes). Double precision default is 14 digits (8 bytes). To locate the address (memory location) of either a Single or Double precision variable: ADDRESS1=VARPTR(FLOATING POINT VARIABLE [(SUBSCRIPT(,SUBSCRIPT[ ,.. ])]) Single and Double precision variables are stored in Binary Coded Decimal format (BCD). Bit 765 ... 0 *ADDRESS1= Bit 7: Bit 6: Bit 5-0: ADDRESS2 ADDRESs3 ADDRESS4 ADDRESs5 ADDRESS6 ADDRESS? ADDRESs8 Mantissa sign (0=POSITIVE, 1= NEGATIVE) The exponent sign (0=E+, 1=E-) The exponent value (0 to 64) Digit 1 and 2 (Four bits for each digit) Digit3 and 4 Digit 5 and 6 (Single precison default) Digit 7 and B Digit9 and 10 Digit 11 and 12 Digit 13 and 14 (Double precision default) ADDRESS28 Digit 53 and 54 (Limit of significant digits) ~ :Single precision defaults to 4 bytes (six digits) and Double precision defaults to 8 bytes (12 digits). Macintosh computers use two bytes for mantissa and exponent for its high precision double precision variable type: ADDRESS1 & 2 Bit 15: Bi:14: Bil13-0 Bit 15 14 13... 0 Mantessa sign Exponent sign Exponent value 0-16383 Range of 32 bit double precision is ±1.0E-16,383 to ±9.999E+ 16,384. Note: Single precision range is the same on all machines Important Note: Some versions of ZBasic offer an optional high speed binary-floatingpoint option. While the speed of binary math packages is superior, the accuracy, range and memory requirements of binary math are much different from the standard BCD math described above. See the manual provided with the binary math package for details. 59 Variables VARIABLES ACCURACY VERSUS PROCESSING SPEED While ZBasic is capable 01 configuration to extremely high accuracy, you should be aware that calculation time is in direct relation to the number of digits of accuracy. The following chart will clarify the relationship of processing time to accuracy. ACCURACY versus PERFORMANCE ........... Math Relative \ EUD!0 AND ASC (A$) =0 THEN ASCII CODE=O STRING, NUMBER CONVERSIONS VAL STR$ CVI, CVB MKI$, MKB$ Converts a string to a number: X=VAL(A$) Converts a number to a string: A$=STR$ (43) Converts a condensed string to a number Converts numbers to condensed strings a See DEFSTR LONG for using CVI and MKI$ with Longlntegers. DEFINING STRING VARIABLES Use a $ symbol following a variable name to make it a string variable. A$ will always be a string variable because of the $. To define a range of variables beginning with a certain character to be string variables (so you do not have to use $ every time), use the statement DEFSTR: DEFSTR A-M DEFSTR X, Y, Z Makes all variables starting with A, B, C... up to M as string variables. A is the same as A$. Makes all variables starting with X,Y and Z as string variables. Z is the same as Z$. STRIN.G VARIABLE ASSIGNMENTS String variables are aSSigned alphanumeric values like this: A$="Hellothere" ART$="VanGogh"+" DaVinci" Z$=B$ Z$=B$+C$ Z$="Hello"+C$+TEST$ MID$(A$,2,3)="YES" 61 Variables (+) connects the strings (concatenates) Puts "YES" into A$ starting at position 2 VARIABLES STRING FUNCTIONS AND RELATED COMMANDS String variables are used for storing and manipulating character information. Here are some examples of ZBasic's string capabilities: STRING FUNCTIONS DIM 10 A$ DEF LEN 20 W$=LEFT$(A$,3) W$=RIGHT$(A$,1 ) B$=MID$(A$,4,2) MID$(A$,2,3)=B$ C$=CHR$(65) X=ASC("A") X=INSTR(2,A$,B$) A$=STR$(2345) X=VAL(A$) X=LEN(A$) INPUTA$ LlNEINPUTA$ A$=INKEY$ A$=UCASE$("Hello") X=VARPTR(A$) WRITE#1,A$;20 READ#1,A$;20 A$=STRING$(10,"#") PRINT SPACE$(4) SWAP A$,B$ LPRINTA$ PRINT A$ PRINT#2,A$ OPEN"R",1 ,F$, 129 KILL A$ A$=DATE$ A$=TlME$ A$=B$+C$ A$="HI"+"THERE" PSTR$ DEFINITION Sets the string variable A$ to a length of ten. Sets following strings to 20 character length. W$= 3 characters from the left of A$. W$= 1 character from the right of A$. B$= 2 characters from A$ beginning at position 4. Puts first 3 characters of B$ into A$ starting at position 2. C$= the character represented by ASCII 65 (letter A). X= the ASCII code of "A" (65). Looks for B$ in A$ starting at position 2, and makes X equal to the pOSition if found, otherwise X= zero. Makes A$ equal "2345". Makes X equal the VALue of A$ (2345 if above). X= the number of characters in A$ . Gets input from the keyboard and stores it in A$. Accepts any keyboard characters, stores them in A$ and terminates input only with the key. Makes A$= the last key pressed without using . Converts A$ to UPPERCASE. (A$ now equals "HELLO"). X= the memory address of the variable A$. Writes 20 characters of A$ out to the disk file#1. Reads 20 characters off the disk into A$. Makes A$ equal to "##########" . PRINTs 4 spaces. Make A$ equal B$ and B$ equal A$. Prints A$ out to the printer. Prints A$ to the screen. Prints A$ to disk file 2. Opens the random access file named F$. Erases the file specified by A$ off the storage device. Puts the date into A$ (MM/DD/yy) (Most systems). Puts the time into A$ (HH/MM/SS) (Most systems). Makes A$ equal to B$ plus C$ (Concatenates). Makes A$ equal to "HI THERE". Special command to avoid duplication of string constants. SPECIAL INDEX$ COMMANDS INDEX$ (n)="simple string" INDEX$="Simple string". INSERT A$ at INDEX$(n), moves up all other elements. INDEX$I (n)=A$ DELETE element (n) of INDEX$ and move up other elements. INDEX$D(n) Looks for A$ in INDEX$ (all) X equals element if A$ found. X=INDEXF(A$) else X equals -1. Look for "END" in INDEX$ starting at the 950th element. X=INDEXF("END",950) Set aside nnnnn bytes for INDEX$. CLEAR nnnnn Nullify the contents of the entire INDEX$ array. CLEAR INDEX$ Variables 62 VARIABLES STRING CONDITIONALS Strings may be compared using conditional operators just like numbers. The difference is that they are compared by the value of the ASCII code for that number. For instance, the ASCII code for "A" is 65 and "B" is 66. Therefore the expression "A"<"B" would be true (-1). See ASCII Chart in your computer manual. ASCII characters may vary from computer to computer and from printer to printer. Be aware that ZBasic differentiates between upper and lowercase characters. "a" is greater than "A" because the ASCII code for "a" is 97 and the ASCII code for "A" is 65. If you want ZBasic to look at a string variable as uppercase only, use the UCASE$ function to convert it. ZBasic "looks" at all the characters in a string when dOing comparisons. "Aa" is greater than "AA". "AAAAAAa" is greater than "AAAAAAA" etc. ZBasic will compare characters in a string to the last character in that string. CONDITION "RRRRR"<"S" "FRANK"= " FRANK " "abc">"ABC" TEST$="Hello" (If TEST$="Hello") "A">"B" "YES 11 ="yes" RESULT True (-1) True (-1) True (-1) True (-1) False (0) False (0) SIMPLE STRINGS Quoted string: "Hello", "This is within quotes" String variable: A$, NAME $ , FF$, BF$ (2,3) Any of the following string commands: MKI$, MKB$, CHR$, HEX$, OCT$, BIN$, UNS$, STR$, ERRMSG$, TIME$, DATE$, INKEY$, INDEX$(n) COMPLEX STRINGS May be any combination of SIMPLE STRINGS. String operations containing one of the following commands: simple- string + simplestring, LEFT$, RIGHT$, MID$, STRING$, SPACE$, UCASE$ would be a complex string. COMPLEX STRINGS MAY NOT BE USED WITH IF-THEN STATEMENTS. ZBasic allows only one COMPLEX STRING per statement. If you wish to perform more than one complex string at a time, simply divide the complex string expression into multiple statements like this: CHANGE complex strings B$=RIGHT$(A$+C$,2) B$=UCASE$(LEFT$(A$,3» IF LEFT$(B$,2)="IT" THEN 99 63 Variables IQ simple strings B$=A$+C$: B$=RIGHT$(B$,2) B$=LEFT$(A$,3): B$=UCASE$(B$) D$=LEFT$(B$,2): IFD$="IT" THEN 99 VARIABLES USING STRING VARIABLES EFFICIENTLY String variables will require 256 bytes of memory for each string used if the string lengths are not defined by the user. It is important to realize that extensive use of string variables or string array variables may require the user to define string lengths to avoid running out of memory. Note: Some BASIC(s) have what is referred to as "Garbage collection". ZBasic's method of storing strings NEVER creates time wasting "Garbage Collection". DEFINING THE LENGTH OF STRING VARIABLES ZBasic strings have a default length of 255 characters. This can cause excessive memory usage. To obtain maximum memory efficiency, there are two ways of defining the length of string variables and string array variables: DEF LEN = number (Numbers only. No expressions.) DIM number STRING VARIABLE, or number STRING ARRAY, ... DEFINING STRING LENGTHS WITH DIM DIM X$(10), 20 A$, Z$(5), 45 TEST$, 10 MD$(20,20) In this example the strings are allocated: X$( 10) 255 each element (255 is the default. 2816 bytes) A$ 20 (21 bytes) Z$(5) each element of Z$ as 20* (21*6=105 total bytes of memory used.) 45 (46 bytes) TEST$ MD$( 20, 20) each element of MD$(20,20) as 10. (21 * 21 *11=4851 total bytes of memory used.) * If no length is defined, the last given length in t.!lal. DIM statement is used (20 for A$ in this example). If no length was defined in that DIM statement then the DEFined LENgth is assumed (255 if the string length has not been previously defined) Note: Add one to the defined length of each string to determine the actual memory requirement of the string PLUS ONE for the LENGTH BYTE. Variables 64 VARIABLES DEFINING STRING LENGTHS WITH DEFLEN Another command for DEF(ining) the LEN(gth) of string variables is: DEF LEN = NUMBER (No expressions) (In the range of 1 to 255) Each string variable located liEIEB the statement will have that length, unless another DEFLEN or DIM statement is used. DIM A$(9,9), X(99), H#(999), DEF LEN=50:B$="HOPE" C$="HELLO" DEF LEN=100 ART$="COOL" DIM Coolness$(9) A$=ART$ 4Bull$ In the example: A$(9,9) allocated 255 characters for each array element (ZBasic automatically allocates 255 if length has not been defined). Bull$ allocated 4 characters. B$ and C$ allocated 50 characters each. ART$ allocated 100 characters. Coolness$ allocated 100 characters for each element. A$ allocated 100 characters. Note: The actual memory required for each string (each string element in an array) is the defined length plus one byte for the length byte. 65 Variables VARIABLES HOW STRING VARIABLES ARE STORED IN MEMORY ADDRESS=VARPTR(STRING VARIABLE [( SUBSCRIPT[ ,SUBSCRIPT[ ,....)))) ADDRESS ADDRESS+1 ADDRESS+2 Length Byte: Holds number of characters in the string. First character of the string variable Second character ADDRESS+n ADDRESS+255 ADDRESS+Defined Length Last character of the string variable Last address available for undefined string variable Last address available for defined string variable .>: ........,'-'~;"~"- ~ r::; '~<"'.". of,;>,'"' -",,"", '. WARNING 1: Strings should never be assigned a character length longer than the assigned length, If the length of A$ is 5 and a program line is executed that has: A$="1234567890", the characters "6" through "0" will overwrite the variables following A$, possibly causing system errors or faulty data. WARNING 2: If using INPUT to input strings with set length, always make sure the string length is at least one longer than the length being used for input. For most versions of ZBasic, no error is generated if string assignments exceed the length of the string. ~ See "Configure" in the Macintosh appendix for setting string length error checking. Variables 66 67 INDEX$ Variables INDEX$ ASIC SPECIAL INDEX$ STRING ARRAY INDEX$ is a special ZSasic string array with some powerful and unique capabilities. The following commands work with INDEX$ variables only. INDEX$ COMMAND INDEX$(n)=simple string MEANING Assigns a value to INDEX$(n) INDEX$ I(n)=simple string Move element n and all consecutive elements up one and INSERTsimple string at element n (the value in element 3 moves up to element 4...). Actually inserts the value into the array without destroying any other elements. INDEX$ D(n) DELETE element n and move all consecutive elements back down to fill the space (value in element 4 moves down to element 3 ... ). X=INDEXF(simple string [,start#] ) FIND simplestring in INDEX$. Segin looking at element START#. If found X=element number If not found X = -1. USING INDEX$ INDEX$ array variables may be assigned values like other string variables. To illustrate the power of INDEX$, the following values have been stored into INDEX$ elements INDEX$(O) through INDEX$(3) and will be used in the examples on the following pages: ELEMENT # INDEX$(O) = INDEX$(1) = INDEX$(2) = INDEX$(3)= MIA "AL" "SOS" "DON" "ED" INDEX$ Variables 68 INDEX$ INSERTING ELEMENTS INTO INDEX$ INDEX$I (n) To INSERT "CHRIS" into INDEX$, between "SOS" and "DON", you would use the commandlNDEX$ 1(2)="CHRIS". This instructs ZSasic to move "DON" and "ED" down and insert "CHRIS" in element 2. (INDEX$ 1(2)=A$ would also be legHimate) INDEX$ would now look like this: ELEMENT # INDEX$(O) = INDEX$(1) = INDEX$(2) = INDEX$(3) = INDEX$(4) = DATA "AL" "SOS" "CHRIS" "DON" "ED" DELETING ELEMENTS FROM INDEX$ INDEX$ 0 (n) To DELETE "SOS" from INDEX$ use the command INDEX$ D(1). This instructs ZSasic to delete element one, and move "CHRIS" and "DON" and all the other elements up to fill in that space. The INDEX$ array would now look like this: ELEMENT # INDEX$(O) = INDEX$(1) = INDEX$(2) = INDEX$(3) = J2AIA "AL" "CHRIS" "DON" "ED" FIND A STRING IN INDEX$ X=INDEXF(simplestring [,element n I) ZSasic will begin searching from element n (element zero if not specified) for the string specified by simple string. Examples: IF FOUND X=ELEMENT NUMBER IF NOT FOUND X=NEGATIVE ONE(-1) To FIND "DON" in the above list let's say that A$="DON". Using the command X=INDEXF(A$), X would return 2 to show that "DON" is in element 2 of INDEX$. To FIND "CHR" (part of "CHRIS"), you would use the command X=INDEXF("CHR"). X would return with the value of 1 since a match was found in the first three characters of "CHRIS". If you tried to FIND "RIS": X=INDEXF("RIS"), X would return wtth a value of -1 (negative one) since the FIND command begins the search at the 1irs1 character of each element, which MUST be significant ("C" must be part of the search). If the command had been INDEXF("CHRIS", 3), X would have equaled -1 since the search began at element 3 and "CHRIS" is at element 1 Hwould never find "CHRIS," 69 INDEX$ Variables INDEX$ INDEX$ MEMORY REQUIREMENTS INDEX$ variable elements use memory only if there are characters stored in that element and only as much memory as needed to hold those characters (plus one for length byfe). CLEAR nnnnn is used to allocate memory for INDEX$. CLEAR INDEX$ will clear (nullify) the present contents of INDEX$. INDEX$ LIMITATIONS INDEX$ may not be used wnh SWAP. USES OF INDEX$ INDEX$ is a valuable tool for disk indices, in-memory data bases, creating word processors, holding lists of strings with varying lengths and much more. INDEX$ is especially useful anyfime unknown string elements lengths are needed. USING INDEX$ FOR AN INSERTION SORT A good example of the power of INDEX$ is using it to create a perpetual sort. It allows you to add items to a list instantly and always have the list in order: CLEAR 10000: TRONB DO INPUT"Input String";A$: GOSUB "INSERTION SORT" UNTIL A$="END" <--- Type END to end inserting GOTO "PRINT LIST" "INSERTION SORT" REM N=Nurnber of items REM A$= New to string to insert B=N: S=O DO H=(B-S+1»>1. LONG IF A$ <= INDEX$(B-H) B=B-H XELSE S=S+H END IF UNTIL B=S INDEX$ I(B)=A$ N=N+1 RETURN "PRINT LIST" FOR X=l TO N PRINT INDEX$ (X) NEXT END INDEX$ Variables 70 INDEX$ HOW INDEX$ ARRAY VARIABLES ARE STORED IN MEMORY The INDEX$ array is stored in memory in one contiguous block. The distance between each element is the number of characters in the string plus one byte for the length byte of the string. WARNING: It is suggested that strings in INDEX$ not be manipulated with PEEK and POKE. Note: CLEAR is used on some computers to allocate memory for INDEX$. CLEAR INDEX$ is used to nullify the contents of INDEX$ !b This version has the ability to use up to ten INDEX$ arrays at the same time. See appendix for details. Also see MEM(-1) for determining memory remaining for INDEX$. 71 INDEX$ Variables ARRAY VARIABLES ASIC ARRAY VARIABLES An Array variable is a multi-celled variable followed by coordinates for specifying which cell is to be used. The following is an example of a one dimension string array with 101 elements. ARRAY ELEMENT YA!..!LE. NAME$(0)= NAME$(1)= NAME$(2)= NAME$(3)= "ABE" "ADAM" "ALEX" "AMOS" NAME$(100)= "ZORRO" Separate variables could be used for each value, like NAME1$="ABE", NAME2$=.. ADAM..... but typing a hundred different variables would become very tiring. Array variables are much easier to use when inputting, saving, loading, printing long lists, moving data around in a list, sorting lists of information, etc. This example shows how easy it is to print a complete list of the names in the array of variables. FOR X =0 TO 100 PRINT NAME $ (X) NEXT Computers are very good at manipulating large amounts of data and using regular variables to do this is very impractical. MULTI-DIMENSIONED ARRAYS ZBasic will allow arrays of 1, 2, 3 or more dimensions, depending on the amount of memory available on your computer. Array Variables 72 ARRAY VARIABLES TWO DIMENSION ARRAY EXAMPLE The following chart shows a two dimensional integer array; A(3,3). The number of elements are determined by the BASE OPTION that was configured when loading ZBasic. The default is Base 0: A(3,3) BASE 0 dimensions are 4 elements down (0,1,2 and 3) and 4 elements across (0,1,2 and 3). Base zero utilizes all the elements including the italicized. A(3,3) BASE 1 dimensions are 3 elements down (1,2,3) and 3 elements across (1,2,3) (not the italicized): TWO DIMENSION ARRAY A(O,O) A(t,O) A(2,O) A(3,O) A(O,t) A (1,1) A (2 ,1) A(3,l) A(O,2) A(l,2) A(2,2) A(3,2) A(O,3) --- A (2,3) A (3,3) A (1, 3) This array was DIM(med) A(3,3). A(1,3) represents the cell underlined above. Accessing a cell only requires giving the correct coordinate after the variable name. Variables, constants or expressions may be used in specifying coordinates: A(3,2), A(X,Y), A(2,X) , A(X*2/3,2+Y) . BASE OPTION Zero is considered an element unless you set the BASE OPTION to one when configuring ZBasic. See "Configure" for more information about setting the Base option. The default BASE is zero. DEFINING THE DIMENSIONS OF AN ARRAY All variable arrays ~ be DIMensioned at the beginning of a program. When you RUN a program, memory is set aside for the array based on the number of elements you have DIMensioned. An example of DIM: DIM A%(10,10,10), MI(5), A! (9,7), B$(10), 5Coo1$(20) Only numbers may be used within DIM statement parentheses. The following DIM expressions are /IIegal : DIM A(X), 73 A"ay Variables A(2*X) , A(FR) • . ~" ~ .)..' ARRAY. VARIABLES " ,~ ~ , "," , ,\ HOW ARRAYS USE MEMORY The following chart shows how to calculate the memory requirements of the arrays DIMensioned above with a BASE OPTION of zero (default value). ARRAY A%(10,10,10) A#(5) Ai (9,7) B$(10) Cool$(20) IY.M INTEGER DOUBLE PREC. SINGLE PREC. STRING STRING Bytes per Element 2 8 4 256 6 How to Cal!;ulat~" 11'11'11'2 6'8 10*8*4 11'256 21*6 Memory Reg!,!lreg 2662 Bytes 48 Bytes 320 Bytes 2816 Bytes 126 "Note: If you use a BASE OPTION of ONE, you will not need to add one to the dimension. For instance, in the first example the way to calculate the memory required would be: 10*10*10*2. Also see DEF LEN and DIM under STRING VARIABLES for info about defining string lengths. Macintosh also has Longlnteger arrays. Each element takes 4 bytes. ARRAY BOUNDS CHECKING During the initial stages of writing a program, it is a good idea to configure ZBasic to check array bounds in runtime. See "Configure" for more information. OUT OF MEMORY ERROR FROM DIMMING It is necessary to have an understanding of how arrays use memory. DIMensioning an array larger than available memory will cause ZBasic to give an OUT OF MEMORY error at Compile time or RUN time. When calculating large arrays be sure to check if memory is sufficient. Array Variables 74 ARRAY VARIABLES PRINTING ARRAYS Arrays were designed to make manipulating large lists of data easy. The following routines print the values of ARRAY(50) and/or ARRAY(50,5) to the screen (Substitute LPRINT for PRINT or use ROUTE 126 to print to the printer). Use AUTO or make your own line numbers. It does not matter which numbers are used. "One Dimension array PRINT routine" DIM ARRAY (50) FOR X=0 TO 50 PRINT ARRAY(X) NEXT "Two Dimension array PRINT routine" DIM ARRAY (50, 5) FOR X=0 TO 50 FOR X2=0 TO 5 PRINT ARRAY(X,X2), NEXT X2 PRINT NEXT X MAKING AN ENTIRE ARRAY ONE VALUE The following examples show how to make an entire array (ARRAY(50) or ARRAY(50,5)) equal to a certain value. This would be convenient if you wanted to zero out an array or have all the elements start the same values. "One Dimension array ASSIGNMENT routine" DIM ARRAY (50) FOR X=0 TO 50 ARRAY(X)=VALUE NEXT "Two Dimension array ASSIGNMENT routine" DIM ARRAY (50, 5) FOR X=0 TO 50 FOR X2=0 TO 5 ARRAY(X,X2)=VALUE NEXT X2 NEXT X 75 Affay Variables ARRAY VARIABLES USING ARRAYS FOR SORTING Arrays are also very convenient for organizing large lists of data alphabetically or numerically, in ascending or descending order. The first program below creates random data to sort. This program is for example purposes only and should not be included in your programs. These programs are Included on your master disk. Follow the GOSUB with the label of the sort routine you wish to use (either "QUICK SORT" or "SHELL SORT"). Any line numbers may be used. These sort routines may be copied and saved to disk (using SAVE' or +) as a subroutine to be loaded with APPEND. See APPEND. ""S""OJ,JR.... T..... ,B""A"S'-__ FILL ARRAY WITH RANDOM DATA FOR SORTING _ _ DIM SA(500), ST(30,1): REM ST (30,1) FOR QUICK SORT ONLY, NI=500: REM Change DIM 500 and NI if sort larger FOR X=OTO NI SA(X)=RND(1000) : REM Stores random numbers for sorting NEXT PRINT"Start Time:";TIME$ GOSUB "QUICK SORT": REM Or SHELL SORT PRINT"Finish Time:";TIME$ FOR X=NI-10 TO NI PRINT SA (X): REM Print last to make sure SORT worked. NEXT END >i!S!lH!:!EL!:!L"".A~PC1P=--_ _ _ _ _SHELL-METZNER SORT_ _ __ "SHELL SORT" Y=NI "Zl" Y=Y/2 REM Sort complete IF Y=0 THEN RETURN: Z99=NI-Y FOR K9=1 TO Z99 I=K9 "X2" E2=I+Y REM: In line below change <= to >= for descending order IF SA ( I ) <= SA (E2) THEN "x3" ELSE SWAP SA ( I ), SA (E2) I=I-Y IF 1>0 THEN "X2" "x3" NEXT K9 GOTO "Zl" END Note: To sort string arrays instead of numeric arrays add a "$" to the appropriate variables. Also see "Perpetual Sort" using INDEX$ in the previous chapter. Array Variables 76 ARRAY VARIABLES ___________ auCK~_____________ ~au~I~OUW~uP "QUICK SORT" REM Improved Quicksort submitted by Johan Brouwer, Luxembourg. REM Thanks for the submission, Johan. SP=O:ST(O,O)=O:ST(O,l)=O ST(O,l)=NI DO L=ST(SP,O): R=ST(SP,l) :SP=SP-l DO LI=L: Rl=R: SA=SA«L+R)/2) DO WHILE SA(LI)< SA LI=LI+l WEND WHILE SA(RI»SA RI=RI-l WEND LONG IF LI<= RI SWAP SA(LI), SA(RI) LI=LI+l:RI=RI-l END IF UNTIL LI>RI LONG IF (R-LI) >(RI-L) LONG IF L DD ·0 0 Notice the variation in quality. Programmers porting programs over to other machines should keep the resolution of the target computer in mind when creating programs. 83 Graphics GRAPHICS MORE GRAPHIC EXAMPLES AT DIFFERENT RESOLUTIONS Quality deteriorates as graphic complexity increases and screen resolution decreases. although usually the lower the resolution the faster the execution speed. In this line example you can see the variation of quality. The ZBasic statement to create all the lines in the first example was the same: PLOT 60,660 TO 1000, HIGH RESOLUTION 10: LOW RESOLUTION CHARACTER Additional examples of more complex graphics forms in different resolutions: HIGH RESOLUTION CHARACTER Graphics 84 GRAPHICS MODE ZBasic offers different modes of text and graphics output depending on hardware and model. The ability to change modes allows you to simulate the output for different machines. Syntax: MODE expression The following chart gives the modes for some popular microcomputers, and illustrates how modes are grouped according to resolution. MODE CHART MSDOS Mode number 0 1 2 3 4 5 type APPLE lie, IIc Text Graphic character 40x24 character 32x16 40x25 40x40 none 40x48 64x16 128x48 80x25 character 80x24 character 32x16 character 80x25 80x25 none 80x48 64x16 128x48 40x24 character 32x16 character 40x24 280x192 64x16 128x48 80x24 character 32x16 character 640x200 80x24 560x192 64x16 128x48 character 40x24 character 32x16 640x240? Bottom 40x48 64x16 128x48 80x24 character 32x16 character 80x48 64x16 128x48 character 32x16 character 80x25 40x25 6 80x25 7 8 80x25 9 40x25 10 11 12 13 14 15 80x25 40x25 80x25 80x25 40x25 character 320x200 character 40x40 character 80x25 Bottom character 80x24 320x200 80x25 character 80x25 640x200 MACINTOSH Text Graphic Many Font styles and sizes here! SEE Macintosh APPENDIX Bottom 80x24 Bottom 280x165 Normally 80x24 Graphics Graphic character 128x48 character 32x16 character 560x165 64x16 128x48 CP/M-SO Text Text 64x16 Graphic SEE Z80 APPENDIX Note: Check your computer appendix for variations. 85 I, III 40x25 Text Graphic TRS-SO Be sure to read the appropriate appendix for exact mode designations. GRAPHICS PLOTTING POINTS AND LINES To set a specific screen position(s) to the current color or to draw lines from one screen position TO another, TO another... , or to draw from the last screen position used (in another ZBasic statement) TO another... PLOT [TO] horizontal, vertical [TO [ horizontal, vertical [TO ...]]]] PLOT draws with the last color defined by COLOR. COLOR=O is the background color of most computers, while COLOR=-1 is the foreground color. If you have a system with a black background, COLOR -1 is white and COLOR 0 is black. See COLOR in this chapter. PLOT 209 . 0.0 PLOT TO !J!l7 . 'III1111.IIIIIIIIIIIIIIIIIII'IIIIIIJII"'" . . : II 209 1023 PLOT 209,304 a/37 0.0 .-'-~u..u.u.J..LLJ..J.1.I.J~u..u.LU..LLJ..~L.Cu.LU..u..c:. 1023 ·· .. . . .. 643: ': ..................................~~ ~. ~ ~ } ... : : > : ·· " PLOT 967,643 . .. PLOT :!09, 30~ TO 987, 643 TO :322,742 ,304.: ........ 304,; .•.•••••. ~ .••• 322 ': . .. . : , 643 •. : ••..•••.•.•.•.• .:............... ·· · ... : .: . . 742 .• : •.•...•.•.•.•.••.. 767 As with all other graphic commands, PLOT uses the standard ZBasic coordinates of 1024 x 768 regardless of the computer being used. When TO is used, ZBasic will plot a line from the first position TO the next position, TO the next position ... EXAMPLES OF PLOTTING PLOT 4,5 RESULT Turns on the pixel at the graphic position 4 positions over and 5 positions down PLOT 0,0 TO 1023,767 Plots a line from the upper left corner of the screen down to the lower right corner of the screen. PLOT TO 12,40 Draws a line from the last position used with the PLOT command TO the point on the screen 12 positions over by 40 pOSitions down. PLOT 0,0 TO 400,0 TO 0,300 TO 0,0 Plots a triangle in the upper left corner of the screen. NOTE: All the examples above will plot in the current COLOR. Graphics 86 GRAPHICS POINT POINT (horizontal coordinate, vertical coordinate) Returns the COLOR of the pixel at the ZBasic coordinate. Point is available on many computers to inquire about the COLOR of a specific screen graphic position (some computers do not have the capability to "see" pixels). As with other commands, ZBasic Device Independent Graphic coordinates may overlap pixels. The following illustration shows the pixels and color types associated with them. In this example: I2l=BACKGROUND (WHITE) ZBasic coordinates ~0123 ... o 1 2 3 1 =FOREGROUND (BLACK) P0 INT {h, V ) ~----------EXAMPLES * POINT (0,0) =1 POINT (1,0) =1 POINT (0,2) =0 POINT (2,1) =0 POINT (2,2) =1 Screen Pixel • Note: Point returns COLOR of coordinate As with all other ZBasic graphic commands the standard device independent coordinate system of 1024 x 768 is used. Note: The ZBasic device independent coordinate system specifies poSitions on the screen, not pixels. See below for ways of setting your system to actual pixel coordinates, if needed. Macintosh and MSDOS systems can be set to use pixel coordinates with COORDINATE WINDOW. See Apple appendix for ways of configuring to pixel coordinates. Z8D see your hardware technical manual and the Z80 appendix for specifics of your machine. 87 Graphics GRAPHICS CIRCLE CIRCLE [FILL] horizontal, vertical, radius CIRCLE draws a circle in the currently defined COLOR and RATIO. COLOR=O is the background color of most computers, while COLOR=-l is the foreground color. If you have a system with a black background, COLOR -1 is white and COLOR 0 is black. See RATIO for ways of changing the shapes of circles. Also see CIRCLE TO and CIRCLE PLOT for creating PIES and ARCS. If FILL is used, the circle will be a solid ball in the current color. CIRCLE 850 1023 324 ~ d. CIRCLE FILL 850, 624, 50 r~. ~~~...................... 624 .. ............... . • .. 674 .: ............ ........... ..... ....... ... ......... -- . '" -. ra~~us 767 As with all ZBasic graphic commands, the Device Independent Graphic Coordinates of 1024 x 768 are the default. ~ FILL is taken from PEN pattern; PEN .... n. Where n is one of the pen patterns used under the control panel. Quickdraw circles are also available using toolbox calls. See appendix. Graphics 88 GRAPHICS GRAPHICS THAT EXTEND OFF THE SCREEN (CLIPPING) Jf coordinates are given that exceed the limits of the ZBasic screen coordinates, that part of the image exceeding the limtis will be "CLIPPED". It is still permissible to use these numbers and in many cases H is important to have them available for special effects. CIRCLE, or other graphic commands like PLOT, BOX, PRINT% etc., wHh coordinates that are off the screen but are within the limits of -8191 to +8192 are permissible and that part out of range will be "Clipped": GRAPHICS THAT EXTEND OFF THE SCREEN 0,0 1023 CIRCLE 1023,767,687 767 As with all ZBasic graphic commands, the Device Independent Coordinates of 1024 x 768 are used. 89 Graphics GRAPHICS SEGMENT OF A CIRCLE (PIE) 512 0,0 1023 SEGMENT OF A CIRCLE (ARC) 512 0,0 .. · ,.................. .~t ......... .. ···· 383 . ! 383 .; r~ ··········cr····· CIRClE 512,383,320 PLOT 192,84 CIRCLE 512,383,320 TO 192, 84 767 767 '. J~\,' 1023 t"'IIIIIIIIIIIIIIIIIIIIIIIIIIIII"I","1 CIRCLE 512,383,320 PLOT 80,32 CIRClE 512,383,320 TO 80,32 ,'~t, f , ::t,. SEGMENT OF A CIRCLE 0 " . •,·;1 (PIE) To draw an enclosed segment of the circumference of a circle (PIE), use this syntax: CIRCLE h, v, radius TO starting BRAD degree, number of BRADs (counter clockwise) CIRCLE draws with the last color defined by COLOR. COLOR=O is the background color of most computers, while COLOR=-1 is the foreground color. If you have a system with a black background, COLOR -1 is white and COLOR 0 is black. See COLOR in this chapter. SEGMENT OF A CIRCLE (ARC) To draw a segment of the circumference of a circle (an ARC) use the syntax: CIRCLE h, v, radius PLOT starting BRAD degree, number of BRADs (counter-clockwise) CIRCLE draws with the last color defined by COLOR. COLOR=O is the background color of most computers, while COLOR=-1 is the foreground color. If you have a system with a black background, COLOR -1 is white and COLOR 0 is black. See COLOR in this chapter. Note: 256 BRADS=360 DEGREES. See the BRAD chart on the next page. As with all ZBasic graphic commands, the standard coordinates of 1024 x 768 are used. l!o FILL may be used with the CIRCLE FILL x,y,r, TO s,n statement on this version. The FILL pattern is taken from PEN pattern; PEN .... n. Where n is one of the pen patterns used under the control panel. Quickdraw arcs are also available using toolbOX calls. Graphics 90 GRAPHICS BRADS Brads are used with ZBasic CIRCLE commands to determine a position on the circumference of a circle. Instead of DEGREEs of zero to 359, BRADs range from zero to 255. (Starting at 3 O'clock going counter-clockwise.) ZBaslc™ BRAD CHART 112 128 142 Degrees INSIDE circle Brads OUTSIDE circle 192 Methods of Measuring Angles and Circles RADIANS DEGREES GRADS BRADS ~Ej~Ej Total Radians Total Degrees Total Grads Total Brads 6.2831852 360 400 256 CONVERSIONS FROM ONE TYPE TO ANOTHER GRADS=10 * DEGREES/9 RADIANS=DEGREES* ATN(1 )/45 RADIANS=9*GRADS/10 GRADS=RADIANS*63.66197723 RADIANS=BRADS/40.7436666 GRADS=BRADS*1.5625 DEGREES=RADIANS*45/ATN(1) DEGREES=BRADS*1.40625 DEGREES=GRAD/63.66197723 BRADS=DEGREES/1.40625 BRADS=GRADS/1.5625 BRADS=RADIANS*40.743666 Also see USR8 and USR9 for high-speed Integer SIN and COS. 91 Graphics GRAPHICS RATIO ZBasic allows you change the aspect ratio of any CIRCLE, ARC or PIE with the graphic statement RATIO: RATIO Width (-128 thru + 127), Height (-128 thru +127) (See CIRCLE) RATIO 0,0 :e ~ ~ 767 Examples: Ratio settings are executed immediately and all CIRCLE commands will be adjusted to the last ratio. +127 +64 +32 (2) -32 -64 -96 -128 2 1.5 1.25 (2) .75 .5 .25 o times normal times normal times normal Normal proportion times normal times normal times normal (no width or height) !b Quickdraw circles use box coordinates to set circle shape. See toolbox section of appendix. Graphics 92 GRAPHICS BOX Box is used for drawing rectangles in the current color. The size of a rectangle is specified by giving the coordinates of opposing corners. BOX [FILL] M, v1 TO h2, v2 h1, v2 h2, v2 The first corner coordinate of the BOX. The opposite corner coordinate of the BOX. The BOX is plotted in the current color. If FILL is used the BOX will be filled with the current COLOR. BOX 209 0,0 II I I I I I I I I : II 465 - .i • I I I I II I I II' 843 I" 1'1 I 1 ' 1 ' 1 " " I BOX 209,3·04 TO 465; ~ 987 ~I'" . . I I I 1'1': , 1023 ~ :1::0.• • • • • B~X 843~'134 FILL TO 987,643 : / 767 As with all ZBasic graphic commands, the device independent coordinates of 1024 x 768 are used. Notice the different quality of BOXes on various computers and different modes. !!b FILL is taken from PEN pattern; PEN .... n. Where n is one of the pen pattems used underthe control panel. Quickdraw boxes are also available using toolbox calls. See appendix. 93 Graphics GRAPHICS FILL FILL Horizontal expression, Vertical expression The fill command will fill a screen position from the upper left most position it can reach without finding a color other than the background color, and down to the right and to the left until a non-background color is found. This command will not function on computers lacking the capability to read screen pixel coordinates. See computer appendix. Example: F~ll BEFORE AFTER FILL 0,384 etO As with all ZBasic graphic commands, the Device Independent Coordinates of 1024 x 768 are used. Also see CIRCLE FILL and BOX FILL. !b FILL pattern is taken from PEN pattern; PEN""n. Where n is one of the pen patterns used under the control panel. A much faster way to fill screen segments is using Quickdraw FILL with polygons, circles and rectangles. See appendix. Graphics 94 GRAPHICS COLOR COLOR is used to signify the color to be used with PLOT, CIRCLE, BOX and FILL. All systems support zero and -1 for background and foreground colors (BLACK and WHITE respectively on most systems). COLOR [=) expression The following chart represents the color codes for IBM PC and compatible systems with color graphics. Colors codes vary significantly from system to system so check your computer appendix for variations. IBM pc and Compatible COLOR codes 0= BLACK 8= GRAY 1= BLUE 9= LIGHT BLUE 10= LIGHT GREEN 2= GREEN 11= LlGHTCYAN 3= CYAN 4= RED 12= LIGHT RED 5= MAGENTA 13= LIGHT MAGENTA 14= YELLOW 6= BROWN 7= WHITE 15= BRIGHT WHITE Color intensities will vary depending on the graphics hardware and monitor being used. Check your computer appendix for variations. & While most Macintoshes are black and white, COLOR is useful when printing to the ImageWriter II with a color ribbon. See appendix for details. CLS, CLSLlNE, CLSPAGE CLS is used to clear the entire screen of graphics or text quickly. Optionally, the text screen may be filled with a specific ASCII character (in most modes). Check your computer appendix for variations. CLS [ASCII code:O-255 ) CLS LINE is used to clear a text line of text and graphics from the current cursor position to the end of that line. CLS LINE CLS PAGE is used to clear a text screen of text and graphics from the current cursor poSition to the end of the screen. CLS PAGE See Computer Appendix 95 Graphics GRAPHICS BUSINESS GRAPHS, CHARTS ETC. Business graphs and charts are easily accomplished with ZBasic graphics. An added benefit is that the graphs are also easily transported to different computers. HIGH RESOLUTION LOW RESOLUTION CHARACTER ~1m/"/ ... JDl . 1 2.2'tS ffJ' 5 • To further assist you in porting graph programs, ZBasic has two text commands that correspond to the graphic position on the screen instead of the text position: PRINT%(h, v) Prints from the position specified by the ZBasic graphic coordinates. INPUT%(h,v) Positions the input to be from the graphic position specified by h,v. The syntax of these commands is the same as PRINT and INPUT. Also see PRINT@. Graphics 96 GRAPHICS SPECIALIZED GRAPHICS The Apple, MSDOS, Macintosh and some Z80 versions of ZBasic have some added powerful features for graphics. See the appendix for your version of ZBasic for specific information: APPLE 1/ GRAPHICS B Double Hi-Res with 16 colors is supported for the Apple /Ie, /lc and /lGS with 128K or more. Text and graphic may be integrated on the screen and customizable character sets are also supported. LONG FN's for DRAW, BLOAD and BSAVE are on the master disk. IBM PC, MSDOS GRAPHICS • Version 4.0 supports most of the graphic modes of IBM PC's and compatibles including; Hercules Monchrome Graphics, Hercules PLUS, Enhanced Graphics Adaptor (EGA), Color Graphics Adaptor (CGA), Monochrome and all other graphics modes. Also supported are GET and PUT graphic commands, PLOT USING, COORDINATE and COORDINATE WINDOW. See appendix for specifics. MACINTOSH GRAPHICS !b The master disk contains examples of printing and displaying MacPaint graphics and TI FF bit images. Also supported is GET and PUT graphics, PICTURE, TEXT, Apple's QuickDraw and toolbox routines, PEN and many more. See appendix for specifics. TRS-80, CP/M-aO GRAPHICS )a"k ............. Most TRS-80 graphics are supported including Radio Shack's Hi-Res and Micro-Lab's Hi-Res boards on the Model 4 in MODE 8 and 15 (text and graphic integration is not supported with the Radio Shack Hi-Res board). Hi-Res is not supported on the model one or three. Because of the diversity of machines for CP/M systems and because of a lack of a common interface, graphics are not supported wHh CP/M systems (although we have special graphics versions for Kaypro 4 and 10 with graphics capabilities). 97 Graphics FILES TM ASIC FILE HANDLING ZBasic file commands are the same on all versions. This section explains file commands and statements. ZBasic file concepts are similar to a file cabinet: John Last Name ~S~m~i~th~____________ Address 1234 East SouthWest Ave. City San Mateo Age 34 State~ZIP 98345 Money Spent ~.23 EVERYDAY TERMS ZBASIC TERMS FILE CABINET Holds files in drawers. DISK OPERATING SYSTEM Holds files on diskettes, cartridges etc. FILE Contains data for a mail list or inventory control system among other things. FILENAME, FILENUMBER Contains data for a mail list or inventory control system among other things. RECORD One logical part of a file: All the data for Mr. Smith in a mail list (name, address ... ) RECORD One logical part of a file: All the data for Mr. Smith in a mail list file (name, address ...) PARTS OF A RECORD One part of a Record: The address or the City in a mail list record. LOCATION One part of a RECORD: The address in a mail list record or even one character in the address. Files 98 FILES GLOSSARY OF ZBASIC FILE TERMS DOS: The Disk Operating System is a program residing in a computer's memory which takes care of the actual reading, writing and file control on a storage device such as floppy drives, hard drives, tape backup devices, etc. ZBasic works with the formats and syntax of each disk operating system using its syntax for such things as filenames, drive specs, etc. FILENAME: Tells ZBasic which file to access. A string constant or variable is used. FILESPEC: The part of a filename (or some other indicator) that specifies the device, directory or sub-directory a file is on. See your DOS manual for correct filespec syntax. FILENUMBER: ZBasic may be configured to have from 0 to 99 files OPEN at the same time (if DOS and available memory permit). Filenumbers are used in a program with disk file commands to instruct ZBasic which file is being referred to. For example; if you open a file called "Fred" as number one, when doing file commands you need only refer to file number one, not "Fred". This saves a lot of typing. RECORD: A record is one segment of a file. A mail list record might include Name, Address, City, State, ZIP, etc. If you want data from a specific record, it is called up using the RECORD command. The first record in a ZBasic file is RECORD O. There may be up to 65,535 RECORDs in a file" RECORD #filenumber, record, location. LOCATION: Specifies a location within a record. There may be from 0 to 65,535 locations in a record. Each location in a record can hold one character (1 byte). Location is the second parameter in RECORD; RECORD #fiIenumber, record, location. SEQUENTIAL METHOD: This is a method of reading a file one element or record at a time, in order ---one after another i.e. 1,2,3 .... RANDOM METHOD: This is the method of reading file items randomly--- out of order. i.e. RECORD 20, 90, 1, 22 .... FILE POINTER: "is often important to know how to manipulate the file pointer. ZBasic allows you to position the file pointer by using RECORD, and tells you where the file pointer is currently positioned by using REC(filenumber) and LOC(filenumber). COMPATIBILITY WITH MSBASICTM Experienced BASIC programmers will like the power and simplicity of ZBasic file commands. For the first time, BASIC file handling commands have been made compatible and portable. All ZBasic disk commands function the same way regardless of the computer being used. Sequential file commands are very similar. The main difference being that items written with PRINT# should be separated with quoted commas in ZBasic if being read back with INPUT#. Random file commands have been made simpler, yet just as powerful. Those experienced with MSBASIC file commands should find the conversion painless: 99 Files ZBASIC COMMANDS READ, WRITE, RECORD MSBASIC EQUIVALENTS FIELD, GET, PUT, MKI$, CVI, MKS$, CVS, MKD$, CVD, LSET, RSET PRINT#, INPUT#, LlNEINPUT# PRINT#, INPUT#, LlNEINPUT# FILES FILE COMMANDS COVERED IN THIS SECTION This outline gives an overall perspective of file commands available in this section and groups commands in logical order. This section of the manual provides lots of examples and a tutorial for the file commands of ZBasic. OPENING AND CLOSING FILES OPEN CLOSE DELETING OR ERASING FILES KILL RENAMING A FILE RENAME POSITIONING THE FILE POINTER RECORD WRITING TO A FILE WRITE# PRINT# PRINT# , USING ROUTE READING FROM A FILE READ# INPUT# LlNEINPUT# GETTING IMPORTANT FILE INFORMATION LOF LOG REG Be sure to read the appendix for your computer. Many versions have extra commands that take advantage of a particular system. Files 100 FILES CREATING AND OPENING FILES OPEN ["0, lor R"J, filenumber, "filename" [,record length J All ZBasic files must be opened before processing. OPEN "0" Opens a file for "O"utput only. If the file does not exist, it is created. If it does exist, all data and pointers are erased and it is opened as a new file. OPEN "I" Opens a file for "I"nput only. If the file does not exist, a "File Not Found" error is generated for that file number. OPEN "R" Opens a "R"andom access file for reading and/or writing. If the file does not exist, it is created. If the file exists, it is opened, as is, for reading or writing. fifenumber ZBasic may be configured to have from 1 to 99 files open at one time in a program (depending on the DOS and available memory for that computer). Files are assigned numbers so ZBasic knows to which file it is being referred. The original copy of ZBasic is configured to allow up to two open files at a time. If you wish to have more files open, you may configure ZBasic for up to 99 open files. See "Configure". "filename" The filename is the name of the file on the disk. Filenames may be string constants or string variables. Filenames may also specify which drive to use. Filename and drive speCification syntax is dictated by the disk operating system. See your DOS manual. record length Record length is optional. If it is omitted, a record length of 256 characters is assumed. Maximum record length is 65,535 characters, or bytes (check appendix for variations). EXAMPLES OF OPENING FILES OPEN "0", 2, "NAMES", 99 Opens filenumber 2 as "NAMES", with a record length of 99 characters, for OUTPUT only. If "NAMES" doesn1 exist, a file named "NAMES" is created. If a file called "NAMES" exists, all data and pointers in it are deleted and it is opened as a new file. OPEN "1",1, A$ Opens file number 1 whose filename is the contents of A$, with assumed record length of 256 for INPUT only. If A$ doesn't exist, a "File Not Found" error is generated for filenumber one. See "Disk Error Trapping" for more information. OPEN "R", 2, "BIGFILE" , 90 Opens filenumber 2 named "BIG FILE", with a record length of 90, for Reading and Writing. If "BIG FILE" doesn't exist it is created. a OPEN"IR", "OR", "RR" for resource forks. OPEN "A" for append also supported. Volumn number is used after record number i.e. OPEN"R",1,"Fred",99, vol%. A number of other enhancements are covered in the appendix. . 101 Files FILES CLOSING FILES CLOSE[# filenumber [. filenumber, ... )] All files should be closed when processing is finished or before ending a program. to close files resuff in lost data maY E.ailJ.J.!f1 CLOSE without a filenumber closes all open files (STOP and END will also CLOSE all files). It is very important to close all opened files before exiting a program. When a file is closed, the end-of-file-marker is updated and any data in the disk buffer is then written to the disk. After you close a file, that filenumber may be used again with another OPEN. DELETING FILES KILL "filename" Files may be deleted from the disk from within a program or from the editor with the "KILL" command. From the editor the filename must be in quotes on Macintosh and Z80 versions. Filename is a simplestring and may be represented by a string constant or variable: TRONB INPUT"FILE TO KILL: ";FILE$ INPUT"ARE YOU SURE? ";A$ IF A$<>"YES" THEN END KILL FILE$ END RENAMING FILES RENAME "oldfilename" TO [or comma I "newfilename" Files may be renamed on the disk from within a program or directly using RENAME. Filenames may be a string constant or variable. Example: TRONB INPUT"FILE TO RENAME";OLDFILE$ INPUT"NEW NAME: ";NEWFILE$ RENAME OLDFILE$ TO NEWFILE$ pl!l The TRS-80 Model 1 ,3 version does not support RENAME. a.a Macintosh: Both KILL and RENAME also use Volumn number. See appendix for syntax. MSDOS: CHDIR and Path names may be used. APPLE ProDOS: Pathnames may be used. Files 102 FILES WRITING TO A FILE USING PRINT#, WRITE# AND ROUTE# PRINT# PRINT # filenumber, (variables, constants or equations) [ j"," ...) PRINT# is used for writing data in TEXT format. It is saved to the disk quite like an image is saved to paper using LPRINT. PRINT# is useful for many things but it is not the fastest way or most efficient way to save data. See WRITE# below. Examples: PRINT#1, A$ j","j C$j","j Z% j","j X# Prints A$, C$, Z%, and X#, to filenumber one starting at the current file pointer. A carriage return* is written after the X#. This command stores data the same way it would be printed. Syntax is compatible with older versions of BASIC. The file pointer will point at the location in the file directly following the carriage return: PRINT#1,USING "##.##"j 12.1 Formats output to filenumber one starting at the current file pointer (stores 12.10). Functions like PRINT USING. *Data MUST be separated by a delimiter of a quoted comma or a carriage retum if reading data back using INPUT#. Some systems write a carriage return and a linefeed (two bytes). WRITE# WRITE [#) filenumber, variable [. variable ... ) WRITE# is used for storing data in condensed format at the fastest speed. WRITE# may only be used with variables and data is read back with the READ# statement. Example: WRITE#1, A$j10, Z%, K$j2 Writes 10 characters from A$, the value of Z%, and 2 characters from K$ to file number one, starting at the current file pointer. In the example; A$;1 0 stores A$ plus enough spaces, if any, to make up ten characters (or truncates to ten characters if longer). ROUTE# ROUTE [#] device ROUTE is used to route output to a specific device. Device numbers are: " video monitor (default) 128 PRINTER (same as LPRINT) 1-99 DISK filenumber (1-99) -1 or -2 SERIAL port 1 or 2* Example of routing screen data to a disk file or serial port: 1. 2. Open a file for output (use OPEN "C" and -1 or -2 for serial ports) ROUTE to filenumber or serial port number that was opened. All screen PRINT statements will be routed to the device specified. 3. ROUTE" (so output goes back to the video) 4. Close the file or port using: CLOSE# n. * Be sure to see your computer appendix for specifics. 103 Rles FILES READING FROM A FILE USING INPUT#, L1NEINPUT# AND READ# INPUT# INPUT # fifenumber, variable [. variable ...] INPUT# is used to read text data from files normally created with PRINT#. The data must be read back in the same format as it was sent with PRINT#. When using PRINT# be sure to separate data items with quoted comma or carriage return delimiters, otherwise data may be read incorrectly or out of sequence. Example: INPUT#1, A$, C$, Z%, X# Inputs values from filenumber one from the current RECORD and LOCATION pointer, into A$, C$, Z%, and X#. In this example the data is input which was created using the PRINT# example on the previous page. The file pointer will be pointing to the next location after X#. L1NEINPUT# L1NEINPUT# filenumber, variable (One variable only) L1NEINPUT# is used primarily for reading text files without the code limitations of INPUT#. Commas, quotes and other many other ASCII characters are read without breaking up the line. It will accept all ASCII codes accept carriage returns or linefeeds. TEXT is read until a carriage return or Iinefeed is encountered or 255 characters, whichever comes first: L1NEINPUT#5, A$ Inputs a line into A$ from filenumber five from the current file pointer. Accepts all ASCII codes including commas and quotes, except linefeed (chrl0) and carriage return (chr 13). Terminates input after a chr 13, chr 10, End-of-file, or 255 characters. READ# READ [#] fifenumber, variable [. variable ... ] READ# is the counterpart of WRITE#. It is used to read back data created with WRITE# in condensed high-speed format. This is the most efficient way of reading files. Example: READ#l, A$;10, Z%, K$;2 Reads 10 characters into A$, an integer number into Z%, and 2 characters into K$ from filenumber one, from the current file pointer. The file pointer will be pointing to the location directly following the last character in K$ (includes trailing spaces tl string was less than ten). GETTING IMPORTANT INFORMATION ABOUT A SPECIFIC FILE ~ REC( filenumber) Description Returns the current RECORD number location for fifenumber. LOC( filenumber) Returns the current location within the current RECORD for fifenumber (the byte offset). LOF( filenumber) Returns the last RECORD number of fifenumber. If there are one or zero records in the file, LOF will return one. Due to the limitations of some disk operating systems this function is not always exact on some systems. Check the COMPUTER APPENDIX for specifics. Files 104 FILES ZBASIC FILE STRUCTURE All ZBasic files are a contiguous string of characters and/or numbers (bytes). The order and type of characters or numbers depends on the program that created the file. FILE STRUCTURE OPEN "R", 1, "TESTFILE", 30 f ~~~~~R~E~C;O~R~D~(~S)~W~lt~h~le~n~g~th~S~O~f~3~O~~;:~ L-L...J'--I......L....J....L~~....L.......L..."'--"'--L...J'--I'--I....J....L...L..J....~.J Up to 65,535 RECORD(s) In 8 ZBasle file. RECORD 6 ?.:=:::=::~b~~~~i,J~=::~:=::~ L...l.....L..1....1.....L..1....1....L..JL...L....L....IL...L..1...JL...L............L............L..L..L-L...L..L~ o 1 23456... .. Up to 65,535 LOCATION(s) In a ZBasle RECORD. ... 29 ' T h e "d" Is at LOCATION 3 In RECORD 6 In the illustration, the name "Fred Stein" was stored in RECORD six of "TESTFILE". To point to the "d" in FILENUMBER 1, RECORD 6, LOCATION 3 use the syntax: RECORD/tl, 6, 3 The location within a record is optional, zero is assumed if no location is given. If RECORD 1, 6 had been used (without the 3). the pointer would have been positioned at the ··F" in "Fred" which is LOCATION zero. If RECORD is not used, reading or writing starts from the current pointer position. If a file has just been OPEN(ed), the pointer is at the beginning of the file. (RECORD#n, 0, 0 ) After each read or write, the file pointer is moved to the next available position in the file . ~ Macintosh: RECORD length and number of records is 2,147,483,647. 105 Rles FILES POSITIONING THE FILE POINTER RECORD [#] filenumber, RECORD number [. LOCATION numbetj To point to any LOCATION in any RECORD in any FILE, use: RECORD 3, 23, 3 Sets the pOinter of filenumber 3 to RECORD 23, LOCATION 3. If RECORD 23 contained "JOHN", then LOCATION 3 of this record would be "N", since zero is significant. RECORD #3, 23 Sets the pointer for file#3 to location zero in RECORD 23. If RECORD 23 contained JOHN, the character being pointed at would be "J". RECORD IS OPTIONAL If the RECORD statement is not used in a program, the pointer will have a starting position of RECORD 0, LOCATION 0 and is automatically incremented to the next position (for reading or writing) depending on the length of the data. FILE SIZE LIMITATIONS' The file size limitations for sequential files are either the physical limitations of the storage device or the limit of the Disk Operating system for that computer. The limitation for Random access files is 65,536 records with each record containing up to 65,536 characters. Maximum file length is 4,294,967,296 characters (although multiple files may be linked to create larger files). It is important to note that most Disk Operating Systems do not have this capability. Check your DOS manual for maximum file sizes and limitations. !b Macintosh: RECORD length and number of records is 2,147,483,647. CONFIGURING THE NUMBER OF FILES IN A ZBASIC PROGRAM If the number of files is not configured, ZBasic assumes only 2 files will be used and sets aside only enough memory for two files. To use more than 2 files, configure ZBasic for the number of files you need under "Configure" . ZBasic allows the user to configure up to 99 disk files for use in a program at one time (memory and disk operating system permitting). Each type of computer requires a different amount of buffer (memory) space for each file used so check your computer appendix for specifics (usually there are 256--1024 bytes allocated per file; 10 files would require between 2,560-10,240 bytes). 'See computer appendix for variations. Files 106 SEQUENTIAL METHOD 107 Sequential File Method SEQUENTIAL METHOD TM ASIC SEQUENTIAL METHOD This section covers some of the methods that may used when reading or writing files sequentially. It covers the use of READ, WRITE, PRINT#, INPUT# and LlNEINPUT#. SEQUENTIAL METHOD USING PRINT# AND INPUT# These two programs demonstrate how to create, write, and read a file with PRINT# and INPUT# using the Sequential Method: PRINT# OPEN n O",l,"NAMES" DO: INPUT"Name: "; NAME$ INPUT "Age:"; AGE PRINT#l, NAME$","AGE UNTIL NAME$="END" CLOSE#l: END INPUT# OPEN"I",l,"NAMES n DO: INPUT#l, NAME$,AGE PRINT NAME$","AGE UNTIL NAME$="END" CLOSE#l:END Type "END" to finish inputing names in the PRINT# program. The INPUT# program will INPUT the names until "END" is read. FILE IMAGE CREATED WITH PRINT# 1m!. i/ Iff IT 10 12 13 1rrl H la Ir Ir Iy I· 14151 !fIG I I I d Ia I. 11 17 I KI a I t Ih Iy I. 11 10 rr Carriage return and sometimes lineteed depending on the Disk Operating System (DOS) l1jfirl Unless a semi-colon is used after the last data being printed to the disk, the end of each PRINT# statement is marked with a carriage retum. PRINT# USING USING is used to format the PRINT# data. See "PRINT USING". COMMAS IN PRINT# AND INPUT# It is important to remember when using PRINT# w~h more than one data ~em, that quoted commas (",") must be used to set delimiters for data being written. It commas are not quoted, they will merely put spaces to the disk (as to the printer) and INPUT# will not be able to discern the breaking points for the data. Sequential File Method 108 SEQUENTIAL METHOD SEQUENTIAL METHOD USING READ# AND WRITE# Other commands which may be used to read and write sequential data are READ# and WRITE#. The main difference between READ#--WRITE# and PRINT#--INPUT# is that the latter stores numeric data and string data, much the same way as H appears on a printer; READ# and WRITE# store string and numeric data in a more condensed and predictable format. In most cases this method is also much faster. VARIABLES MUST BE USED WITH READ# AND WRITE# READ# and WRITE# require that variables be used for data. Constants or expressions may not be used with these commands except the string length, which may be an expression, constant or variable. HOW STRINGS ARE STORED USING WRITE# When using WRITE# or READ# wHh strings, you must follow the string variable with the length of the string: WRITE#1, A$;10, B$;LB READ#1, A$;10, B$;LB An expression may be used to specify the string length and .IIll..lS1 be included. When WRITE#ing strings that are shorter than the specnied length, ZBasic will add spaces to the string to make H equal to that length. If the string is longer than the length specified, it will be "Chopped off" (If the length of A$ is 20 and you WRITE#1 ,A$;1 0, the last 10 characters of A$ will not be written to the file). Normally, you will READ# strings back exactly the same way you WRITE# them. Notice that the spaces become a part of the string when they are READ# back. If you WRITE# A$;5 , and A$="HI" when you READ# A$;5, back, A$ will equal "HI "(three spaces at the end of H). The length of A$ will be 5. To delete the spaces from the end of a string (A$ in this example), use this statement directly following a READ# statement: WHILE ASC (RIGHT$ (AS, 1» ~32: A$~LEFT$ (A$, LEN (A$) -1): WEND You can use READ# and WRITE# using variable length strings as well. See the two format examples on the following pages. 109 Sequential File Method SEQUENTIAL METHOD READ# AND WRITE# IN CONDENSED NUMBER FORMAT Numbers are stored in condensed format when using READ# and WRITE#. This is done to conserve disk space AND to make numeric space requirements more predictable. ZBasic automatically reads and writes condensed numbers in this format. Just be sure to read the data in exactly the same order and precision with which it was written. Space requirements by numeric variable type are as follows: PRECISION INTEGER SINGLE PRECISION DOUBLE PRECISION MAXIMUM DIGITS 4.3 (±32,767) 6 (defautl) 14 (default) SPACE 2 bytes 4 bytes 8 bytes REQUIRED Since single and double preCision may be configured by the user, use this equation to calculate the disk space required if different than above: (Digits of precision I 2) +1 = number of bytes per variable ~ Longlnteger has 9.2 digits and requires 4 bytes for storage. To calculate the storage needs for Macintosh Double precision; Digits/2+2=space required per variable. INTEGER NUMBER CONVERSIONS For those programmers that want to control conversions these commands are available. They are not required with READ and WRITE since these commands do it automatically. X=CVI (simplestring) A$=MKI$ (integer) Converts the first two bytes of simple-string to integer (X). Converts an integer to a 2 byte string. SINGLE AND DOUBLE PRECISION NUMBER CONVERSIONS For those programmers that want to control conversions these commands are available. They are not required with READ and WRITE since these commands do it automatically. X#=CVB (simplestring) A$=MKB$ (X#) XI=CVB (simplestring) A$=MKB$ (X!) Converts up to the first 8 bytes' of simplestring to an uncondensed double precision equivalent and stores the value in X#. (If string length is less than eight characters, only that many characters will be converted. At least two bytes are needed.) Converts a Double precision number to an 8 byte string.' Converts the first 4 bytes' of simplestring into a single precision number and stores the value in Xl If string length is less than eight characters, only that many characters will be converted. At least two bytes are needed. Converts a single preCision number to a 4 byte string: 'Note: The number of bytes of string space in the conversions depends on the precision set by the user. Use the equation above for calculating the space requirements. ZBasic assumes 8 bytes for double precision and 4 bytes for single precision if the user does not set precision. ~ To manipulate Longlntegers with MKI$/CVI use DEFSTR LONG. See Macintosh appendix. Sequential File Method 110 SEQUENTIAL METHOD SEQUENTIAL FILE METHOD USING READ# AND WRITE# The following programs illustrate how to use READ# and WRITE# using the sequential file method. USING READ# AND WRITE# WITH SET LENGTH STRINGS The programs below create and read back a file with the sequential method using READ# and WRITE#. String length is set to 10 characters by the "10" following NAME$. Z8asic adds spaces to a string to make it 10 characters in length. then saves it to the disk. AGE is assumed to be an integer number since it was not defined and is stored in condensed integer format. WRITE# OPEN"O", 1, "NAMES" DO: INPUT"Name: "; NAME$ INPUT"Age:"i AGE WRITE#l,NAME$;lO, UNTIL NAME$="END" CLOSEU: END AGE OPEN U I",l,"NAMES" DO:READ#l,NAME$;lO, PRINT NAME$;",";AGE A$=LEFT$(NAME$,3) UNTIL NAME$="END" CLOSEU: END AGE Type "END" to finish inputting names for the WRITE# program. The READ# program will READ the names until "END" is encountered. FIXED STRING LENGTH WRITE# This illustration shows how strings saved with set lengths appear in a disk file: FILE IMAGE CREATED WITH WRITE# Condensed 2 byte Integer numbers ~ Wrth SET STRING LENGTHS 23 _ _ _ _ _ _ _-... 4S A. A. A. Sets 10 characters for each string. ~ a string is less than 10 characters the rest of the string is packed with spaces. The reason the ages 23. 45 and 17 are not shown in the file boxes is because the numbers are stored in condensed format (2 byte integer). 111 Sequential File Method SEQUENTIAL METHOD USING READ# AND WRITE# with VARIABLE LENGTH STRINGS READ# and WRITE# offer some benefits over PRINT# and INPUT# in that they will read and write strings with ANY ASCII characters. This includes quotes, commas, carriage retums or any ASCII characters with a code in the range of 0-255. The following programs will save strings in condensed format, using the amount of storage required for each string variable. WRITE# OPEN"O",l,IINAMES" DO: INPUT"Name: "; NAME$ INPUT" Age: "; AGE LB$=CHR$(LEN(NAME$» WRITE#l,LB$;l WRITE#l, NAME$;ASC(LB$),AGE UNTIL NAME$="END" LAST$="END" : WRITE#1,LAST$;3:CLOSE#1 END OPEN"I",l,"NAMES" REM DO: READ # 1 ,LB$; 1 READ # 1 , NAME$;ASC(LB$) ,AGE PRINT NAME$","AGE UNTIL A$="END" CLOSE#l END The WRITE# program stores a one byte string called LB$ (for Length Byte). The ASCII of LB$ (a number from 0 to 255) tells us the length of NAME$. Notice in line 30 (of READ#) that LB$ is read BEFORE NAME$, thus allowing us to read the length of NAME$ first (all data in file handling statements is processed IN-ORDER). VARIABLE STRING LENGTH WRITE# This illustration shows how the data is saved to the disk when string data is saved using the variable length method. LB for "Tom" would be 3, LB for "Harry" would be 5, elc... FILE IMAGE CREATED USING WRITE# W~h Condensed 2 byte ~ 23 Integer numbers A .. 45 A VARIABLE STRING LENGTH • 17 A • 101 A I~ITI olml-I-I ~I HI aIrIrIy I-I-I~ IGI i II Idla I-I-I~ IKia II IhE 1-1-1 bRepresents the Length Byte (stored as LB$ in the example) Sequential File Method 112 SEQUENTIAL METHOD APPENDING DATA TO AN EXISTING FILE CREATED USING THE SEQUENTIAL METHOD Sometimes it is faster (and easier) to append data to the end of an existing text file, instead of reading the file back in, and then out again. This may be accomplished by using "RH, for random access file when opening the file, and keeping track of the last position in a file using REC(filenumber) and LOC(filenumber) and pulling a character 26 at the end of the file . To append sequentially to a text file created with other programs try using this example program. The key is setting the record length to the right amount. The MS-DOS version uses 128. Other versions will vary. This example creates a function called: FN Open ( f$, F%) and will OPEN the file named f$, with file number f%, for appending. The RECORD pointer will be positioned to the next available space in the file. To close a file properly for future appending, use the function called FN Close (f$, f%). LONG FN Open (f$,f%): REM FN OPEN(f$, f%) OPEN "R", f%, f$,128:REM Change 128 to correct# for your DOS Fi1e1en%=LOF(f%): NextRec%=Fi1eLen%: NextLoc%=0 LONG IF FileLen%>0 NextRec%=NextRec%-1 RECORD #f%, NextRec%, NextLoc% READ #f%, NextRec$;128: REM Change this 128 too! NextLoc%=INSTR(1,NextRec$,CHR$(26»: REM (zero on Apple) IF NextLoc%>O THEN NextLoc%=NextLoc%-1 ELSE NextRec%=NextRec%+1 END IF RECORD #%f, NextRec%, NextLoc% END FN LONG FN Close (f$, f%) REM TCLOSE the file correctly with an appended chr 26. PRINT#f%, CHR$(26); CLOSE#f% END FN NOTE: This method will work with ASCII text flies ONL VI ~ See Open "A" in the appendix for opening files for APpend. 113 Sequential File Method RANDOM METHOD ASIC CREATING FILES USING THE RANDOM ACCESS METHOD Random access methods are very important in disk file handling. Any data in a file may be stored or retrieved without regard to the other data in the file. A character or field from the last record in a file may be read (or wrnten) without having to read any other records. A simple example of the Random access method is the following program that reads or wrnes single characters to any LOCATION in a file: RANDOM ACCESS EXAMPLE USING A ONE BYTE RECORD LENGTH OPEN "R", REM RECORD 1 , "DATA", 1 LENGTH = 1 character "Get record number" DO: INPUT "Record number: ";RN INPUT "ead, rite, nd:"; A$ IF A$="R" GOSUB "Read" ELSE IF A$ = "W" GOSUB "Write" UNTIL A$="E": CLOSE#l: END uWrite" INPUT "Enter character:" RECORD # 1 , RN WRITE #l,A$;l :RETURN A$ "Read" RECORD #l,RN :REM Point at record# RN READ #l,A$;l PRINT" Character in RECORD# "; RN ;" was" ;A$: RETURN To change this program to one that would read or wrne people's names, merely change the RECORD LENGTH to a larger number and increase the number after the A$ in the READ# and WRITE# statements. The following pages will demonstrate a more practical use of the Random Access method by creating a mail list program in easy to understand, step by step procedures. Random Access File Method 114 RANDOM METHOD CREATING A MAIL LIST USING THE RANDOM ACCESS METHOD This mail list uses: First and Last name, Address, City, State, Zip, Age and Money spent. The first thing to do is calculate the record length for the mail liS! file. This is done by calculating the space requirements for each field in a RECORD. FIELD VARIABLE TYPE FIRST NAME LAST NAME ADDRESS STRING$ STRING$ STRING$ STRING$ STRING$ DOUBLE PRECISION INTEGER SINGLE PRECISION CITY STATE ZIP AGE MONEY SPENT Totals: 8 VARIABLES SPACE NEEDED 10 characters 18 characters 35 characters 25 characters 15 characters 8 bytes (holds up to 14 digits) 2 bytes (Holds up to 32,767) 4 bytes (Holds up to 6 digits) 117 bytes per RECORD The following illustration illustrates how the mail list data is stored within each RECORD. LOCATION numbers are shown by position. MAIL LIST RECORD LAYOUT 0--------- Locations ·----------9 10-------------------- Locations ------------------------------27 IJ I01 h In! I I I I I II simi ij t I hI I I I I I I I First name 117 TOTAL LOCATIONS I I I I I I Last name 10 Character :stnng 18 character :stnng 28------------------------------------------------------ Locations ------------------------------------------------------------62 191415161811El a lsltilMlij s lslilsislilpiplij Isltl·IIAlplq 1 9 13 1 111 Address 35 Character :string 63----------------------------------------- Locations -----------------------------------87 IslolultlhlelalsltllTlulsiclalllol o Isial I I I I I Age City 2 byte Integer 25 character String /' 88-----------· Locations ----------------------102 103------ Loc. --------110 111-112 .--.--. 113---116 condo State 15 character string 115 Random Access File Method ZIP 8 byte Double precision Money Spent 4 byte Single precision RANDOM METHOD MAIL LIST PROGRAM The following program will READ# and WRITE# mail list data as described on previous pages. The names are input from the user and a mail list file record is created for each name. You will be able to retrieve, print, and search for names in the mail list and, with some simple modifications (like using the sort routines in the ARRAY section of this manual) you will have a complete mail list program ready to use. EXPLANATIONS OF THE MAIL LIST PROGRAM BY LINE NUMBER 10-21 Asks if you want to create a new file. If you say yes the old data is written over. 22 If old data is being used, the data in RECORD zero is READ to find out how many names are on the disk. NR holds the number of records on the disk. 25-77 Puts a menu on the screen and awaits user input. 80 "END" routine. Closes file and exits the program. 100-210 "ADD" names to mail list. Gets data from user, checks if OK. If not OK starts over. Note that the spaces in the input statements are for looks only. Space may be omitted. 220 If not OK then redo the input. 230-255 Gets the disk record (DR) from NR. Saves the variables to disk, then increments the number of records. (NR=NR+ 1) and saves it to disk record zero. 500-590 PRINT(s) all the names in the file to the printer. (Change LPRINT to PRINT for screen output). 700-780 "FIND" all occurences of LAST NAME or PART of a LAST NAME. To find all the names that start with "G" just type in "G". To find "SMITH" type in "SMITH" or "SMIT" or "SM". 1000-1040 "READ A MAIL LIST ITEM" READ(s) RECORD DR from the disk into the variables FIRST_NAME$, LAST_NAME$, ADDRESS$, ... 1100-1140 "WRITE A MAIL LIST ITEM" WRITES the variables FIRST_NAME$, LAST_NAME$, ADDRESS$, ... out to the RECORD specified by DR. HINTS: Spaces are not important when typing in the program, except between double quotes (if you have set "Spaces required between keywords" they will be required). Random Access Rle Method 116 RANDOM METHOD MAIL LIST PROGRAM EXAMPLE 0010 0015 0016 0021 0022 0025 0030 0040 0050 0052 0055 0060 0075 0077 0079 0080 0099 0100 101 102 0130 0140 0150 0160 0170 0180 0190 0200 0210 0220 0230 0240 0250 0255 0260 0261 0500 0510 0515 0520· 0530 0540 0550 0560 0570 0575 0580 0585 0590 CLS OPEN"R",1,"MAIL",117 INPUT"CREATE A NEW FILE:Y/N";A$: IF A$><"Y" THEN 22 NR=l: RECORD1,0: WRITE#l,NR:REM NR=Number of names in list RECORD 1,0: READ # 1 , NR DO: CLS PRINT"MAIL LIST PROGRAM" PRINT"I. Add names to list", "Number of names: ";NR-l PRINT"2. Print List" PRINT"3. Find names" PRINT"4. End" INPUT@(0,7)"Number: ";ANSWER: IF ANSWER<1 OR ANSWER>4THEN60 ON ANSWER GOSUB "ADD", "PRINT", "FIND" UNTIL ANSWER=4 "END": CLOSE#I: END "ADD" CLS PRINT"MAIL LIST INPUT": PRINT INPUT"First Name: ";FIRST NAME$ INPUT"Last Name: ";LAST NAME$ INPUT"Address: ";ADDRESS$ INPUT"City: ";CITY$ INPUT"State: ";STATE$ INPUT"ZIP: ";ZIP# INPUT"AGE: ";AGE% INPUT"Money Spent:";SPENT! PRINT INPUT"Is everything correct? yiN: ";A$: IFA$<>"Y"THEN "ADD" RECORD 1,0:READ#l,NR: DR=NR: NR=NR+l: REM NR is incremented GOSUB"WRITE A MAIL LIST ITEM": REM when names added RECORD 1,0: WRITE#I, NR : REM Stores records to record zero RETURN "PRINT" REM Change LPRINT to PRINT if screen output preferred RECORD 1,0: READ#l,NR FOR X=lTO NR-1: DR=X :REM DR=DISK RECORD GOSUB"READ A MAIL LIST ITEM" LPRINT FIRST NAME$;" ";LAST NAME$ LPRINT ADDRESS$ LPRINT CITY$;",";STATE$;" ";ZIP# LPRINT AGE%, "SPENT:"; USING"$###,###.##";SPENT! LPRINT:IF FLAG=99 RETURN NEXT DELAY 3000 RETURN Continued next page 117 Random Access File Method RANDOM METHOD 0700 0704 0705 0710 0720 0730 0740 0750 0755 0760 0770 0780 0781 0782 1000 1001 1020 1030 1035 1040 1041 1042 1100 1101 1110 1120 1130 1135 1140 "FIND" CLS RECORD 1,0: READ#l, NR IF NR=l THEN PRINT "No names to find!":DELAY 999:RETURN INPUT"NAME TO FIND: ";F$:F$=UCASE$ (F$) FOR X=l TO NR-1 DR= X: GOSUB"READ A MAIL LIST ITEM" T$=UCASE$(LAST NAME$) :REM CASE must match IF INSTR(l,T$,F$) THEN FLAG=99: GOSUB 540: FLAG=O NEXT INPUT "LOOK FOR ANOTHER? Y/N:";A$:IFA$="Y" THEN 700 RETURN "READ A MAIL LIST ITEM" REM:This routine READS RECORD DR RECORD 1, DR READ#l, FIRST NAME$;10, LAST NAME$;18, ADDRESS$;35, READ#l, CITY$;25, STATE$;15,-ZIP#, AGE%, SPENT! RETURN "WRITE A MAIL LIST ITEM" REM: This routine WRITES RECORD DR REM CALL WITH DR=DISK RECORD NUMBER TO WRITE RECORD 1, DR WRITE#l, FIRST NAME$;10, LAST NAME$;18, ADDRESS$;35 WRITE#l, CITY$;25, STATE$;15,-ZIP#, AGE %, SPENT! RETURN: END Random Access File Method 118 MIXING FILE METHODS 119 Mixing File Methods MIXING FILE METHODS ASIC MIXING SEQUENTIAL AND RANDOM FILE METHODS Since ZBasic stores data as a series of bytes whether sequential methods or random methods are used, these methods may be intermixed. The following program uses both methods. The program reads files from the mail list program created with the random access method earlier in this chapter. The second and third lines read the number of records in the file. Then the list is read off the disk sequentially using the DO/UNTIL loop. To read and print the mail list in sequential order: OPENIII", 1, "MAIL", 117 RECORD 1,O:READ#1, NR:REM Gets number of records to read RECORD 1,1: REM Set pointer to the first record REM Change LPRINT to PRINT if screen output prefered DO: NR=NR-1: REM Counts down the number of names READ#l, FIRST NAME$;10, LAST NAME$;18, ADDRESS$;35, CITY$;25, STATE$;15, ZIP#, AGE%, SPENT! LPRINT FIRST NAME$;" ";LAST NAME$ LPRINT ADDRESS$ LPRINT CITY$;",";STATE$;" ";ZIP# LPRINT AGE%, "SPENT:"; USING"$###,###.##";SPENT! LPRINT UNTIL NR=l:REM Until the last name is read CLOSEn END The READ#1 after the DO reads the data in. Whenever read or write functions are executed, ZBasic automatically positions the file pointer to the next position. Mixing File Methods 120 DISK ERRORS 121 Disk Errors DISK ERRORS ASIC D~K ERROR MESSAGES If a disk error occurs while a program is running, ZBasic will print a message something like this: File Not Found Error in File (C)ontinue or (S)top? Ul2 If you type "S", ZBasic will stop execution of the program and return to the disk operating systern (or to the editor if you are in interactive mode). If you press "e", ZBasic will ignore the disk error and continue with the program. This could destroy disk data!! The following pages will describe how to ''TRAP'' disk errors and interpret disk errors which may occur. END OF FILE CHECKING Some versions do not have an "END OF FILE" command because some operating systems do not have this capability. Example of END OF FILE checking for some versions: ON ERROR GOSUB 65535: REM Set for User Error trapping OPEN"I",l,"DEMO":IF ERROR PRINT ERRMSG$(ERROR) :STOP DO LINEINPUTU,A$ UNTIL ERROR <>0 IF ERROR >< 257 THEN PRINT ERRMSG$(ERROR): STOP REM 257=EOF Error in filenumber l(See error messages) ERROR=O:REM You ~ reset the ERROR flag. ON ERROR RETURN:REM Give error checking back to ZBasic CLOSEU Note: Many versions have an EOF function. See your appendix fordetails. Disk Errors 122 DISK ERRORS TRAPPING DISK ERRORS ZBasic provides three functions for disk error trapping: ON ERROR GOSUB 65535 Gives complete error trapping control to the user. User must check ERROR (If ERROR <>0 then a disk error has ocurred) and take corrective action if any disk errors occur. (Remember to set ERROR=O after a disk error occurs). ZBasic will not jump to a subroutine when the error occurs. The 65535 is just a dummy number. See the ON ERROR GOSUB line: ON ERROR GOSUB line GOSUB to the line number or label specified whenever and wherever, ZBasic encounters a disk error. ON ERROR RETURN Gives error handling control back to ZBasic. Disk error messages will be displayed if a disk error occurs. When l(QJ.!. are doing the ERROR trapping it is essential that ERROR be set to ;zero after an error is encountered (As in line #45 and #1025 in the program example). Failure to set ERROR=O will cause additional disk errors. DISK ERROR TRAPPING EXAMPLE The following program checks to see if a certain data file is there. If disk error 259 occurs (File Not Found error for file #1), a message is printed to insert the correct diskette: 10 15 20 30 40 45 46 50 1000 1003 1005 1010 1015 1020 1025 1030 ON ERROR GOSUB "CHECK DISK ERROR" REM Line above Jumps to line 1000 if any disk error occurs OPEN"I",l,"TEST" IF ERROR=O THEN 50 INPUT"Insert Data diskette: press ";A$ ERROR=O:REM You MUST reset ERROR to zero! GOTO 20 :REM Check diskette again ... ON ERROR RETURN:REM ZBASIC DOES DISK ERROR MESSAGES NOW "CHECK DISK ERROR" REM ERROR 259 is "File Not Found Error in File *01" IF ERROR=259 RETURN PRINT ERRMSG$(ERROR) :REM Prints error if not 259 INPUT"(C)ont. or (S)top? ";A$ A$=UCASE$(A$): IFA$<>"C" THEN STOP ERROR=O:REM You MUST reset ERROR to zero! RETURN Note: This method may not work on some Disk Operating Systems (like CP/M). Check your computer appendix for specifics. 123 Disk Errors DISK ERRORS DISK ERROR CODES AND MESSAGES If you wish to do the disk error trapping yourseH (using ON ERROR GOSUB), ZBasic will return the ERROR CODE in the reserved variable word "ERROR". For instance, if a "File not Found Error in file# 2" occurs, then ERROR will equal 515. To decode the values of 'ERROR', follow this table: DISK ERROR COPES & MESSAGES f.B.R.QB. No Error in File # End of File Error in File # Disk Full Error in File # File Not Found Error in File # File Not Open Error in File # Bad File Name Error in File # Bad File Number Error in File # Write Only Error in File # Read Only Error in File # Disk Error in File # ERROR COPE 12) 1 (257=file#1, 513=file#2, 769=file#3, etc.) 2 3 4 5 6 7 8 9-255 ERROR CODE=ERROR AND 255 FILE NUMBER= ERROR» 8 ERROR FUNCTION ERROR returns a number between 12) and 32,767. IF ERROR does not equal zero then a disk error has occurred. The disk error code of the value returned in ERROR is deciphered by using one of the following equations or statements: IF ERROR =515 calculate the disk error type by: ERROR AND 255 =3 File Not Found Error in File # ERROR »8 =2 File Number is 2 ERRMSG$(ERROR)= File Not Found Error in File #02 Also See ERROR and ERRMSG$ in the reference section. Important Note: To avoid getting the same error again ... ALWAYS set ERROR back to zero after an error occurs; ERROR=I2). & Also see SYSERROR in the Macintosh appendix. Disk Errors 124 SCREEN AND PRINTER 125 Screen and Printer Control SCREEN AND PRINTER ASIC SCREEN AND PRINTER ZBasic has several functions and commands for screen and printer control. PRINT or LPRINT are the most frequently used. The following syntax symbols are used to control the carriage return and TAB for either PRINT or LPRINT: PRINT SYNTAX Semi-Colon ";" RESULT Suppress Carriage retum and Iinefeed after printing. Subsequent prints will start at the cursor posHion. Comma"," TAB over to the next TAB stop. The default is16: TAB stops are: 16,32,48,64, ... 25 (also see DEF TAB below). DEFTAB=n Defines the space between the TAB stops for comma (,). Any number from 1-255. If 10 is used then positions 10, 20, 30, ...250, are designated as TAB stops. PRINT EXAMPLES PRINT''HI'' RESULT Screen PRINT "HI" to the current cursor posHion and move to the beginning of the next line. PRINT"HI"j Screen PRINT "HI" and DON'T move to next line (the semi-colon suppresses the carriage return) PRINT"HI", Screen PRINT "HI" and move over to next TAB poSition. PRINT TAB(20)"HI" Print "HI" at the 20th position over from the left or at the current position if past column 20. PRINT ,"HI" Print "HI" at the next TAB stop position. See" DEF TAB". PRINT USING"##.##";23.2 PRINTS 23.20 and moves to the next line. See "USING" in the reference section for further information. POS(O) Returns the horizontal cursor position on the screen where the next character will be printed. POS(1) Returns horizontal cursor position of the printer where the next character will be printed. Screen and Printer Control 126 SCREEN AND PRINTER PRINTING AT A SPECIFIC SCREEN LOCATION o 1 2 3 4 .... HORIZONTAL o H i 1 2 3 ~ N m 0 : ........ PRINT@(l,l)"HI"; V E R r'\ T I C A L \ , PRINT @ (O,5)"Name: .. PRINT@(H,V)"HI" Start printing H characters over horizontally and V lines down vertically from the upper left hand corner of the screen, then move to the beginning of the next line (Use a SEMI-COLON or COMMA to control the carriage return). PRINT %(Ghoriz, Gvert) Position the print output to be at the graphics coordinates specified by Ghoriz, GVert (or as close as possible for that computer. Great for easy porting of programs. CLS [ASCII] Fill Screen with spaces or optional ASCII characters. (CLS 99 would fill the screen wHh c's.) CLS LINE or PAGE Fill with spaces to the end of the LINE or to the end of the PAGE (screen). STRING$(Qty, ascii or string) Used to print STRINGS of charaters. STRING$ (10, "X" ) prints lOX's to the current cursor posHion. STRING$ (25, 32) will print 25 spaces. SPACE$(n) or SPC(n) Prints n spaces from current cursor position. COLOR [=] n Sets the color of Graphics output and sometimes text. (0= background color, usually black. -1= foreground, usually white).* MODE [=] n Sets screen attributes. Some computers allow 80 character across or 40 characters across, etc.. Graphics may also be definable.* ROUTE byte integer Used to route output to the screen, printer or disk drive .• • See Computer Appendix for specifics. 127 Screen and Printer Control SCREEN AND PRINTER PRINT % The PRINT % command functions exactly the same way as PRINT@ except the X-V coordinate specifies a screen graphic position instead of a character position. Since ZBasic utilizes device independent graphics, this is a handy way of making sure the text goes to the same place on the screen regardless of the computer being used. Use MODE to set certain character styles for some computers. Examples: PRINT % (512,383) PRINT % (0,0) PRINT % (0,767) Print to middle of screen Upper left corner of screen Lower left corner of screen !b Same as the toolbox MOVETO function. ZBasic coordinates unless COORDINATE WINDOW is used. TYPICAL VIDEO CHARACTER LAYOUTS Here are some of the typical character layouts for a few of the more popular computers: COMPUTER IBM PC and compatible APPLE liE, IIC TRS-80 Modell, III TRS-80 Model 4, 4p CP/M-80 computers Macintosh Columns (across) 80 or 40 800r40 640r32 80 or 40· 80 Almost any1hing ... Rows (down) 25 24 16 24 24 See appendix ·Will also run TRS-80 models 1, 3 version. Screen and Printer Control 128 KEYBOARD INPUT 129 Keyboard Input KEYBOARD INPUT ASIC KEYBOARD INPUT ZBasic utilizes the INPUT and L1NEINPUT statements of getting keyboard data from a user. There are many options allowed so that input may be configured for most input types. Parameters may be used together or by themselves in any order. Syntax for INPUT and L1NEINPUT: [L1NE]INPUT[;][[@or%] (horiz,vert);] [I] [& n,] ["string constanf';] var[, var[, ... ] L1NEINPUT Optional use of INPUT. Allows inputting quotes, commas, and some control characters. A semi-colon directly following "INPUT" disables the carriage return (cursor stays on same line after input). an, "&" directly following "INPUT" or semi-colon, sets the limit of input characters to n. Length of strings used in INPUT must be one greater than n. An exclamation point used with "&" terminates the INPUT when the character limit, defined by "&", is reached, without pressing . If "!" is not used, ends input. @(horiz, vert); Pos~ions the INPUT message to appear at character coordinates horiz characters over & vert lines down. %(horiz, vert); Positions the INPUT message to appear at the closest graphic coordinates horiz pixels over avert pixels down. "string constanf'; Prints a message in front of the input. var [, varU, ... ] The variable(s) to receive the input. Using more than one variable at a time is allowed except with L1NEINPUT. Important Note: When using strings with INPUT make sure that you define the length of the string at least one character more than will be input. Keyboard Input 130 KEYBOARD INPUT EXAMPLES OF REGULAR INPUT EXAMPLE INPUT AS RESULT , Wait for input from the keyboard and store the input in A$. Quotes, commas and control characters cannot be input. to finish. A carriage return is generated when input is finished (cursor moves to beginning of next line). INPUT'NAME: ";A$ Prints "NAME: " before input. A semi-colon must follow the last quote. A carriage return is generated after input (cursor moves to next line). INPUT;A$ Same as INPUT AS above, only the semi-colon directly after INPUT disables the carriage return (wrsor stays on the same line). EXAtJlPLES OF LIMITING THE NUMBER OF CHARACTERS WITH INPUT EXAMPLE INPUT &10, AS RESULT Same as INPUT A$ only a maximum of ten characters may be input. (&10) A carriage return is generated after input (cursor moves to the beginning of the next line). The limit of input is set for ALL variables, not each. INPUT; &10,1% Same as INPUT &10, except the SEMI-COLON following INPUT stops the carriage return (cursor stays on line). INPUT 1&10, A$ Same as INPUT & 10 except INPUT is terminated as soon as 10 characters are typed (or is pressed). INPUT ;! &10, "NAME: ";A$ Same as INPUT ;&10,A$ except no carriage return is generated (semi-colon). INPUT is terminated after 10 characters(&10 and Exclamation point). and the message "NAME: " is printed first. LlNEINPUT;!&5,"NAME: ";A$ LlNEINPUT A$ until 5 characters or is pressed. (no carriage retum after or after the 5 characters are input. Accepts commas and quotes.) Note 1: Wherever INPUT is used, LlNEINPUT may be substituted when commas, quotes or some other control characters need to be input (except with multiple variables). Note 2: If more than one variable is INPUT, commas must be included from the user to separate input. If all the variables are not input, the value of those variables will be null. !b In certain cases EDIT FIELD, MENU or BUTTON may be preferable. See appendix. 131 Keyboard Input KEYBOARD INPUT INPUTTING FROM A SPECIFIC SCREEN LOCATION o 1 2 3 4 .... HORIZONTAL o 1 ?~ '" 2 3 ~ V E R T I C A L Na I"i. m e : ....... ......... INPUT @(2,1)"?";X 1\ ~ INPUT @ (O,5)"Name: ";A$ INPUT@(H,V); A$ Wait for input at TEXT screen POSITION defined by Horizontal and Vertical coordinates. No "?" is printed. A carriage return is generated. INPUT %(gH, gV);A$ Input from a graphic coordinate. Syntax is the same as "@". Very useful for maintaining portability without having to worry about different screen widths or character spacing. INPUT@(H,V);!10,"AMT: ";0# Prints "AMT:" at screen position H characters over by V characters down. 0# is input until 10 characters. or . are typed in. and the input is terminated without generating a carriage return (the cursor DOES NOT go to the beginning of the next line). INPUT%(H,V);!10,"AMT: ";0# Prints "AMT:" at Graphic position H positions over by V positions down. 0# is input until 10 characters. or . are typed in, and the input is terminated without generating a carriage return (the cursor DOES NOT go to the beginning of the next line). Note: Replace INPUT with LlNEINPUT whenever there is a need to input quotes, commas and control characters (except with multiple variables). Keyboard Input 132 KEYBOARD INPUT INPUT % The INPUT % command functions exactly the same way as INPUT@ except the X-Y coordinate specifies a screen graphic position instead of a character position. Since ZBasic utilizes device independent graphics, this is a handy way of making sure the INPUT goes to the same place on the screen regardless of the computer being used. Use MODE to set certain character styles for some computers. Examples: INPUT% (512,383) INPUT% (0,0) INPUT% (0,767) middle of screen upper left corner of screen lower left corner of screen a Although all parameters above function properly, EDIT FIELD, MENU or BUnON are preferable for getting user input. See appendix. TYPICAL VIDEO CHARACTER LAYOUTS Here are some of the typical character layouts for a few of the more popular computers: COMPUTER IBM PC and compatible APPLE 1/ series TRS-80 Modell, III IRS-80 Model 4, 4p CP/M-80 computers Macintosh 133 Keyboard Input Columns (across) 800r40 800r40 640r32 800r40 80 Almost anything ... Rows (down) 25 24 16 24 24 See appendix KEYBOARD INPUT INKEY$ Unlike INPUT which must WAIT for characters, INKEY$ can receive characters from the keyboard "on the fly". When INKEY$ is encountered in a program, the keyboard buffer is checked to see if a key has been pressed. For computers with no buffer, the keyboard is checked when the command is encountered. If a key is pressed, INKEY$ retums the key. If no key has been pressed, INKEY$ retums a null string. Examples: I$=INKEY$ When the program reaches the line with this command on it, ZBasic checks to see if a character is in the input buffer. If a key has been pressed it will be returned in 1$. Otherwise 1$ will contain nothing (1$ will equal "" or LEN(I$)=zero). IF INKEY$="S" STOP If the capital "S" key is pressed the program will stop. Sometimes more appropriate than using TRONB or TRONX for debugging purposes. DO: UNTIL LEN(INKEY$) DO: UNTIL LEN(lNKEY$)=O Wait for any key press, then continue Clears characters out of INKEY$ buffer Note: TRONX, TRON or TRONB may cause INKEY$ to function improperly! && Macintosh: If doing EVENT Trapping or any TRON type, the INKEY$ function may operate incorrectly. Use DIALOG(16) instead. See appendix for examples. MSDOS: See appendix for special ways of getting function keys (INKEY$ retums two characters). INKEY$ EXAMPLE The program below will wait awhile for a key to be pressed. If you make it wait to long, it will complain loudly. If you do press a key, it will tell you which key was pressed. If you press "S" or "s", the program will stop. "Start": CLS DO A$=INKEY$:REM Check if a key has been pressed X=X+l: IF x>3000 THEN GOSUB"YELL FOR INPUT! ":REM Timer UNTIL LEN(A$): REM If a key is pressed then LEN(A$)=l PRINT "You pressed ";A$ X=O: REM Reset timer IF A$="S" OR A$="s" THEN STOP: REM PRESS "s" to STOP! GOTO "Start":REM Go look for another key "YELL FOR INPUT!":REM This routine complains PRINT"HURRY UP AND PRESS A KEY! I'M TIRED OF WAITING" X=O:REM Reset Timer RETURN Keyboard Input 134 LOOPS 135 Loops LOOPS ASIC LOOPS Loops are sections of a program that repeat over and over again until a condition is met. Loops are used to make programs easierto read by avoiding IF THEN and GOTO, (although these commands may also be used to loop). ZBasic has a number of ways of looping or executing a routine until a condition is met. * FOR, NEXT, STEP UNTIL WHILE, WEND * DO, • Each of these loop types is executed at least once. ENTERING OR EXITING LOOPS ZBasic loops may be entered or exited without ill affects. Some compilers require you to use a loop EXIT statement. This is not required with ZBasic. Just use a GOTO or RETURN to exit as appropriate. IMPORTANT LOOP REQUIREMENTS ZBasic requires that each FOR has one, and only one, NEXT. Each WHILE must have one WEND and each DO must have one UNTIL. Otherwise a STRUCTURE error will resutt when you attempt to RUN the program. AUTOMATIC INDENTING OF LOOPS ZBasic automatically indents loops two characters in listings for readability (LIST). Loops 136 LOOPS FOR-TO-STEP NEXT FOR VAR counter= start expression TO end expression [STEP expression] Program flow... NEXT [VAR counter] STEP is an optional part of FOR/NEXT. If STEP is omitted, the step is one. An example of a FOR-NEXT-STEP loop: FOR x=o TO 20 PRINT X; ·NEXT X STEP 2 program continues ... LINE 1: Begin the loop where X is incremented in STEPs of 2 (0,2,4,6... 20) LINE 2: Prints the value of X each time the loop is executed. LINE 3: If X => 20 the loop falls through to line 4. X will equal 22 in line 4 of this example program. FOR-NEXT loops will go through the loop at least once regardless of the values in the FOR instruction. See WHILE-WEND for immediate exiting. To count backwards in a FOR/NEXT loop set STEP to a negative number. Note 1: STEP zero will cause an endless loop. 'Note 2: With integer loops, be sure the maximum number is less than 32,767; otherwise an endless loop may occur for some systems. The reason for this is that the sign of the number increments to -32768 after 32767 which restarts the loop all over again! Endless loop example: FOR x%= 1 TO 32767 <--Endless loop! NEXT X% Note 3: STEP number must stay within the integer range. STEP 32767 would create an endless loop. Note 4: Unlike most other languages, FOR-NEXT loops may be entered or exited in the middle with no ill effects. a 'The same problem arises with four byte integers when the maximum Longlnteger number in the FOR loop exceeds 2,147,483,647. 137 Loops LOOPS DO UNTIL DO Program flow... UNTIL conditional expression is TRUE DO X=X+2 PRINT X; UNTIL X>19 program continues ... LINE 1: LINE 2: LINE 3: LINE 4: Start of the DO loop Make X=X+2 PRINT the value of X each time the loop is executed. If X<20 then go back to the beginning of the loop. When X> 19 program falls through to the next statement (line 4 in example) A DO loop wllf execute at least once. In contrast to WHILE-WEND, which checks the condition at the beginning of the loop, DO-UNTIL checks the condition at the end of the loop. Use WHILE-WEND when you need to check the condition at the beginning. Note: Unlike most other languages, the loop may be entered or exited in the middle with no ill effects. For instance, in line 2 above, you could used: IF X>10 then RETURN. This would not cause any problems in the program. Loops 138 LOOPS WHILE WEND WHILE conditional expression Program flow... WEND end loop here when condition of WHILE is FALSE WHILE X<20 X=X+2 PRINT X; WEND program continues ... LINE 1: LINE 2: LINE 3: LINE 4: Continue the loop while X is less than 20. Make X=X+2. Print the value of X each time the loop is executed. If X is less than or equal 20 then go back to the WHILE and do the loop again, otherwise continues at the first statement after WEND. In contrast to DO-UNTIL and FOR-NEXT (which check the condition at the end of a loop), WHILE-WEND checks the condition at the beginning of the loop and will exit Immediately If the condition Is not met. Note: Unlike most other languages, a WHILE-WEND loop may be entered or exited in the middle wijh no ill effects. For instance, in line 30 above, you could have used: IF X>1 0 then RETURN. This would not cause any problems in the program. 139 Loops FUNCTIONS AND SUBROUTINES ASIC FUNCTIONS AND SUBROUTINES ZBasic contains some powerful tools for creating re-usable subroutines and appending or inserting them into other ZBasic programs that you create. APPEND APPEND is a command that will take an un-line numbered subroutine and insert it anywhere in an existing program. The syntax for the command is APPEN D linenumber or label, filespec. To save a subroutine or program without line numbers, use the SAVE+ command. MERGE is available for merging subroutines or programs with line numbers into an existing program. DEF FN ZBasic incorporates the DEF FN and FN statements similar to many other BASIC languages. This is very handy for creating functions thai may be used like commands in a program. A function is given a name and may be called and passed variables. FN's save program space. Note thai functions may utilize other functions within definitions and program code. Examples of using DEF FN to create Derived Math functions. DEF FN eil = EXP(l.) DEF FN Piil = ATN(l) « 2 DEF FN SECiI(xiI) = 1. \ cos (Xii) DEF FN ArcSinil(XiI) = ATN (Xii \ SQR(l-xil * Xii» DEF FNArcCos#(xiI) = ATN(1.)*2-FN ArcSin#(X#) Examples of PRINT FN Angleil = PRINT FN program use: Pi# SIN (FN ArcSin#(IiI» ArcCos# (Gil) Note: Be sure to define the function at the beginning of the program before attempting to use it otherwise an UN DEF error will result at compile time. Functions and Subroutines 140 FUNCTIONS AND SUBROUTINES LONG FN Included is a sophisticated and powerful multiple line function called LONG FN. LONG FN allows you to create mUlti-line functions as large as a subroutine and allows you to pass variables to the routine. This comes in very handy for creating reusable subroutines that you can insert or APPEND to other programs. LONG FN is similar to DEF FN except that the function being defined may be many lines long. Use END FN to end the LONG FN subroutine. WARNING: Do not exit a LONG FN except at END FN otherwise system errors may result. Example of LONG FN to remove trailing spaces from a string: LONG FN RemoveSpace$ (x$) WHILE ASC(RIGHT$(x$,1)=32 x$= LEFT$(x$, LEN(x$)-l) WEND END FN= x$ Name$="ANDY PRINT X$, FN RemoveSpace$ (Name$) z$=FN RemoveSpace$(fred$) Example of a LONG FN for dOing a simple matrix multiplication: DIM A%(lOOO) LONG FN MatrixMult%(number%, FOR temp%= 0 TO last% A%(temp%)=A%(temp%)*number% NEXT END FN A%(O)=l: A%(1)=2:A%(2)=3 FN MatrixMult%(lO,3) PRINT A%(O), A%(l), A%(2) last%) SYNTAX OF DEF FN AND LONG FN NAMES FN names have the same syntax as variable names. A function that returns a string value should end with a $. A function that returns a double precision value should end with a#. AUTOMATIC INDENTATION ZBasic automatically indents that code between a LONG FN and END FN so programs are easier to read. SAVING FUNCTIONS FOR USE IN OTHER PROGRAMS To save DEF FN'S or LONG FN's (or any subroutine) for future use, use SAVE+. This saves the subroutine without line numbers so it may be used in other programs by loading with the APPEND command (be sure to avoid line number references and GOTOs in subroutines to make them easily portable). 141 Functions and Subroutines FUNCTIONS AND SUBROUTINES MORE EXAMPLES OF LONG FN The following example will check to see if a random file specified by the filename file$ exists. If it does it will open it as a random file. If it does not exist, it will return a disk error. Remember; with OPEN"R" if the file exists it is opened, if it doesn't exist it is created. You may not want it created in certain circumstances (like if the wrong diskette is in a drive). LONG FN Openfil.e% (files$, filenum%, reclen%) ON ERROR 65535: REM Disk error trapping on "Open file" OPEN"I",filenum%,file$ LONG IF ERROR LONG IF (ERROR AND 255) <>3 PRINT@(O,O);"Could not find ";file$;" Check disk drive" INPUT"and press when ready";temp% ERROR=O: GOTO "Open file" END IF XELSE CLOSE* filenum% END IF ON ERROR RETURN: REM Give error checking back to ZBasic OPEN"R",filenuril%, file$, reclen% END FN EASY GETKEY FUNCTION LONG FN Getkey$ (Key$) DO Key$=INKEY$ UNTIL LEN(Key$) END FN = Key$ Functions and Subroutines 142 MACHINE LANGUAGE SUPPORT 143 Machine Language Support MACHINE LANGUAGE SUPPORT ASIC MACHINE LANGUAGE Occasionally it is important to be able to use machine language programs with your program, whether for speed or to utilize special features of the hardware of that machine. ZBasic incorporates a number of special commands to integrate machine language subroutines into your programs. CAUTION: Unless you have a working knowledge of the machine language of the source computer and target computer, use extreme caution when porting programs with machine language commands or subroutines. MACHLG This statement allows you to put bytes or words directly into your program: CALL LINE "Machlg": END "Machlg": REM EXAMPLE ONLY--> DO NOT USE! MACHLG 10, 23 ,233, 12, 0, B%, A, 34, 12, &EF MACHLG 23, 123, 222, 123, 232, GameScore%, &AA Hex, Binary, Octal or Decimal constants, Integer variables, or VARPTR may be used. Be sure to put a machine language RETURN at the end of the routine if using CALL. Be sure you understand the machine language of your computer before using this command. LINE This gives you the address of a specific line as it appears in the object code. This allows you to CALL machine language programs starting at specific line numbers or labels. Syntax is or LINE label LINE line number a Since the Macintosh is a 16 bit machine, MACHLG code is stored in WORDS not BYTES. The code above would be stored in every other byte. With LINE parentheses are required because it is also a toolbox call Le. LINE (n). Machine Language Support 144 MACHINE LANGUAGE SUPPORT CALL Allows you to CALL a machine language program. The syntax is: CALL address Be sure the routine being called has a RETURN as the last statement if you wish to return control to your program. If you wish to CALL a machine language subroutine in your program that was made with MACHLG, use CALL LINE line number or label. aa These versions have additional parameter passing capabilities. See appropriate appendix under CALL for specifics. II The ProDOS version provides a special interface to the ProDOS Machine Language Interface (MLI). See appendix for specifics. DEF USR 0 - 9 Allows you to set up to 10 different machine language user routines. The syntax for using this statement is: DEFUSR digit =address This command may be used to pass parameters or registers. See your computer appendix for the specifics about your computer. There are also default routines. See USR in the reference section. INTEGER BASE CONVERSIONS ZBasic makes integer BASE conversions simple. Some of the commands for converting between BASES: BIN$, HEX$, &X &H or & UNS$ OCT$, &0 See "Numeric Conversions" for specifics. a See DEFSTR LONG for configuring conversions above for Longlnteger (and also CVI and MKI$). 145 Machine Language Support MACHINE LANGUAGE SUPPORT OTHER MACHINE LANGUAGE COMMANDS Other tools for machine language programmers include powerful PEEK and POKE statements that can work with 8,16 or 32 bit numbers and BOOLEAN MATH operators. PEEK, POKE In addition to the "standard" BYTE PEEK and POKE provided by many versions of BASIC, WORD (16 bft) and LONG (*32 bit) PEEK and POKE are also provided: PEEK PEEKWORD PEEKLONG 8 BIT 16 BIT *32 BIT POKE POKEWORD POKE LONG 8 BIT 16 BIT *32 BIT !l * Macintosh only at this time. BINARY/BOOLEAN MATH FUNCTIONS OR XOR SHIFT LEFT AND NOT SHIFT RIGHT EXP and IMP may be emulated easily. See "Logical Operators" in the "Math" section of the manual. VARIABLE POINTER VARPTR (variable) will return the address of that variable. a& Macintosh: Remember to use Longlntegers to store the address since Macintosh memory exceeds 65,535 (the limit 01 regular integers). Also see DEFSTR LONG for defining integer functions to do Longlnteger. MSDOS: Check appendix for way of determining SEG 01 variable. Machine Language Support 146 STRUCTURED PROGRAMMING 147 Structure STRUCTURED PROGRAMMING ASIC STRUCTURE Much has been said about the difficulty of reading BASIC programs and the socalled spaghetti code created (the program flow is said to resemble the convoluted intertwinings of string spaghetti). While we believe structure is important, we don't believe that a language should dictate how a person should compose a program. This inhibits creativity and may even paint programmers into comers. Nevertheless, we have provided powerful structure support in ZBasic. THAT NASTY "GOTO" STATEMENT The GOTO statement has been classified by many as a programmer's nightmare. If you want programs that are easy to read, do not use this command. If you must use GOTO, do not use line numbers, use labels to make the code easier to follow. LINE NUMBERS VERSUS LABELS The standard line editor (command mode) uses line number for three reasons: 1. Remain compatible with older versions of BASIC 2. For the Standard line editor commands 3. To give more easily understandable error messages To make programs easier to read you should use alphanumeric labels for subroutines or any other area of a program that does a specific function. It is much easier to follow the flow of a program if GOSUB, GOTO and other branching statements use labels instead of line numbers. To LIST programs without line numbers use LIST+. Many versions of ZBasic now use full screen editors that don't require line numbers. See your appendix for specifics. Structure 148 STRUCTURED PROGRAMMING INDENTATION OF LOOPS, LONG FN and LONG IF Some versions of structured languages require that you manually indent nested statements for readability. ZBaslc does all the Indenting automatically! Each nested portion of a program will be indented 2 spaces when the program is listed. Program statements like FOR-NEXT, WHILE-WEND, DO-UNTIL, LONG FN, LONG-IF etc. will be indented. Example using LIST+: LONG FN KillFile(file$) PRINT@(0,10);"Erase ";file$;" YIN"; DO temp$=INKEY$ UNTIL LEN (temp$) LONG IF temp$="y" or temp$="Y" KILL tempS END IF END FN FOR X=l TO 100 DO : G=G+l WHILE X<95 PRINT "HELLO" LONG IF J< 4 J=J+l END IF WEND UNTIL G >= 3.5 NEXT X MULTIPLE LINE STATEMENTS ZBasic allows putting more than one statement on a line with ":" (colon). While this is handy for many reasons, over-use of this capability can make a program line very difficult to understand. UNSTRUCTURED 10*FORX=lT0100:DO:G=G+1:PRINT G:UNTILG=99:NEXT STRUCTURED FOR X = 1 TO 100 DO : G=G+1 PRINT G FOR V=l TO 20:NEXT UNTIL G=99 NEXT X *FOR V=l TO 20:NEXT 'Note: An asterisk will appear at the beginning of a line containing a complete loop if that line is not already indented. In that case the line will be un-indented two spaces (as in the examples above). 149 Structure STRUCTURED PROGRAMMING SPACES BETWEEN WORDS To make code more readable, you should insert spaces between words, variables and commands, just as you do when writing in English. While ZBasic does not care if spaces are used (unless you configure ZBasic to require spaces), ~ is a good practice to insert spaces at appropriate places to make reading the program easier. Hard to Read Easier to Read IFX=93*24THENGOSUB"SUB56"ELSEEND IF X=93*24 THEN GOSUB "SUBS6" ELSE END VARIABLE NAMES To make code more readable, use logical words for variables. Hard to Read Easier to Read B=OP+I Balance = Old_Principle + Interest ZBasic allows variable name lengths up to the length of a line, but only the first 15 characters in the name are significant. Do not use spaces or symbols to separate words in a name, use underlines; Buildin(LPrinciple, Freds_House. Keywords may not be used in variable names unless they are in lowercase and "Convert to Uppercase" is "NO" (this is the default). Also see next paragraph. INCLUDING KEYWORDS IN VARIABLES To allow keyword in variables configure ZBasic for; "Spaces Required after Keywords" (not available on all systems). See "Configure". HOW CASE AFFECTS VARIABLE NAMES To make the variable "FRED" and "fred" the same variable configure ZBasic for "Convert to Uppercase". See "Configure". GLOBAL VERSUS LOCAL VARIABLES Programmers familiar with LOCAL variables in PASCAL and some other languages can structure their variable names to approximate this in ZBasic. (All ZBasic variables are global.) GLOBAL variables should start with a cap~alletter. LOCAL variables should start with lowercase. Many programmers also use (and re-use) variables like temp$ or local$ for local variables. Structure 150 STRUCTURED PROGRAMMING DEFINING FUNCTIONS Use DEF FN or LONG FN to define functions and then call that function by name. This is easy reading for people trying to decipher your programs. It saves program space as well. FN names have the same definition as variable names. Passing values to functions in variables is also very easy. LONG FN may be used when a function the size of a subroutine is needed. One FN may call previously defined functions. LOADING PREVIOUSLY CREATED SUBROUTINES To insert subroutines you have used in previous programs, use the APPEND command. This will append (or insert) a program saved with SAVE+ (a non-line numbered program or subroutine), into the current program starting at the line number you specify; APPEND Iinenumber or label filename Be sure to avoid the use of line numbers or GOTO statements in your subroutine to make them more easily portable. If using variables that are to be considered LOCAL, we recommend keeping those variables all lowercase characters to differentiate them from GLOBAL variables (all ZBasic variables are GLOBAL). Sometimes LONG FN may be more appropriate for re-usable subroutines. LISTINGS WITHOUT LINE NUMBERS To make program listings easier to read, use LIST+ or LLIST+ to list a program without line numbers. ZBasic automatically indents nested statements with LIST for even more readability. ~& Macintosh: Listings can be sent to the Screen, LaserWriter or ImageWriter without linenumbers and with keywords boldfaced by using LLIST+*. MSDOS: Screen listings with highlighted keywords and no linenumbers are accomplished with LIST+* (no printer support for highlighted keywords). 151 Structure STRUCTURED PROGRAMMING LONG IF For more control 01 the I F statement. ZBasic provides LONG IF lor improved readability and power. UNSTRUCTURED 10 IFX=ZTHENY=10+H:G=G+Y:F=F+RELSEGOSUB122:T=T-1 STRUCTURED LONG IF X=Z Y=10+H G=G+Y F=F+R XELSE GOSUB"READ" T=T-1 END IF UNSTRUCTURED 10 FORI=-3T03:PRINT"I= ";I:IF I> THEN IF 1>-3 AND 1<3 PRINT I;">O",ELSEPRINT"Inner If False":GOTO 30 20 *PRINT I;"<=O", :X=-4:DO:X=X+1:PRINT"X=";X:UNTILX=I 30 NEXT I STRUCTURED FOR I = -3 TO 3: PRINT "1= ";I LONG IF I > 0 LONG IF I > -3 AND I < 3 PRINT Ii n> 0", XELSE PRINT "Inner LONG IF false" END IF XELSE PRINT Ii"<= 0", X = -4 DO : X=X+1 PRINT"X="iX UNTIL X=I ENDIF NEXT I Important Note: Any loops enclosed in LONG IF structures must be completely contained within the LONG IF. END IF construct. ~. The Macintosh and IBM versions also support SELECT CASE. a structured. multi-conditional LONG IF statement. See appendices lor syntax. Structure 152 DEBUGGING TOOLS 153 Debugging Tools DEBUGGING TOOLS ASIC DEBUGGING TOOLS To get programs running bug-free in the shortest amount of time, ZBasic has incorporated some powerful error catching tools. TRON Display program flow Tums on the line trace statement. As the program is running, ZBasic will display the line number where the program is being executed on the screen. !L Also see TRON 128 for sending the line numbers to the printer so the display is not affected. TRONS Single Step SINGLE STEP line trace debugging. Allows you to single step through that part of a program. To activate single step mode press CTRL Z. To single step press any key. To return to regular mode press CTRL Z again. To single step and display line numbers use TRONS:TRON. Note: CTRL Sand CTRL Z will function during any TRON type. TRONB Check for key Sets a break point on that line and all the following lines of that program (until a TROFF is encountered). As each line is executed, the program will check HCTRL C or is being pressed. If is pressed, the program will return to the edit mode (the operating system if RUN' was used). Without a break point the program will not respond to the key. No line numbers are displayed unless TRON was also used. !L BREAK ON is often preferable as a check for . See appendix. Debugging Tools 154 DEBUGGING TOOLS TRONX Check for on that line only Sets a break point only on that line. If CTRL C or is pressed as that line is executed, theprogram will return to the edij mode (if interactive) or to the operating system. TROFF Disable all TRON modes Turns off TRON, TRONB, TRONX and TRaNS. line number display and points will be disabled in the program flow following this statement. ARRAY BOUNDS CHECKING Set "Check Array Bounds" to "YES" when configuring ZBasic to make sure you do not exceed DIM limits. This is a RUN TIME error check and is very important for use during the debug phase. Exceeding array limits could cause overwriting of other variables and fauRy data. After you have finished debugging your program, disable this function since it will slow execution speed and increase program size. STRING LENGTH CHECKING (not all versions; check your appendix) Set "String Length Checking" to "YES" when configuring ZBasic to make sure you do not exceed defined string length limits. This is a RUN TIME error check and is very important for use during the debug phase. Exceeding string lengths could cause overwriting of other variables and/or faulty data. After you have finished debugging your program, you may wish to disable this function since ij will slow execution speed and increase program size. COMPILE TIME ERROR CHECKING ZBasic compile time error messages help you pinpoint the cause of the problem immediately by highlighting the error on the line and printing a descriptive message instead of an error number. Unlike BASIC interpreters, ZBasic will not execute a program with syntax errors in it. If the program compiles without an error you can be sure ij is at least free of syntax errors. DISK ERROR CHECKING ZBasic gives the programmer a choice of trapping disk errors themselves or letting ZBasic display the disk error. See "Disk Error Trapping" lor more information. 155 Debugging Tools PORTING PROGRAMS ASIC PORTING PROGRAMS Porting means taking a program from one computer and moving it to another computer of different type or model. As from an Apple to an IBM. Because most ZBasic commands contained in the reference section of this manual (except USR, OUT, INP, PEEK, POKE, VARPTR, CALL and MACHLG) function the same way, it is very easy to move the source code from one machine to another. The following pages will describe some of the problems and solutions of porting programs. OBJECT CODE AND SOURCE CODE There are two separate types of programs created with ZBasic and you should understand the differences. SOURCE CODE This is the text part of a program you type into the computer and looks like the commands and functions you see in this manual. In order to turn SOURCE CODE into OBJECT CODE, ZBasic compiles it when you type RUN (or RUN' or RUN+). OBJECT CODE The OBJECT CODE is what ZBasic creates from the SOURCE CODE after you type RUN. Object code is specific to a certain machine. i.e. an IBM PC uses an 8088 CPU and and Apple /I uses a 6502 CPU. The ZBASIC OBJECT CODE for each of these machines is different and cannot be ported. Port the SOURCE CODE to the target machine and then recompile it into the OBJECT CODE of that computer. FILE COMMANDS ZBasic file commands work almost exactly the same way from one computer to the next. The areas to be aware of when porting code from one machine to another are covered in the following two paragraphs. Porting Programs 156 PORTING PROGRAMS DISK CAPACITIES Make sure the target machine has enough storage space to accommodate the program and program files being ported. COMMON DRIVE CAPACITIES IBM PC, XI, jr. 5.25" 3.50" IBM PC AT 5.25 3.50" variable density Apple /I series 5.25" 3.50· Macintosh single sided double sided Macintosh Plus Other: SSSD 5.25" SSSD B.OO" SSDD 5.25" DSDD 5.25" DSDD B.OO" 320K-360K 7BOK 360K 7BOK 1200K 143K BOOK 400K BOOK SOK 200-500K 160K 320K 600-2000K SSSO: Single sided Single density 5500: Single sided Double density DSDD: Double sided Double density FILESPECS ZBasic filenameslfilespecs work within the limitations of the disk operating system. When porting programs make sure the filespecs are corrected. For instance; if porting a program from a TRS-80 Model 3 to an IBM PC, you must change all references to a file like; Fred:1 to A:Fred Some computers cannot do RENAME or EOF. Others are incapable of certain DISK ERRORS. Be sure to study the DOS manual of the target machine for variations. MEMORY Memory is another area of importance when porting programs from one machine to another. Porting from smaller machines to machines with larger memory should not be a problem, as long as other hardware is similar. Programs from TRS-BO MODEL I, 111,4, Apple lie and IIc and CP/M SO machines should port over to an IBM PC or Macintosh with little or no changes. Porting a large program (12BK or more) from a larger machine like an IBM PC or Macintosh to a smaller machine will require a number of memory saving measures covered in the following paragraphs: CHAINING PROGRAMS TOGETHER If a 12SK program is being moved to a 64K system, you will have to split it up into two or more separate programs and CHAIN them together. Since ZBasic allows sharing variables while chaining, this should solve most problems. 157 Porting Programs PORTING PROGRAMS CHECK STRING MEMORY ALLOCATION ZBasic allows the user to change the size of strings. Since some programmers on larger machines may not be concerned with creating efficient code or keeping variable memory use down, check if string size has been set. Setting string size from the 256 byte default to 32 or 64 will reduce string variable memory requirements dramatically. See DEFLEN, DIM and "String Variables" in this manual for more information about allocating memory for strings. QUOTED STRINGS Excessive use of quoted strings often occurs on larger computers because there is so much free memory. Shortening quoted strings may save memory. Also see ZBasic PSTR$function for an extremely efficient way of utilizing string constants in DATA statements and in regular statements. EFFICIENT CODE Careful examination of source code may uncover ways to decrease code size by making repeated commands into subroutines or FN's, or just cleaning up inefficiencies. RAM DISKS Some smaller computers allow the use of RAM disks. The Apple /I ProDOS version for example, allows RAM disks up to 8 megabytes, while program and variable size are limited to 4OK-50K. Utilizing a RAM disk to store indices, large arrays or whatever is nearly as fast as having that data in direct memory. USE DISK INSTEAD OF MEMORY If very large arrays or indices have been used in a large program you may have to store and access them from disk in a random file. This is slower than RAM access but is usually quite acceptable on most systems. TEXT WIDTHS Some computers have only 64 or 40 characters across the screen or 16 rows down the screen. You may have to adjust the program to accommodate this. You should think about using the PRINT% or INPUT% commands if you plan on porting programs often. PRINT% puts text at ZBasics' device independent graphic coordinates, not text column/row coordinates. This makes porting programs much simpler. Here are some ~ character layouts: COMPUTER IBM PC and compatible Apple /I series TRS-80 Modell, III TRS-80 Model 4, 4p CP/M-80 (typical) Macintosh Columns (across) 800r40 800r40 64or32 80, 64 or32 80 Almost anything ... Rows (down) 25 24 16 16 or 24 24 See appendix Porting Programs 158 PORTING PROGRAMS CHARACTER SETS Screen and printer characters vary from one computer to the next. Check the ASCII chart in the owners manuals to see the differences. (Most between 32-127 are the same.) KEYBOARD, JOYSTICK AND MOUSE Keyboards vary from computer to computer so be sure the target computer has the same keys available. If not, make changes in the program to use other keys. Joystick and MOUSE devices vary considerably. Test the controls on the target computer and make adjustments for the hardware. SOUND Sound tone may vary from machine to machine. Check program and make any adjustments needed. Some machines may not have this capability at all. DEVICE INDEPENDENT GRAPHICS ZBasic makes use of very powerful and simple graphic commands that work the same way regardless of the graphic capabilities of the target computer (or lack of). You will have to determine if the graphic hardware on the target computer is of sufficient quality to display the graphics of your program. Note: Colors and grey levels may have to be adjusted. Here are some of the typical graphic types available for some major computers: COMPUTER IBM PC and compatibles Apple ][, ][+,lIe, IIc,lIGS Apple lie, IIc, IIGS Macintosh TRS-80 Modell,lII TRS-80 Model 4, 4p CP/M-80 (typical) KAYPRO with graphics Horizontal x Venlcal pixels CGA: 640x200 (3 color) or 320x200 (8 color) EGA: 640x348 (many colors) HERCULES and HERCULES PLUS: 720x348 MDA: 80x25 (text simulation) Hi-Res 280x192 (6 color) Double Hi-Res 560x192 (16 color) 512x340 (larger monitors also supported) 128x48 160x72 RS and Micro-Lab's hi-res boards 640x240 80x24 (text simulation) 160x100 MACHINE DEPENDENT SUBROUTINES If the program being ported contains machine language subroutines, you will need to rewrite those routines in the machine language of the target computer. Watch out for: DEFUSR MACHLG PEEK POKE USR LINE PEEKWORD POKEWORD OUT CALL PEEKLONG POKELONG INP Unless you completely understand the machine language of both the target and source computer, use extreme caution when porting programs with these commands. 159 Porting Programs PORTING PROGRAMS MACHINE SPECIFIC COMMANDS In order to take advantage of unique or special features of some computers, ZBasic offers special commands that will not work or function on others. Be sure the program you are porting contains only commands from the reference section of this manual. Special ZBasic commands may have to be rewritten for the target computer. Be sure to read the ZBasic appendices for both the Target and Source computers. They will explain in detail the special commands for each system (you must purchase a version of ZBasic for each computer you wish to compile from). METHODS OF TRANSFERRING SOURCE CODE FROM ONE MACHINE TO ANOTHER Telephone Modem Transfer Transfer files using a Modem and simple communications software routines like the ones under OPEN"C" in the main reference section of this manual. Serial (RS-232) Transfer Transfer files over the Serial (RS-232) ports of the two computers using a good communication software package like Crosstalk or SmartCom. Crosstalk is available at computer or software stores nationally. Diskette File Transfer Utility Programs Use Diskette file transfer utility programs like Uniform or Interchange. These programs will convert a file from one disk format, like from a TRS-80 diskette, to another disk format, like MS-DOS or CP/M. These programs are available from computer or software dealers nationally. Re-type the Program Type the program into the other computers. This may be acceptable for small programs but you will save plenty of time by using one of the options above. See OPEN"C" in the reference section for a ZBasic terminal routine that may be used to transfer files. Important Note: Always transfer files in ASCII. Tokens are not necessarily the same from one version of ZBasic to another and from old versions to newer versions on the same machine. Porting Programs 160 CONVERTING OLD PROGRAMS 161 Converting old Programs CONVERTING OLD PROGRAMS ASIC CONVERTING PROGRAMS WRITTEN IN OTHER VERSIONS OF BASIC ZBasic is a very powerful and improved version of BASIC. Many of the traditional BASIC commands have been retained to make conversion as easy as possible. Nevertheless, ZBasic is not 100% compatible with every BASIC. You will have to make some changes to your old programs if you wish to convert them to ZBasic. If file and graphic handling are not used, conversion will normally be very simple. If files or graphics are used the conversion will take a little more thinking. The following pages will give you important insights into making the conversion process as easy as possible. The following pages will give you some ideas about converting your older BASIC programs. Following the paragraphs step-by-step will make conversion much easier. SAVE YOUR OLD BASIC PROGRAM AS ASCII OR TEXT Save your old BASIC program in ASCII or TEXT format so it can be loaded into ZBasic. ZBasic tokens are different from other BASIC tokens so loading them without first converting them to ASCII will make programs loaded look like random control codes or the wrong commands (if the program will load at all). See the owners manual for the older BASIC to determine how to save in ASCII or TEXT format for your computer. The typical syntax is; SA VE '1ilename",A . Note: When upgrading to newer versions of ZBasic, programs may have to be saved in ASCII in the older version before loading into the newer version since tokens may have changed. Converting old Programs 162 CONVERTING OLD PROGRAMS CONFIGURING ZBASIC TO MAKE CONVERSIONS A LOT EASIER ZBasic has been configured to give you maximum performance. When converting older BASIC programs this can be a problem. Often they are configured for ease of use instead of performance. ZBasic allows you to configure options so that converting your programs is simpler. Setting some of the options below will also make ZBasic more like the BASIC you may be used to (like MSBASIC and BASICA). Be sure to see "Configure" in the main reference section and in your appendix for details about other ways of configuring ZBasic. To solve many of the problems encountered in converting we suggest setting the following options when converting other programs. Be sure to set these options BEFORE LOADING your program: CONFIGURE OPTION 1. Double precision digits of accu racy 2. Single Precision Accuracy 3. Array bounds checking YIN 4. Default Variable type ingle, ouble, nteger 5. Convert to Uppercase YIN *6. Optimize expressions for Integer YIN *7. Spaces Required between Keywords YIN S Y N Y 1. Since ZBasic does all floating point operations in double preCision, it is important to configure ZBasic for the speed and accuracy that you need. In most cases the configuration above will be suitable (but not in all cases). If you wish disk files and memory requirements to be the same as MSBASIC leave the digits of accuracy at 14 and 6 as they take up B bytes of Double and 4 bytes for single (the same as MSBASIC). 2. Set to two digits less than Double precision. 3. Sets array bounds checking to give runtime errors. Set to "N" when your program is debugged. 4. Set to Single (S) if you want code to be most like other BASICs. We highly recommend you set ~ to Integer if possible. Integer will often increase program speeds 10 to 100 times. 5. Setting allows variables like "Fred" and "FRED" to be the same variable. If you want CASE to be significant, do not change the configuration. 6. ZBasic gives you two options for deciding how expressions may be evaluated. ZBasic defaults to optimizing expressions for Integer to get the fastest and smallest code. Most other languages do not. Set to "N" for easier conversions. See "Math" for explanation of ZBasic options for expression evaluations. 7. Some BASICs allow using keywords in variables (like INTEREST). To allow this, spaces or other non-variable type characters are required around keywords. Set this for easier conversion in most cases (especially IBM PC and Macintosh BASIC type programs). 'Note: Not available on all versions of ZBasic. 163 SET TO 60rB 40r6 Y Converting old Programs CONVERTING OLD PROGRAMS CONVERTING RANDOM FILES ZBasic incorporates FIELD, LSET, MKI$, MKS$, MKD$, CVI, CVS, and CVD into the READ and WRITE statements saving the programmer a lot of time. RECORD is used instead of GET and PUT for positioning the file pointer. The OPEN and CLOSE statements are the same for both BASICs except for MSBASIC use of OPEN FOR RANDOM type. This is changed easily. ZBASIC statements OPEN"R" MSBASIC equivalents OPEN"R" or OPEN FOR RANDOM READ, WRITE, RECORD FIELD, GET, PUT, LSET, RSET, CVS, CVD, MKS$, MKD$, CVI, MKI$ Note: While ZBasic also supports MKI$, CVI and MKB$, CVB, they are not necessary for use in Random files since ZBasic's READ and WRITE automatically store and retrieve numeric data in the most compact format (ZBasic's MKI$, CVI, MKB$ and CVB are most useful for condensing numbers for other reasons). Since ZBasic allows using any variable type in READ and WRITE statements, the user is not faced with complicated conversions of strings-to-numbers and numbers-to-strings. CONVERTING SEQUENTIAL FILES Most ZBasic Sequential file commands are very similar or the same to MSBASIC. ZBASIC statements OPEN"I" or OPEN"O" OPEN"A" some versions EOF(n) some versions MSBASIC equivalents OPEN"I", OPEN"O" or OPEN"A" or OPEN FOR INPUT, OUTPUT or APPEND some versions EOF(n) some versions L1NEINPUT, INPUT, PRINT L1NEINPUT, INPUT, PRINT Note: The biggest difference when converting sequential file statements is that ZBasic's PRINT# statements should have quoted commas: MSBASIC: PRINT#l, A$, B$, C$ or PRINT#l, A$ B$ C$ ZBASIC: PRINTjfl, A$", "B$", "C$ DISK ERROR TRAPPING ZBASIC statement ON ERROR GOSUB MSBASIC equivalent ON ERROR GOSUB Read "ON ERROR" and "Disk Error Trapping" in this manual for detailed information. ZBasic error codes are much different from MSBASIC. Important Note: ZBasic does not necessarily store data in disk files in the same way or format as other versions of BASIC. You may have to convert existing BASIC files to ZBasic format. Converting old Programs 164 CONVERTING OLD PROGRAMS CONVERTING GRAPHIC COMMANDS ZBasic's Device Independent Graphics are very powerful and simple to understand. Conversion should be painless in most cases: ZBASIC GRApHICS PLOT CIRCLE BOX COLOR MODE POINT GET, PUT (some systems) RATIO FILL PLOT USING MSBASIC equivalent LINE, PSET, PRESET CIRCLE LINE (with parameters) COLOR (PSET, PRESET black and white) SCREEN POINT GET, PUT (some systems) aspect parameter of CIRCLE PAINT DRAW ZBasic defau Its to a relative coordinate system of 1024x768. This system does not pertain to pixels but to imaginary positions on the screen. Most older versions of BASIC use pixel coordinates. a.a Macintosh and MSDOS: Use COORDINATE WINDOW at the beginning of program to set a program to pixel coordinates. Apple: See appendix for ways of using POKE to set system to pixel coordinates. LOOP PAIRS All ZBasic FOR-NEXT, WHILE-WEND and DO-UNTIL loops must have matching pairs. Some BASIC interpreters allow the program to have two NEXTs for one FOR, or two WENDs for one WHILE. Since ZBasic is a compiler it will not allow this. A STRUCTURE ERROR will be generated when you compile a program with unmatched LOOP pairs. Another way to find unmatched pairs is to LIST a program. Since ZBasic automatically indents loops, just read back from the end of the LiSTing, looking for the extra indent, to find the unmatched statement. COMPLEX STRINGS Complex strings may have to be converted to simple strings (some machines). Improper Proper B$=LEFT$(Right$(A$,12), 13) B$=RIGHT$(A$,12): B$=LEFT$(B$,13) IF-THEN statements may have only one level of complex string. Improper Proper 165 Converting old Programs IF B$=LEFT$(A$,5) THEN GOSUB "END" C$=LEFT$(A$,5): IF B$=C$ THEN GOSUB "END" CONVERTING OLD PROGRAMS LONG LINES Multiple statement lines with over 253-256 characters (depending on computer) will automatically be shortened by ZBasic when loading. That part of the line longer than 253 will be added to a new line number. Most programs do not have lines of that length. TIMING LOOPS Timing loops may have to be lengthened to make up for ZBasic's faster execution time. For some BASIC Languages a FOR-NEXT loop of 1000 would take second or two. (About 111000 of a second in ZBasic!) Replace these types of delay loops with the ZBasic DELAY statement. STRING MEMORY ALLOCATION ~ Important Note: ZBasic assumes a 255 character length for every string and string array element and allocates 256 bytes for each (255+1 for length byte) unless string length is defined with DIM or DEF LEN. Many versions of BASIC, like BASICATM, MSBASICTM, APPLESOFTTM and others, allocate string memory as a program needs. While this may seem efficient on the surface, immense amounts of time are wasted in "String Garbage Collection". Garbage Collection is what happens when your program suddenly stops and hangs up for two or three minutes while BASIC rearranges strings in memory. This makes this method unusable for most serious programming. HOW DIMMING STRING ARRAYS AFFECT PROGRAM CONVERSION MSBASICTM: CLEAR 10000 DIM A$(1 000) ZBaslc™: ZBaslc™: DIM A$(1000) DIM 10 A$(1000) Sets aside 10,000 bytes for ALL strings Uses memory allocated with CLEAR plus 3-8 byte pointers per element. 256,256 bytes allocated (1001x256) 10,010 bytes allocated (1001x10) Many BASICs use CLEAR to set aside memory for strings. Each string in ZBasic is allocated memory at compile time. A problem you may encounter while converting: Out of Memory Error from DIMension statements, like the ones above (just define the length of the string elements). ZBasic allows you to define the length of any string with DEFLEN or DIM statements. Check the string requirements of the program you wish to convert and set the lengths accordingly. If you have large string arrays that must have elements with wide ranging lengths (constantly changing from zero to 255 characters), use ZBasic's speciallNDEX$ string array. Like other BASIC's CLEAR is used to set aside memory for this array (no "Garbage collecting" here either). See INDEX$, DEFLEN, DIM and "String Variables" for more information. Converting old Programs 166 CONVERTING OLD PROGRAMS OTHER INFORMATION Check your appendix for more information about converting programs. A good resource for information about converting from one version of BASIC to another is David Lien's "The BASIC Handbook". CONVERTING OLD COMMANDS Some BASIC(s) have commands that may be converted over quickly using a word processing program. Simply load the BASIC ASCII file into the word processor and use the FIND and REPLACE commands. (You may also use ZBasic FIND command if you choose.) A good example would be converting Applesoft™'s HOME commands into ZBasic's CLS command. Have the word processor FIND all occurrences of HOME and change them to CLS. If you don1 have a word processor try using this simple ZBasic convert program to change commands in a BASIC file quickly (file MUST have been saved in ASCII using SAVE*). SINGLE COMMAND CONVERSION PROGRAM ON ERROR GOSUB "DISK ERROR": REM Trap Disk Error INPUT"Command to Change:";Old$ INPUT"Change to:";New$ CLS: PRINT" Changing File .... One Minute please" OLDFILE$="oldfile" :NEWFILE$="newfile": REM < .. Change to correct filenames OPEN"I",l, OLDFILE$ OPEN"O",2, NEWFILE$ WHILE ERROR=O LINEINPUT#l, Line$ DO Line$=LEFT$ (Line$, I-I) +New$+RIGHT$ (Line$, LEN (Line$) -I+l+LEN (Old$)) I=INSTR(l, Line$, Old$) UNTIL 1=0 PRINT#2, Line$ WEND "Done Changing" ERROR=O CLOSE PRINT "All '";Old$;''' have been converted to '";New$;''''' INPUT"Rename OLD file? YIN: "; A$: A$=UCASE$ (A$) IF A$="Y" THEN KILL OLDFILE$ RENAME "NEWFILE" TO OLDFILE$ END "DISK ERROR" PRINT ERRMSG$(ERROR) CLOSE: STOP Important: Practice on a dummy file until you are sure the program is working properly. 167 Converting old Programs KEYWORDS ASIC STANDARD STATEMENTS, ABS AND ASC ATN BIN$ BOX CALL CHR$ CIRCLE CLEAR CLOSE CLS COLOR COS CVB CVI DATA DATE$ DEF DEFDBL DEFINT DEFSNG DEFSTR DELAY DIM DO ELSE END ERRMSG$ ERROR EXP FILL FUNCTIONS AND OPERATORS FIX FN FOR FRAC GOSUB GOTO HEX$ IF INDEX$ INDEXF INKEY$ INP INPUT INSTR INT KILL LEFT$ LEN LET LINE LaC LOCATE LOF LOG LONG LPRINT MACHLG MAYBE MEM MID$ MKB$ MKI$ MOD MODE MOUSE NEXT NOT OCT$ ON OPEN OR OUT PAGE PEEK PLOT POINT POKE pas PRINT PSTR$ RANDOM RATIO READ REC RECORD REM RENAME RESTORE RETURN RIGHT$ RND ROUTE RUN SGN SIN SOUND SPACE$ SPC SOR STEP STOP STR$ STRING$ SWAP TAB TAN THEN TIME$ TO TROFF TRON UCASE$ UNS$ UNTIL USING USR VAL VARPTR WEND WHILE WIDTH WORD WRITE XELSE XOR IMPORTANT: See your computer appendix for other keywords that pertain to your version of ZBasic. Most versions of ZBasic offer more and also use two-word keywords like LONG FN, POKE WORD etc. Keywords 168 KEYWORDS STANDARD COMMANDS APPEND AUTO DELETE or DEL DIR EDIT. E or comma .... FIND or semicolon ";" 169 Keywords HELP LIST. L or period .... LLiST LOAD MEM MERGE NEW QUIT RENUM RUN SAVE ---- STANDARD REFERENCE ASIC STANDARD REFERENCE GLOSSARY This reference section is an alphabetical listing of the "Standard ZBasic Commands". The following paragraphs describe the information layout and syntax of this section. TYPE OF INFORMATION CONTAINED IN THIS REFERENCE SECTION function statement command operator Retums a value; used wherever an expression is used Executed by Hself Used from the standard line edHor mode; EDIT, SAVE. .. Like AND, OR, XOR or NOT COMPATIBLE COMMANDS BLACK BAR SPECKLED BAR may Check to see if your system does not support that command. PAGE LAYOUT The pages are layed out in the same way. Whenever possible descriptions are kept to one page. The header has the command type and description. Paragraph layout is: FORMAT DEFINITION EXAMPLE REMARK Correct syntax for that statement, function or command Definition or explanation of usage Program example or direct example of usage. Note that linenumbers are usually omitted. Add linenumbers if needed. Other information of importance and usually a reference to other related sections that will aid the understanding of that item. IMPORTANT NOTE ABOUT DIVIDE ZBasic compiles divide symbols based on configuration. If the default expression evaluator; "Optimize Expressions as Integer?" is YES; I=integer divide \=floating point divide If the expression evaluator; "Optimize expressions as Integer?" is NO; 1= floating point divide \=integer divide See "Configure" and "Converting Old Programs" and "Math expressions" for more information about the options offered for expression types and how they are evaluated. continued next page ... Standard Reference 170 STANDARD REFERENCE CROSS REFERENCE These commands work the same way on almost every version of ZBasic. There is an extensive cross-reference to other commands and how a command works on specific machines. The reference section uses a computer icon to bring attention to a specific version of ZBasic. The following icons are used: II l i D O S 3.3 and ProDOS versions. MSDOS and IBM PC and compatible versions. !b The Macintosh versions (all except the 128K machine). ell Z80 machines; Amstrad, CP/M-80 2.x and higher, Kaypro Graphics versions and TRS-80 model 1, 3 and 4 versions. SYNTAX GLOSSARY GLOSSARY PEFINITION RUN or COMMAND What follows is program or command output. Items within the brackets are optional (may be omitted) Anyone of A, B or C may be used Three periods following ijems indicates a repeating sequence Something you type in, a program example, or program output Numeric: Any; including integer and floating point Numeric: 0-255 Numeric: 0 to 65,535 or ±32,767 Numeric: 0 to 4,294,966,293 or ±2,147,483,647 Any Variable String, integer, Longlnteger, single or double precision variable types, respectively Quoted strings (string contants) String variable, string contant, BIN$, CHR$, HEX$, INDEX$, OCT$, PSTR$, STR$, SPACE$, STRING$ or UNS$. File number: An expression 1-99. See "Configure" A legal filename for that operating system filename Drive or storage volume specifier A line number from 0 to 65,534 or a "label" Requires a number. No variable or expression allowed A valid variable name [brackets I { AlBIC} ... repeats Courier text expression or expr byte expression word expression long expression variable or var var$, vat'/o, var&, var!, var# "string" simplestring or string filenumber filename filespec line number varname Be sure to take note when you see this hand. It is pointing out important information about using that command. If there is the message "Important Note" with the hand it is even more critical that you read the notes. 171 Standard Reference function ASS FORMAT ABS ( expression ) DEFINITION Returns the absolute value of an expression. The absolute value is the value without regard to the sign (negative, zero or positive). The result of ASS will always be a positive number or zero. EXAMPLE A=-15: B=15 PRINT ABS(A), ABS(B), ABS(-555) X=ABS (0) PRINT X RUN 15, 15, 555 o REMARK The SGN function will return the sign of an expression. Standard Reference 172 FORMAT expression1 AND expression2 DEFINITION Used to determine if BOTH conditions are true. If both expression1 AND expression2 are true (non-zero), the result is true. Retums -1 for true, 0 for false. See AND truth table below. Also used to compare bils in binary number operations. 1 AND 1 return a 1, all olher combinations of O's and 1's produce O. See truth tables below. EXAMPLE IF 30>20 AND 20<30 THEN PRINT "TRUE " IF "Hi"="hello" AND 6-5=1 THEN PRINT "TRUE TOO!" RUN TRUE PRINT BIN${ &X00001111 AND &X11111111) PRINT 4 AND 255 RUN 0000000000001111 4 REMARK See OR, XOR and NOT. AND TRUTH TABLE condition AND condition TRUE(-1) if both conditions TRUE, else FALSE(O) AND 1 AND o AND 1 AND o AND BOOLEAN "16 BIT" LOGIC 00000001 00000111 AND 00001111 AND 00001111 00000001 00000111 1 1 0 0 l!b 1 o o o Longlnteger will function wilh this operator in 32 bits. 173 Standard Reference command APPEND line or label line or label ["I filename [ "I ["I filename [ "I FORMAT APPEND APPEND· DEFINITION Used to append or insert a program segment or subroutine (saved with SAVE+) into the present program in memory. A non-line numbered ASCII program file is required to append a subroutine into the present program in memory at the specified line number. Line numbers will be assigned in increments of one. APPEND" will strip REM(arks) and spaces to free up more memory for the program as the program in inserted. EXAMPLE 10 20 30 40 50 "TEST ROUTINE" FOR I = 1 TO 10 PRINT I NEXT I RETURN SAVE+ TEST .APP APPEND 31 TEST.APP LIST 00010 00020 00030 00031 00032 00033 00034 00035 00040 00050 REMARK "TEST ROUTINE" FOR I = 1 TO 10 PRINT I "TEST ROUTINE" FOR I = 1 TO 10 PRINT I NEXT I RETURN NEXT I RETURN <----Subroutine inserted here <--- (Example only, program will not run) The program to be appended must be in ASCII format and not contain line numbers. Use the SAVE+ command to save programs without line numbers. If any line number being used in APPEND already exists, it will overwrite the existing line. Also see MERGE, LOAD, SAVE, SAVE', SAVE+. Standard Reference 174 Ase function FORMAT ASC ( string) DEFINITION Returns the ASCII code value (a number between 0 and 255) of the first character in a string. ASCII stands for American Standard Code for Information Interchange. EXAMPLE PRINT ASC("A"), ASC("B") PRINT CHR$(65), CHR$(66) PRINT ASC("America") RUN 65 66 A B 65 REMARK ASC returns 0 if the length of string is zero or the ASCII code of the string is zero. Use this logic to determine the true status if an ASCII zero is the resuH: LONG IF ASC(A$)=O AND LEN(A$»O PRINT "ASCII code of A$ =0" XELSE PRINT"A$ is an empty string" END IF The inverse function of ASC is CHR$. To return the character represented by the ASCII code, use CHR$(ASCII number). ASCII codes may vary from machine to machine. ASCII codes 32 through 127 are usually the same for all microcomputers. See CHR$ with example ASCII listing. 175 Standard Reference function ATN FORMAT ATN ( expression) DEFINITION Returns the angle, in radians, for the inverse tangent of expression. A=ATN(Y/X), PI=ATN(1)« 2 EXAMPLE pijI=ATN(l) PRINT pijI « 2 RUN 3.141592 ___ <---Based on digits of accuracy set in configuration. REMARK ATN is a scientific function. Using ATN in an expression will force ZBasic to calculate that part of an expression in Double Precision. ZBasic allows you to configure the accuracy for scientific functions separately for both Double and Single Precision. See "Configure". Also see "Expressions" and "Derived math functions" in the "MATH" section of this manual. Standard Reference 176 AUTO command FORMAT AUTO AUTO starting line AUTO starting line, increment AUTO ,increment DEFINITION This command automatically generates line numbers in the Standard Line editor to save time. The two optional parameters are: starting line increment Starting line number (default is 10) Line spacing (default is 10) To end AUTO line numbering press either or at the first line number you will not use. EXAMPLE AUTO 10 20 30 AUTO 100,20 100 *120 130 REMARK Standard Reference <---- Careful this line already exists!! An asterisk appearing before a line number indicates an occupied line. Pressing will skip that line leaving the original contents intact and resume auto line numbering with the next line. To remove the line type a space and . Also see LIST, EDIT 177 <---- Type in text then to go to next line. statement BEEP ........................................................................................................................................................................... .l'."'."' ....... "' ................... "' .... "'.rI'.......... .. • "' ....... .". • .". ....... "'."'.". .... "' .......... .1' .... "'."' .... .". • .,. .... "' .... "..rl'."'.rI' .... "." .... -:""'""'""'"":""'""'"":"":""'""'"":':.":"":""'""'"":""'""'""'"":""'""'"":0:.":""'""'"":",,:" ... "... "... "... "... "... ".... "... ".... ":" ... "... ",,:":-" ... "... "... "... "... ",,:",,:':.,,:":"0:.:00 FORMAT BEEP DEFINITION Sounds the speaker. EXAMPLE FOR X=1 TO 10 BEEP NEXT RUN BEEP, BEEP ... REMARK Also see SOUND. BEEP is not supported with Apple /I or zao computers. For Apple /I and most CP/M computers use PRINT CHR$ (7) instead. See your SOUND and your computer appendix for other ways of creating audio output. Standard Reference 178 BASE OPTION conti o or 1? FORMAT Array Base DEFINITION An option in the ZBasic configuration routine to set the array BASE to either zero or 1. The default is zero. EXAMPLE See "Configure" in the beginning of this manual for an explanation of configuring your version of ZBasic to your preferences. ARRAY BASE ZERO DIM A(lDD) DIM Tables (22) <-- elements 0-100 (101 elements) <-- elements 0-22 (23 elements) ARRAY BASE ONE DIM A(lDD) DIM Tables REMARK 179 Standard Reference (22) See DIM and "Array Variables". <-- elements 1-100 (100 elements) <-- elements 1-22 (22 elements) function BIN$ FORMAT BIN$ (expression ) DEFINITION Returns a 16 character string which represents the binary (BASE 2) value of the result of the integer expression. Sorne typical binary numbers: 0000000000000001 0000000000000011 0000000000000111 0000000011111111 0000000100000000 1111111111111111 EXAMPLE 1 3 7 255 256 -1 (65,535 unsigned) The following program will convert a decimal number to binary or a binary number to decimal: "Binary Conversion" CLS DO INPUT"Decimal number to convert: ";Decima1% PRINT BIN$(Decima1%) INPUTUBinary number to convert: ";Binary$ Binary$="&X"+Binary$ PRINT VAL(Binary$) UNTIL Decimal% = 0 RUN Decimal number to convert: 255 0000000011111111 Binary number to convert: 0000000000000011 3 REMARK Note that conversions are possible from any base to any other base that ZBasic supports. &X is the inverse function of BIN$. Also see HEX$, OCT$, UNS$ and "Numeric Conversions". !b Use DEFSTR LONG to set BIN$ and &X to work in Longlnteger (32bits). Standard Reference 180 BOX statement FORMAT BOX [TO] expr x1 ,expry1 [TO expr x2 , expr y2 ...] BOX FILL [TO] exprx1 ,expry1 [TO exprx2' expr y2 ...] DEFINITION Draws a BOX from the coordinates defined by the first comer (x1.y1) to the coordinates defined by the opposite corner (x2.y2) in the current COLOR. If BOX TO x.y is used the first comer will be the last graphic point used. If undefined then 0.0 will be the defauH. If the optional FILL appears directly after the command. the BOX will be painted as a solid BOX in the current color. The defauH screen positions are given using Device Independent Coordinates of 1024 across by 768 down. EXAMPLE BOX 209 465 843 987 0.0 .-"""c.L"w.'",,".!.!"w.'~:'''''''c.L'w. ........c.L..w..~.:.!.!..w..u....., ..c.L..w.·.......!.! ..w.·""".1.:':cL'u.........!.!..w.·"""-!-i.'!.!.'!-'.,1023 134 1. ·~~~·~~·~·~r .~~ ·~~7············· ~ :,·:··0:. . . . . .:/ BOX FILL 843.134 TO 987.643 767 REMARK 181 Standard Reference The output will vary depending 01'1 the graphic capability of the host computer. Also see CIRCLE. MODE. FILL. PLOT. RATIO and COLOR. statement CALL FORMAT CALL number CALL LINE line or label DEFINITION CALL will execute a machine language subroutine at the address specified by number or the address of the compiled line. EXAMPLE Use these examples only if you understand machine language. REM TRS80 I & III, CALL DEBUG CALL &H440D REM CPM 80, CALL WARM START (Exits to DOS) CALL 0 REM APPLE CALL TO SOUND BELL TONE CALL -198 10 20 30 40 50 REMARK REM CALL LINE examples CALL LINE 40 CALL LINE "LABEL" MACHLG 34, 21, x%, 255, 9: RETURN "LABEL": MACHLG. RETURN CALL is useful for transferring program control to a machine language subroutine from which a return to the ZBasic program is desired. The routine to be called must be terminated by that machine's instruction for RETURN. Also see MACHLG, USR, LINE and DEFUSR. ~ WARNING: Use of this command requires an understanding of machine language programming and the computer hardware being used. Porting of this code may not be possible without re-writing the machine language routines. ~. See CALL in your appendix for enhancements. Standard Reference 182 CASE statement .................................................................................................................................................................. "' .......... ;a .... "'.J'.rI' ................ "' .... oI' ......."' ....... ".."' .... ". .... " .... "' .... rI' ................ "."' ....... "' .... ". ....................,. ...... . '''''''':'''r'':'''''''''''''':''''''''''''''''''''''''''''':''''''''':'''''''''''''':'''':'''''''''''''''''''''''''''''''''''"":' ... "..."... "... "":" ... "... "..."... "... "... ":-" ... "... "... "... "... "":''':'''':'''':'''':'' ... '''':' ... ' ... FORMAT SELECT [CASE] [expression] CASE [IS] relational condition I. relational condition] statement [:statement:...]] CASE [IS] condition [. condition] [....] statement [:statement:...]] CASE boolean expression statement [:statement:...]] CASE ELSE statement [:statement ... ]] END SELECT DEFINITION When SELECT/CASE is encountered. the program checks the value of the controlling expression or variable. finds the CASE that compares true and executes the statements directly following the CASE statement. After these statements are performed. the program continues at the line after the END SELECT statement CASE relational .... I. ... ] If the expression after SELECT compares true to anyone of a number of relational conditions. the statements following the CASE are executed and the program continues after the END SELECT: SELECT 12 CASE >10 PRINT "This is the right answer" CASE >20, <10 PRINT "This is not true" END SELECT program continues here ... CASE condition.... If the expression following the SELECT equals anyone of a number of conditions the statements following the CASE are executed (program continues after the END SELECT). A=23 SELECT A CASE 10 PRINT "This is the wrong answer" CASE 10,23,11,10 PRINT "This would be true" END SELECT CASE boolean If an expression after SELECT is omitted. you may use a boolean or TRUE/FALSE condition. The statements after the first TRUE (non-zero) CASE condition will be executed. Only one boolean statement is allowed following CASE. A=10:B=20 SELECT CASE (A=10 AND A>20) PRINT "This is the correct answer" CASE (A>B OR A=B) PRINT "This is the wrong answer" END SELECT 183 Standard Reference statement CASE ................................................................................................................................................................. ·"."'."' ...."'·I'·"'·I'· ..·.. ·rlI." ...."'." . .r-..oI' ........ ,,.."' • ."'."'.".."..".rI'." .... "."'.".rI'."."."'.". .... "....... .. .I'."..·"·". .... .I' "..,/'.J'.". .... "'""'""'""'""'""'"":"":"":""'""'""'""'""'""'"":""'""'""'"":"":"":"":""'"":""'""'" ":.":.":.":''':.'':''':.'':.'':.'':.'':.'':.'':~:-.'':.'':.'':.'':''':''':':.'':.'':.'':':'':.'':':.'':'. CASE ELSE If all of the CASE statements in the SELECT CASE structure are false the statements following the CASE ELSE are executed. "Start" A$="Maybe" SELECT A$ CASE "Yes" PRINT "Thank you for saying Yes" CASE "No" PRINT "Thank you for saying No" CASE ELSE PRINT "You smart aleck! "<--Does this one END SELECT REMARK This is a powerful structured way of doing complicated IF-THEN-ELSE or LONG IF statements especially when there are multiple lines of complicated comparisons. This structure is also much easier to read than complicated IF statements. See SELECT for more information. Important Note: Never exij a SELECT CASE structure using GOTO. This will introduce problems into the stack and cause unpredictable system errors. Always exit the structure at the END SELECT. Be sure to enclose loops and other contructs completely within the SELECT-CASE and CASE ELSE constructs. !i"l -"" The Z80 versions do not support SELECT CASE. See LONG IF and IF for ways of doing the same thing. The Apple DOS 3.3 and ProDOS versions does not support SELECT CASE. See LONG IF and IF for ways of doing the same thing. Standard Reference 184 CHR$ function FORMAT CHR$ (expression ) DEFINITION Returns a single character string with the ASCII value of the result of expression. The range for the value of expression is 0 to 255. The inverse function of CHR$ is ASC; EXAMPLE "Print ASCII character set for this computer" CLS REM Use ROUTE 128 here to send output to printer. FOR I=32 TO 127 STEP 8 FOR J= 0 TO 7: X =I+J PRINT USING "###=";X;CHR$(X);" "; NEXT J :PRINT NEXT I RUN 32= 40=( 48=0 56=8 64=@ 72=H 80=P 88=X 96=' 104=h 112=p 120=x 33=! 41=) 49=1 57=9 65=A 73=I 81=Q 89=Y 97=a 105=i 113=q 121=y 34=" 42=* 50=2 58=: 66=B 74=J 82=R 90=Z 98=b 106=j 114=r 122=z 35=# 43=+ 51=3 59=; 67=C 75=K 83=S 91=[ 99=c 107=k 115=s 123={ 36=$ 44=, 52=4 60=< 68=D 76=L 84=T 92=\ 100=d 108=1 116=t 124=1 37=% 45=53=5 61== 69=E 77-M 85=U 93=] 101=e 109=m 117=u 125=} 38=& 46=. 54=6 62=> 70=F 78=N 86=v 94=A 102=f 110=n 118=v 126=- 39=' 47=/ 55=7 63=1 71=G 79=0 87=W 95= 103;;;g 111=0 119=w 127=# PRINT CHR$ (64) PRINT ASC("A") RUN A 64 REMARK When the program above is run, the character set for that computer will be displayed. Some of the characters above may differ from what you get on your system. Try changing the range above from 127 to 255. Some computers have extra characters or graphic symbols for these codes. Characters in the range of 0-31 are usually reserved for control codes like linefeed (10), carriage return (13) ... If the PRINT statement is changed to lPRINT the printer's character set will be printed. If expression is less than 0 or greater than 255, only the low order byte will be used. CHR$ (256) CHR$(257) 185 StandardReference CHR$(O) CHR$ (1) statement CIRCLE FORMAT DEFINITION CIRCLE [FILL) CIRCLE CIRCLE expr1, expr1, expr1, expr2, expr2, expr2' PLOT expr5 , exprS ' exprB exprB Draws a CIRCLE in the current COLOR. If the optional FILL is used directly after the command, the CIRCLE will be filled with the current COLOR. If TO is used, a PIE segment will be displayed (shaped like pie slices). If PLOT is used, only the ARC segment will be displayed (a segment of the circumference). expr1 expr2 exprR exprs exprB horizontal center vertical center radius (diameter of circle) in graphic coordinates start of angle in brads (zero starts at 3:00 o'clock) Number of brads to draw ARC or PIE (counter clockwise). o or 256 126 192 DeQrees INSIDE circle 6rods OUTSIDE circle EXAMPLE SEE ILLUSTRATIONS ON FOLLOWING PAGE. REMARK CIRCLE uses the ZBasic Device Independent Graphic Coordinates of 1024 x 768. For more details see the CIRCLE in the "Graphics" section in this manual. Also see RATIO, MODE, PLOT, COLOR, FILL and BOX. :!b& MacIntosh: See COORDINATE WINDOW for pixel coordinates and toolbox for ways of using QuickDraw for creating boxes. MSDOS: See COORDINATE WINDOW for converting to pixel coordinates. Apple: See appendix for ways of converting to pixel graphics. Standard Reference 186 CIRCLE statement EXAMPLE exprt. exprt. CIRCLE CIRCLE FILL 320 D,D expr2. expr2. exprR exprR CIRCLE 8!iD 1'11111\1'1111'1'1'111111"1'1'11'"'11111'" lD23 ~4 : C6)IRCLE3~'~4'300 ~ 3OO ' radJUS • CIRCLE FlLL850: 624, 50 6 2 4 , : " " " " " , , , , , , , , , , , , , , , , , , , , , , . , 50 674 .: " • . . . . . . • . . . . . . • . . • . • . . . . . . . . . • . . . .. radius " " 767 SEGMENT OF A CIRCLE (ARC) 0,0 512 1023 " CIRCLE 512.383,320::7PLOT ~.32 ····: · 383"! ~ ~.. " " " " """""""""""U""""'" CIRCLE 512.383.320 PLO~ i 192.64 767 CIRCLE exprt. expr2' exprR TO exprs. exprB SEGMENT OF A CIRCLE (PIE) 512 " .. " ............. ;..................... 0.0 ",1 • 767 187 Standard Reference """':':<0. Standard Reference 190 COLOR statement FORMAT COLOR [= I expression DEFINITION Sets the COLOR to be used by all graphic drawing commands. Color values will vff.ry from one compuler to the next. See your computer appendix for specifics. For most computers 0 is the background color and -1 is the foreground color. If you have a black and while monitor, 0 is Black, -1 is white. If your computer is incapable of graphics or you are using one of the character modes, the expression will determine the ASCII character to be used. (With some graphics modes, zero = space, all others = asterisk "*"). EXAMPLE CLS: MODE 6 COLOR ASCC"*") PLOT 0, 256 MODE=7 CIRCLE 768,200,50 COLOR=6 BOX 0,0 TO 10,10 END <---even modes are character graphics with some versions <---Uses asterisks for graphics (nol all versions) <--- odd modes are actual graphics <----Sels COLOR to 6 Also see MODE, PLOT, CIRCLE, BOX, POINT and FILL. Colors vary by mode, graphic type, monitors and other hardware criteria. Check hardware manual and Ihe ZBasic appendix for your computer for specific color codes. REMARK Macintosh: NOT(O) =black, O=white. See appendix for variations especially with Macintosh II which supports a number of colors and grey levels. MSDOS: COLOR is also used 10 change text color, background color, blinking, underlineelc. See appendix for specifics. See CGA colors below. Apple: Color chart below and the Apple appendix. TRS-SO and Kaypro: Black=O, -l=white. EXAMPLE COLORS CODES IBM PC and compatibles CGA MODE 5 0= BLACK 8= GRAY 1= BLUE 9=LTBLUE 2= GREEN 10= LTGREEN 3= CYAN 11= LTCYAN 4= RED 12= LTRED 5=MAGENTA 13= LTMAGENTA 6= BROWN 14= YELLOW 7= WHITE 15= BrightWHITE 191 Standard Reference Apple /I ProDOS and DOS 3.3 MODE 5 MODES 1,3 and 7 O=BLACKI O=BLACK 8=BROWN ldGREEN I=MAGENTA 9=ORANGE 2=VIOLET 2=DARK BLUE 10dGREY 3=WHITEl 3=PURPLE I1=PINK 4=BLACK2 4=DARK GREEN 12=GREEN 5=ORANGE 5=GREY 13=YELLOW 6=BLUE 6=MED. BLUE 14=AQUA 7=WHITE2 7-LlGHT BLUE lS=WHITE statement COMMON ................................................................................................... "" ............................................................ ...."'.r/'........ "'."..rI'."'."'.,."'.r/'."'."'."'•.".."'........rI'."' ..".."'...."' ...."'."'.11'.,/'.1'."'."' ...."' ...."' ...."' .........."'."' .... 01' ...."' ...."' .... .. ":"'l""":""'""'""'""'""'""'""'""'""'""'""'""'""'""'"":""'"":""'"":""'"":""'"":""'"":''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''l"''':''':''':''':'~''':'':' FORMAT COMMON variable list. .. DEFINITION Identical to the ZBasic DIM statement. It is used to allocate memory for variables and for declaring variables common to chained programs. The order of the variables declared in COMMON is important when chaining programs. The COMMON statement in one program must be exactly the same and in exactly the same order in other programs being chained. EXAMPLE See DIM. REMARK See DIM and "Chaining" in this manual. This statement is added to make ZBasic compatible with other versions of BASIC . •• Not available on the Apple" or Z80 versions of ZBasic. Use DIM. Standard Reference 192 COMPILE command ........................................................................................................................................................... rI'."'.,...rI'.rI'......................... r/'."'."'."'."'."'."'.r!'...."'...."'....rI."'.". ...."'...."' ...."'...."'...."'. -":-":-":-"'-"'-"'-"'-"'-":-":-":-":-":-":-":-":-":-":-":-":-":-":-":-"'-":-":-":-":-":-":-":-,)-"'-"'-"'-"'-"'-"'-":-":-":-"'-":-":-"'-"'-"'-":-"'-"'-":-"'-": ... rI' .... r/' ....... " ....... ,/'."."'."' .... I FORMAT [L COMPILE DEFINITION Compiles a program and lists all of the compile time errors that are encountered. If optional "L" is used, the error listings are sent to the printer. This command is essentially the same as RUN except the compiler does not stop at the first error. EXAMPLE PWINT "Hello" X=X+1 INPUT "Yes or No:"A$ GOSUB "Routine" END COMPILE Syntax Error in Stmt 01 at Line 00001 00001 PWINT "Hello" ";" Expected Error in Stmt 01 at line 00003 00003 INPUT "Yes or No:"_A$ Linew Error in Stmt 01 at Line 00004 00004 GOSUB "Routine" REMARK See RUN and the section in the front of the manual called "Errors". II Not supported. Use RUN. lal!l Not supported. Use RUN. 193 Standard Reference command CONFIG ................................................................................................................................................................................... ."' .... "' ................ "'.".."' ................ "'.......".."' .... "'."' ....... "."' ................ "'............. "' .... "' ....... "'."' ......................." "'""'""'"":""'""'""'"":-""'""'"":""'""'"":""'"'" "... "":" ... "... "... "... "... "... "... "... " ...":-""'""'""'""'""'""'""'""'"":"":""'".":""'"":"":""'""'""'"":""'""'"::"':"":""'" FORMAT CON FIG DEFINITION Invokes the configuration prompts that allow you to set preferences for a number of items including: Digits of precision Default variable types Integer or floating pOint expression evaluation Spaces between keywords Convert to uppercase Number of files that can be opened The Rounding factor for PRINT USING Test Array bounds and a number of special options for your computer. EXAMPLE See "Configure" in the front of this manual and the section in your appendix for specific configuration options available for your version of ZBasic. REMARK This command is not available on all versions. See below. l!!!l The Z80 versions of ZBasic do not offer this command. The option to configure is offered only when you first load ZBasic. !b CON FIG is not offered as a command but "Configure" is always available as a menu item. See appendix for the options specific to this version. Standard Reference 194 COORDINATE statement FORMAT COORDINATE II WINDOW] horizontal, vertical] DEFINITION Allows you to change the coordinate system used for graphic functions and statements. ZBasic defauHs to a coordinate system of 1024 x 768. This allows programs created on one computer work on other computers with different graphic hardware. EXAMPLE COORDINATE horiz, vert Sets the relative coordinate system to the specified limits minus one. COORDINATE 100,100 would allow setting the coordinates from 0 to 99 for both the horizontal and vertical. COORDINATE WINDOW Sets the system to pixel coordinates. This allows you calculate the graphic positions by the actual resolution on the screen. While this is not recommended for programs that will be ported to other computers, some people prefer it for certain applications. PLOT 1023, 767 <--- Puts a graphic dot at the ZBasic default coordinates (lower right comer) REMARK COORDINATE WINDOW PLOT 100,100 <--- Puts a graphic dot at the pixel coordinate COORDINATE 1000,500 PLOT 100,100 <--- Puts a graphic dot at the relative coordinate Some versions do not support this statement. See below for aHernatives to changing coordinate systems. IB'!l Not supported on ZSO versions although COORDINATE WINDOW may be emulated by using this instruction: POKE&xx3F, &C9 to enable pixel graphics and POKE&xx3F, &C3 to return to the default coordinates of 1024x76S. The value of xx varies by version type: CP/M-SO=01, TRS-SO 1,3=52 and TRS-SO model 4=30. ~ Not supported on these versions although COORDINATE WINDOW may be emulated using the statements below: Apple ProDOS: POKEWORD &85,0 for pixel coordinates for that mode of graphics. Use MODE to set back to regular coordinates. Apple DOS 3.3: POKE &F388, &60 for pixel coordinates of that mode. POKE &F388, &A9 to set back to the defauH coordinates of 1024x768. 195 Standard Reference function COS FORMAT COS (expression) DEFINITION Returns the Cosine of the expression in radians. COS(A)=XlH, H*COS(A)=X, XlCOS(A)=H EXAMPLE X#=COS (X) REMARK Using COS in an expression will force ZBasic to calculate that expression in floating point. COS is a scientific function. You may configure BCD scientific accuracy separately from both Double and Single Precision immediately after loading ZBasic. Integer Cosine may be accomplished with the predefined ZBasic USR function; USR9 (angle in Brads). This returns the integer cosine of an angle in the range ±255 (corresponding to ± 1). The angle must be in Brads. This example program will draw a sine wave using USR9: MODE7 :CLS FOR 1=0 TO 255 PLOT 1«2,-USR9(1)+384 NEXT I For more information about scientific functions and derived math functions see the "Math" section of this manual. See CIRCLE for more about BRADS. Also see ATN, SIN, TAN, EXP, SQR. Standard Reference 196 CSRLIN function ............................................................................................................................................................... ...... "' ........... .... ......................................... .... .,. ................ "' ............................ "' .......... .......".".... "' .... "... ... ... ... ... "":" ... ... ... ... "":" ... ... ... ... "":" ... ... ... ... "":" ... "":"":" ... "":"":"":" ... ... ... ... ... "":" ... ... ... ... "":" ... ... "":" ... ... ... "":" ... ... ... ... "... ... ":: ". " " " " ". " " " ". " " " " " " ". " " " " " " " " " " FORMAT CSRLIN DEFINITION Returns the line where the cursor is positioned. EXAMPLE CLS PRINT PRINT PRINT CSRLIN ,/'. " " " " RUN 2 REMARK See POS to determine the horizontal cursor position. Be!l Not supported with the Apple II or Z80 versions of ZBasic. For Apple II use (37) to get the current cursor line. PEEK 197 Standard Reference function eVB FORMAT eVB (string) DEFINITION Returns the binary floating point value of the first n characters of the condensed number in string (depending on whether Single or Double Precision is used). Double Precision Returns the digits of accuracy defined in configure for double precision. (default is 8 digits i.e. the first 8 string characters.), Single Precision Returns the digits of accuracy defined in configure for single precsion. (default is 4 digits i.e. the first 4 string characters.) This function is the compliment of MKB$. EXAMPLE A#=12345.678: B!=12345.678 A$=MKB$(A#): B$=MKB$(B!) PRINT LEN (A$), LEN(B$) C#=CVB(A$): D!=CVB(B$) PRINT CII, D! RUN 8 12345.678 REMARK 8 12345.7 This function is used with some versions of BASIC to save space on disk when storing large amounts of numeric data in strings with FIELD. ZBasic does this automatically but CVB is still useful for string packing, etc. Also see MKI$, CVI, MKB$, READ# AND WRITE#. This command is not compatible with CVS or CVD. A few things to remember concerning CVB: Null strings or 1 character strings return 0 Two character strings will retum 2 digits accuracy. Four character strings will return four digits. See "Floating Point Variables" for more information. ~ ·See "Floating Point Variables" for detailed information on how extended double precision variables are stored and the added range of this precision for the Mac. Standard Reference 198 CVI function FORMAT CVI (string ) DEFINITION Retums the binary integer value of the first 2 characters of string. This function is the compliment of MKI$. EXAMPLE A$=MKI$(30000) PRINT LEN(A$) Z%=CVI (A$) PRINT Z% END RUN 2 30000 REMARK Also see MKI$, CVB, MKB$, READ# AND WRITE#. A few things to remember conceming CVI: Null string retums 0 One character strings will retum the ASCII value. Two character strings will retum an integer value. ASC(second character) • 256 + ASC(first character) This function was used with MBASIC to save space on disk when storing large amounts of numeric data. ZBasic does this automatically when using WRITE# and READ# but CVI is still useful for string packing, etc. a See DEFSTR LONG in the Mac appendix for using this function with Longlntegers. When Longlntegers are used the memory requirements are four bytes instead of two bytes. MSB and LSB are stored in reverse order for regular integers with this version. 199 Standard Reference statement DATA FORMAT DATA data item [ • data item [ •... 11 DEFINITION The DATA statement is used to hold information that may be read into variables using the READ statement. DATA items are a list of string or numeric constants separated by commas and may appear anywhere in a program. No other statements may follow the DATA statement on the same line. Items are read in the order they appear in a program. RESTORE will set the pointer back to the beginning of the first DATA statement. RESTORE n will set the pointer to the nth DATA item. EXAMPLE DATA Tom, Dick, Harry, 12.32, 233 READ A$, B$, C$, Ai, B% DEF TAB 6 PRINT "DATA items are: ";A$,B$,C$,Ai,C% RUN DATA items are: Tom Dick Harry 12.32 233 DATA Tom, Dick, Harry, 12.32, 233 RESTORE 3 READ Name$ PRINT "Third DATA item is: ";Name$ RUN Third DATA item is: Harry REMARK Alphanumeric string information in a DATA statement need not be enclosed in quotes Hthe first character is not a number. math sign or decimal point. Leading spaces will be ignored (unless in quotes) . DATA statements can be included anywhere within a program and will be read in order. Typical storage requirements for DATA items: Number with zero value Non-zero integer Strings Floating Point BCD Floating Point Binary 2 bytes 3 bytes Length of string + 2 ·See Floating Point Constants" ·See Floating Point Constants· See READ. PSTR$ DIM and RESTORE for common statements used with DATA. Note: See PSTR$ for extremely efficient way of retrieving strings in DATA statements. Standard Reference 200 DATE$ function FORMAT DATE$ DEFINITION Returns an eight character string containing the system date using the format MM/DDNY, where MM=month, DD=day and YV=year. EXAMPLE DATA January, February, March, April, May, June DATA July, August, September, October, November, December A$=DATE$ Day$=MID$(A$,4,2) REM If leading zero; peel off on next line IF ASC(Day$)=ASC("O") THEN DAY$=RIGHT$(DAY$,1) Month%=VAL (A$) RESTORE Month% READ Month$ <---Get month name from DATA Year$="19"+RIGHT$(A$,2) PRINT "Computer date: ";TAB(20);DATE$ PRINT "Human date: lf i TAB(20);Month$;" ";Day$i", niYear$ RUN Computer date: Human date: REMARK 08/03/88 August 3, 1988 If the system does not support a date function, 00/00/00 will be returned. See your computer appendix for more information. Also see TIME$ and DELAY. Macintosh: Date can only be changed from the "Control Panel DA" MSDOS: Date may be set in program: DATE$="MM/DD/YV" Apple: Date must be set from the system. CP/M-80 3.0 and PLUS: DATE$ supported. CP/M 2.x does not support date. 201 Standard Reference statement DEF J [, letter J [, letter J [, letter J [, letter J [, letter J, ... J J, ... J J, ... J J, ...J J, ...J FORMAT DEFINT DEFSNG DEFDBL DEFSTR *DEFDBL INT DEFINITION These statements define which variable type ZBasic will assume when encountering a variable name with letter as a first character and not followed by a type declaration symbol (% integer, ! single, # double, $ string, & double integer). DEFINT DEFSNG DEFDBL DEFSTR *DEFDBL INT letter letter letter letter letter [-letter [-letter [-letter [-letter [-letter [-letter [-letter [-letter [-letter [-letter Integer Single Precision Double Precision String Longlnteger (Macintosh only) ZBasic will assume that all variables are integers unless followed by a type declaration symbol or defined by a DEF type statement. See "Configure"for another way of defining the default variable type. letter letter - letter Letter from A to Z. Case is not significant. Defines an inclusive range of letters. EXAMPLE DEFSNG DEFDBL DEFINT DEFSTR DEFSTR DEFDBL DEFSGL REMARK Other versions of BASIC may assume all numeric variables are single precision unless otherwise defined. See the sections on "Floating Point Variables", "Math" and "Converting Old Programs" in the front of this manual for more information. A B F Z B-D, X,Y,Z A, F-J, T A, G, B-E <--- A and A! are the same variable (A$ is still a string). <--- B and B# are the same variable (B% is still an integer). <--- F and F% are the same variable (F! is still single prec). <--- Z and Z$ are the same variable (Z# is still double prec). <--- B, C, D, X, Y and Z all strings <--- A, F,G,H,I,J and T all Double precision <--- A, G, B, C, D and E all Single Precision !l * Also see DEFSTR LONG in appendix for way of forcing HEX$, OCT$, UNS$, CVI and MKI$ to default to Longlnteger instead of regular integer. Standard Reference 202 DEF FN statement FORMAT DEF FN name [ ( variable [ , variable [ , ... 1 1 ) 1= expression DEFINITION This statement allows the user to define a function that can thereafter be called by FN name. This is a handy way of adding functions not provided in the language. The expression may be a numeric or string expression and must match the type the FN name would assume if ij was a variable name. The name must adhere to variable name syntax. The variable used in the definition of the function is a dummy variable. When using FN the dummy variables, other variables or expressions may be used to pass the values to the function. The variable should be of the right type used in the function. EXAMPLE DEF DEF DEF DEF FN FN FN FN e# = EXP(1.) Pi#= ATN(1)«2 Sec#(x#) = 1.\COS(x#) ArcSin#(x#) = ATN (x# \ SQR( 1 - x# * x#» PRINT FN pit 1#=4.2312 P1anet#= FN ArcSin#(Sin(I#»* FN e#+ FN Sec#(Elipse#) RUN 3.14159 ... REM REM A Handy rounding function Send the routine the number and places to round DEF FN Round#(num#, p1aces)=INT(num#*10 places+.5)/10 places A A PRINT FN Round#(823192.124567576,5) X#=202031.12332 PRINT FN Round#(X#,2) END RUN 823192.12457 202031.12 REMARK One function may call another function as long as the function was defined first. LONG FN is another form of DEF FN that allows multiple lines of code. It is very powerful for creating reusable subroutines. See "Derived Math functions", "Functions and Subroutines", LONG FN, END FN and FN. 203 Standard Reference statement DEF LEN FORMAT DEF LEN [=] number DEFINITION The DEF LEN statement is used to reset the default length of string variables until the next DEF LEN statement is encountered. The number must be from 1 to 255. If DEF LEN is not used string length default is 255 characters each. Each string will consume 256 bytes; 1 byte for length byte, the rest for characters. Since strings will consume so much memory if their length is 'lot defined; it is imperative that thought be given to string length, especially if memory is at a premium. EXAMPLE REMARK C$="Welcome lf <---Length of C$ defaults to 255 characters. DEF LEN 20 DIM M(lO) Greeting$="Hello" <--A$() aliocateQ 20 characters per element. <---Greeting$ allocated 20 characters DEF LEN 200 B$="Goodbye" <---B$ allocated 200 characters DIM 50 Z$ <---Z$ allocated 50 characters. See DIM DEF LEN will allocate the specnied amount of memory to every string that is defined after it (unless defined differently in DIM or another DEF LEN). Strings that appear before the DEF LEN statement are not affected. For example, in the above program, C$ is allocated the default length of 255 characters because it appeared BEFORE the DEF LEN statement. DIM may also be used to set the length of string variables. See DIM. Also see "String Variables" and "Converting Old Programs" in the front section for important information about strings and how they use memory. Imponant Note: Always allocate one extra character for strings used with INPUT. Never use a one character string for INPUT. The extra character position is needed for the carriage return. Standard Reference 204 DEF MOUSE statement .................................................................................................................................................................. .................. "'."'."'."'.... "'."'....... "' ....... "'."' .... "' ...."'." .......... rl'."' ................ rI'."' ............."................................. . ~-:.~.-:.-:.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.": ":-":-"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"": FORMAT DEF MOUSE [=] expression DEFINITION The DEF MOUSE statement is used to define the device to be used with the MOUSE functions and statements, or the type of mouse commands to use with the program. DEF MOUSE=O Regular ZBasic MOUSE commands for a mouse device. See MOUSE in this reference section. MSDOS: Uses Microsofl''M compatible mouse devices. Be sure to "Configure" ZBasic for a mouse. Apple II: Assumes a mouse is connected. Macintosh: Standard MOUSE commands in this section of the reference manual. See DEF MOUSE=1 to do MSBASIC type mouse commands. zao: DEF MOUSE= n NOT SUPPORTED. Tells ZBasic that other devices are to be used instead of a MOUSE (in the case of the Macintosh ij tells ZBasic to use MSBASIC mouse syntax). MSDOS: n=1 defines joystick/paddle A* n=2 defines joystick/paddle B* n=3 defines a lightpen device Apple II: n=1 defines a joystick/paddle device* *MOUSE(3) function returns button status: 0= No button pressed 1= Button zero pressed 2= Button one pressed 3= Both buttons pressed Macintosh: n= non-zero sets commands to MSBASIC mouse commands. See Macintosh appendix for specifics. zao: NOT SUPP08TED. EXAMPLE See the appendix for your computer for specifics. REMARK See MOUSE in this reference section and in your appendix for specifics. jB'!l MOUSE or DEF MOUSE is not supported with any zao versions of ZBasic. This is due to the fact that most zao computers do not offer this hardware device. 205 Standard Reference statement DEF TAB FORMAT DEF TAB [=] expression DEFINITION The DEF TAB statement is used to define the number of characters between tab stops for use in PRINT, PRINT# or LPRINT statements Tab stops are the number of spaces to move over when the comma is encountered in a PRINT statement. The expression must be a number from 1 to 255. TAB default is 16. EXAMPLE PRINT 1,2,3 <---Tab stop default is 16, 32, 48 .. . DEF TAB = 8 <---Tab stops now set to 8,16,24.. . PRINT 1,2,3: PRINT FOR X=1 TO 5 DEF TAB=X PRINT 1,2,3 NEXT X RUN 1 1 1 1 1 1 1 REMARK 2 3 2 2 3 3 2 3 2 3 2 3 2 3 Also see TAB, WIDTH, WIDTH LPRINT and PAGE. Standard Reference 206 DEF USR statement FORMAT DEF USR digit DEFINITION The DEF USR statement is used to define the addresses of up to 10 machine language user subroutines; USRO to USR9. EXAMPLE Examples only. Do Not Use! expression REM Calls graphic routine at memory address 5000 DEFUSR1=5000 X=USRO (45) DEFUSR2=23445 PRINT USR2(x) REMARK A machine language return is needed at the end of the routine to return program control to ZBasic. See USR, MACHLG, CALL, LINE, VARPTR, BIN$, HEX$, OCT$, UNS$, PEEK, PEEKWORD, POKE, POKEWORD and the chapter "Machine Language". Some other default USR functions are included in the appendix for your computer. WARNING: Use of this command requires a knowledge of machine language and a computer's hardware. Porting of programs with this statement may not be possible without re-writing the routines. 207 Standard Reference statement DELAY FORMAT DELAY expression DEFINITION The DELAY statement will cause a program to pause a specified amount of time. The expression sets the delay in milliseconds; thousandths of a second. EXAMPLE CLS FOR I = 1 TO 5 PRINT "DELAYING "; I; "SECONDS" DELAY I * 1000 NEXT I END RUN DELAYING DELAYING DELAYING DELAYING DELAYING 1 SECONDS 2 SECONDS 3 SECONDS 4 SECONDS 5 SECONDS (after (after (after (after 1 second) 2 seconds) 3 seconds) 4 seconds) FOR X=1000 TO 0 STEP -50 PRINT X DELAY X NEXT (try it) REMARK The key is not scanned during DELAY. Any negative expression will cause delays in excess of 32 seconds (the unsigned value). Note that DELAY -1 will delay over 65 seconds (unsigned -1 = 65,535). There may be a slight time variation from machine to machine due to processor speed, interupts, hardware differences, etc. Also see DATE$ and TIME$. !b. Also see TIMER. Standard Reference 208 DELETE command FORMAT DEL DEL DEL DEL [ETE) [ETE) [ETE) [ETE) line -line line -line line- DEFINITION This command will remove a line or range of lines from a program in memory. DELETE is used from the Standard Line Editor. EXAMPLE 10 20 30 40 50 CLS FOR I 1 TO 10 PRINT "NUMBER ". I NEXT I END DEL 10-20 LIST 30 40 50 PRINT "NUMBER ". I NEXT I END 10 20 30 "FRED" PRINT "NUMBER ";1 PRINT "Fred was here" END DELETE "FRED" LIST 20 30 REMARK 209 Standard Reference PRINT "Fred was here" END Use this command with care as recovery of deleted lines is not possible. statement DIM FORMAT DIM [len ] var [type] [( number [ • number .. ])] [ •...] DEFINITION The DIM statement is used to allocate memory for variables and array variables and to define common variables for chained programs. len Defines the length a of a string (how many characters it may hold). This is optional and defines the length of all the following string variables in that DIM statement or until a new length is encountered in that statement. The default is 255 characters unless changed by a previous DEFLEN. var The name of a variable (any variable type). type Forces the variable to be of that type. %=Integer &=Longlnteger (Macintosh only) !=Single Precision #=Double Precision $=String Also see "Variables" in the front section of this manual. number The maximum number of elements that a dimension may contain from 1 to 32,767elements (add one narray BASE option is set to zero. default=O). Only numbers may be used, not variables. EXAMPLE See the following page for more information and examples. REMARK Use care when allocating memory with the DIM statement. See BASE OPTION, DEFLEN, "Array Variables", "String Variables", INDEX$ and RUN+ for more important information about using DIM. fl. Macintosh: This version is limited to 2,147,483,648 elements in an array. MSDOS: In order to optimize performance; integer variables and integer array variables are limited to one 64K segment. String and BCD arrays may cross segment borders to use up to available memory. continued next page ... Standard Reference 210 DIM statement DIM continued DETERMINING THE MEMORY NEEDS OF DIMMED ARRAYS DIM A% (10, 10, 10), Ail (5), A! (9,7), B$ (10), DIM Long&(10): REM Macintosh Only 5Cool$ (20 The following chart shows how to calculate the memory requirements of the arrays dimensioned above with a BASE OPTION of zero. ARBAY A%(10,10,10) A#(5) A! (9,7) B$(10) Cool$(20) Long&(10) :r.me. Integer Double Precision Single Precision String String Longlnteger Bytes per How to !i1~m~DI Ci!I~I.!Ii!I~·· B~gl.!l[~d 11'11'11'2 6*8 10'8'4 11'256 21'6 11'4 266? 48 320 2816 126 44 2 8 4 256 6 4 Memory DEFINING STRING LENGTHS WITH DIM DIM X$(10), 20A$, Z$(5), 45TEST$, 10MD$(20,20) In the example above the maximum character capacities are: X$ A$ Z$ (5) TEST$ MD$( 20, 20) 255 (default is 255) 20 each element of Z$ as 20' (21'5=105 total bytes) 45 each element of MD$(20,20) as 10. (20 * 20 '11 =4400 total bytes of memory used) * " no length is defined, the last given length in that DIM statement is used. In the example each element of Z$(n) gets a length of twenty. "no length is defined in that DIM statement then 255 characters is the default (or the last length used in DEF LEN). "" you configure BASE OPTION 1 you will not need to add one to the dimension. To calculate the memory required for A%(10,10,10): 10*10*10'2. See "Configure". Note: Add one to the defined length of each string for the length byte to determine the actual memory requirement of the string. This extra byte is the "Length byte" and it is the first byte in the string. It is what is pointed at by VARPTR(var$). Important Note: Unpredictable system errors may result if an attempt is made to assign a string variable a string longer then its allocated length. It is also important to define the length of a string at least one greater than the maximum number of characters received in an INPUT or LlNEINPUT statement. 211 Standard Reference command DIR 1 FORMAT DIR [ drivespec DEFINITION DIR will display the directory of the disk drive specified by drivespec. The drivespec will vary from one computer to the next. See your Computer's Disk Operating System reference manual for syntax. EXAMPLE DIR LEDGER. COM JUL.LED ZBasic REMARK MAY. LED AUG.LED JUN. LED Ready The appearance of the directory layout will vary by computer. See appendix for further information. This is a command so it does not operate during runtime. See below, or your appendix, for possible ways of getting directories at runtime. Macintosh: Syntax is OIR "rootname or foldername". To get a directory during runtime see FILES$ in the appendix. LOIR will output the directory to a printer. MSDOS: Use OIR •. BAS to see all the .BAS files or OIR Z·" to see all the files starting with Z. To get a directory during runtime see FILES. Apple ProDOS: To get a directory during runtime; OPEN"I" the directory pathname. Example: OPEN"I",1,"ZBASIC". See directory layout in ProOOS reference manual for more information about directory file layout. This version also supports LOIR to list the directory to the printer. CAT may be used as well as OIR. Apple DOS 3.3: To get a directory during runtime: LONG FN DIR (slot,drive) POKE &AA6A,slot POKE &AA68, drive CALL &A56E END FN Z-80: See appropriate section in appendix for your computer and ~OS. Some versions do not allow getting a directory at runtime. zao Standard Reference 212 DO statement FORMAT DO UNTIL expression DEFINITION The DO statement is used to define the beginning of a loop with the UNTIL statement defining the end. Program functions and statements appearing between the DO and UNTIL will be executed over and over again until the expression defined at the UNTIL statement is TRUE. EXAMPLE DO PRINT"Hi!" UNTIL LEN(INKEY$) END RUN Hi! Hi! Hi! Hi! <-----you press a key and it stops DO X=X+1 UNTIL X=2492 PRINTX END RUN 2492 REMARK The statements in a DO loop will be executed at least once. See WHILE-WEND for a loop type that ends immediately if the condition is false. ZBasic automatically indents text appearing between a DO and UNTIL two spaces. This is helpful in debugging and documenting programs. See the "Structure" and "Loops" sections of this manual for more information. Also see FOR-NEXT-STEP and WHILE-WEND. 213 Standard Reference command EDIT FORMAT E fine fine EDIT DEFINITION EDIT is used from the Standard Line Editor to specify the line you wish to edit. EDIT may be abbreviated to E. A comma will start editing at the line currently selected by ZBasic's line pOinter. List of the EDIT sUb-commands: SUB-COMMAND [n] [n] I X [n]D [n]C key H [n]S key L A [n]K key n is a number from 1 to 255. Note: EXAMPLE 10 20 30 FOR I PRINT NEXT I EDIT If n is not used, one is assumed. 1 TO 20 I 20 20 REMARK DEFtNITION - MOVE CURSOR RIGHT (n characters) - MOVE CURSOR LEFT (n characters) - Begin INSERT mode at cursor position - Goto the end of the line and EXTEND it - Exit INSERT mode (you will still be in line edit mode) - DELETE characters ( if n is used deletes n characters) - CHANGE character to [n) times - HACK to end of line and enter INSERT - SEARCH for [n)th occurrence of - LIST line being edited, home cursor - ABORT changes, restore original line - KILL text to [n)th occurrence of - EXIT editing with changes intact - ABORT EDIT SESSION (no changes made) n20 was the last line used.) <---- or E20 (comma <---- Press spacebar or backspace to move cursor. Use keys above to edit this line. If you want to edit the current line, press the comma key <,> in command mode. It will do the same as E . Line numbers may be edited in ZBasic. The line being edited will remain unchanged, the edited line with the new line number will be created. See the "Standard Line Editor" section in the beginning of this manual. Also see FIND, DELETE, AUTO and LIST. ~. These versions offer full screen editors as well as the Standard Line Editor. See "Full Screen Editor" in the appropriate appendix for details. Standard Reference 214 ELSE statement FORMAT IF- THEN- ELSE line or label IF- THEN- ELSE statement(s) DEFINITION ELSE is used with an IF statement to route control on a false condition. ELSE may refer to a linenumber or label or it may be followed by one or more statements that will be executed if the condition in the IF statement is FALSE. EXAMPLE X=99 IF X = 100 THEN STOP ELSE PRINT X END RUN 99 IF X=100 THEN STOP ELSE "End" END "End" PRINT"Stopped here." END RUN Stopped here. REMARK All statements on a line following an ELSE are conditional on that ELSE. See "Structure", IF-THEN, LONG IF, XELSE and ENDIF. ~. Also see SELECT CASE. 215 Standard Reference statement END FORMAT END DEFINITION END is used to stop the execution of a program. END will return control to the Standard Line Editor if program was executed using RUN, or to the operating system if the program was compiled using RUN" or RUN+. EXAMPLE PRINT END PRINT "HELLO" "THERE" RUN HELLO REMARK END will close all open files. Also see STOP and TRONB. & See SHUTDOWN. Standard Reference 216 END FN statement FORMAT LONG FN END FN [= expression DEFINITION I Marks the end of a LONG FN statement. The optional expression MUST be numeric for numeric functions (#,%,&,!) and MUST be a string ($) for string functions. EXAMPLE REM Removes spaces from the end of a string LONG FN RemoveSpace$(x$) WHILE ASC(RIGHT$(x$,1)=32 x$= LEFT$(x$, LEN(x$)-l) WEND END FN= x$ Name $= "ANDY PRINT "Before:"iName$i"*" PRINT" After:"; FN RemoveSpace$(Name$);"*" RUN ANDY * ANDY* REM Example of a simple Matrix Multiplication DIM A% (1000) LONG FN MatrixMult%(number%, last%) FOR temp%= 0 TO last% A%(temp%)=A%(temp%)*number% NEXT END FN A%(O)=l: A%(l)=2:A%(2)=3 FN MatrixMult%(10,3) PRINT A%(O), A%(l), A%(2) RUN 10 REMARK 20 30 If an END FN is omitted in a LONG FN construct, a structure error will occur. You must exit a function from an END FN otherwise problems will occur internally. Also see "Functions and subroutines", "Structure", LONG FN, FN statement, FN function and DEF FN. Important Note: Loops like FOR-NEXT, DO-UNTIL or WHILE-WEND must be entirely contained within a LONG FN-END FN. Do not exit a function except at the END FN. 217 Standard Reference statement END IF FORMAT LONG IF expression [XELSEI END IF DEFINITION This is an end marker for the LONG IF statement. Program execution will continue normally at the END IF after completion of a LONG IF orXELSE. EXAMPLE Love$="Forever" LONG IF Love$="Forever" PRINT "How Romantic!" XELSE PRINT "How heartbreaking!" END IF END RUN How Romantic! REMARK If an END IF is omitted in a LONG IF construct, a structure error will occur. See "Structure", LONG IF, IF-THEN, ELSE and XELSE. && Also see SELECT CASE. Standard Reference 218 END SELECT statement ....................................................................................................................................................................... "'.oI' ...."' ....... "' ......."'.".."'."' ...."' ................"' ...."...."'."'.".1/'."."'.",.."' .... "' ......... . ................................................................................................................................................................ . . -... -............................................... . ... ,..."'.".". .... " .... "' ........ ". ....... rI' .... FORMAT SELECT [CASE) [expression) CASE [IS) relational condition1 [, relational condition) [, ...) statement(s) CASE [IS) condition I. condition] I. ... J statement(s) CASE [IS) boolean expression statement(s) CASE ELSE statement [:statement ...)) END SELECT DEFINITION END SELECT is the end marker for the SELECT /CASE structure. When SELECT/CASE is encountered, the program checks the value of the controlling expression or variable, finds the CASE that compares true and executes the statements directly fOllowing the CASE statement. After these statements are performed, the program continues at the line after the END SELECT statement EXAMPLE A=100 SELECT A CASE >100 PRINT "A>100" CASE 100 PRINT "A=100" CASE ELSE PRINT"None of the above" END SELECT PRINT "Program continues ... n END RUN A=100 Program continues ... REMARK Also see SELECT and CASE. ]a'!l SELECT CASE is not supported with the Z80 versions. See IF and LONG IF for accomplishing the same thing. SELECT CASE is not supported with this version. See IF and LONG IF for accomplishing the same thing. 219 Standard Reference function EOF. ......... .................................................................................................................................................... "'."'.01'...."'• r/'."'...."'.... -.; .......... "' .... ,/'."' ....... "'.,/' .... ,/' .... "' ....... "' .... "'.,."' .... ,/'.,."' .... r/'.i'.r/' ....... "'."' .... .1' .... ". .... "'.r!'.r/'.r/' "'''''''''''''''''''':'''''''''''''''''''''''':''''''''':''''''''':'''''''''''''''''''''''''''''''''''''''''''':-'':''''''''':''"''''':'''':''''''''''''''''''':'''''''''''''''''''''''''''''''''''''':l'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''. FORMAT EOF ( filenumber) DEFINITION Returns true if an end-of-file condition exists for filenumber , returns zero if the endof-file has not yet been reached. This function is only available on the Macintosh and MSDOS versions of ZBasic. EXAMPLE OPEN"I",l,"FILE.TXT" DO LINEINPUTH, A$ PRINT A$ UNTIL EOF (1) CLOSEH END What to do if you don't have EOF on your computer: ON ERROR GOSUB 65535 <--- Enable disk error trapping OPENtlI", 1, "FILE.TXT" IF ERROR GOSUB"Error message" DO LINEINPUTH, A$ PRINT A$ UNTIL ERROR <>0 IF ERROR <> 257 THEN GOSUB "Error message" ERROR=O <--- Error 257 is an end·of-file error. Reset Error here then continue. CLOSEH END "Error message" PRINT "A disk error occurred: "; ERRMSG$(ERROR) INPUT"ontinue or top? ";temp$ IF temp$="C" THEN ERROR=O:RETURN STOP REMARK Some versions 01 ZBasic do not support EOF because of system reasons. Also see ERROR function and statement, ON ERROR and ERRMSG$ jal!l EOF is not supported on zao versions of ZBasic. Use the second example above to accomplish the same thing. II EOF is not supported on the Apple /I ProDOS or DOS 3.3 versions of ZBasic. Use the second example above to accomplish the same thing. Standard Reference 220 ERRMSG$ function FORMAT ERRMSG$ (expression ) DEFINITION Returns the error message string for the error number specified by expression. In most cases you will use the number returned by the ERROR function when a disk error has occurred. EXAMPLE OPEN "I",l, "OLDFILEI1 ON ERROR GOSUB "Error message" "Error message" PRINT "A disk error has ocurred!! n PRINT "The error was: ";ERRMSG$(ERROR) ERROR=O : REM ALWAYS SET ERROR TO ZERO AFTER ERROR OCCURS!' RETURN RON A disk error has ocurred!! The error was: File Not Found Error in File 11 FOR X=O TO 255 PRINT ERRMSG$(X) NEXT X RON PRINTS ALL lHE ERROR MESSAGES FOR THAT COMPUTER. REMARK ZBasic will display disk errors for you unless you use the ON ERROR disk trapping options. The ERROR function is commonly used for error trapping and display purposes. The expression is stored as follows: The low byte is used for the ERROR number The high byte is used for the file number (ERROR AND 255) (ERROR» 8) or (ERRORl256) See "Disk Errors", ON ERROR GOSUB and ERROR functions and statements. 221 Standard Reference ERROR statement FORMAT ERROR [=] expression DEFINITION Allows the programmer to set or reset ERROR conditions for the purpose of disk error trapping. ~ EXAMPLE ~"""""" Importanl Hoi" • ,"' do ... ,,"k ERROR m"" be re,. \0 >oro after a disk error occurs or ERROR function will continue to return an error value. REM REM REM This routine checks to see if a file exists. If it does exist it is opened as random, if it doesn't exist an error message is returned. LONG FN Openfile%(files$, filenum%, reclen%) ON ERROR GOSUB 65535: REM Disk error trapping on "Open file" OPEN"I",filenum%,file$ LONG IF ERROR LONG IF (ERROR AND 255) <>3 PRINT@(O,O);"Could not find: ";file$;" Check drive" INPUT"and press when ready";temp% ERROR=O: GOTO "Open file" END IF XELSE CLOSEt filenum% END IF ON ERROR RETURN: REM Give error checking back to ZBasic OPEN"R",filenum%, fileS, reclen% END FN REMARK ERROR may also be used as a function. See "Disk Error Trapping", ERROR function, ERRMSG$ and ON ERROR. a.a Macintosh: Also see SYSERROR in appendix. MSDOS: See appendix for ways of doing critical error handling. Apple ProDOS: See appendix for additional ways of trapping ProDOS errors. 223 Standard Reference function ERROR FORMAT ERROR DEFINITION Returns the number of an ERROR condHion, if any. Zero (0) is returned if no error has occurred. This function is available to programmers who wish to trap disk errors using the ON ERROR statement. EXAMPLE ON ERROR GOSUB 65535: REM User disk trapping enabled OPEN n I", 1, "OLDFILE" IF ERROR=259 GOSUB"NOT FOUND": GOTO 20 ON ERROR RETURN: REM Let ZBasic do the error checking nowl "NOT FOUND" REM ERROR 259 is: Rle Not Found error in Filenumber 1 PRINT" The file is not on that disk!" PRINT" Please insert the correct disk" PRINT" and press " INPUT A$:ERROR=O:RETURN REMARK ERROR may also be used as a statement. See ERROR statement, ERRMSG$ and ON ERROR GOSUB. Important Note: If you do the disk error trapping, ERROR must be reset to zero after a disk error occurs or ERROR function will continue to return an error value. ~ •• Macintosh: Also see SYSERROR in appendix. MSDOS: See appendix for ways of doing crHical error handling. Apple ProDOS: See appendix for additional ways of trapping ProDOS errors. Standard Reference 222 function EXP FORMAT EXP (expression ) DEFINITION Returns e raised to the power of expression. This function is the compliment of LOG. The BCD internal constant of the value of e is: 2.71828182845904523536028747135266249775724709369995957 The result will be rounded to the digits of precision configured for Double Precision accuracy. EXAMPLE DEFDBL A-Z DO INPUT "ENTER A NUMBER ";X PRINT "e RAISED TO X =" UNTIL X=O END EXP(X) RUN ENTER A NUMBER e RAISED TO X = REMARK 1 2.718281828459 <---14digitaccuracy This is a scientific function. See "Configure" for information about configuring scientific accuracy. For more information about scientific functions see "Math", "Math expressions", "Floating POint Variables", COS, SIN, ATN, TAN, SQR and raise to the power "A". Standard Reference 224 FILL statement FORMAT FILL expressionx • expressiony DEFINITION The purpose of FILL is to paint an area of the screen in the current COLOR. The point defined by the two expressions are: expressionx (horizontal position) and expressiony (vertical position). Fill will search for the uppermost point in the contained area that has the background color, then start filling from left to right and down. For this reason irregular shapes may not fill completely with one fill command. It may be necessary to use a fill statement for each appendage. EXAMPLE FILL BEFORE AFTER FILL 0, 384 .J/' 0 COLOR=l FILL 0,284 RUN See chart. REMARK FILL may not be available on machines without the capability of seeing pixels on the screen. See computer appendix. Also see CIRCLE FILL, BOX FILL, MODE, POINT and PLOT. !b BOX FILL, CIRCLE FILL and the QuickDraw routines like FILLPOLY, FILLRGN, FILLRECT etc. are much faster ways of filling areas. 225 Standard Reference command FIND commands or keywords line quoted string text or labels items in REM statements items in DA TA statements FORMAT FIND FIND # FIND" FIND REM FIND DATA DEFINITION FIND is used in the Standard Line Editor to locate text in a program. To FIND additional occurrences, press semi-colon (;l or FIND . EXAMPLE YOU TYPE FIND "HELLO FIND A$ or .. . or .. . FIND 99 FIND #12345 (line#) FIND X(C) or ... FIND PRINT FIND "SUBS or ... FIND OPEN FIND CLOSE FIND REM This FIND DATA 123, 232 FIND DATA "Fred" REMARK ZBASIC FINDS 01010 A=20:PRINT"HELLO THERE" 01022 Z=l:A$=B$:PRINTA$+B$ 01222 BA$="hel1o" 01333 ABA$="goodbye" 05122 F=2:X=X+2+F/999 08000 GOTO 12345 03050 A=1:T=ABS(X(C)/9-293+F) 03044 ZX(C)=4 00230 A=92:PRINTA 00345 "SUB500": CLS 03744 GOSUB "SUB500" 03400 OPEN"R",1,"FILE54",23 09900 CLOSE#2 02981 REM This is a remark 09111 DATA 123, 232 10233 DATA "Tom", "Dick", "Fred" When finding a string inside quotes, you must supply all of the characters up to the point that will insure the uniqueness of the string. See "Standard Line Editor" in the beginning of this manual. !l& See "Full Screen Editor" in the appropriate appendix for other FIND commands. Standard Reference 226 FIX function FORMAT FIX (expression ) DEFINITION Truncates the digits on the right side of the decimal point. EXAMPLE PRINT FIX (123.456), AiI=1293.21 PRINT FIX (AJI), PRINT FIX (.12340), PRINT FIX (999999.455) + O. RUN 123 REMARK 1293 o 999999 FIX works the same as INT in ZBasic. They are both included to maintain compatibility with other forms of BASIC. FIX will consider an expression floating point. FRAC is the opposite of FIX. It retums the fraction part of the number. See FRAC and INT. 227 Standard Reference function FN FORMAT FN name [ (expression1 [, expression2 [, ....]] ) ] DEFINITION FN calls a function by name which was previously defined by DEF FN or LONG FN. The name of the function must follow the syntax of variable names, that is, a string FN must have a name with a $, an integer FN must have a name with a "la, etc. The expressions must match the variable types as defined by the DEF FN or LONG FN. Numeric expressions are not a problem, string expressions allow only simple strings. FN may not be used before it is defined with DEF FN or LONG FN. EXAMPLE DEF DEF DEF DEF FN FN FN FN e# = EXP(l.) pi#= ATN(l) « 2 Sec#(x#) = 1.\ COS (x#) ArcSin#(x#) = ATN (x# \ SQR(l-x# * x#» PRINT FN pH RUN 3 . 14159 . .. <--- Returned in the current digits of accuracy REM Round number to the number of places indicated_ LONG FN ROUND#(number#, places) number#=INT(number#*10 A places+.5)/10 A places END FN=numbed PRINT FN ROUND # (43343.327, 2) RUN 43343_33 REMARK This function is useful for saving program space and for making a program easier to read. Also see "Functions and Subroutines", "Structure", LONG FN, END FN, DEF FN, APPEND and FN statement. Standard Reference 228 FN statement FORMAT FN name [( expression1 [, expression2 [, .... ]])] DEFINITION FN calls a function by name which has previously been defined by a DEF FN or a LONG FN. The expressions must match the variable types as defined by DEF FN or LONG FN. EXAMPLE DEF FN LastChr%(x) = PEEK( x + PEEK(x» LONG FN RemoveSpace$(x$) WHILE FN LastChr%(VARPTR(x$» = ASC(" x$= LEFT$(x$, LEN(x$)-l) WEND END FN= x$ Name $ ="ANDY PRINT Narne$;"*", FN RemoveSpace$(Name$);"*" ") RUN ANDY REMARK 229 Standard Reference ANDY * Also see "Functions and Subroutines", "Structure", LONG FN, END FN, DEF FN, APPEND and FN function. statement FOR FORMAT FOR variable = expression1 TO expression2 [STEP expression3] NEXT [variable] [, variable ... ] DEFINITION Permits the repeated execution of commands within the loop. A FOR/NEXT loop will automatically increment variable by the amount set by STEP and compare this to the end value, expression2, exiting the loop when var exceeds this value alter adding STEP. Default STEP = 1. Note the loop will be executed at least once with the value of expression1 . EXAMPLE FOR Counter = 0 TO 100 STEP 2 PRINT Counter; NEXT RUN 02468 10 12 ... 100 FOR Counter = 100 TO 0 STEP -2 PRINT Counter; NEXT Counter RUN 100 98 96 94 92 90 88 ... 0 FOR Counter* = 0.0 TO 1.0 STEP .01 PRINT Counter*; NEXT Counter* RUN o REMARK .01 .02 .03 .04 .. , 1 ZBasic will automatically indent all of its loop structures in listings. This is helpful in debugging and documenting programs. See chapter called "Loops" and WHILE·WEND and DO-UNTIL. Note: If STEP is set to zero, the program will enter an endless loop. If the variable is an integer, do not allow the loop to exceed 32,767 or you will enter an endless loop (unsigned integer). Standard Reference 230 FRAC function FORMAT FRAC (expression ) DEFINITION FRAC retums the fractional part of expression. The digits to the left of the decimal point will be truncated. This function is the compliment of INT and FIX. EXAMPLE A#=123.456 B#=99343.999 C#=3.5 PRINT A#, FRAC(A#) PRINT B#, FRAC(B#) PRINT C#, FRAC(C#) PRINT 2.321, FRAC(2.321) RUN 123.456 99343.999 3.5 2.321 REMARK .456 .999 .5 .321 This function will automatically set floating point calculation. FIX and INT are the opposite. They retum the whole part of the number. See FIX and INT. 231 Standard Reference statement GET FORMAT GET (x1,y1)-(x2,y2), variable[array(index[,index ... ,])] DEFINITION Stores a graphic image from the screen into a variable or variable array so that it may be retrieved later and put to the screen with PUT. GET and PUT are extremely fast and useful for sophisticated graphic animation. x1, y1 x2,y2 Coordinates of the upper-left-comer of the graphic image on the screen. Coordinates of the lower-right-corner of the image. Coordinates are pixel coordinates; use with COORDINATE WINDOW. The image is normally stored in memory specified by an integer array since it is easier to calculate how much memory is required this way (although other variables may also be used as long as the memory set aside is correct). To calculate the amount of ~ to DIM for a graphic image, use this equation. Bitsper-pixel (bpp) has to do with colors or grey levels available. See next page for specifics: 6+ ( ( y2-y1)+1) * «x2-x1 +1) • bpp +7) I 8) Failure to DIM enough memory for an image will cause unpredictable system errors so be sure to carefully calculate the memory needed. EXAMPLE DIM A(750) MODE 7 COORDINATE WINDOW <--- Bytes above divided by two for integer array <--- Not needed on the Macintosh version <--- Pixel coordinates CIRCLE 100,100,80 GET (0,0)-(100,100), A(l) FOR x= 1 TO 200 STEP 3 <--- Does twice to move the image across PUT (x, 90), A(l) the screen without disturbing the background PUT (x, 90), A(l) NEXT x END This routine moves a section of a circle across the screen. It is PUT to the screen twice so the item doesn't repeat and it will appear to move across the screen without disturbing the background (default PUT mode is XOR) . continued ... Standard Reference 232 GET statement ................................................................................................................................................................ . "' .... .1 .... ". .......... ". ....... "' .... ". ................... " .... ,/' .... ". ....... ............ ". .......".."' ...."'.".". ....... J".".."..". ............."' ...... . ~.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.": " REMARK ... "":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"": Important Note: Failure to DIM enough memory for the variables storing the graphic images may result in unpredictable system problems. Also see DIM and PUT. ~ Macintosh: With this version of ZBasic, PUT has another, optional, parameter: (xl,yl) [- (x2,y2) l, var. The second parameter allows you to scale the image, making it either larger or smaller by giving the rectangle size in which it is to appear. The x2, y2 parameter is the lower-right corner of the image. PUT Bits-per-pixel (bpp) will vary by the type of Macintosh you have. The standard black and white Macintoshes have one bit per pixel. The Macintosh II may have up to 32 bits-per-pixel. Sixteen colors is 4 bpp, 256 colors is 8 bpp. Check addendum or "Inside Macintosh Volume V (Color Quickdraw)" for the specifics of your color board. MSDOS: Bits per pixel (bpp) will TYPE CGA CGA EGA EGA HERCULES vary by the graphics adaptor board being used: MODE(s) COLORS BITS PER PIXEL (bpp) 5 4 2 2 1 3-16 2 (64K or less on EGA card) 4 (More than 64K on card) 7 16-19 16-19 20 16 1 1 J='ll Z80: GET and PUT are not supported with these versions of ZBasic . • Apple /I ProDOS and DOS 3.3: GET and PUT are not supported with these versions. See DRAW example on ProDOS disk and the BLOAD and BSAVE functions for possible alternatives. 233 Standard Reference statement GOSUB FORMAT GOSUB line or label DEFINITION GOSUB will call that part of a program starting wHh line or label and return to the next statement following the GOSUB when RETURN is encountered. EXAMPLE 10 GOSUB 40: PRINT "All Done!" 20 END 30 40 PRINT"He1Io" 50 RETURN RUN HELLO All Done! GOSUB "Hello Routine" PRINT "All Done!" END l1Hello Routine" PRINT"Hello" RETURN RUN HELLO All Done! REMARK On multiple statement lines, a RETURN will return control to the next statement on the line following the originating GOSUB. To avoid errors, be certain there is a line with the number or label that you GOSUB. All subroutines must be terminated with a RETURN statement. Note: IF Zbasic encounters a RETURN wHhout a matching GOSUB, it will return to the operating system or the editor. ZBasic does not check for stack overflow which may cause errors if subroutines do not end with a RETURN. See RETURN LINE, GOTO, ON GOTO and ON GOSUB. ~ See SEGMENT RETURN in appendix. Standard Reference 234 GOTO statement FORMAT GOTO line or label DEFINITION GOTO will transfer control to a line or labalin a program. Note that excessive use of this statement is considered inappropriate for structured code because in complex programs it becomes extremly hard to read. In most programming situations GOSUB, DO-UNTIL, WHILE-WEND, FOR-NEXT or other programming structures are much easier to follow. EXAMPLE 10 X~X+1 PRINT X, 20 IF X<5 THEN GOTO 10 RUN 1 2 3 4 "Loop" X~X+1 PRINT X, IF X<5 THEN GOTO "Loop" RUN 1 REMARK 2 3 4 A line error will occur during compile if the destination line or label cannot be found. See "Structure", GOSUB, ON GOTO, ON GOSUB, LONG FN, FN statement, WHILE, DO, FOR, LONG IF. 235 Standard Reference command HELP 1 FORMAT HELP [number DEFINITION HELP without a number prints the HELP menu to the screen. This menu will give you corresponding numbers to the help topics available. This command is used from the Standard Line Editor. Type HELP and a number to get answers to a specific topic. Press the SPACE BAR to continue when you see "MORE". EXAMPLE HELP A menu for your version of ZBasic will be printed to the screen. To get help for an item in the menu, type HELP and the number corresponding to that item. REMARK HELP will return control to the Standard Line Editor upon completion of the listing. If the help file has been deleted from the disk a File Not Found Error will occur. Check your computer appendix for the filename of the HELP file. & The HELP window is brought up when you type this command or select "About ZBasic" under the. menu. The command does not work exactly as above. Just double click the appropriate item with the mouse. Standard Reference 236 FORMAT HEX$ ( expression ) DEFINITION The HEX$ function converts a numeric expression to a four character HEXadecimal string ( BASE 16). The following program will convert a Decimal number to HEX or HEX to Decimal. Some sample HEX numbers: Decimal 0-9 10 Hexadecimal 0-9 A 11 12 13 14 15 EXAMPLE B C D E F DO INPUT"Decimal number to convert: ";Decimal% PRINT "Decimal";Decimal%;"= HEX ";HEX$(Decimal%) PRINT INPUT"HEX number to convert: ";Hx$ Hx$="&H"+Hx$ PRINT"Decimal value of "iHx$i "="VAL (Hx$) PRINT"The unsigned Decimal value of "Hx$"=" UNS$(VAL(Hx$)) UNTIL (Decimal% =0) OR (LEN(Hx$)=2) RUN Decimal number to convert: 255 Decimal 255= HEX FF HEX number to convert: F9CD Decimal value of F9CD = -1587 The unsigned Decimal value of F9CD REMARK 63949 Floating point numbers will be truncated to integers. See "Numeric Conversions", VAL, OCT$, BIN$ and UNS$. & See DEFSTR LONG in the appendix for doing Longlnteger conversions in Hex, Octal, CVI and MKI$. In this case HEX$ would return an eight character string. 237 Standard Reference statement IF FORMAT DEFINITION IF expression THEN line [or labe/J[ ELSE line [or label)) IF expression THEN statement [:statement: ...J [ ELSE statement [:statement: ... ]] The IF statement allows a program to do a number of things based on the result of expression: 1. 2. 3. 4. EXAMPLE Branch to a line or label after the THEN if a condition is true; expression ",0 Execute statement(s) after the THEN if a condition is true; expression ",0 Branch to a line or label after the ELSE if a condition is false; expressiorr-O Execute statement(s) after the ELSE if a condition is false; expressiorr-O X=99 IF X=99 THEN PRINT"X=99":PRINT"HELLO: ELSE STOP IF X=99 THEN "CHECK AGAIN" END "CHECK AGAIN" IF X=lOO THEN PRINT"YEP" ELSE PRINT"NOT TODAY!";:PRINT x END RUN X=99 HELLO NOT TODAY! 99 REMARK Complex strings will generate an error if used in an IF statement. Improper Proper IF LEFT$(A$,2)="HI" THEN STOP B$=LEFT$(A$,2): IF B$="HI" THEN STOP See LONGIF, ELSE, XELSE , WHILE-WEND and DO-UNTIL for more ways of doing program comparisons. Note: In many cases LONG IF is easier to read. a& Also see SELECT CASE. Standard Reference 238 INDEX$ statement ( expression ) = string expression ( expression ) = string expression ( expression ) FORMAT INDEX$ INDEX$I INDEX$D DEFINITION INDEX$ is a special array unique to ZBasic. Expression indicates an element number. Statement INDEX$(n)=simple string INDEX$I(n)=simple string INDEX$D(n) EXAMPLE INDEX$(O)="FRED" INDEX$(l)="TOM" INDEX$(2)="FRANK" GOSUB"Print INDEX$" INDEX$I(l)="HARRY" GOSUB"Print INDEX$" INDEX$D(O) GOSUB"Print INDEX$" END Definition Assigns a value to INDEX$(n) Move element n (and all consecutiveelements) up and INSERT simple string at INDEX$ element n DELETE element n and move all consecutive elements down to fill the space. <---Normal assignments <----HARRY INSERTED between FRED and TOM <---FRED is DELETED here "Print INDEX$": REM Routine prints contents of INDEX$ FOR X=O TO 4 PRINT X; INDEX$(X) NEXT: PRINT RETURN RUN o FRED 1 TOM 2 FRANK 0 FRED 1 HARRY 2 TOM 3 FRANK <-- Notice how values move from one element to another as items are inserted and deleted with INDEX$I and D. 0 HARRY 1 TOM 2 FRANK REMARK INDEX$ provides for memory efficient string array manipulation and lends itself very well to list management applications. See "SpeciaIINDEX$ Array", INDEX$ function, CLEAR, CLEAR INDEX$ and MEM. ~ Allows up to ten simultaneous INDEX$ arrays. See INDEX$ in your appendix. 239 Standard Reference function INDEXF FORMAT INDEXF (string [.expressionj) DEFINITION INDEXF is a speciallNDEX$ array function used to FIND a leading string within an INDEX$ array quickly. If INDEX$(1000) equaled "Hello", then X=INDEXF("Hel") would return 1000. If X=INDEXF("IIo") X would equal-1 since "110" would not be found. The leading characters are significant. EXAMPLE INDEX$(O)="FRED" INDEX$(l)="MARY" INDEX$(2)="TOM" X=INDEXF ("TOM") PRINT x <--- Search for TOM PRINT INDEXF ("MARY") <--- Search for MARY PRINT INDEXF ("RED") <--- Search for RED PRINT INDEXF ("FRED" , 1) <--- Search for FRED starting at element 1 RUN 2 1 -1 -1 REMARK <----- TOM found at element two <----- MARY found at element one <--- RED not found. The first characters are significant <----- FRED not found because search started at element 1 INDEX$ provides for memory efficient string array manipulation and lends itself very well to list management and text editing applications. See "Perpetual Sort" under "SpeciaIINDEX$ Array". Also see INDEX$, INDEX$I, INDEX$D , CLEAR, CLEAR INDEX$ and MEM. a Allows up to ten simultaneous INDEX$ arrays. See INDEX$ in your appendix. Standard Reference 240 FORMAT INKEY$ DEFINITION INKEY$ retums the character of the last key that was pressed or an empty string if no key was pressed. EXAMPLE WHILE A$<>"S": REM Press "5" to Stop DO A$=INKEY$ UNTIL LEN(A$) A$=UCASE$ (A$) PRINT A$; WEND END R.UN GHUIJD, KEUG FAQCCQ OPU ... S <---When is pressed program stops REM An easy function you can use to get a key LONG FN Waitkey$(local$) DO local$=INKEY$ UNTIL LEN(local$) END FN=local$ key$=FN Waitkey$(key$) PRINT keyS END R.UN (user presses "b") b REMARK When using INKEY$ for character entry, avoid having the TRON function active as this may cause pressed keys to be missed. See INPUT, LlNEINPUT, INPUT#, ASC and CHR$. See your computer appendix for variations or enhancements. aa Macintosh: See DIALOG (16) for way of doing INKEY$ during event trapping. MSDOS: INKEY$ retums two characters for function keys. ON INKEY$ does event checking for function keys. See appendix for specifics. 241 Standard Reference function INP ................................................................................................................................................................... ."'.".."." ....... ". .......... ",.."' ....... "' .... "'."'." .... "'.". ....... "'."' .... J'.J'."'."'."..". ....... "' .... "' .... ". .... "..".."..".,/' .... ". .... rI' ....... .. :-'... "":' ... ' ... ':-' ... "":" ... ' ... "... ' ... "... "... ' ... "... "... ' ... "... "":" ... ' ... "... ''':' ... ' ... ' ... '":''':'":''''''''''':''''':-''''''':''''''''''''"'':''''''':''':''';:''''''':''''''''"'''''''''''''''' FORMAT INP ( expression ) DEFINITION The INP function is used to read an input port. The function returns the value that is currently at the port specified by expression. EXAMPLE X=INP(l) PRINT X PRINT INP (G-1) RUN o 255 REMARK Note: This function requires a knowledge of your computer hardware and may not be portable to other computers (may not be available on your version of Z8asic or may have an unrelated function). See your computer appendix for specifics. B Not supported with this version. See INSLOT. !l Not supported with this version. See OPEN"e" and "Toolbox" in the appendix for accessing hardware ports. Standard Reference 242 INPUT statement FORMAT INPUT [(@ or%)( expr x , exprY)] [;] [!] [&expr,] ["string";] var[,var ... ] DEFINITION The INPUT statement is used to input values (string or numeric) from the keyboard into variables. Multiple variables must be separated by commas (this is bad form since users often forget commas). If no value is INPUT, a zero or null string will be retumed. @(xprc,exprY) Places cursor at text coordinate horiz,vert. % (exprc,exprY) Places cursor at graphic coordinate horiz,vert. Suppress carriage returnlline feed. Automatic Carriage return after maximum characters entered. User doesn't have to press . &expr, Sets the maximum number of characters tobe INPUT. Defaun is 255. Will not allow more than expr characters. "string"; Optional user prompt will replace the question mark. If a null string is used the question mark will be suppressed. var May be any variable type integer, single,double or string. EXAMPLE See examples on following pages... REMARK Differences in screen width may affect operation. See LOCATE and PRINT for more information on cursor positioning. Also see INPUT#, LlNEINPUT, LlNEINPUT# and INKEY$ for others ways of getting input. See "Keyboard I nput" in the technical section. Important Note: String lengths MUST be one greater than maximum INPUT length since a CHR$(13) is temporarily added. Never define a string used in an INPUT or LlNEINPUT as ONE. !b In certain cases EDIT FIELD, MENU or BUTTON may be preferable. See appendix. 243 Standard Reference statement INPUT INPUT continued EXAMPLES OF REGULAR INPUT EXAMPLE INPUTA$ RESULT Wait for input from the keyboard and store the input in A$. Quotes, commas and control characters cannot be input. to finish. A carriage return is generated when input is finished (cursor moves to beginning of next line). INPUT"NAME: ";A$ Prints "NAME: " before input. A semi-colon must follow the last quote. A carriage return is generated after input (cursor moves to next line). INPUT;A$ Same as INPUT A$ above, only the semi-colon directly after INPUT disables the carriage return (cursor stays on the same line). EXAMPLES OF LIMITING THE NUMBER OF CHARACTERS WITH INPUT EXAMPLE INPUT &10, A$ RESULT Same as INPUT A$ only a maximum of ten characters may be input. (& 10) A carriage return is generated after input (cursor moves to the beginning of the next line). The limit of input is set for ALL variables, not each. INPUT ;&3,1% Same as INPUT &10, except the SEMI-COLON following INPUT stops the carriage return (cursor stays on line). INPUT !&10,A$ Same as INPUT & 10 except INPUT is terminated as soon as 10 characters are typed (or is pressed). INPUT;!&10,"NAME: ";A$ Same as INPUT ;&10,A$ except no carriage return is generated (semi-colon). INPUT is terminated after 10 characters(&10 and Exclamation point). and the message "NAME:" is printed first. LlNEINPUT;!&5,"NAME: ";A$ LlNEINPUT A$ until 5 characters or is pressed. (no carriage return after or after the 5 characters are input. Accepts commas and quotes.) Note 1: Wherever INPUT is used, LlNEINPUT may be substituted when commas, quotes or some other control characters need to be input (except with multiple variables). Note 2: If more than one variable is INPUT, commas must be included from the user to separate input. If all the variables are not input, the value of those variables will be null. Standard Reference 244 INPUT statement INPUT continued INPUTTING FROM A SPECIFIC SCREEN LOCATION o 1 2 3 4 .... HORIZONTAL ?!w. 1 2 3 N m e ...... INPUT@(2,1)"?";X V E R T I C A \ r\ \ INPUT @(O,S)"Namo: ";A$ L INPUT@(H,V); A$ Wait for input at TEXT screen POSITION defined by Horizontal and Vertical coordinates. No "?" is printed. A carriage retum is generated. INPUT %(gH, gV);A$ Input from a graphic coordinate. Syntax is the same as "@". Very useful for maintaining portability without having to worry about different screen widths or character spacing. ° INPUT@(H,V);!10,"AMT: ";0# Prints "AMT:" at screen position H characters over by V characters down. 0# is input until 1 characters, or , are typed in, and the input is terminated without generating a carriage retum (the cursor DOES NOT go to the beginning of the next line). ° INPUT%(H, V) ;!1 O,"AMT: ";0# Prints "AMT:" at Graphic position H positions over by V positions down. D# is input until 1 characters, or , are typed in, and the input is terminated without generating a carriage return (the cursor DOES NOT go to the beginning of the next line). Note: Replace INPUT with LlNEINPUT whenever there is a need to input quotes, commas and control characters (except with multiple variables). 245 Standard Reference statement INPUT# FORMAT INPUT # expression, var [,var [, ...JJ DEFINITION This slalemenl will read INPUT from a disk or other device specified by expression until a carriage retum. . End-Of-File or 255 characters are encountered. Commas and leading spaces may be read inlo a string variable if the data on disk was enclosed in quotes. otherwise leading spaces and line feeds will be ignored. See LlNEINPUT# for ways of inputting commas. quotes and some control characlers. EXAMPLE A$="HELLO" B$="GOODBYE" C$="WHAT?" XiI=12.345 OPEN"O",l,"TEST.TXT":REM OPEN FOR OUTPUT PRINTil1, A$", "B$", "C$", "xii <--- Quoted commas important with PRINT# CLOSEU OPEN"I",l,"TEST.TXT":REM OPEN FOR INPUT INPUTU, X$, Y$, Z$,AiI <---INPUT# in same order and type as PRINT# CLOSEn DEFTAB=10: PRINT X$,Y$,Z$,AiI END RUN HELLO REMARK GOODBYE WHAT? 12.345 See OPEN. CLOSE. PRINT#. and LlNEINPUT#. See your computer appendix for available devices. Compatibility Note: ZBasic and MSBASIC have almost the same syntax wtth the following exceptions: MSBASIC ALLOWS PRINT#n. A$. B$. X#. C% PRINT#n. A$ B$ C$ ZBaslc REaUIRES PRINT#n. A$ ..... B$..... X# .....C% PRINT#n. A$ ..... B$..... C$ If you remember that ZBasic puts the image to the disk just as if tt were going to the printer or to the screen you will see why the syntax is important. Standard Reference 246 INSTR function FORMAT INSTR ( expression, string 1 , string 2 ) DEFINITION Finds the first occurrence of string 2 in string 1, starting the search at the position specified by expression. expression string1 string2 EXAMPLE Starting position of the search. String to be searched. String to search for. Humble$="I am cool!" PRINT INSTR(l,Humble$,"cool") B$="am" PRINT INSTR(l,Humble$, B$) X=INSTR(l, Humble$, "FRED") PRINT X END RUN 6 3 o <--- "Cool" started at the sixth position <--- "am" started at the third position <--- There was no "FRED" in the string. Name$="Fred Smith" Lastname$=RIGHT$ (Name$, LEN (Name$) -INSTR (l,Name$, " PRINT "Hello there Mr.";Lastname$ END RUN Hello there Mr. Smith REMARK If the string is not found, zero (0) will be returned. See LEFT$, RIGHT$, MID$ and INDEXF. 247 Standard Reference "» function INT FORMAT INT ( expression ) DEFINITION Truncates all digits to the right of the decimal point of expression. EXAMPLE DEFDBL A-Z DEFTAB 8 PRINT" X","ABS(X) ,"INT(X) ","FRAC(X) ","SGN(X) " FOR X = PRINT PRINT PRINT PRINT PRINT NEXT X END -15.0 TO +15.0 STEP 3.75 USING"-iliI.iliI";X, USING"-U.H";ABS(X), USING"-"."";INT(X), US ING" -H. U" ; FRAC (X) , USING"-"."";SGN(X) RUN X -15.00 -11.25 - 7.50 - 3.75 .00 3.75 7.50 11.25 15.00 REMARK ABS(X) 15.00 11.25 7.50 3.75 .00 3.75 7.50 11.25 15.00 .IlIT..OO.. -15.00 -11. 00 -7.00 -3.00 .00 3.00 7.00 11. 00 15.00 FRAC(X) .00 -.25 -.50 -.75 .00 .75 .50 .25 .00 SGN(X) -1. 00 -1. 00 -1. 00 -1. 00 .00 1. 00 1. 00 1. 00 1. 00 INT works the same as FIX in that expression will be restricted to the integer range of -32,768 to +32,767 only when the expression has not been defined as floating point. INT is simply as a function that truncates an expression to a whole number. To get the fractional part of a number use FRAC. See FIX, SGN, ABS and FRAC. !b INT range for the Macintosh is -2,147,483,648 to +2,147,483,647. Standard Reference 248 KILL statement FORMAT KILL simplestring DEFINITION KILL will erase a disk file specffied by simplestring . KILL functions either as a command or from within a program. EXAMPLE INPUT"File to erase:";A$ PRINT"Are you sure you want "iA$;" erased?"; INPUT B$ LONG IF B$<>"YES" PRINT"File not erased": STOP XELSE KILL A$:PRINT A$;" is history." END IF END RUN File to erase: Oldfile Are you sure you want Oldfile erased? YES Oldfile is history! REMARK Use this statement with caution. When a file has been killed it is normally unrecoverable. See RENAME, ERROR, ON ERROR, ERRMSG$ and the "Files" section of this manual for more information. 249 Standard Reference This page intentionally left blank. Standard Reference 250 FORMAT LEFT$ (string. expression ) DEFINITION LEFT$ returns the left-most characters of string defined by expression. The string will not be altered. EXAMPLE Quote$="Early to Bed, Early to rise •.. " PRINT LEFT$(Quote$, 5) Part$= LEFT$(Quote$, 12) PRINT PartS PRINT LEFT$(Quote$, 50); PRINT "Makes men healthy ... at least" RON Early Early to Bed Early to Bed, Early to rise ... Makes men healthy ... at least" REMARK 251 Standard Reference Also see RIGHT$, MID$, LEN, VAL, STR$, INSTR, INDEX$, SWAP and the "String Variable" section of this manual for more information about using strings. function LEN FORMAT LEN (string ) DEFINITION Retums the number of characters that are stored in a string constant or string variable. If zero is retumed it indicates a null (empty) string. EXAMPLE A$="FRED" B$="SMITH" PRINT A$;" has";LEN(A$);" characters." PRINT B$;" has";LEN(B$);" characters." PRINT LEN(A$)+LEN(B$) PRINT LEN("Hello Fred") RUN FRED has 4 characters SMITH has 5 characters 9 10 REMARK The maximum length of a string is 255 characters. You may set the length of strings in ZBasic. See DIM, DEF LEN and the chapter on "String Variables· for more information about defining string length. Since the first character of a string stored in memory is the length byte, PEEK(VARPTR(var$)) will also retum the length of a string. The memory required for a string variable is the defined length + one for the length byte (256 bytes if not defined). Standard Reference 252 LET statement FORMAT [LEn variable = expression DEFINITION LET is an optional statement that may be used to assign an expression to a variable. Numbers, strings, numeric expressions, or other variables may be used to assign values to a variable if the types are compatible or convertable. EXAMPLE LET B=100 PRINT B LET B=B+10 PRINT B Z$="HELLO n +" THERE" PRINT Z$ <---Notice "LET" is optional RUN 100 110 HELLO THERE REMARK 253 Standard Reference See SWAP, "Optimize expressions for Integer", "Math Expressions" and "Conversions Between Variable Types" for more information about assignments. function LINE FORMAT LINE line number or label DEFINITION Returns the starting address of a compiled line in memory. Normally used with CALL to execute machine language subroutines created with MACHLG. EXAMPLE 10 CALL LINE 30 <--- Example only. DO NOT RUN! 20 END 30 MACHLG 23,323,11,232,A%, 2,1,0,0,1:RETURN "START" PRINT"THIS IS A TEST ",1,2,3 !lEND" A = LINE "END" - LINE "START" PRINT "The second line is n;A;" bytes longlt RUN THIS IS A TEST The second line is REMARK 1 36 bytes long 2 3 This statement is useful for calling machine language subroutines embedded in your program or for calculating the number of bytes used by program lines. Also see MACHLG and CALL. !l& Macintosh: Use Longlntegers for addresses. See CALL in the appendix. MSDOS: See CALL in appendix. Apple ProDOS: See MLI in ProDOS appendix. Standard Reference 254 LINEINPUT statement FORMAT LINEINPUT[(@ or %)(expr1,expr2) U; U!][ &expr, U"string"; ]var$ DEFINITION The LlNEINPUT statement is used to input characters from the keyboard into a string variable. It is different from INPUT in that quotes, commas and some control characters may also be entered. LlNEINPUT is terminated when is pressed. @(expr1,expr2) %( expr1 ,expr2) Inputs from horizontal,vertical TEXT coordinate. Inputs from horizontal,vertical GRAPHIC coordinate. Suppresses carriage-returnlline-feed after input is complete. (disable inputs that cause scrolling or overwriting.) Automatically executes a carriage return after the maximum number of characters are entered. The user doesn't have to press . EXAMPLE &expr, Sets the maximum number of characters to be input. "string"; Optional string prompt will replace the question mark "?" normally shown wtth LlNEINPUT. vat$ Only string variables may be used with LlNEINPUT. INPUT"Last name First name";A$ PRINT A$ LINEINPUT"Last name First name";B$ PRINT B$ RUN Smith Smith, Fred REMARK See the chapter on "Keyboard Input" in the front of this manual for more examples. The advantage of using LlNEINPUT over INPUT is its ability to receive most of the ASCII character set except: CARRIAGE RETURN CONTROL "C" DELETE or LEFT ARROW DELETE CURRENT LINE NO CHARACTER Important Note: String lengths MUST be at least one greater than the number of characters being input, otherwise a string overflow condition will destroy subsequent variables. Never use a one character string with LlNEINPUT. 255 Standard Reference statement LINEINPUT# FORMAT LlNEINPUT # expression. variable$ DEFINITION This statement will input ASCII or TEXT data from a disk file specified by expression until , End-Of-File or 255 characters are encountered. Useful for accepting commas, quotes and other characters that I N PUT# will not accept. A good example of using LlNEINPUT would be for reading an ASCII or TEXT file a line at a time (as in the example below). EXAMPLE REM Read a text file and print it to the screen REM Routine compatible with all versions of ZBasic ON ERROR GOSUB 65535: REM Error trapping on to check for EOF OPEN"I",l,"TEXT.TXT" Counter=O WHILE ERROR=O: REM Read file until an EOF error LINEINPUTU, A$ PRINT A$ WEND IF ERROR <> 257 THEN PRINT ERRMSG$(ERROR): STOP ERROR=O ON ERROR RETURN: REM Give error trapping back to ZBasic END REMARK The advantage of using LlNEINPUT# over INPUT# is its ability to receive most of the ASCII character set. Leading linefeeds will be ignored on some systems. If a CHR$(O) or CHR$(26) is encountered as a leading character it may assume EOF and set ERROR = End Of File (varies by computer). Also see INPUT#, LlNEINPUT and "Keyboard Input" in the front section of the manual. && These versions support an EOF function that would simplify the error trapping techniques used above. See the appropriate appendix for details about EOF: OPEN"I",1, "TEXT.TXT" Counter=O WHILE EOF=O: REM Read until EOF LINEINPUTU, A$ PRINT A$ WEND:CLOSE#l Standard Reference 256 LIST command FORMATS DEFINITION [L)L [1ST] [L)L [1ST] [L)L [1ST] [L)L [1ST] line or label • line or label line or labe/· line or label LIST (or L) is used from the Standard Line Editor to list the current program to the screen. LLIST will list the current program to a printer. Suppress line numbers Highlight keywords on the screen (some versions) + " EXAMPLE [+ )[*) [+ )[*) [+ )[*) [ +)[*) you TYPE LIST or L LLIST LIST 100-200 LLlST-100 LIST "SUBROUTINE" LIST 100- or L 100 L+ LLlST+ L+-100 (slash key) ZBASIC RESPONDS Lists complete program to the screen Lists complete program to the printer Lists lines from 100-200 Lists lines up to 100 to printer Lists the line with that label Lists lines from 100 on Lists the last line listed or edited Lists previous line (or plus <+> key)" Lists next line (or minus <-> key)" Lists program without line numbers Lists to printer without line numbers Lists up to line 100 without line numbers PAUSE. continues PAGE AT A TIME: Lists 10 lines to the screen" "See computer appendix for keyboard variations. REMARK LIST automatically indents program lines two spaces between FOR-NEXT, DO-UNTIL, WHILE-WEND, LONG IF-XELSE-END IF and LONG FN-END FN structures. See PAGE, WIDTH, WIDTH LPRINT and the chapter; "Formatting listings". Note: Labels may be used in place of line numbers. !L LLIST+" will forrnatlistings to an Imagewriter or Laserwriter with no line numbers and witt keywords in bold. While the output in of this format is extremely attractive and easy to read, it should be noted that listings will take about twice as long to print. 257 Standard Reference command LOAD ["] filespec ["] ["] filespec ["] FORMATS LOAD LOAD' DEFINITION LOAD is used from the Standard Line EdHor to load a ZBasic tokenized or a regular ASCII text file into memory. ZBasic does not load tokenized files from other languages; the file must first be saved in TEXT or ASCII format. If the program does not have line numbers they are added in increments of one. LOAD' will strip away remarks and unnecessary spaces from an ASCII file releasing more room for the source and object code in systems with limited memory. <--- Loads a regular tokenized or text file <---Double Quotes optional <---Strips spaces and REM's while loading EXAMPLE LOAD LOAD LOAD * REMARK Each operating system may require specific syntax for a drivespec. PROGRAM "SOURCE" THISONE Line numbers are optional in ASCII files. If a program was created using another form of BASIC it must be in ASCII format before the ZBasic editor can load H. aa These versions of ZBasic support a Full Screen Editor that may support other forms of LOAD. See appropriate appendix for information about full Screen Editors. Standard Reference 258 LOC function FORMAT Loe DEFINITION Retums the byte pointer position within the current RECORD of the filenumber specified by expression. EXAMPLE OPEN"R",1,"TESTFILE",30 RECORDiIl, 6, 3 PRINT LOC ( 1 ) (expression ) <--See illustration READl/l, Char$;l PRINT LOC(l) PRINT CharS CLOSEiIl RUN 3 4 d FILE STRUCTURE OPEN "R", 1, "TESTFILE", 30 ~~:;~~R~E~C~O~R~D~(~S~)~W~lt~h~le~n~g~th~S~O~f~3~0~~;:~ (. ~p to 65,535 L-L..J....J..-'-....L...J....:~.l.-L...JL..J....J..-'--'-..L....L....J......JL....J...J..-'-...J RECORD(s) In a ZBaslc fils. c.~;:::=:;::::::;~~~~~~~h:~::;:;::::~~ r Up to 65,535 LOCATION(s) In L:L:-1:J~.L:J-:-I-L.L..LJu....L.J.....L..L..L...LJL...J....L..I....L..L..L...L.IL...I;:;! a ZBaslc RECORD. 0123456... • ... 29 'The "d" Is at LOCATION 3 In RECORD 6 REMARK The LaC position is incremented to the next file position automatically when READ#, WRITE#, INPUT#, LlNEINPUT# or PRINT# are used. REC(filenumber) retums the current RECORD. LOF retums the last record in the file. Also see "Files" section for more information. aa The record length limits are different for these versions. See appendix. 259 Standard Reference statement LOCATE FORMAT LOCATE exprx' expry , [exprcursor J DEFINITION Positions the cursor to the coordinates given by exprx, expry and optionally turns on or off the cursor character (zero=off, not zero=on). exprx The horizontal coordinate (characters across) expry The vertical coordinate (lines down) exprcursor Zero= cursor OFF. Non-zero = cursor ON <---- sets cursor in upper left corner <---- sets Cursor 10 char to right at top <---- sets Cursor 10th line down. Cursor OFF <---- sets Cursor 12th line down. Cursor ON EXAMPLE LOCATE LOCATE LOCATE LOCATE REMARK This function is also useful with CLS LINE and CLS PAGE for clearing the screen to the end of line and end of page. 0,0 10,0 0,10,0 0,12,1 See "Screen and Printer Control", PRINT@, PRINT%, INPUT@, LlNEINPUT@, LlNEINPUT% and INPUT% for other ways of controlling the cursor positioning. The ability to turn the cursor on or off may be limited by the hardware or software of some computers. !b& These versions of ZBasic allow you swap the horizontal and vertical coordinates under "Configure". This is handy for converting other BASIC programs that use the vertical coordinate first (not Apple DOS 3.3). Standard Reference 260 LOF function FORMAT LOF ( expression ) DEFINITION Retums the last valid RECORD number for the file specified by expression. stands for Last-Of-File. LOF Important Note: This function may not return the last record correctly on some systems. especially if the record length of the file is different from the operating system's internal record length or if a file is opened with a different record length then that which it was opened originally. This is often remedied by simply selling the record length to the system default record length or the record length of which it was opened originally. EXAMPLE See "Opening files for Append" in the "Files" section in the front of this manual for methods of gelling a pointer to the last position in a file. REMARK LOF retums the last record in the file. The default record length is 256 and may need to be changed to make LOF function properly. See LOC and REC for gelling file pointer information. See "Files" and "Disk Errors" for more information. Some systems return one for both record zero and record one. Note to better usage: If you need to keep track of the last byte position of a sequential file or the last record of a random file. you might consider storing the last REC and LOC of a file in record zero before it is closed. Examples: OPEN"O",l,"Textfile.txt" RECORDU,l <---Set file pointer to record one (zero will store last REC and LOC) PRINTj/l,A$", "B$", "X", "zj/ <--- Save data RECORDU, 0<---- Position pointer to RECORD 0 to save last REC and LOC R=REC(l) :L=LOC(l) WRITEU, R, L <--- Save pointers for future use CLOSEU To add data to the end of the file later: OPEN"R",1, "Textfile.txt" RECORDU,O READj/l, R, L RECORDj/l, R,L PRINTU, A$ <--- Get last positions of file <----- Position pointer to append data to the end of the file. <-- Now you can append new data to the file Don't forget to store the LOC and REC before clOsing! You could do the same thing with random files by saving the last record. L Also supports: LOF(filenumber. [recordlength]). LOF(1.1) would return the length of filenumber one in bytes. 261 Standard Reference function LOG FORMAT LOG ( expression ) DEFINITION Retums the natural logarithm of expression (LN). LOG is the compliment of EXP. Common LOG10= LOG(n) \LOG(10) EXAMPLE PRINT LOG(2) X#=LOG(3) PRINT X# RUN .69314718056 1.09861228857 REMARK LOG is a scientific function. Scientific preCision may be configured by the user differently from both single and double precision. See "Configure" and "Math" in the beginning of this manual. Also see COS, SIN, EXP. 'w·. ATN and TAN. Standard Reference 262 LONG FN statement FORMAT LONG FN name [ ( var [ , var [ , .•. ] ]) ] END FN [= expression] DEFINITION LONG FN is similar to DEF FN but allows the function to span over several lines. This is usful for your own functions that you can use with ZBasic. A re-usable, non-line-numbered function may be saved to the disk with SAVE+ and retrieved later for use in other programs with APPEND. The variables being passed to the function must not be arrays. The expression must be numeric for numeric functions and string for string functions. EXAMPLE LONG FN RemoveSpace$(x$) WHILE ASC(RIGHT$(x$),l)=32 x$=LEFT$(x$,LEN(x$)-l) WEND END FN= x$ Name$="ANDY PRINT Name$i"*" Name$=FN RemoveSpace$(Name$) PRINT Name$;"*" RUN ANDY ANDY* * REM wait until key press. Return key in keyS LONG FN WaitKey$(key$) DO key$=INKEY$ UNTIL LEN(key$) END FN=key$ Z$=FN waitKey$(Z$) PRINT Z$ RUN (returns key that was pressed) REMARK 263 Standard Reference Also see APPEND, SAVE+, DEF FN, FN statement, FN function and "Structure". statement LONG IF FORMAT LONG IF expression [XELSEI ENDIF DEFINITION LONG IF allows multiple line IF-THEN-ELSE structures. Very useful for breaking down complicated IF statements into more readable, logical structures. Two things happen based on the result of expression: • If expression is TRUE: • If expression is FALSE: EXAMPLE Executes all the statements up to the XELSE (if used) and then exits at the END IF. Executes all the statements between the XELSE and END IF and then exits at the END IF. If XELSE is not used it will simply exit at the END IF. INPUT"How old are you: ";Age% LONG IF Age% >=30 PRINT "You are Old aren't you!?" XELSE PRINT "You're just a baby!" END IF RUN How old are you: 30 You are Old aren't you!? LONG IF Name$="Fred" PRINT"Hello Fred ... Long time no-see!" PRINT"The balance you owe is";USING"$iiii.iin;Duei PRINT"Thanks for asking." XELSE PRINT "I don't know you! Go away!" END IF RUN Hello Fred ... Long Time no-see!" The balance you owe is $1234.56 Thanks for asking. REMARK No loop may be executed within a LONG IF construct unless it is completely contained between a LONGIF and XELSE or between the XELSE and ENDIF. The entire LONG IF construct must be completely contained within loops or nested loops in order to compile properly. ZBasic will automatically indent program lines between LONG IF, XELSE and END IF two spaces. See the chapter about "Structure" for more information. Standard Reference 264 LPRINT statement FORMAT LPRINT [variables, constants, ...] DEFINITION The LPRINT statement sends output to a printer. To use LPRINT from the Standard Line Editor use a colon first (:LPRINT). EXAMPLE LPRINT "REPORT OF THE CORPORATION" LPRINT LPRINT LPRINT "SALES:"; TAB (50) ; US,ING" $11, III, III. Ill"; Salesll (1) LPRINT LPRINT "PROFITS:";TAB(50);USING"$III1,III1I1,III1*.III1";Profitsll(1) RUN ~.0'Zl.'l22.'2'3 'Z3,23',n'.03 REMARK Some systems may lock up if a printer is not connected. See your hardware manual for required action. See ROUTE 128, PRINT, LLlST, TAB, DEFTAB, PAGE, USING, WIDTH LPRINT and POS(1). a.& Macintosh: See DEF LPRINT, PRCANCEL, DEF PAGE, PRHANDLE, TEXT and ROUTE 128 in the appendix for more information about printing to the Imagewriter and Laserwriter printers. See appendix for specifics. MSDOS: To use more than one printer you may also use OPEN"I",1 ,"LPT2:" and use PRINT#1, [variables, constants ... ]. Be sure to close the printer device when finished. See MSDOS reference manual for more information about LPT2:, LPT1: and any other devices you may have available for your hardware. Apple ProDOS and DOS 3.3: See DEF LPRINT for setting the printer slot. 265 Standard Reference statement MACHLG FORMAT MACHLG ([bytes ,...Il-or- ([words ,... ]} -or-( [variables] [, ... ]} DEFINITION The MACHLG statement is used to insert bytes directly into a compiled program. These bytes may be machine language programs, variables or other items. It may be used to insert machine language into memory without using POKE. bytes Numbers from 0 to 255 words Numbers from 0 to 65535. They are stored in standard format variables Will create the address where the variable is located. See appendix for specifics. Note: ZBasic uses registers when calculating elements of an array variable. Contents of these registers may be destroyed. EXAMPLE x = LINE "Machine Language Routine" FOR I = 0 TO 10 PRINT PEEK(X+I); NEXT I END "Machine Language Routine" MACHLG 0,1,2,3,4,5,6,7,8,9,10 RUN o 1 2 3 4 5 6 7 8 9 10 REMARK See LINE, CALL, USR, DEFUSR, PEEK, POKE and the chapter about "Machine Language" in the technical section of this manual. Important Note: Use of this statement requires knowledge of the machine language of the computer you are using. Machine language may not be portable to other computers. ~.s Macintosh: Since the Macintosh is a 32 bit machine, MACHLG puts the code into word, not byte, positions. MSDOS: See DEF SEG in appendix. Apple ProDOS: See section entitled Machine Language Interface in appendix. Standard Reference 266 MAYBE function FORMAT MAYBE DEFINITION MAYBE is a random function that retums either a TRUE (-1) or FALSE(O) wHh equal probabilHy. MAYBE is faster than RND. convenient. and requires little program space. EXAMPLE DEFTAB = 8: DIM Coin$(l) Coin$(O)="HEADS":Coin$(l)="TAILS" "Flip a Coin" DO X=X+1 PRINT Coin$(MAYBE+l), UNTIL X=25 END RUN HEADS TAILS TAILS HEADS HEADS REMARK HEADS TAILS TAILS HEADS TAILS TAILS TAILS HEADS HEADS TAILS HEADS HEADS TAILS HEADS TAILS TAILS HEADS TAILS TAILS HEADS This function is useful anytime a 50% random factor is needed. MAYBE with logical operators: MAYBE MAYBE AND MAYBE MAYBE OR MAYBE 267 Standard Reference 50% TRUE 25% TRUE 75% TRUE 50% FALSE 75% FALSE 25% FALSE command MEM FORMAT MEM[ORY) DEFINITION Typing either MEM or MEMORY in command mode will retum information about system memory use. EXAMPLE TEXT The number of bytes being used by the source code. The source code is that part of the program that you type in. MEMORY The number of bytes remaining for program use (varies; see your computer appendix for details). OBJECT The size of the object code after compiling. Valid only immediately after RUN VARIABLES The number of bytes required for variables, INDEX$ array, and disk 110 buffers. This varies dramatically by version. See computer appendix. Valid onlv immediately after RUN MEM 00046 Text 41244 Memory 00039 Object 00388 Variable (some versions may display more information) REMARK These numbers are relative to that version of ZBasic being used. Varies significantly by computer. See your computer appendix for more information. Also see MEM function, CLEAR, CLEAR INDEX$, CLEAR END, LOAD· and the chapter about "Converting Old Programs". Standard Reference 268 MEM function FORMAT MEM DEFINITION Returns the number of bytes available in the INDEX$ array. EXAMPLE CLEAR 1000 PRINT MEM A= MEM INDEX$(O) PRINT MEM STRING$(49,"*") RUN 1000 950 See also INDEX$, MEM command, and CLEAR INDEX$. This function varies by version. See appendix for specifics. REMARK !l MEM(index number) returns the memory available to that INDEX$ (there are ten available on the Macintosh). MEM (-1): Retums the maximum amount of memory available for variables. Also forces unloading of all unlocked memory segments. Returns a Longlnteger. INDEX$ has many enhancements with this version. See appendix . • See appendix for various additions to the MEM function that return memory pointers to arrays, strings, BCD variables and more. 269 Standard Reference command MERGE ["] filespec ["] ["] filespec ["] FORMATS MERGE MERGE> DEFINITION MERGE is used to overlay a line numbered TEXT/ASCII program from disk onto the current program text in memory. Program being merged must be in ASCII (saved w~h SAVE». Incoming text with the same line number(s) as resident text will replace resident text. The asterisk is used to strip spaces and REM's from the incoming program. EXAMPLE 010 REM Program one 120 DO 130 I$=INKEY$ 140 UNTIL LEN(I$) SAVE * "PROGl" NEW 10 20 30 40 50 60 REM Program two PRINT "MAIN MENU" PRINT PRINT "1. Do Inventory" PRINT "2. Print Inventory" PRINT "3. Delete Inventory" MERGE "PROGl" LIST 00010 00020 00030 00040 00050 00060 00120 00130 00140 REMARK REM Program one <---- Line from first program overwrote this line PRINT "MAIN MENU" PRINT PRINT "1. Do Inventory" PRINT "2. Print Inventory" PRINT "3. Delete Inventory" <--- First program merged here DO I$=INKEY$ UNTIL LEN(I$) MERGE has the same affect as manually typing in text. Programs that were written in another BASIC must be in ASCII format before being MERGED into ZBasic. Also see LOAD, SAVE*, RENUM, APPEND and DELETE Standard Reference 270 MID$ function FORMAT MID$ ( string , expr1 [, expr2j ) DEFINITION Returns the contents of string starting at posnion expr1, and expr2characters long. EXAMPLE string The string from which the copy will occur. expr1 The distance from the left that the copy will begin. expr2 Optional parameter that determines how many characters will be copied. If omitted, all characters from expr1 to the end of the string will be copied. A$="The Sun Shines Bright" PRINT MID$(A$,5,3) Z$=MID$ (A$, 15) PRINT Z$ FOR Pointer = 1 TO LEN(A$) PRINT MID$(A$,Pointer,l) NEXT RUN Sun Bright T h e S u n INPUT"First and Last name p1ease:";Name$ PRINT "Thank you Mr. ";MID$(Name$,INSTR(l,Name$," ")+1) RUN First and Last name please: Fred Smith Thank you Mr. Smith REMARK 271 Standard Reference See LEFT$, RIGHT$, INSTR, LEN, STR$ and the MID$ statement. statement MID$ FORMAT MID$ (string1. expr1 [, expr2] ) = string2 DEFINITION Replace a portion of string1 starting at expr1, with expr2 characters of string2. EXAMPLE strIng 1 Target string. String2 will be inserted or layed over this string. strlng2 String to be inserted or layed over string1 . expr1 Distance from the left of string1 where overlay is to begin expr2 How many characters of string2 to insert into string1. Using 255 will assure that all characters are used. A$ B$ "SILLY BOY" "SMART" PRINT A$ MID$(A$,1,5) PRINT A$ B$ RUN SILLY BOY SMART BOY REMARK This function is very useful for altering selected portions of strings. Also see RIGHT$, LEFT$, MID$ function, STR$, INSTR, VAL, LEN, SPACE$, STRING$. Standard Reference 272 FORMAT MKB$ (expression) DEFINITION Returns a string which contains the compressed floating point value of a ZBasie BCD expression. This function works with either single or double precision. The amount of string space used will vary depending on the digits of precision configured. See "Configure". To return the floating point values stored in strings use the cva function. EXAMPLE A$=MKB$(991721.645643) PRINT "The length of A$=";LEN(A$) X!=CVB(A$) PRINT X! PRINT B$=MKB$(991721.645643) PRINT "The length of B$=";LEN(B) Xii=CVB (B$) PRINT Xii RUN REMARK The length of A$=4 991722 <--- Value returned depends on configured precision The length of B$=8 991721.645643 <--- Value returned depends on configured precision Since ZBasie automatically compresses and decompresses BCD variables when using READ# and WRITE#, this function is of primary interest to those people that need to conserve memory for other reasons. See also eVB, CVI, READ#, WRITE# and MKI$. See your appendix for default accuracy and variations. 273 Standard Reference FORMAT MKI$ ( expression ) DEFINITION Returns a two character string which contains a two byte integer specified by expression. To extract the integer stored in a string wth MKI$ • use the CVI function. EXAMPLE A$=MKI$(12345) PRINT"Length of A$=";LEN(A$) B%=CVI (A$) PRINT B% PRINT A$=STR$(12345) PRINT "Length of A$=";LEN(A$) PRINT VAL (A$) RUN REMARK Length of A$=2 12345 <--- MKI$ saves space ... (4 bytes compared to below) Length of A$=6 12345 <--- Leading blank reserved for the "SIGN" Used in older versions of BASIC to convert integers to strings for FIELD statements. ZBasic does this automatically when using READ# and WRITE#. Nevertheless. MKI$ and CVI are still useful for packing strings to save memory-- especially on systems with limited memory. See also CVI. CVB. READ#. WRITE# and MKB$. !l Use DEFSTR LONG to allow MKI$. CVI. HEX$. OCT$ and BIN$ to work with Longlntegers. Use DEFSTR WORD to set back to regualr integer. Note that MKI$ returns a four byte string with Longlntegers. Standard Reference 274 FORMAT expression 1 MOD expression2 DEFINITION MOD returns the remainder of an integer division with the sign of expression 1 . EXAMPLE PRINT "9 DIVIDED BY 2=";INT(9/2);"REMAINDER =";9 MOD 2 RUN 9 DIVIDED BY 2= 4 REMAINDER= 1 PRINT "-4 DIVIDED BY 2=";INT(-4/2);"REMAINDER=";-4 MOD 2 RUN -4 DIVIDED BY 2= -2 REMAINDER= 0 REMARK 275 Standard Reference MOD replaces the old BASIC routines for finding the remainder of a division and is also much faster: OLD BASIC: x= ZBasic: X=XMODN (X - INT(X/N) • N) statement MODE FORMAT MODE expression DEFINITION MODE is used to set the screen graphics or text format. Most computers offer a number of different character and/or graphic modes. Use MODE to choose the mode most applicable to the program. For most systems EVEN modes are character graphics and ODD modes are regular graphics. Not all machines have graphic capability. MODE for some popular microcomputers: MSDOS type Mode number Text ll::irapOiC 0 1 2 40x25 character 40x25 80x25 3 4 80x25 80x25 80x25 character 40x25 5 6 7 80x25 uraphlc Text lliraphlc character 32x16 40x40 none 40x48 64x16 128x48 character 80x24 character 32x16 character character 640x200 Text character none 80x48 64x16 128x48 40x24 character 32x16 character 40x24 280x192 64x16 128x48 80x24 character 32x16 character 80x24 560x192 64x16 128x48 40x24 character 32x16 640x240? 8 9 40x25 40x25 40x40 Bottom 40x48 64x16 128x48 10 11 80x25 character 80x24 character 32x16 character 80x48 64x16 128x48 12 13 80x25 character 32x16 character 14 15 80x25 character 80x25 40x25 80x25 80x25 character 320x200 character 640x200 MACINTOSH Text REMARK TRS-SO I, III 40x 24 320x200 80x25 APPLE lie, IIc Graphic Many Font SEE styles and sizes herel Macintosh APPENDIX Bottom 80x24 Bottom 80x165 64x16 128x48 80x24 character 32x16 character 560x165 64x16 128x48 Bottom CP/M-SO Graphic Text Normally 80x24 SEE ZOO APPENDIX Be sure to read the appropriate appendix for exact mode designations. MODE will reset COLOR to the default, usually the darkest background and lightest foreground, and may clear the screen with some systems. !b& Macintosh: MODE is ignored with the Macintosh. See the TEXT statement for setting character styles and sizes. To emulate other computers you will probably want to use Monaco or Courier mono-spaced fonts. TEXT font, size, face, mode. MSDOS: Modes 16-19 support EGA modes. Mode 20 supports Hercules graphics. See appendix for details. Standard Reference 276 MOUSE function .............................................................................................................................................................. . ..:.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.... ... ... ... ... ... ... ... ... ... "":"... "":"":" ... ... ... ... ... ... ... "":" ... ... ... ... ... ............... "' .......................................................... j' ... • "' ....... "' .................................................................. . ~.":.":.":.'::'.":.":.":.":.": " " " " " " " " " " " " " " " " " " " FORMAT MOUSE (expression ) DEFINITION Returns information concerning the position and status of a MOUSE or JOYSTICK if one is connected to the system. The fOllowing values are returned. EXAMPLE MOUSE (0) Innializes the MOUSE on some systems (nialization is required on the Apple /I ProDOS and DOS 3.3 versions). MOUSE (1) Returns the horizontal coordinate of the mouse. MOUSE (2) Returns the vertical coordinate of the mouse. MOUSE (3) Returns 0 if button not pressed. MODE 5 :REM GRAPHIC MODE CLS X= MOUSE (0) Non-zero if button pressed. <---Initialize mouse WHILE LEN(INKEY$)=O <--- Press any key to stop <--- If button down then ok to draw LONG IF MOUSE (3) PLOT MOUSE (1), MOUSE (2) <--- Plot where mouse (or joystick) is END IF WEND REMARK The above example uses a mouse to draw on the screen. A joystick may also be used (depending on the system). See your computer appendix for hardware device specifics that may apply to these functions. Also see DEF MOUSE. Macintosh Note: You may use the mouse functions above or configure ZBasic for MSBASIC Mouse compatibility using DEF MOUSE=1. See Mac Appendix. MSDOS: Compatible with Microsoft Mouse. ZBasic has to be configured to support a mouse. See "Configure" in MSDOS appendix. If MOUSE(O) <> 0 then a mouse is installed. MOUSE(3) returns 0-3; Zero if both buttons up, three if both buttons down, one or two if one button pressed. MOUSE(4) and MOUSE(5) hide and show the mouse cursor.. DEF MOUSE=O for Mouse, 1 or 2 for joysticks, 3 for lightpens. Apple ProDOS and DOS 3.3: Compatible with AppleMouse or joysticks. Use DEF MOUSE=O for AppleMouse or DEF MOUSE=1 for Joysticks. If using a joystick MOUSE(3) returns 0-3. Zero if both buttons up, three if both buttons down, one or two if one button pressed. See appendix for specifics. Z80: MOUSE IS NOT SUPPORTED with Z80 versions of ZBasic. 277 Standard Reference statement NAME ..................................................................................................................................................................... .".."."'."'."'.".."'."." .... "'.".".."'."."."."."."."..". .... ".".".'".".."'."' ....".".."."."..".."..".."'."."'.1'."."." ...."'.".".".".." -:"-:"":"":",,:",,:",,,",,:",,,",,:":--:,":-''''"'''"'':"'''"'''"'''"0::"'''"'''"'''"'':"'':"'''"'':"'':"":""'"":""'""'""'":-""'""'""'""'""'""'""'"":0:.:-" ... "..."... ".,,:",,:" ... ".,,:-.,,:",,:0:.":" FORMAT NAME string1 AS string2 DEFINITION Renames a file with a filename of string1 to string2. Same as the RENAME statement except for syntax. This statement is provided to make ZBasic compatible with other BASIC languages. EXAMPLE DIR FRED.BAS DICK. BAS TOM.BAS HARRY. BAS NAME FRED.BAS AS GEORGE.BAS DIR GEORGE.BAS DICK.BAS REMARK TOM. BAS HARRY. BAS See RENAME for more information. Bj·'!~ Not available on Apple /I or Z80 versions of ZBasic. See RENAME. Standard Reference 278 NEW command FORMAT NEW DEFINITION NEW is used to clear the text buffer of the current program. Since programs that have been erased in this manner are impossible to recover, SAVE your program first! EXAMPLE LIST+ CLS PRINT"THIS IS A PROGRAM ' ; PRINT"WHICH IS ABOUT TO BE LOST FOREVER AND EVER ..... END NEW LIST (Nothing listed ... ) REMARK 279 Standard Reference Use this command with care. See LOAD. statement NEXT FORMAT FOR var = expression1 TO expression2 [STEP expression3 NEXT [ variable • [ variable . .. I IJ DEFINITION The NEXT statement is used as the end marker of a FOR loop. There must be a matching NEXT for every FOR, otherwise a Structure Error will occur at compile time. EXAMPLE FOR Countl= 1 TO 2 FOR Count2 = 2 TO 4 STEP 2 PRINT Countl, Count2 NEXT Count2, Countl RUN 1 2 1 2 2 2 4 4 FOR X= 1 TO 2 FOR y= 1 TO 2 PRINT X,Y NEXT NEXT RUN REMARK 1 1 2 1 2 2 2 1 The variable(s) following the NEXT statement are optional; however, if used they must match the corresponding FOR variable(s). A FOR-NEXT loop will execute AT LEAST ONCE! A Structure Error will specify the line number if there is an extra NEXT; or will specify line 65535 if a NEXT is missing. ZBasic automatically indents all loop structures when you LIST your program. This may be used to find where the missing NEXT is located by simply following the program listing back to the point where the extra indent ends. See "Loops" in the front of this manual and; WHILE-WEND, DO-UNTIL, LONGIFXELSE-ENDIF for other loop and structure types. Standard Reference 280 FORMAT NOT expression DEFINITION NOT retums the opposHe of expression. True is False, False if True. This is equivalent to changing a logical true (-1) to a logical false(O) and vice versa. WHh Boolean (binary) operations, the NOT function will toggle all bHs in expression. That is, all bits that are one will be changed to zero, and all bits that are zero will be changed to one. EXAMPLE A$="Hello" IF NOT A$="Bye" THEN PRINT"True, it is False" END RUN True, it is False REMARK A logical true is -1 and logical false is O. Also see XOR, OR, AND. NOT condition NOT NOT NOT 1 0 !l 0 1 TRUE(-1) if condition FALSE, else FALSE (0) if TRUE BOOLEAN "16 Blr' LOGIC NOT 11001100 NOT 01111011 00110011 10000100 Will also function with 32 bit Longlntegers. 281 Standard Reference function OCT$ FORMAT OCT$ (expression ) DEFINITION OCT$ returns a 6 character string which represents the Octal value (base 8) of the resuH of expression truncated to an integer. Octal digits are from 0-7. Q.QIA1. 0-7 10 11 12 13 14 15 16 17 20 EXAMPLE DECIMAL eaulvalent 0-7 8 9 10 11 12 13 14 15 16 The following program will convert a decimal number to Octal or an Octal number to decimal: CLS DO INPUT"Decimal number: n;Decimal% PRINT "Octal Equivalent: ";OCT$(Decimal%) INPUT"Octal number: ";Octal$ Octal$="&O"+Octal$ PRINT"Decimal Equivalent: ";VAL(Octal$) UNTIL (DECIMAL%=O) OR (LEN(Octal$)=2) RUN Decimal number: 8 Octal Equivalent: 000010 Octal number: 100 Decimal Equivalent: 80 REMARK Conversions are possible from any base to any other base that ZBasic supports. See the Chapter "Numeric Conversions" in the front of this manual. See also BIN$, HEX$ and UNS$. a Use DEFSTR LONG if you want to use OCT$, HEX$, BIN$, UNS$, MKI$ or CVI with Longlntegers. Use DEFSTR WORD to set back to regular integer. Standard Reference 282 ON ERROR statement FORMAT DEFINITION EXAMPLE ON ON ON ERROR ERROR ERROR GOSUB Line or label RETURN GOSUB 65535 The ON ERROR allows the user to enable and disable disk errortrapping. If ON ERROR is not used ZBasic will display disk errors as they occur and give the user the option of continuing or stopping. Options offered with ON ERROR: ON ERROR GOSUB 65535 Enable user disk error trapping. Errors are retumed using the ERROR function. You must check for errors---ZBasic will not when this parameter is set. ON ERROR GOSUB line If a disk error occurs the program does a GOSUB to the line or label specified. ON ERROR RETURN Disable user disk error trapping. ZBasic will trap the disk errors and give error messages at runtime. ON ERROR GOSUB 65535: REM Enable disk error trapping "Start" OPEN "I" ,1, "TEST" IF ERROR GOSUB"Disk error" GOTO "Start" program continues ... "Disk error" LONG IF (ERROR AND 255)=3: REM Check for File not found error PRINT"Check that correct diskette is in drive: "; DO UNTIL LEN{INKEY$) ERROR=O : RETURN XELSE PRINT"A Disk Error has occurred:";ERRMSG${ERROR) PRINT"ontinue or top?"; DO temp$=UCASE${INKEY$) UNTIL (temp$="C") OR (temp$="S") IF temp$="C" THEN ERROR=O: RETURN END IF PRINT"P rogram aborted!" ERROR=O STOP REMARK Also see ERROR and ERRMSG$ and the chapter about "Disk Error Trapping" in the "Files" section of the manual. See RETURN line for another way of returning from ON ERROR GOSUB line. Important Note: Always remember to set ERROR=O after a disk error occurs when you are doing the disk error trapping. Failure to do this will cause ZBasic to continue to retum a disk error condition. 283 Standard Reference statement ON GOSUB 11 FORMAT ON expression GOSUB line [, line [, line . .. DEFINITION The ON GOSUB statement is used to call one of several subroutines depending on the value of expression. The ON statement will call the first subroutine nthe expression evaluates to one, to the third subroutine if the expression evaluates to three and so on. The RETURN statement at the end of a subroutine will return the program to the statement immediately following the ON GOSUB. EXAMPLE "Inventory Menu" CLS PRINT "1. Inventory" PRINT "2. Print Listing" PRINT "3. Month End" PRINT "4. EXIT PRINT PRINT "Enter item wanted: , n. DO Item%=VAL(INKEY$) UNTIL (Item% >0) AND (Item% <5) ON Item% GOSUB "Inventory", "Print", "EOM", If Exit 11 GOTO "Inventory Menu" END "Inventory" RETURN "Print n RETURN llEOM" RETURN "Exit" END REMARK ZBasic will truncate expression to an integer. For example, if expression equalled 1.9, the ON statement would go to the first line (INT(1.9)=1). If expression <=0 or> (number of line numbers listed), the program will continue on to the next statement in the program. Standard Reference 284 ON GOTO statement FORMAT ON expression GOTO line [, line [ , line . .. II DEFINITION The ON GOTO statement is used to branch, or jump, to one of several portions of a program depending on the value of expression. The ON statement will jump to the first subroutine if the expression evaluates to one, to the third subroutine if the expression evaluates to three, and so on. EXAMPLE A=RND(4) ON A GOTO "ONE", "TWO", "THREE", "Last" END "ONE" PRINT 1 END "TWOII PRINT 2 END "THREE" PRINT 3 END "Last" PRINT 4 END RUN 4 REMARK ZBasic will truncate expression to an integer. For example, if expression equalled 1.9, the ON statement would go to the first routine (INT(1.9)=1). If expression <=0 or> (number of line numbers listed), the program will continue on to the next statement in the program. See "Structure". 285 Standard Reference statement OPEN [ # I filenumber, filename [, record length [ # I filenumber, filename [, record length [ # I file number , filename [, record length I I I FORMAT OPEN "I", OPEN "0", OPEN "R", DEFINITION The OPEN statement is used to access a data file. Once a file is opened, information may be read from or written to the file depending on the way the file was opened. The first argument determines access: EXAMPLE "R" Read/write file: Open file if it exists, create the file if it doesn't. "I" Read only file: Open file for input. If file doesn~ exist, a disk error occurs (file not found error). "0" Write only file: Open file for output. Overwrites the old file. filenumber The number you assign to a file which is subsequently used with file commands like READ#, WRITE#, INPUT#, LlNEINPUT#, PRINT#, REG, LOG and LOF. filename The filename as it appears in a directory. See your DOS manual and the appendix in this manual for information about drive specifiers, pathnames, sub-directories or whatever syntax is used for that computer. record length Optional record length to be used with that file (default is 256). REM Open a file for READ and WRITE OPEN "R",1, IIINVEN", 180 REM Open a file for Input only OPEN "1", File%, D$+"INVEN", 180 REM Open a file for Output only OPEN "0",2, Filename$ REMARK To configure ZBasic to have more than two files open at a time; see "Configure". Each file buffer will require between 160 and 1024 bytes of memory depending on the Disk Operating System and your version of ZBasic. No more than 99 files may bQ open at one time. See your computer appendix for more information about file types, changing directories and more. Also see INPUT#, PRINT#, READ#, WRITE#, LOC and REC. TO INSURE DATA INTEGRITY, ALWAYS CLOSE OPEN FILES BEFORE EXITING YOUR PROGRAM. continued ... Standard Reference 286 OPEN statement OPEN continued r!n~ Macintosh: Extra parameters included: vofume% The number you get from FILES$ that sets the folder or root location of the file. Much easier than pathname specifiers. See appendix for details. Also see FILE$, EJECT, EOF, LOF, "File size", APPEND and pathnames. Example of volumn number: OPEN"type", Additional types j.' Pathnames fnurn, "filename", 200, vo.lume% "R[R]", "O[R]", "I[R]", "A[R]" and "R[D]", "O[D)", "I[D)", "A[D]" The optional "R" or "D" after the file type specifies opening the resource fork (R) or data fork (D). The data fork is the defauK. See appendix for specifics. The "A" type opens a file for append. Also see APPEND for positioning the file pointer to the end. Pathnames are supported like: Root: Folder: Fred MSDOS: There are many ways to specifiy, create or remove diieCiories and sUb-directories. See PATH$, CHDIR, MKDIR and RMDIR in the appendix. Apple ProDOS: See PATH. Filenames may contain pathname information like: PROFILE I ZBAS ICI SOURCE. See appendix for details. Apple DOS 3.3 uses CP/M type drivespecs like: A: instead of D1, B: instead of D2, etc. Filetype is specified by a leading exclamation mark and a number: OPEN"-", filenumber, !type= "n !type) [drlvespec) filename", record length 1= Text file 2= Integer BASIC 3= Applesoft BASIC 4= Binary file 5= 6= 7= 8= S type file Relocatable file type A type file B type file Example: OPEN"-", fnurn, "!4A:Fred", 200 jal!l CP/M-80: You may use a drive specifier in the filename: OPEN"-",n,"A:Fred.DAT", 200 TRS-80: You may use a drive specifier in the filename: OPEN"-",n,"Fred/DAT.password:l",200 287 Standard Reference statement OPEN FORMAT OPEN "C",-1 or -2 [,[baud rate J[,[paritY)[,[stopbit][, word length 1111 DEFINITION This statement is used to set serial communication port parameters. If any of the parameters are omitted the default will be used. -1 -2 Serial port one Serial port two baud rate 110, 150, 300(default), 600, 1200, 2400, 4800, 9600 parity o = none "c" <-- default 1 = odd 2 = even stopbit o= one <-- default 1 = two word length EXAMPLE 0=7bits 1 = 8 bits <-- default REM A Very Cheap Terminal Program OPEN"C", -1, 300 <---Change parameters as needed DO READjf-l, A$;0 IF LEN(A$) THEN PRINT A$; A$=INKEY$ IF LEN(A$) THEN PRINTjf-l,A$; UNTIL A$="j" REMARK <--- (;0) Won't "Hang" if nothing at port <--- Set a key to stop Serial ports may be accessed using the same statements used in disk I/O: PRINT#, INPUT#, LINE INPUT#, READ#, and WRITE#. In all of these statements, the port is not read or written to until the status indicates that the port is ready. The one exception to the paragraph above is when READ# is used to read a string of zero length. In this case, the character will be returned if ready, otherwise a null string will be returned (similar to the INKEY$ function) (Not supported with CP/M). A port does not have to be opened in order to be accessed. The OPEN "C" statement is used only to set the current port parameter values. Without this statement, the port will simply use the parameters to which it was last set. All versions have a number of machine specific parameters. See appendix for important details. continued ... Standard Reference 288 OPEN "c" statement OPEN "C" continued The following are examples of sending or receiving files over a modem or serial line. Check appendix and hardware manuals for specifications. Add your own line numbers, and modify programs as needed. Save with SAVE+ to use later. SENP FILES TO ANOTHER COMPUTER "SEND FILES" LINEINPUT"File to send: ";File$ IF LEN(File$)=0 THEN STOP: REM No file? STOP OPEN"I",l,File$ ON ERROR GOSUB 65535: REM Catch errors OPEN"C",-1,300: REM Change parameters as needed DO LINEINPUT#l, Line$ IF LEN (Line$) THEN PRINT#-l, Line$ DO <---- This DO loop is an example of "Handshaking" remove READ#-l,A$;O this loop, and the PRINT# below, if not needed. UNTIL ASC(A$)=l UNTIL ERROR IF ERROR=O CLOSE#! PRINT#-l,"*END*": REM Tell receiver "All Done!" RETURN RECEIVE FILES FROM ANOTHER COMPUTER "RECEIVE FILES" LINEINPUT"Filename to Receive: ";File$ IF LEN(File$)=0 THEN STOP: REM No File? STOP OPEN"O",l,File$ OPEN"C",-1,300: REM Change parameters as needed DO LINEINPUT#-l, Line$ IF Line$<>"*END*" THEN PRINT #1, Line$ PRINT#-l, CHR$ (1) ; <--- Goes with "Handshaking" Do Loop above. UNTIL (Line$="*END*") CLOSE#! RETURN 289 Standard Reference FORMAT expression OR expression DEFINITION Performs a logical OR on the two expressions for IF THEN testing and BINARY operations. If either or both conditions are true the statement is true. See truth table below. In binarylboolean operations if either bit is one than a one is returned. EXAMPLE A$="HELLO" IF A$="GOODBYE" OR A$="HELLO" THEN PRINT"YES" RUN YES REMARK Truth table for the OR function. condition OR condition TRUE(-1) if either or both is TRUE, else FALSE(0) BOOLEAN "16 BIT" LOGIC OR 1 OR o OR 1 OR o OR 1 1 1 0 1 1 0 0 OR 00000001 00001111 00001111 OR 10000101 10000111 10000111 Also see AND, XOR and NOT. & Functions with 32 bit Longlnteger as well. Standard Reference 290 OUT statement ............................................................................................................................................................... ... "'.". .... J" .......... Il' ............. "' ............. "'." .......... J' .......... ............... " ....... "'."' ............. "' ................ "."' ....... ". ... . "":"":"":"":"":"":"":"":"":"":"":-":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":"":""''''':'''':'''':'''':'''':'''':'''':'''':'''':'''':'''':'''':'''':'''':'''':-'':"": port, data FORMAT OUT DEFINITION The OUT statement sends dala to the specified port number. EXAMPLE OUT 1,12 A=6:B=9 OUT A,B OUT END REMARK A/2,B/3 This statement is microprocessor dependent and works only with Z80 and 8086 type processors. Also see INP for a way of reading data in from the port. !lS Not supported with these versions. 291 Standard Reference statement PAGE FORMAT PAGE DEFINITION Relurns the current line position of the printer. The first line is line zero. EXAMPLE PAGE PRINT PAGE LPRINT LPRINT LPRINT PRINT PAGE <---Also see PAGE statement RUN a 3 REMARK This function is similar to POS except the line position is returned instead of the character position. Important Note: If your operating system uses forms control and checks lines per page, you must disable the operating systems forms control or ZBasic's PAGE . • See CSRLN in the MSDOS appendix for getting the line position of the screen cursor. Standard Reference 292 PAGE function 1[. [expression3 IIII FORMATS PAGE [[expression11 [. [expression2 DEFINITION PAGE is used to format output to the printer and to control the number of actual lines per page, printed lines per page and top margin. Following is a description of the parameters: PAGE Without parameters will send a page feed to the printer. this forces the print head to move to the defined position of the top of the next page. expression 1 The number of printed lines per PAGE. expression2 The number of actual lines per PAGE. Also resets line count to zero (normally 66 lines per page). expression3 Lines for the top margin. This number is a subset of expression1. If the line count is zero, this many linefeeds will be output immediately. <--- Sets Listings to 60 lines per page with 3 lines as top margin. Skips perforations nicely. EXAMPLE PAGE 60,66,3 REMARK WIDTH LPRINT should be set to your printer's character width for proper PAGE operation when doing LLiST. See PAGE function. To disable PAGE use PAGE 0. Important Note: If your operating systems uses forms control and checks lines per page, you must disable the operating systems forms control or Z8asic's PAGE. 293 Standard Reference PATH ....".."'.........."'.... "'." ...."............."............."...."'....................................."......."......................".". .... ....'" "'"":"":""'"":""'""'""'"":""'""'"":"":"":"":""'""'""'""'"":""'""'""'"":""'""'""'"":" ... "":"":" ... "":" ... "":"":" ... "":" ... "":"":" ... "":"":"":"":" ... "":"":" ... ... "... ... ......................................................................................'\0 ......................................................................... ". " FORMATS PATH DEFINITION PATH or PATH type commands are available on many versions of ZBasic that support multi-level directories. Rather than give the exact syntax for each machine this page gives a general overview. See your computer appendix for specifics. MSDOS " " See PATH$ function in the appendix. This allows you to get the current path name so that you can return to that sub-directory. Syntax is PATH$(drive number). Note: Drive A=1, B=2, ... Pathname syntax example: C:\ZBasic\TEMP Apple ProDOS See PATH command in the appendix. Also see the example function on the master disk called: PREFIX.SAMPLE for ways of getting ProDOS pathnames during runtime. Pathname syntax example: IPROFILElZBASIC/OBJECT Path names not supported w~h DOS 3.3 version. Macintosh The most appropriate way of specifying where a file is located is using the volumn number. This is recommended in "Inside Macintosh". Volume numbers are obtained easily using the FILES$ function. See Macintosh appendix. Nevertheless, pathnames are supported and may be used. Pathname syntax example: Fred:Tom:Harry zao Pathnames are not supported since the operating systems for this CPU do not currently implement sub directories. EXAMPLE See your appendix for examples. REMARK This command varies significantly by computer type. See DIR, OPEN and also be sure to see your appendix for specifics. j·'!l Pathnames are not supported with Apple DOS 3.3 or zao versions of ZBasic. Standard Reference 294 PEEK function FORMAT PEEK [WORD) (expression ) PEEK LONG (expression)* DEFINITION Returns the contents of the memory localion(s) specified by expression: PEEK PEEK WORD PEEK LONG* EXAMPLE Returns a one byte number (0-255) Returns a two byte number (-32768 to 32767) Returns a four byte number (*32 bit versions) X=VARPTR (A$) <---Get a safe place in memory to play wilh POKE X, 10 POKE WORD X+1, 12000 PRINT PEEK(X) PRINT PEEK WORD (X+1) RUN 10 12000 REMARK See POKE, POKE WORD and POKE LONG, USR, MACHLG, CALL, LINE, HEX$, OCT$, UNS$ and the section in the front of this manual; "Machine Language". Important Note: This function is for people experienced with machine language and the hardware of their computer. aa *Maclntosh: Always use Longlntegers for expressions to pass an address or to retrieve a four byte Longlnteger. See appendix. MSDOS: An extra parameter is available to determine the segment of the variable: PEEK[WORD) (address, segment). Also see MEM and DEF SEG in the appendix. 295 Standard Reference statement PLOT FORMAT DEFINITION PLOT PLOT [TO exprt , expr2 expr1 , expr2 [ TO expr3, expr4 ... J [TO expr3, expr4 ... J The PLOT statement is used to draw either one graphic point, or a line between two or more pOints, in the current COLOR. Examples: PLOT PLOT PLOT PLOT EXAMPLE J 10,12 10,12 TO 100,100 10,12 TO 10,90 TO 1,1 TO 10,12 CLS MODE 5 PLOT 209, 304 PLOT one point at position 10,12 PLOT a line from 10,12 to 100,100 PLOT two lines: 10,12 to 10,90, to 1,1 PLOT a line from last position to 10,12 <-<-<-<-- <---Set graphics mode <--- Plots one pixel <--- Sets COLOR to foreground COLOR -1 REM PLOT an angle PLOT 209,304 TO 987, 643 TO 322,742 END RUN See illustrations on the following page. REMARK As with all other ZBasic graphic commands, Device Independent Graphic coordinates of 1024 by 768 are the default. Expressions are truncated to an integer. Character type graphics will be substituted on computers, or modes, without graphic capabilities. Also see CIRCLE, BOX, FILL, POINT, COLOR. Macintosh: Use COORDINATE WINDOW to set to pixel graphics. Use COORDINATE to set yur own relative coordinates or to set back to 1024x768. The upper left-hand comer of a WINDOW is coordinate 0,0. MSDOS: Use COORDINATE WINDOW to set pixel coordinates. See COORDINATE to set relative coordinates or to set back to ZBasic coordinates. Z80: POKE &xx3F, &C9 for pixel coordinates. POKE &523F, &C3 to set back to ZBasic coordinates. xx= CP/M=01, TRS-80 model 1,3=52. TRS-80 model 4=30. Apple /I ProDOS: POKEWORD &85, back to ZBasic coordinates. ° for pixel coordinates. Use MODE to set Apple II DOS 3.3: POKE &F388,&60 for pixel coordinates. POKE &F388, &A9 to set back to ZBasic coordinates. Standard Reference 296 PLOT statement PLOT continued PLOT 209 9!l7 ...........: ................................... : ............ 1023 '" · ···· · : : PLOT 209,304 .. ... . . J . II> 304: ............ .0 ..... . _ PLOT 987,643 ,-.. "" .. . 643~ ................................................... - IF 767 PLOT 0.0 209 . 322 . 9.87 . 1 •• 111111 . . . . . . . 11111 . . . . , . , 1 . 1 • • • • • • • • • • 1'1 • • • 1' • • 111111.111 PLOT 209.304 TO 987.643 TO 322.742 767 297 Standard Reference 1023 function POINT FORMAT POINT ( expression 1 , expression2 ) DEFINITION Point is available on many computers to inquire about the COLOR of a specific screen graphic position. As with other commands, ZBasic Device Independent Graphic coordinates may overlap pixels. In the example: 0=Background (white here), 1 =Foreground (black here) ZBeslc coordinates POINT ( h, V ) "'!"'!"---- "'0123. , EXAMPLES' POINT (0,0) =1 POINT (1 ,0) =1 POINT (0.2) =0 POINT (2,1) =0 POINT (2,2) =1 Screen Pixel • Note: Point returns COLOR of cocrdinate As with all other ZBasic graphic commands, the device independent coordinate system of 1024 x 768 is the default. EXAMPLE COLOR 1 PLOT 0,0 to 900,767 PRINT POINT(O,O) RUN 1 REMARK If the coordinate is outside screen coordinates, a -1 will be returned. See COLOR, BOX, CIRCLE and the section; "Graphics". See COORDINATE or PLOT for ways of converting some versions of ZBasic to pixel coordinates that can used with POINT. _ J-"l... POINT is not available for CP/M versions (including the Kaypro graphic verSions). Standard Reference 298 POKE statement FORMAT POKE [WORD] express;on%, express;on2 POKE LONG expression&, expression2&' DEFINITION POKE writes the value of express;on2 into a memory location. The first expression is the address to POKE. The express;on2 is the data to POKE. J:Y£I:. POKE POKE WORD POKE LONG" EXAMPLE eXPress/an2 One byte Two bytes Four bytes ("32 bit machines only) x = 12345: XA = VARPTR(X) PRINT"Byte at ";UNS$(XA);" =";PEEK(XA) POKE XA,99 PRINT"Byte at ";UNS$(XA);" =";PEEK(XA) POKE WORD XA,44444 PRINT"WORD at .. ;UNS$ (XA);" =" ;UNS$ (PEEK WORD (XA» END RUN Byte at 59009 Byte at 59009 Word at 59009 REMARK 57 99 44444 Also see PEEK, PEEK WORD, PEEK LONG, MACHLG, CALL, LINE and the chapter "Machine Language" at the beginning of this manual. Important Note: Indiscriminate use of this command may cause unpredictable computer operation and loss of data or program. This statement is for experienced machine language programmers only. Porting of programs with POKE is not recommended. ~. "Macintosh: Always use Longlntegers for addresses and when using POKE LONG or PEEK LONG. MSDOS: There is an optional parameter for segment: POKE [WORD] address, data, segment. See MEM and DEF SEG in the appendix. 299 Standard Reference function POS FORMAT P~S DEFINITION Returns the current horizontal cursor position, from zero to 255, for a screen, printer or disk file. (byte expression ) The expression specifies a device as follows: Default device (normally the video monitor) Printer Disk file (limited to one file using carriage retums) POS(O) POS(1) POS(2) EXAMPLE CLS PRINT "READ and DISPLAY SCREEN pas" FOR I O T a 30 STEP 10 PRINT TAB(I); POS(O) NEXT PRINT PRINT "READ and DISPLAY PRINTER pas" DEFTAB 5 FOR I o TO 6 LPRINT, PRINT POS(1), NEXT END RUN READ o READ 6 REMARK and and 12 DISPLAY SCREEN pas 10 20 DISPLAY 18 PRINTER 24 30 pas 30 36 A carriage return will set the POS value to zero. PAGE will return the current line position for the printer. Also see WIDTH, PAGE and WIDTH LPRINT. While this command will work the same on all systems, it is dependent on screen and printer widths. Standard Reference 300 PRINT# statement FORMAT PRINT # expression. list of things to print..... . DEFINITION Used to PRINT information to a disk file or other device in text format. Numbers or strings will appear in the file or device similar to how they would look on the screen or printer. The expression is the file number assigned to a disk file or other device in an OPEN statement. INPUT# or LlNEINPUT# are normally used to read back data created with PRINT# (although READ# may also be used). EXAMPLE A$="TEST":B$="TEST2":C=900 OPEN "0" ,1, "TEST.DAT" PRINTill, "HELLO·..·, "A$", "B$","C <--- Quoted comma delimeters for INPUT# CLOSE ill OPEN"I",l,"TEST.DAT'1 INPUT#1, X$, Y$, Z$, A% <--- INPUT in same order and same type PRINT X$, Y$, Z$, A% CLOSE END ill RUN HELLO REMARK TEST TEST2 900 While this command will work the same on all systems. it is dependent on disk inpuVoutput capabilities. Use INPUT# or LlNEINPUT# to read back data written with PRINT#. Be sure to see the entry on INPUT# in this reference section for more infonnation about using PRINT# and INPUT# together and also information about MSBASIC syntax differences. See ROUTE. OPEN. OPEN"C". INPUT#. LlNEINPUT#. READ#, WRITE#, LPRINT and the section in the front of this manual called "Files" for more information. 301 Standard Reference statement PRINT FORMAT PRINT [ {@ I %J (expr1, expr2 )] [list of things to print.... ] DEFINITION The PRINT statement is used to output information to the current device, normally the video. @ (expr1,expr2) % (expr1 ,expr2) Specifies text coordinates. Specifies graphic coordinates. Note: Expr1 =Horizontal. Expr2=Vertical. EXAMPLE o I. 1 2 3 4 .... HORIZONTAL ...... N a m e : , PRINT@(1,1)",HI"; V E R T I C A \ \ , PRINT @ (O,S)",Name: ";AS L PRINT@(l,l)"Hi"; PRINT@(O,5)"Name:";A$ END REMARK PRINT followed with a semi-colon will disable the carriage retum. A PRINT item followed by a comma will cause the next element to be printed at the next tab stop defined by DEF TAB. While this command will work the same on all systems, it is dependent on hardware. See ROUTE for ways of sending PRINT data to another device like a printer, disk file or serial port. See "Screen and Printer Text Control" in the front section of this manual for other ways of formatting text. As with all other ZBasic graphics commands, PRINT %(x,Y) defauHs to printing at the position specified by the Device Independent Graphic coordinates of 1024 x 767. See PLOT or COORDINATE for ways of changing some versions of ZBasic to using other coordinates. Standard Reference 302 PRINT USING function FORMAT PRINT[# filenumber ,] USING formatstring ; numeric expression; [USING ... ] DEFINITION This function permits formatting numeric data in PRINT or PRINT# satements. The last numeric digit displayed will be rounded up by adding 5 to the first digit on the right that is not displayed. The formatstring may be a quoted or string variable using the following symbols: ~ Definition # Holds place for a digit. More than one may be used. An example of using this symbol to hold dollars and cents: PRINT USING "$#U.U";A# $123.45 Insert a comma in that place. An example of using it to format numbers with dollars and cents would be: PRINT USING"$##,###.iliI";A# $12,345.67 Determines placement of decimal point within the format field: PRINT USING"$iIiI, U#, ilU. U"; A# $12,345,678.90 $ Prints a dollar sign on the left of the format. See examples above. + Prints a floating plus or minus sign on the side of the number where the plus sign holds the place. PRINT USING"+UU.U";AiI +1234.56 PRINT USING"+UU. U"; -1234.56 -1234.56 Prints a minus sign only if the expression is negative. PRINT USING"+UU.U";AiI 1234.56 PRINT USING"+ilU#. U"; -1234.56 -1234.56 * Fill the spaces before a number with asterisks. One example would be formatting ouput when printing checks. PRINT USING"$#iI,##iI,###.iI#";12.34 $********78.90 EXAMPLE See examples on next page ... REMARK When error is printed in the format field, this indicates the occurrence of an overflow condition and replaces the number that would have been printed. An overflow condition is when the value of the expression used would have exceeded the bounderies of the format. USING not available for string formatting. See LEFT$, RIGHT$, STRING$ and MID$. !b This version allows USING without PRINT. A$=USING"####.##";232 is acceptable. See appendix for additions to exponential formatting with this version. 303 Standard Reference function PRINT USING PRINT USING continued FORMAT EXAMPLES In all the examples A =12345.678. Note that .678 rounds up to .68. PRINT USING FORMAT "*$"',"',"',"'."";A RESULT **********$12,345.68 "%III.'";A/1000 %12.3 "+"',"'."";A "-"',III.II";-A +12,345.68 -12,345.68 ""/"/"";A 1/23/45 "":#':"";A 1:23:45 "."',"',"',"'";1.345E-8 .000,000,013,450 ".""""""";1.345E-8 .000000013450 ""',"',"',"',"'";9.123E15 9,123,000,000,000,000 12.30E16 ""'."E16";123E15*lE-16 PROGRAM EXAMPLE A$=""."" PRINT USING A$;10.2,USING A$;9.237, USING A$; 4.555 PRINT 10,12,13, USING A$;12.399 PRINT@(O,10);USING A$;23.12321 PRINT%(O,295);USING "@###'#."";12.33 OPEN"O",1, "TESTFILE lt PRINT'l, USING A$;9.999 CLOSEIl RUN 10.20 10 23.12 @12.33 10.00 9.24 12 4.56 13 12.40 <--- at text position 0,10 <--- at graphic position 0,295 <--- To disk file "TESTFILE" Standard Reference 304 PSTR$ function/statements FORMATS function PSTR$( var%) statements READ PSTR$( var%) PSTR$( var%) = "quoted string constant' DEFINITION The statements load the address of a string constant into var"/.. The function returns the string pointed to by var"/.. EXAMPLE DATA Andy, Dave, Scott, Mike DIM D (4) FOR X=l TO 4 READ PSTR$ (D (X) ) NEXT <---Set Pointer String to DATA items above "Print PSTR$ of D(n)" FOR X=lT04 PRINT PSTR$(D(X)) NEXT END PSTR$(g%)="Hello" PRINT PSTR$ (g%) <--- Set Pointer String to a constant RUN Andy Dave Scott Mike Hello REMARK This is a handy way to save string memory. Examples: A$="Hi There!" A$ will take at least 10 bytes (256 bytes if not defined). The quoted string takes another 10 bytes. Total memory used: 20 bytes PSTR$(A)="Hi There!" The quoted string "Hi There!" takes 10 bytes. The integer variable "A" takes two bytes. Total memory used: 12 Bytes !l Macintosh: Use var& instead of var"/.. 305 Standard Reference statement PUT .............................................. "' .................................................................................................................... ."."'."'."'.,/'."."."."."'."."."'."'."."."'.".1'." ...."."'."'."' .... '".1'.rI" •.I'."' ...."."' ....J"." ....... "'.oI'.".". .."..I'.".".". rl'.ol' .... ". .... ",,,,,,,,,,,""''''''''''''''':-'':''''''''''''''''''''''''''''''''''''''':'''''''''''''''''''''''''''''''''''''''''''':'''''''":"":"":""''''':''''''''''''''''''''"''''''''''''''''''''''''''''''''''''''''''''''''''''''''':'''''''''''''''''''''''''''.:FORMAT PUT (x1,y1) variable [(array index I. array index [, ... J) I. mode 1 DEFINITION This statement places the graphic bit image stored in an array with the GET statement, to the screen position at coordinates specified by x1,y1. If an array has been used then you MUST specify the index number of the array (some versions of BASIC always assume an integer array. ZBasic will allow you to store bit images in any variable type as long as enought memory is available to do so. Memory required for pixel images is calculated using this formula (based on GET (x1,y1)(x2,y2) where x1 and y1 deSignate the upper right-hand-comer of the image and x2 and y2 are the pixel positions designating the lower-Ieft-hand-corner of the image) : 6+((y2-y1)+1) * ((x2-x1+1) * bpp+7)/8) The number of bits per pixel (bpp) depends on system colors or grey levels. See next page for specifics. Also see GET in this reference section, for detailed information about storing the pixel image in an array. mode XOR XORs the pixels over the background pixels. This is the most usful for animation purposes and is also the default. OR ORs the pixels over the existing pixels This one way to cover the background graphics (overlays the existing graphics). AND ANDs the picture with the background. PRESET Similar to PSET except the reverse image is shown (negative). PSET Draws the image over the background exactly as created. It is recommended that COORDINATE WINDOW be used when using GET. EXAMPLE DIM A(10000) MODE 7 COORDINATE WINDOW <---- Not needed on the Macintosh version <--- Pixel coordinates CIRCLE 100,100,80 GET (0,0)-(100,100), A(l) FOR x= 1 TO 200 STEP 3 PUT (x, 90), A (1) <--- Do it twice to XOR the pixels and move the image across PUT (x, 90), A (1) the screen without disturbing the background NEXT x END This routine moves a section of a circle across the screen. It is XORed to the screen twice so the item doesn't repeat and it will appear to move across the screen without disturbing the background (default PUT mode is XOR) . continued ... Standard Reference 306 PUT statement ................................................................................................................................................. .......... . . ~ .......... "' .......... oI' ............. rI' .... rI' ................... rl' .... rl' .... "'."' ............. J'.rl' .............".."' .......... "" "'.01' ....".."' ............. "' • ~.~.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.":.": "":"":""'"":"":"":"":"":"":"":""'"":"":"":"":"":"":"":"":"":"":"":"":"":"":"": REMARKS It is important to see entry under GET for more information. ~ Macintosh: With this version of ZBasic, PUT has another, optional, parameter: [- (x2, y2) 1, var. The second parameter allows you to scale the image, making it either larger or smaller by giving the rectangle size in which ij is to appear. The x2, y2 parameter is the lower-right comer of the image. PUT (xl, yl) Btts-per-pixel (bpp) will vary by the type of Macintosh you have. The standard black and white Macintoshes have one bit-per-pixel. The Macintosh II may have up to 16 bits-per-pixel (with upto 256 colors or grey-levels per pixel). Check addendum of Macintosh II for specifics . • MSDOS: Biis-per-pixel (bpp) will vary with the graphics adaptor board being used: GRAPHIC TYPE MODE(s) CGA 5 CGA EGA EGA HERCULES 7 16-19 16-19 20 COLORS 4 2 3-16 16 1 BITS PER PIXEL (bpp) 2 1 2 (64K or less on EGA card) 4 (More than 64K on card) 1 Ja'!l Z80: GET and PUT are not supported with these versions of ZBasic. II Apple 1/ ProDOS and DOS 3.3: GET and PUT are not supported with this version. See DRAW example on ProDOS disk and the BLOAD and BSAVE functions for possible alternatives. 307 Standard Reference command QUIT FORMAT QUIT DEFINITION QUIT is used to exit the ZBasic Standard Line editor and retum control to the operating system. EXAMPLE QUIT DOS REMARK Ready <----DOS prompt of your system We highly recommend saving your program prior to using QUIT. !b& Macintosh: You may also quit from the menu. MSDOS: SYSTEM functions the same as QUIT. Standard Reference 308 RANDOM statement I FORMAT RANDOM [IZE] [expression DEFINITION Seeds the random number generator so that ZBasic produces a new sequence of random numbers. If expression is used, the RND function will return a repeatable series of numbers. DEFTAB 5 RANDOM 12345 FOR I = 1 TO 5 PRINT RND(10), NEXT I EXAMPLE RANDOM 12345 <--- Let's see if it repeats as above. FOR I = 1 TO 5 PRINT RND(10), NEXT I: PRINT RUN 8 8 1 1 10 10 4 4 7 7 PRINT"Press any key to set random seed" DO R=R+1 UNTIL LEN(INKEY$) RANDOM R <--- Paranoid seed routine FOR I = 1 TO 5 PRINT RND (10), NEXT I END RUN Press any key to set random seed 1 8 8 5 9 The results of the first two passes were the same because the seed of 12345 was the same. When a different number is used, or no number, the result will be RANDOM. REMARK If expression is the same, the same random pattern will be repeated with all versions of ZBasic. IIJ!!~l .•The [IZEI part of RANDOM is not supported on the Apple II and Z80 versions. 309 Standard Reference statement RATIO FORMAT RATIO byte expression 1, byte expression2 DEFINITION This statement will change the aspect ratio of graphics created with CIRCLE. byte expression1 Horizontal ratio. A number between -128 and +127 that gives the relationship of the width of the circle to normal (zero). byte expression2 Vertical ratio. A number between -128 and + 127 that gives the relationship of the height of the circle to normal (zero). ~ +127 +64 +32 o -32 -64 -96 -128 Relationship to normal 2.0 times normal 1.5 times normal 1.25 times normal o Normal proportion 0.75 times normal times normal 0.5 0.25 times normal o times normal (no width or height) EXAMPLE RATIO 0,0 ~ ~ 767 RATIO -50, 127 CIRCLE h,v,r REMARK RATIO settings are executed immediately and all CIRCLE commands, including CIRCLE TO and CIRCLE PLOT will be adjusted to the last RATIO. & Also see ROUNDRECT toolbox routines for other options to creating circles with various rations. Standard Reference 310 READ# statement FORMAT READ # filenumber, {var Ivar $ ; stringlength } [, ... I DEFINITION Reads strings or numbers saved in compressed format with WRITE# and stores them into corresponding variables. The list may consist of any type string or numeric variables or array variables. filenumber vcr var$ ; stringlength The filenumber to work from Any numeric type variable String variable The number of characters to load into the string variable Imponant Note: A string variable must be followed by ;stringlength to specify the number of characters to be read into that string. EXAMPLE REM The four variables below will require 18 bytes for storage REM A$=4 bytes, A!= 4 bytes, A#=8 bytes, A%=2 bytes A$="TEST": A!="12345.6":A#="12345.67898":A%=20000 OPEN"O",l, "DATAFILE" , 18 WRITE #1, A$;4, A!, A#, A% CLOSE#1 OPEN"I" ,1,"DATAFILE", 18 READ #1 , Z$; 4, Z!, Zit, Z% CLOSE# 1 <--- Wr~e a file with a record length of 18 <---Read in same order and type (see notes) PRINT Z$, Z!, Z#, Z% END RUN TEST REMARK 12345.6 12345.67898 20000 Note: Do not mix variable types when using READ# and WRITE#. Reading string data into numeric variables, and visa-versa, will create variables with incoherent data. READ# and WRITE# store and retrieve numeric data in a compressed format. This saves disk space and speeds program execution. While you may load numeric data into strings and convert using CVB or CVI, ~ is best to refrain from this since it requires more time and is less efficient. See the chapter "Files" for more detailed information using random and sequential files. Also see RECORD, LOC, REC, LOF and "Disk Error Trapping". 311 Standard Reference statement READ FORMAT READ [variable (-or- PSTR$( vat'lo) } [ , ...]] DEFINITION The READ statement reads strings or numbers from a DATA statement into corresponding variables. The variable list can consist 01 any combination of variable types (string or numeric, including arrays). II no variable is given the READ statement will skip one DATA item. EXAMPLE DIM P% (3) DATA Joe, Smith, Harry, "@ Cost" DATA 1234.5, 567.8, 91011.12, 1314.15 READ A$, B$, C$, D$ READ A!, B!, e!, D! PRINT A$, B$, C$, D$ PRINT A!, B!, C!, D! <--- Regular old fashioned READ RESTORE <--- Set pointer back to start 01 DATA to READ again FOR X=O TO 3 READ PSTR$ (P% (X) ) <---Use pOinter string to point at DATA string constants NEXT:PRINT PRINT "PSTR$>"; FOR X= 0 TO 3 PRINT PSTR$(P%(X», NEXT <--- Set DATA pointer to the sixth item RESTORE READ A# PRINT A# END RUN Joe 1234.5 Smith 567.8 PSTR$> Joe Harry 91011.12 Smith @ Cost 1314.15 Harry @ Cost 567.8 REMARK Leading spaces in string data statements will be ignored unless contained in quotes. Do not read numeric data into string variables and vice versa (no error is generated). Don't read past the end of a data list. See RESTORE, PSTR$ and DATA. Standard Reference 312 RECORD statement 1#] filenumber, I, FORMAT RECORD DEFINITION The RECORD statement is used to position the file pointer anywhere in a file. Once the file pointer has been posHioned you may read or wrHe data from that position. recordnumber location in record ] RECORD can position both the RECORD pointer and the location within a record. EXAMPLE filenumber Filenumber from 1 to 99 recordnumber RECORD number to point to. Default is zero. location in record Optional location in RECORD. Default is zero. OPEN"R",1,"TESTFILE",30 FOR position = 0 to 29 RECORD #1, 6, position READ#!, A$; 1 <--- Reads one character at a time from record 6. PRINT A$; NEXT CLOSEn END RUN Fred Stein See illustration next page ... REMARK The default RECORD length is 256 by1es. The maximum record length is 65,535. The maximum number of records in a file is 65,535. See OPEN, READ#, WRITE#, PRINT#, INPUT#, LlNEINPUT#, LOC, LOF, REC, CLOSE, and the chapter entitled "Files". l!l The maximum record length and number of records in a file is 2,147,483,647. 313 Standard Reference statement RECORD RECORD continued FILE STRUCTURE OPEN "R", 1, "TESTFILE", 30 up to 65,535 RECORD(s) In a ZBaslc file. b-:;::;;::;:~;:;:~~~~~~,i,:+:;::;::;::~::;::~~ Up to 65,535 LOCATION(s) In L...L...L..JL....L...L..JL....I....L..JL....I.....L...I....L..1...J....L..L..l....l......L...I....I.....L..l....L..L..l....L...I a ZBaslc RECORD. o1 II>- 2 34 5 6... ... 29 ' T h e "d" Is at LOCATION 3 In RECORD 6 In the illustration, the name "Fred Stein" was stored in RECORD six of "TESTFILE". To point to FILE #1, RECORD 6, LOCATION 3 use the syntax: RECORD# 1, 6, 3 The location within a record is optional (zero is assumed if no location is given). If RECORD 1, 6 had been used (without the 3), the pointer would have been positioned at the "F" in "Fred". If RECORD is not used, reading or writing starts from the current pOinter position. If a file has just been opened, the pOinter is positioned at the beginning. After each read or write, the file pointer is moved to the next position in the file. !l The maximum record length and number of records in a file for this versions is 2,147,483,647. Standard Reference 314 REC function FORMAT REC ( filenumber) DEFINITION Returns the current position of the record pointer for the file specified by expression. The first record in a file is record zero (0). Also often used with REC is LOC which returns the poSition within the record. EXAMPLE OPEN "0",1, "THISPROG", 10 <--- Record length of ten A$="01234S" <--- String length of six FOR I = 0 TO 3 PRINTU, A$; PRINT "On pass";I;" file position was ". PRINT "REC="REC(l);" and LOC=";LOC(l) NEXT I RECORD #1, 0, 4 <--- Position the file pointer with RECORD PRINT "Right after the middle RECORD statement; ". PRINT "REC="REC(l);" and LOC=";LOC(l) CLOSEU END RUN On On On On Pass Pass Pass Pass 0 file position was REC=O and LOC=6 1 file position was REC=l and LOC=2 2 file position was REC=l and LOC=8 3 file position was REC=2 and LOC=4 Right after the middle RECORD statement; REC=O and LOC=4 REMARK The default record length is 256 bytes. LOC returns the position within a RECORD. See OPEN, CLOSE, LOC, LOF, RECORD, READ#, WRITE# and the chapter entitled "Files". 315 Standard Reference statement REM FORMAT REM fol/owed by programming remarks DEFINITION The REM statement is used for inserting comments or remarks into a program. ZBasic ignores everything following a REM statement. To save time, you can type an apostrophe (') at the beginning of a line and it will be converted into a REM statement. EXAMPLE REM REM REM This is a comment or remark ZBasic ignores everything following a REM Including any commands enbedded in the remark REM Colons are often used to make blank lines. REM Thoughful use of REM makes a program easier to read. RUN ZBasic Ready_ REMARK REM statements are not compiled and do not take up any memory in the object code. Note: Some versions of ZBasic will not convert the apostrophe to REM. Standard Reference 316 RENAME statement I TO } string2 FORMAT RENAME string1 DEFINITION This statement is used to rename the Ii Ie string1 to the new name string2. EXAMPLE DrR GOOGOO FRE~BAS {, ZBASIC.COM OLDFILE.BAS INPUT "FILE NAME TO CHANGE: ";Filel$ INPUT "NEW NAME FOR FILE: ";File2$ RENAME Filel$ TO File2$ RUN FILE NAME TO CHANGE: GOOGOO NEW NAME FOR FILE: GOONIE DrR GOONIE FRED.BAS REMARK ZBASIC.COM OLDFILE.BAS This command is also available in command mode. Remember that filename lormats are different Irom system to system and may not be available lor some machines. JIII!l TRS-SO model 1,3: RENAME not supported with these versions. a ..... Macintosh: Pathnames or volume number may be used. Macintosh: RENAME lile1$ {TO I, } lile2$ [. volume number%]. Also see NAME. MSDOS: See CHOIR, PATH$, RMOIR and MKOIR in the MSOOS appendix lor controlling pathnames and directories. Also see NAME. Apple 1/ ProDOS: Pathnames supported. 317 Standard Reference command RENUM FORMAT RENUM [new] [, [old]] [, increment] DEFINITION Used for renumbering program lines. new okJ increment The first new assigned line number desired after renumbering is complete. default = 10 The first old line where you want renumbering to begin. default = 0 The increment between line numbers. default = 10 (256 maximum) If an argument is omitted the default will be used. This command will automatically update line references (GOTO, GOSUB, etc). If a line reference is to a non-existent line, it will use the next existing line number. EXAMPLE 7 IF I = 200 THEN 567 74 PRINT I 197 I I + 1: GOTO 74 567 END RENUM LIST 10 20 30 40 REMARK IF I 200 THAN 40 PRINT I I I + L: GOTO 10 END Line increments are limited to 256. If you issue a RENUM command that exceeds the number of allowable lines (65,534) , an error will occur and your text will be unaltered. If you are unsure of what the results may be, SAVE your program BEFORE renu mbering! aD Some versions offer options for using, or not using, line numbers with full screen editors. Check your appendix for specifics . • See RENUM*, UNNUM, INDENT and FIX in the MSDOS appendix for other options. Standard Reference 318 RESET statement ............................................................................."1. .................................................................................. .,..". .... ". .......... .,..". .... "'."' .... ".."' ....... ". ................ "' • .,.."'."' ................ rI' .... .,.."' • .,. .... "' • .,..".."'."' • .,.."..".."."."'.". • .,. • .,.."'. "-:"":"":"":"":"":"":""''''':'''':'''':'''':'''':''''''''':'''':'''':"'':'''':'''::''''':"''''''':"'':''''''''':'''':"":"":"":""''''':''''''''::''''':"'''"'':'''':'''':'''':"'':'''':''''''''':'''':'''':"''''''':"'':"''''''':'''':"'': FORMAT RESET DEFINITION Closes all open files and devices. Functionally identical to CLOSE without parameters. EXAMPLE OPEN"O", 1, FRED " OPEN"I",2,"HARRY" II IF ERROR THEN RESET END REMARK See CLOSE. a. Not supported on Apple /I or Z80 versions of ZBasic. Simply use CLOSE without a filenumber to close all open files. 319 Standard Reference statement RESTORE 1 FORMAT RESTORE [expression DEFINITION This statement resets the DATA pOinter to the first DATA statement or optionally to the DATA item specified by expression. If the expression is omitted, the first DATA item is assumed. ZBasic automatically sets the pointer to the next item after each variable is READ. EXAMPLE DATA ZERO, ONE, TWO, THREE, FOUR, FIVE DATA SIX, SEVEN, EIGHT, NINE, TEN tlStart U DO INPUT"What item do you want";Item% IF (item%10) THEN "Start" RESTORE Item% READ A$ PRINT "Item number"jltem%;n is: ";A$ UNTIL Item%=O RESTORE READ A$: PRINT A$ <--- Set to beginning of DATA END RUN What item do you want: 4 Item number 4 is: FOUR What item do you want: 9 Item number 4 is: NINE What item do you want: 0 Item number 0 is: ZERO ZERO REMARK If an attempt is made to READ or RESTORE past the last DATA item, the result will be zeros or NULL strings. No error will be returned. Also see READ, PSTR$ and DATA. Standard Reference 320 RETURN statement I FORMAT RETURN [line DEFINITION The RETURN statement is used to continue execution at the statement immediately following the last executed GOSUB or ON GOSUB statement. If optional line is used, the last GOSUB is POPPED off the stack and a GOTO line is performed. EXAMPLES GOSUB "First" "Second" PRINT "RETURN comes here." END "First" PRINT "This is a subroutine" RETURN RUN This is a subroutine Return comes here GOSUB "Routine" END "Weird" PRINT"Ended Here!" STOP "Routine" PRINT"At 'Routine'" RETURN "Weird" RUN At 'Routine' Ended Here! REMARK When ZBasic encounters a RETURN statement which was not called by a GOSUB, it will retum to the program that executed it (either DOS or the ZBasic editor). Using RETURN line WITHOUT A GOSUB or from the middle of a LONG FN will cause unpredictable (probably disastrous) system errors. & Use caution when using RETURN line to exit eveht trapping routines like DIALOG ON, MENU ON, TRON, BREAK ON ... 321 Standard Reference function RIGHT$ FORMAT RIGHT$( string, expression ) DEFINITION Returns the righi-most expression characters of string. EXAMPLE A$="HELLO" FOR I = PRINT NEXT I A$ a TO 6 I, RIGHT$(A$,I) "JOHN DOE" INSTR(l,A$," ") SP PRINT"LAST NAME:", PRINT RIGHT$(A$,LEN(A$)-SP) END RUN a 1 2 3 4 5 6 LAST NAME: REMARK a LO LLO ELLO HELLO HELLO DOE If expression is more than the characters available, all the characters will be returned. See LEFT$, VAL, STR$, STRING$, SPACE$, SPC, MID$ and the chapter entitled "String Variables" in the front section of this manual. Standard Reference 322 RND function FORMAT RND (expression ) DEFINITION The RND function returns a random integer number from 1 to expression. EXAMPLE RANDOM A=9 FOR I=l TO 5 PRINT RND (A) , PRINT RND(10000)*.0001 NEXT I END RUN 3 7 1 2 9 Remark .9201 .8211 .0912 .7821 .0108 Some versions of BASIC return a floating point random number between 0 and 1; use RND(10000} •. 0001 to emulate this (it will slow down execution). Also see MAYBE and RANDOM. If the same seed number is used for RANDOM, the random numbers generated by RND will be predictable on the all versions of ZBasic. The largest number you may use for a RND expression is 32,767. 323 Standard Reference statement ROUTE FORMAT ROUTE [#) expression DEFINITION This statement is used to route PRINT statements to a specified device. The following are the values to be used as expression. Device number negative numbers o 1-99 128 EXAMPLE ROUTE 128 PRINT "HELLO" OPEN 11 0",1, "Test " ROUTE 1 PRINT "HELLO" CLOSE#l OPEN"C",-1,300 ROUTE -1 PRINT "HELLO" CLOSE#-l ROUTE a PRINT"HELLO" END Routes PRINT statements to I/O devices; See your appendix for specifics Screen (default) Disk files specified by number Printer <--- This HELLO goes to the printer <--- This HELLO goes to the file "Test" <--- This HELLO goes to a serial device <--- This HELLO goes to the screen RUN HELLO REMARK You should eventually route the output back to a screen device (ROUTE 0 ). See PRINT, OPEN"C" and the chapter "Files" for more information. ~ Also see ROUTE 128, CLEAR LPRINT, DEF LPRINT and DEF PAGE for more information about routing text and graphic output to the Imagewriter and Laserwriter. Be sure to use CLEAR LPRINT with ROUTE 128 to tell the Macintosh printer driver to print the page. Standard Reference 324 RUN statement 1 FORMAT RUN [ filenumber DEFINITION The RUN statement does one of two things. RUN filenumber Loads a compiled chain program specified by filenumber and executes it: OPEN"I", 1, "Prog.CHN" RUN 1 RUN EXAMPLE REMARK Clears all variables and pointers and restarts the current program from the first line. OPEN"I",2,"MENU" RUN 2 <---Loads and RUNS CHAIN program "MENU" TRONB FOR X=l TO 100 PRINT X NEXT RUN <--- RUNS this program over and over... Also see the RUN command and the chapters "Running ZBasic Programs" and "Chaining" for more information. !L Also see RUN filename$, volumenumber"/O in the appendix. 325 Standard Reference command RUN FORMATS RUN [[(+ I * DEFINITION This command is used from the Standard Line Editor to compile a program: EXAMPLE })[ "1 filename [" II RUN Compiles source code in memory and executes. RUN filename Compiles source code called filename from disk and executes. Source code must have been saved in tokenized format with SAVE (not as a text file). RUN* Compiles source code in memory and saves as a stand-alone application on disk. Asks for filename after compiling. RUN* filename Compiles source code called filename from disk and saves as a stand-alone application on disk. Source code must have been saved tokenized (not as a text file). Asks for filename after compiling. RUN+ Compiles source code in memory and saves as a chain file to disk (no runtime included). Asks for filename after compiling. RUN+filename Compiles source code called filename from disk and saves as a chain file to disk (no runtime included). Asks for filename after compiling. PRINT "THE PROGRAM RUNS!" RUN THE PROGRAM RUNS! REMARK Compiling from disk will destroy any text currently in memory. If an error is encountered when compiling from disk, ZBasic will load the source code and print an error message. After a successful compilation, typing MEM will return memory used for the object code and variables. See "Executing Programs" in the front of this manual for more information about compiling large programs. !b. Also see COMPILE and LCOMPILE for ways of compiling a program and seeing all the compile time errors at once (instead of one at a time as wtth RUN). Standard Reference 326 SAVE command FORMAT SAVE [[ {* I +J] ["] filename ["II DEFINITION SAVE is used from the Standard Line Editor to save the source code in memory. You may save your source code in a number of formats: SAVE Saves program in tokenized format. This requires less room on the disk and saving and loading is much faster than with text files. In order to compile a file from disk a program must be saved in this format. SAVE* Saves program in TEXT or ASCII format. This allows you to load the program into other word processors or editors. Loads more slowly than SAVE above. SAVE+ Same as SAVE" but line numbers are removed. Be sure your program doesn't uses label references with GOTO, GOSUB or other commands, since when a program is re-Ioaded, line numbers are added back in increments of one which will make line number references incorrect. Note: Source code is the program you type in. Object code is the machine language program created when you compile the source code with RUN. See RUN for more information about compiling and saving compiled programs to disk. 327 <---SAVE program in ASCII (text) <---SAVE program tokenized (condensed) <---SAVE program in ASCII- with no line numbers EXAMPLE SAVE* PROGRAM. TXT SAVE AR.BAS SAVE+ FILE.TXT REMARK Also see LOAD, APPEND, MERGE and RUN. Standard Reference statement SELECT ............................................................................... "" ........................................................................... ."..". .... ". ....".."'."' .......... ". .... ". .... ". ...."'."'.".."'."..1'.". ....... "..". .......... "..".."'.".."."........ "'.".". ....... ". ...."'."."..".".".". "'"":""'"":""'"":""'""'""'"":"":"":""'""'""'""'"":""'"":""'"":""'"":"":""'""'""'" ":''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':''':~'':''':''':',,:' FORMAT SELECT [expression or simplestring] CASE [IS] relational condition [, relational condition] statements ... CASE [IS] condition L condition ]L ...] statements ... CASE [IS] boolean expression statements ... CASE ELSE END SELECT DEFINITION Provides a structured and efficient way of doing multiple comparisons with a single expression. While IF-THEN or LONG-IF statements could be used, they are harder to follow when reading program listings. EXAMPLE X=CARDTYPE:REM MSDOS Cardtype example. SELECT X CASE 0 PRINT"CGA CARD":MODE 7 CASE 1 PRINT"EGA CARD":MODE 19 CASE 2 PRINT"EGA with Mono": MODE 18 CASE 3 PRINT"HERCULES CARD":MODE 20 CASE 255 PRINT "Monochrome Monitor":MODE 2 CASE ELSE PRINT"No Video card installed" END SELECT REMARK See CASE and END SELECT for more examples. I. ... ] Important Note: Exit a SELECT structure only at the END SELECT. lI!al!l SELECT is not supported with the Apple or Z80 versions of ZBasic. Use IF-THEN or LONG-IF to accomplish the same thing. Standard Reference 328 SGN function FORMAT SGN ( expression ) DEFINITION Returns the sign of expression. If expression is: positive Zero Negative EXAMPLE +1 is returned. o is returned. -1 is returned. DEFDBL A-Z: DEFTAB 8: WIDTH 40 X","ABS(X)" ... INT(X) ..... FRAC(X) .. ,SGN(X) .. PRINT" FOR X = PRINT PRINT PRINT PRINT PRINT NEXT X -15.0 TO +15.0 STEP 3.75 USING"-"."";X. USING ""."";ABS(X), USING"-II.I''';INT(X), USING "-'."";FRAC(X). USING "-'."";SGN(X) RUN X ABS (X) INT(X) -15.00 -11.25 7.50 - 3.75 .00 3.75 7.50 11.25 15.00 15.00 11.25 7.50 3.75 .00 3.75 7.50 11.25 15.00 -15.00 -11.00 - 7.00 3.00 .00 3.00 7.00 11. 00 15.00 - REMARK 329 Standard Reference - FRAC(X) .00 -.25 -.50 -.75 .00 .75 .50 .25 .00 Also see UNS$, FRAC, INT, ABS and negation. SGN(X) -1. 00 -1. 00 -1. 00 -1. 00 .00 1.00 1. 00 1. 00 1. 00 f' " ' • " function SIN FORMAT SIN ( expression ) DEFINITION The SIN function returns the sine of the expression in radians, SIN(A)=Y/H, H*SIN(A)=Y, Y/SIN(A)=H EXAMPLE X#=SIN(123) PRINT SIN(X2#) REMARK SIN is a scientific function, The precision for scientific functions may be configured, See "Configure" in the front of this manual for more information, See the "Math" and "Expressions" sections of this manual and ATN, TAN, COS, EXP,SQR, A, INTEGER SINE: ZBasic provides a predefined USR function to do hi-speed integer sines, This speeds up sine speed by up to 30 times: USR8(angle ) returns the integer sine of angle in the range ±255 (corresponding to ±1), The angle must be in brads, See CIRCLE for examples of brads, Example: MODE? :CLS FOR I=O TO 255 PLOT I«2,-USR8(I)+384 NEXT I Standard Reference 330 SOUND statement FORMAT SOUND frequency, duration DEFINITION SOUND may be used to create sound effects or music. frequency duration Frequency 120 Hz to 10,000 Hz. Duration in 1 millisecond increments. Note: Hz (Hertz) represents cycles-per-second. EXAMPLE DO INPUT"Tone: niTone INPUT"Duration: "iDuration SOUND Tone, Duration UNTIL (Tone=O) OR (Duration=O) Example frequencies you may use in your program to create music or sound effects. (Choose the duration as required.) Quality of sound may vary by machine. OCTAVES NOTES C cb D Eb E F Gb G Ab A Bb B REMARK 1 33 35 37 39 41 44 46 49 52 55 57 61 2 66 70 74 79 82 88 93 99 105 110 115 123 3 132 140 148 158 165 176 187 198 211 220 231 247 4 264 281 297 316 330 352 375 396 422 440 462 495 5 528 563 594 633 660 704 751 792 844 880 924 990 6 1056 1126 1188 1267 1320 l408 1502 1584 1689 1760 1848 1980 7 2112 2253 2376 2534 2640 2816 3004 3168 3379 3520 3696 3960 Some computers may not have sound. See your computer appendix for more information. LII'!l CP/M-SO: Sound not supported. CHR$(7) may sound a bell on some sytems. TRS-SO model 1,3: Requires that a speaker be connected to the cassette port. TRS-SO Model 4: Frequency range of internal speaker limited to 0,0 to 7,31. !l See appendix for using four voice sound and utilizing the sound buffer. 331 Standard Reference function SPACE$ FORMAT SPACE$ ( expression DEFINITION Returns a string of spaces expression characters long (range of 0 to 255). EXAMPLE PRINT "ZEDCORZEDCORZE" FOR X=7 TO 0 STEP -1 PRINT SPACE$(X);"ZEDCOR" NEXT PRINT"ZEDCORZEDCORZEDCOR" END RUN ZEDCORZEDCORZE ZEDCOR ZEDCOR ZED COR ZED COR ZED COR ZED COR ZEDCOR ZEDCOR ZEDCORZEDCORZEDCOR REMARK See STRING$, MID$, RIGHT$, LEFT$, INSTR and SPC. Standard Reference 332 SPC function FUNCTION SPC (expression ) DEFINITION SPC prints expression spaces from 0 to 255. Prints the number of spaces specified by expression. EXAMPLE DO PRINT"*";SPC(RND(20»;"+" UNTIL LEN(INKEY$) RUN + + + + + + REMARK 333 Standard Reference Also see SPACE$, LEFT$, STRING$, RIGHT$, MID$ and INSTR. function SQR FORMAT SQR (expression ) DEFINITION The SQR function returns the square root of expression. H=SQR(X'X+ Y'Y) EXAMPLE A=9 PRINT SQR (A) RUN 3 REMARK SQR is a scientific function. Scientific functions may be configured to a different precision. See "Configure" in the front of this manual for more information. For more information on scientific functions see the "Math" and "Expression" sections of this manual and ATN, SIN, COS, TAN, EXP and A • Standard Reference 334 STEP statement FORMAT FOR variable = NEXT [variable expr1 TO expr2 [STEP expr3 J J[ ,variable. .. J DEFINITION This parameter allows you to set the increments used in a FOR-NEXT loop. If STEP is omitted than one is assumed. EXAMPLE FOR X= 0 TO 10 STEP 2 PRINT X; NEXT FOR X = 10 TO 0 STEP -1 PRINT X; NEXT END RUN o 2 4 6 8 10 10 9 8 7 6 5 4 3 2 1 0 REMARK Also see FOR, NEXT, DO, UNTIL, WHILE, WEND and the chapter on "Loops". IF STEP =0 an endless loop will result. If expr1 or expr3 change while the loop is executed this change will be in effect when NEXT is encountered. Avoid long or complex loop expressions for expr1 or expr3 as they are evaluated every loop and will slow execution. 335 Standard Reference statement STOP FORMAT STOP DEFINITION STOP halts execution of a ZBasic program and prints the line number where execution stopped (if line numbers weren't used the lines are numbered in increments of one). STOP when used from ZBasic will return to the Standard Line Editor. STOP when used from a stand-alone program will return to the operating system. EXAMPLE PRINT"HELLO" STOP RUN Break in 00002 zBasic Ready REMARK STOP closes all files. END may be used when no message is desired. See TRONB and TRONX for ways of inserting break pOints in your programs so that may be used to exit a running a program. Standard Reference 336 STR$ function FORMAT STR$ (expression ) DEFINITION STR$ returns the string equivalent of the number represented by expression. This is used to convert numbers or numeric variables to a string. This function is the compliment of VAL. VAL returns the numeric value contained in a string. EXAMPLE Integer% =20000 Single! =232.123 Double# = .12323295342 A$=STR$(Integer%) A$=STR$(Single!) A$=STR$ (Double#) :PRINT A$ :PRINT A$ :PRINT A$ X#=VAL(A$) PRINT X# RUN 20000 232.123 .12323295342 .12323295342 REMARK 337 Standard Reference Also see BIN$, OCT$, HEX$, MKI$, CVI, MKB$, CVB ljnd VAL. function STRING$ FORMAT STRING$ ( expr 1 ' string ) STRING$ ( expr1 , expr2 ) DEFINITION Relurns a string of the length expr1 consisting of the characters specified by either the ASCII equivalent of expr2 or the first character of string. EXAMPLE PRINT STRING$ (5,"'") PRINT STRING$ (10,65) PRINT STRING$ (10,CHR$(65» A$ = STRING$(3,"*") + "TEST"+ STRING$(3,"&") PRINT A$ END RUN H.H AAAAAAAAAA AAAAAAAAAA ***TEST&&& REMARK STRING$ is more efficient than using an equivalent string of characters. See SPACE$, LEFT$, RIGHT$, MID$,INSTR, VAL, STR$,INDEX$ and SPC. Standard Reference 338 SYSTEM statement .............................................................................................................................................................. .......................................". ....... rI" ..................................... "' ..................................... "' .... " .... "'."' ............... . "":""'"":"":""'"":""'""'""'""'""'""'""'""'"":"":"":""'"":""'"":"":""'""'""'"":'"'"""'""'""'""'"":"":"":"":"":""'"":""'""'"":""'"":""'""'"":"":"":"":"":"":"":"": FORMAT SYSTEM DEFINITION Same as END. Provided for compatibility wnh other versions of BASIC. EXAMPLE PRINT"HELLO" SYSTEM RUN HELLO REMARK Functionally identical to the ZBasic END statement. See END and STOP. •.J!!!l Not Supported with Apple /I or 339 Standard Reference zao versions of ZBasic. Use END. statement SWAP FORMAT SWAP var1 DEFINITION SWAP exchanges the contents of var1 and var2. The variables can be of any type exceptlNDEX$ variables. I var2 Var1 and var2 must be of the same type. EXAMPLE B$="YES" A$="NO" PRINT A$, B$ SWAP A$, B$ PRINT A$, B$ PRINT A=1:B=100 PRINT A,B SWAP A,B PRINT A,B END RUN YES NO REMARK NO YES 1 100 100 1 SWAP will execute faster and take less memory than similar methods using "holding variables" . SWAP does not function with INDEX$. Standard Reference 340 TAB function FORMAT TAB ( expression) DEFINITION Tab will move the cursor to the posijions; 0 through 255, designated by expression. Three devices may be used wnh Tab: DEVICE SCREEN PRINTER DISK EXAMPLE fQ.B.MPRINT LPRINT PRINT# WILL POSITION CURSOR PRINT HEAD FILE POINTER DATA Fred Smith, 12 E. First, Tucson, AZ, 85712 DATA Dana Andrews, 32 Main, LA, CA, 90231 PRINT "Name " TAB (15) "Address"TAB(30) "City"TAB(40) "State PRINT STRING$(50,"-") FOR Item= 0 TO 1 RESTORE Item*5 READ N$, A$, C$, S$, Z$ PRINT N$ TAB(15) A$ TAB(30) C$ TAB(40) S$" NEXT END ZIP" "Z$ RUN REMARK 341 Standard Reference Name Address City State ZIP Fred Smith Dana Andrews 12 E. First 32 Main Tucson LA AZ CA 85712 90231 Tab will start numbering from the zero poSition. Also see DEFTAB, PRINT@, PRINT%, pas, PAGE, WIDTH and WIDTH LPRINT. function TAN FORMAT TAN (expression) DEFINITION Returns the value of the tangent of the expression in radians. TAN(A)=Y/X, X=Y/TAN(A), Y=TAN(A)*X EXAMPLE Xjf=TAN(T+Z)/3 REMARK TAN is a scientific function. Scientific accuracy may be configured differently than single or double precision. See "Configure" at the beginning of this manual. Also see ATN, COS, SIN, EXP, SOR and A. For more information on scientific functions see "Math" and "Expressions" in the front section of this manual. Standard Reference 342 TIME$ function FORMAT TIME$ DEFINITION Returns an eight character string which represents the systems clock value in the format HH:MM:SS where HH=1 to 24 hours, MM= 0 to 60 minutes, SS= 0 to 60 seconds. EXAMPLE PRINT TIME$ DELAY 1000 A$=TIME$ PRINT A$ RUN 10:23:32 10:23:33 REMARK See DATE$ and DELAY. This function will return a 00:00:00 if the system or version has no clock. )-"l -- Macintosh: Set time from the Control Panel Desk Accessory. Also see TIMER for other ways of getting seconds. MSDOS: Set time using TIME$= hh, mm, ss. Also see TIMER. Apple: See appendix for variations of system clocks. zao: See appendix for your particular hardware. 343 Standard Reference statement TROFF FORMAT TROFF DEFINITION TROFF is used to tum off the trace statements: TRON, TRONX, TRON and TRONS. EXAMPLE TRON FOR X=l TO 3 NEXT TROFF PRINT "Line tracing now off" FOR X=l TO 10 NEXT RUN 00001 00002 00003 00002 00003 00002 00003 00004 Line tracing now off REMARK See also TRON, TRONS, TRONB, TRONX and the chapter on "Debugging Tools". Standard Reference 344 ---- TRON statement FORMAT DEFINITION TRON[ {B I S I X} 1 These statements are used for tracing program execution, single stepping through a program, and setting break points for monitoring the key so that you can break out of a program. TRACING PROGRAM FLOW TRON Prints the line numbers of the program as each line is executed so you can trace program flow and check for errors. TRON S lets you single step through a program. Program execution will pause at the beginning of every line in the program following TRON S (up to the end of the program or when a TROFF is encountered). Press any key to continue or press the key to enable/disable single-stepping. also works. SETTING BREAK POINTS TRON X Sets a break point at that line in a program and checks to see if the key has been pressed. TRON B Sets a break point at the beginning of every line in the program following it (up to the END or until a TROFF is encountered). Note: The key is checked at the beginning of a line. IF is encountered in a program compiled with RUN, program exits to the Standard Line Editor. If is encountered in a stand-alone program, exit is to the system. will pause execution when encountered during execution of TRONB, TRONX or TRON. Any key will restart. will activate/deactivate singlestep mode when any TRON is active. Note: INKEY$ may lose keys if TRON is used. EXAMPLE TRON:TRONS PRINT "HELLO" TROFF RUN 00001 00002 00003 HELLO 00004 REMARK Every line between a TRON and TROFF may use up to eight extra bytes per line. Use TRON sparingly to save memory and increase execution speed. See chapter entitled "Debugging Tools" for more information. INKEY$ may lose keys with TRON. MacIntosh: is . Also see BREAK ON, and TRON WINDOW in appendix for other ways of tracing program flow and variable values. MSDOS: is . CP/M: is . Apple" ProDOS or DOS 3.3: is or . TRS·aO: is . 345 Standard Reference function UCASE$ . ., , f' - ~ FORMAT UCASE$ (string ) DEFINITION Returns a string with all characters converted to uppercase (capital letters). EXAMPLE PRINT UCASE$ ("hello") A$=IIHeLLo n PRINT UCASE$ (A$) END RUN HELLO HELLO DO key$=UCASE$(INKEY$) UNTIL LEN (key$) PRINT keyS END RUN S <---always returns an uppercase character REM This function converts a string to Lowercase LONG FN lcase$(string$) FOR X=l TO LEN(string$) A=PEEK(VARPTR(string$)+X) IF (A>64) AND (A<91) THEN A=A+32 POKEVARPTR(string$)+X,A NEXT END FN=string$ PRINT FN lcase$("HELLO") RUN hello REMARK This function is very useful when sorting data containing upper and lower case and for checking user input without regard to case. Also see LEFT$, RIGHT$, MID$, INSTR, STR$, VAL, and the chapter "String Variables" in this manual. Standard Reference 346 UNS$ function FORMAT UNS$ (expression ) DEFINITION Returns a string which equals the integer value of expression in an unsigned decimal format. EXAMPLE PRINT UNS$ (-1) PRINT UNS$ (4) PRINT PRINT 65535 RUN 65535 00004 -1 REMARK This function is useful for displaying integers in an unsigned format (0 through 65,535 instead of -32,768 through 32,767). See STR$, DEC$, OCT$, HEX$, VAL and the chapter on "Numeric Conversions". !b See DEFSTR LONG for enabling this function to work with Longlntegers. 347 Standard Reference statement UNTIL FORMAT DO UNTIL expression DEFINITION UNTIL is used to mark the end of a DO loop. The DO loop repeats until the expression following the UNTIL is true (non-zero). A DO loop will always execute at least once. EXAMPLE DO X=X+l UNTIL X=100 PRINT X "Wait for a key" DO I$=INKEY$ UNTIL LEN (I$) END RUN 100 REMARK Notice ZBasic will automatically indent DO loop structures fwo spaces. See the chapter on "Formatting Program Listings" for other ways of formatting listings. Also see FOR, NEXT, STEP, WHILE, WEND and the chapter on "Loops" in the technical section of the manual. WHILE,WEND may be used to exit a loop immediately if a condition is false. Standard Reference 348 USR function FORMAT USR digit (word expression) DEFINITION The USR function calls the user created subroutine, defined wHh DEFUSR, specified by a digit 0 to 9, and retums the value of integer expression in the 16 bit accumulator. EXAMPLE REM EXAMPLE ONLY DO NOT USE! DEFUSR2 = LINE "Routine two" X=USR2 (938) PRINT X END "Routine two" MACHLG &8B,&C4,&C3:RETURN RUN 23921 REMARK A machine language retum is necessary at the end of a USR routine. ZBasic provides pre-defined USR functions that perform some powerful functions like integer sine and cosine. See next page. && Macintosh: Be sure to use Longlntegers whenever referencing memory addresses. Also see CALL in the Macintosh appendix. MSDOS: See CALL in your appendix. Apple ProDOS: See MLI in the ProDOS appendix. 349 Standard Reference functions PRE-DEFINED USR Predefined USR functions These pre-defined USR functions are available for ali versions of Z8asic. See your Computer Appendix for possible other USR functions. USR6(expr) Retums the last line number executed that used any of the TRON functions (expr is not used). TRONX I=USR6 (0) PRINT I USR7(expr) Returns Z8asic's random number seed used in the RND function (expr is not used). FOR I=l TO 10 PRINT USR7(0) NEXT I USR8(angle ) Returns the integer sine of angle in the range ±255 (corresponding to ±1). The angle must be in brads. MODE7 :CLS FOR I=O TO 255 PLOT I«2,-USR8(I)+384 NEXT I USR9(angle ) Returns the integer cosine of angle in the range ±255 (corresponding to ±1). The angle must be in brads. MODE7 :CLS FOR I=O TO 255 PLOT I«2,-USR9(I)+384 NEXT I Standard Reference 350 USR statement FORMAT USR digit ( expression) DEFINITION This statement will call the USR routine defined by DEFUSRdigit and transfer the result of expression in the integer accumulator. EXAMPLE Example only DO NOT USE DEFUSRO=LINE "Machine language" USRO (0) END "Machine Language" MACHLG &39, &C9: RETURN REMARK The USR routine must be set by the program or be a predefined USR routine. Also see DEFUSR, USR function, LINE, CALL, MACHLG, the chapter about "Machine Language" in this manual, and your computer appendix. l!w&. Macintosh: Be sure to use longlntegers whenever referencing memory addresses. Also see CAll in the MAcintosh appendix. MSDOS: See CAll in your appendix. Apple ProDOS: See MLI in the ProDOS appendix. 351 Standard Reference function VAL FORMAT VAL (string) DEFINITION Returns the numeric numeric value of the first number in a string. The VAL function will terminate conversion at the first non-numeric character in string. This function is the compliment of STR$. STR$ will convert a numeric expression to a string. EXAMPLE A$="HELLO" B$="1234.56 C$="99999" PRINT "The value of A$="; VAL (A$) PRINT "The value of B$=";VAL(B$) PRINT "The value of C$=";VAL(C$) PRINT PRINT "The value of 9876.543=";VAL("9876.543") END RUN The value of A$= 0 The value of B$= 1234.56 The value of C$= 99999 The value of 9876.543= 9876.543 REMARK The numeric value returned by VAL will be in floating point forrnat See STR$, UNS$, HEX$, OCT$ and BIN$, INT, FRAC, ABS, FIX. Also see the chapter on "Math" and "Expressions" in the front section of this manual. Standard Reference 352 VARPTR function FORMAT VARPTR ( variable) DEFINITION Retums the address of a variable . Any variable type may be used except INDEX$. EXAMPLE A$="HELLO" PRINT "Address of A$=";VARPTR(A$) PRINT "Length of A$ =";PEEK(VARPTR(A$» PRINT "Contents of A$= "; FOR X=l TO LEN(A$) PRINT CHR$(PEEK(VARPTR(A$)+X»; NEXT END RUN Address of A$= 23456 Length of A$ = 5 Content of A$= HELLO REMARK The following paragraphs describe which address VARPTR will be pointing to with different variable types. INTEGER Points to the 1st byte of an integer variable SNG/DBL Points to the sign/exponent byte STRING Points to the length byte ARRAY Points to the element specified See the sections in the front of this manaul for the variable type you interested in to see how variables are stored in memory. && Macintosh: Be sure to use Longlntegers to store addresses. MSDOS: var=VARPTR(var) retums two values: The address of varand the segment of var in a special variable called VARSEG. See appendix for details. 353 Standard Reference statement WEND FORMAT WHILE expression WEND DEFINITION This statement is used to terminate a WHILE loop. When expression becomes false the loop will exit at the first statement following the WEND. EXAMPLE "Get a YES Answer and nothing else!" INPUT"What is your answer :";A$ WHILE A$ <>"Y" INPUT"Please reconsider and say :";A$ WEND PRINT"Thank you for seeing things my way ..... program continues .... RUN What is your answer : N Please reconsider and say : Y Thank you for seeing things my way ... WHILE X*X <23000 PRINT X*X, X=X+l WEND END RUN o REMARK 1 4 9 16 ... ZBasic will automatically indent all lines two spaces between WHILE and WEND when you use LIST. This makes programs much easier to read. Also see FOR, NEXT, STEP, DO, UNTIL and the chapters on "Loops" and "Structure" in the front of this manual. A structure error will occur if a WHILE exists without a matching WEND. To find a missing WEND, LIST the program and track back from the last indent. Standard Reference 354 WHILE statement FORMAT WHILE expression WEND DEFINITION In a WHILE statement, expression is tested for true before the loop is executed and will exit to the statement immediately following the matching WEND when expression becomes false. EXAMPLE "GET A KEY" WHILE LEN(Key$)=O Key$=INKEY$ WEND PRINT Key$ END RUN WHILE X 23 Integer numbers ~ I lilTI • 45 ~ • 17 ~ .. 101 ~ 01 ml- I-I iii HI a I r I r I y 1- I-I § IGI i II I d I a 1- I-I§ I Kia I tI hE 1-1-1 ~ Represents the Length Byte (stored as LB$ in the example) Standard Reference 358 XELSE statement FORMAT LONGIF expression XELSE ENDIF DEFINITION This statement is used to separate the FALSE from the TRUE section of a LONG IF structure. The statements following the XELSE will only be executed if the statement following the LONG IF is false. EXAMPLE LONGIF 10 = 0 PRINT"TRUE" XELSE PRINT"FALSE" ENDIF END RUN FALSE REMARK All program lines between the LONG IF and XELSE are indented two characters when using LIST. This makes a program easier to read. A structure error will occur the XELSE does not have a matching LONG IF. 359 Standard Reference FORMAT expression 1 XOR expression2 DEFINITION Provides a means of doing a logical EXCLUSIVE OR on two expressions for IFTHEN testing and BINARY operations. This operator will return true if one condition is true and one condition is false. False will be returned if both conditions are true or both conditions are false. EXAMPLE A$="Hello U IF A$="Hello" XOR A$="Goodbye" PRINT "YES" IF A$="Hello" XOR A$="Hello" PRINT "YES" RUN YES REMARK XOR TRUTH TABLES condition XOR condition XQB 1 XOR 0 XOR 1 XOR 0 XOR 1 1 0 0 0 1 1 0 FALSE TRUE FALSE TRUE XOR XOR XOR XOR FALSE FALSE TRUE TRUE TRUE(-l) if only one condition is TRUE, else FALSE(0) BQOLEAN "16 BIT" LOGIC 00000001 10000101 XOR XOR fZlfZlfZlfZlllll lfZlfZlfZlfZllll 00000010 00001110 FALSE TRUE TRUE FALSE Standard Reference 360 MSDOS APPENDIX 4 .; liUW£ A-1 MSDOSTMAppendix gwww; MSDOS APPENDIX TM ASIC II ZBasic MSDOSTM Version 4.0 For MSDOSTM, PCDOSTM and IBM® PC and compatible computers Original code by Scott Terry 4.0 Enhancements by Halbert P. Liang © Copyright 1985,1986,1987 ZEDCOR, Inc. All Rights Reserved MSDOSTM Appendix A-2 MSDOS APPENDIX TABLE OF CONTENTS A-3 Getting Started A5 Enhancements to 3.02 Files Included On Master Diskette Special Notes Loading Old 3.02 programs Pathnames Note to Tandy 2000 Note to Zenith Z-150 Additions to The Standard Line Editor Optional Keys Other Enhancements Graphic Enhancements EGA, CGA, MDPA Hercules Graphics A6 A7 A8 A8 A8 A8 A8 A9 A9 A9 A 10 A 10 A 10 Executing ZBaslc from MSDOS MSDOS Specific Configuration Options Memory Use With 4.0 Variables Notes on the Memory Map Memory Map RS-232 Communications Common Problems Cables Diagram Jump Tables List of Alterable USR functions Machine Language Examples Critical Error Handling Assembly Listing ZBasic Listing A11 A 12 A 14 A14 A 15 A 16 A17 A 17 A 18 A19 A21 A22 A23 A23 A24 Converting BASICA and QulckBASIC programs A25 Alphabetical Reference statement BLOAD BSAVE statement CALL statement statement CALL "DOS" function CARDTYPE CHDIR statement function CINT statement COLOR function COM BUFF statement COM ON function COMMAND$ CON FIG command statement DATE$ DEFMOUSE statement A28 A29 A30 A31 A32 A33 A34 A35 A36 A38 A40 A41 A43 A42 A43 MSDOSTM Appendix MSDOS APPENDIX -?.;":=il ' ~:~ ~ ,' .. . ..tJ. . . x' /'. TABLE OF CONTENTS DEF PAGE DEFPAGEREADtWRITE DEF SEG DEFUSR END ERROR FILES FIX FRE INDENT INKEY$ INKEY$ KEY LOCATE MEM MEM MKDIR MODE MOUSE MOUSE ON COM ERROR ON INKEY$ OPEN"C" PAGE LPRINT PAINT PALETTE PATH$ PEEK PLOT USING POKE RENUM* RMDIR SCREEN SCREEN SHELL TFORMAT TIME$ TIMER UNNUM USRI (EOF) USR2 USR3 USR4 USR5 VARPTR VARSEG VIEW PRINT WAIT statement statement statement statement statement function statement command function command function statement command statement function command statement statement function statement statement statement statement statement statement statement function function statement statement statement statement function statement statement statement statement function command function statement function statement function function function statemeni statement New Full Screen Editor Difference between the two Editors Moving the Cursor Full Screen Editor Commands A44 A45 A46 A47 A48 A49 A50 A51 A52 A53 A54 A55 A56 A57 A58 A59 A60 A61 A63 A65 A66 A67 A69 A71 A72 A73 A74 A75 A76 A77 A78 A79 A80 A81 A82 A83 A84 A85 A86 A87 A87 A88 A89 A90 A91 A91 A92 A93 A94 A94 A95 A96 MSDOSTM Appendix A-4 MSDOS APPENDIX J JUM GETTING STARTED ... : This version of ZBasic is provided on a 180K diskette to be compatible with most MSDOS computers. It is recommended that you make a backup of the diskette and put the master away for safekeeping. HOW TO MAKE A BACKUP 1. Put an MSDOS or peDOS diskette in drive A: and start the system. 2. Put a Write protect tab on the ZBasic master diskette. 3. Put the ZBasic disk in drive A: and a blank diskette in drive B: 4. Type: DISKCOPY A: B: 5. Put the master ZBasic diskette away for safekeeping. HOW TO PUT ZBASIC ON A BOOTABlE MSDOS DISKETTE 1. Put an MSDOS diskette in drive A: and start the system 2. Put a blank diskette in drive B: 3. Type: FORMAT/S B: 4. Take the newly created diskette out of B: and pul it in drive A: 5. Put the ZBasic diskette in B: 6. Type: copy B: * . * A: HOW TO COPY THE ZBASIC FilES TO A HARD DISK: 1. Pullhe ZBasic disk in drive A: 2. Type: Copy A:*.* C: NECESSARY FilES The only necessary file for running ZBasic is: ZBasic .COM. If you are using a Hercules board then ZHERC • BAT and HERC. COM are required when mixing text and graphics. If only graphics are used Ihese files are nol necessary (Ihese files are not required with other graphic boards). All the other files are optional. See "Files included on the Master Diskette" on the next page. RUNNING ZBASIC To run ZBasic from DOS just type: ZBAS IC. If you are using a Hercules board type; ZHERC. For more detailed information see "Running ZBasic" in the main section of this manual and "Executing ZBasic from MSDOS" in this appendix. TWO EDITORS You will see a start-up screen as described in "Getting Started" in the front section of this manual. Press "E"lo go into the Standard Line Editor. Use the key to toggle between the Standard Line Editor (where all direct commands are executed) and the Full Screen Editor. CONFIGURING ZBASIC FOR YOUR COMPUTER You may configure many of the default settings of ZBasic to your preferences and for your computer type. See "Configure" in the front section of this manual and "MSDOS Specific Configuration Options" in this appendix for ways of changing the standard settings. A-5 MSDOSTM Appendix MSDOS APPENDIX ",_liwfill. ._.,tl.wmBt_l.1tfB;¥itllt;;B@%\W¥ml ENHANCEMENTS TO 3.02 When ZBasic was first introduced for MSDOS machines in late 1985 we knew it was a great product, but we were also realistic and knew that there must have been things we overlooked and that people would wan!. So we listened carefully to all the feedback we received. This version of ZBasic is the culmination of that feedback. We have worked hard to add the features you wanted (let us know what else you would like). The following enhancements have been made to ZBasic 3.0: UNLIMITED VARIABLE SIZE: for String and BCD arrays. Array sizes may be up to available memory (640K on most systems). In addition, Integer variables and INDEX$ may be up to 64K (since data storage may be so large we had to change the way that VARPTR worked. See VARPTR in this appendix for specifics). EGA GRAPHICS: New modes have been added to take advantage of the Enhanced Graphics Adapter. Resolution up to 640x350 in 16 colors is available. MODE 16-19 are used for EGA modes. CGA modes may also be emulated. See MODE, SCREEN, COLOR and PALETIE for details. HERCULES AND HERCULES PLUS GRAPHICS: The popular "HERC" board is now supported in MODE 20. Resolution is up to 720x348. See MODE and "Hercules Graphics" in this appendix for details. LOTS OF NEW COMMANDS: We have made ZBasic even more compatible with other BASIC languages. Some of the commands added since the last version: COORDINATE SCREEN BSAVE CHOIR CSRLN RMDIR KEY LIST END SELECT COORDINATE WINDOW CARDTYPE DEFSEG COM ON EOF VARSEG COM BUFF CASE GET(graphics) BEEP SHELL COM OFF MKDIR KEY ON WAIT SELECT CASE PUT BLOAD CONFIG COMMAND$ PATH$ KEY OFF PALETTE CASE ELSE FULL SCREEN EDITOR: We have included a powerful and easy to full screen editor with ZBasic. To toggle between the Line Editor and the Full Screen Editor just press F10. Instructions are at the back of this appendix. IMPROVED USER INTERFACE: Both editors display function key equivalents at the bottom of the screen. Just press the appropriate function key to do the command. LOAD and SAVE automatically append the pathname and .BAS suffix where appropriate. If you use another suffix just add it under "Configure". ADVANCED COMMUNICATION FEATURES: An interrupt driven, 32K buffer has been added that supports both communication ports. See COM ON, COM OFF, COM BUFF and the chapter in this appendix entitled "RS-232 Communications". NEW CONFIGURATION OPTIONS: We have added options to configure "Spaces between Keywords" so that you can embed keywords in variables and an option to set expression evaluation to do floating point like QuickBASIC and BASICA. See "Converting QuickBASIC and BASICA Programs" in this appendix and "Converting Old Programs" in the main reference section. MSD05TM Appendix A-6 MSDOS APPENDIX fJWi@. ill I~• • • • • • • •I FILES INCLUDED ON THE MASTER DISKETTE SYSTEM FILES ElLENA ME DESCRIPTION This is the main ZBasic compiler and editor. Just type ZBASIC from the MSDOS to execute. ZBASIC ZBASIC.COM DEMO ZDEMO.COM A limited demo version of ZBasic (public domain). Feel free to give it away to your friends, relatives and co-workers. This and ZBAS IC . HLP may be given away together (please do not give away any other programs on this disk). HERCULES GRAPHICS ZHERC.BAT This batch file loads the Hercules text driver and ZBasic into memory in the correct order. Always use it when with Hercules Graphics boards. HERC.COM This file is necessary for intermixing text and graphics in Hercules graphics modes. If you are creating applications that may be run on a Hercules Graphics adaptor be sure to have this file available for the program. FILE~AM!:; EXAMPLE FILES HELP ZBASIC.HLP D!:;SCRIPTION This is the help file. It is not necessary for using ZBasic. KEYBOARD DTEST.BAS Configuration for keys. GRAPHICS PYRAMID.BAS HOUSE. BAS SIEVE.BAS COLOR. BAS PAGEFLIP.BAS ZROSE.BAS APPLE.BAS 3-D pyramid rotates in space using standard graphics. 3-D house rotates in space. The Sieve of Erastothenes benchmark from Byte, Jan. 1983. Shows different uses of color. Demonstration of graphics page flipping in EGA modes. Does a graphic "Rose" using High-speed and regular speed SIN and COSINE routines. Change mode for different graphics types (MODE 7 for CGA, MODE 19 for EGA, MODE 20 for Hercules and Hercules Plus). A powerful graphic editor. Requires a Microsoft mouse. This program displays some of the MODE type available in ZBasic. It does not demonstrate EGA or Hercules modes. Extend the loop from 16 to 20 to do that. Bar and Line Graphs in Device independent Graphics. GAME KILLER.BAS A simple game written in ZBasic. It is quite fun. Try it. SORTS SORT.BAS This routine creates random data for arrays to demonstrate the SHELL and QUICK sort routines on this disk. Load this program firstthen do APPEND 1000 SHELL .APP (or QUICK.APP) The SHELL SORT that appears in the manual (under "Array variables.) A powerful sort when less items are used. The QUICK SORT that appears in the manual (under "Array variables.) A powerful sort when many elements need to be sorted. GEDIT.BAS MODE.BAS SHELL.APP QUICK.APP MATH FUNCTIONS A-7 SCIFN.APP MSDOSTM Appendix Examples of creating your own functions with ZBasic. MSDOS APPENDIX SPECIAL NOTES LOADING OLD ZBASIC 3.02 PROGRAMS To convert old ZBasic 3.02 programs to work with ZBasic version 4.0: 1. Load programs into ZBasic 3.02 2. Use SAVE< to save them in ASCII format 3. Load them into ZBasic 4.0 Note: Be sure that "Spaces between Keywords" is set to "NO" when loading old programs (otherwise keywords without spaces will result in syntax errors [or worse]). PATHNAMES The filenames in ZBasic are the standard MSOOS filenames as specified in the MSOOS reference manual. Pathnames may not be used as filenames within OPEN statements in this version (although by using CHOIR you may have files open in many different directories simultaneously). To control pathnames use one of the following: PATH$, RMOIR, MKOIR and CHOIR and ERROR 11. See the listings for these commands in this appendix. NOT QUITE 100% IBM PC COMPATIBLE NOTES For many computers that are not quite 100% compatible with the IBM PC there are a number of things you may want to do. First; be sure to read the text in the "MSOOS Specific Configuration Options" section of this manual. Especially under IBM Text Compatible and IBM Graphics Compatible items. You may need to set these. Other than that you should have few problems using ZBasic on your computer. NOTE TO TANDY 2000 OWNERS The Tandy 2000 boots up with random characters on the screen. While this may look like the system has crashed, it is alive and well on another page. Simply press "E" and everything works fine from there on out. Use CON FIG from the Standard Line Editor to configure ZBasic to your preferences. ZBasic operates normally on all the other Tandy computers including the Tandy 1000, 1200 and 3000. NOTE TO ZENITH Z-150 OWNERS Zenith Z-150 computers work great with ZBasic when you use the PC emulation program available from Zenith and Heath dealers nationally. Failure to use this program produces a "Wild Interrupt Error". MSDOS'M Appendix A-8 MSDOS APPENDIX mMt.. . . . . .,;,;: AU bW&i4iWMWi ADDITIONS TO THE STANDARD LINE EDITOR OPTIONAL KEYS The standard reference manual describes certain keys to be used with the Standard Line Editor. The following list of keys may also be used: KEY Up arrow Down arrow Home End Page down Ctrl-Home Cursor keys Insert Delete ---> ---> ---> ---> ---> ---> ---> ---> ---> DefiNITION List previous line List next line List first line List last line List next 10 lines Clear the screen Cursor movement left or right (or and This is the standard way to startup ZBasic. See "Getting Started" in the front of this manual and also "MSDOS Specific Configuration Options" in this appendix. 2. Type: ZBASIC filename This will force ZBasic to load the file given by filename and go directly into the ZBasic editor, skipping the initial prompt screen. Using this procedure saves the time of going through the initial prompt screen (note: BASICA or QuickBASIC files must have been saved in ASCII format). 3. Type: ZBASIC filenamel filename2 [/C 1 This will force ZBasic to load the file given by filename1, then compile it into the file given by filename2. If the "/C" option is included, then the file will be saved as a ZBasic chain file (same as using RUN+), else the file will be saved as an executable file (same as using RUN-). ZBasic will always return to the operating system when done compiling, making this procedure very useful for compiling several programs at once using a batch file. NOTE To convert old ZBasic 3.02 programs saved in tokenized format so they can be loaded into the new version 4.0: 1. Load programs into ZBasic 3.02 2. Use SAVE- to save them in ASCII format 3. Load them into ZBasic 4.0 EXAMPLES ZBASIC TEST.BAS TEST. COM This compiles TEST. BAS and creates TEST. COM; an executable file. ZBASIC TEST.BAS TEST.CHN/C This compiles TEST. BAS and creates TEST. CHN; a chain file (runtime not included). If there is an error during loading or compiling, the error will be displayed and ZBasic will retum to the operating system. ZBasic will also return an exit code of 1 if there was an error, 0 if your program compiled and saved successfully. This exit code can be examined using the batch sub-commands IF and ERRORLEVEL. See the MSDOS manual for more information on using batch files. A-11 MSDOSTM Appendix MSDOS APPENDIX MSDOS SPECIFIC CONFIGURATION OPTIONS ZBasic may be configured by typing "C" in the initial prompt screen. ZBasic will then ask for the standard configuration parameters explained in the "Configure" section of the manual (this version may also be configured directly from the editor by typing CON FIG). Following the "Standard configuration parameters" are the MSDOS specific configuration parameters. The additional configuration prompts are: Default BASIC file type BAS? Allows you to set the default suffix. If you save a program called FRED, it will be saved as FRED.BAS. If you change BAS to ZBS, it will be saved as FRED.ZBS. Use a space if no suffix is desired. The default is .BAS. Default screen length 0019 00025 ? The normal IBM screen allows 25 rows of text to be displayed. There are some MSDOS computers, however, that cannot display this many rows of text. For these computers, simply enter the actual screen length under this prompt and ZBasic will automatically correct this IBM incompatibility. DELAY 1ms time constant 012C 00300 ? The ZBasic DELAY expression statement is designed to delay a number of milliseconds given by expression. However, each millisecond delay is dependent on the speed of the computer hardware. ZBasic assumes the computer speed to be that of the IBM PC (i.e. 4.77 megahertz clock speed using the 8088 microprocessor). If your clock-speed varies; enter a number under this prompt corresponding to your computer's speed: For 8mhz calculate using 8/4.77 *300=503. For 12mhz calculate using 12/4.77*300=754 This 1ms time constant is also used in the ZBasic SOUND statement; thus, if a program uses sound at all, it is necessary that this time constant be accurate. The time constant can also be changed during program execution using the pre-defined user function -USR2. See USR2 statement in this appendix for more information. Mouse supported . N ? ZBasic defaults to not supporting a mouse driver. If ZBasic is configured to support the mouse, it will assume the Microsoft mouse and will always check to see if the mouse hardware and software are installed. On some machines, this check is invalid and can cause unpredictable results. This is because ZBasic checks and, if non-zero, uses interrupt H33 for the mouse interface. If a system uses this interrupt vector for something else, problems will result. If configured to use the mouse, make sure to test ZBasic with the mouse driver. MSDOSTM Appendix A-12 MSDOS APPENDIX IBM graphics compatibl.e . Y? Graphics in MODE 5 and MODE 7 go directly to memory and, thus, are very fast. This is a problem, however, on systems with the graphics memory arranged differently from the IBM PC's graphics. If this is the case, enter "N" under this prompt and ZBasic will no longer use direct memory when implementing graphics (which will noticeable slow down the graphics functions). Selecting the "N" option will also allow ZBasic to handle COLOR ranges from 0 to 255 for foreground, background, and palette in MODE 5 and MODE 7 (see "COLOR" in this appendix). This will allow the full color range on some advanced color adapters; however, the expressions used in the COLOR statement should not exceed the highest allowed value for the adapter, else the result will be unpredictable. IBM text compatible . N? If ZBasic is configured to be IBM text compatible, then ZBasic writes text directly to memory. This speeds up the PRINT statement by as much as ten times, depending on what is being printed. If the machine is not a true compatible, however, ZBasic will not operate properly. To find out if this works on your machine, Simply type "Y" after the question mark; if the next configuration parameter shows up normally on the screen, then the machine is IBM text compatible. A program that is compiled to disk using 'RUN", however, cannot be configured to be IBM text compatible. This is done as a safety measure to insure that a compiled ZBasic program will run on different machines. A program can set itseH to this configuration by using: POKE &342,1 POKE &342,0 sets to IBM text compatible (for high speed text printing) sets to non-IBM text compatible (prints through BIOS) <--<--- A program should allow the user to configure the program to his machine. LOCATE order is X, y . Y? ZBasic assumes an orientation of X,Y in the LOCATE statement, which corresponds to column,row. This is different from MSBASIC. Thus, if converting a program from a BASIC using Y,X orientation, enter "N" under this prompt and ZBasic will then use this representation. This will not, however, change the orientation on the ZBasic PRINT@(X,Y) statement. LOCATE start is 0, 0 . Y? The LOCATE statement in IBM BASIC uses 1,1 as the upper left hand corner of the screen, but ZBasic uses 0,0. If "N" is entered under this prompt, ZBasic will use the same convention as IBM BASIC. Notice that both the "LOCATE start" and "LOCATE order" configuration parameters must be changed to "N" in order for the LOCATE statement to operate as IBM BASIC. A-13 MSDOSTM Appendix MSDOS APPENDIX MEMORY USE WITH VERSION 4.0 The MSDOS version of ZBasic is designed to run on the IBM PC and most compatibles under MSDOS 2.0 or greater. For those Not-So-Compatible-Compatibles, see "MSDOS Specific Configuration Options" in this appendix for ways of configuring ZBasic to work with your computer. At least 128 k of memory is required for editing and compiling of programs, although ZBasic compiled programs can be written to run on 64K systems. See "Memory Considerations" in this appendix for more information. MEMORY FOR VARIABLES SINGLE AND DOUBLE PRECISION This version of ZBasic offers extended capacities for Single and Double precision arrays. Arrays are limited to available memory up to 640K. The array may be larger than 64K. See MEM BCD function for determining where the regular BCD variable segment begins (not arrays). See FRE to determine available memory. Regular Single and Double precision variables (not arrays) and regular string variables are limited to 64K total. STRING String arrays may be larger than 64K in this version. See MEM STR function for determining where segment begins for string arrays. Regular Single and Double precision variables (not arrays) and regular string variables are limited to a total of 64K. INTEGER Integer variables may use a maximum of 64K memory. This includes all integer arrays and regular integer variables. If you need an integer array larger than 64K you can use either a floating point array or use a string array and store and retrieve the integer numbers in the string array with CVI and MKI$. This will take only 2 by1es per element. OTHER MEMORY CONSIDERATIONS The MSDOS version of ZBasic has three different modes of operation concerning memory organization -- EDIT mode, RUN mode, and RUN" mode (see memory map on following page). At least 128k of memory is required for the EDIT and RUN modes (the development stage of the program). However, after a program has been compiled and saved using RUN", it can be run on as little as 64k of memory depending on the size of the program (the RUN" mode is shown on the memory map). continued ... MSDOSfM Appendix A-14 MSDOS APPENDIX • •_ _ _ _ J; Hi·,bStA continued from previous page While in EDIT mode, ZBasic will assume to own all of the existing memory available in the machine. Thus, nanother program (i.e. a .COM or .EXE file) attempts to use parts of memory located above (higher address than) ZBasic, the contents of this memory could be destroyed by ZBasic. A "Memory Allocation Error" may also be generated by the operating system in this case (because a memory block created by the other program will have been written over). Thus, any drivers are to be resident in memory, they should be installed before ZBasic is given control. n A program compiled by ZBasic as a .COM file only uses the amount of memory required by the program. This means that other programs can use the memory outside of the ZBasic compiled program. If a ZBasic program chains to another program, ZBasic will try to re-size its current memory block to fit the chained program. If the new program is larger and does not fit, ZBasic will not execute the chain and will return a disk error. Note: See VARPTR for details about locating variables in memory. NOTES ON ZBaslc MEMORY MAP: 1. The MEM type functions are used to return the address of a segment break. MEMC MEMO CODE segment Disk buffer and INTEGER variable segment. Integer variables (including arrays) and disk buffers may use up to 64K total. MEME EXTRA segment MEMS STACK segment MEMI INDEX$ segment MEMBCD The segment address for the BCD "simple" variables (non-array). Up to 64K total memory may be used (single or double precision variables). MEMSTR The Segment address for the String "Simple" variables (non-array). Up to 64K total memory may be used. MEM ARR \a,(n) The segment address for the String or BCD array specnied by var (n is a dummy expression or number and is not used). For more information, see "MEM function" in this appendix. A-15 2. The ZBasic subroutines and jump tables are not saved to disk when a program is compiled as a chain file using RUN+. Thus, chain files take about 18-19k less on disk. 3. ZBasic is not necessarily located immediately after MSDOS. There may be drivers or other applications installed before ZBasic. ZBasic does, however, assume to own all of the memory above it. 4. The size of the INDEX$ segment is determined by the CLEAR statement (see reference section in main manual). The MSDOS version of ZBasic defauRs to CLEAR 1024, making the INDEX$ segment 1k. If there is not enough memory to create a segment of the size specified, then the largest size available will be allocated. The size of the INDEX$ memory can be determined using the MEM function. 5. When the CALL string or SHELL string statements are used to load and execute another program, the program is loaded just above the ZBasic INDEX$ segment (see CALL and SHELL in this appendix. MSDOSTM Appendix MSDOS APPENDIX MSDOS MEMORY MAP EDIT MODE: RUN- ~' RUN" or RUN+: Top Of,'::: ~ INDEX$ Segment User Stack Arrav Y# Array XI MEM ARR Y#(n) MEM ARR XI(n) Array 8$ MEM ARR S$(n) Arrav A$ String var sim-ole MEM ARR A$(n) MEM STR MEM BCD . S~~~"' pto 64k MEM I MEMS Up to available Memory pto 64k MEM ARR Y#(n) INIt:(;t:H MEM 0, MEM E (ES, OS) Simple and Array Disk Buffers p to 64k Copy of Jump tables tac ZBasic Compiler Runtime urn ta es DOS I.SSS1 • Available memory _ . Segment break Array B$ ZSasic Program Text Stack ZBasic Compiler Runtime MEMI MEMS Up to available Memory Array A$ up to 64k p to 4B'k MEM STR up to 64k MEM BCD up to 64k MEM C MEM 0, MEM E (ES, OS) saved to disk using RUN+ ... About18K· ... Jump tables MEMC+ DOS up to 64k MEM ARR A$(n) Data Copy Runtime ",About SOK' ... MEM ARR XI(n) User Stack rra Array XI MEM ARR B$(n) I Quoted stnngs Object code ZBasic Program Text INDEX$ Segment p to 64k uoted strings Data Object code Created by ZBasic (up to 4Bk') saved to disk using RUN' Runtime Jump tables DOS 'Note: Object code size limitation subject to change in subsequent releases. Check addendum (if any) for possible variations. MSDOS'" Appendix A-16 MSDOS APPENDIX IMlIM. . . . . . . . . . . . . . . .1MfAt.fiijB RS-232 COMMUNICATION ZBasic for MSDOS supports asynchronous communication using the numbers; -1 for COM1 and -2 for COM2 within the OPEN"C" statement. Baud rate, parity, stop bits, word length, handshaking and buffer length are all controlled in the OPEN "C" statement. The OPEN "C" statement has additional parameters that can be used to control the handshaking on the RS-232 cable when writing to the port. See OPEN "C" in this appendix and the example routines under OPEN"C" in the main reference section. To switch the communication interrupts on or off, the commands COM ON and COM OFF may now be used. The buffer size may be up to 32,700 bytes. See COM ON and COM OFF in this appendix for details. To determine the status of the buffer see COM BUFF in this appendix. To trap communication errors see ON COM ERROR GOSUB in this appendix. There is also a predefined user function -- USR5 -- that retums the modem and line status for the asynchronous adapter; see USR5 function in this appendix. COMMON COMMUNICATION PROBLEMS If the asynchronous communication is not working properly, try any of the following: 1. Check to make sure the baud rate, parny, stop bits, and word length settings are the same on both sides of the communication. See ON COM ERROR GOSUB in this appendix. 2. Examine the modem and line status. Type in the program below to observe the status of the asynchronous port: CLS DO PRINT@(O,O) BIN$(USR5(-1));: REM COM 2 is -2 UNTIL LEN (INKEY$) : REM Press a key to stop If using COM2, then use USR5(-2). The meaning of the bits are explained in this appendix under USR5 (bn 15 is on the left, bit 0 on the right). A Framing error or Parity error usually means that the sender and receiver are operating at different baud rates, parity, stop bits, or word length. An overrun error usually indicates an improper cable or buffer length has been set to small. 3. continued ... A-17 MSDOSTM Appendix Check for proper cable. The cable must support the standard RS-232 asynchronous interface. If the serial transfer works at a low baud rate (like 300 baud), but fails at higher baud rates, then the cable is improper. The diagrams on the next page show the two most typical cable configurations. The top diagram is for communication between two DTE's (Data Terminal Equipment) or two DCE's (Data Communication Equipment). This configuration is typical for an IBM talking to another IBM or compatible. The bottom diagram is for communication between a DTE and a DCE. These cable configurations are not the "rule", they are only the most typical for proper RS-232 interface. MSDOS APPENDIX RS-232 COMMUNICATION continued DTE <----> DTE DCE <----> DCE (Typical for IBM to IBM communication) Communication devices: CONNECTOR 1 CONNECTOR 2 PIN PIN Carrier Detect 2 3 4 5 6 7 8 2 3 4 5 6 7 8 Data Terminal Ready 20 20 Transmit Data Receive Data Request to Send Clear to Send Data Set Ready Ground DTE DCE Communication devices: <----> <---> Transm~ Request to Send Clear to Send Data Set Ready Ground Carrier Detect Data Terminal Ready DCE DTE CONNECTOR 1 CONNECTOR 2 PIN PIN 2 3 Data Set Ready 2 3 4 5 6 Ground 7 Carrier Detect Transmit Data Receive Data Request to Send Clear to Send Data Terminal Ready Data Receive Data Transm~ Data . Receive Data 4 Requastto Sand 5 Clear to Send 6 Data Set Ready 7 Ground 8 8 Carrier Detect 20 20 Data Terminal Ready DTE: Data Terminal Equipment DeE: Data Communication Equipment MSDOST" Appendix A-18 MSDOS APPENDIX ZBasic JUMP TABLE The MSDOS version of ZBasic makes a jump table available starting at address 0103 hex. These jumps can be altered to jump to some other routine to handle the same function. This can be useful for implementing special hardware or for handling noncompatible DOS or BIOS. Also included in this section are the USR function jumps, many of which are predefined. The following is a list of all the available jump locations with a short description of each: LIST OF ALTERABLE JUMPS: .Add.Ws. &103 A-19 Description ZBasic exil - where ZBasic jumps on a STOP or END statement. On entry: --On ed: exit program ... &106 Video output - all characters output to the screen. On entry: AL = character On exit: &109 Printer output - all characters output to the printer. On entry: AL = character On exit: Remarks: altering will disable ZBasic PAGE control &10C Scan keyboard - used by INKEY$ and TRON commands. On entry: On exit: Z flag Wno character NZ flag Wcharacter in AL Remarks: SI must be preserved &10F Inil. COM port - called by the OPEN "C" statement. On entry: On exit: Remarks: sets Baud,Parity,Stopbits, and Wordlength &112 Write COM port - used whenever filenumber is #-1 or #-2. On entry: AL = character On exit: Remarks: CX,DX must be preserved &115 Read COM port - used whenever filenumber is #-1 or #-2. On entry: On exit: AX = character Remarks: CX,DX must be preserved MSDOSTM Appendix MSDOS APPENDIX LIST OF ALTERABLE JUMPS continued ~ &118 Description Scan COM port - used by READ #-1 ,A$;O (same as INKEY$, but for COM). On entry: DS:SI points to destination string On exit: DS:SI contain string in form length,characters &11B SOUND frequency,duration - ZBasic statement. On entry: AX = duration BX = frequency On exit: ... sound ... &11E MOUSE (expression) - ZBasic function (not statement). On entry: AX = expression On exit: AX = value returned &121 Write dot - sets each graphic point in MODE 5 and MODE 7 when ZBasic is configured to not be IBM graphics compatible (see "MSDOS CONFIGURATION" in this appendix). On entry: AX = row number BX = column number On exit: Remarks: the row and column are actual screen pixels &124 POINT function - reads the color of a screen point. On entry: AX = row number BX = column number On exit: AX = color of point Remarks: the row and column are actual screen pixels &127 Convert screen coordinates - converts ZBasic X,Y to pixel col,row. On entry: AX = ZBasic Y (or row) BX = ZBasic X (or column) On exit: AX = screen row number BX = screen column number &12A PLOT USING statement. On entry: AX = row number BX = column number CL = magnitude SI points to string On exit: Remarks: the row and column are actual screen pixels MSDOSTM Appendix A-20 MSDOS APPENDIX 111ilttt?if. . . . . . . . .• . . .I. . . . . LIST OF ALTERABLE USR FUNCTION JUMPS User functions using USRn( expression) statement. On entry: AX = expression ~ &120 &133 &139 &13F &145 &14B &151 &157 &150 &163 Descriptjon USRO - not predefined USR1 - predefined ---> End 01 File function (same as EOF) USR2 - predefined ---> DELAY time constant USR3 - predefined ---> keyboard functions USR4 - predefined ---> set break vector USR5 - predefined ---> read COM port status USR6 - predefined ---> last line number recorded USR7 - predefined ---> random number generator USR8 - predefined ---> integer sine USR9 - predefined ---> integer cosine NOTES ON USING THE ZBaslc JUMP TABLES: 1. All routines must exit with the segment registers DS, ES, and SS the same as that upon entry. 2. Exiting the routine is done with a RET assembly opcode (or a RETURN ZBasic statement). 3. The jumps are all relative to the code segment on the 8088/86 processor, so the actual value to poke into the jump table has to be calculated. The program below is an example of how to change a jump vector. REM EXAMPLE TO CHANGE SOUND TO LINE 1000 Jump = &l1B Line = LINE 1000 POKE WORD Jump+1, Line-(Jump+3), MEMC This program can easily be modified to change any of the jump vectors to any ZBasic line number. 4. The MSDOS version of ZBasic contains a 30 byte patch area that can be used to contain a small routine. By using the patch utility (from the ZBasic startup screen), a jump vector can be permanently changed to jump directly into a routine written into the patch area. Patch area address: Additional patch area: start stop stop ---> ---> ---> &169 & 187 &1B9 (30 bytes) (49 bytes more) This additional patch area (49 bytes) can only be used if the ON INKEY$ statement is not implemented. (For more information on ON INKEY$, see "ON INKEY$" in this appendix.) A-21 MSDOSTM Appendix MSDOS APPENDIX MACHINE LANGUAGE EXAMPLES Following is a simple machine language example that instructs the operating system to print a ZBasic string variable. The operating system is accessed through a DOS function call (see DOS manual for more information on DOS function calls). The assembly listing below is implemented using the MACHLG statement given in the ZBasic listing. Notice how the address of the variable A$ is generated in the MACHLG statement -- ZBasic automatically inserts the address of the variable when it is specified. ------------------------------------- ASSEMBLY LISTING ------------------------------------- 0000 CSEG ASSUME SEGMENT PUBLIC 'CODE' CS:CSEG, DS:DSEG ;MAKE MSDOS FUNCTION CALL TO PRINT STRING ; (must be terminated with '$') 0000 0000 BA 0000 PRINTS: ORG MOV a DX,OFFSET String ;Get string address in OX 0003 42 0004 B4 09 0006 CD 21 INC DX MOV AH,9 INT 21H ;Skip length byte ;Make DOS call 9 SEGMENT PUBLIC 'DATA' 0000 DSEG 0000 01 String DB 0008 0008 DSEG CSEG ENDS ENDS END 256 DUP (?) ------------------------------------- ZBasic LISTING ------------------------------------- CLS A$ = "PRINT ME" A$ = A$ + "$" :REM Must be terminated with "$" REM ----- MAKE CALL TO DOS TO PRINT A$ ----MACHLG &BA,A$,&42,&B4,&09,&CD,&21 The next two pages give a more involved example of the MACHLG statement. The example modifies interrupt 24 hex to jump to a ZBasic subroutine. This interrupt is used for control whenever a critical error occurs within DOS (such as the disk drive door being open during a read). MSDOSTM Appendix A-22 MSDOS APPENDIX W@!Ul1§]. •a.. Assembly Listing of Routines to Control the Critical Error Handler: 0000 CSEG SEGMENT PUBLIC 'CODE' ASSUME CS:CSEG, DS:DSEG GET CRITICAL ERROR HANDLER VECTOR ON EXIT _Seg:_Offset= Address of error handler 0000 0000 0001 0004 0006 OOOA OOOE 06 B8 CD 8C 89 07 ORG PUSH MOV INT MOV MOV POP GETVEC: 3524 21 06 0006 R IE 0004 R a ES ;Save ZBasic's ES AX,3524H 21H ; DOS function call 35H - GET VEe: _Seg,ES ;Save current vector _Offset,BX ES SET CRITICAL ERROR HANDLER VECTOR Seg = ZBasic's code seg ON ENTRY: =Offset = LINE # of error handler 0000 0000 0001 0005 0009 OOOC OOOE I • IE 8B 8E B8 CD IF 16 0004 R IE 0006 R 2524 21 0000 0000 0001 0002 0003 0004 0005 0007 OOOA OOOD 53 51 52 IE 06 8B 8E 8E 89 0000 0000 0003 0004 0005 0006 0007 0008 Al 0002 R 07 IF SA 59 5B CF EC 5E IE 46 20 3E 0000 R 0000 0000 0002 0004 0006 0008 0008 A-23 ORG PUSH MOV MOV MOV INT POP SETVEC: 01 01 01 01 a DS ;Save ZBasic's DS DX,_Offset ;Get vector in DS:DX DS,_Seg AX,2524H ;DOS function call 25H - 21H SET VEeT DS NEW CRITICAL ERROR HANDLER VECTOR ORG BX ;SS,SP,DS,ES,BX,CX,DX must ERRVEC: PUSH :be preserved! PUSH CX PUSH DX PUSH DS PUSH ES BP,SP MOV DS, [BP+30) :Get ZBasic's DS and ES MOV ES, [BP+32) MOV Error, Dr MOV :Put error code into variable END OF NEW CRITICAL ERROR HANDLER ORG a AX,Response MOV ES POP POP DS DX POP CX POP BX POP IRET DSEG SEGMENT PUBLIC 'DATA' Error OW DW Response _Offset DW _Seg DSEG CSEG MSDOSTM Appendix OW ENDS ENDS END DUP (?) DUP (?) DUP (?) DUP (?) VECTOR ;Put decision in AL :Restore registers iReturn to DOS ... MSDOS APPENDIX ZBasic Listing to Control Critical Error Handler: REM ----- GET PREVIOUS CRITICAL ERROR VECTOR MACHLG &06,&BB,&3524,&CD,&2l,&BC,&06 MACHLG 01d_Seg%,&B9,&lE,01d_offset%,&07 REM ----- SET CRITICAL ERROR VECTOR TO LINE 1000 ----Seg%=MEMC : Offset%=LINE "Error routine" MACHLG &lE,&BB,&16,Offset%,&BE,&lE,Seg%,&BB,&2524,&CD,&2l,&lF REM ----- READ DRIVE A: WITH DOOR OPEN ----OPEN "Rn,l,nA:HELPME" REM ----- RESET ERROR VECTOR BEFORE EXIT TO ZBASIC ----MACHLG &lE,&BB,&16,01d offset%,&BE,&lE MACHLG 01d_seg%,&BB,&2524,&CD,&2l,&lF STOP 1'Error routine" REM START OF ERROR HANDLER ROUTINE REM ****************************** MACHLG &53,&5l,&52,&lE,&06,&BB,&EC,&BE MACHLG &5E,&lE,&8E,&46,&20,&B9,&3E,Error%: REM ----- DO ANYTHING HERE EXCEPT DISK I/O PRINT PRINT"Error. What do you want to do" PRINT"(Ignore, Retry, Terminate)? "; DO A$=INKEY$ UNTIL LEN (A$) PRINT A$ : A$=UCASE$(A$) I%=INSTR(l, "IRT",A$) : IF 1%=0 THEN 1060 Response%=I%-l "DO DOS" REM ----- RETURN TO DOS ----MACHLG &Al,Response%,&07,&lF,&5A,&59,&5B,&CF REM * ** * * * * * ** * ** * * * ** ** * * *** * * * ** * * ** * * * * *.* **** ** * * * * * * NOTES ON EXAMPLE 1. The ZBasic code that handles the critical error (lines between "Error routine" and "Do DOS" above) cannot use any DOS function calls greater than 12H. ZBasic uses these function calls on the following: a. b. c. d. e. All RISK I/O! TIME$ function and statement DATE$ function and statement CALL string statement END = expr statement 2. See YOUR MSDOS manual for more information on the critical error handler vector. MSDOsnr Appendix A-24 MSDOS APPENDIX CONVERTING OLD BASICATM or QuickBASICTM PROGRAMS TO COMPILE WITH ZBasic™ First; Read the chapter in the front of this manual called "Converting Old Programs". Be sure to set the the following options under "Configure" b.e!Qre.loading your old QuickBASIC, BASICA or other MSBASIC programs: • Default variable type: • Convert to Uppercase YIN: • Optimize expressions for Integer YIN: • Spaces required after keywords YIN: • LOCATE x,y YIN: • LOCATE start is 0,0 YIN: S (to increase speed: avoid doing this) Y N Y N N WHAT DO WE HAVE THAT THEY DON'T? • Hercules and Hercules Plus Graphics support. • String arrays may be greater than 64K; up to available memory. • Floating point arrays may be larger than 64k; up to available memory. • No String "Garbage Collection". Static and dynamic String allocation. • INDEX$ string array and special commands: INDEX$I, INDEX$D and INDEXF. • Direct commands from the Standard Line Editor. • Configurable BCD math up to 54 digits of precision. • Device independent Graphics. See COORDINATE. • Apple II, Macintosh and versions. zao STRING LENGTH NOTE QuickBASIC allows up to 32k for a string length. The maximum string length in ZBasic is 255. See notes under "Strings" in "Converting Old Programs" in the main reference section of this manual. COMMANDS THAT ARE DIFFERENT The following list of QuickBASIC commands are not completely compatible with ZBasic. Examples of possible alternatives are given. CAll CDBl CHAIN CIRCLE CLEAR COLOR COM STOP COMMON CSNG CVD,CVS DATA continued ... A-25 MSDOSTM Appendix Different syntax w~h ZBasic. See CAll in this appendix. Not applicable. See CHAIN in the main reference section. Some variation in extra parameters. Some syntax the same. Does not allow changing stack size. Some syntax differences. See COLOR. COM STOP not supported. See COM ON IOFF. Same as ZBasic DIM. The SHARED parameter is not supported. Automatic when the target variable is a single precision number. ZBasic uses CVB w~h both single and double precision BCD variables. ~ is not necessary to use this with ZBasic file commands since numeric variables may be used with READ# and WRITE# ( see FIELD below). Same except that strings beginning with numbers must be in quotes. MSDOS APPENDIX continued from previous page DRAW ENVIRON[$] ERASE ERDEV[$] ERRIERL ERROR EXIT FIELD GET (files) INPUT$ IOCTL[$] KEYn KEY LlST/ON,oFF LBOUND LINE LOCATE LOCK/UNLOCK LPOS LSET MKD$, MKS$ ON COM ON ERROR ON KEY$ ON PEN ON PLAY ON STRIG ON TIMER OPEN OPEN COM OPTION BASE PALETTE PCOPY PEN PLAY PMAP PRESET PSET PUT (files) REDIM RESTOREn RESUME RND(x) RUN filespec SADD SCREEN SHARED SUB,SUBEND STATIC STICK STRIG UBOUND WINDOW Not supported. See PLOT USING. Not supported. See PATH$ and SHELL for alternatives. Not supported w~h ZBasic since all arrays are STATIC. See "Critical Error Handling" in this appendix. Not supported. Not the same. See ERROR in this appendix and reference section. See END FN, END IF, END SELECT and END. Not supported. Fielding is done automatically in the READ# and WRITE# statements. There is no need to use MKI$, MKD$, MKS$, CVI, CVS, CVD, LSET or RSET to store or remove data from a field. Saves lots of time. See "Files" in the main reference section of this manual. Not supported. See RECORD# Not supported. See READ# filenumoor, A$;length See USRS in this appendix. See INKEY$ (n) statement in this appendix (ignored at runtime). See KEY ON/OFF/LIST and ON INKEY$ in this appendix for variations. KEY ON and OFF in program code is ignored. Since arrays are all static this is not necessary. Use PLOT, PLOT TO, BOX, BOX FILL X and Yare opposite, 0,0 is start. You may configure ZBasic for this. Not supported. Use POS(1) instead. See FIELD above. See MKB$ in main reference section (BCD) and FIELD above. See COM ON/OFF, COM BUFF and ON COM ERROR GOSUB. Not the same. Disk errors only. See "Disk Error Trapping" in the front of the main reference section of this manual. Also see ON COM ERROR. See ON INKEY$ in this appendix. See DEF MOUSE statement in this appendix. Not supported. See DEF MOUSE and MOUSE statement in this appendix. See TIMER in this appendix. The same in most respects. See OPEN in the main reference section. Pathnames are not allowed in filenames. See PATH$, CHOIR, RMDIR and MKDIR in this appendix. See OPEN"C" for syntax variations The BASE of an array may be configured under "Configure". Same except that PALETTE USING is not supported. Not supported. See DEF MOUSE and MOUSE function in this appendix. Not supported See DEF PAGE, VIEW PRINT and COORDINATE COLOR=background: PLOT x,Y. COLOR=foreground: PLOT x,y Not supported. See RECORD# and "Files" in reference section. Not supported since ZBasic uses static arrays. With ZBasic n restores to the nth ~em not the nth line. Not supported. See ON ERROR GOSUB in the main reference. ZBasic returns an integer number from 1 to x. Not a number between zero and one. This method provides higher performance. See RUN, SHELL and CALL in this appendix. See VARPTR and VARSEG in this appendix. See SCREEN, MODE and COLOR in this appendix. See "Chaining" in the main reference. See LONG FN, END FN and APPEND. All arrays are already static so this is not needed. See DEF MOUSE and MOUSE function to set for joysticks. See DEF MOUSE and MOUSE function to set for joysticks. Not needed with ZBasic since all variables are STATIC. See DEF PAGE and VIEW SCREEN. MSDOsrn Appendix A-26 MSDOS APPENDIX "':31_": A-27 MSDOSTM Appendix ; 4; MSDOS APPENDIX ASIC ZBaslc™ VERSION 4.0 MSDOSTM REFERENCE SECTION The following pages contain commands, statements and functions included in the MSDOS version of ZBasic that are not necessarily included with other versions of ZBasic. Also be sure to see the definitions of the following new commands in the main reference section: BEEP CASE COMMON COORDINATE COORDINATE WINDOW CSRLlN END SELECT EOF GET and PUT (graphics) NAME PATH RESET SELECT MSDOSTM Appendix A-28 MSDOS APPENDIX BLOAD statement FORMAT BLOAD filespec [. [offset j[,segmenO] DEFINITION Loads a block of memory that was saved as filespec using the BSAVE statement. The optional offset is the position in memory to load the block and it will load into the current segment as defined using the DEF SEG statement (or the segment option if used). If offset and/or the segment is omitted, the information that was stored in the file with BSAVE is used. EXAMPLE REM Loads the CGA screen saved with BSAVE on the next page. MODE 7 BLOAD "CGASCRN . MEW' DELAY 4000 REMARK See BSAVE and DEF SEG. Address and lengths of different graphics memory: M..Q..Q.E. IYf.L 0-15 CGA 2 MDPA Hercules (pageO) Hercules (page1) 20 20 ADDRESS &HB800 &HBOOO &HBOOO &HB800 LENGTH 2048-16,3844,096 32,767 32,767 Note: EGA graphics are stored in memory in a different format than other graphic cards. To save images in EGA modes (16-19) you should GET the screen. Save the screen to disk using: BSAVE filespec, VARPTR(var%(n», number of elements/2 BLOAD the integer array back into memory using BLOAD filespec, VARPTR(var%(n» and then PUT the image back to the screen (see GET and PUT in the main reference section of the manual. 'See CGA, EGA, Hercules and MDPA technical manuals for more information. A-29 MSDOSTM Appendix MSDOS APPENDIX ~'i%filtEl'g$Jt.tt~IKiwfIHf"'##II?lttsi.'t1flt$f4itw.1JkI[tti.llt1+1 BSAVE statement L segmen~ FORMAT BSAVE filespec DEFINITION Saves a block of memory as filespec so that it may be loaded later wtth BLOAO. It saves an exact image of memory. , offset, length The optional offset is the position in memory to load the block and will save the current segment as defined using the DEF SEG statement (or the segment option if used). If DEF SEG is not used, the DATA SEGMENT (MEMO) is used. EXAMPLE REM This program saves a high-res CGA screen REM which may be loaded with BLOAD on the previous page. MODE 7: REM Adjust MODE for your computer. PRINT "Hello there!!" CIRCLE FILL 512, 383, 300 BSAVE "CGASCRN.MEM",O, 16384,&HB800 REMARK See BLOAO and OEF SEG. Address and lengths of different graphics memory: M.Q!lE. 0-15 2 20 20 TIeL GGA MOPA Hercules (pageO) Hercules (page1) ADDRESS &HB800 &HBOOO &HBOOO &HB800 LENGTH 2048-16,384' 4,096 32,767 32,767 Note: EGA graphics are stored in memory in a different format than other graphic cards. To save images in EGA modes (16-19) you should GET the screen. Save the screen to disk using: BSAVE filespec, VARPTR(var%(n», number of elements/2 BLOAD the integer array back into memory using BLOAD filespec, VARPTR(var%(n» and then PUT the image back to the screen (see GET and PUT in the main reference section of the manual. 'See GGA, EGA, Hercules and MDPA technical manuals for more information. MSDOSTM Appendix A-3~ MSDOS APPENDIX CALL statement 1 FORMAT CALL address [, segment DEFINITION This statement is used to execute a subroutine located in memory at the segment given by segment with an offset of address. If segment is not given, then ZBasic's code segment is used. EXAMPLE CALL LINE "Routine" Calls a ZBasic subroutine starting at "Routine" (same as GOSUB "Routine" but takes longer to execute). CALL &H100, &H0BD7 Calls a subroutine located at &HBD7 with an offset of &H1 00. This is a very dangerous use of the CALL statement. REMARK Use caution when specifying the segment. Rarely is any subroutine loaded in the same place every time. The operating system will load a program into the lowest available address, which depends on other programs that may be resident in memory. Any subroutine that is called by specifying the segment must return from the subroutine with a far return. Otherwise, unpredictable results will occur. A-31 MSDOSTM Appendix MSDOS APPENDIX CALL statement (same as SHELL) FORMAT CALL string DEFINITION The CALL statement followed by string will load and execute another program or MSDOS command specified by string. If a null (empty) string is specified, then MSDOS will be loaded and executed, in which case typing EXIT in DOS will return to ZBasic. This is identical to the "SHELL" statement and is retained to remain compatible with older versions of ZBasic. Also see SHELL in this appendix .. String must be either a string variable or a quoted string. EXAMPLE CALL "DISKCOPY A: B:" This will perform a diskcopy as if it was typed in from the DOS command line. CALL Gives control to MSDOS; displays DOS prompt. Type EXIT to return to ZBasic. CALL "ZBASIC" This will actually load and execute ZBasic. Typing QUIT will then retum to the original ZBasic. A$ = "DIR A:*.BAS": CALL A$ This will get the directory of all .BAS files on the A drive. REMARK This statement can also be very useful for executing batch files -- just use the name of the .BAT file (batch file) for string. There must be at least 17k of memory free to use the CALL statement. If the "COMMAND.COM" file is not found, the message "File not found" will be echoed to the display and control will be returned to ZBasic. MSDOsm Appendix A-32 MSDOS APPENDIX CARDTYPE function FORMAT CARDTYPE DEFINITION Returns the type of graphic hardware connected to the current system: CARD TYPE Color Graphics Card Enhanced Graphics Card EGA with Monochrome monITor Hercules (or compatible) Monochrome EXAMPLE IYPE CGA EGA EGA-Mono HERC MDPA COQE RETIJRNED o 1 2 3 255 A= CARDTYPE SELECT CASE A CASE 0 PRINT"A CGA card is installed" MODE 7 CASE 1 PRINT"An EGA card is installed" MODE 19 CASE 2 PRINT"A monochrome monitor is connected to an EGA card" MODE 18 CASE 3 PRINT"A Hercules card is installed" MODE 20 CASE 255 PRINT"A Monochrome card (MDPA) is installed" MODE 2 CASE ELSE PRINT"You can't read this!" END SELECT RUN A Monochrome card is installed REMARK This command can be useful in determining the display card of any system so that the MODE parameters in a program can be changed accordingly. Combine this with the Device Independent Graphics that ZBasic offers and one can write a program that will work the same way on a variety of graphics adaptors. Also see COORDINATE, COORDINATE WINDOW and the section in this appendix "Graphics Enhancements". A-33 MSDOSTM Appendix MSDOS APPENDIX CHOIR statement FORMAT CHOIR pathname DEFINITION Changes the current directory to the directory specified by pathname. This enables ZBasic to access files in different directories. A pathname is : drive: directory\ directory\ ... EXAMPLE A$ = PATH$(O): REM CHOIR "\ZBASIC\OATA": REM OPEN "I" 1,"MYOATA.TXT ": REM CHOIR A$: REM REMARK Also see PATH$, RMDIR and MKDIR. gets current path changes path opens file using new path back to original path Note: IF an error is encountered when using CHOIR, RMDIR or MKDIR, ZBasic returns an error eleven (11) in the ERROR function. See ERROR, ON ERROR GOSUB and the Chapter "Disk Error Trapping" in the front of this manual. MSDOSTM Appendix A-34 MSDOS APPENDIX CINT statement FORMAT CINT (expression) DEFINITION Same as INT. The difference between INT and CINT in BASICA and QuickBASIC is that CINT rounds up and INT rounds down. Example: CINT(99.5)=100 INT(99.5)=99 Use the function below to emulate the BASICA CINT statement. EXAMPLE REM This function emulates the BASICA CINT statement DEF FN cint#( x#) = INT(x#+ (SGN (x#) PRINT FN cint# ( 99.3), CINT(99.3) PRINT FN cint# ( 99.5), CINT(99.5) PRINT FN cint# (-99.5), CINT(-99.5) END RUN 99 100 -100 REMARK A-35 99 99 -99 See INT, FRAC and FIX in main reference section. MSDOSTM Appendix * .5)) MSDOS APPENDIX . . .'*IWB.liI.I-. . . . . . .w.4MI.&l COLOR statement FORMAT Graphics MODES: COLOR [=] [foreground] [, [background] [, palette Iblinking]] Character MODES: COLOR [=] [character] [, [attribute] [, border]] DEFINITION This statement controls the color of all output to the screen. All of the parameters are optional. This statement acts quite differently between graphics and character MODE (EGA colors in MODE 18: O=black, 1=low intensity, 2=blinking, 3=highintensity). Under all modes COLOR 0 will tum foreground off (black in BIW modes, space in character modes). COLOR -1 will set it to the brightest color (white in BIW modes): CHARACTER MODES character = 0-255 attribute = 0-255 border = 0-15 0.2,4,6 (represents an ASCII number) (see below and table 2 on the next page ) (use table 1) Examples of character formats available in most modes: Normal Intensity Regular Blinking Underline UL Blinking Invisible Statement COLOR ,7 COLOR,135 COLOR,1 COLOR,129 COLOR,136 High Intensity Regular Blinking Underline UL Blinking Statement COLOR,15 COLOR,143 COLOR ,9 COLOR,137 Reyerse (lnyerse) Regular Blinking Statement COLOR ,112 COLOR,240 (Blue on some color monitors) (not all systems) (Blue on some color monitors) GRAPHIC MODES 1,3,5,7 (use table 1 [limited by memory if using an EGA card]) foreground = 0-15 (not available in EGA modes) background = 0-31 blinking = 0 or not 0 MODE5foreground = 0-3 background = 0-15 palette = 0,1 (use table 3) (use table 1) (use table 3) MODE7foreground = 0 or not 0 background = not used palette = not used continued ... MSDOSTM Appendix A-36 MSDOS APPENDIX ff...-. _iJtffAVi.SJi1WWlii. . . .*. . . . . COLOR statement continued Be sure to see the other sections in this appendix that cover graphics and color, including; COLOR, SCREEN, PLOT, CIRCLE, PALETTE, DEF PAGE READ/WRITE and MODE. MODE contains a chart of the resolutions, pages, memory and SCREEN numbers required for different boards. TABLE 1: Border, background, and foreground colors VALUE VALUE COLOR COLOR 0 1 2 3 4 5 black blue green cyan red magenta brown white 6 7 Gray Light Blue Light Green Light Cyan Light Red Light Magenta Yellow White Intensified 8 9 10 11 12 13 14 15 Note: Text Borders are not used in EGA modes TAB LE 2: Attribute byte definitions attribute bits 76543210 G G IBIR TI Bill R BI T,--_I~::~ ~~~e~;~~nd . ; color Background color (not EGA) ' - - - - - - - - - - - . - Blinking TABLE 3: COLOR o 1 2 3 Foreground colors PALLETE = 0 Green Red Brown PALLETE= 1 background - - Cyan Magenta White In Hercules mode there are only two colors; Black and White. There are three character formats: Regular, Reverse and XOR. See TFORMAT for more information. A-37 MSDOSTM Appendix MSDOS APPENDIX wr...f{fl &1. . .'.I. . . . . . . . . .XtJ. . . COM BUFF function FORMAT COM BUFF (port) DEFINITION Returns the number of bytes storeing in the communication buffer. .EQl1 ~ -1 -2 COM 1 COM 2 The communications buffer is a first in, first out (FIFO) buffer. To read data out of the buffer use READ#, INPUT# or LlNEINPUT#. To set baud rate, buffer size, parity and handshaking, see OPEN"C". EXAMPLE OPEN "en, -1, 300"",,32000: OPEN "Ou,l,"File.TXT I1 REM COM (-1) ON is automatic program continues here ... LONG IF COM BUFF > 1000 GOSUB"Read Buffer" ENO IF "Read Buffer" DO READ#-l, A$; 0 <--- Reads even if buffer empty IF LEN(A$) THEN WRITE#1, A$;l <---Savesincomingdatatoafile UNTIL COM BUFF=O RETURN END RUN Prints incoming serial data to the capture file until the buffer is empty. REMARK In this appendix see COM ON, COM OFF, OPEN"C", ROUTE and the chapter called "RS-232 communications". Also see in the main reference section ROUTE, OPEN"C", READ#, WRITE#, INPUT#, LlNEINPUT# PRINT# and the chapter called "Files". continued ... MSDOsrn Appendix A-38 MSDOS APPENDIX COM BUFF function continued COM BUFF determines the size of the communication buffer in the following way; (COM END and COM START are imaginary pointers we use for illustration of how COM BUFF determines communication port size). COM START and COM END I- ~ en ::; ~ ~ w :E 0 () 1 .,. As bytes are read from the com port into the buffer the COM END pointer is positioned to the next available cell in the buffer. When it gets to the end of the buffer it wraps around to the beginning. n CB+H+f111 11111111111111111 rH+FifD Communications Buffer I0: Myprog Hel.l.o there fred <--- Typed from MSDOS Hello there fred REMARK A-41 Also see "Executing ZBasic from MSDOS" in this appendix. MSDOSTM Appendix MSDOS APPENDIX DATE$ statement FORMAT DATE$ = [month) [. [day) [, year)) DEFINITION This statement is used to set the current date. Any of the three parameters can be omitted, in which case the parameter will not be changed. The following values are accepted: month: day: year: EXAMPLE 1 - 12 1 - 31 1980 - 2099 DATE$ = 8,20,1987 PRINT DATE$ DATE$=,1 PRINT DATE$ RUN 08/20/87 08/01/87 REMARK If any of the specified parameters are not in the accepted range given above, the date will not be changed. See TIME$ statement in this appendix and the TIME$ and DATE$ functions in the main reference section. MSDOsm Appendix A-42 MSDOS APPENDIX DEF MOUSE statement FORMAT DEF MOUSE [=] expression DEFINITION This statement sets the MOUSE function to return information from anyone of four device drivers defined by expression: DEF MOUSE = o 1 2 3 MOUSE JOYSTICK A JOYSTICK B LIGHT PEN If the DEF MOUSE statement is not used, the mouse driver is used as the default. If expression is not 0 to 3, then the MOUSE(n) function will always return zero. EXAMPLE DEF MOUSE=O DO PRINT MOUSE (1) , MOUSE (2) <--- Press the Mouse button to stop. UNTIL MOUSE (3) REMARK If you are using a mouse device, you must configure ZBasic for a mouse under "Configure". See "MSDOS Specific Configuration Options" for more information. Also see MOUSE statement and MOUSE function in this appendix and in the main reference section. A-43 MSDOSTM Appendix MSDOS APPENDIX Wlffi*}%;Yflffii*$• •1r~1ta~._i1£i_&• •#Mliit~~I*,sm&1 DEF PAGE statement FORMAT DEF PAGE xl, yl TO x2, y2 DEFINITION This statement defines the size of the screen used in print operations where the parameters are as follows: xl,yl = the upper left character position of the screen x2,y2 = the lower right corner of the screen ZBasic uses the screen size in scrolling the characters on the screen and in the CLS statement. Programmers may use this command as an aid in creating "WINDOWS". EXAMPLE REM Example of creating WINDOWS MODE 7: COLOR ,255: REM CGA or EGA "MENU BAR" PRINT@(0,0)CHR$(2);" PLOT 0,30 TO 1024,30 MODE "WINDOW" BOX 123,150 TO 910, 650 PRINT @(33,4);"ZEDCOR WINDOWS"; BOX 123,150 TO 910,121 PRINT@ (10,5) ; DEF PAGE 10,5 TO 70,20 FILES EDIT" <--- Put a box around the window <--- Window title <--- Put a box around the title bar <--- Put cursor to first window position DO PRINT"HELLO THERE ... "; UNTIL LEN(INKEY$) END <--- Text scrolls in window. ZBasic keeps the text within the window specified. This will force scrolling and CLS n to operate from the 5th row and 10th column to the 20th row and the 70th column. This will leave the last four rows (rows 21 to 24) and the last 9 columns (columns 71 to 79) unaffected by normal print operations. REMARK This statement is most useful for displaying information and status on the screen that will not be erased by a CLS or by scrolling characters. The area outside the defined screen can be accessed using LOCATE or PRINT@ to locate the cursor in this area. Then normal printing can be done, except that none of the screen will be scrolled. When done printing in this area, a LOCATE or PRINT@ is again used to go back to the normal area (CLS will also home the cursor inside the normal area). Use MODE to reset the screen to normal text coordinates. MSDOsrn Appendix A-44 ,U MSDOS APPENDIX titt• • Wilt iM;; mw J DEF PAGE READ/WRITE statements FORMAT DEF PAGE READ [=) expression DEF PAGE WRITE [=) expression DEFINITION ZBasic can access the extra pages of memory available in text modes on the IBM PC with EGA, CGA, MDPA and HERCULES graphic cards. There are 4 pages of text when in 80 column text mode (ZBasic MODEs 2,3,4,6,10,11,12,14) and 8 pages of text when in 40 column text mode (ZBasic MODEs 0,1,8,9 [16 when 256K is on the EGA card)). EGA MODES 17-19 allow 1, 2 or 4 pages depending on whether there is 64, 128 or 256k on the board. See MODE for details. ZBasic can write to and display any of the available screens. This allows the programmer to write an entire screen full of data while a different screen is being displayed; then display the new screen instantly. The syntax is as follows: Set Display Page: DEF PAGE READ [=) expression Set Write Page: DEF PAGE WRITE [=) expression EXAMPLE <--- Writes to page 1 while page 0 is displayed. DEF PAGE WRITE = 1 CLS FOR I=l TO 20 PRINT "STRING NUMBER"; I NEXT I <--- You won't see this till you display page one PRINT "Press a key ... " <--- Write back to page 0 to display message. DEF PAGE WRITE=O PRINT"Press a key ... " *DO: UNTIL LEN(INKEY$) <--- Display page one. DEF PAGE READ=l *DO: UNTIL LEN(INKEY$) Set display back to page zero. <--DEF PAGE READ = 0 This example will show you the resuHs of "flipping" text pages. REMARK When the screen being displayed is not the same as the screen being written, the ZBasic "CLS" statement does not work. Also, the auto scrolling feature, which occurs when writing beyond the 25th row on the screen, does not work. However, the ZBasic "CLS expression" statement will work regardless of the displayed page. Thus, use CLS 32 to clear on any page (32 is ASCII for" "). Note: Hercules graphics support only page 0 and 1 (MODE 20). A-45 MSDOSTM Appendix MSDOS APPENDIX DEF SEG statement FORMAT DEFINITION DEF SEG [=] [address] Defines the current segment in memory. The address is an integer number between o and 65,535 (or the signed integer numbers -32,768 to 32,767). Any subsequent use of a BLOAD, BSAVE, CALL, PEEK or POKE definition specifies the offset into the segment (if the ZBasic segment option is not used in these commands). EXAMPLE REMARK DEFSEG = &BOOO BLOAD "TEXT.FIL" , 80 This will load the file TEXT. F IL into monochrome display memory (which starts at &BOOO ) at an offset of 80 bytes. See MEM, PEEK, POKE, BLOAD, BSAVE, VARPTR, VARSEG and the sections in this appendix entitled "Memory Considerations" and "MSDOS Memory Map" for more information. MSD08TM Appendix A-46 MSDOS APPENDIX DEF USR statement FORMAT DEF USR n [=) address [, segment ) DEFINITION This statement is used to tell ZBasic where a user function is to be located in memory. The difference with the regular ZBasic and the IBM version of DEF USR is in the definition of the address. Address is used as the offset into the segment given by segment. If the segment is not given, then ZBasic's code segment is used. EXAMPLE DEFUSR1 = LINE 100 This defines the subroutine at ZBasic's line 100 as user function 1. DEFUSR1 = VARPTR(I),MEMD This defines the address of variable I in ZBasic's data segment as user function 1. The subroutine must end with a far return. DEFUSR1 = &HO, &HOB7D This defines offset zero into the segment at &HB7D as address of user function 1. This is a very dangerous use of the USR function and is not recommended. REMARK Use caution when specifying the segment. The subroutine must always be located at that specific address, which is very uncommon on the IBM machines. Any subroutine that is called by specifying the segment must return from the subroutine with a far return. Otherwise, unpredictable resuijs will occur. Also see CALL, MACHLG and the section in the front of this manual "Machine Language". A-47 MSDOSTM Appendix MSDOS APPENDIX tt._",llWWi*&WItllWl&1ttr;1WMWwffi..thW@j@1 END statement I FORMAT END [= expression DEFINITION The END statement is the normal way to exit a ZBasic program. On the MSDOS version, however, an error return code can be sent using the END = expression. This value can then be interrogated by the batch subcommands IF and ERRORLEVEL. If the END = expression statement is not used to terminate a program, then the error code returned is zero. ZBasic does two things depending on how END is used. END USED WITH RUN RUN+orRUN* EXAMPLE END = RESULT Control is returned to the Standard Line Editor. Control is returned to MSDOS. 4 A program terminated by this statement could be tested by the following batch subcommand: IF ERRORLEVEL 4 ECHO ERROR IS AT LEAST 4 This subcommand will echo to the screen "ERROR IS AT LEAST 4". REMARK See your MSDOS technical reference manual for more information on batch files and the ERRORLEVEL subcommand. Also see SYSTEM in this appendix and STOP in the main reference section. MSD05TM Appendix A-48 MSDOS APPENDIX @'''''''''''' Itl}l}~.''''}I~$BI?l'''• • ERROR function FORMAT ERROR DEFINITION The same as the standard ZBasic ERROR function except that other errors are returned: ERROR=11 An error was encountered with RMDIR, MKDIR or CHDIR. Errors encountered depend on the statement but usually are related to that statement i.e. if you get an error 11 doing RMDIR either the directory didn't exist, the wrong diskette was used, a write protect was on the disk or the wrong pathname was used. See ON COM ERROR GOSUB for errors returned from the communication ports. EXAMPLE ON ERROR GOSUB 65535 MKDIR "Mydir n LONG IF ERROR>O LONG IF ERROR =11 PRINT "Could not make a new directory!" PRINT "Please check your disk drive" INPUT "and press to continue";temp$ GOTO "START" END IF XELSE PRINT "A disk error occurred" PRINT ERRMSG$(ERROR) INPUT" ontinue or top";temp$ IF temp$="C" THEN ERROR=O: GOTO "START" END END IF Program continues .... REMARK A-49 See PATH$, RMDIR, CHDIR, MKDIR, ERROR function, ON COM ERROR GOSUB, ON ERROR GOSUB, ERROR statement and the chapter "Trapping Disk Errors" in the main reference section. MSDOSTM Appendix MSDOS APPENDIX FILES statement FORMAT FILES [ filespec I DEFINITION Prints a directory of the files in the directory specified by filespec. If filespec if not used the current directory contents are listed. EXAMPLE CLS FILES "A:" END RUN Fred Harry ZBasic ZDEMO BAS BAS COM COM 4 Fi1e(s) REMARK 9843 23020 92020 12312 03/23/87 02/22/87 02/22/99 12/23/86 9:45 10:32 23:12 12:34 13993949 bytes free Also see RMDIR, CHDIR, MKDIR and your MSDOS reference manual for file specifications and pathname syntax. COMMAND.COM must be on the disk. Note: Other ways to obtain directories during runtime: To create a Directory file that you can read into your program (say into string arrays, so you can manipulate them) try using; SHELLnDIR>DIR.TXT". This creates a text file called nDIR.TXT" that will contain a listing of the current directory. This example program should give you some ideas: CLS DIM 80A$ (100) SHELL"DIR>DIR.TXT" OPEN"I", 1, "DIR. TXT"<--- This routine opens the file and loads it into A$(x). DO READjfl, temp$;l IF ASC(temp$)=13 THEN X=X+l UNTIL EOF(l) OR X>99 X=X+1 CLOSEU END PRINT "There areniXi" items in this directory" MSDOS'M Appendix A-50 MSDOS APPENDIX .al iii:: £@ ; 3 FIX command FORMAT FIX (spaces to indenf) DEFINITION This command is used from the Standard Line Editor to remove line numbers (that are not referenced) and set the number of spaces to indent structures for the Full Screen Editor (not the line editor). Unless this command or the INDENT command is used ZBasic will not normally indent in the full screen editor (it indents two spaces in the Standard Line Editor). ZBasic structures are FOR-NEXT, DO-UNTIL, LONG-XELSE-END IF, WHILE-WEND, LONG FN-END FN and SELECT CASE, CASE ELSE, END SELECT. This is the same as doing both UNNUM and INDENT. EXAMPLE LIST 10 20 25 30 40 50 60 DO x=x+2 X=X-1 UNTIL X=100 PRINT"HELLO" PRINT "This is just a test" GOTO 10 FIX 10 <--- To go into the Full Screen Editor 10 DO X=X+2 X=X-1 UNTIL X=100 PRINT "HELLO" PRINT"This is just a test" GOTO 10 REMARK A-51 Also see INDENT, UNNUM and RENUM' MSDOSTM Appendix MSDOS APPENDIX FRE function FORMAT FRE (dummy argument) DEFINITION Returns the amount of free memory left in the system (divided by 16). Multiply the number returned by 16to get the amount of free memory in bytes. EXAMPLE All M# FRE(x) A#*16 <---M# contains the amount of free memory in bytes RUN 345329 It is imperative that these variables be double precision to get the true amount of free memory. REMARK ~ <\:c";~; .'. •. ,.. ., '<.- Also see MEM and the sections in this appendix "Memory Considerations" and "MSDOS Memory Map". Since there is no "Garbage Collection" with ZBasic, this function does not compact memory or return the remaining string space as BASICA does. String space is allocated at compile time. MSDOsm Appendix A-52 MSDOS APPENDIX .IW.'@lt_._m",~ INDENT command inden~ FORMAT INDENT (number of spaces to DEFINITION This command is used from the Standard Line Editor to set the number of spaces to indent structures for the Full Screen Editor (not the line editor). ZBasic normally does not indent in the full screen editor. It indents two spaces in the Standard Line Editor. ZBasic structures are; FOR-NEXT, DO-UNTIL, LONG-XELSE-END IF, WHILE-WEND, LONG FN-END FN and SELECT CASE, CASE, CASE ELSE, END SELECT. EXAMPLE LIST DO X=X+2 X=X-l UNTIL X=lOO PRINT"HELLO" PRINT "This is just a test" INDENT lO <--- To go into the Full Screen Editor DO X=X+2 X=X-l UNTIL X=lOO PRINT "HELLO" PRINT"This is just a test" REMARK A-53 Also see FIX, UNNUM and RENUM* MSDOSTM Appendix MSDOS APPENDIX li_A\\}t*#jjw\t%ltt0• •'_1.il&w%%}lJlg(®;._*.~t1{lmg\.&*%f%SW1 INKEY$ function (Special checks for function and other keys) FORMAT INKEY$ DEFINITION This function operates the same as described in the ZBasic reference section, except in its handling of function keys. Normally, the INKEY$ function will return a string whose LEN=1 if a key is available, otherwise a null string is returned. However, on the IBM version only, the string returned will have a LEN=2 when a function key is pressed. The first character in the string will be a null and the second character will be the value of the key pressed. See "ON INKEY$ statement" for the value corresponding to each function key. EXAMPLE DATA F1,F2,F3,F4,F5,F6,F7,F8,F9,F10 DATA HOME, UP, PAGE UP, NONE, CURSOR LEFT, NONE, CURSOR RIGHT DATA NONE, END, CURSOR DOWN, PAGE DOWN, INSERT, DELETE CLS:PRINT"Key";TAB(30);"ASCII Code of 2nd char." DO DO A$=INKEY$ UNTIL LEN(A$) LONG IF LEN(A$)=2 B$=RIGHT$ (A$, 1) LONG IF (ASC(B$»S8) AND (ASC(B$)<69) RESTORE ASC(B$)-59 READ C$ PRINT "You pressed: ";C$;TAB(30) ;ASC(B$) ELSE IF RESTORE 10+ASC(B$)-71 READ C$ PRINT "You pressed: ";C$;TAB(30) ;ASC(B$) END IF END IF UNTIL LEN (A$)=l END This example will print the function key you pressed if one is detected on the INKEY$ function. REMARK See ON INKEY$ and INKEY$ statement in this section for more information on how to make full use of the function keys. MSDOSTM Appendix A-54 MSDOS APPENDIX ; '" INKEY$ statement FORMAT INKEY$ ( expression) DEFINITION This statement is used to enable or disable function key interrupts. The function keys can be used to control program flow with ON INKEY$ GOTO (see ON INKEY$ statement in elsewhere in this appendix). The expression in the INKEY$ statement does the following: ---> zero non-zero ---> disables the function keys enables the function keys Enabling or disabling the function keys does not destroy the previous ON INKEY$ key definitions, it simply decides whether or not ZBasic should check for function keys. EXAMPLE ON INKEY$(I) GOTO "FI" ON INKEY$(2) GOTO "F2" INKEY$ (I) <--- Function key interrupts ON "Event Loop" I$=INKEY$:IF I$="S" THEN STOP GOTO "Event LOOp" INKEY$ (0) <--- Function key interrupts OFF "Fl" PRINT "Fl":GOTO "Event Loop" IIF2" PRINT "F2":GOTO "Event Loop" END REMARK The ability to turn the function keys on and off is very useful when parts of a program use function keys and other parts do not. If a subroutine does not want to use function keys, the INKEY$(O) statement is used at the beginning and then INKEY$(1) is used when the routine is done. Without this statement, ON INKEY$(n) RETURN would have to be done to all function keys at the beginning and ON INKEY$(n) GOTO line# at the end. A-55 MSDOSTM Appendix MSDOS APPENDIX KEY command FORMAT KEY ON KEY OFF KEY LIST DEFINITION Controls the display of function key oplions from the standard Line Editor. EXAMPLE KEY ON Shows the function key equivalents on the last row of the screen. This is the default. KEY OFF Hides the function key equivalents. KEY LIST Prints a list of the function key equvalents: KEY Fl F2 F3 F4 FS F6 F7 F8 F9 FlO REMARK LIST LIST RUN LOAD SAVE FIND EDIT CONFIG COMPILE KEY EDITOR Also see INKEY$ statement and ON INKEY$ in this appendix for other ways of controlling function keys during runtime. Note: The keys on the bottom of the screen for the Full Screen Editor are different. See "Full Screen Editor" at the end of this appendix for specifics. Note: KEY ON and KEY OFF are ignored during runtime. MSDOSTM Appendix A-56 MSDOS APPENDIX LOCATE statement x, YI [ ,[ cursor onloffl [ , [ start line I [ , stop line III FORMAT LOCATE ( DEFINITION This statement handles all of the cursor functions. parameter X;Y onloff start/ine stop/ine Definition horiz, vert coordinate on screen. 0= cursor off, not O=cursor on start line for cursor character 0-13 (cursor appearance) stop line for cursor character 0-13 The start and stop lines for the cursor determine the size and vertical position of the cursor; LOCATE ",0,13 makes a fat cursor. LOCATE ",13,13 makes a thin cursor. This example illustrates the different cursor types: DO INPUT"Start line, Stop line",x,y LOCATE '" x,y UNTIL X13 For the monochrome adapter, the values of these two parameters can be from 0 to 13. Zero specifies the top of the character block and 13 specifies the bottom. With the graphics adapter, 0 is top and 7 is the bottom. The cursor can be turned on and off without the start and stop lines being affected. EXAMPLE LOCATE 0,20,0 This sets the cursor location at column zero of row 20. The cursor is also turned off. LOCATE ,,1,3,4 This turns the cursor back on and sets the cursor start and stop lines to 3 and 4 (which is about the middle of the character on the graphics adapter). REMARK Note: The X,V orientation can be reconfigured to be V,X (row,column). See "MSDOS Specific Configuration Options" in this appendix for details. Also note that ZBasic defaults to accessing character cells using numbers from 0 to 79 accross and 0 to 24 down. BASICA LOCATE uses 1 to 80 and 1 to 25 respectively. Vou may configure ZBasic for this under "Configure". A-57 MSDOSTM Appendix MSDOS APPENDIX MEM function FORMAT MEM MEM letter MEM STR MEM BCD MEM ARR array variable name (dummy expression) DEFINITION This function returns the segment address of specific portions of a ZBasic compiled program. The segments returned are as follows: MEM MEMC MEMD MEME MEMS MEMI MEMSTR MEMBCD MEM ARR A$(1) EXAMPLE CLEAR 2000: REM Clear room for INDEX$ DIM A$ (100), A# (200) ,A! (300) PRINT PRINT PRINT PRINT PRINT PRINT REMARK Memory remaining in INDEX$ segment CODE segment DATA segment EXTRA segment STACK segment INDEX$ segment Simple strings BCD variables. Array A$ begins. MEM, MEM MEM MEM MEM MEM MEMC, MEMO, MEME, MEMS, MEMl STR BCD ARR A$(O) ARR A#(200) ARR A! (300) When using the MEM ARR function the string array is given only one dummy argument. For example: DIM A$(10,10) A = MEMARR A$(12) Only one argument is given, even though the array is 2 dimensional. It does not matter what the value inside the ( ) is , it is only a dummy argument. It's 12 in this example but could have been any number. In effect, it is the same as VARPTR A$(O,O) and reading the segment from the variable VARSEG. See VARPTR for further info. Also see VARPTR, VARSEG and the chapter in this appendix entilled "Memory Considerations" and especially the MSDOS Memory Map. MSDOSTM Appendix A-58 MSDOS APPENDIX MEM command FORMAT MEM DEFINITION The MEM command now gives some extra information about the memory usage of variables. The following is an example of its output: EXAMPLE ZBasic Ready COMPILE ZBasic Ready MEM 00167 64238 14364 01232 00008 00512 00001k 00392k Text Memory Object Buffer + Integer size BCD size String size BCD/String size Available ZBasic Ready REMARK Do not confuse the MEM command with the MEM function. The MEM command is not a runtime feature. The above values for Object, Buffer+lnteger size, BCD size, String Size, and BCD/STRING (array) size will be true only after a successful COMPILE, RUN, RUN> or RUN+. A-59 MSDOSTM Appendix MSDOS APPENDIX ._; %& wi@@fl%@!1[ FORMAT MKDIR pathname DEFINITION Creates a new directory (same as the DOS MKDIR command). EXAMPLE A$=PATH$ MKDIR "Mydirect" IF ERROR=ll THEN PRINT"Disk error making directory": ERROR=O END REMARK Also see PATH$, CHOIR and RMDIR. Note: If an error is encountered when doing CHOIR, RMDIR or MKDIR ZBasic returns an error eleven (11) in the ERROR function. See ERROR function, ERROR statement, ON ERROR GOSUB and the chapter "Disk Error Trapping" in the front of this manual. MSDOS'" Appendix A-60 MSDOS APPENDIX MODE statement FORMAT MODE expression DEFINITION MODE sets the system screen attributes. MODE can be set in the range 0-20 and takes advantage of all popular graphic and text devices available for IBM PC's and compatibles. Color Graphics Adaptor (CGA) MODE 0-7 Same as the slandard ZBasic modes defined in the reference section. All of these modes will use the color of the CGA card (or EGA card when dip switches set to CGA mode) if it is available. This card uses memory located at &HB800 and uses between 2,048 and 16,384 bytes depending on the MODE. Allows 16 colors in text and low resolution graphics modes only. Four colors in MODE 5 and 2 colors in MODE 7. Monochrome Display and Printer Adaptor (MDPA) MODE 2 If a Monochrome Display and Printer Adaptor is all that is available then only MODE 2 and 3 will be allowed. This board uses memory at adress &HBOOO. It uses 4,096 bytes. CGA Black and White MODE 8-15 On the IBM. Modes 8-15 are the same as 0-7 with the exception that only black & white is used on the screen. These modes can be slightly faster. especially in graphics. Enhanced Graphics Adpator (EGA) MODE 16-19 These modes require the Enhanced Graphics Adaptor (EGA). Resolution varies depending on the amount of memory on the board (see MODE chart). This board uses memory at &HAOOO and uses 8.192 bytes for MODE 16 and 32,768 bytes for MODE 17,18 and 19 (in monochrome graphics modes colors are: O=black, 1=low-intensity. 2=blinking, 3=high-intensity). Hercules and Hercules Plus Monochrome Graphics Cards This mode allows the use of the Hercules or Hercules Plus high MODE 20 MODE 2 (text only) resolution graphics boards (or compatibles). Text and graphics may be intermixed if the Hercules character driver; HERe. BIN has been loaded first. No other graphic modes will work with the Hercules cards. It uses memory at &H8000 and uses 16.384 bytes. To utilize high-resolution text-only. use MODE 2. Note: Also see SCREEN. COLOR, PALETTE, DEF PAGE and the section in the main reference "Graphics". continued ... A-61 MSDOSTM Appendix MSDOS APPENDIX MSDOS VERSION MODE CHART MODE Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 SCREEN Number 0 1 2 7 8 10 9 TEXT Column/Row 40x25 40x25 80x25 80x25 80x25 40x25 80x25 80x25 40x25 40x25 80x25 80x25 80x25 40x25 80x25 80x25 40x25 80x25 80x25 80x25 80x25 GRAPHICS horizon x vert character 40x25 character 80x25 character 320x200'" character 640x200'" character 40x25 character 80x25 character 320x200'" character 640x200'" 300x200· 640x200· 640x350· 640x350· 720x348·· MAX COLORS MONITOR PAGES Available TYPE 8 8 4 4 4 8 4 4 8 8 4 4 4 8 4 4 2/4/8 1/214 1/2 1/2 2 16 16 16 16 16 4 16 2 8IW 8IW 8IW 8IW BIW BIW 8IW 8IW 16 16 3 4/16-2 C/RGB C/RGB MONO C/RGB C/RGB C/RGB C/RGB C/RGB C/RGB C/RGB MONO C/RGB C/RGB C/RGB G/RG-S- C/RG8 C/RGB C/RGB MONO C/RGtr MONO Screen Number is the corresponding QuickBASIC equivalent and may be used instead of MODE. See SCREEN. ·The maximum number of pages for modes t 6-19 depends on the total graphic memory installed. The first number is 64K, the second 128K and the last number is 256K See DEF PAGE READIWRITE .•• Mode 19 requires 12BK or more to display 16 colors. C/RGB stands for Color or RGB monitor. MONO stands for monochrome monitor. •• Requires Hercules or Hercules+ display or compatible. ···Requires CGA or EGA. • Requires EGA. REMARK To determine what board is installed on a computer see CARDTYPE function in this appendix. Also see SCREEN, DEF PAGE READ/WRITE and COLOR in this appendix for information on setting text types and colors and manipulating pages. Also see PALETTE. MSDOsm Appendix A-62 .. MSDOS APPENDIX MOUSE function FORMAT MOUSE (expression) DEFINITION This function returns information from the current mouse driver as defined by the DEF MOUSE statement. Expression will determine the value retumed as follows: MOUSE(O) MOUSE(l) MOUSE(2) MOUSE(3) ---> Resets and returns true if installed. ---> Retums X posHion --> Retums Y posHion ---> Returns button status The X and Y posHions returned are in terms of Z8asic's graphic coordinate system. If expression is not 0 to 3, then zero will be returned. Also, MOUSE(O) is supported only forthe mouse driver (i.e. for DEF MOUSE = 0). EXAMPLE DO PLOT MOUSE (1) , MOUSE (2) UNTIL MOUSE (3) This will plot on the screen the posHion of the mouse device until a button is pushed. REMARK The MOUSE function does not operate exactly the same for all DEF MOUSE types. Use the fOllowing for more specific information: DEF MOUSE = 0 ---- MOUSE DRIVER MOUSE(O) Resets the mouse hardware and software and returns 0 (false) if hardware is not installed, otherwise returns -1 (true). Z8asic always initially resets the mouse. MOUSE(1) Returns the horizontal position of the mouse. MOUSE(2) Returns the vertical poSition of the mouse. MOUSE(3) Returns button status from 0 to 3. Zero if both buttons up, 1 or 2 if only one buttom is pushed and 3 if both buttons down. The mouse cursor can also be shown and hidden by using the MOUSE(4) and MOUSE(5) statements. See MOUSE Statement. Note that the Z8asic has to be configured to support the mouse. See configuration and DEF MOUSE. continued ... A-63 MSDOSTM Appendix MSDOS APPENDIX MOUSE function continued =1 or 2 DEF MOUSE ---- JOYSTICK DRIVER MOUSE(1) Returns horizontal position of joystick MOUSE(2) Returns vertical position of joystick MOUSE(3) Returns button status from 0 to 3. Zero if both buttons up and 3 if both buttons down. ZBasic debounces the joystick buttons for 1 millisecond. DEF MOUSE =3 ---- LIGHT PEN DRIVER MOUSE(1) Returns last horizontal position. If pen switch is currently down, the X and Y poSitions are updated and the new X position is returned; else the last position is returned. MOUSE(2) Returns last vertical position, operating the same as MOUSE(1). MOUSE(3) Returns pen switch status from 0 to 1 (0 if light pen switch not down/not triggered, 1 if down/triggered). If pen switch is down, the X and Y positions are updated. If a mouse driver is installed, the light pen driver will no longer work. The MOUSE function will then return the mouse position and buttons instead of the light pen, still updating position only when a button is pressed. MSDOS'" Appendix A-64 MSDOS APPENDIX FORMA T MOUSE ( expression ) DEFINITION This statement is used to show and hide the mouse cursor. It is only used for the mouse driver (i.e. DEF MOUSE = 0; see "DEF MOUSE Statement" in this appendix). The expression defines the operation as follows: MOUSE(4) MOUSE(5) Show mouse cursor Hide mouse cursor " expression is not 4 or 5, the statement is ignored. EXAMPLE X=I MODE 7 I=MOUSE(O) NOUSE (4) <--- Reset mouse hardware <--- Let's see that mouse cursor "Mouse" DO IF LEN (INKEY$) THEN STOP <--- Press a key to stop PLOT MOUSE(I), MOUSE (2) UNTIL MOUSE (3) <---Press mouse button to toggle Mouse cursor X=X*-I <--- Toggle mouse cursor IF X>O THEN MOUSE(4) ELSE MOUSE(5) GOTO "Mouse" REMARK It is important to note that the number of calls to one of the mouse statements must be equal to the number of calls to the other to get the cursor to the same state. For example, if MOUSE(5) is called 10 times to hide the cursor, then MOUSE(4) must be called 10 times to show the cursor. Also, ZBasic initially resets the mouse and leaves the cursor off (same as the MOUSE(O) function); one call to MOUSE(4) will tum the cursor on. This cursor can only be seen in ZBasic MODE's 5,7,13,15,16. A-65 MSDOSTM Appendix MSDOS APPENDIX 1I,81.i'Mt.'@11. . . . . . . .41DfM&11ij'immljf,jtwtful] ON COM ERROR GOSUB statement FORMAT ON COM ERROR GOSUB line DEFINITION Used to cali an error routine when an error is detected while reading data from the communications ports. EXAMPLE OPEN"C l1 , -1, 1200" ",,20000 ON COM ERROR GOSUB "COM Error Routine" "COM Error Routine U PRINT"A Conununications error has occurred!" PRINTItThe error is: 11. X=USR5 (-1) <--- Change to -2 if other port is being used SELECT CASE X CASE AND 2 A 9 <--- See USR5 for errors associated with bits 9-12 PRINT"Overrun Error" CASE AND 2 10 A PRINT"Parity Error" CASE AND 2 ll PRINT"Framing Error" CASE AND 2A12 PRINT"Break detect" CASE ELSE PRINTItUnKnown Error!1t END SELECT INPUT"ontinue or top?";temp$ temp$=UCASE$(temp$) IF temp$="C" THEN RETURN END A REMARK See COM BUFF, COM ON, COM OFF, OPEN "C" and USR5(-1) in this appendix for details. Also see OPEN"C" in the main reference section for other information. MSDOSTM Appendix A-66 MSDOS APPENDIX 8%UAW ON INKEV$ statement FORMAT ON INKEY$( expression ) GOTO line# ON INKEY$( expression ) RETURN DEFINITION This statement is used to control the action when a function key is pressed. ZBasic supports 20 of the function keys on the IBM standard keyboard. Table 1 on the next page shows the function keys and the corresponding number associated with each. When using the ON INKEY$ statement, expression determines which function key is being defined according to Table 1. The function key is not actually recognized until a ZBasic keyboard function is implemented, such as INPUT, LINE INPUT, and INKEY$ function. When the GOTO is used, the line# specifies where the program will continue execution alter the function key is hit. When RETURN is used, the function key is no longer implemented. All function keys are disabled until the INKEY$O statement is used. See "INKEY$O statement" in this appendix for more information. EXAMPLE ON INKEY$(l) GOTO "Fl" ON INKEY$(2) GO TO "F2" INKEY$(l) "Event Loop" I$=INKEY$:IF 1$="5" THEN STOP GOTO "Event Loop" INKEY$(O) IfFl" PRINT "Fl":GOTO "Event Loop" "F2" PRINT "F2":GOTO "Event Loop" END REMARK Remember to use the INKEY$(1) statement to enable the function keys; otherwise, ZBasic doesn1 check to see if the ON INKEY$O statement was used. See "INKEY$O" statement in this appendix. continued ... A-67 MSDOSTM Appendix MSDOS APPENDIX ON INKEY$ statement continued When a GOTO is made from a function key, the current program execution is terminated and then restarted at the location specified in the ON INKEY$O GOTO statement. Thus this program location cannot be nested in a subroutine' If a RETURN is executed before a GOSUB, the program will stop and ZBasic will return to the editor (or the operating system if in a compiled program). The following is a list of the function keys supported by ZBasic and the numbers with which each key is associated. The ON INKEY$ column refers to the number of each key in the ON INKEY$( expression) statement. The INKEY$ column is the value that the INKEY$ function will return when the function key is not implemented (see INKEY$ function in the this appendix). TABLE 4: Function Key Codes KEY F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 ON INKEY$ 1 2 3 4 5 6 7 8 9 10 HOME 13 CURSOR UP 14 PAGE UP 15 CURSOR LEFT 17 CURSOR RIGHT 19 END 21 CURSOR DOWN 22 PAGE DOWN 23 INSERT 24 DELETE 25 INKEY$ 59 60 61 62 63 64 65 66 67 68 71 72 73 75 77 79 80 81 82 83 MSDOSTM Appendix A-68 MSDOS APPENDIX OPEN "c" ,{ -1 I -2} "e" statement FORMAT OPEN (.(baud ]I,(parity ](.(stopbit ]I,(word length ](,(status ](,(control ](,buffer sizelllllll DEFINITION The OPEN "C" statement has three additional parameters more than is provided with the Standard ZBasic, ·Status and· Control; can be used to control the handshaking on the RS-232 cable when writing to the port - modem status and modem control. The modem status and modem control parameters indicate the following: Bits :1 716 Is 14 13 12 11 I 0 I II ~I ! l'·'·"~ L..:; Delta Data Set Ready Trailing Edge Ring Indicator Delta Rx Une Signal Detect Clear to Send (CTS) •••• Data Set Ready (DSR) .... L -_ _ _ _ _ _ _- i .. Ring Indicator L S I ' - - - - - - - : : - - - - -... Receive Una Signal Detect Modem Status Bits :1 71 61 Sl 41 31 211 I 0 I II ~. ~:~~est ~II ! 1~'..m-,~ to Send (RTS) •.- Out 2 Loop not used L----------i~ not used ' -_ _ _ _ _ _ _ _ _• not used Modem Control The default bits for these two parameters are shown by the four asterisks (•••• ) after the bits set. This makes the default values &'<0011.0000 (or 48 decimal) for modem status and &X00000010 (or 2 decimal) for modem Control. ( t • buffer size is used for loading incoming data with COM ON and COM OFF. COM ON is automatically executed when OPEN"C" is used. The buffer defaults to 256 bytes but may be configured up to 32,700 bytes. Also see ON COM ERROR GOSUB and COM BUFF. continued ... A-69 MSDOSTM Appendix MSDOS APPENDIX OPEN"C" statement continued EXAMPLE OPEN "C",-1,300""O This will force ZBasic to ignore the signal lines DSR and CTS when writing to the port. This will normally work at 300 baud. REMARK It is important to note that all of these optional parameters affect both COM1 and COM2. When a character is written to the COM port, ZBasic does the following: 1) Sends an indicator to the modem control register using the value given in the modem control parameter. This is usually a Request to Send (RTS). 2) Waits for the appropriate signals from the modem status register given in the modem status parameter. These are usually Data Set Ready (DSR) and Clear to Send (CTS). 3) Waits for the transmitter holding register to be empty and then sends the character to the port. If the default parameters do not work properly on your machine, try setting the Data Set Ready and/or Clear to Send bits to zero and/or tuming the Data Terminal Ready bit to one. Also see COM ON, COM OFF, COM BUFF, ON COM ERROR GOSUB, USR5 and the chapter in this section call "RS-232 Communications". Also see OPEN"C" in the main reference section for other information. MSDOf3TM Appendix A-70 MSDOS APPENDIX -MAt PAGE LPRINT statement (Screen Dump) FORMAT PAGE LPRINT DEFINITION A screen dump to the printer will occur if the PAGE LPRINT statement is executed. This statement is the same funclion as typing "Shift-PrtSc" from the IBM keyboard. EXAMPLE PRINT"HELLO" PAGE LPRINT END This will cause the entire screen image to be dumped to the printer. REMARK This statement is most useful for printing screen graphics created by ZBasic. Graphics are not normally dumped to the printer, however. The program "GRAPHICS.COM" that comes with MSDOS must be run before using the program in order to install the graphics printer driver. See the MSDOS reference manual for more information. Requires IBM PC compatible screen dump routines. May not function on not-socompatibles. A-71 MSDOSTM Appendix MSDOS APPENDIX tP.Mj• • •liiiN.*. . . . . . .¢IIBt#t+fh'a PAINT statement FORMAT PAINT (x,y) DEFINITION Fills a section of the screen with the current color. Same as the ZBasic FILL statement. PAINT will use the default coordinate system of 1024x768. If you wish to use pixel coordinates, or your own coordinate system, use the COORDINATE ststement in the beginning of your program (see coordinate in the main reference section). EXAMPLE CIRCLE 512, 383, 300 COLOR 3 PAINT (512,383) END REMARK See FILL, GET, PUT, PLOT, BOX FILL, CIRCLE FILL, PALETTE, MODE, COLOR (in this appendix and in the front reference section), COORDINATE WINDOW and the section in the front of this manual entitled "Graphics". Note: BOX FILL and CIRCLE FILL are much faster than PAINT or FILL. In some modes COLOR, attribute can be used to set the color of the background. This is also much faster than FILL or PAINT when the entire background needs to changed. MSDOS'" Appendix A-72 MSDOS APPENDIX PALETTE statement (EGAonly) FORMAT PALETTE attribute, c%r DEFINITION Changes a color in the EGA color palette. This statement will only work with PC's equipped with an EGA card. attribute color EXAMPLE 0-15 0-63 COLOR = 1 CIRCLE 100,100,50: REM draw a blue circle DELAY 2000: PALETTE 1,2 REM the circle will instantly change to green and all REM subsequent writes with color =1 will show REM as green. REMARK This statement allows the user to select a palette of 16 colors out of 63 available colors. The PALETTE statement works only on systems with the Enhanced Graphics Adaptor (EGA). Each attribute is paired with an actual display color. A-73 MSDOS'M Appendix MSDOS APPENDIX 1}}NfWg~I}!tt}}}1lififliJ{I,}I%_I.')iirfr*w#}$Mt_Jiifttll}}ttl}'jl.lf»1ii;(}weJiJ PATH$ function FORMAT PATH$ (drive number) DEFINITION The first format returns a string containing the current path of the specified drive. drive drive drive drive drive EXAMPLE A$ number;O number;1 number;2 number;3 number;4 default drive, drive A: drive B: drive C: drive E: etc. = PATH$ (0) PRINT "Current Path ";A$ RUN Current Path; REMARK C:\ZBASIC\TEMP This can be used to save the current directory, so that the programmer can change to other directories (with the CHDIR statement) and have a way of retuming to the original directory. See also CHDIR. See PATH in the main reference section. MSDOSTM Appendix A-74 MSDOS APPENDIX PEEK function FORMAT PEEK [ WORD I ( address [ , segment I) DEFINITION This statement is used to read a particular address in memory. The address is actually the offset into the segment given by segment. If the segment parameter is not given, then the data segment used by ZBasic will be used as the segment. EXAMPLE PEEK WORD (&HOOCC, 0) Returns the mouse interrupt vector. PEEK (0, &HB800) Returns the first location on the screen. PEEK WORD (VARPTR(I» Returns the value of the variable I. REMARK By specifying the segment, every address available on the IBM PC can be accessed. The PEEK is done much faster, however, when the segment is not given. This statement is most frequently used in directly accessing screen memory (although IBM does not recommend doing this). For this purpose, use &HBOOO for the segment if you have the monochrome adapter, and &HB800 if you have the color graphics adapter or EGA in CGA modes. A-75 MSDOSTM Appendix MSDOS APPENDIX PLOT USING statement x, Y, string [, magnification I FORMAT PLOT USING DEFINITION This statement is used to plot a set of pixels on the screen in a pattern defined by string starting at the location X, Y. The starting location X, Y defines a point on the screen according to the ZBasic graphic coordinate system. The simple string string tells ZBasic where to plot each point corresponding to the one before it. The following characters are accepted: "UDLRHIJK", which control direction, and "+" or "-", which turn plotting on and off. The letters specify direction as follows: H U I L + R K EXAMPLE D J PLOT USING 512,383,"UUUURRRDDDDLL" This example plots a rectangle in the middle of the screen. PLOT USING 512,383,"UUUU-RRR+DDDD",2 This example just plots the vertical halves of the rectangle in the previous example and twice as big. MODE 7 <--- Change MODE for your system. A$="UUURRRRRRDDDLLLLLL" FOR X= 1 TO 90 STEP 5 COLOR=-l PLOT USING 0, 767, A$,X COLOR=O PLOT USING 0, 767, A$,X NEXT END REMARK The PLOT USING statement only works in ZBasic graphic MODEs 5, 7, 13, 15, 16, 17,18,19 and 20 unless ZBasic is configured to not have IBM compatible graphics, in which case the PLOT USING function is oompletely disabled. Each pixel is plotted in the color last set by the COLOR statement; thus, a pattern can be erased by setting COLOR = 0 and replotting. When turning the plotting back on with a "+" imbedded in the string, note that the pixel at that point is plotted. Note: This statement is similar to the DRAW statement found in BASICA. MSDOSTM Appendix A-76 MSDOS APPENDIX j; ii! UJ,,, POKE statement FORMAT POKE [WORD I address ,data DEFINITION This statement is used to set a particular address in memory to a value determined by data. [, segment I The address is actually the offset into the segment given by segment. If the segment parameter is not given, then the data segment used by ZBasic will be used as the segment. EXAMPLE POKE WORD &HOOCC,LINE 10,0 Sets the mouse interrupt vector to line 10 (not recommended!). POKE O,ASC("A"),&HB800 Sets the first location on the screen to "A". POKE WORD VARPTR(I%),0 Sets variable 1% to O. REMARK By specifying the segment, every address available on the IBM PC can be accessed. The POKE is done much faster, however, when the segment is not given. This statement is most frequently used in wr~ing directly to screen memory (although IBM does not recommend doing this). For this purpose, use &HBOOO for the segment if you have the monochrome adapter, and &HB800 if you have the color graphics adapter or using the EGA card in CGA mode. A-77 MSDOSTM Appendix ...........MSDOS .,.t...APPENDIX ifllt£'.witI3%1t.ill RENUM* command FORMAT RENUM* new, old, increment DEFINITION Adds line numbers to programs without line numbers. The compliment of UNNUM. EXAMPLE FOR X=l TO 100 PRINT X NEXT END RENUM* LIST 10 FOR X=l TO 100 20 PRINT X 30 NEXT 40 END REMARK Also see UNNUM, FIX and INDENT in this appendix and RENUM in the main reference section. MSDOSTM Appendix A-78 ------ MSDOS APPENDIX RMDIR statement FORMAT RMDIR pathname DEFINITION Removes a directory. Only empty directories may be removed. EXAMPLE RMDIR "Mydirect" IF ERROR=11 THEN PRINT"Does not exist ! ":ERROR =0 REMARK Also see PATH$, CHDIR and RMDIR. Note: If an error is encountered when doing CHDIR, RMDIR or MKDIR ZBasic returns an error eleven (11) in the ERROR function. See ERROR function, ERROR statement, ON ERROR GOSUB and the chapter "Disk Error Trapping" in the front of this manual. A-79 MSDOSTM Appendix MSDOS APPENDIX ~lfwlflf.~flt_'8'Mf*.iW¥¥lfI_it_f~i• •}.}$,§o/ti*'lm SCREEN function FORMAT SCREEN (row, column [, color]) DEFINITION If color is zero or is not used this function returns the ASCII code for the character on the active screen at the specified row and column. Only valid in text modes. If color is used and is non-zero the color of the character at the screen location specified by row and column is returned. lOW expression from 0-24. column expression from 0 - 39 or 0 - 79, depending on current mode. color an expression that evalutes to a true (not zero) or false(zero) The upper left comer is defined the same way as the LOCATE function (see "Special MSDOS Configuration Options" in this appendix). The number returned when using the color parameter may be interpreted as follows: (number MOD 16) (( ( number- forground) / 16) MOD 128) EXAMPLE ; foreground color ; background color A = SCREEN (9,9) REM If character at poSition 9,9 is "8", A will equal 66 A = SCREEN ( 2,2,1) REM The variable A will equal the color attribute of character at position 2,2 REMARK Also see COLOR, SCREEN statement and MODE. MSDOSTM Appendix A-80 MSDOS APPENDIX SCREEN statement FORMAT SCREEN mode number DEFINITION Allows changing from one graphic type to another. Similar to ZBasic's MODE statement (added for compatibility to other BASIC languages). mode number 0,1,2,7,8,9,10. ZBaslc MODE o 5 1 2 7 8 10 9 7 16 17 18 19 EXAMPLE SCREEN mode number equivalent 2 CLS SCREEN 0 PRINT "HELLO" END Prints "HELLO" in monochrome mode. Same as MODE 2 using ZBasic MODE statement. REMARK A-81 See MODE, PALETTE, VIEW SCREEN, DEF PAGE READ, DEF PAGE WRITE, SCREEN function, COLOR and the chapter on graphics in this section. MSDOSTM Appendix MSDOS APPENDIX SHEll statement (CALL) FORMAT SHELL string DEFINITION The SHELL statement followed by string will load and execute another program specified by string. If a null (empty) string is specified. then MSDOS will be loaded and executed. in which case typing EXIT in DOS will return to ZBasic. This is identical to the old ZBasic CALL string statement. String must be either a string variable or a quoted string. EXAMPLE SHELL "DISKCOPY A: B:" This will perform a diskcopy as if it was typed in from the DOS command line. SHELL This will go directly into DOS and give the DOS prompt. SHELL "ZBASIC" This will actually load and execute ZBasic. Typing QUIT will then return to the original ZBasic. A$ = "DIR A:*.BAS": SHELL A$ This will get the directory of all .BAS files on the A drive. REMARK This statement can be very useful for executing batch files -- just use the name of the .BAT file (batch file) for string. There must be at least 17k of memory free to use the SHELL statement. If COMMAND.COM is not found. the message "File not found" will be echoed to the display and control will be returned to ZBasic. MSDOSTM Appendix A-82 MSDOS APPENDIX ; i TFORMAT statement (Herculesll!> or Hercules Plusll!> graphic boards only) FORMAT TFORMAT [=] expression DEFINITION The TFORMAT statement is used to set the text format when using text in the Hercules graphics MODE 20: The values for expression: o 1 2 EXAMPLE Reverse video normal (PSET); Overlays graphics XOR mode. XOR text over background. , Make sure ZBasic (or your program) was loaded using the , ZHERC.BAT batch file (or your own batch file) so that the , HERC.COM text driver is loaded into memory first. MODE 20: REM Hercules graphics mode ONLY! TFORMAT=l PRINT"HELLO" <--- Regular text TFORMAT=O PRINT"HELLO" DELAY 2000 MODE 2 END <--- Reverse text <--- Back to MODE 2 for editing RUN HELLO HELLO <--- Prints in black on white REMARK A-83 Also see MODE, and the section about "Hercules and Hercules Plus Graphics" in this appendix. MSDOSTM Appendix MSDOS APPENDIX TIME$ statement [hour] [. [minute] [,second]] FORMAT TIME$ DEFINITION This statement is used to set the current time. Any of the three parameters can be omitted, in which case the parameter will not be changed. The following values are accepted: = hour: minute: second: EXAMPLE 0 - 23 0 - 59 0 - 59 PRINT TlME$ TlME$ = 17,0,0 PRINT TlME$ END RUN 16:33:12 17:00:00 REMARK If any of the parameters used are not in the accepted range, the current time will not be changed. TIME$ = ,,0 This only sets the seconds to zero, not destroying the current hours and minutes. See TIME$ function in the main reference section. MSDOS'M Appendix A-84 MSDOS APPENDIX TIMER function FORMAT TIMER DEFINITION Returns the number of seconds elapsed since midnight. EXAMPLE STARTiI = TIMER FOR X = 1 TO 32000:NEXT FINISHiI = TIMER TiI= FINISHiI - START# PRINT "The loop took ";TiI;" seconds" RUN The loop took 2 seconds REMARK A-85 Since the number of seconds elapsed since midnight can be greater than 65535, the variable must be BCD. The TIMER function can also be used to re-seed the random number generator when used with the RANDOMIZE statement. MSDOSTM Appendix MSDOS APPENDIX UNNUM command FORMAT UNNUM DEFINITION Removes line numbers from lines that are not referenced elsewhere in the program by a GOSUB line number, GOTO line number etc. Extremely useful cosmetic command for removing unsightly line numbers from your old BASIC programs (we should have used this sentence in our advertisements). EXAMPLE 10 20 30 35 40 FOR X=l TO 100 PRINT X NEXT GOTO 10 END UNNUM LIST 10 FOR X=l TO 100 PRINT X NEXT GOTO 10 END REMARK Also see RENUM* in this appendix and FIX and INDENT. MSDOSTM Appendix A-86 MSDOS APPENDIX USR1 function (Check End Of File status) FORMAT USR1(fiIenumber) DEFINITION USR1 is a predefined user function available on the IBM PC. This user function is equivalent to the EOF(filenumber) function. The result is -1 if end of file, 0 otherwise. Use the EOF function instead. This is retained only for compatibility with older versions of ZBasic. See EOF in the main reference section of this manual. USR2 statement (Set the the clock constant) FORMAT USR2 ( expression ) DEFINITION USR2 is a predefined user function available on the IBM PC version. USR2 is used to control the 1millisecond time constant used in the DELAY statement. The ZBasic DELAY statement should delay a specified number of milliseconds (1/1000 of a second). This delay time is, however, very dependent on the actual speed of the computer. The delay time constant defaults to a 1ms delay on the IBM PC (i.e. 4.77 megahertz clock speed using the 8088 microprocessor). If using ZBasic on a different speed computer, then use the USR2 statement to adjust the time constant. IBM PC faster computer slower computer ---> ---> ---> expression = 300 use a larger expression use a smaller expression This delay time constant is also used in the SOUND statement to specify the duration. EXAMPLE USR2(470) This will set the time constant to 470. This is the value used on the IBM PCIAT to correct the delay times. REMARK A-87 This time constant can also be altered in configuration, which would change the default value. See "MSDOS Specific Configuration Options" in this appendix. MSDOSTM Appendix MSDOS APPENDIX USR3 function (Check keyboard status) FORMAT USR3(expression) DEFINITION USR3 is a predefined user function available on the IBM PC. This user function is used to control keyboard input and status as follows: USR3(O)---> Returns the next character struck from the keyboard. The ASCII code is returned in the lower 8 bits. The keyboard scan code is returned in the upper 8 bits. USR3(1 )---> Scans the keyboard buffer. Zero is returned ~ no key was struck. If there is a key in the buffer, the ASCII and scan codes are returned same as USR3(O), except the character will remain in the buffer. USR3(2)---> Returns the current shift status. The bits returned are as follows: °Bit7 OBitS OBitS °Bit4 Bit3 Bit2 Bit1 BilO Insert key active Caps Lock key toggle Num Lock key toggle Scroll Lock key toggle Alternate key depressed Control key depressed Left Shift key depressed Right Shift key depressed °Note: You can toggle the Insert, Caps Lock, Num Lock and Scroll Lock keys with the following statement: POKE &17, PEEK(&17,&40) XOR (2 bit), &40 A (bit= 4-7 corresponding to the keys with bits 4-7 above). EXAMPLE DO UNTIL USR3(1)<>0 A$=INKEY$ This is the same as DO: A$=INKEY$: UNTIL LEN (A$) , exceptthe above example is much faster. DO PRINT@(O,O) BIN$(USR3(2»; UNTIL INKEY$="Q" This example will print the individual status bits on the screen. Pressing the keys specified in the list above shows the response of the status bits. REMARK Remember that USR3( 1) does not take the character out of the buffer. This can be useful for checking the keyboard for a specific key before going into a standard input routine, such as INPUT or INKEY$. MSDOSTM Appendix A-88 MSDOS APPENDIX iN USR4 statement (Jump on CTRL C or CTRL BREAK) A-89 FORMAT USR4 ( address ) DEFINITION USR4 is a predefined user function available on the IBM PC version. USR4 is used to set the clrl-break address (or ctrl-C) when one is detected. The address specified must be in ZBasic's code segment. EXAMPLE USR4(LINE 20000) This sets the ctrl-break address to be ZBasic's line 20000. In this case, if during program execution a ctrl-break is detected, a jump will be made to line 20000. REMARK When USR4 is used to set the ctrl-break address, it must be understood that the program still cannot continue normal execution after the break is detected. The register and stack will be unpredictable; thus, the subroutine at the break address should finish with a stop or end to exit the ZBasic program. MSDOSTM Appendix MSDOS APPENDIX USR5 function (Get Communication port status) FORMAT USRS( -lor -2) DEFINITION USR5 is a predefined user function available on the IBM PC version. USR5 is used to return the status on either of the communication ports (see OPEN "C"). The status bits returned are defined as follows: Status 1I ne EXAMPLE Bit 15 Bit 14 Bit 13 Bit 12 Bit 11 Bit 10 Bit 9 Bit 8 = Time Out = Trans Shift Register Empty = Tran Holding Register Empty = Break Detect = Framing Error = Parity Error = Overrun Error = Data Ready Modem Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 = Received Line Signal Detect = Ring Indicator = Data Set Ready = Clear To Send = Delta Receive Line Signal Detect = Trailing Edge Ring Detector = Deija Data Set Ready = De~a Clear To Send <--- <--- These bits checked with ON COM <--- ERROR when a communication <--- error occurs. Status J=USR5 (-1) This gets the status of the communications port 1 (COM1). REMARK This function can be useful in investigating the RS-232 control. "there is a problem with the 232 communication (such as mismatched baud rate, parity error, time out, or cable hookup), it can be evident by observing the status via the USR5 function. See "RS-232 COMMUNICATION" in this appendix for more information. Also see OPEN"C", COM ON, COM OFF, COM START, COM END and ON COM ERROR GOSUB in this appendix. Also see OPEN"C" in the main reference section. MSDOS'" Appendix A-90 _.ff... MSDOS APPENDIX ilt.Mffirjii;W;!ilili::iiWiii tw:m\;;;!:::II:::M8WlWMj VARPTR function VARSEG function FORMAT VARPTR (variable) VARSEG DEFINITION This pair of functions is used to determine the memory address of a variable. VARPTR (variable) returns the offset of the variable. VARSEG returns the segment of variable. EXAMPLE DIM A$(400) AS (400) = "HELLO" A = VARPTR (A$(400»: B = VARSEG: PRINT PEEK(A,B) : PRINT CHR$(PEEK(A+l,B» REM REM REM REM gets the offset gets the segment print the length print the first char. RUN 6 H REMARK Because of the enhanced variable memory capability of this version of ZBasic, the VARPTR function is slightly different from previous versions. In earlier versions, the variables were put in one 64K segment which began at the data segment ( OS). The address was returned in one 16-bit number. Now in 4.0 integers, BCD's, strings and BCD/string arrays are given there own dedicated block of memory so that more data can be stored. Therefore, two numbers are needed; one for the offset; one for the segment. The VARSEG function returns the segment of the last variable used with VARPTR. Its value is valid only immediately after a VARPTR has been executed. A-91 MSDOSTM Appendix MSDOS APPENDIX ~• •*l)llal}i*.\%Wl.i.&.l§W&IIWI'I.ffl.}.&;;tMl'i4f.t.Jf,fj)l VIEW PRINT statement FORMAT VIEW PRINT topline TO bottomiine DEFINITION Used to the set scrolling bounderies. topline bottomline The top line to be used for output. The last line to be used for output. This statement is very similar to the ZBasic DEF PAGE statement which also allows setting the column bounderies as well. EXAMPLE CLS VIEWPRINT 5 TO 10 LOCATE 0,5 <--- Set cursor to first line position DO PRINT"HELLO l1 i UNTIL LEN(INKEY$) END Demonstrates how the text is retained within the row limits. REMARK Also see DEF PAGE. MSD05TM Appendix A-92 MSDOS APPENDIX WAIT statement FORMAT WAIT portnumber, AND expression [, XOR expression 1 DEFINITION Suspends program execution while checking the status of an input port. portnumber AND expression XOR expression numeric from 0-65535. integer from 0-255 integer from 0-255 EXAMPLE WAIT Port (x) , 255,255 REMARK The WAIT statement causes execution of the program to be suspended until a specnied port produces a certain bit pattem. The data read at the port is XORed with the XOR expression, the ANDed with the AND expression. If the result is zero the program loops back to read the port again. CAUTION: The computer may lock up n the required bit pattern does not appear on the port. A·93 MSDOSTM Appendix MSDOS APPENDIX ASIC FULL SCREEN EDITOR ZBasic 4.0 includes a powerful, yet simple, built in full screen editor for editing program text. To toggle between the Full Screen Editor and the Standard line Editor, use the key. DIFFERENCE BETWEEN THE FULL SCREEN AND STANDARD LINE EDITORS STANDARD LINE EDITOR This editor is provided for two reasons; • The user may enter direct commands quite like a BASIC interpreter. You can enter things like PRINT ASC(A) and ZBasic will return 65. Math expressions may be entered like ?SQR(9) and 3 will be returned. See the section in the front of this manual call "Standard line Editor" for detailed information about this editor. • The Standard line Editor works the same way on all versions of ZBasic inlcuding Apple II, CPIM, Z80 and Macintosh. This allows a common interface that someone may use that doesn't have the time to learn all the Full Screen Editors provided. Note: If you opt to disable line numbers you will need to do all the editing in the Full Screen editor since EDIT requires a line number. FULL SCREEN EDITOR The full screen editor is provided to make entering and editing program code easy and fast. The following two pages describe the commands used with this editor. continued ... MSDOsrn Appendix A-94 MSDOS APPENDIX FULL SCREEN EDITOR Following is a list of command keys and control keys. Take a few minutes with the editor to become familiar with what these keys do. MOVING THE CURSOR KEY ft II CURSOR MOVEMENT <= => UP a line DOWN a line LEFT one character RIGHT one character Ctrl<= Ctrl=> LEFT A WORD RIGHT A WORD Home End BEGINNING OF LINE END OF LINE Ctrl-Home TOP OF TEXT (beginning or start of program text) Ctrl-End BOTTOM OF TEXT (end of program text) Pg Up Pg Dn PAGE UP PAGE DOWN DELETING TEXT KEY Delete ACTION DELETE character under cursor Ctrl-E ERASE TO END OF LINE INSERT MODE or OVERWRITE MODE KEY Insert A-95 MSDOSTM Appendix ACTION Toggles between INSERT mode and OVERWRITE mode. Insert mode inserls text at the current cursor poSition. Overwrite mode allows you type over the text under the cursor. (cursor is thicker in insert mode) MSDOS APPENDIX FULL SCREEN EDITOR COMMANDS The Full Screen Editor commands are easy to leam. Spend a few minutes trying out the various commands. You will notice that the function key commands are displayed on the bottom of the screen. When you press the ALT key the alternate set of commands is displayed. FUNCTION KEY EDITOR COMMANDS Editor Keys Definitions F1 LOAD file ALT F1 SAVE file F2 ALT F2 F3 ALT F3 F4 ALT F4 F5 ALT F5 F6 ALT F6 F7 ALT F7 F8 ALT F8 F9 ALT F9 F10 ALT F10 CUT line into buffer (for use with PASTE! REPLACE) PASTE line from buffer to the current line COpy line into buffer without erasing REPLACE current line with line in buffer INSERT a new line after current line DELETE current line FIND texl. See FIND in main reference section FIND NEXT occurence Set TAB value for indenting AUTO TAB on/off. Toggles carriage retum positioning RESTORE line to condition before changes made LLiST to printer SCROLL screen text up (does not move cursor) SCROLL screen text down (cursor doesn't move) FREEZE top of screen (press again to unfreeze) FREEZE bottom of screen (press again to unfreeze) Return to Standard Line Editor NEW. Erases all text in text buffer Note: Programmers that use ZBasic on both the Apple and IBM should notice that the key sequences correspond to the open and closed Apple sequences so switching from one machine to another is much less confusing (of course the Standard Line Editor commands are the same). MSDOsm Appendix A-96 zao APPENDIX 8-1 Z80 Appendix tAl: EM zao APPENDIX ASIC L-nl -'" Zao™ Versions TRS-80™ Models; 1, 3 and 4, CP/MTM-80 2.2, 3.0 and CP/MTM-80 Plus by Andrew Gariepy © Copyright, 1985, 1986, 1987 ZEDCOR, INC. All Rights Reserved ZBasIc is a registered trademark of Zadcor. Inc. ZSO is a registered trademark of Zilog, Inc. TAS-SO Is a registered trademark of Tandy Corporation CP/M [s a registered trademark of Oigltal Research Incorporated Z80 Appendix 8-2 zao APPENDIX M . . . . . . . . . . . . . .. TABLE OF CONTENTS Table of Contents 83 Flies on the Master Diskette 84 Getting Started TRS-80 Model 1 TRS-SO Model 3 TRS-80 Model 4 CP/M Kaypro 85 85 85 85 85 85 Notes on the Z80 Version Memory Filenames Sound Z80 ICON Z8asic DEMO program Schools Graphics Mouse Help CALL "string" (TRS-80 versions only) COLOR TIME$/DATE$ 86 86 86 86 86 86 87 87 87 87 87 87 87 Z80 Disk Formats TRS-SO CP/M 88 88 Z80 Optional Binary Math Package B-3 Z80 Appendix 88 89 Executing ZBaslc 810 Z80 Specific Configuration Options TRS-80 Specific Options CP/M Specific Options 811 Using the Patch Utility 815 Memory Considerations Memory Map 816 RS-232 Communications 818 Jump Tables 819 Default USR Routines 820 Using Overlays instead of Chaining Overlay Example 821 822 Z80 MODE Chart 823 812 813 817 zao APPENDIX FILES ON THE MASTER DISKETTE SYSTEM FILES ZBASIC FILENAME ZBASIC.COM DESCRIPTION This is the main ZBasic compiler and editor. Just type ZBASIC to execute. Note: On TRS·80 the file is called ZBASIC/CMD. THE FILE ABOVE IS THE ONLY ONE REQUIRED TO RUN ZBASIC THE FILES BELOW ARE OPTIONAL AND MAY BE DELETED FROM WORKING DISKETTES EXAMPLE FILES DEMO FILENAME ZBDEMO.COM DESCRIPTION A limited demo version of ZBasic (public domain). Feel free to give it away to your friends, relatives and co-workers. This and ZBAS IC. HLP may be given away together (please do not give away any other programs on this disk). Note: ZBDEM013 on the TRS-80 model 4 version is the Model 1 ,3 demo. HELP ZBASIC.HLP This is the help file. It is not necessary for using ZBasic but is helpful when leaming ZBasic syntax. Just type HELP from the editor to get a menu of the help available. DISK I/O DISKIO.BAS Example of using ZBasic disk file handling (DTEST on some disks) GRAPHICS ZROSE.BAS Does a graphic "Rose" using High-speed and regular speed SIN and COSINE routines. (GTEST on some Z80 versions). Not included with all Z80 versions (storage limitations). Graphic clock example (most versions). Bar and Line Graphs in Device independent Graphics. CLOCK APPLE.BAS SORT ROUTINES SORT.BAS SHELL.APP QUICK.APP MATH FUNCTIONS SCIFN.APP This routine creates random data for arrays to demonstrate the SHELL and QUICK sort routines on this disk. Load this program firstthendoAPPEND 1000 SHELL.APP (or QUICK.APP) The SHELL SORT that appears in the manual (under "Array variables.) A powerful sort when less items are used. The QUICK SORT that appears in the manual (under "Array variables.) A powerful sort when many elements need to be sorted. Examples of creating your own functions with ZBasic. NOTE TO FILENAME SUFFIX SYNTAX: Filename suffixes will vary depending on the disk operating system being used. Syntax above is for CP/M. If you have a TRS· 80 the suffix differs: ZBASIC.COM and ZBDEMO.COM become ZBASIC/CMD and ZBDEMO/CMD respectively. The period is changed to a slash for all the other files above; SORT. BAS becomes SORT/BAS ... Z80 Appendix 8-4 zao APPENDIX GETTING STARTED TRS-SO MODEL 1 1. Make a backup and put the original in a safe place. 2. Read this appendix, making notes of any variations for the Modell. 3. Follow the instructions under "Getting Started" in the main reference manual. TRS-SO Model 3 1. 2. 3. 4. Since this diskette is in TRS-80 Model one format, you MUST use the CONVERT utility to transfer the files on the master diskette to model 3 diskettes. After converting the files make a backup of that diskette and put it and the master disk in a safe place for future use. Read this appendix, making notes of any variations for the Model 3. Follow the instructions under "Getting Started" in the main reference manual. TRS-SO MODEL 4 1. 2. 3. Make a backup and put the original in a safe place. Read this appendix, making notes of any variations for the Model 4. Follow the instruction under "Getting Started" in the main reference manual. CP/M-SO GENERIC 1. The diskette is provided on a Kaypro format Single sided-double density diskette. You will need a program like "Uniform™" to transfer the files over to your computer's diskette format if your drives will not read this diskette. ZBasic is also available on 8" format for an extra charge. Use the PIP utility to transter files to your CP/M diskette. 2. Make a backup of your newly created master diskette and put it and the original in a safe place for future use. 3. See "Special Configuration Options" in this appendix to set up ZBasic to work with your terminal type. You will probably need your terminal or computer hardware reference manual for control codes for Clear screen, cursor control and the sort. 4. Read this appendix, making notes of any variations for the Model 3. 5. Follow the instruction under "Getting Started" in the main reference manual. KA YPRO® CP/M 1. 2. 3. 8-5 Z80 Appendix Make a backup of your master diskette and put it, and the original, in a safe place for future use. Read this appendix, making notes of any variations for the Model 3. Follow the instruction under "Getting Started" in the main reference manual. zao APPENDIX NOTES ON THE Z80 VERSION MEMORY ZBasic 3.0 for the zao Versions is designed to run in a DOS environment (CP/M-aO or TRSDOS). The typical programming area available in a 48k to 64k machine is from 24k to 56k. ZBasic also has the capability of OVERLAYS which are explained later in this Appendix (this version will only use a single bank of 64k.) FILENAMES The filenames in ZBasic are the standard DOS filenames. (Disk Operating System). Example: TRSDOSTM ZBASIC/CMD PROGRAM/BAS:l MYPROG/BAS. SECRET: 0 A: PROGRAM. BAS B:MYPROG.BAS CP/MTM-ao ZBASIC.COM SOUND TRSTM-ao Model 4, 4p The range of frequencies for the internal speaker of the model 4 are limited to: 121,121 through 7,31. TRSTM-80 Model 1&3 The frequency range is from 100hz to 10,000 hz and is routed out the out the cassette port. Connect a speaker amplifier to the cassette port to get sound. See your Radio Shack dealer for priCing (about $10). CP/MTM-80 & Kaypro™ Since most CPIM systems do not support sound, SOUND is routed as CHR$(7) (tone will not vary). Check your users manual for sound capabilities and porting. Sometimes OUT (n) may be used. zao ICON -- JB"l Whenever you see this icon in the main reference section of the manual take note of it's contents. It is referring to a variation in the use of that command for one of the zao versions. ZBASIC DEMO PROGRAM There is a ZBasic demo program on your disk that may be copied and given away to friends called ZDEMO.COM or ZDEMO/CMD. This is a limited version of ZBasic that contains all the functions and is only limited by program size and saving object code. Feel free to give copies of the ZDEMO program and the ZBasic.HLP program to your friends. continued ... zao Appendix 8-6 Notes on zao continued SCHOOLS Schools may duplicate the ZDEMO/CMD program for teaching. This program is very useful in a classroom since, in most cases, a full blown language is rarely necessary. Note that this also cuts down the costs to schools (under no circumstances may the actual ZBasic program be copied for distribution). GRAPHICS Special graphics Modes: TRS-80™ Model 4, 4p This version will use the Radio Shack™ Model 4, 640 x 240 high-resolution graphics board and the Micro-Labs™ high-resolution board in MODES through 15 only. a TRS-80™ Model 1& 3 No High resolution modes are supported. CP/MTM-80 Graphics are not supported. All Graphics are emulated using text characters. See COLOR and CLS for changing the character type being used. KAVPRO II, 4, 10 SpecIal GraphIcs versIon Kaypro 160x1 00 Graphics are supported with this special CPIM version. Your Kaypro must have graphics for this version to work. MOUSE Does not function with this version. See "Patch" in this appendix for ways a mouse can be patched in. HELP FILE The file used in the ZBasic HELP command is called ZBASIC/HLP or ZBASIC.HLP. This file may be deleted to allow more room on the disk. If HELP is not on the disk, typing HELP from the editor will generate a "FILE NOT FOUND" error. CALL "string" Supported only in the TRSTM-80 Versions. This passes a DOS command to the operating system. Example: CALL "DIR". COLOR number All present versions use 0 (zero) as BLACK. Any other value will be WHITE or the ..... character. TIME$/DATE$ These commands are supported on the TRS-80 only. CPIM versions will return 00:00:00 and 00/00/00 respectively. B-7 Z8D Appendix zao zao APPENDIX Z80 DISK FORMATS The Z80 versions of ZBasic are provided on a specific disk format depending on the machine. The format descriptions are as follows: TRS-80 MODEL 1 & 3 Format: TRSTM-80 Modell 5 1/4 inch, 35 track, Single Sided, Single Density Modell Transfer: Model 3 Transfer: Modell TRSDOS 2.3 Boot ZBasic™ disk in drive O. The disk will copy all files to a formatted TRSDOSTh' 2.3 System Disk Model 3 (4 in 3 mode) TRSDOS 1.3 Use TRSDOSTM 1.3 or compatible CONVERT command to move files from the model 1 formated diskette to a model 3 compatible format. See instructions for CONVERT in your TRSDOS manual. TRS-80 MODEL 4 & 4p Format: TRSTM-80 Model 4 & 4p TRSDOS 6.0.2 5 1/4 inch, 40 track, Single Sided, Double Density (TRSDOSTM 6 Format) Transfer: Just copy files to your system disk. OTHER TRS-80 OPERATING SYSTEMS ZBasic can be copied over to most TRS-80 Disk Operating Systems like MultiDos, DosPlus, Newdos, and LDOS. CP/M-80 VERSIONS 2.2, 3.0 or PLUS Format: CP/MTM-80 version 2.2 or 3.0 5114 inch, 40 track, Single Sided, Double Density (KayproTM II Format) Transfer: If your computer cannot copy the ZBasic files over to your format using PIP, try using a transfer program to move files onto your disk format. Some popular transfer programs: Interchange™, Multidisk™, Uniform™. Once ZBasic is in your disk format it may copied like other files. SPECIAL KA YPRO GRAPHICS VERSION Format: KAYPROTM, CP/MTM-80 version 2.2 5 1/4 inch, 40 track, Single sided, Double Density Transfer: Use PIP to transfer programs onto your system disk. Z80 Appendix 8-8 zao .._-_...... APPENDIX zao OPTIONAL BINARY MATH PACKAGE Zedcor offers an optional Binary Math package that allows you to get faster execution times when doing floating point math. Contact Zedcor at 1-800-482-4567 if you want this optional package. While high speed floating math may be desirable, there are a number of trade-offs: • Speed increase of 10x is typical. Precision is not definable like BCD versions of ZBasic. Digits of accuracy for both single and double precision is 6.2 digits with a range of E±38. • Binary constants and variables require four bytes each for RAM and DISK storage. • Binary numbers are stored in a different format that BCD numbers. • MKB and CVB work with binary numbers only. • Speed increases are up to 10 times the speed of the BCD version. There is the typical binary rounding error factor (not in the regular version of ZBasic). ~ Note: Programs created with the binary math version of ZBasic cannot read files with BCD floating point created with the BCD version and vice-versa. The binary format is subject to change in future and other versions of ZBasic. Do not use PEEK or POKE on binary variables. Note: A# and A! are dnferent variables (even though single and double are the same precision). 8-9 ZBO Appendix zao APPENDIX EXECUTING ZBasic™ There are basically two ways of starting ZBasic from the operating system prompt. With CP/M the DOS prompt is A>or C> depending on the drive used. With TRSDOS ~ is DOS Ready. 1. Type: ZBASIC This is the standard way to startup ZBasic. See "GETIING STARTED" in the ZBasic standard manual. Also see "CONFIGURATION" in this appendix. 2. Type: ZWARM This is a special way to startup ZBasic to recover a ZBasic text program after a crash or reset. A version of ZBasic must be created using the arm start creator option from the ZBasic start up screen. To Create this WARM start version configure ZBasic for your machine and save using the ave option from the ZBasic startup menu. (DO NOT use your MASTER DISK only use a BACKUP COPY of your master diskette). Exit ZBasic using QUIT and re-enter the just created configured ZBasic and use the arm Start Creator option to create a WARM start version of ZBasic to be called (TRSTM-80: ZWARM/CMD ,CP/MTM-80: ZWARM.COM) which can be used to recover ZBasic program text after a RESET or program lock-up. Important Note: ZWARM will only recover a program if it is still intact in memory and has not been overwritten. This will not recover from a NEW as ~ erases the program. The ZBasic 3.0 patch option allows the user to PATCH specific addresses in ZBasic to Change areas in the JUMP TABLE for special hardware or software and to apply fixes to the actual program as specified by Zedcor to provide some special features. These changes may be saved by using the ave option from the start-up MENU. Z80 Appendix 8-10 zao APPENDIX zao 'W.6::i:miiiii:;i• •jWMWtfM#j SPECIFIC CONFIGURATION OPTIONS After typing "C" in the initial prompt screen, ZBasic will ask for the standard configuration parameters explained in the "Getting Started" section of the manual. Following these standard parameters are the Z80 specific configuration parameters. The additional prompts displayed are as follows: NOTE: Press to skip options. Press to exit «CTRL C> with CP/M). CONFIGURE OPTIONS ON ALL Z80 VERSIONS Default Clear nnnnn Size 03E8 01000 ? This selects the default amount of memory to be set aside for strings in the INDEX$ area at compile time. The actual amount of memory in the running compiled program can be found by using MEM function in the program. If this area becomes less than or equal to zero due to high memory drivers a 'Not Enough Memory' error will be displayed and the program will exit back to DOS. LIST First Line 0019 00025 When pressed as the first key on a line will cause the editor to LIST the first program line and make it the current line. Typical key: LIST Last Line 012C 00300 When pressed as the first key on a line will cause the editor to LIST the last program line and make it the current line. Typical key: LIST Previous Line 012C 00300 When pressed as the first key on a line will cause the editor to LIST the previous program line and make it the current line. Typical key: LIST Next Line 012C 00300 When pressed as the first key on a line will cause the editor to LIST the next program line and make it the current line. Typical key: FIND Next occur. 003B 00059 When pressed as the first key on a line will cause the editor to FIND the next occurrence of the string last used with the FIND command and make it the current line. Typical key: Overlay Offset (see "Overlays"): 00000 00000 Allows you to set the Offset for overlay programs. See OVERLAYS in this appendix for details. continued ... 8-11 Z80 Appendix zao APPENDIX SPECIAL TRS-80 CONFIGURATION OPTIONS TRSDOS, NEWDOS or Other 012C 00300 This special Configuration is used to tell the EDITOR which type of DOS you are using 50 the DIR command will be available from the editor. Type a 'T' if you are using TRSDOS. Type an "N" if you are using NEWDOS (be sure to re-enable the BREAK key with NEWDOS; see your NEWDOS manual for details). Type an "0" for using most OTHER TRS-80 type disk operating systems. If not configured correctly, a system crash may occur when DIR is used from the editor. This is one of those things in machine language that was never truly standardized by TRSDOS and other Disk Operating Systems. DIR does not function from the editor with Model 1 TRSDOS or NEWDOS. Most other Model 1 Disk Operating Systems like LDOS, MultiDOS etc. function properly. DOS COMMANDS FROM THE TRS-BO VERSIONS ONLY To use DOS commands from within your programs use CALL"DOS Command". To do a DIR from within a ZBasic program use CALL"DIR". To find out how much disk space is available use CALL"FREE", etc. Note: The DOS function being called MUST NOT use memory over 5200H for Model 1 or 3 and 3000H for Model 4. This may not work with some disk operating systems. Note: NEWDOS stops the system scan of the key. Use the NEWDOS: SYSTEM BREAK ON command (or whatever command that particular version of NEWDOS uses. See your NEWDOS MANUAL). continued ... zao Appendix 8-12 zao APPENDIX SPECIAL CP/M CONFIGURATION OPTIONS PRINT@ Control (Hex 3D1B Code) 15643 This Configuration question tells Z8asic which control codes for the screen will cause the cursor to be posnioned for used with the PRINT@ or LOCATE function. The codes for this can be found in your computer terminal technical manual. If a single character just type the character code in decimal or Hex (precede the Hex code with a "&"). If the code is two characters like 18 and 54, type the number in Hex in reverse order; &5418. These codes must be correct for the Z8asic text graphics or screen PRINT@ or LOCATE functions to operate. Clear Screen String (Hex Code) 001A 00026 This Configuration question tells Z8asic which control code for the screen will cause the screen or terminal to be cleared of text and graphics using CLS. The correct codes for this can be found in your computer or terminal technical manual. If a single character just type the character code in decimal or Hex (precede a Hex code with a "&"). If the code is two characters like 18 and 54, type the number in Hex in reverse order; &5418. These codes must be correct for the Z8asic text graphics or screen CLS function to operate. Clear To End of Line (Hex Code) 541B 21531 This Configuration question tells Z8asic which control code for the screen will clear the text and graphics from the cursor position to the end of the line using CLS LINE. The correct codes for this can be found in your computer or terminal technical manual. If a single character just type the character code in decimal or Hex (precede a Hex number with a "&"). If the code is two characters like 18 and 54, type the number in Hex in reverse order; &5418. These codes must be correct for the Z8asic text graphics or screen CLSLINE function to operate. Clear End of page (Hex Code) 591B 22811 This Configuration question tells Z8asic which control code for the screen will clear the screen from the cursor position to the end of the screen using CLS PAGE. The correct codes for this can be found in your computer or terminal technical manual. If a single character just type the character code in decimal or Hex (precede a Hex number with a "&"). If the code is two characters like 18 and 54, type the number in Hex in reverse order; &5418. These codes must be correct for the Z8asic text graphics or screen CLSPAGE function to operate. Note: Also see JUMP TA8LE and PATCH in this appendix for configuring control strings longer then two characters. continued .... 8-13 Z8D Appendix zao APPENDIX Special CP/MTM-80 Configurations continued Cursor (off) String (Hex Code) 451B 17691 This Configuration question tells ZBasic which control code for the screen will turn on the blinking cursor using LOCATE x,y, OFF. The correct codes for this can be found in your computer or terminal technical manual. If a single character just type the character code in decimal or Hex (precede a Hex code with a "&"). If the code is two characters like 1Band 54, type the number in Hex in reverse order; &541 B. These codes must be correct for the ZBasic text graphics or screen LOCATE x,y, OFF function to operate. Cursor (on) String (Hex Code) 521B 21019 This Configuration question tells ZBasic which control code for the screen will turn on the blinking cursor using LOCATE x,y, ON. The correct codes for this can be found in your computer or terminal technical manual. If a single character, just type the character code in decimal or Hex (precede a Hex code with a "&"). If the code is two characters like 1Band 54, type the number in Hex in reverse order; &541B. These codes must be correct forthe ZBasic text graphics or screen LOCATE x,y, ON function to operate. NOTE: IF these parameters are not set properly the corresponding functions will not operate. Z80 Appendix 8-14 zao . .a APPENDIX USING THE PATCH UTILITY The zao versions of ZBasic™ provide a utility to Patch or modify ZBasic internal code to allow fixes or modifications for specific Hardware or software. To get into the PATCH mode enter ZBasic™ from DOS and use the

atch menu option. You will then be prompted for an address which may be decimal (or HEX if preceded by a '&' character). The Modifications made during the patch session may be saved by using the ave option when completed. Some example patches are shown below. Enter PATCH mode from ZBasic start-up. Address: Enter Address to View and/or Patch Data to Abort to menu aaaa bb? (aaaa=hex-address) (bb= byte at address) Enler dala 10 change 10 Skip to Abort and go back to Address: If Data or selected the next address will be shown. BOLDFACE text is what you type in. • COORDINATE WINDOW

atch Address: &xx3F xx3,-C3?_ &C9 Address: dit Patch (enable pixel graphics) get into patch mode Jump table address for x,y conversion Change JP to RET • Patch to route MOUSE(x) to a user routine. get into patch mode

atch Jump table address for JP mouse Address: &xx3D Change JP to RET xx3f C3? &C9 Address: - dit • Patch to Set the default USR3 vector. get into patch mode

atch Jump table address for USR3(expr) Address: &xx61 Change JP to address FI2lI2lI2l xx3F_C3?_ &00 XX40 FF? &F0 Address: dit xx=01 for CP/MTM ·80 xx=30 for TRS-80™ Model 4 TRSDOS/LDOS 6.2 xx=52 for TRS-80™ Model 1 and 3 8-15 zao Appendix zao APPENDIX MEMORY CONSIDERATIONS zao The versions of ZBasic have three different modes of operation concerning memory organization -- EDIT mode, RUN mode, and RUN- mode (see memory map on following page). At least 32k of free memory is required for the EDIT and RUN modes (the development stage of the program). However, after a program has been compiled and saved using RUW, it can be run on as little as 16k of free memory depending on the size of the program (the RUW mode shown on the memory map). NOTES ON THE zao MEMORY MAP: The system top of memory is observed by ZBasic in both the editor and object code. The CLEAR area in the ICMD or .COM file created by ZBasic is the only area of the compiled program which can adjust to different sizes of high memory drivers or machine language routines. If this area is too small when an attempt is made to execute this program from DOS a "Not Enough Memory" error will occur and it will return to DOS. The ZBasic subroutines and jurnp tables are not saved to disk when a program is compiled as a chain file using RUN+. Thus, chain files take up 10k less on disk. ZBasic is located immediately after the DOS. There may be drivers or other applications installed at the top of memory. ZBasic does, however, assume to own all of the memory from DOS to the TOP of memory as defined by the DOS. The size of the INDEX$ is determined by the CLEAR statement (see reference section). This version defaults to CLEAR 1000, making the INDEX$ equal to 1k. If there is not enough memory, the largest size available will be allocated. The size of the INDEX$ memory can be determined using the MEM function within the running program. When the CALL string statement is used to execute a DOS function the DOS function must not use the area where ZBasic resides otherwise a system crash may occur (this DOS function jump vector is located in the ZBasic jump table so it may be re-vectored for different Disk Operating Systems). TopRam is the highest RAM address the system will allow ZBasic to use. This address varies from system to system and even on the same system depending on the DOS. The INDEX$ CLEAR area is the only area of ZBasic that can adjust to this area if not enough room is allocated. When the object code is executed, a "Not Enough Memory" error will occur and the object code will stop and return to the operating system. MEM will return memory for INDEX$. Z80 Appendix 8-16 Z80 APPENDIX RS-232 COMMUNICATION TRS-80 Modell, 3 and 4 SERIAL INTERFACES ZBasic for the TRS-80 Modell, III and 4 supports asynchronous communication using the file number -1 (negative one) for the standard serial Interface. Baud rate, parity, stop bits, and word length are all controlled in the OPEN "C" statement (see OPEN "C" in the reference section). CP/MTM-80 SERIAL INTERFACES The serial interface on Kaypro™ and CP/MTM-80 attempts to use the CPIM TTY device and the OPEN"C" does not affect parameters as these are not software selectable. See your CPIM terchnical reference manual for changing parameters of the n-v device. Use the Patch option to add your own Machine language drivers to the jump table. SERIAL COMMUNICATION PROBLEMS If asynchronous communication is not working, try one of the following: • Check to make sure the baud rate, parity, stop bits, and word length settings are the same on both sides of the communication . • Check for proper cable wiring. The cable must support the standard RS-232 asynchronous interface. "the serial transfer works at a low baud rate (like 300 baud) but fails at higher baud rates, the cable is probably wired improperly. See the diagrams which shows the two most typical cable configurations in the MSDOS appendix. Z80 Appendix 8-18 zao APPENDIX -;&4& iN WAU;¥! Z80 JUMP TABLE The Z80 versions make available a jump table that can be altered to route routines to other addresses. This can be useful for implementing special software or for handling non-compatible Disk Operating Systems or Serial ports (etc.). The following is a list of all the available jump locations with a short description of each: ~ ~ XXOO XX03 XX06 XX09 XXOC XXOF XX12 XX15 XX18 XX1B XX1E XX21 XX24 XX27 XX2A XX2D XX30 XX33 XX36 XX39 XX3C XX3F XX42 XX45 XX48 XX4B XX4E XX51 XX54 JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP JP SUBRTN WARM EXIT CHRINP VIDOUT LPROUT SCANKY ICOMM BAUD PARITY STOPBT WORDLN RSREAD RSWRT RSSCAN TIME DATE PRINTA PRINTG SOUND MOUSE CONVXY MODE COLOR SETXY PLOTXY FILLXY POINT DOSCALL Desc!ip!On Special Notes NONE NONE NONE • RETURNS KEY IN A • SENDS CHAR IN A • SENDS CHAR IN A • A=O NO KEY ELSE A=KEY Set Baud,Parity,Stop bits,Word len UAR HL=BAUD RATE 300,1200 .. SET RS232 PARITY, HL=PARITY 0,1,; SET RS232 STOP BITS HL=STOP BITS 0, 1, 2 ... SET RS232 WORD LENGTH HL=WORD LEN 5, 6, 7, 8 ... READ 1 CHAR FROM RS232 'On exit A=char from RS-232 set Z flag WRITE 1 CHAR TO RS232 • A=CHAR TO SEND set Z flag on exit GET RS232 CHR NO WAIT • A=O NO Char,Z flag set else A=CHAR GET TIME STRING ON Exit HL >=> 9 bytes: lenHH:MM:SS GET DATE STRING ON Exit HL >=> 9 bytes: lenMM/DDIYY HL=Y,DE=X Set cursor for next characte PRINT @(X,Y) ROUTINE PRINT %(X,Y) GRAPHIC Loc HL=Y,DE=X set cursor for next char HL=DURATION MS,DE=FREQ in HZ GENERATE SOUND HL=TYPE RETURNS IN HL READ MOUSE STATUS CONVERT GRAPHIC POS HL=Y,DE=X RETURN IN HL, DE HL=MODE# SET GRAPHICS MODE SET COLOR FOR GRAPHICS HL=COLOR LOCAL COORDINATES SET POINT DE,HL PLOT FROM LAST POINT TO DE, HLLOCAL DE, HL FILL AREA around X,Y FILL FROM POINT DE,HL RETURNS HL=COLOR READ COLOR AT POINT CALL DOS COMMAND HL >==> STRING Cold Start entry point Warm Start entry point ExH to System Get Keyboard Character Output Character to display Output character to printer Get Key from kybrd no waHing INITIALIZE RS232 PORT SET RS232 BAUD RATE 'save registers XX=01 XX=30 XX=52 8-19 zaG Appendix for CP/MBO 2.2 & 3.0 for TRS-BO Model 4 and 4P, TRSDOS/LDOS 6.2 for TRS-BO Model 1 and 3 versions zao APPENDIX DEFAULT USR TABLE USR digit (expression) Entry: Exit: Address XX57 XX5A XX5D XX60 XX63 XX66 XX69 XX6C XX6F XX72 expression >==> ZSO register HL HL register returned in the expression contained in the USR function. Vectors JP USRO JP USR1 JP USR2 JP USR3 JP USR4 JP USR5 JP USR6 JP USR7 JP USRS JP USR9 Description Special Notes OLD HL RETURNS HL ON COLD START ENTRY RETURN RETURN RETURN RETURN RETURN RETURNS LAST LINE # EXECUTED WITH TRON ACTIVE RETURNS RAW RANDOM # 0 TO 65535 RETURNS SIN OF HL IN BRADS AS A VALUE OF +1- 256 RETURNS COS OF HL IN BRADS AS A VALUE OF +1- 256 SPECIAL STRINGS AND CONSTANTS These Strings and constants may be changed by POKES or using the PATCH function from the MENU. XXSO XXS4 CLSSTR PRNTAM XXSA XXSE XX92 XX96 XX9A XX9B XX9C XX9D CUROFF CURON CLRLlNE CLRPAGE PAGED PAGE1 PAGE2 PAGE3 4 BYTE CLEAR SCREEN STRING 6 BYTE PRINT AT CONTROL STRING , <=>, Y+32, X+32, 0, 0 (TRS-SO versions first 2 bytes are RS232 configuration bytes) 4 BYTE CURSOR OFF STRING 4 BYTE CURSOR ON STRING 4 BYTE CLEAR TO END OF LINE STRING 4 BYTE CLEAR TO END OF PAGE STRING 1 BYTE PRINTED LINES PER PAGE (O=disabled) 1 BYTE TOP MARGIN (O=none) 1 BYTE ACTUAL PAGE LENGTH IN LINES (O=disabled) 1 BYTE PRESENT LINE (Iine#1=0, line#2=1 .... ) OTHER IMPORTANT ADDRESSES 52AO and 52A2 XXA4 TO XXBF XXOO +200H XX=01 XX=30 XX=52 ------> TRSSO Model 1, 3, 4 High resolution 240,640 in words ------> User area for PATCHES (Saved with ave configuration option) ------> 256 buffer (OK to use whole buffer during machine language routine) CP/MSO 2.2 & 3.0 TRS-SO Model 4 and 4P, TRSDOS/LDOS 6.2 TRS-SO Model 1 and 3 versions zao Appendix 8-20 zao APPENDIX USING OVERLAYS ZBasic 3.0 on Z80 based computers allows for Overlays to be used to make the most efficient use of a systems available memory. An Overlay is a program which is loaded from disk (without destroying the program in memory) and executed. After it is executed, it will RETURN to the main program. As long as it is in memory it may be called over and over again by RUN O(zero) until it is overwritten by another overlay or program. The main advantage of Overlays is they are small and will normally load up quickly. After they have been loaded, they work like a GOSUB with the variables being chained that appear in the DIM statements at the start of the main program and the overlay program. Here are the steps in creating an overlay program. 1. Create the MAIN program and define the Overlay subroutine(s). 2. To determine the OFFSET for the overlay subroutine: A Type RUN+ from the MAIN program (type when it asks for a filename) B. Type: MEM 00000 00000 00000 00000 Text Memory Object Variable <--- This is the room available for the overlay. <--- This, plus 100, is the OFFSET amount. Add 100 to the number in front of Object to get the offset. This what is used in the onfigure startup to create the OFFSET for the overlay program. 3. Set up all variables which will be used by the Overlay program in identical DIM statements at the start of both the MAIN program and OVERLAY subroutines. 4. Compile and save the MAIN program using the RUN' command. 5. Compile and save the OVERLAY subroutine using RUN+. 6. When the MAIN program requires the use of the overlay the first time use: OPEN"I",1,"Overlay Filename": RUN 1 7. After the overlay is loaded it may be executed again without reloading the OVERLAY by using the RUN" (zero) statement. See the OVERLAY program examples on the next page ... 8-21 zao Appendix zao APPENDIX OVERLAY PROGRAM EXAMPLE To see how the overlay capabilities work try typing in these program examples as shown. is the key. OVERLA Y Program MAIN Program ZBASIC (in configure) OVERLAY OFFSET = a ZBASIC (in configure All Else Same!) OVERLAY OFFSET = 200+256 (aprox)=500 E E ZBasic Ready ZBasic Ready 00010 CLEAR 5000: DIM E,X,Y,Z,T$ 00020 PRINT "STARTING MAIN PGM" 00030 OPEWI",1 ,"PGMOVL" 00040 PRINT "GOING TO OVERLAY" 00050 E=O : RUN 1 00060 PRINT "BACK FROM OVERLAY" 00070 E=1 : RUN a 00080 E=2: Y=1 : Z=8: RUN a 00090 E=3 : RUN a 00100 PRINT "T$=M;T$;"'" 00110 STOP 00010 CLEAR 5000: DIM E,X,Y,Z,T$ 00020 IF E=O THEN PRINT "OVERLAY" 00030 ON E GOTO "HELLO","TEST",120 00040 PRINT ""BAD COMMAND"" D0050 RETURN 00060 "HELLO" 00070 PRINT "HELLO" : RETURN 00080 "TEST" 00090 FOR X= Y TO Z 00100 PRINT X, 00110 NEXT X : PRINT: RETURN 00120 T$=STRING$(20,"X") 00130 RETURN RUN. don1 Save Objectlll MEM 00217 Text ----- Memory 00200 Object 06000 Variable RUN.Object Filespec .... PGMOVL RUN" (TRSDOS) (CPMOO) Object File .. MAIN/CMD or MAIN.COM MEM 00217 Text ----- Memory 11000 Object >==> (size on disk) 06000 Variable QUIT (Compile overlay program) MEM 00208 Text ----MEMORy 00150 Object >==> (size on disk) 06000 Variable QUIT MAIN STARTING MAIN PGM GOING TO OVERLAY IN OVERLAY "BAD COMMAND" BACK FROM OVERLAY HELLO 12345678 T$='XXXXXXXXXXXXXXXXXXXX' Break in 00110 Z80 Appendix 8-22 zao APPENDIX I . . . . . . A:" 1. . . . . . . ;tliMi&il_i Z80 MODE CHART ZBasic™ Graphics Mode Chart E: 0 Q. CD CPMTM-80 Z80 ver. 2.2,3.0 Graphics Mode x 0 Text , Graphics Y x y x 2 Text y x 3 Graphics y 4 Text y 5 Graphics 6 Text 7 Graphics 8 Text y 9 Graphics y 10 Text '1 Graphics 12 Text y 13 Graphics y 14 Text y 15 Graphics y x x y x y x y x x x y x y x x x x KayproTM With Graphics TRSTM-80 Model 1&3 TRSTM-80 Model4&4p Print Plot Print Plot Print Plot Print Plot 80 24 80 24 80 24 40 12 32 16 32 16 40 24 40 24 80 24 80 24 80 24 80 50 32 16 64 48 40 24 80 80 24 80 24 80 24 60 18 32 16 32 16 40 24 40 24 80 24 80 24 80 24 120 72 32 16 64 48 40 24 80 72 80 24 80 24 80 24 80 24 64 16 64 16 80 24 80 24 80 24 80 24 80 24 160 96 64 16 128 48 80 24 160 72 80 24 80 24 80 24 80 25 64 16 64 16 80 24 80 24 80 24 80 24 80 24 160 100 64 16 128 48 80 24 160 72 80 24 80 24 80 24 40 12 32 16 32 16 40 24 40 24 80 24 80 24 80 24 80 50 32 16 256' 192' 40 24 320' 240' 80 24 80 24 80 24 60 18 32 16 32 16 40 24 40 24 80 24 80 24 80 24 120 72 32 16 256' 192' 40 24 320' 240' 80 24 80 24 80 24 80 24 64 16 64 16 80 24 80 24 80 24 80 24 80 24 160 96 64 16 512' 192' 80 24 640' 240' 80 24 80 24 80 24 80 25 64 16 64 16 80 24 80 24 80 24 80 24 80 24 160 100 64 16 512' 192' 80 24 640' 240' 72 , Model 4 Radio Shack™ or Micro Labs™ Graphics Board Only. (Do not use Modes 8 to 11) Note: ZBasic™ will not scale High resolution graphics correctly on the Model 4 in 3 mode. x=Honzontal resolution, y=vertlcal resolution NOTE: ZBasic does not support both text and graphics in MODE 13 or 15 (Micro-Lab's board does). 8-23 Z80 Appendix APPLE DOS 3.3 APPENDIX a dRUMi'll] Notes C-1 Apple DOS 3.3 Appendix APPLE DOS 3.3 APPENDIX TM ASIC DOS 3.3 VerSDon \For the Apple® lie, lie, Laser 128™ and! HGS (lie requires the extended 80 column card) Original version by David Overton Enhancements by Greg Branche © Copyright, 1985, 1986, 1987 ZEDCOR, INC. All Rights Reserved ZBasic is a trademark of Zedcor, Inc. DOS 3.3 Is licensed from Apple CoTJl)uter, Inc. Apple, lie, lie, I1GS, ProOOS and App\eSoft are a registered trademarks of Apple CorT1>uter, Inc. Apple DOS 3.3 Appendix C-2 APPLE DOS 3.3 APPENDIX TABLE OF CONTENTS C-3 Table of Contents C3 Hardware Requirements Apple IIc, JIGS and Laser 128 Apple lie Creating Programs for a)[+ Using the Videx 80 Column Card ProDOS C4 C4 C4 C4 C4 C4 Flies Included on the Master Diskette C5 Getting Started Set up Executing ZBasic from DOS 3.3 Note to main reference manual C6 C6 C6 C6 Important Notes About using "MODE" MODE problems 80 Column Card problems C7 C7 C7 Miscellaneous C8 ~~~ ~ Editor notes Text and Graphics Integration Blinking Characters Apple lie Extended 80 Column Card RESET key versus CTRL-C Relative versus Pixel Coordinates Compatibility with Applesoft Using Hard Disks and/or Foreign DOS C8 C8 C8 C8 C9 C9 C9 C9 Special DOS 3.3 Configuration Options Configuring Drive specifications Configuring Printer Slots Printer Initialization Sequence C10 C10 C10 C10 Reference COLOR statement DEF LPRINT statement DEF MOUSE statement Important IIc MOUSE patch MEM command DOS 3.3 Memory Map MODE statement OPEN statement OPEN"C" statement C12 C13 C14 C15 C16 C17 C18 C18 C19 C20 Apple DOS 3.3 Appendix APPLE DOS 3a3 APPENDIX HARDWARE REQUIREMENTS APPLE lie, IIGS, LASER 128™ The Apple™ version of ZBasic™ 3.2 functions with a standard Apple J1c or IIGS. A 5.25" disk drive is required. An Apple™ Mouse, second Disk drive and Joystick are supported but are not required. The IIGS emulates the /Ie and /lc with this version. IIGS specific features are not used. APPLE lie ~ an Extended SDcolumn card Installed In auxiliary slot 3 and 1 disk drive. The Apple™ version of ZBasic™ 3.2 for the Apple lie An Apple™ Mouse wlinterface, Joystick and Super Serial Card are supported but are not required. CREATING PROGRAMS TO EXECUTE ON AN APPLE ][+ RUNNING DOS 3.3 ZBasic requires a minimum of 128K memory to create programs, but compiled programs will normally function on the older machines with 64K since the Object Code (Machine language program) is compiled into the lower bank of 64K. Code can be generated which will run on an Apple™ 11+ if certain restrictions are observed. Avoid the use of MODE 3 or 7 as they require an extended 80 column card which will not function inan Apple 11+. The Apple 11+ MUST have a 16k memory card installed in slot # zero in order to execute programs created with ZBasic (total of 64K memory). VIDEXTM 80 COLUMN CARD The Videx 80 column card works in MODE 2. You may need to clear the screen with CHR$ (n). See 80 column manual for value of n (usually 12). Older style 80 column cards mayor may not function. ProDOSTM Another option is to create your programs with the 64K ProDOS version of ZBasic. Programs created with this version will run on any Apple /I. You may order the ProDOS version from Zedcor at 800-482-4567. Apple DOS 3.3 Appendix C-4 APPLE DOS 3.3 APPENDIX FILES INCLUDED ON MASTER DISKETTE The following files are included on your master copy of ZBasic for Apple /I DOS 3.3: Description Hello program starts up ZBasic when you boot the disk. .EI.Jll A 002 HELLO *B 037 ZBASIC The ZBasic master program *B *B *B *B *B *B *B *B Part of the main program 003 042 026 011 006 047 010 013 INTERPILER VERSION 3.2 COPYRIGHT 1985 BY ZEDCOR, INC. ALL RIGHTS RESERVED APPLE //TM128K The files above are required to create ZBaslc programs. The flies below are optional and are not required to execute ZBaslc. Example Flies *T 133 ZBASIC.HLP C-5 Description The ZBasic HELP file accessed from ZBasic wnh HELP. If file is not located you will get a File-Not-Found error. T 003 GRAPH.BAS Example of graphs. T 013 DISKIO.BAS Example of doing disk file handling wnh ZBasic (make sure "Convert to Uppercase" is set to NO under "Configure"). T 004 QUICK.APP T 003 SHELL.APP T 004 SORT.BAS Quick sort. Append to SORT.BAS to see how it used. Shell sort. Append to SORT.BAS to see how it used. Creates random data to demonstrate the SHELL and QUICK sort subroutines above. T 003 SIEVE.BAS The Infamous "Sieve of Erastothenes" benchmark. T 004 BLOAD.FUNCTION T 003 BSAVE.FUNCTION T 010 BLOAD/BSAVE DEMO BLOAD function you can use in your programs. BSAVE function you can use in your program. Demo of the BLOAD and BSAVE function above. Apple DOS 3.3 Appendix APPLE DOS 3.3 APPENDIX GETTING STARTED 1. Before doing anything ... Make a Backup of the master diskette. See your DOS 3.3 users manual for instructions on using the COPYA program. 2. Put the BACKUP in a safe place. 3. You may delete all the "T" (text) files on the disk if you need more room. If you don't need "HELP", the ZBasicHLP file may also be deleted. 4. Read the "Getting Started" section of the main reference manual. EXECUTING ZBaslc FROM DOS 3.3 There are two ways to load and execute ZBasic: 1. Put the ZBasic diskette into the first drive and tum the system on. ZBasic will BOOT automatically from the "HELLO" program. 2. After loading DOS 3.3 put a ZBasic diskette in the second and type: BRUN ZBASIC NOTE TO THE MAIN REFERENCE MANUAL When you are reading the main reference section of this manual always take note of this icon: It indicates a variation to this version that you will want to read (sometimes it will make note of the ProDOS version in which case you can ignore it). Apple DOS 3.3 Appendix C-6 APPLE DOS 3.3 APPENDIX ~ IMPORTANT NOTES ABOUT "MODE" ZBasic allows you to set different graphics and text modes. This feature lets you jump from one MODE to another as your program requires. This does introduce some unique potential problems that are easily avoided if you know about them. 1. While programs compiled in the interactive method (RUN) of ZBasic will usually operate correctly even if the MODE is not set at the beginning of a program, a program compiled to disk as a stand-alone program (RUN' or RUN+) may appear to "Hang the system" if MODE is not set. To solve this problem just--->BE SURE TO SET THE MODE AT THE BEGINNING OF EVERY STAND-ALONE PROGRAM. 2. Sometimes when typing programs in the editor, especially after pressing CTRL C or CTRL-RESET from a running program, you may experience an unresponsive screen or keyboard. What has happened here is that the MODE has been changed in the compiled program and needs to be reset in the editor (your keys are actually appearing on an invisible screen of another MODE). Just type: MODE 2 Even though you will not see the keys being typed and the screen will return to normal. Do not press RESET, or REBOOT the system, as you will lose the program in memory . The above method works just fine as long as you remember that you can't the see the keys being pressed until you press . CONTROL KEYS IN LISTINGS The 80 column card responds to certain control codes. Sometimes a REM statement or quoted string may contain a control character that will set the 80 column card to 40 characters or to a different mode. Use the example above to correct the setting and delete the control character from the offending line. C-7 Apple DOS 3.3 Appendix APPLE DOS 3.3 APPENDIX MISCELLANEOUS The following is important information about how standard ZBasic commands may vary on this version. LIST KEYS ZBasic allows you to use the cursor keys for listing programs and for use in the line editor. The delete key or the left arrow key may be used whenever the reference section says . FULL SCREEN EDITOR VERSUS STANDARD LINE EDITOR This version of ZBasic does not support a Full Screen Editor. Should you desire to use a Full Screen editor you may want to try the ProDOS version of ZBasic. It comes with a Full Screen Editor built-in. You may also use other editors to create your programs if you save your programs in ASCII using SAVE+ or SAVE'. TEXT AND GRAPHICS ZBASIC ALLOWS THE INTEGRATION OF TEXT AND GRAPHICS IN MODE 5 AND 7 ZBasic allows the user to integrate text and graphics on the screen just like other computers. This permits porting programs over to the Apple from the IBM PC and many other computers! (Modes 5 and 7 only.) BLINKING CHARACTERS Blinking Characters are not supported in Graphics mode text. Inverse characters may be obtained by setting the high bit of the character by OR-ing the character with 80 Hex or adding 128 to the ASCII value. APPLE lie EXTENDED 80 COLUMN CARD CONTROL CODES All features of the Apple™ Extended 80-column card may be used by printing characters to the screen in modes 2,4,6. For example, printing a control-w will cause the screen to scroll up. See the ProDOS appendix for a list of the 80 column card control characters. Apple DOS 3.3 Appendix C-8 APPLE DOS 3.3 APPENDIX 5 • •::i:ilM:@WfMMiikW. CONTROL-RESET VERSUS CONTROL-C If the computer should "Lock-Up" for some reason, or you faced with the monitor prompt you can press GTRL-RESET to re-enter the ZBasic line editor. In most cases your source code will remain intact. n, GTRL-RESET may also be used instead of GTRL-G to break out of programs and in many cases is preferable since it is much more responsive. RELATIVE GRAPHIC COORDINATES VERSUS PIXEL COORDINATES ZBasic provide the standard device independent graphic coordinate system of 1024x768 so that programs created on other computers will also function on the Apple 1/ and visa·versa. Even so, should the need arise where you MUST use pixel coordinates use these POKEs: POKE &F388, &60 Sets to Pixel coordinates of that MODE (see MODE chart) POKE &F388, &A9 Sets back to ZBasic's standard device independent coordinates of 1024x768. See "Graphics" in the front section of this manual for more information about using ZBasic graphics. COMPATIBILITY WITH APPLESOFTTM ZBasic supports quite a number of the Applesoft commands. The big differences are in Graphics and Disk file handling. To see a listing of the commands that are not supported and some suggestions on converting your Applesoft programs over to ZBasic, see the Apple 1/ ProDOS appendix in this manual. USING WITH HARD DISKS ANDIOR NON-STANDARD DOS This version of ZBasic overwrites the area of memory that is normally occupied by the DOS 3.3 command interpreter to provide you with as much programming area as possible. ZBasic can get away with this because it does not use the command interpreter; it uses the DOS file manager directly. Because of this, foreign operating systems (such as Diversi DOS) usually will not work with ZBasic. In addition, hard drives that force the use of a modified DOS 3.3 mayor may not work. If you need the increased speed of a compiler and require the storage capacity of a hard rive, we suggest you consider the ProDOS version of ZBasic. It does not modify ProDOS in any way and is compatible e-9 Apple DOS 3.3 Appendix APPLE DOS 3.3 APPENDIX SPECIAL DOS 3.3 CONFIGURATION OPTIONS CONFIGURING DRIVE SPECIFICATIONS DRIVE DRIVE DRIVE A: B: C: SLOT SLOT SLOT 6 60- DRIVE DRIVE 1 2 Besides the regular configuration options that ZBasic offers, (See "Getling Started" in the reference section) the DOS 3.3 version allows you to configure which physical slot and drive will be associated with a logical drive specifier. ZBasic specifies drives with letters instead of numbers (similar to MS-DOS and CPIM drive specs). D1=A, D2=B etc. During configuration you will be prompted with a logical drive specifier e.g. A: , and asked which physical slot and drive will be associated with that logical drive spec. You are allowed to configure multiple logical specifiers for a single physical drive. For example, you can configure both drive A: and C: to access slot 6, drive 1. You may also configure for drives that are not present on your system. You should be careful when doing this, so that you do not try to access these drives. This is however, useful when developing software for other systems when using ZBasic™. You can configure extra drives, and access them if the end users have them in their systems. CONFIGURING PRINTER SLOTS PRINTER SLOT 1-7 01 ? 00001 The printer slot may also be set during configuration. This allows you to place your printer interface card in any 5101. ZBasic will support any printer card that conforms to the Apple™ interface card standards for the ROMs. (Either Serial interfaces or Parallel.) This merely sets the default printer sial. The slot may be changed at any time using the special DEF LPRINT statemenl. The default printer slot is number 1. The Apple™ lie has the equivalent of a serial printer card in slot #1. SETTING UP A PRINTER INITIALIZATION SEQUENCE ENTER THE EXACT KEYSTROKES REQUIRED INTERFACE CARD (....... TO END): FOR YOUR PRINTER AND/OR The printer initialization string can be any sequence of up to 12 ASCII characters. See the ProDOS appendix under "Configure" for the details of using this option (it is exactly the same syntax). Apple DOS 3.3 Appendix C-10 APPLE DOS 3.3 APPENDIX C-11 Apple DOS 3.3 Appendix APPLE DOS 3.3 APPENDIX ASIC APPlE® II DOS 3.3 REFERENCE This section describes the additional commands and differences to the standard ZBasic. You will notice there are relatively few variations from the main reference section of this manual. This version of ZBasic is very good for leaming programming and for creating programs that will work on virtually all versions of ZBasic with little or no changes. When converting programs to other computers you usually only have to take COLOR, MODE, filename variations and communication device numbers into account. Apple DOS 3.3 Appendix C-12 APPLE DOS 3.3 APPENDIX IE COLOR Statement =n FORMAT COLOR DEFINITION The same as the standard ZBasic COLOR statement. The color codes are as follows: Mode Mode Mode Mode Mode 0: 2: 3: 4: 6: Text Characters only Text Characters only Same as Mode 1 Text Characters only Text Characters only MODE 1,3 NUMBER o 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Mode 5: NUMBER o 1 2 3 4 5 6 7 Mode 7: NUMBER o 1 REMARK C-13 ~ Black Magenta Dark Blue Purple Dark Green Grey Medium Blue Light Blue Brown Orange Grey Pink Green Yellow Aqua White HI-RES GRAPHICS ~ 280X192 Black1 Green Violet White 1 Black 2 Orange Blue White2 ~ Black White Note: DOUBLE HI-RES 560X192 The ProDOS version of ZBasic supports 16 colors in this mode. The colors on the video display of Apple /I computers are affected by neighboring colors and the condition of RAM. This is a phenomena of the Apple /I hardware and is not correctable. Apple DOS 3.3 Appendix APPLE DOS 3.3 APPENDIX DEF LPRINT statement FORMAT DEF LPRINT [=] Slot number DEFINITION This command is used to configure the printer slot during runtime. Afterthis command is used, all printer output will be diverted to the selected slot. The slot number may be specified by a numeric expression but the value of Slot number MUST be between one and seven (1-7). ~ ~'-.~ If value exceeds the range of 1 through 7, the system may hang up. = EXAMPLE DEF LPRINT REMARK Be sure to validate the slot if it is input from the user. Incorrect values may cause the system to hang up. 1 This command supersedes the value set under "Configure" but does not supercede the printer initialization string. Apple DOS 3.3 Appendix C-14 APPLE DOS 3.3 APPENDIX [6£ DEF MOUSE statement [=1 expression FORMAT DEF MOUSE DEFINITION This statement defines which device (MOUSE or JOYSTICK) will be used with the ZBasic MOUSE functions. VALUE expression = zero expression = non-zero EXAMPLE DEVICE Apple™ Mouse Interface card in slot number 4. Joystick/paddle port. DEF MOUSE=l: REM Define as a JOYSTICK DO PRINT MOUSE (1) , MOUSE (2) UNTIL MOUSE(3) END Program will print positions of the joystick until you press the joystick button. REMARK The defauK is to read a mouse card in slot 4. Older Apple™ lie systems have the equivalent of a mouse card in slot 4. Unfortunately, Apple changed the slot in the newer Apple IIc to slot 7. If you have a newer Apple IIc or want your commercial program to operate on any Apple IIc, use this routine in the beginning of your program. It checks to see if it is a new or old IIc board (donl use it on a lie, IIGS or Laser 128™) and configures itself accordingly. LONG IF PEEK(&FBB3)=6 AND PEEK(&FBCO)=O AND PEEK(&FBBF)=3 POKE &D1F8, &7F POKE &D1FF, &7F POKE &D204, &7F POKE &D20A, &FF POKE &D20F, &FF POKE &D217, &C7 POKE &D21C, &C7 POKE &D21E, &70 POKE &D222, &C7 END IF Note: The ProDOS version DOES NOT require this routine. C-15 Apple DOS 3.3 Appendix APPLE DOS 3.3 APPENDIX MEM command FORMAT MEM DEFINITION This command is used to show the amount of memory remaining for text and object code and the amount of text and object code space used in each bank. MEMORY BANK 1 00000 Code Mem 00000 Object 00000 Variable -Code and variable space remaining. -Size of object code generated. -Amount of variable space used. MEMORY BANK 2 00000 Text 30050 Text Mem -Shows amount of text space used. -Amount of text room remaining. EXAMPLE MEM 00043 29842 00000 00000 00000 REMARK Text Text Mem Code Mem object Variable See Memory map in this appendix. Apple DOS 3.3 Appendix C-16 APPLE DOS 3.3 APPENDIX fi'l . DOS 3.3 MEMORY MAP Apple™ lie, lie Memory Map OBJECT CODE 65535 Editor / Compiler 65535 System Monitor 63488 57344 System Monitor 63488 ZBasle Subroutln., 5"48 57344 ZBasle Editor 53248 Hardware Addresses Hardware Addresses 49152 DOS '3008 .3006 COMPILED OBJECT CODE ZBASIC SOURCE CODE TEXT SPACE t . VARIABLE STORAGE ," lM32 ZBa,le Subroutines 16384 ZBa,le Complier '638' Graphics Screen 8192 Graphics Screen 8192 ZBasle Subroutines ZBasle Complier Text Screen System Variables Text Screen and System Variables 2048 LOWER BANK C-17 Apple DOS 3.3 Appendix UPPER BANK APPLE DOS 3.3 APPENDIX MODE statement n FORMAT MODE DEFINITION ZBasic uses MODE to define the characteristics of a screen. ZBASIC ALLOWS TEXT and GRAPHICS INTEGRATION That's right. ZBasic allows a program to integrate text and graphics anywhere on the screen in MODE 5 and 7. This feature allows ZBasic programs from an IBM PC and other computers to run on your Apple. DOS 3.3 version MODE CHART MODE TEXT GRAPHICS 0 40 x 24 character 1 none 40 x 48 2 80 x 24 character 3 none 80 x 48 4 80 x 24 character 5 40 x 24 280 x 192 6 80 x 24 character 7 80 x 24 560 x 192 MODES 8-15 are reserved for future use character = Text only MODE. Draws graphics using characters. 40 x 48 = Low resolution graphics 80 x 48 = Medium Resolution "Color" Graphics 280 x 192 = High Resolution "Color" Graphics 560 x 192 = Double High Resolution. Not on ][+. Modes 9, 11, 13 and 15 have graphics althe top olthe screen and text althe bottom, similar to Applesoft BASIC. Apple DOS 3.3 Appendix C-1B APPLE DOS 3.3 APPENDIX OPEN statement "I! filetype 1 I drivespec I filename", record length FORMAT OPEN "--", filenumber, DEFINITION This version of ZBasic has the same syntax as other versions with the exception that file specifications are within the filename: lflletype is a number from 1 to 8 and sets the filetype only at the time the file is created. At all other times it is ignored. The types of files that may be defined: Iflletypes 1) 2) 3) 4) 5) 6) Text file (defauH) Integer BASIC file Applesoft™ BASIC file Binary File Stype file Relocatable type file 7) A type file 8) Btypefile See your Apple DOS 3.3 reference manual for specifics about file types. drlvespec is a letter A through H followed by a colon separator. The letter must be in upper case and specifies the physical slot and drive set in configuration. A: 01 B: 02 filename is a standard Apple OOSTM 3.3 filename of up to 30 characters. EXAMPLE OPEN"O",1,"!4 A:FREO" REMARK Any type of file can be opened in ZBasic. If files are to be read from other software, they should be written with the correct file type and file format for that software. <-- Creates a Binary file named "Fred" on drive A: (normally 01) If drivespec is omitted, the last accessed drive will be used as the defauH. See "Files" in reference section for more information about using files. Also see the example program DISKIO.BAS on the master disk. C-19 Apple DOS 3.3 Appendix APPLE DOS 3.3 APPENDIX OPEN"C" statement FORMAT OPEN"C". slot [. [baua] [. [parity] [. [ stopbm [. [word length]lll DEFINITION Same as OPEN"C" in the main reference section except that slot designates the slot that contains the Super Serial Card. The default slot number is 2. The normal slot for use with a modem is slot two. The Apple IIc contains the equivalent of a Super Serial Card in slot number 2. The IIGS must have a Super Serial Card in order to use this statement. It will not operate with the built-in IIGS serial port. slot -1 -2 -3 -4 -5 -6 -7 Indicates Super Serial Card in slot 1 Indicates Super Serial Card in slot 2 Indicates Super Serial Card in slot 3 Indicates Super Serial Card in slot 4 Indicates Super Serial Card in slot 5 Indicates Super Serial Card in slot 6 Indicates Super Serial Card in slot 7 EXAMPLE OPEN"C",-2,300 REMARK See the main reference section for more information and examples of using the OPEN "C" statement. Apple DOS 3.3 Appendix C-20 APPLE DOS 3.3 APPENDIX C-21 Apple DOS 3.3 Appendix APPLE ProDOS APPENDIX ~ Notes D-1 ProDOSTM Appendix APPLE ProDOS APPENDIX ASIC ProDOS~ For the Apple~ 8 Version ][+, lie, lie, and Laser 128™ JIGS by Greg Branche Original DOS 3.3 version by Dave Overton © Copyright 1985, 1986, 1987 ZEDCOR, INC. All Rights Reserved Z8asic is a trademark of Zedcor, Inc. Apple, IIGS, Imagewriter, and ProOOS are registered or licensed trademarks of Apple Computer, Inc. Zedcor, Inc. is not affiliated with Apple Computer. inc. ProDOSTM Appendix D-2 APPLE ProDOS APPENDIX TABLE OF CONTENTS D-3 TABLE OF CONTENTS 03 HARDWARE REQUIREMENTS 64K Version 128K Version 05 FILES INCLUDED ON ZBASIC DISKETTE 64K Versions 128K versions 06 06 07 GETTING 08 STARTED NOTES ON THE ProDOS VERSION Boot-up Process Note to main reference section Importance of using a Ram Disk ProOOS PATHNAMES File BUFFER size (how to get an extra 2048 bytes) List Keys Help File Reset Key ProDOS Disk Error Codes Hexadecimal Constants Relative Coordinates versus Pixel Coordinates MOUSE IMPORTANT NOTES about video/system problems Using the Super Serial Card Commands not supported in this version Integration of Text and Graphics 80 Column Card Control Codes INVERSE text Mouse TextCharacters Custom Character Sets 09 09 09 D10 D10 D10 D11 D11 D11 D11 D12 012 D12 013 D13 D13 D14 D14 D14 D15 D15 SPECIAL "CONFIGURE" OPTIONS "Printer Slot 1-7" Setting up a Printer initialization sequences LOCATE order CON FIG Note on Case Conversion 016 D16 D16 D17 D17 D17 ProDOSTM Appendix APPLE ProDOS APPENDIX TECHNICAL NOTES ProDOS Machine language Interface Entry Points ZBasic to ProDOS interface Using MACHlG MEMORY Usage Zero Page Memory Map 64K Memory Map 128K Memory Map D18 D18 D18 D18 D19 D19 D19 D20 D21 CONVERTING Applesoft PROGRAMS TO ZBaslc Applesoft commands and ZBasic Equivalents Applesoft file commands and ZBasic Equivalents Converting DOS 3.3 ZBasic programs to ProDOS D22 D23 D24 D25 REFERENCE ClS COLOR DATE$, TIME$ DEFlPRINT DEF MOUSE DIR EDITOR INSlOT MEM MODE ONLINE OUTSlOT PATH POINT RENAME RUN USR USR5 D26 D27 D28 D29 D30 D31 D32 D34 D35 D36 D37 D38 D39 D40 D41 D42 D43 D44 D45 command statement functions statement statement command command statement command statement command statement command function command command function function FULL SCREEN EDITOR Difference between the Full Screen Editor and the Standard Line Editor 80 Column Editor 80 column cursor movement DIAGRAM 40 column Editor 40 column cursor movement DIAGRAM Full Screen Editor Quick Reference Page Cursor key definitions (40 and 80 column) Editor Command definitions D46 D46 D47 D47 D48 D48 D49 D50 D51 ProDOSTM Appendix D-4 APPLE ProDOS APPENDIX l$jtt1&1;1waaw:u leA:· .tt£ZJ&WWUU HARDWARE REQUIREMENTS Apple /lc, IIGS and Laser 128 The 64K and 128K ProDOS versions of ZBasic function with a standard Apple /lc and IIGS. A disk drive is required (5.25 or 3.5 inch). ProDOS provides a tRAM disk, size depending on available memory. An Apple Mouse™ with interface, Joystick and Super Serial Card are supported but are not required. IIGS Note: The IIGS emulates the /Ie, /lc modes with this version of ZBasic. Super High-Res graphics are not supported on this version directly. Apple /Ie 64K Version The 64K ProDOS version runs with a standard Apple /Ie. A disk drive is required (5.25 or 3.5 inch). An AppleMouse™ with interface, Joystick and Super Serial Card are supported but are not required. If you have an Extended 80 column card, or other memory board, ProDOS provides a tRAM disk, size depending on additional memory. If you have only 64K there will be more disk accesses and compilation will take longer. /lc, /Ie, /lGS Note: Code can be generated which will run on the older Apple )[+ or)[ if certain restrictions are observed; Avoid MODE 3 or 7 as they require an extended 80 column card which will not function in an Apple ][+. 128K Version The 128K version of ZBasic requires an Extended 80 Column Card and a 65C02 or 65802 microprocessor. Apple ][ or Apple ][+ 64K Version If you have an Apple )[ or ][+, you M.USI have a 16K bank-switched memory card installed (giving you at least 64K memory). If you have a ProDOS compatible memory board that allows ProDOS to create a tRAM disk, ZBasic will take advantage of it. If you have only 64K there will be more disk accesses and compilation will take longer. A disk drive is required (5.25 or 3.5 inch). ZBasic requires a minimum of 64K memory to create and execute programs. An AppleMouse™ with interface, Joystick and Super Serial Card are supported but are not required. 128K Version The 128K ProDOS version of ZBasic will not operate on an Apple ][ or ][+. OLDER 80 COLUMN CARDS Older style 80 column cards mayor may not function. The Videx 80 column card works in mode 2 although you will have to do some manual switching. When typing CLS from the Standard line editor ZBasic will sense the Videx board and clear the screen automatically. D-5 ProDOSTM Appendix APPLE ProDOS APPENDIX F~lES ~NCLUDED 64K VERSION ON THE MASTER DISKETTE The following files are included with the 64K ProDOS version of ZBasic: File ZBASIC. SYSTEM Description The boot program and low-memory subroutines. RUNTIME.OBJ High-memory runtime subroutines. This program MUST accompany stand-alone programs you create with ZBasic. EDITOR.OBJ COMPILER.OBJ The ZBasic command environment and Standard line editor. The ZBasic compiler. FSEDIT. 80 .OBJ aD-column full screen May be deleted if not 40-column full screen May be deleted if not FSEDIT.40.0BJ INIT.64.0BJ editor for IIc, IIGS and aO-collle. used. editor for 40-col lie, ]! and ][+. used. Contains a stand-alone program initialization sequence. THE FILES ABOVE ARE REQUIRED WHEN CREATING ZBASIC PROGRAMS. THE FILES BELOW ARE OPTIONAL OR EXAMPLE PROGRAMS ZBASIC.HLP Help file accessed with the "HELP" command. DISKIO.BAS GRAPH.BAS Sample program demonstrating ZBasic file commands. Sample program demonstrating ZBasic graphics. SORT.BAS QUICK.APP SHELL.APP Program to illustrate the use of the QUICK.APP and SHELL.APP sorting programs. Load this program first then type: APPEND 1000 QUICK.APP (or SHELL. APP). Append file containing a quicksort subroutine. Append file containing a shell sort subroutine. SIEVE GRAPHICS.COLORS The SIEVE benchmark program from BYTE magazine. Demonstrates the colors available in each of the graphics modes. BLOAD . SAMPLE BSAVE.FN BLOAD.FN DHRBSAVE.FN DHRBLOAD.FN DRAW.FN Demonstrates the use of the BLOAD and BSAVE functions. Function to simulate the ProDOS BASIC. SYSTEM BSAVE command. Function to simulate the ProDOS BASIC.SYSTEM BLOAD command. Double Hi-Res BSAVE function saves Double Hi-Res Graphic screen. Double Hi-Res BLOAD function loads Double Hi-Res Graphic screen. Function to simulate the Applesoft DRAW command. PREFIX. SAMPLE PREFIX.FN CREATE.FN Sample program demonstrating the use of the PREFIX function. Function to set or retrieve the ProDOS default prefix at runtime. Function to create a ProDOS subdirectory from within a ZBasic program. DATETIME.FN Function to manually set the date and time. ProDOSTM Appendix D-6 APPLE ProDOS APPENDIX ."".,EffffiM&44h iW@&:lliiiirMMMifMMMf4 FILES INCLUDED ON THE MASTER DISKETTE 128K VERSION The following files are included on the 128K ProDOS version of ZBasic (flip side of the diskette): ~ ZBASIC.SYSTEM Description The boot program and low-memory subroutines. The following three files MUST accompany stand-alone programs you create with ZBasic. RT.MAIN.OBJI RT.AUX.OBJO RT.AUX.OBJI High-memory runtime subroutines. Low auxiliary memory routines. High auxiliary memory routines. EDITOR.OBJO EDITOR.OBJI EDITOR.OBJ2 The ZBasic command environment and Standard line editor and Full Screen Editor. COMPILER.OBJO COMP ILER. OBJI The ZBasic compiler. INIT.128.0BJ 128K Stand-alone program initialization sequence. Use the example programs on the 64K side of the diskette (see previous page for details). There will also be a couple examples on this side of the diskette. These programs will not work with the 64K version. D-7 ProDOSTM Appendix APPLE ProDOS APPENDIX GETTING STARTED 1. Make a BACKUP of your master ZBasic diskette. Store the master in a safe place (refer to the ProDOS reference manual for backup methods). Note: There are two versions of ZBasic for ProDOS; a 64K version and a 128K version. On 5.25" diskettes they occupy opposite sides. On 3.5" diskettes they are in two different subdirectories. If using 5.25" diskettes make sure to backup both sides. 2. Due to storage limitations. the ZBasic disk does not contain the ProDOS operating system. Therefore you must create a ProDOS environment. There are a couple of ways to do this: a. BOOT FROM A ProDOS Master Disk (/USERS.DISK). Then type "B" from the menu to enter Applesoft BASIC. From the prompt (1 ). enter: "PREFIX IZBASIC". then: "-ZBASIC.sVSTEM". b. CREATE A ZBASIC BOOT DISK: Format a blank disk (using the FILER utility). Copy the file "PRODOS" from a ProDOS disk to your freshly formatted disk. Transfer the following files from your ZBasic Master Disk to your new copy: 64KVERSION ZBASIC.SYSTEM EDITOR.OBJ RUNTIME.OBJ INIT.64.0BJ COMPILER.OBJ FSEDIT. SO .OBJ (use FSEDlT.40.0BJ if using a40 col Apple ][.][+. or /Ie) 128K VERSION ZBASIC.SYSTEM RT.MAIN.OBJl RT.AUX.OBJO RT.AUX.OBJl EDITOR.OBJl COMPILER.OBJO COMPILER.OBJl INIT.12S.0BJ EDITOR.OBJO EDITOR.OBJ2 CTRL RESET will now load and execute ZBaslc from this disk. 3. Read this appendix. making notes of any variations. 4. Now read "Getting Started" in the main reference section. ProDOSTM Appendix D-8 APPLE ProDOS APPENDIX . . . .:miii:mil!!liim BOOT·UP ::i:ii:::i:::liiiMiI• •;;ii ::::::11& PROCESS When the ZBASIC.SYSTEM program is loaded from ProDOS, it does several things prior to putting you into the editor: • ZBasic Title page displayed during the boot process. Zero page locations are initialized. • The low-memory runtime module is moved into place. • ZBasic looks for a volume with the first four characters "/RAM". If found, it will copy the necessary system files into the ram disk. If you do not wish to have ZBasic use the IRAM disk, simply rename it prior to loading ZBasic. • The command environment and standard line editor overlay is loaded into memory (to invoke the full screen editor type EDITOR or EDITOR+). NOTE TO THE MAIN I'IEFERENCE SECTION Wherever there are notable differences between the text and the Apple ProDOS version you will see an Apple ICON that will tell you the difference or refer you to the correct section. The icon looks like this: Occasionally the icon refers to the Apple /I DOS 3.3 version. In those instances simply ignore this icon. THE IMPORTANCE OF USING A RAM DISK In order to leave as much free memory as possible for program development, there is a lot of overlay swapping and other disk access involved while editing and running a program interactively (like an interpreter). For example, if you type "PRINT 2.345'32" from the editor command line, quite a number of events take place: • the editor saves whatever program you have in memory to the disk (/RAM disk, if enabled). • loads and runs the compiler from disk ( IRAM disk, if enabled). • compiles the command and stores the object code in memory . • loads and runs the runtime system (/RAM disk, if enabled). • the runtime executes the object code (which in this example prints 75.04). • then reloads and executes the editor (/RAM disk, if enabled). • editor reloads the temporary file (I RAM disk, if enabled) and waits for the next command. Phew! As I said, a lot of disk access! It should be obvious that a IRAM disk will speed up the whole process 10-15 times since disk access is nearly eliminated. 0-9 ProDOSTM Appendix APPLE ProDOS APPENDIX USING THE RAM DISK These versions of ZBasic require 64K and 128K of memory, respectively. If your system has more then the minimum amount of memory required, and the extra memory is configured as a ProDOS tRAM disk, ZBasic will use it to store some system files and overlays so that overall program development time will be reduced and system speed will be improved. In addition, a temporary file used to hold your source code is also saved to disk during the overlay swapping. This file is named ZTEMP.ZBS. If there is no tRAM volume, the ZBasic disk MUST remain in the drive for normal operation. If the tRAM disk is not large enough to hold ZTEMP .ZBS, ZBasic returns a DISK FULL error and returns to the editor. You should save the file to a diskette and compile from disk at this point (RUN") or exit ZBasic, disable the tRAM disk by renaming it from ProDOS, then reenter ZBasic without rebooting. .~."".'.)Ijj.\.' ~ '",", ,,:: . ""-". '.:.:..:-~" 1 ') ''- Warning: DO NOT RENAME THE tRAM DISK WHEN IN USE! ProD OS PATH NAMES The filenames used in ZBasic are standard ProDOS pathnames. ProDOS pathnames can consist of up to 64 characters, including separating slashes. Individual filenames can be up to 15 characters long, and can consist of alphanumeric characters and periods only. Pathnames may be used with OPEN, RENAME, SAVE, LOAD and all other disk commands and statements. See your ProDOS manual for more information about pathname syntax. FILE BUFFER SIZE--- OR HOW TO GET AN EXTRA 2048 BYTES Each file opened by a ZBasic program requires a 1024 byte file buffer. two file buffers (2048 bytes). ZBasic defaults to If you configure ZBasic for one file buffer, 1024 bytes is freed for program or variables (configuring for no open files would free 2048 bytes). See "Configure" in main manual. ProDOSTM Appendix D-10 APPLE ProDOS APPENDIX LIST KEYS The following is a list of additional keys which can be used in the command mode editor to list lines of source code (as well as those described in the main manual): UpArrow Down Arrow Left Arrow Right Arrow List previous line List next line List first line of the file Lis1last line of the file HELP The file used by the HELP command is named "ZBASIC.HLP". If you so desire, this file can be deleted to allow more storage room on the disk. "ZBasic is not able to find this file in it's system directory, Hwill look in the user's currently logged directory (see the PATH command). If ZBasic still cannot find the help file, you will get a "File-Not-Found" error. CONTROL-RESET VERSUS CONTROL-C This version allows you to use eHher CTRL-C or CTRL-RESET to exH a running program. If the computer should "lock up" for some reason, or you are faced with the monitor prompt ( * ), you can press CTRL-RESET to restart the ZBasic editor. Your source program should remain intact. If you press CTRL-RESET while executing a stand alone program, the program will be terminated, and you will be allowed to load and execute another ProDOS system program. If you are faced with the monitor prompt anywhere wHhin the ZBasic system, pressing CTRL-Y will also return you to the editor. ADDITIONAL DISK ERROR CODES In addition to the standard ZBasic disk error codes referred to in the main reference section, the following codes are defined and may be trapped with ON ERROR GOSUB: Error Code 9 10 11 12 13 14 15 16 17 18 19 20 21-255 Error Message Position Error No Device Connected Error Disk Switched Error Duplicate Filename Error Incompatible File Format Error Access Error File Already Open Error Directory Structure Damaged Error Not a ProDOS Volume Error Duplicate Volume Online Error File Structure Damaged Error 110 Error Disk Error The actual disk error code will be the filenumber times 256 plus the number above. See disk error in the main reference manual for more information. D-11 ProDOSTM Appendix APPLE ProDOS APPENDIX HEXADECIMAL CONSTANT INDICATORS ($ and &) In addition to the "&" prefix signifying a hexadecimal constant (as in &FF69). the "$" character may also be used (as in $FF69). This is so that Apple users will feel more at home. Remember that if this character is used the program will not be directly transportable to the Apple DOS 3.3, IBM, Macintosh, CP/M, or other versions of ZBasic. RELATIVE GRAPHIC COORDINATES VERSUS PIXEL COORDINATES The standard ZBasic graphic coordinate system is great for porting programs between the various computers that run ZBasic or between Hi-Res and double Hi-Res. Occasionally you may need to switch to PIXEL coordinates. Use this statement: POKE WORD &85, 0 After this statement is executed, the following screen dimensions will be in effect with the different graphics modes: MODE 1 MODE 3 MODE 5 MODE 7 40 x 40 80 x 40 280 x 192 560 x 192 (not available with the Apple 1[+ or lie without an extended 80 col. card) MODE automatically resets to the device independent coordinate system, so you must use the POKE WORD &85, 0 statement immediately after setting MODE to re-enable the pixel coordinates above. MOUSE If your program uses the MOUSE function to receive input from the mouse (DEF MOUSE=O), you MUST use a MOUSE(O) function at the beginning of the program prior to any other MOUSE call. ~."-'"" ~' -. MOUSE(O) forces ZBasic to scan the slots for a mouse interface card, and then initialize the mouse properly. If the mouse is not initialized prior to accessing it, your program may die a horrible death (crash)! In addition, ~ a mouse interface could be found and initialized properly, MOUSE(O) will return a value of -1 (true,) otherwise a value of zero (false) will be returned. ProDOS"" Appendix D-12 APPLE ProDOS APPENDIX IMPORTANT NOTES ABOUT VIDEO/SYSTEM PROBLEMS ZBasic allows you to set many different graphics and text modes. This feature lets you jump from one MODE to another as your program requires. This does introduce a unique potential for contusing video problems that are easily mistaken for system errors. ~ • While programs compiled in the interactive method (RUN) of ZBasic will usually operate correctly even if the MODE is not set at the beginning of a program, a program compiled to disk as a stand-alone program (RUN" or RUN+) may appear to "Hang the system" if MODE is not set. To solve this problem; BE SURE TO SET THE MODE AT THE BEGINNING OF EVERY STAND-ALONE PROGRAM. If using an Apple][+ (or lie without an extended 80 column card) be sure to avoid MODE 3 and 7. • Sometimes when typing programs in the editor, especially after pressing CTRL-C or CTRLRESET from a running program, you may experience an unresponsive screen or keyboard. Nine times out of ten what has happened here is that the MODE has been changed in the compiled program and needs to be reset in the editor (your keys are actually appearing on an invisible page of another MODE). Just type: MODE 2 Even though you will not see the keys being typed, the screen will retum to normal when you're finished typing. Do not REBOOT the system, as you will lose the program in memory. Remember: You can't see the keys being pressed until you press . • CONTROL KEYS IN LISTINGS: The 80 column card responds to certain control codes. Sometimes a REM or quoted string may contain a control character that may set the 80 column card to 40 characters or to a different mode. Use the example above to correct the setting and delete the control character from the offending line. USING THE SUPER SERIAL CARD The file number specified in serial 110 must be the negative slot # in which an Apple Super Serial Card is installed. The Apple IIc has the equivalent of a Super Serial Card installed in slot # 2. This card would be accessed by: OPEN "C",-2,300 ••• ZBasic communication commands only support the Apple Super serial card and compatible serial interfaces. Note: The IIGS serial port is not yet supported. A Super Serial Card or compatible card or modem will function properly. COMMANDS NOT SUPPORTED IN THIS VERSION OF ZBASIC The following two functions are not supported: INP() and OUT( ) . See the notes at the bottom of the pages in the main reference section for commands that may not be fully compatible. D-13 ProDOSTM Appendix APPLE ProDOS APPENDIX INTEGRATION OF TEXT AND GRAPHICS Unlike Applesoft, ZBasic allows you to integrate text and graphics on the screen. This permits porting programs over to the Apple from the IBM PC and many others (MODE 5 only on the 1[+ and 64K /Ie. MODE 5 and 7 only on the 128K /Ie and /lc). ao COLUMN CARD CONTROL CODES The Apple 80-column text card firmware supports many control codes to perform special operations, such as screen scrolling up and down. These control codes are available in modes 2 and 6. Simply print CHR$(x), where x is the code for the function you want to perform (see the aD-column text card manual for a listing of these codes.) In addition, several of these codes are available in Modes 5 and 7. The codes and the function they perform in MODES 5 and 7 are listed in the following table: CHR$ Code 7 8 10 13 14 15 22 23 24 27 28 .ElJ.n.Q1lQn Beep the Apple speaker Moves cursor position one space to the left; from left edge of window, moves to right end of line above Moves cursor position down to next line, scrolls if necessary Moves cursor position to left end of next line, scrolls if necessary Sets display format normal (white on black) Sets display format inverse (black on white) Scrolls the display down one line, leaving the cursor at the current position. Scrolls the display up one line, leaving the cursor at the current position Turns MouseText off Turns MouseText on Moves cursor pOSition one space to the right; from right edge of window, moves it to left end of line below Other Apple screen control codes are not implemented (as control codes) for graphics MODE 5 and 7. INVERSE TEXT To shift to the inverse character set, print a CHR$(15). All characters printed after this will be in inverse text. To switch back to normal text, print a CHR$(14). These are the same control codes that Apple's 80-column card uses to switch modes. As mentioned before, this works with the 40-column screen also (a slight enhancement to Apple's firmware done by our software). ProDOSTM Appendix D-14 APPLE ProDOS APPENDIX ¥ 1ft MouseText CHARACTERS In addition to the MouseText characters available in 40 and 80 column modes of the new Apple /I machines, MouseText is available in Modes 5 & 7. To shift the character set to MouseText, print a CHR$(27) and a CHR$(15). • 0A H I • ~ ~.: p B ...; ....: R Q v I z - ....... XC VD L'Ji!:i E F G -1-J l'K C ::. x ~ - • 5 I - L ~ M L ~ T U •I I ~ N - ,...... 3 \" I V 0 W I - To de-select MouseText, print a CHR$(14) and a CHR$(24). Since Apple's procedure for printing MouseText requires you to shift to inverse mode (the CHR$(15)), you might think that inverse MouseText isn't possible. Not so with ZBasic! If you want to experiment a lillie, just use a CHR$(27) to select inverse MouseText, and CHR$(24) to select normal alphanumerics again! CUSTOM CHARACTER SETS The character set that is included with your ZBasic system and used by the graphics character driver is the standard ASCII character set with the addition of the MouseText characters (MODE 5 and MODE 7 only). If you wish, you can customize the character set to your liking. Space does not permit gelling into the specifics of how each character is defined or used, but I can tell you how to change the character set to a pre-defined sel. Our character set is defined in exactly the same way as the character sets included on the DOS Toolkit disk, available from Apple Computer, Inc. To change the character set, follow these instructions: 1. From Applesoft BASIC, with ProDOS active, insert a BACKUP COPY of your ZBasic master disk in the drive. 2. Type: 64K· BLOAD" /ZBASIC/ZBASIC. SYSTEM, A$2000, TSYS" 128K: BLOAD "/ZBASIC/RT.AUX.OBJO, A$2800" This loads the character set (and some other stuff) into memory. 4. Load your character set by typing: BLOAD , A$3900" This loads your character set over our character sel. Since the DOS Toolkit character sets are only 768 bytes long, (characters 32-128) and only contain definitions for the standard ASCII characters, you will not be overwriting the MouseText (0 to 31). 5. Re-insert your ZBasic master disk, and type: 64K: 128K: D-15 ProDOSTM Appendix BSAVE "/ZBASIC/ZBASIC.SYSTEM, A$2000,L$4000,TSYS" BSAVE "/ZBASIC/RT.AUX.OBJO, A$2800" APPLE ProDOS APPENDIX SPECIAL ProDOS CONFIGURATION OPTIONS ZBasic can be configured by typing "C" at the initial prompt screen (see the "Configure" section of the main reference manual), or by typing "CON FIG" while in the editor (see "CON FIG" on the next page). In addition to the standard configuration parameters, there are two more parameters which you can set for the Apple II. PRINTER SLOT? 1-7 This allows you specify which slot your printer interlace is in. This number must be from 1 to 7 (slot 1 is the standard printer slot for Apples). As in the rest of the configuration questions, pressing as a response will accept the defauH and skip the initialization string configuration. If you type a number from 1 to 7, you are telling ZBasic that your printer interlace card is in that slot and you will be given an opportunity to specify a printer initialization string (the IIc has the equivalent of an Apple Super Serial Card in slot 1): SETTING UP A PRINTER INIALIZATION SEQUENCE ENTER THE EXACT KEYSTROKES REQUIRED BY YOUR PRINTER AND/OR INTERFACE CARD (nAn TO END): The printer initialization string can be any sequence of up to 12 ASCII characters that can be typed from your keyboard (end input with the 'W' symbol (caret). To enter the initialization string, type the EXACT keys required by your printer and/or interlace card. The keys will appear on the screen as you type them. Unprintable control characters will appear prefixed by a carettA) character on the screen. Once set, this string is sent to the printer prior to anything else being sent out (such as LLlST, LPRINT, or ROUTE 12S). Be sure to see the ave option under "Getling Started" in the front of this manual. Some common control codes may be entered from the keyboard using: CTRLH CTRLL CTRL \ CTRL =S =12 =2S =31 TAB or CTRL I RETURN CTRL) ESC or CTRL [ =9 =13 =29 =27 CTRLJ DELETE CTRL' =10 =127 =30 See your Apple reference manual for other character sequences. This is most useful for those users who have an older interlace card that does not interlace correctly with the SO-column screen. These cards will echo characters to the screen using the 40-column screen firmware, instead of the SO-column firmware when the SO-column card is active (usually messing everything up). One solution is to tell the interlace card to NOT echo characters by using the following initialization sequence: 80N This would instruct the interlace to turn 011 the screen, and allow up to SO characters per line on the printer. See your interlace card manual for more details. You can also send printer configuration characters to your printer for all kinds of fancy printing, if your printer is capable of it. Your printer manual will list printer control codes that are applicable. continued ... ProDOSTM Appendix 0-16 APPLE ProDOS APPENDIX r• • •fI#W4IWiWE8iilii@ooli@",liiilii**i4,£QiIcontinued from previous page LOCATE order X,Y? Y This option allows you to configure the order of the coordinates in the LOCATE statement. Normally ZBasic expects the horizontal (X) coordinate first. By answering "N"to this question you can make the vertical (Y) coordinate first and the horizontal (X) coordinate second. Note: This also alters the coordinate base of the screen to make the upper-left hand corner character position 1,1 instead 010,0 (only affects LOCATE). This option is provided to maintain compatibiHy wijh the IBM/MSDOS versions of ZBasic which have this option so that BASICA programs are easier to convert. This makes porting BASIC programs from other computers much easier. CONFIG You may re-configure the system any time from the standard line editor by using the CON FIG command. Use caution when doing this while working with CHAIN programs or programs that will be sharing data (especially floating point numbers). Each CHAINed program must be compiled using the same configuration as the other programs in the overall CHAINed system. Otherwise, you will get a chain error when attempting to run them. II you elect to (S)ave your custom configuration, ZBasic will ask you to enter the complete pathname 01 the ZBASIC.SYSTEM file. This will normally be "IZBASICIZBASIC.sYSTEM", unless you have installed ZBasic on a hard disk and/or changed the name of this file. If ZBasic has trouble saving your configuration, it will give you an error message and wait for a keypress. After pressing a key, you will be returned to the configure menu. If no error is encountered, you will automatically be put into the line editor. NOTE ON CASE CONVERSION During boot-up, the system checks to see if ij is running on an Apple 1[+ or a newer machine. If you are using a J[+ the system will automatically convert from lower to upper case for both keyboard input and screen output. If it's a newer machine, the system will skip the conversion. Upper/lower case conversion can be configured separately by the user from the configure menu. See "Configure" in the front of this manual. 0-17 ProDOSTM Appendix APPLE ProDOS APPENDIX THE ProDOS MACHINE LANGUAGE INTERFACE These versions of ZBasic have been written with the ease of direct access to ProDOS in mind. This section of the manual describes how a ZBasic program can talk with ProDOS directly. MLI INTERFACE First of all, this is NOT a tutorial on how to use the ProDOS Machine Language Interface. For more information on that subject, consult the ProDOS Technical Reference Manual. ENTRY POINTS All parameters for ProDOS calls that are made by ZBasic are located in a parameter block at $1 FOO (all addresses are in HEX). There is an 18 byte buffer here that the ZBasic system uses for all MLI calls (18 being the maximum length of any MLI parameter block). In addition, the entry point for a ProDOS call with the 64K version is at $803 ($865 for the 128K version). One more buffer that might be useful is the file name buffer. It is located at $1 F12, and is 64 bytes long (the maximum length of a ProDOS pathname). ZBaslc TO ProDOS INTERFACE To use the ZBasic to ProDOS interface, first set up the parameter list for the MLI call that you wish to make. If you need to, you can set up the pathname pointer with: POKEWORD &lF01, VARPTR(name$) since ZBasic strings conform to the ProDOS pathname standards (a count byte followed by the string). Next, you must load the 6502 Accumulator with the MLI command code, and then JMP or JSR to location $803 ($865 for the 128K version). The ProDOS call will be performed, and the carry flag will have the status of the call upon return. II the carry is clear, then the call returned with no error. II, on the other hand, the carry is set, then there was an error and the error code can be retrieved from location $A2. The ProDOS error that is returned by the MLI is translated into the appropriate ZBasic error code, if possible. II not, then the actual MLI error code will be returned. If you wish to use the standard ZBasic error handler, then you can perform a JMP to location $809 ($87F for the 128K version) if the carry is set upon retum from the ProDOS interface. For example, to use this interface to set the ProDOS system prefix to "!ZBASIC": PATH$ = "/ZBASIC" POKE &lFOO, 1 POKE WORD &lF01, VARPTR(PATH$) MACHLG &A9, &C6 &20, $803 MACHLG &90, 3, &20, $809 END <--- Sets up parameter block <--- 128K version change to $865 <--- 128K version change to $87F Note: Either "&" or "$" may be used to denote Hex numbers (ProDOS version only). ProDOSTM Appendix D-18 APPLE ProDOS APPENDIX it U _tt,a.; HI USING MACHLG The assembly language source for the MACHLG statements would look something like this: SET.PREFIX EQU LDA JSR BCC JSR EQU ERROR DONE * #$C6 $803 DONE $809 ;MLI CODE FOR SET_PREFIX ;CALL THE INTERFACE ;NO ERROR ;LET ZBASIC HANDLE THE ERROR * ProDOS ERROR CODES For the 64K version only; another location of interest is $806. This is the entry point for the subroutine that translates ProDOS error codes into ZBasic error codes. If you wish to access the MLI directly, but still want ZBasic error codes retumed, you can perform a JSR to this subroutine with the ProDOS error code in the accumulator. The translated error code will be stored in location $A2. For more examples of how to use the ProDOS-ZBasic interface, see the CREATE, PREFIX, BLOAD, and BSAVE functions included on your master diskette. MEMORY USAGE The following diagrams illustrate memory usage for the various phases of operation of the ZBasic system. Note: Memory locations 768-975 (page 3) are not used by the ZBasic system. This would be a good place to store short machine language subroutines. Zero Page Map ilS3 lIB m= = Editor 1 0 2 Ox 1x 12x 13x 14x ISx 3 4 l1li Compiler ~ _S 7 ~ = All = Runtime 9 8 A B C D E F Ox 1x j ISx ~ ~~ Bx Cx D" Ex ~,,'C: Fx I X ProDOSTM Appendix •t I 2x 3x <\x ~x ~~ ~ I~II 't" 0-19 rrnm ~ " I ~ ~ ~~ .~7x ~:: ~""-~ Ax ~~~~ __ II :0; F. APPLE ProDOS APPENDIX 64K VERSION MEMORY MAP Runtime Edit/Compile 65535 & System Monitor &F80 63488 Applesott Roms (Not used by ZBasie) ProDOS System Monitor Applesott Roms (Not used by ZBasle) ProDOS &0000 53248 Hardware VO Hardware 110 &COOO 49152 EDITOR.CBJ (whllo editing) RUNTIME.CBJ COMPILER.OBJ (while compiling) &8900 35072 <3- File Bufl.r. Variables ~ t t ZBasle Complied Program ZBasle Source Program &4000 16384 Hi·Res Graphics Page Hi·Res Graphics Page &2000 819 2 ZBasle Subroutines 204 8 1024 0 11K per lIIe) Text PaQe Zero Page. Staek ZBasle Subroutine. &0800 &0400 &0000 Text Page Zero Page. Stack (Numbers on the lett map are in decimal. numbers on the right map are in hexadecimal) ProDOSTM Appendix D-20 APPLE ProDOS _-!Ii . III. APPENDIX ·arnram· 128K MEMORY MAP Main Bank Aux Bank 65535 &FFFF Monitor ROM I Copy 01 Monitor ROM ProOOS &EOOO 57344 ProOOS 53248 I EDITOR OBJI ~ COMPILER OBJI &0000 Hardware 110 Hardware 110 49152 &COOO EDITOR RT.MAIN OBJO OBJO COMPILER OBJO 44032 (&ACOO) Variables . -These fiies are overlayed as needed ~ File Buffers (IK per file) RT.AUX.OBJI &A800 (43008) ~ t t Pseudo St.ck 16364 Program Data ZB •• lc Complied Program &4000 Hi-Res Graphics Page Hi·Res Graphics Page &2000 8192 ZB.slc RT.AUX.OBJO Subroutines 2048 1024 0 D-21 &800 Text Page Zero Page, Stack ProDOSTM Appendix &40 &0 TextPao. Zero Paoe, Stack These fifes are overlayed as needed EDITOR. OBJ2 1 APPLE ProDOS APPENDIX CONVERTING APPLESOFT PROGRAMS TO WORK WITH ZBASIC ZBasic is an advanced version of BASIC. While it shares many of the commands and syntax of Applesoft, it is not exactly the same in many areas, such as graphics, disk file handling and such. CONVERTING APPLESOFT FILES FOR LOADING INTO ZBASIC. ZBasic source code files and Applesoft files are not compatible. To convert an Applesoft program so you can load it into ZBasic: 1. Make sure you have a Backup of your Applesoft program then load the Applesoft program into Applesoft. Make sure your program doesn't have a line zero then add the following line to the program. 0F$="FILENAME":PRINTCHR$(4) "OPEN";F$ :PRINTCHR$ (4) "WRITE";F$:POKE33,33:PRINT"0"; :LIST 1-:PRINTCHR$(4) "CLOSE":TEXT:END Note: The program above is one line. Enter without spaces or . 2. Change "FILENAME" above to the name of the file you wish to create for loading into ZBasic. Then type RUN. 3. Load ZBasic, press "E" for edit, and then load the program using LOAD. To compile the program type RUN. When errors occur use the chart on the next few pages to convert syntax to ZBasic syntax. CONFIGURING ZBASIC FOR COMPATIBILITY WITH APPLESOFT ZBasic allows you to configure the system for your preferences. To make ZBasic as compatible as possible to Applesoft, set the following configurations. See "Configure" in the front of this manual for details about setting configuration options: Default Variable type: Convert to Uppercase YIN: Optimize Expressions for integer YIN: S (avoid doing this whenever possible) Y N (avoid doing this whenever possible) STRING LENGTH NOTE ZBasic uses strings differently than Applesoft. See "Converting Old Programs" and DIM and DEF LEN in the front section of this manual for more infomnation. COMMANDS THAT ARE DIFFERENT The following commands are different and will require converting. The list includes hints on how to convert the various Applesoft statements to ZBasic equivalents. ProDOSTM Appendix D-22 APPLE ProDOS APPENDIX wM'Wllw 44 & Applesoft Commands BLOAD/BSAVE CALL CLEAR COLOR CONT DEFFN DIM DRAW FLASH FRE GET GR HCOLOR HGR HGR2 HIMEM HUN HOME HPLOT HTAB IN# INVERSE LOMEM NORMAL ON ERRGOTO PDL POP POS(expr) PR# RECALL RESUME ROT RUN RND(n) SCRN SCALE SHLOAD SPEED STORE TEXT TRACE VLlN VTABy WAIT XDRAW • ZBaslc Equivalent See the BLOAD and BSAVE functions on the master disk. ZBasic uses a constant as an address (not a variable). Parameters not allowed. See CLEAR in the main reference section for ZBasic's additional options. ZBasic uses this statement for all graphics modes (not just low-res). Not supported (ZBasic is a compiler). More options in ZBasic. See DEF FN and LONG FN in the main reference section. ZBasic only allows constants in DIM exrpressions. See DIM. Not available (see DRAW.FN example on the master disk). Not available. Not applicable (and not necessary since ZBasic doesn't do "Garbage collection"). Not available. See GET.FN on the master disk. Use: MODE 1 :CLS. Use: COLOR. Use: MODE 5 (also see MODE 7 for double hi-res). Not applicable Not applicable Use PLOTx,y TO x2,y2 Use CLS. Use PLOT Use LOCATE x, PEEK(37) (also see PRINT@ 1% and INPUT@/%) Use INSLOT Use CHR$(15). See "Inverse Characters" in this appendix. Not applicable Use CHR$(14). See "Inverse Characters" in this appendix. See ZBasic's ON ERROR GOSUB statement. See DEF MOUSE and MOUSE in this appendix and the main reference section. Use RETURN nnnn instead. Expr=O for default device, 1 for printer and 2 for disk. See OUTSLOT, LPRINT, OPEN"C" and ROUTE. Not available. Use RETURN with ON ERROR GOSUB Not available. See RUN in this appendix and in the main reference section for other options. ZBasic returns an integer number between one and n. Use POINT Not available. Not available. Not available. Not available. Not available. Use MODE 0, 2, 4 or 6 instead. See MODE. Use TRON or TROFF (also see TRONX, TRONS). Use PLOT x,y TO x2,y2 Use LOCATE PEEK(36), Y (see PRINT@ 1% and INPUT@.I''Io) Not available. Not available. Many of the commands Applesoft supports have extentions in ZBasic. For instance; ELSE is supported with IF THEN. RESTORE will allow you to position the DATA pointer to a specific item, PRINT USING is supported, etc. Note: When converting programs a word processor with FIND and REPLACE is very handy. continued ... D-23 ProDOSTM Appendix ; APPLE ProDOS APPENDIX 'AlII DIFFERENCES IN DISK FILE COMMANDS Applesoft File Commands ZBaslc Equivalents OPEN A FILE FOR INPUT PRINTCHR$(4)"OPEN filename" PRINTCHR$(4)"READ filename" OPEN"I",filenum, '1ilename" OPEN A FILE FOR OUTPUT PRINTCHR$(4)"OPEN filename" PRINTCHR$(4)"WRITE filename" OPEN"O",filenum,"filename" OPEN A FILE FOR READ/WRITE PRINTCHR$(4)"OPEN filename, L100" PRINTCHR$(4)"OPEN filename, R10" OPEN"R",filenum,"filename",100 RECORD#filenum,10 CLOSE FILES PRINTCHR$(4)"CLOSE filename" PRINTCHR$(4)"CLOSE" CLOSE#filenumber CLOSE Note: Also see "Files" in the front section of this manual for more information about ZBasic's powerful file handling commands. Also see: RECORD, READ#, WRITE#, DIM, PRINT#, INPUT# and L1NEINPUT#. PEEKS, POKES, AND SYSTEM CALLS Applesoft CALL -958 CALL -868 X=PEEK(-16336) X=PEEK(-16287), Y=PEEK(-16286) ZBaslc Equivalents CLSPAGE CLS LINE See SOUND in reference section. See MOUSE(3) and DEF MOUSE Other PEEK and POKE statements should work as expected except those dealing with Applesoft. Also see MACHLG, USR, CALL and LINE in the main reference section. ProDOS7>f Appendix 0-24 APPLE ProDOS APPENDIX TRANSFERRING ZBaslc DOS 3.3 FILES TO THE ProDOS VERSIONS OF ZBaslc The file format for the ProDOS version of ZBasic is different than the file format for the DOS 3.3 version of ZBasic. Therefore; follow these instructions to convert files: 1. LOAD your program into the DOS 3.3 version of ZBasic. 2. Use the SAVE" command to save the source code in ASCII. 3. Exit the DOS 3.3 version of ZBasic and boot your favorite DOS 3.3 to ProDOS conversion program; such as CONVERTfound on your ProDOS tUSERS.DISK or APPLE SYSTEMS UTILITIES. 4. Copy the file just saved in ASCII to a ProDOS formatted diskette. 5. Execute either the 64K or 128K ProDOS versions of ZBasic and LOAD the program. Programs created in the DOS 3.3 version should run with few, if any, changes; aHhough you may want to modify the programs to take advantage of the ProDOS tRAM disk or the 16 colors available in Double Hi-Res. D-25 ProDOSTM Appendix APPLE ProDOS APPENDIX ASIC REFERENCE SECTION This section of the appendix discusses commands unique to the ProDOS version of ZBasic and commands that may have other meanings other than those described in the main reference section. ProDOSTM Appendix D-26 APPLE ProDOS APPENDIX fflgWgf.,...,........,..,.~ CLS command FORMAT CLS [n] DEFINITION Clears the screen. Same as the standard CLS statement with the following variations: • If you are currently editing in one of the text modes, the screen will be cleared immediately (without going through the compiler) . • If you are currently in one of the graphics modes, the command must first be compiled before it is executed by the runtime system, and takes longer. EXAMPLE See CLS in the main reference section for delailed information. REMARK This command works correctly with the standard Apple 80-column card and Videx 80column cards (and compatible). Any control key typed at the keyboard that is not defined as an editor command will be passed through unchanged to the 80-column firmware. What this means is that if your card requires a CHR$(26) to clear the screen you can press CTRL-Z to accomplish the same thing. To use any of the other CLS options from within the editor, such as CLS nn, precede the command with a colon. e.g. : CLS ASC (" A") D-27 ProDOSTM Appendix APPLE ProDOS APPENDIX COLOR statement n FORMAT COLOR [=] DEFINITION The COLOR codes for the ProDOS version of ZBasic are: Modes 0, 2, 4, & 6: Text Characters only, no color. Modes 1, 3, & 7: NUMBER o 1 2 3 4 5 6 7 B 9 10 11 12 13 14 15 Mode 5: NUMBER o 1 2 3 4 5 6 7 ~ Black Magenta Dark Blue Purple Dark Green Grey Medium Blue Light Blue Brown Orange Grey Pink Green Yellow Aqua Whhe QQ.J..QR Black1 Green Violet Whhe1 Black 2 Orange Blue White2 IIGS Note: The IIGS Super Hi-Res graphics mode is not supported directly (the /Ie, /Ie modes are emulated). ProDOSTM Appendix D-28 APPLE ProDOS APPENDIX lid :Wii DATE$, TIME$ function FORMAT DATE$ TIME$ DEFINITION See the main reference manual. EXAMPLE See the main reference manual for details of usage. REMARK These functions behave exactly as described in the standard reference section if your system has a ProDOS compatible clock installed. The system performs a ProDOS call to retrieve the date and time from a clock card. If no card is installed, then the strings that are returned will be set to whatever the current values are of the ProDOS date and time locations on the global page (00/00/00 and 00:00 norrnally). If your system has no clock, and you wish to set the date and time manually, you can include the DATETIME function in your program (from your master diSk). Since ProDOS does not have any storage space for seconds, the TIME$ seconds field will always be ''~O''. D-29 ProDOSTM Appendix APPLE ProDOS APPENDIX DEF LPRINT statement FORMAT DEF LPRINT [=) Slot number DEFINITION This command is used to configure the printer slot during runtime. Alter this command is used, all printer output will be diverted to the selected slot. The slot number may be specified by any numeric expression but the value of Slot number MUST be between one and seven EXAMPLE DEF LPRINT 1 REMARK This command supersedes the configuration value, except for the initialization string. See the notes on configuration for more info. ~ If value exceeds the range of 1-7, the number will be masked to stay in range. ProDOSTM Appendix 0-30 APPLE ProDOS APPENDIX DEF MOUSE statement FORMAT DEF MOUSE [=) expression DEFINITION This statement defines which device (MOUSE or JOYSTICK) will be used for the MOUSE function call. expression=O expression<>O EXAMPLE APPLE MOUSE INTERFACE JOYSTICK DEF MOUSE=l: REM Define as a JOYSTICK DO PRINT MOUSE (1) , MOUSE (2) UNTIL MOUSE (3) END This program will print the positions of the joystick until you press the joystick button. REMARK The default is equivalent to DEF MOUSE=O. The Apple /lc has the equivalent of a mouse card built-in. If DEF MOUSE=1 is used to activate the joystick, the function MOUSE(3) will return a value corresponding to which joystick button was pressed. WR o 1 2 3 D-31 ProDOSTM Appendix Meaning Neither button pressed Button 0 pressed Button 1 pressed Both buttons pressed APPLE ProDOS APPENDIX DIR command FORMAT [L]DIR [+] [pathname] [L]CAT [+] [pathname] DEFINITION These commands display a directory of a ProDOS volume, as explained in the reference section. DIR and CAT are interchangeable. CAT was implemented to make conversion easier for Applesolt programmers. When the command DIR is given by itself, ZBasic will display a directory of the currently logged ProDOS pathname (see the PATH command) in the standard 40 column format. DIR+ operates in the same way as DIR without the "+", and will produce the ProDOS standard BO-column display format (more information is shown). \I in 40-column mode the output will wrap to the second line. The optional pathname specifies a directory to be displayed. The pathname can be a full or partial ProDOS pathname. Full pathnames start with a slash ("t'), and specify the root volume. If a partial pathname is specified, ZBasic will append this pathname to the currently logged pathname, and display the contents of this sub-directory. Pathnames can be any legal ProDOS pathname. The optional "L" preceding the command will direct output to the printer. There must not be a space between the "L" and the "DIR". REMARK As you can see, the first line of the directory contains the name of the directory which the listing is produced from. A slash preceding the directory name (as in the example) signifies that this is a root (volume) directory. Sub-directory names are not preceded by the slash. The heading line is pretty much self-explanatory, except the ENDFILE (found on a DIR+ listing). The figures in the ENDFILE column represent the total number of bytes in that file. The TYPE column represents the ProDOS standard file types, with one exception -ZBS. This file type is a ZBasic tokenized source file. An asterisk (*) preceding a file name signifies that this file is locked. It can not be modified in any way from within the ZBasic system. As with the editor "L1ST' command, the directory can be temporarily halted by pressing the space bar once. Pressing the space bar again will advance the directory one line. Pressing any other key will restart the listing. Pressing CTRL-C will abort the directory listing. To read a directory from within a running program, simply OPEN the directory file as you would any other, then read the necessary information from it. See the ProDOS Technical Reference Manual, Appendix B, for information concerning the format of directory files. Also see the special ZBasic Pro DOS command: ONLINE. ProDOSTM Appendix D-32 APPLE ProDOS APPENDIX : . . . . . . . . .1 EXAMPLE • ZBasic Ready DIR !ZBASIC NAME TYPE BLOCKS SYS BIN BIN TXT TXT ZBS TXT TXT 33 17 28 57 ZBASIC.SYSTEM *RAM.FILLER *RUNTIME.OBJ *ZBASIC.HLP DISKIO.BAS GRAPH.BAS CREATE.FN DRAW.FN BLOCKS FREE: 26 MODIFIED 10-FEB-87 31-JAN-86 29-JAN-87 12-0CT-86 5-DEC-86 6-NOV-86 20-JAN-87 29-DEC-86 BLOCKS USED: 12:02 11: 40 15:49 13:18 14:26 10:25 11 :31 17:08 254 ZBasic Ready ZBasic Ready DIR+ !ZBASIC NAME ZBASIC.SYSTEM *RAM.FILLER *RUNTIME.OBJ *ZBASIC.HLP DISKIO.BAS GRAPH.BAS CREATE.FN DRAW.FN BLOCKS FREE: TYPE SYS BIN BIN TXT TXT ZBS TXT TXT 26 BLOCKS 33 17 28 57 MODIFIED CREATED 10-FEB-87 31-JAN-86 29-JAN-87 12-0CT-86 5-DEC-86 6-NOV-86 20-JAN-87 29-DEC-86 10-FEB-87 10-FEB-87 10-FEB-87 10-FEB-87 10-FEB-87 10-FEB-87 10-FEB-87 10-FEB-87 BLOCKS USED: ZBasic Ready NOTE: endfile numbers may not be actual. D-33 ProDOSTM Appendix 254 12:02 11: 40 15:49 13:18 14:26 10:25 11 :31 17:08 TOTAL BLOCKS: ENDFILE 12 :51 12: 51 12: 51 12 :51 12:51 12:51 12: 51 12: 51 280 16384 9384 7644 384 844 1982 123 456 APPLE ProDOS APPENDIX EDITOR command FORMAT EDITOR [+J DEFINITION This command is used to enter the full screen text editor from the Standard line editor. Typing "EDITOR" on the ZBasic command line will transform any program currently in memory from ZBasic tokenized format to full ASCII format and enter the full screen editor. If you use the optional "+", the program currently in memory will have the line numbers stripped prior to entering the full screen editor. Be sure that you have not used any line number references in your program (such as GOTO or GOSUB). Use label references instead. REMARK See the section entitled "Full Screen Editot' in this appendix for a complete description of editor commands and operation. Note: To get back to the standard line editor press ESC (or CTRL-K CTRL-Q on U+ ). ProDOSTM Appendix D-34 APPLE ProDOS APPENDIX INSLOT statement FORMAT INSLOT(Slot Number) DEFINITION This statement will allow you to specify the slot number of an interface card which your program is to receive input from. This is supplied so that you can use non-standard interface cards (Le. other than those supported directly by ZBasic, such as a graphics tablet). Do not use this command to access a Super Serial Card; use the OPEN"C" command instead. INSLOT(O) will Ore-attach" the keyboard for input. EXAMPLE CLS DO INPUT"Which slot is the widget?";Slot UNTIL (Slot>O) AND (Slot<8) INS LOT (Slot) do something with the slot here •.. INS LOT (0) <--- Set the slot back to normal. END (example only do not use) REMARK See your hardware technical reference manuals for details. Note: Any interface card that attempts to store a value into an Applesoft variable (such as some clock cards) will not work correctly with ZBasic since there are no "Applesoft variables" in ZBasic. Check the technical reference manual of the device to set it to some other parameters. D-35 ProDOSTM Appendix APPLE ProDOS APPENDIX MEM command FORMAT MEM DEFINITION This command is used to show the amount of memory remaining for text and object code remaining and the amount of text and object code space used during each phase of operation. ##### ##### ##### ##### ##### Text Text Mem Object Variable Code Mem • Shows amount of text space used • Amount of text room remaining • Size of object code generated· • Amount of variable space used" • Object and variable space remaining" ·Values returned only correct immediately after compiling (RUN). REMARK See Memory map in this appendix for the 64K or 128K ProDOS versions of ZBasic. Also see MEM in the main reference section. ProDOSTM Appendix D-36 APPLE ProDOS APPENDIX taU ill::IiIb 1. iii;;;' MODE statement FORMAT MODE [=]expression DEFINITION ZBasic uses MODE to define the characteristics of a screen. ZBasic allows a program to integrate text and graphics anywhere on the screen in MODE 5 and 7. This feature allows ZBasic programs from an IBM PC and other computers to run on your Apple. ProDOSTM Version MODE CHART MODE 0,8 REMARK I TEXT 40 x24 I GRAPHICS Character 1 None 40 x 48 2,10 80 x 24 Character 3 None 80 x 48 4,12 40 x 24 Character 5 40 x 24 280 x 192 6,14 80 x 24 Character 7* 80 x 24 560 x 192 9 40 x4 40 x 40 11 80 x 4 80 x 40 13 40 x4 280 x 160 15* 80 x 4 560 x 160 character 40x48 80x48 280 x 192 '560 x 192 = Graphics are defined as text characters = Low Resolution Color Graphics = Medium Resolution Color Graphics = High Resolution Color Graphics = Double High Resolution. For lie, IIc and IIGS only. Modes 9, 11, 13 and 15 have graphics at the top of the screen and text at the bottom, similar to Applesoft GR and HGR commands. MODE will set COLOR to default, white in most modes. See COLOR for the other colors available in each mode. 'Double Hi-Res does not function in the 64K version (it requires 128k). D-37 ProDOSTM Appendix APPLE ProDOS APPENDIX ON LINE command FORMAT ONLINE DEFINITION When the ONLINE command is issued in the Standard Line Editor, a list of all ProDOS volumes currently connected to the system will be displayed on the screen. Each entry will display the slot, drive, and volume name of the device. EXAMPLE ZBasic Ready ONLINE S6,Dl S3,D2 REMARK /ZBASIC /RAM Since ZBasic will only operate on volumes by using pathnames, this is supplied so that you can identify a particular volume in a drive. ProDOSTM Appendix D-38 APPLE ProDOS APPENDIX "'1111'.~ OUTSLOT statement FORMAT OUTSLOT(s/ot numbef) DEFINITION This command allows you to redirect output to the interface card located in the slot number specified. This is not intended as an altemative to the existing ZBasic commands (such as LPRINT or ROUTE). This command is supplied only to allow you to interface your program with those cards that ZBasic does not support directly (such as graphics tablets. etc.). OUTSLOT(O) will "re-attach" the screen for output. EXAMPLE CLS DO INPUT"Which slot is the widget?";Slot UNTIL (Slot>O) AND (Slot<8) OUTSLOT(Slot) do something with the slot here ... OUTSLOT(O) END <--- Set the output back to normal. (example only do not use) REMARK 0-39 See INSLOT statement and your hardware technical reference manuals for details about using slots. ProDOSTM Appendix APPLE ProDOS APPENDIX tllff,f,M'tiI'{il,lw. . . . . . . .lJiMiifll• •I¥Wi%{i!11ifiq PATH command FORMAT PATH [[-] [-] ... ] [pathname] PREFIX [[-] [-] ... ] [pathname] DEFINITION The PATH command allows you to set and/or display the currently logged ProDOS pathname. PREFIX is also provided for compatibility reasons. PATH without any parameters will display the current ProDOS prefix. "PATH pathname" will set the current ProDOS prefix, then display it as a verification that it was indeed set. Pathname can be either a full or partial pathname. If it starts with a slash ("f'), ZBasic will treat it as a full path name and reset the prefix appropriately. If you specify a partial pathname, ZBasic will append it to the current prefix to create the new prefix. The "-" parameter will "step-back" the current prefix by one directory. If a pathname is specified after the "-", ZBasicwill then set this as the current prefix. You may use more than one "-" parameter to specify stepping back multiple directories. EXAMPLE ZBasic Ready (display current prefix) PATH /PROFILE ZBasic Ready PATH ZBASIC/SOURCE /PROFILE/ZBASIC/SOURCE (append ZBASIC/SOURCE ) (to current prefix) ZBasic Ready PATH-OBJECT /PROFILE/ZBASIC/OBJECT (remove SOURCE and) (append OBJECT) ZBasic Ready REMARK ZBasic will not allow you to remove the prefix entirely. The system MUST have a prefix set at all times. ProDOSTM Appendix 0-40 APPLE ProDOS APPENDIX l&l_if_AW". . . . .W@ :iI:i~-._ 44i1' POINT function FORMAT POINT (expression1 , expression2) DEFINITION This function will return either a 0, signifying that the pixel is "off," or a 1 signifying that the pixel is "on." EXAMPLE PLOT 0,0 PRINT POINT(O,O) CLS PRINT POINT(O,O) END RUN 1 o REMARK 0-41 In modes 5 and 7, the POINT function cannot return the color of the pixel at the specified coordinates, due 10 the method that the Apple uses to create colors on the screen. ProDOsm Appendix APPLE ProDOS APPENDIX 'x' ~ ..., RENAME command FORMAT RENAME ["] pathname1 ["]. ["] pathname2 ['1 DEFINITION Renames the file specified by pathname1 to the name specified by pathname2. The comma separating the names.lS. required. This command is supplied as an editor command in addition to the ZBasic statement so that the compiler does not have to be accessed every time you wish to rename a file. EXAMPLE RENAME ZBASIC.SYSTEM, ZBASIC REMARK See RENAME in the main reference section for more information about using RENAME. ProDOSTM Appendix D-42 APPLE ProDOS APPENDIX mmmmmll ~!i!~'Ii~! RUN* command FORMAT See the main reference manual for syntax. REMARK When saving your compiled programs to disk with the RUN" command, ZBasic will create a SYS type file that can be executed directly from ProDOS. 64KVERSION In addition to your object file, the file "RUNTIME.OBJ" MUSTbe in the same directory. 128K VERSION In addition to your object file, the following three files must be in the directory: RT.MAIN.OBJl RT.AUX.OBJO RT.AUX.OBJl As part of it's initialization, your program attempts to load the runtime modules from disk (you don't have to do this; the compiler will generate the necessary code automatically). If the required runtime files cannot be found, a ProDOS error message will be generated, and you will be left in the Apple system monitor. D-43 ProDOSTM Appendix , APPLE ProDOS APPENDIX . USR function FORMAT See the main reference manual. REMARK When your USR subroutine is entered, the value that was in the parentheses in the ZBasic program can be found at zero page locations $64 and $65. This value will be a 16-bit integer in standard least-significant-byte/most-significant-byte order. If your subroutine is to pass a 16-bit value back to the ZBasic program, it should place the value in locations $64 and $65, again in Isb/msb order. 128K Note: Be aware that with this version the USR routine must be located in the program auxiliary bank of memory. This is most easily accomplished by using" DEF USRx=LINE nnnn ProDosm Appendix D-44 APPLE ProDOS APPENDIX USR5 function = USR5(slot) FORMAT variable DEFINITION This pre-defined USR function returns the status byte of an Apple Super Serial Card in slot number slot. The status byte will be returned in the lower 8 bits of variable. The variable must be an integer variable. If no Super Serial Card is installed in the system, the value returned will be undefined. REMARK D-45 See OPEN"C" for more details about using communication functions and the Super Serial Card reference manual for the format of the status byte. ProDOSTM Appendix APPLE ProDOS APPENDIX TM ASIC \FUll SCREEN EDITOR This version includes an easy-to-use, full screen text editor. It can be used to enter and edit ZBasic source program liles, or any other text file. Some of it's features include full screen cursor movement, long distance cursor movement, split screen operation, cutlcopy/paste/replace lines, global search, automatic indentation, full scrolling capabilities up/down and left/right, and some other goodies. DIFFERENCE BETWEEN THE FULL SCREEN EDITOR AND STANDARD LINE EDITOR ZBasic comes with a Standard line editor, as described in the main reference section, that works the same way on all versions of ZBasic. From this editor you can also do direct commands as described in the main reference section. You cannot do direct commands from the Full Screen Editor (other than those defined). INVOKING THE FULL SCREEN EDITOR To enter the full screen editor, type "EDITOR" from the Standard line editor ("EDITOR+" if you want to strip line numbers). If you currently have a file in memory, the file will be converted to a text file and transferred. If no file is in memory, you will enter the full screen editor without text. RETURNING TO THE STANDARD LINE EDITOR To return to the Standard line editor (command environment), press (CTRL-K 0 in the 40-column editor). The file that you were editing will be re-Ioaded into the line editor (with line numbers added Hthe file did not contain any). ProDOSTM Appendix D-46 APPLE ProDOS APPENDIX ___awl ; iilI& aO-COLUMN EDITOR If you are using an Apple lie with an 80-column text display, most of the functions are accessed by pressing one of the 0 or. keys in combination with one of the numeric keys. While the editor is waiting for you to enter a character, you have the option of using one of the commands available. HELP LINE When you press one of the Apple keys, a short "help" line will appear on the bottom line in place of the status line. This help line will remain on the screen for as long as you keep pressing an • or 0 key. The help lines are not meant to be complete descriptions of the commands available, just memory joggers. ao COLUMN CURSOR MOVEMENT KEYS • Beginning of File (j Up a Page Up a line + Left 1 Character (j Left 1 Word Beginning of Line '* Down a Line (j Down a Page It End of File D-47 ProDOSTM Appendix Right 1 character (j Right 1 Word .End of Line APPLE ProDOS APPENDIX 40-COLUMN EDITOR Since Apple U+ users don't have Apple keys on their keyboard, control keys are used in place of the Apple keys. These commands have been set up to match Wordstar™, a word processor from MicroPro where possible. For those commands that are not a part of WordstarTM, we tried to make the command key match the command as logically as possible (the command is followed by an asterisk if it is not WordStar compatible). When one of the prefix keys (Ctrl-Q or Ctrl-K) is pressed a "AQ" or "AK" appears in the lower left corner of the screen, to remind you that one of the prefix keys has been pressed. If you change your mind, and don't want to access one of the commands, simply press the space bar to cancel the command. The following pages describe all of the commands and cursor movements available. Each one operates exactly the same way, whether the machine is a 1[+ or one of the newer machines. 40 COLUMN CURSOR MOVEMENT KEYS NOTE: 1\ = USING THE FULL SCREEN EDITORS The following pages contain a complete description of the Full Screen Editor. You may want to Xerox the Quick Reference page. ProDOSTM Appendix 0-48 APPLE ProDOS APPENDIX .M::: FULL SCREEN EDITOR QUICK REFERENCE PAGE 40 Column Left 1 Character CTRL·D Right 1 Character CTRL·A Left 1 Word CTRL·F Riqht 1 Word To Beginning of Line To End of Line CTRL·Q CTRL·S CTRL·Q CTRL·D CTRL·E Up a Line CTRL·X Down a Line CTRL·R CTRL·Q CTRL·R Up a Page Down a Page To Beginning of File CTRL·Q CTRL·C To End of File CTRL·C "---' 40 Column ----"-~ .... ..- CTRL·K CTRL·Q CTRL·Q CTRL·Q CTRL·Y CTRL·V CQMMA.ND~ BO Column +- --.. d+0--.. .+.--.. t d d .,• BO Column Return to Line Editor ESC Delete Character Delete to Line Start d Delete End of Line Switch INSERT/Overwrite • Delete d .0 Delete Delete CTRL·K CTRL·N Clear Text Buffer NEW • ·0 CTRL·K CTRL·L LOAD File 0 ·1 CTRL·K CTRL·S SAVE File CTRL·K CTRL·X d ·2 CTRL·K CTRL·V Cut Line Paste Line CTRL·K CTRL·C Copy Line d • ·2 CTRL·K CTRL·R ti ·3 CTRL·N Replace Line Insert Line d Delete Line CTRL·Q CTRL·F Find '* ·4 CTRL·Y d ·4 ·5 CTRL·L Find Next Occurence CTRL·K CTRL·I d • ·5 ·6 CTRL·Q CTRL·I Set Tab Value Autotab On/Off Ii ·6 CTRL·K CTRL·F Restore Line 0 ·7 CTRL·K CTRL·P Ii ·7 d ·8 d • ·8 ·9 • ·9 CTRL·Z LLiST Scroll Up CTRL·W Scroll Down CTRL·K CTRL·T Freeze Top Freeze Bottom CTRL·K CTRL·B D-49 CURSOR CTRL·S ProDOSTM Appendix • ·1 ·3 APPLE ProDOS APPENDIX 5 iL [ hi"'. ifi' WX CURSOR KEY DEFINITIONS This page contains the detailed descriptions of the cursor key movements for the Full screen ed~or: 80 COLUMN 40 COLUMN DOWN A LINE UP A LINE Up-Arrow Moves the cursor up one line. CTRL-E Down Arrow Moves the cursor down one line. DOWN A PAGE UP A PAGE ~-Up-Arrow CTRL-R Moves the cursor one page back in the file. A page is defined as the current number of lines in the editing window minus one. ~-Down-Arrow CTRL-C Moves the cursor down one page in the file. DOWN TO END OF FILE a-Down-Arrow CTRL-Q Moves the cursor to the end of the file. UP TO TOP Gt-Up-Arrow CTRL-Q Places the cursor at the beginning of the file. CTRL-X CTRL-C CTRL-R LEFT A CHARACTER Left Arrow Moves the cursor one character to the left. CTRL-S LEFT A WORD ~-Left Arrow CTRL-A Moves the cursor to the beginning of the word to the left of the current cursor pos~ion. LEFT TO START OF LINE Ii-Left-Arrow CTRL-Q Moves the cursor to beginning of current line. CTRL-S RIGHT A CHARACTER Right Arrow Moves the cursor one character to the right. CTRL-D RIGHT A WORD ~-Rlght-Arrow CTRL-F Moves the cursor to the beginning of the next word to the right of the present pos~ion. RIGHT TO END OF LINE .-Rlght-Arrow CTRL-Q CTRL-D Moves the cursor to the end of the current line. ProDOSTM Appendix D-50 APPLE ProDOS APPENDIX FUll SCREEN EDITOR COMMANDS This following pages contain the definitions for the full screen ed~or commands (cursor movement definitions are on the previous page). 80 COLUMN The current setting of the Insert/Overwrite switch can be seen on the status line. NEW (Clear Text Buffer) 40 COLUMN DELETE CHARACTER DELETE Left Arrow" Delete~ the character to the left of the cursor. If the cu~sor I~ currently at the beginning of the line, then the edrtor will assume that the user means to delete the carriage. return at the end of the previous line. The current line and the previous line will be combined and the cursor will be placed at the old end of the previous line. DELETE TO BEGINNING OF LINE O-DELETE CTRL-Q Left Arrow" Deletes characters from the beginning of the line through the character to the left of the cursor. The remainder of the line will be moved to the left. DELETE TO END OF LINE Ii-DELETE CTRL-Q CTRL-Y Deletes characters from the current cursor position to the end of the line. QUIT THE FULL SCREEN EDITOR ESC CTRL-K CTRL-D CTRL-K CTRL-Q This command qu~s the Full Screen Ed~or and returns to the Standard line editor. Any text that is currently in the text buffer will be re-Ioaded into the line editor with line numbers added to each line if the text does n~t already contain line numbers. INSERT / OVERWRITE 0-0 CTRL-V This command is another toggle, switching the editor between Insert and Overwrite modes of operation. The ed~or "wakes-up" with overwrite mode selected (as can be seen on the bottom status line). The overwr~e cursor is the underline character. While overwrite mode is active, any characters that you type will replace whatever character the cursor is currently on (except for the carriage return character at the end of a line). If the cursor is at the end of a line, then any characters that you type will effectively be inserted ahead of the terminating carriage return. When Insert mode is selected, the cursor character changes to the caret ("'") character, and any characters that you type will be inserted at the current cursor pos~ion, moving any characters at and to the right of the cursor over one pos~ion to the right. If you press D-51 RETURN while in the middle of a line, the cursor will be moveddown a line and to the left margin, and the portion of the line at and to the right of the cursor will be brought down as well. ProDOSTM Appendix 8-0 CTRL-K CTRL-N* This command will clear any text from the text buffer and set the search string to null. It will then clear the active wind~w, and place the cursor in the upper left corner of the Window. k also removes the current file name from memory, and selects overwr~e mode. If no file is in memory when the ed~or is entered, this is the state that is set when the ed~or "wakes-up." LOAD A FILE 0-1 CTRL-K CTRL-L" This commands clears any text from the text buffer and then will prompt you for the ProDOS path name of a file to load. The fil~ MUST be a TEXT type file (TXT). If it isnl, you Will receive an error message. Hyou have previously loaded a file, the system will place the file name of this file on the screen for you ~utomaticaJJy. If this is the file that you wish to re-Ioad (~, for example, you really botched up the file and want to start over again), simply press the return key. If you want a d~ferent file altogether, press CTRL-X to remove the old file name, and enter the new file name. The left arr~w key or the dele!e. ~ey ca~ be used to correct any typing errors. H you mrtlate thiS command by accident, you can press CTRL-C to return to the editor with your current file intact. SAVE A FILE .-1 CTRL-K CTRL-S This command will prompt you for a ProDOS pathname to save the current text. If you have previously used the Load command to load a file into the buffer, the system will place the current file name on the prompt line for you. You have the same options here as you did when you loaded the file. Use caution w~h this command. If a file already exists on the disk w~h the same file name, the editor will replace whatever was previously in the file without any warning message. CUT LINE 0-2 CTRL-K CTRL-X" This command will remove the current line from the text buff~r and place ~ o.n the. clipbo~rd Oust a temporary holding area). The line Will remain on the clipboard until you e~her Cut another line, or Copy a line. This line can be pasted from the clipboard back into the main text buffer with the Paste command. This command will only work w~h entire lines. There is no way to Cut in increments of less than, or more than, a single line. APPLE ProDOS APPENDIX (This command actually does a COPY, and then a DELETE.) PASTE LINE .-2 CTRL-K CTRL-V* This command will copy whatever line is currently on the clipboard into the current pos~ion within the main text buffer. The current line will be moved up in the buffer (down on the screen) to make room for the new line. This action does NOT remove the line from the clipboard. Therefore, you can paste the same line as often as you like, into as many places in the text as you like. COpy LINE CTRL-K CTRL-C* 0-3 This command will make a copy of the current line to the clipboard. It does not remove the line from the main buffer. You are then free to paste this line to your liking. REPLACE LINE ~-3 CTRL-K CTRL-R* This command will replace the current line w~h the line that is currently on the clipboard. If there is no line currently on the clipboard, no action will be taken. INSERT LINE 0-4 CTRL-N This command will insert a carriage return at the current cursor position without moving the cursor. H the cursor is at the beginning of a line, then the current line will move down on the screen, leaving a blank line for you to enter a new line on. If the cursor is in the middle of a line, the portion of the line at and to the right of the cursor will be moved down to the next line, and the cursor will remain at the (new) end of the current line. DELETE LINE 0-4 CTRL-Y This command deletes the current line from the text. No copy of the line is retained in memory. Therefore, this is not a reversible command. Use ~ with caution. FIND This command searches for the last search string that was entered using the FIND command. This command operates in exactly the same way as the find command, except that it does not prompt for the search string. (As a matter of fact, the find command prompts for the search string, and falls through to this command.) SET TAB STOP 0-6 CTRL-K CTRL-I This command will allow you set the size of the tab stops. The editor will prompt you for the new value on the bottom line of the screen. The last part of the prompt is the current value of the tab setting, which has a default of 16. To leave this setting, simply press the RETURN key. To change ~, enter the new value. The editor uses the same tab value as the rest of the ZBasic system, so this command accomplishes the same thing as the DEF TAB statement in a ZBasic program. This also implies that ~ the value is changed here, then the value will be changed for the rest of the system as well. This tab value is used in the screen ed~or whenever you press the TAB key (CTRL-I for 1[+ users). The cursor will be pos~ioned to the next calculated tab stop on the screen. H the next tab stop is beyond the end of the line, the cursor will be placed AT the end of the line. H you continue to press the TAB key, the cursor will move to the beginning of the next line (the absolute first tab position on the screen), and then continue normally. AUTO TAB ON/OFF d-6 CTRL-Q CTRL-I* This command is simply a toggle to turn the autotab feature on or off. The ed~or starts with autotab on. The current setting of autotab can be seen on the status line at the bottom of the screen. Autotab is a feature that will allow you to enter nicely formatted source code. When Insert mode is on, and RETURN is pressed at the end of a line, the cursor will be moved down to the next line, and then spaces will be inserted in the new line until the cursor is in a position underneath the first nonspace character in the line above. H Insert is off (Overwrite mode), autotabbing is only operable when you are entering text at the end of the file. This is so that spaces are not inserted ahead of any existing text. RESTORE LINE 0-5 CTRL-Q CTRL-F This command will allow you to enter a character sequence of up to 30 characters. The ed~or will then search from the current position to the end of the file for the character sequence. If ~ can1 find the search string, a message will be displayed on the last line to this effect, and the cursor position will not change. If the string is found, the line containing the string will be placed at the current cursor position, and the cursor will be placed at the beginning of the string. FIND NEXT OCCURRENCE 6-5 CTRL-L 0-7 CTRL-K CTRL-F* This command will restore the line at the current cursor pos~ion, deleting any changes that you have made to the line. This will only work ~ the cursor has NOT moved off the line since you made the changes, and/or the screen has not scrolled sideways. Normally, while you are ed~ing a line, you are actually editing a copy of the line in an ed~ buffer. When the cursor is moved off the line, or Hthe screen is scrolled either left or right, this edit copy of the line is moved back to the main text buffer prior to moving the cursor. If you have made some changes to a line, and then change your mind, an old copy of the line still resides in the main buffer. A ProDOSTM Appendix D-52 APPLE ProDOS APPENDIX copy of this old line is placed into the edit buffer over any changes that you might have made when you invoke this command. 0-9 PRINT LINE ,*-7 CTRL-K CTRL-P This command will print the contents of the text buffer to your printer. This command accomplishes the same operation as the line editor's LLiST command w~hout any parameters. The entire contents of the text buffer will be printed; no provision is provided for printing only a portion of the buffer. H no printer is connected in the slot that is currently configured, the system may "hang". Press CTRL-RESET to warm start the ed~or. SCROLL DOWN 0-8 CTRL-W This command will scroll the screen down, with the cursor remaining in the same screen position (which means that ~ will be on the previous text line). H the cursor is currently w~hin the first page of the text, the screen will not scroll, but the cursor will move up a line. The cursor will NOT move past the first line of the file. CTRL-Z This command will scroll the screen up, w~h the cursor remaining in the same screen position (which means that it will be on the next text line). H the cursor is currently within the last page of the text, the screen will not scroll, but the cursor will be moved down a line. The cursor will NOT move past the last line of the file. CTRL-K CTRL-T* This command will freeze the top of the screen. A separating line will be drawn at the current cursor pos~ion, and the portion of the screen above this line will be frozen. The line that the cursor is in will remain w~hin the new active portion of the screen (the active window). While the screen is frozen, the cursor will not move into the frozen portion, and no changes will be made within the frozen portion. Only the screen is frozen. You can still move the lines that are in the frozen portion into the active window and make changes, but these changes will not appear in the frozen window. To "thaw out" the window, press the control key sequence again. The separating line will be removed, and the screen will be refreshed, leaving the cursor at whatever pos~ion it was at. FREEZE SCREEN FROM LINE DOWN .-9 SCROLL UP .-8 FREEZE SCREEN FROM THAT LINE UP CTRL-K CTRL-B* This command freezes the bottom portion of the screen. A separating line will be drawn at the current cursor position, and the portion of the screen below this line will be frozen. The text line that the cursor was on will remain within the active window. This command is very much like the Freeze Top command. To "thaw out" the bottom window, press the command key sequence again. These two Freeze commands are entirely separate from each other. You can have up to two frozen windows on the screen: a top window and a bottom window, leaving a third, active window in the middle of the screen between the two frozen portions. This can be handy if you have a couple of dijferent subroutines in a couple of different sections of your program, while accessing those subroutines in a third portion of your program. D-53 ProDOSTM Appendix For Macintosh Programmers ... ASIC CONSTRUCTION SET A utility that brings you a MacDraw-like environment for easily creating: WINDOWS EDIT FIELDS MENUS BUTTONS SCROLL BARS Very little typing.... just draw with the mouse. You can set up complicated EDIT FIELD, BUTTON, MENU and WINDOW layouts in minutes (that used to take many incredibly boring, tedious, hours). The ZBasic Construction Set creates a ZBasic Source file that you just merge into your programs. Created by a ZBasic programmer that got tired of spending a couple of days for each program JUST TO DO THE SCREEN LA YOUTS! Best of all the price i~n~ght: $49.95 -,., 1/1 S !--- plus shipping and handling: $5 U.S., $12 Canada, $25 Overseas The ZBasic ConstructiQn Set is available now only from Zedcor direct: 800-482-4567 ZED COR 4500 E.Speedway,#22 Tucson, Arizona 85712 (602) 881-8101 E -1 Macintosh™ Appendix MACINTOSH APPENDIX ASIC ZBasnc Macoll1ltoslhl™ Version 4.0 For the Macintosh 512K, Macintosh Plus, Macintosh SE, Mac XL and LlSA® with MacWorks™ and the Macintosh II Additions and Enhancements to 4.0 by Andrew Gariepy Original version by Andrew Gariepy, Dave Overton and Scott Terry © Copyright 1985, 1986, 1987 ZEDCOR, Inc. All Rights Reserved MacintoshThl, Apple, FinderTld, RMaker™, MacintalkTN and AppletalkTN are registered trademarks of Apple Computer,lnc. Macintosh™ Appendix £-2 MACINTOSH APPENDIX TABLE OF CONTENTS Getting Started E6 Files Included on the Master Diskette E7 Notes to this version Enhancements to The Old Version Executing ZBasic from the FINDER Keyboard variations in the Command Window Line Editor versus Full Screen Editor COMMAND Window EDIT Window No Line Numbers Errors HELP Window HFS versus MFS Loading Old ZBasic files Memory Available to Variables Machine Language Longlnteger Using MKI, HEX, OCT & BIN with Longlntegers File and Memory Requirements Setting Defaults to Longlnteger Floating Point enhancements 10,000 digits of Accuracy? Obtaining Maximum Speed Speed versus Accuracy File Length Enhancements RS-232 Communications Determining if Old or New ROMs are installed Speed and EventTrapping Debugging Programs Breaking Out of Programs E8 E8 E8 E8 E8 E9 E10 E10 E10 E11 E11 E11 E12 E12 E12 E12 E12 E12 E13 E13 E13 E14 E15 E15 E15 E15 E15 E15 Macintosh Specific Configuration Options E16 How To Write a Macintosh-Type Application The Macintosh Interface Things to Avoid Structure of Macintosh Programs E17 E17 E17 E18 Macintosh Memory Manager Using SEGMENT Taking Advantage of Memory Management CHAINING E19 E19 E20 E20 Clipboard E21 E21 E22 E22 Get "TEXT" and "PICT" from Clipboard Put "PICT" on the Clipboard Using INDEX$ to get and put "TEXT" Macintosh Graphics MacPAINT, Tiff and MacDrawfiles QuickDrawn.< and PostScript™ E-3 Macintosh™ Appendix E23 E23 E23 MACINTOSH APPENDIX Printing Using PostScript™ E24 E25 E26 Appletalk Macintalk Phoneme Table E27 E2B Converting MSBASICTM programs E29 Using RMaker™ E32 Example of Adding Icons to your Applications E39 ALPHABETICAL APPEND APPLE MENU BLOCKMOVE BREAK BUNDLE BUTTON BUTTON CALL CLEAR LPRINT COMPILE CREATOR CURSOR DEFDBL INT DEFLPRINT DEFMOUSE DEFOPEN DEFPAGE DEFSTRLONG DEFSTRWORD DIALOG DIALOG DIR EDIT FIELD EDIT MENU EDIT$ EJECT FILES$ FINDERINFO FLUSHEVENTS GET FILE INFO GET VOLUME INFO GET WINDOW HANDSHAKE INDEX$ INKEY$ KILL KILL PICTURE LCOPY LOF LPRINT MEM(n) MEMORY MONITOR MENU MENU (ON/OFF/STOP) MENU MODE MOUSE MOUSE E42 E43 E44 E45 E46 E47 E4B E50 E52 E53 E54 E55 E56 E58 E59 E60 E61 E62 E63 E63 E64 E68 E72 E73 E75 E76 E77 E78 E81 E82 E83 E85 E87 E88 E89 E91 E92 E93 E94 E95 E96 E97 E98 E99 E101 E102 E103 E104 E106 REFERENCE statement statement statement statement command function statement statement function command function function statement function statement statement function statement statement function statement statement statement statement function function function function statement function function statement statement enhancements alternatives statement statement statement function enhancements function Desk Accessory function statement statement statement function statement Macintosh™ Appendix E-4 MACINTOSH APPENDIX ON BREAK GOSUB ON DIALOG GOSUB ON MENU GOSUB ON MOUSE GOSUB ON TIMER GOSUB OPEN"new types" OPEN"C" OPEN TALK PAGE LPRINT PEN PICTURE PICTURE PRCANCEL PRHANDLE PRINT USING PUT PUT FILE INFO READ FILE RENAME ROUTE 128 RUN SCROLL SCROLL BUTTON SEGMENT SEGMENT RETURN SHUmOWN SOUND SOUND SYSERROR TALK TEHANDLE TEXT TIMER TIMER TRON#128 TRONV TRON MONITOR USR defaults WAVE WIDTH [LPRINTJ-2 WINDOW WINDOW WINDOW PICTURE WRITE FILE statement statement statement statement statement statement statement statement statement statement function statement function function statement enhancement statement statement statement statement enhancement statement statement statement statement statement function statement function statement function statement function statement statement statement Desk Accessory function statement statement function statement statement statement Macintosh Toolbox ~ E-5 El07 El08 El09 Ell0 Elll E112 E113 E114 E115 E116 E117 E119 E120 E121 E123 E124 E125 E126 E127 E128 E129 E130 E131 E134 E135 E136 E137 E138 E139 E140 E141 EI43 EI44 E145 E146 E147 E148 E149 E151 E152 E153 E155 E158 E159 Pointers and Handles E160 E163 A5 Global Memory Locations Useful Memory Locations E166 E198 Alphabetical listing of terms E199 Alphabetical listing of Toolbox routines E204 Macintosh™ Appendix MACINTOSH APPENDIX GETTING STARTED Welcome to ZBasic, the most powerful and easy to use language available for the Macintosh. Follow these instructions and you'll be up and running in no time. + MAKE A BACKUP FIRST ZBasic is not copy protected. Make a copy or two for your personal backup purposes. Put the master diskette in a safe place for future use. It's a good idea to set the write protect tab on the master diske. + MOVE MAIN. PROGRAMS TO AN HFS SYSTEM DISK ZBasic is provided on a 400K single sided diskette. The diskette is readable by any Macintosh. It doesn't come with a system so you'll need to copy files to a system disketle or hard disk. The main files to copy are: ZBasic™ and ZBasic.HLP. If you plan on using MacinTalk copy this file to your system folder. All other files are example programs and may be copied at your discretion. + INSTALL PRINTER DRIVERS \I you haven't done so already, be sure to put a printer driver in your new system folder. + USE FONT/DA MOVER TO INSTALL THE ZBASIC DESK ACCESSORIES Use FontiDA Mover to move the ZBasic MEMORY MONITOR and TRON MONITOR Desk Accessories over to your system. These DA's are very useful for debugging purposes (see MEMORY MONITOR and TRON MONITOR in the reference section for explanations and examples of use). + NOTE DIFFERENCE BETWEEN THE "COMMAND WINDOW" AND "EDIT WINDOW" The EDIT Window is the Macintosh-type editor and will probably be the one you use the most. The Command Window is the "Standard Line Editor" and is the one being referred to in the front of this manual. Use to switch from one to the other. Be sure you understand the difference between these two modes before proceeding. ~ READ "GETTING STARTED" IN THE FRONT OF THIS MANUAL Read "Getling Started" in the front of this manual to get the feel of ZBasic. ~ READ THIS APPENDIX Read through this appendix and get an idea of the Macintosh specific information that is available like; the Mac specific commands in this reference section, using the Toolbox, Converting MSBASIC programs, ."How to write a Macintosh Application", and so on. ~ TRY THE EXAMPLE PROGRAMS Try out some of the example programs we've provided on the master disk. Of special interest is the Thinner.BAS program by Andrew Gariepy. It illustrates how easy it is to create Macintosh-type applications using ZBasic. There are also example programs in the toolbox section you may want to type in and try . • CREATE YOUR OWN PROGRAMS Now you can start creating your own programs. Still got questions? Call us at (602) 795-3996 and we'll be glad to help you. Macintosh™ Appendix E-6 MACINTOSH APPENDIX FILES INCLUDED ON THE MASTER DISKETTE ~ ZBasic'" The ZBasic™ BASIC Compiler (version sometimes shown). ZBasic™.HLP The Help File. Select from Apple menu or type HELP n from Command window. Macintalk™ Macintalk file licensed from Apple. Must be in the system folder of an application's start-up disk. MEMORY Monitor DA TRON Monitor DA ZBasic desk accessory. Described in the reference section. ZBasic desk accessory. Described in the reference section. ZEXAMPLE FOLDER HOUSE PYRAMID Examples of "Standard graphics". Examples of "Standard graphics". THINNERxxx.BAS A MacPaint type program that will allow you to load, modify and save out Macpaint files and Digitized TIFF files. Great example of doing Macintosh graphics (xxx is the version number). SCIFN.BAS A number of Scientific Math FN's you can use in your programs. SORT.BAS QUICK.APP SHELL.APP Example program to be used with QUICK.APP and SHELL.APP Two sort routines you can customize for your applications. QUICK is good for a large sort. SHELL is good for smaller sorts. IOTEST.BAS NEWFILE.BAS GETSCRAP.BAS GETPUT.BAS WINDOWPIC.BAS PICT.BAS SEGEXAM PLE.BAS Example of using Windows, Edit fields and more. Get pathnames at runtime. Example of getting things off the clipboard. Example of doing Window refresh with GET/PUT statements. Example of Window refreshing with WINDOW PICTURE statement. Example of deleting a PICTURE handle from memory. Example of using SEGMENT and SEGMENT RETURN How to Install Icons In your Applications: Numerous examples for putting icons into your applications. A Complete description of how to use these files is included in this appendix: RMaker™: Resource compiler licensed from Apple Computer, Inc. IOTEST.R: RMake(fM source file example program for installing Icons. XICON.Rsrc Example Icon resource. ResEdit Not included with ZBasic ...but you may want it, or some other Icon editor, for adding or editing application icons. Note: These were the examples as of 5/87, check the disk, there may be other examples. E-7 Macintosh™ Appendix MACINTOSH APPENDIX NOTES TO THE MACINTOSH VERSION ENHANCEMENTS TO VERSIONS BEFORE 4~ The following items have been added to this version of ZBasic: SELECT CASE Structure: Makes structured programming even easier. TRON MONITOR Desk Accessory: Trace variables and program flow at runtime. NEW-VASTLY IMPROVED-EDITOR: We've eliminated Apple's EDIT and the old EDIT Window. Note that you can now do most commands from the editor environment. Now you don't need line numbers at all!! Set for no line numbers under "Configure". 128K ROM SUPPORTED: Especially in the area of Toolbox calls and function. The biggest additions are with LIST MANAGER and SCSI calls. NEW MANUAL: You'll find the examples and syntax improvements in the toolbox area and the alphabetized reference section especially helpful. NEW COMMANDS like: TEHANDLE and GET WINDOW. See the reference section for details. EXECUTING ZBASIC FROM THE FINDER Insert a backup of the ZBasic™ diskette into either drive. Double-click the ZBasic icon. KEYBOARD VARIATIONS IN THE COMMAND WINDOW The ZBasic manual makes reference to certain keys for certain purposes. The actual keys you will use on the Macintosh may be different. Wherever reference is made to a key that does not exist, use this chart to find out which key to use: Reference manual Key Macintosh Key or


Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.3
Linearized                      : No
XMP Toolkit                     : Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:56:37
Create Date                     : 2011:07:02 17:51:31-08:00
Modify Date                     : 2011:07:03 09:34:56-07:00
Metadata Date                   : 2011:07:03 09:34:56-07:00
Producer                        : Adobe Acrobat 9.43 Paper Capture Plug-in
Format                          : application/pdf
Document ID                     : uuid:87f1ca38-92af-471f-8da1-17cbd3d67252
Instance ID                     : uuid:f0e8cc4b-2607-4ee5-b820-d9f5b525f511
Page Layout                     : SinglePage
Page Mode                       : UseNone
Page Count                      : 772
EXIF Metadata provided by
EXIF.tools

Navigation menu