without permission in writing from the publisher.
Specifications are subject to change without prior notice.
All products and c omp any n ames m entio ned in th is man ual are tradema rks or re gistere d trademarks of their respective holders.
BHT is a trademark of DENSO CORPORATION.
Page 3
Preface
This manual describes the syntax and development procedure of BHT-BASIC 3.5 which is a
programming language for developing application programs of the BHT-100Q/100B.
It is intended for programmers who already have some experience in BASIC programming.
For the basic description about the BASIC language, refer to documentations concerning
Microsoft BASIC
Windows documentations.
®
or QuickBASIC®. For the details about Windows™, refe r to the Mi crosoft
i
Page 4
How this book is organized
This manual is made up of 18 chapters and appendices.
Chapter 1. Software Overview for the BHT
Surveys the software structure of the BHT and introduces the programs integrated in the ROM
and the language features of BHT-BASIC.
Chapter 2. Development Environment and Procedures
Describes hardware and software required for developing application programs and the developing procedure.
Chapter 3. Program Structure
Summarizes the basic structure of programs and programming techniques, e.g., program
chaining and included files.
Chapter 4. Basic Program Elements
Describes the format of a program line, usable characters, and labels.
Chapter 5. Data Types
Covers data which the programs can handle, by classifying them into data types--constants
and variables.
Chapter 6. Expressions and Operators
Surveys the expressions and operators to be used for calculation and for handling concatenated character strings. The operators connect, manipulate, and compare the expressions.
Chapter 7. I/O Facilities
Defines I/O facilities and describes output to the LCD, input from the keyboard, and control for
the timer, beeper, and other I/Os by the statements and functions.
Chapter 8. Files
Describes data files and device files.
Chapter 9. Event Polling and Error/Event Trapping
Describes the event polling and two types of traps: error traps and event (of keystroke) traps
supported by BHT-BASIC.
Chapter 10. Sleep Function
Describes th e sleep function.
Chapter 11. Resume Function
Describes the resume function.
ii
Page 5
Chapter 12. Power-related Functions
Describes low battery warning, the prohibited simultaneous operation of the beeper/illumination LED, the wakeup, and remote wakeup.
Chapter 13. Backlight Function
Describes the backlight function
Chapter 14. Statement Reference
Describes the statements available in BHT-BASIC, including the error codes and messages.
Chapter 15. Function Reference
Describes the functions available in BHT-BASIC, including the error codes and messages.
Chapter 16. Extended Functions
Describes the extended functions available in BHT-BASIC, including the error codes and messages.
Chapter 17. Spread Spectrum Communication
(For models equipped with a spread spectrum wireless block)
Describes the spread-spectrum communication system and wireless communications programming.
Chapter 18. TCP/IP
Surveys the socket application program interface (API) and FTP client. This chapter also
describes the two function libraries--SOCKET.FN3 and FTP.FN3, which provide BHT-BASIC
programs with access to a subset of the TCP/IP family of protocols.
Appendix A: Error Codes and Error Messages
B: Reserved Words
C: Character Sets
D: I/O Ports
E: Key Number Assignment on the Keyboard
F: Memory Area
G: Handling Space Characters in Downloading
H: Programming Notes
I: Program Samples
J: Quick Reference for Statements and Functions
K: Unsupported Statements and Functions
iii
Page 6
■
Notational Conventions Used in This Book
Several notational conventions are used in this book for the sake of clarity.
1. Reserved words are printed in UPPERCASE. These are BHT-BASIC’s keywords. You
should not use them as label names or variable names.
Example:
2. Parameters or arguments which should be specified in the statements or functions are
expressed in italics.
Example:
3. Items enclosed in square brackets [ ] are optional, which can be omitted.
Example:
4. Items enc losed in b races { } and sep arated by vert ical b ars | rep resen t alterna tive i tems.
You should choose either item.
Example:
5. An ellip sis . . . indi cates that you can co de t he prev ious it em descri bed in o ne line two or
more times in su ccession.
Example:
6. Hexadecimal values are followed by h. In many cases, hexadecimal values are
enclosed with parentheses and preceded by decimal values.
Example:
In program description, hexadecimal values are preceded by &H.
Example:
CHAIN, GOSUB, and ABS
characode and onduration
[commonvariable]
CURSOR {ON|OFF}
READ variable[,variable...]
65 (41h) and 255 (FFh)
&H41 and &HFF
7. Programs make no distinction between uppercase and lowercase letters, except for
character string data.
The uppercase-lowercase distinction used in this manual is intended to increase the
legibility of the statements. For example, reserved words are expressed in uppercase;
label names and variable names in lowercase. In practical programming, it is not necessary to observe the distinction rules used in this manual.
The examples below are regarded as the same.
Example 1:
Example 2: A AND B, aandb, and aANDb
Example 3: PRINTSTR$(12), Print Str$(12), and print str$(12)
&HFFFF, &hffff, and &hFFFF
iv
Page 7
■
Icons Used in This Book
Statements and functions unique to BHT-BASIC.
■ Syntax for the Statement Reference and Function Reference
The syntax in programming is expressed as shown in the example below.
For the
INPUT statement
Syntax:
According to the above syntax, all of the following samples are correct:
The BHT-BASIC Compiler, which is a development tool, is expressed as Compiler.
The BHT-BASIC Interpreter, which runs in the BHT, is expressed as Interpreter.
Source Program and Object Program (User Program)
Generally, a source program is translated into an object program by a compiler. This
manual calls an object program a user program.
BHT and CU
This manual expresses all BHT series as "BHT." If it is necessary to make a clear distinction between the BHT supporting 2D codes and the BHT exclusively designed for
bar codes, this manual expresses the former as "BHT-100Q" and the latter as "BHT100B."
BHT SeriesModels
Readable codes
2D codesBar codes
BHT-100QBHT-103Q
BHT-103QF
BHT-100BBHT-102B
BHT-102BF
The BHT-103QF and BHT-102BF are equipped with a spread spectrum communications device.
The CU-7000 series is expresse d as "CU ."
v
√
√
-
-
√
√
√
√
Page 8
■
Bar Code and 2D Code
The BHT- 100 B is capa ble of rea ding bar c odes; the BHT-100Q is capabl e of readi ng 2D
codes and bar codes. In descriptions common to bar codes and 2D codes, both of
those codes are expressed as "bar code" in this manual.
■
Abbreviations
ANKAlphaNumerics and Katakana
BASICBeginners All purpose Symbolic Instruction Code
BCCBlock Check Character
BHTBar code Handy Terminal
CTS (CS)Clear To Send (RS-232C signal control line)
CUCommunications Unit
I/FInterface
I/OInput/Output
LCDLiquid Crystal Display
LEDLight-Emitting Diode
MODModulo
MS-DOSMicrosoft-Disk Operating System
RAMRandom Access Memory
ROMRead Only Memory
RTS (RS)Request To Send (RS-232C signal control line)
TCP/IPTransmission Control Protocol/Internet Protocol
UDPUser Datagram Protocol
VRAMVideo RAM
■
Related Publications
BHT-100 Series User’s Manuals
BHT-100 Series User’s Manual (LAN support version)
Transfer Ut ili ty Gu ide
Ir-Transfer Utility C Guide
Ir-Transfer Utility E Guide
■
Screen Indication
The lettering in the sc reens of the BHT and hos t comp uter in this manu al is a li ttle dif f erent from that in the actual screens. File names used are only for description purpose,
so they will not app ear if you hav e not down loaded files havi ng thos e names to the BHT.
The structure of software for the BHT is shown below.
User programs
BHT-BASIC Interpreter
Font files
Flash memory
User data
Extension libraries
and extended functions
System Mode
Drivers
Hardware
Application
programs
System
programs
The BHT has a fla sh ROM and RAM. All of the system pr ograms, user programs, extension
libraries, and extended functions are stored in the flash ROM. The RAM is used to run those
programs efficiently.
2
Page 11
Chapter 1. Software Overview for the BHT
System Programs
Drivers
A set of programs which is called by the BHT-BASIC Interpreter or System Mode and
directly controls the hardware. The drivers include the Decoder Software used for bar
code reading.
BHT-BASIC Interpreter
Interprets and executes user programs.
System Mode
Sets up the exec ution environment for user programs.
Extension Library
A set of programs which exten ds the func tion of th e BHT-BASIC to enable the following:
• Transmitting/receiving files by using the X-MODEM and Y-MODEM protocols
These extension programs are stored in files having an FN3 extension, in each file per
function. You should download a xxxx.FN3 file containing the necessary function from
the BHT-BASIC Extension Library (sold separately) to the user area.
Extended Functions
A set of functions integrated in system programs, which extends the function of the
BHT-BASIC. No downloading is required for those functions since they are integrated
in System. For details, refer to Chapter 16, "Extended Functions."
NOTE
Use extension libraries suited for your BHT.
Application Programs
User Programs
User-written object programs which are ready to be executed.
3
Page 12
1.1.2Overview of BHT-BASIC
With BHT-BASIC, you can customize application programs for meeting your specific needs as
given below.
• Retrieving products names, price information, etc. in a master file.
• Making a checking procedure more reliable with check digits in bar code reading.
• Improv ing th e chec king proced ure by checkin g the n umber o f di git s ente red from the ke y-
• Supporting a program capable of transferring control to several job programs depending
upon conditions.
4
Page 13
Chapter 1. Software Overview for the BHT
1.2BHT-BASIC
1.2.1Features
BHT-BASIC is designed as an optimal programming language in making application programs
for the bar code handy term inal BHT, and to enable efficient pr ogra m develo pment , with the f ollowing features:
■
Syntax Similar to Microsoft™ BASIC
BHT-BASIC uses th e BASIC langu age whic h is th e most wide ly used on e amon g the hi gh-lev el
languages. The syntax of BHT-BASIC is as close as possible to that used in Microsoft BASIC
(MS-BASIC).
■
No Line Numbers Required
BHT-BASIC requires no line number notation. You can write a branch statement with a label
instead of a line number so that it is possible to use cut and paste functions with an editor in
developing source programs, thus facilitating the use of program modules for development of
other programs.
■
Program Development in Windows95/98 or WindowsNT/Windows2000
You may develop programs with BHT-BASIC on those computers operating on Windows95/98
or WindowsNT4.0/Windows2000.
■
Advantages of the Dedicated Compiler
The dedicated compiler outputs debugging information including cross reference lists of variables and labels, enabling the efficient debugging in program development.
The Compiler ass ign s va riab le s to fixed addresses so that it is not necessary f or the Interpreter
to allocate or release memories when executing user programs, making the execution time
shorter.
■
Program Compression by the Dedicated Compiler
The Compiler compresses a source program into the intermediate language to produce an
object program (a user program).
(When a compiled user program is downloaded to the BHT, the BHT packs a pair of ASCII
bytes into a single byte by converting each byte into a 4-bit hexadecimal number for more efficient use of the memory area in the BHT.)
5
Page 14
1.2.2What’s New in BHT-BASIC 3.5 Upgraded from
BHT-BASIC 3.0?
Based on BHT-BASIC 3.0, BHT-BASIC 3.5 newly supports the following functions:
[ 1 ] Compiler
■ Object linkage editor, Linker
While BHT-BASIC 3.0 Compiler compiles a single source program into a single user program,
BHT-BASIC 3.5 Compiler can convert more than one source program into individual object
programs (intermediate code files for a user program) and then combine them together
through Linker to build a user program. With Linker, you may use existing object programs for
development of user programs.
■
Libraries
The Librarian allows you to build libraries out of object files resulting from compiling, which
makes it easier to use existing application programs. This facilitates the use of existing application programs for development of other programs.
■
Projects
BHT-BASIC 3.5 h as adde d a conce pt of Proj ect that ma kes it eas ier to u se multip le sou rce programs for producing a user program.
[ 2 ] Statements
■ A dded statements
Based on BHT-BASIC 3.0, BHT-BASIC 3.5 newly supports several statements for making distinction between global variables and local variables, and for defining functions and constants.
Newly added statements
CALLCalls a SUB function in addition to an FN3 function.
CONSTDefines symbolic constants to be replaced with labels.
DECLAREDeclares user-defined function FUNCTION or SUB exter-
nally defined.
FUNCTION…END FUNCTIONNames and defines user-defined function FUNCTION.
GLOBALDeclares one or more work variables or register variables
defined in a file, as global variables.
PRIVATEDeclares one or more work variables or register variables
defined in a file, as local variables.
SUB...END SUBNames and defines user-defined function SUB.
BHT-BASIC 3.5 provides the constants definition file "BHTDEF.INC." Reading the "BHTDEF.INC" as an included file allows you to use constant names defined in that file.
Example
’$INCLUDE:’BHTDEF.INC’
OUT .pnLEDCtrl, .pvLEDGrn'Turn LED (green) ON
6
Page 15
Chapter 1. Software Overview for the BHT
■ Defining and declaring user-defined functions more easily
BHT-BASIC 3.5 has added FUNCTION…ENDFUNCTION, SUB...ENDSUB, and DECLARE
statements. With the former two, you may easily define your own functions—FUNCTION and
SUB. With the latter one, you may declare FUNCTION and SUB functions wh ich ar e define d
in any other source files.
■ Scoping variables to be local or global
(with
PRIVATE or GLOBAL statement)
In BHT-BASIC 3.5, work variables and register variables may have "scope" to restrict the
access to them.
With the
be accessed by any routine in a file where it is defined. With the
declare a variable to be gl oba l. A global variable can be access ed b y an y ro uti ne in a program.
However, a variable used inside the
able only within a function where it is defined.
Since local variables are restricted in access, you can define them with a same name in different files.
For details about the scope of variables, refer to Chapter 5, Section 5.5.
PRIVATE statement, you may de clare a variabl e to be loca l. A local variabl e can on ly
GLOBAL statement, you may
FUNCTION or SUB function without declaration is avail-
■
Defining constants
BHT-BASIC 3.5 can define constants.
7
Page 16
1.3Program Development and Execution
BHT-BASIC consists of Compiler and Interpreter.
1.3.1Compiler
BHT-BASIC 3.5 Compiler consists of the following Compiler, Linker and Librarian:
Compiler
■
Compiler, which is one of the development tools, compiles source programs written on a PC
into the resulting "object files."
It checks syntax of source programs during compilation and makes an error file if any syntax
error is found.
■ L inker
Linker, which is one of the development tools, combines object files (translated by Compiler)
together to build a "user program" in the intermediate language.
If linking does not end normally, Linker makes an error file.
■
Librarian
Librarian, which is one of the development tools, builds "library files" out of object files translated by Compiler.
If Librarian does not end normally, it makes an error file.
1.3.2Interpreter
Interpreter interpret s and execut es a use r pro gram d ownload ed to t he BHT, statement by statement.
8
Page 17
Chapter 2
Development Environment and Procedures
CONTENTS
2.1Overview of Development Environment ........................................................ 11
Chapter 2. Development Envi ronment and Procedures
2.1Overview of Development Envir onment
The following hardware and software are required for developing user programs:
2.1.1Required Hardware
■ Personal computer
Use a computer operating with Windows95/98 or WindowsNT4.0/Windows2000.
BHT (Bar code handy terminal)
■
Any of the following BHTs is required:
• BHT-100Q
• BHT-100B
■
CU (Optical communications unit)
For IrDA communication, the following CU is required. Note that no CU is required if the BHT
is directly connected with the host computer via the direct-connect interface.
• CU-7000(Option. Required if the host computer has no IR interface port.)
RS-232C interface cable
■
This cable connects the CU with the personal computer.
NOTE
The RS-232C interface cable should have the connector and pin assignment required
by the perso nal computer.
(For information about the connector configuration and pin assignments of the CU,
refer to the BHT User’s Manual.)
• I r-Transfer Utility C (option) IT3C.EXE(MS-DOS–based)
IT3CW32.EXE(Windows-based)
• Ir-Transfer Utility E (option) IT3EW32.EXE(Windows-based)
Transfer Utility, Ir-Transfer Utility C, or Ir-Transfer Utility E is an essential tool for downloading
user programs to the BHT.
Each of the BHT-BASIC Compiler, Transfer Utility, Ir-Transfer Utility C, Ir-Transfer Utility E is
optionally provided in a CD or floppy disk.
NOTE
Prepare editor versions which are operable with the personal computer on which user
programs are to be developed.
For the manufacturers and models of computers to which Transfer Utility, Ir-Transfer
Utility C, or Ir-Transfer Utility E is applicable, refer to the “Transfer Utility Guide,”“Ir-Transfer Utility C Guide,” or “Ir-Transfer Utility E Guide,” respectively.
12
Page 21
Chapter 2. Development Envi ronment and Procedures
2.2Overview of Developing Procedures
2.2.1Developing Procedures
The program developing procedur es us ing BHT-BASIC 3.5 are outlined below.
• Making source programs
Make source programs with an editor according to the syntax of BHT-BASIC.
• Producing a user program (compiling and linking)
Compile the source programs into object programs by BHT-BASIC Compiler. Then
combine those object programs or libraries (made up by Librarian) together through
Linker to produce a user program in the intermediate language format.
• Downloading the user program
Download the user program to the BHT by u sin g Transfer Utility/Ir-Transfer Utility C/
Ir-Transfer Utility E.
• Executing the user program
Execute the user program on the BHT.
13
Page 22
2.2.2Functions of BHT-BASIC 3.5
BHT-BASIC 3.5 contains Compiler, Linker, and Librarian whose functions are listed below.
Functions of CompilerDescription
Syntax checkDetects syntax errors in source programs.
Output of object filesTranslates source programs into object files and
outputs them.
Output of debug informationOutputs list files and debug information files
required for debugging.
Functions of LinkerDescription
Output of a link map fileOutputs a symbol table along with its memory
address.
Output of a user programIntegrates more than one object program or
library to produce a user program in the intermediate language format. Whe n downlo aded to the
BHT by Transfer Utility/Ir-Transfer Utility C/IrTransfer Utility E, the user program will be compressed into programs that the Interpreter can
translate.
Functions of LibrarianDescription
Output of a libraryBuilds a library out of multiple object files. The
library is a collection of object files that Linker
will use.
14
Page 23
Chapter 2. Development Envi ronment and Procedures
2.3Writing a Source Program
2.3.1Writing a Source Program by an Editor
To write a source program, use an editor designed for operating environments where the BHTBASIC 3.5 Compiler will execute. The default editor is Windows Notepad.
TIP
To write a source program efficiently, use of a commercially available editor is recommended. For the operation of such an editor, refer to the instruction manual for
the editor.
2.3.2Rules for Writing a Source Program
When writing a source program accordin g to the sy nt a x of BHT-BASIC 3.5, observe the following rules:
• A label name should begin in the 1st column.
ABC
2000
• A statement should begin in the 2nd or the following columns.
PRINT
FOR I=1 TO 100 : NEXT I
• One program line should be basically limited to 512 characters (excluding a CR code)
and should be ended with a CR code (by pressing the carriage return key).
If you use an underline (_) preceding a CR code, however, one program line can be
extended up to 8192 characters. For statements other than the PRINT, PRINT#, and
PRINT USING statem ent s, you may use a lso a comm a (,) pre cedin g a CR code , inste ad
of an underline.
15
Page 24
• Comme nt lines s ta rtin g with a singl e quotation mark (') and those w ith a
the following description rule s eac h.
A single quotation mark (') can be put starting from the 1st or the following columns, or
immediately following any other statement.
A
REM should be put starting from the 2nd column or the following columns. To put a
REM should have
REM following any other statement, a colon (:) should precede the REM.
’Comment
CLS’Comment
REMComment
CLS:REMComment
• It is necessary to end the
ment will be treated as a block-stru ctu red statement.
IF statement with an END IF or ENDIF, since the IF state-
IF a$ = “Y” OR a$ = “y” THEN
GOTO SUB12
END IF
• The default number of characters for a non-array string variable is 40; that for an array
string variable is 20.
Specifying the
through 255 characters.
DIM or DEFREG statement allows a single string variable to treat 1
DIM b$[255]
DIM c$(2,3)[255]
DEFREG d$[255]
DEFREG e$(2,3)[255]
NOTE
BHT-BASIC does not support some of the statements and functions used in
Microsoft BASIC or QuickBASIC. For details, refer to Appendix K, “Unsupported
Statements and Functions.”
16
Page 25
Chapter 2. Development Envi ronment and Procedures
2.4Producing a User Program
2.4.1Sta rting the BHT-BASIC 3.5 Compiler
Start the Compiler, e.g., by choosing the "BHTC35W.EXE" from the Windows Explorer or the
"BHT-BASIC 3.5" registered to the Start menu.
Menu bar
Tool bar
Main window
The BHT-BASIC 3.5 Compiler supports the following menus and icons which provide quick
ways to do tasks:
MenusCommandsIconsFunctions
FileNew
Open
Close
Open Project
Close Project
Exit
ViewToolbar
Status Bar
Clear Screen
ProjectSelect File
Add File
BuildCompile
Build
ToolsOptions
Run Editor
Set Editor
(Yellow)
(Red)
Creates a new project.
Opens an existing file.
Closes the active file.
Opens an existing project.
Closes the active project.
Quits the BHT-BASIC 3.5 Compiler.
Shows or hi des the toolbar.
Shows or hides the status bar.
Clears the screen.
Selects or deletes a file in the active project.
Adds one or more files to the active project.
Compiles one or more active files (or active
project) to produce an object file(s).
Compiles one or more active files (or active
project) and then links them to produce a user
program.
Sets compiling options and linking options.
Runs the editor.
Selects the editor you want to run.
HelpAbout BHT-BASIC 3.5Displays the program information, version
number and the copyright.
17
Page 26
2.4.2Outline of User Program or Library Production
Procedure
Unlike the BHT-BASIC 3.0 Compiler that co nv ert s a sin gle s our ce pro gra m int o a u se r p rogra m
(file named XXX.PD3), the BHT-BASIC 3.5 Compiler conver ts so urce pr ograms in to obje ct programs (files named XXX. OBJ) a nd then link s those o bject program s to produc e a user p rogra m
(XXX.PD3). A sequence of the compiling and linking processes is called "Build."
The BHT-BASIC 3.5 Compiler can also build a library (XXX.LIB). You may select whether you
build a user program or library on the Project Configuration Files dialog box.
You may build a user program or library out of either multiple files or a single file (as in the
BHT-BASIC 3.0 Compiler).
Note that to build a library out of a single source file, you need to create a project file for a single source file.
[ 1 ] Building a user program out of a single source program file
What follows is a ge neral procedure for buildin g a user program out of a si ngl e so urce program
file.
(1) Designate a file that you want to use. (For details, refer to Subsection 2.4.3.1, "Designat-
ing a single source file.")
(2) Build a user program out of the designated file. (For details, refer to Subsection 2.4.4,
[ 3 ], "Building.")
[ 2 ]Building a library out of a single sourc e file, or buil ding a user pro gram or
library out o f multiple source files
What follows is a general procedure for building a library out of a single source file or for building a user p rogram or library out of multiple source files.
(1) Desi gnate a pro ject th at you wan t to use. (Fo r deta ils, ref er to Subsect ion 2.4. 3.2, "Desig-
nating a project file.")
(2) Build a use r program or lib rary out of t he des ignate d proje ct. (For deta ils, re fer to Su bsec-
tion 2.4.4, [ 3 ], "Building.")
18
Page 27
Chapter 2. Development Envi ronment and Procedures
2.4.3Designating a Single Source File or a Project File
2.4.3.1 Designating a single source file
Just as in the conventional BHT-BASIC 3.0 Compiler, yo u may designa te a single source file to
build a user program or library.
[ 1 ] Select a source file
(1) In any of the following methods, display the Open File dialog box shown below:
■ From the File menu, choose the Open command.
■ Click the open file button in the toolbar.
■ While holding down the Ctrl key, press the O key.
(2) Select a source file you want to use and then click the Open button.
Then the source file opens.
(3) Proceed to Section 2.4.4, "Compiling and Building."
19
Page 28
2.4.3.2 Designating a project file
To build a library out of a single source file or to build a user program or library out of multiple
source files, you need to create a project file (described in [ 1 ] later) or select an existing
project file (in [ 2 ]).
You may add files or delete existing files to/from the designated project file (described in [ 3 ]
and [ 4 ], respectively).
[ 1 ] Create a new project
(1) In any of the following methods, display the Create File dialog box shown below:
■ From the File menu, choose the New command.
■ Click the new file button in the toolbar.
■ While holding down the Ctrl key, press the N key.
(2) Designate a project file you want to create (Projtest.bhp in this example), and then click
the Save button.
If you create a project file having the same name as one already used, the warning mes-
sage dialog box will appear. If you want to overwrite, click the OK button; if you do not,
click the Cancel button to quit the project creating procedure.
(3) The Add File(s) dialog box appears. Into the newly created project, you need to put files
which should co nfi gure the pro je ct, ac cording to the instructions giv en in [ 3 ], "Add files to
a project file."
20
Page 29
Chapter 2. Development Envi ronment and Procedures
[ 2 ] Select an existing project file
You may select an existing project file in the Select Project File dialog box or in the Open File
dialog box.
Selecting in the Select Project File dialog box
(1) In any of the following methods, display the Select Project File dialog box shown below:
■ From the File menu, choose the Open Project command.
■ Click the open project button (yellow) in the toolbar.
■ While holding down the Ctrl key, press the P key.
(2) Select an existing project file you want to use (Projtest.bhp in this example), and then
click the Open button.
(3) Proceed to Section 2.4.4, "Compiling and Building."
Selecting in the Open File dialog box
(1) Display the Open File dialog box, referring to Subsection 2.4.3.1, [ 1 ].
(2) Select an existing project file you want to use (Projtest.bhp in this example), and then
click the Open button.
(3) Proceed to Section 2.4.4, "Compiling and Building."
21
Page 30
[ 3 ] Add files to a project file
You may add one or more source files and libraries to a project file at a time.
(1) Create a new project (Refer to [ 1 ] in this subsection) or select an existing project file to
which you want to add files (Refer to [ 2 ] in this subsection).
(2) In either of the following methods, display the Add File(s) dialog box shown below:
■ From the Project menu, choose the Add File command.
■ Click the add file button in the toolbar.
(3) Select files you want to add to the active project file and then click the Open button.
(4) The Project Configuration Files dialog box will appear which lists files in the project. For
details about the Project Configuration Files dialog box, refer to [ 4 ], "Select files in the
active project" given later.
22
Page 31
Chapter 2. Development Envi ronment and Procedures
[ 4 ] Select files in the active project
From files existing in the active project, you may select files that you want to compile or build.
(1) In either of the following methods, display the Project Configuration Files dialog box
shown below:
■ From the Project menu, choose the Select File command.
■ Click the select file button (red) in the toolbar.
TIP
The Project Configuration Files dialog box will appear also following the new
project creation process (see [ 1 ] earlier) or the file addition process to an existing project (see [ 3 ] earlier).
(2) Select files you want to compile or build.
Project configuration
files display area
Drive buttons
Main object display area
Selection buttons for user
program or library to be created
(3) In the Project Configuration Files dialog box are the following display areas and buttons
from which you may also select a user program or library to be built, may start compiling
or buildin g, and may run the ed itor, as well as a dding or deleting f iles to/ from the a ctive
project.
• List of Files in a Project
This display area s hows a list of fi le s which confi gures th e acti ve proj ect. Th e filen ames
are displayed as a relative path.
23
Page 32
• Main Object display area
This area shows the name of a main object in a user program if you have selected
"User program (PD3)" with the "Type of File to be Created" selection button. If you
have selected "Create library (LIB)," nothing will appear on this area.
• Type of File to be Created
Lets you select whether you create a user program (PD3) or library (LIB).
• Add File button
Adds the currently selected files to the active project. (Refer to “[ 3 ] Add files to a
project file.”)
• Delete File button
Deletes the currently selected file(s) from the active project.
• Main Object button
Speci fies the curr ently s electe d file as a main ob ject if y ou have selec ted "Use r progra m
(PD3)" with the “Type of File to be Created” selection button. A library cannot be specified as a main object.
This button will be disabled if more than one file is selected or “Create library (LIB)” is
selected with the “Type of File to be Created” selection button.
• Run Editor button
Opens a file currently selected by the editor.
• Compile button
Compiles currently selected source files into object files.
• Build button
Builds a user program out of the active project.
24
Page 33
Chapter 2. Development Envi ronment and Procedures
2.4.4Compiling and Building
First specify the options and then proceed to the compiling or building process.
[ 1 ] Specifying the compiling and linking options
(1) In either of the following methods, display the Set Options dialog box shown below:
■ From the Tools menu, choose the Options command.
■ Click the option button in the toolbar.
(2) Select the check boxes of the options you want to specify.
For details about the options, refer to Subsection 2.4.7.
25
Page 34
[ 2 ]Compi ling
In any of the following methods, compile the currently selected source file(s) into an object
file(s):
■ From the Build menu, choose the Compile command.
■ In the Project Configuration Files dialog box, click the Compile button. (For details
about the Project Configuration Files dialog box, refer to Subsection 2.4.3.2, [ 4 ].)
■ Click the compile start button in the toolbar.
■ While holding down the Ctrl key, press the G key.
If compiling ends normally, the screen shown below will appear.
[ 3 ] Building
In any of the following methods, build a user program or library out of object files:
■ From the Build menu, choose the Build command.
■ In the Project Configuration Files dialog box, click the Build button. (For details about
the Project Configuration Files dialog box, refer to Subsection 2.4.3.2, [ 4 ].)
■ Click the build start button in the toolbar.
■ While holding down the Ctrl key, press the B key.
If building ends normally, the screen shown below will appear.
26
Page 35
Chapter 2. Development Envi ronment and Procedures
2.4.5Setting the Editor for Displaying Files
Set the editor that you want to use for displaying source files and error message files
(XXX.ERR) according to the steps below.
(1) From the Tools menu, choose the Set Editor command.
The Set Editor dialog box appears as shown below.
(2) In th e C om mand line edit box, type th e fi le nam e of the editor . If the ed ito r is n ot loc at ed in
the current directory or working directory, type the absolute path or relative path. (The
default editor is Windows NotePad .)
If you don’t know the editor’s filename or directory path, choose the Browse button in the
Set Editor dialog box to d isp la y the Sele ct Ed itor dialog box. From a list of files an d dire ctories displayed, select the appropriate filename and then choose the OK button.
TIP
Setting the editor having the tag-jump fun ction allows you to efficiently correct a source program file which has caused an error. For details about the
tag-jump function, refer to the user’s manual of the editor.
27
Page 36
2.4.6Error Messages and Their Indication onto the
Main Window
[ 1 ]Selecting either an editor or main window as an error message output
device
According to the procedure below, you may select whether error messages should be outputted to an editor or main window if an error message file (XXX.ERR) is produced.
(1) From the Tools menu, choose the Options command.
The Set Options dialog box appears as shown below.
(2) In the Set Options dialog box, select either "To the Editor" or "To the Window" check box.
(The default output device is Edit or.)
28
Page 37
Chapter 2. Development Envi ronment and Procedures
[ 2 ]How error m essages are displayed on the editor or main window
During building, the BHT-BASIC 3.5 Compiler may detect errors which can be divided into two
types: syntax errors and fatal errors.
■ Syntax errors
If the Compiler detects a syntax error, it outputs the error message to the XXX.ERR file. For
details about the file, refer to Subsection 2.4.9, "Output from the BHT-BASIC 3.5 Compiler."
If the "To the Editor" check box of the Error Message Output is selected in the Set Options dialog box, the editor w ill a utomat icall y open and sh ow the de tected errors. If th e "To the Window"
check box is selected, those errors will be outputted to the main window.
The total number of detected syntax errors always displays on the main window.
- Error messages displayed on the editor
- Error messages displayed on the main window
■ Fatal errors
If the Compiler detects a fatal error, it outputs the error message to the main window.
■ ERRORLEVEL
The ERRORLEVEL function is supported only when a +E option is specified at the command
line. (Refer to Subsection 2.4.8, "Starting the BHT-BASIC 3.5 Compiler from the Command
Line," [ 3 ].)
29
Page 38
2.4.7Options
To specify compiling options and linking options, select the check-box options you want in the
Set Options dialog box. Each of available options is explained below.
[ 1 ]Compi ling options
Compiling OptionsDescription
ebug information fileOutputs debug information files (XXX.ADR, XXX.LBL, and
D
XXX.SYM files).
If this option is not selected, no debug information file will be
outputted. (default)
(For details, refer to [ 3 ].)
Address-source L
ymbol tableOutputs a symbol table to the file XXX.LST.
S
X (Cross) referenceOutputs a cross reference to the file XXX.LST.
ariable sizeOutputs the sizes of common variables, work variables, and
V
istOutputs an address-source list to the file XXX.LST.
If this option is not selected, no address-source list will be
outputted. (default)
(For details, refer to [ 4 ].)
If this option is not selected, no symbol table will be outputted. (default)
(For details, refer to [ 4 ].)
If this option is not selected, no cross reference will be outputted. (default)
(For details, refer to [ 4 ].)
register variables to the file XXX.ERR. or main window.
If this option is not selected, no variable size will be output-
ted. (default)
The output example (TESTA.err) is as follows:
Common area= XXXXX bytes (XXXXX bytes on memory.
XXXXX bytes in file)
Work area= XXXXX bytes (XXXXX bytes on memory.
XXXXX bytes in file)
Register area = XXXXX bytes in file
30
Page 39
Chapter 2. Development Envi ronment and Procedures
[ 2 ] Linking options
Linking OptionsDescription
apfileOutputs map information to the file XXX.MAP.
M
If this option is not selected, no map information will be
outputted. (default)
(For details, refer to [ 5 ] in this subsection.)
[ 3 ] Outputting debug information files
If you select the "Debug information file" check box in the Set Options dialog box and run the
Compiler, then the Compiler will output three types of debug information files.
Each information file will be given the same name as the source program and annexed one of
the three extensions .ADR, .LBL, and .SYM according to the file type as listed below.
Debug Information FilesFilename Extension
Source line–address file
Label-address file
Variable–intermediate language file
• Source line–address file (.ADR)
Indicates the correspondence of line numbers in a source program to their
addresses in the object program written in intermediate language.
Each line consists of a four-digit line number in decimal notation and a four-digit
address in hexadecimal notation.
• Label–address file (.LBL)
Indicates the correspondence of labels and user-defined functions defined in a
source program to their addresses in the object program written in intermediate language.
For user-defined functions in the one-line format, the first addresses of those functions in the object program are listed in this file; for those in the block format, the
addresses of the first statements in the blocks are listed.
Each line consists of a label name or a user-defined function name, and a four-digit
address in hexadecimal notation.
• Variable–intermediate language fi le (.SYM)
Indicates the correspondence of variables used in a source program to the intermediate language.
Each line consists of a variable name and its intermediate language.
.ADR
.LBL
.SYM
31
Page 40
[ 4 ] Outputting list files
The Compiler may output three types of list files as listed below depending upon the options
specified at the start of compiling, in order to help you program and debug efficiently.
List FileOptionFilename Extension
Address-source list
Symbol table
Cross reference
Select the Address-source List check box .
Select the Symbol table check box.
Select the X (Cross) reference check box.
.LST
The list file will be g iven th e sam e name as the sour ce pro gram fil e and a nnexe d with an ext ension .LST.
When outputted, each list file has the header format as shown below.
BHT-BASIC 3.5 Compiler Version X.XX
←Version of BHT35CPL.DLL
Copyright (C) DENSO CORPORATION 1998. All rights reserved.
source = Source filename.ext (to be given as an absolute path)
■ Address-source list
Select the Address-source List check box and run the Compiler, and the following information
will be outputted:
BHT-BASIC 3.5 Compiler Version X.XX←Version of BHT35CPL.DLL
Copyright (C) DENSO CORPORATION 1998. All rights reserved.
source = C:\TEST.SRC
Address of object program in
intermediate language
Line number in source
program
Source program statement
32
Page 41
Chapter 2. Development Envi ronment and Procedures
• Address of object program in intermediate language
Shows an intermediate language address corresponding to a source program line in
four-digit hexadecima l not a tion .
• Line number in source program
Shows a line number for a source program statement in four-digit decimal notation.
• Source program statement
Shows the same content as a statement written in a source program.
Notes for address-source lists
(1) If a source program statement contains line feeding caused by a CR code preceded by an
underline (_) or a comma (,), the line number will increase, but no address will appear.
(2) Neither page headers nor new page codes will be inserted.
(3) If a syntax error occurs, the error message will be outp utt ed on the lin e foll ow in g the error
statement line.
(4) If more than one syntax error occurs in a statement, the error message only for the first
detected er ror will appear.
(5) A TAB code will be replaced with eight space codes.
The total number of syntax errors will be outputted at the end of the list.
■
Symbol table
Select the Symbol table check box and run the Compiler, and the following information will be
outputted:
BHT-BASIC 3.5 Compiler Version X.XX←Version of BHT35CPL.DLL
Copyright (C) DENSO CORPORATION 1998. All rights reserved.
source = C:\Test.SRC
Variables will be outputted in the following format:
In case of global variablesVariablename
In case of local variablesVariablename:Filename (no extension)
In other casesVariablename:Name of user-defined function defining the
variable
33
Page 42
• Symbol table for common variables
Lists common variables arranged according to their types. An array variable has a suffix
of parentheses ( ).
• Symbol table for work variables
Lists work variables and dummy arguments arranged according to their types. An array
variable has a suffix of parentheses ( ).
• Symbol table for register variables
Lists register variables arranged according to their types. An array variable has a suffix
of parentheses ( ).
• Symbol table for labels
Lists labels arranged in alphabetic order.
• Symbol table for user-defined functions
Lists user-defined functions arranged according to their types (i.e. integer, real, and
string types).
Each of common variables, work variables, and register variables can be divided into the following types:
Non-array integer typeNon-array real typeNon-array string type
Array integer typeArray real typeArray string type
■
Cross reference
Select the X (Cross) reference check box and run the Compiler, and the following information
will be outputted:
• For common variables
Outputs line numbers where common variables are defined and referred to.
• For work variables
Outputs line numbers where work variables and dummy arguments are referred to.
• For register variables
Outputs line numbers where register variables are defined and referred to.
• For labels
Outputs line numbers where labels are defined and referred to.
• For user-defined functions
Outputs line numbers where user-defined functions are defined and referred to.
34
Page 43
Chapter 2. Development Envi ronment and Procedures
[ 5 ] Outputting a mapfile
Select the Mapfile check box of the Linking Options in the Set Options dialog box and build a
user program, and the mapfile as shown below will be outputted. The mapfile will be given the
same name as the project file and annexed with an extension .MAP.
COMMON SYMBOL
C%
WORK SYMBOL
A
B
W$
REGISTER SYMBOL
R$
FUNCTION SYMBOL
AAA
OBJECT INFORMATION
PRC
REG
PRD
PRD INFORMATION
[Filename]
test.obj
Function.obj
[Total]
2400
2900
2901
2A00
2E00
003B
offset size
0000
0035
0064
offset size
0000
0038
0035
002F
0047
0038
000F
0047
Map for common variables
Map for work variables
Map for register variables
Map for user-defined function
Map for variables and object
codes
Details of object codes
• Map for common variables
Shows the symbols of common va riables in the Interpreter which are arranged acc ordi ng
to their types together with their pointing addresses. An array variable has a suffix of
parentheses ( ). If no common variables are used, this item will not be outputted.
• Map for work variables
Shows the symbols of work variables in the Interpreter which are arranged according to
their types together wi th thei r pointi ng addr esses . An array variabl e has a suf fi x of pa rentheses ( ). If no work variables are used, this item will not be outputted.
• Map for register variables
Shows the symbols of register variables in the Interpreter which are arranged according
to their types together with their pointing addresses. An array variable has a suffix of
parentheses ( ). If no register variables are used, this item will not be outputted.
35
Page 44
• Map for user-defined functions
Shows the symbols of user-defined functions in the Interpreter which are arranged
according to their types (i.e., integer, real, and string types). If no user-defined functions
are used, this item will not be outputted.
• Map for variables and object codes
Shows the addresses of variables and object codes in a user program. The PRC indicates the pr ogram alloc ation inform ation area, th e REG indicat es the regist er variables
area, and the PRD indicates the program reserved area.
• Details of object codes
Shows the allocation information of objects in a user program. The [Filename] lists the
names of object files configuring a user program. The [Offset] lists the heading
addresses of individual object files in 4-digit hexadecimal form. The [Size] lists the sizes
of individual object files in 4-digit hexadecimal form.
[ 6 ] Calculating the address for a statement causing a run-time error
If a run-time error occurs, the Compiler returns the address (ERL=XXXX) assigned starting
from the head of the user program. When building a user program out of multiple object files,
therefore, you need to calculate an address of a statement in an object file causing a run-time
error according to the procedure given below.
(1) In the Set Options dialog box, select the Address-source List check box of the Compiling
Options and the Mapfile check box of the Linking Options beforehand.
(2) Build a user program out of object files so as to output the address-source list file (source
filename.LST) and the mapfile (project name.MAP).
(3) In the "details of object codes" item, retrieve an object file containing the address
(ERL=XXXX) assigned to a statement causing a run-time error.
(4) In the Address-source List file of the retrieved object file, retrieve the address for the
statement causing a run-time error.
Subtract the heading address of the object file from the address of the statement causing
a run-time er ror, and you can obtain where a run-time error has occurred.
36
Page 45
Chapter 2. Development Envi ronment and Procedures
2.4.8Starting the BHT-BASIC Compiler from the
Command Line
You may start the BHT-BASIC Compiler from the command line in the MS-DOS Prompt of
Windows95/98 or WindowsNT 4.0/Windows2000.
[ 1 ] Syntax
At the MS-DOS command prompt, type in the following format:
filenameYou may specify the name of any of a project file, source file and
optionsYou may specify compiler processing options, compiling options, and
NOTE
TIP
The Compiler will recognize a project specified by filename merely as a group of
files. If you do not specify a +BL option (Building library described in [ 2 ]), therefore, the Compiler automatically produces a user program.
T o produce a us er program from a s ingle source file in a batch file, type in the following:
>START /W BHTC35W +E +B TEST.SRC
Writing START /W as above will not proceed to the next batch processing until the
BHT-BASIC 3.5 Compiler completes the processing. For details about +E or +B
option, refer to “[ 2 ] Options” in this subsection.
You may sp ecify either an absol ute path or relative path. Omitting
this option will mak e t he Compiler look for that file in the current working directory. Specifications of directorypath only is not allowed.
library file.
linking option. For details, refer to the next item, [ 2 ], "Options."
37
Page 46
[ 2 ] Options
The BHT-BASIC 3.5 Compiler supports three types of options—compiler processing options,
compiling options, and linking option.
■ Compiler processing options
Processing optionsDescription
+C
+B programname
+BL libraryname
+E, -E
NOTE
If more than one option with different specifications is written (e.g., +C, +B, and
+BL), the last option takes effect.
If the same option is set more than one time with different specifications (e.g., +E and
-E), the last option takes effect.
Compiles one or more designated file(s) into object file(s).
Builds a user program with th e sp ec ifi ed p r ogra m n ame. If
no
programname is specified, the filename specified
first will apply.
Builds a library with the specified library name. If no
libraryname is specified, the filename specified first
will apply.
Determines whether to terminate the BHT-BASIC 3.5
Compiler after completion of processing.
Specifying the +E terminates the Compiler without displa y-
ing the compiler window after completion of processing.
Specifying the
not termin ate the Compiler even aft er completion of pro cessing.
The default is
-E displays the compiler window and does
-E.
38
Page 47
Chapter 2. Development Envi ronment and Procedures
■ Compiling options
Compiling optionsDescription
+D
+L
+S
+X
+V
■ Linking option
Linking optionsDescription
Outputs debug information files (XXX.ADR, XXX.LBL. and
XXX.SYM files).
(Same as you select the Debug information file check box in
the Set Options dialog box. Refer to Subsection 2.4.7, [ 1 ].)
Outputs an address-source list to the file XXX.LST.
(Same as you select the Address-source List check box in
the Set Options dialog box. Refer to Subsection 2.4.7, [ 1 ].)
Outputs a symbol table to the file XXX.LST.
(Same as you select the Symbol table check box in the Set
Options dialog box. Refer to Subsection 2.4.7, [ 1 ].)
Outputs a cross reference to the file XXX.LST.
(Same as you select the X (Cross) reference check box in
the Set Options dialog box. Refer to Subsection 2.4.7, [ 1 ].)
Outputs the sizes of common variables, work variables, and
register variables to the file XXX.ERR or main window.
(Same as you select the Variable size check box in the Set
Options dialog box. Refer to Subsection 2.4.7, [ 1 ].)
+M
NOTE
Outputs map information to the file XXX.MAP.
(Same as you select the Mapfile check box in the Set
Options dialog box. Refer to Subsection 2.4.7, [ 2 ].)
Options specified at the command line will take effect only when you run the BHTBASIC 3.5 Compiler at the command line. (Those option settings will not be written
into the initialization file BHTC35W.INI.)
Even if you specify a -E option (default) so that the Compiler does not terminate after
completion of processing, neither filename nor options designated for the preceding
processing will be saved. You need to designate them again.
Option settings stored in the initialization file B HTC35W.INI will not apply when
you run the BHT-BASIC 3.5 Compiler at the command line. To output debug information files, therefore, you need to specify options at the command line.
39
Page 48
[ 3 ] Error Level Indication by ERRORLEVEL
If you specif y a +E option at the command line and run the BHT-BASIC 3.5 Compiler, the
ERRORLEVEL of MS-DOS allows the Compiler to set the compi ling en d statu s to the M S-DOS
environmental variable ERRORLEVEL after completion of processing, as any of the error levels listed below.
By referring to this ERRORLEVEL, you can learn the compiling end status.
ERRORLEVELDescription
0
1
2
4
5
6
7
8
9
10
20
21
30
40
70
99
By making a batch file which automatically starts proper operation according to the error level,
you can facilitate debugging procedures.
For details about the ERRORLEVEL, refer to the MS-DOS Reference Manual.
Normal end
No designated file or path found.
Filename format not correct
Project invalid
File open error
Write-protect error
File renaming failure
Project file creating failure
Existing project file deleted
Entered option invalid
Compiling syntax error
Compiling fatal error
Link error
Library error
No empty space in the designated disk
Other errors
40
Page 49
Chapter 2. Development Envi ronment and Procedures
2.4.9Output from the BHT-BASIC 3.5 Compiler
The BHT-BASIC 3.5 Compiler outputs the following information as well as object programs to
the destination depending upon the conditions.
OutputDestinationConditions
Object fileFile XXX.OBJ (in the direc-
tory where the source program is located)
User programFile YYY.PD3 (in the direc-
tory where the project is
located)
Library fileFile YYY.LIB (in the
directory where the project
is located)
Error message
(Syntax error)
Error message
(Fatal error)
File XXX.ERR (in the directory where the source program is located)
File YYY.ERR (in the directory where the project is
located)
Main windowIf a fatal error is detected
When the specified source
program has been normally
compiled without occurrence of a compiling error.
When the specified project
has been normally built without occurrence of a compiling error or linking error.
When the specified project
has been normally built without occurrence of a compiling error or library error.
If a compiling error is
detected during compilation
of the specified source program.
If an error is detected during
building of the specified
project.
during compilation of the
specified source program.
Debug
information
Source line–
Address
information
Label–
Address
information
Variable–
Intermediate
language
information
File XXX.ADR (in the directory where the source program is located)
File XXX.LBL (in the directory where the source program is located)
File XXX.SYM (in the directory where the source program is located)
41
If the Debug information file
check box is selec ted in the
Set Options dialog box.
Page 50
OutputDestinationConditions
Address–Source list
Symbol tableIf the Symbol table check
Cross referenceIf the X (Cross) reference
Sizes of variablesFile XXX.ERR (in the direc-
MapfileFile YYY.MAP (in the direc-
XXX represents a source program filename.
YYY represents a project name.
File XXX.LST (in the directory where the source program is located)
tory where the source program is located) or
File YYY.ERR (in the directory where the project is
located)
tory where the project is
located)
If the Address-source List
check box is selec ted in the
Set Options dialog box.
box is selected in the Set
Options dialog box.
check box is selec ted in the
Set Options dialog box.
If the Variable size check
box is selected in the Set
Options dialog box.
If the Mapfile check box is
selected in the Set Options
dialog box.
42
Page 51
Chapter 2. Development Envi ronment and Procedures
2.4.10 Structure of User Programs and Libraries
If you specify a user program to be produced in the Project Configuration Files dialog box, the
BHT-BASIC 3.5 Compiler produces a user program provided that no compiling error or link
error occurs. The user program file will be given the same name as the project file and
annexed with an extension .PD3.
If you specify a libr ary to be produced , the Compil er produc es a l ibrary p rovide d th at no co mpiling error or library error occurs. The library file will be given the same name as the project file
and annexed with an extension .LIB.
If the name of a newly produced file is the same as that of an existing file in the destination
directory, Compiler will overwrite the existing file with the new file.
Structure of user programs
A user program is expressed in the intermediate language, where statements, functions and
variables are in two-byte form of ASCII characters. A record is 128 bytes in length and
annexed with CR and LF codes.
When downloaded to the BHT and stored in its memory, a user program will be compressed
from two-byte form into single-byte hexadecimal form. Accordingly, the length of a record
comes to 64 bytes.
Struct ure of libra rie s
A library consists of more than one object filename and object information.
43
Page 52
2.5Downloading
2.5.1Overview of Transfer Utilit y/Ir-Transfer Utility C/
Ir-Transfer Utility E
Transfer Utility/Ir-Transfer Utility C/Ir-Transfer Utility E transfers user programs and data files
(e.g., master files) between the BHT and the connected personal computer. It has the following functions:
Functions of T r ans fer U ti lit y/I r-Transfer Utility C/Ir-Transfer Utility E
Downloading extension programs
Downloading programs
Downloading data
Uploading programs
Uploading data
For operations of Transfer Utility/Ir-Transfer Utility C/Ir-Transfer Utility E, refer to the related
guide.
2.5.2Setting up the BHT
If the error message given below appears, it is necessary to set the calendar clock before
downloading user programs.
"Set the current date and time. XX/XX/XX YY:YY"
The above error message appears in any of the following cases:
• The BHT is first powered on from the time of purchase.
• The BHT is powered on after being left without main battery loaded for a long time.
For details about the calendar clock setting, refer to the BHT User’s Manual.
44
Page 53
Chapter 2. Development Envi ronment and Procedures
2.6Executing a User Program
2.6.1Starting
To run a user program, sta rt System Mode an d selec t the desi red progra m in the Prog ram Execution menu.
If you have selected a user program as an execution program in the Setting menu of System
Mode, the BHT automatically runs the user program when powered on.
For the operating procedure of System Mode, refer to the BHT User’s Manua l.
2.6.2Execution
The Interpreter interpret s and ex ecute s a use r program fro m the fi rst st atem ent to the next, o ne
by one.
2.6.3Termination
The BHT system program terminates a running user program if
• the
END, POWER OFF, or POWER 0 statement is executed in a user program,
• the power switch is pressed,
• no valid operations are performed within the specified time length (Automatic powering-
off),
Valid operations:- Entry by pressing any key
- Bar-code reading by pressing the trigger switch
- Data transmission
- Data reception
Specified time length:Length of time specified by the POWER statem ent in the
user program. If not specified in the prog ram, three minutes will apply.
or
• the battery voltage l evel becomes low.
Low battery:If the voltage level of the rechargeable battery cartridge
or that of the dry cells drops below the specified level,
the BHT displays the low battery warning message on
the LCD and powers itself off.
If the resume function is activated in System Mode, only the execution of the
OFF
, or POWER0 statement can terminate a running user program. Other cases above
merely turn off the power, so turning it on again resumes the program.
3.1.2 Notes for Jumping into/out of Statement Blocks ................................ 49
3.2Handling User Programs............................................................................... 50
3.2.1 User Programs in the Memory........................................................... 50
3.2.2 Program Chaining .............................................................................. 50
3.2.3 Included Files..................................................................................... 51
46
Page 55
Chapter 3. Program Structure
3.1Program Overview
3.1.1Statement Blocks
A statement block is a significant set of statements (which is also called "program routine").
The following types of statement blocks are available in programming for the BHT:
Statement BlocksDescription
Subroutine
Error-/event-handling routineAn error-/event-handling routine to which
User-defined functionA function defined by any of the following
A routine called by the
control is passed when an error trap or event
(of keystroke) trap occurs, respectively.
statements:
GOSUB statement.
DEF FN (in single-line form)
DEF FN...END DEF (in block form)
SUB...END SUB
FUNCTION
Block-structured statement
FOR...NEXT
IF
...THEN...ELSE...ENDIF
SELECT
WHILE
Avoid jumping into or out of the midst of any of the above statement blocks using the
statement; otherwise, it will result in an error. (Refer to Section 3.1.2.)
...ENDFUNCTION
...CASE...ENDSELECT
...WEND
GOTO
[ 1 ] Subroutines
A subroutine is a statement block called from the main routine or other subroutines by the
GOSUB statement.
Using the
immediately following the GOSUB statement in the original main routine or subroutine.
RETURN statement pass es con t rol f rom th e c al le d su bro ut i ne ba c k to t he sta tem e nt
[ 2 ] Error-/Event-handling Routines
An error- or event-handling routine is a statement block to which program control passes when
an error trap or event (of keystroke) trap occurs during program execution, respectively.
The
RESUME statement passes control from the error-handling routine back to the desired
statement.
The
RETURN statement in the keyboard interrupt event-handling routine returns control to the
statement following the one that caused the interrupt.
47
Page 56
[ 3 ] User-defined Functions
Before calling user-defined functions, it is necessary to define those functions with any of the
following statements. Generally, those statements should be placed before the main routine
starts.
DEF FN (in single-line form)
DEF FN...END DEF (in block form)
SUB...END SUB
FUNCTION...END FUNCTION
When usin g SUB and FUNCTION functions written in other files, it is necessary to declare
them with the
DECLARE statement before calling them.
[ 4 ] Block-structured Statements
The statements listed below have the statement block structure and are useful for structured
programming.
FOR...NEXT
IF...THEN...ELSE...END IF
SELECT...CASE...END SELECT
WHILE...WEND
■ Nested Structure
Block-structured statements allow you to write nesting programs as shown below.
FOR i=1 TO 10
FOR j=2 TO 10 STEP 2
PRINT i, j, k
NEXT j
NEXT i
Nesting subroutines as shown below is also possible.
GOSUB aaa
.
.
.
aaa
PRINT "aaa"
GOSUB bbb
RETURN
bbb
PRINT "bbb"
RETURN
48
Page 57
Chapter 3. Program Structure
3.1.2Notes for Jumping into/out of Statement Blocks
It is not recommended to jump control from a main routine or subroutines into the midst of significant statement blocks or to jump out from the midst of those statement blocks, using the
✕ :To be avoided. A run-time error may occur.
▲:Not recommended, although no run-time error will result directly. Nesting may
cause a run-time error.
• It is possible to jump control out of the midst of block-structured statements
(except for
FOR...NEXT) by using the GOTO statement.
NOTE
• A void j umpin g the cont rol out of the midst of
FOR...NEXT statement b loc k with the
GOTO statement. The program given below, for example, should be avoided.
FOR I%=0 TO 10
IF I%=5 THEN
GOTO AAA
ENDIF
NEXT I%
AAA
Generally, the frequent or improper use of GOTO statements in a program will
decrease debugging efficiency and might cause fatal run-time errors. You are, therefore, recommended to avoid using GOTO statements, if possible.
49
Page 58
3.2Handling User Programs
3.2.1User Programs in the Memory
The user area of the memory (memories) in the BHT can store more than one user program.
(For details about memories, refer to Appendix F, "Memory Area.")
If you have selected one of those programs as an execution program in the Setting menu of
System Mode, the BHT automatically runs the user program when powered on.
For the operating procedure of System Mode, refer to the BHT User’s Manua l.
3.2.2Program Chaining
Program chaining, which is caused by the CHAIN statement as shown below, terminates a
currently running user program and transfers control to another program.
CHAIN "another.PD3"
To transfer the variables and their values used in the currently running user program to the
chained-to program along the program chain, use the
COMMON a$(2),b,c%(3)
CHAIN "another.PD3"
The Interpreter writes these declared variable values into the "common variable area" in the
memory. To make the chained-to program refer to these values, use the COMMON statement
again.
COMMON a$(2),b,c%(3)
COMMON statement as follows:
In BHT-BASIC, all of the name, type, definition order, and number of COMMON-declared variables used in the currently running program should be identical with those in the next program
(the chained-to program).
When compiling and linkin g more tha n one file to pro duce a us er program , define all necessa ry
common variables in the main object (to be executed first). In other objects, declare common
variables required o nly in that obj ect. If y ou lin k an ob ject w here c ommo n varia bles n ot defin ed
in the main object are newly defined, an error will result.
’ prog1.PD3
COMMON a(10),b$(3),c%
.
.
.
CHAIN "prog2.PD3"
’ prog2.PD3
COMMON a(10),b$(3),c%
.
.
.
Since the COMMON statement is a declarative statement, no matter where it is placed in a
source program, the source program will result in the same output (same object program), if
compiled.
50
Page 59
Chapter 3. Program Structure
3.2.3Included Files
"Included files" are separate source programs which may be called by the INCLUDE metacommand.
Upon encounter with the
the designated included file and then compiles the main source program while integrating that
included file to generate a user program.
You should specify the name of an included file by using the
’$INCLUDE. In the included files, you can describe any of the statements and functions
except the
If a compilation error occurs in an included file, it will be merely indicated on the line where the
included file is cal led by the
detailed information of syntax errors detected in the included files nor the cross reference list
will be outputted. It is, therefore, necessary to debug the individual included files carefully
beforehand.
REM $INCLUDE and ’$INCLUDE.
INCLUDE metacommand in a source program, the Compiler fetches
REM $INCLUDE or
INCLUDE metacommand i n t he mai n sou rce prog ram, a nd neit her
51
Page 60
Chapter 4
Basic Program Elements
CONTENTS
4.1Structure of a Program Line........................................................................... 53
4.1.1 Format of a Program Line .................................................................. 53
A program line consists of the following elements:
[label] [statement] [:statement] ... [comment]
• label
A label is placed at the beginning of a program line to identify lines.
• statement
A statement is a combination of functions, variables, and operators according to the syntax.
A group of the statements is a program.
• comment
You may describe comments in order to make programs easy to understand.
[ 1 ] Labels
To transfer control to any other processing flow like program branching, you may use labels
which designate jump destinations. Labels can be omitted if unnecessary.
Labels differ from line numbers used in the general BASIC languages; that is, labels do not
determine the execution order of statements.
You should write a label beginning in the 1st column of a program line. To write a statement
following a label, it is necessary to place one or more separators (spaces or tabs) between the
label and the statement.
As shown below, using a label in the
which should usually precede a jump-destination label.
IF a = 1 THEN Check
ELSE 500
ENDIF
Where the words "Check" and "500" are used as labels.
For detailed information about labels, refer to Section 4.3.
IF statement block can eliminate the GOTO statement
53
Page 62
[ 2 ] Statements
Statements can come in two types: executable and declarative statements.
• Executable statements
They make the Interpreter pro cess prog ram s by ins truc tin g the opera tio n to be exec ut ed.
• Declarative statements
They manage the memory allocation for variables and handle comments. Declarative
statements available in BHT-BASIC are listed below.
REM or single quotation mark (’)
DATA
COMMON
DEFREG
Multi-statements:You can describe multiple statements in one program line by separating
them with a colon (:).
[ 3 ] Comments
A single quotation mark (’) or REM can begin a comment.
• Single quotation mark (')
A single quotation mark or apostrophe (’) can begin in the first column of a program line
to describe a comment.
When following any other statement, a comment starting with a single quotation mark
requires no preceding colon (:) as a delimit er.
’ comment
PRINT "abc" ’comment
• REM
The REM cannot begin in the first column of a program line.
When following any other statement, a comment starting with a
ing colon (:).
REM comment
PRINT "abc" :REM comment
54
REM requires a preced-
Page 63
Chapter 4. Basic Program Elements
4.1.2Program Line Length
A program line is terminated with a CR code by pressing the carriage return key.
The allowable line length is basically 512 characters excluding a CR code placed at the end of
the line.
In either of the following two description ways, however, you can write a program line of up to
8192 characters:
In the samples below, symbol "↓" denotes a CR code entered by th e carriage return key.
• Extend a program line with an underline (_) and a CR code.
IF (a$ = "," OR a$ = ".") AND b<c _↓
AND EOF(d) THEN ...
• Extend a program line with a comma (,) and a CR code.
FIELD #1,13 as p$,5 as k$,↓
10 as t$↓
Note that the latter description way above (using a comma and CR code) cannot be used for
the
PRINT, PRINT#, and PRINT USING statements. Only the former way should apply to
them.
55
Page 64
4.2Usable Characters
4.2.1Usable Characters
Listed below are characters which can be used for writing programs. Note that a double quote
(") cannot be used inside a character string. Symbols | and ~ inside a character string will
appear as ↓ and → on the LCD of the BHT, respectively.
If used outside of a character string, symbols and control codes below have special meaning
described in Subsection 4.2.2.
• Alphabet lettersIncluding both the uppercase and lowercase letters
(A to Z and a to z).
• Nume ralsIncluding 0 to 9 for de cim al not a tio n, an d 0 to 9 and
A to F (a to f) for hexadecimal notation.
Distinction between Uppercase and Lowercase Letters
■
The Compiler makes no distinction between the uppercase and lowercase letters, except for
those used in a character string data. All of the statements below, for example, produce the
same effect.
e.g.,
e.g.,
PRINT a
print a
PRINT A
print A
When used in a character string data, uppercase and lowercase letters will be distinguished
from each other. Each of the statements below, for example, produces different disp la y output.
PRINT "abc"
PRINT "ABC"
56
Page 65
Chapter 4. Basic Program Elements
4.2.2Special Symbols and Control Codes
Symbols and control codes used outside of a c ha rac ter s tring have the following spe ci al me aning:
Symbols and
control codes
$
(Dollar sign)
%
(Percent sign)
*
(Asterisk)
+
(Plus sign)
–
(Minus sign)
.
(Period)
/
(Slant)
<
(Less-than sign)
=
(Equal sign)
>
(Greater-than sign)
"
(Double quote)
&
(Ampersand)
'
(single quotation mark
or apostrophes)
( )
(Left and right paren-
theses)
Typical use
String suffix for variables or user-defined functions
Integer suffix for v ari abl es , c ons t an t s (in dec im al no tation), or userdefined functions
Multiplication operator
• Addition operator or unary positive sign
• Concatenation operator in string operation
• Format control character in PRINTUSING statement
Subtraction operator or unary negative sign
• Decimal point
• Format control character in
• Division operator
• Separator for date information in
Relational operator
• Relational operator
• Assignment operator in arithmetic or string operation
• User-defined function definition expressions in single-line form
A pair of double quotes delimits a string constant or a device file
name.
• Integer prefix for constants (in hexadecimal notation), which
should be followed by an H.
• Format control character in
• Initiates a comment.
• A pair of apostrophes (single quotations) delimits an included file
name.
• Delimit an array subscript or a function parameter.
• Force the order of evaluation in mathematical, relational, string,
and logical expressions.
PRINT USING statement
57
Page 66
Symbols and
control codes
:
(Colon)
;
(Semicolon)
[ ]
(Square brackets)
{ }
(Braces)
#
(Pound sign)
!
(Exclamation mark)
@
'
(Comma)
_
(Underline)
CR code
(Enter)
(Half-width space)
TAB
(Tab code)
Typical use
• Separates statements.
• Separates time information in
Line feed control character in
• Define the length of a string variable.
• Define the string length of the returned value of a string user-
defined function.
Define the initial value for an array element.
• File number prefix in
ments.
• Format control character in
Format control character in
Format control character in
• Separates parameters or arguments.
• Line feed control character in
If followed by a CR code, an underline extends one program line
up to 8192 characters.
Terminates a program line.
Separator which separates program elements in a program line.
(Note that a two-byte full-width space cannot be used as a separator.)
Separator which separates program elements in a program line.
OPEN, CLFILE, FIELD, and other state-
TIME$ function.
INPUT and other statements.
PRINT USING statement
PRINT USING statement
PRINT USING statement
INPUT and other statements.
58
Page 67
Chapter 4. Basic Program Elements
4.3Labels
A label can contain the following characters:
• Alphabet characters
• Nume ral ch arac ters
• Period (.)
Rules for naming labels
■
• The label length should be limited to 10 characters including periods.
• A program can contain up to 9999 labels.
• Label names make no distinction between uppercase and lowercase letters.
The following labels, for example, will be treated as the same label.
filewrite
FILEWRITE
FileWrite
• No asteri sk (*) or doll ar si gn ($) should be used for a label. The following labe l ex am pl es
are invalid:
*Label0
Label1$
• A label made up of only numeral letters as shown below is valid.
1000
1230
Note that a sin gle 0 (zero) should not be us ed as a label name since it ha s a special
meaning in
• A reserved word cannot be used by itself for a label name, but can be included within a
label name as shown below.
ON ERROR GOTO, ON KEY...GOSUB, and RESUME statements.
inputkey
• A label should not start with the character string FN.
59
Page 68
4.4Identifiers
Identifiers for the names of variables should comprise the same alphanumerics as the labels.
Rules for naming identifiers
■
• The identifier length should be limited to 10 characters including periods and excluding $
(dollar sign) and % (percent sign) suffixes.
• Every type of variables can contain up to 255 identifiers.
• A reserved word cannot be used by itself for an identifier name, but can be included
within an identifier name.
• An identif ier sh oul d not start with a numeral character or the character strin g
ing with an
DEF FN statement.
Examples of identifiers:
FN, the character string will be treated as a function identifier defined by the
a
abcdef$
a1
a12345%
FN. If start-
60
Page 69
Chapter 4. Basic Program Elements
4.5Reserved Words
"Reserved words" are keywords to be used in statements, functions, and operators. For the
reserved words, refer to Appendix B, "Reserved Words."
■
Rules for using reserved words
• A reserved word cannot be used by itself for a label name, a variable name, or other
identifiers, but can be included within them. The following identifiers, for example, are
improper since they use reserved words "input" and "key" as is, without modification:
input = 3
key = 1
• A reserved word can be used for a data file name as shown below.
5.4.1 Type Conversion................................................................................ 69
5.4.2 Type Conversion Examples ............................................................... 70
5.5Scope of Variables......................................................................................... 71
5.5.1 Global Variables................................................................................. 71
5.5.2 Local Variables................................................................................... 73
5.5.3 Variables Not Declared to be Global or Local.................................... 74
5.5.4 Common Variables........................................ ...... ............................... 75
62
Page 71
Chapter 5. Data Types
5.1Constants
5.1.1Types of Constants
A constant is a data item whose value does not change during program execution. Constants
are classified into two types: string constants and numeric constants.
Array variables should be declared in any of the
Note that the
BHT-BASIC can handle array variables up to two-dimensional.
The subscript range for an array variable is from 0 to 254.
DIM statement should precede statements that will access the array variable.
DIM, COMMON, and DEFREG statements.
[ 1 ] String Variables
A string variable should consist of 1 through 255 characters.
• Non-array string variables
A non-array string va riab le should be formatted with an ide ntifier followed by a dollar si gn
($) as shown below.
Syntax:identifier$
Example:a$,bcd123$
The default number of characters for a non-array string variable is 40.
• Array string variables
An array string variab le sh oul d b e formatted with an identifie r fo llowed by a dollar sign ($)
and a pair of parentheses () as shown below.
Syntax:
Example:a$(2),bcd123$(1,3)
Where a pair of parentheses indicates an array.
The default number of characters for an array string variable is 20.
identifier$(subscript[,subscript])
65
Page 74
■
Memory Occupation
A string variable oc cupie s the memor y sp ace by (the numb er of ch aracte rs + one) by tes, wh ere
the added one byte is used for the character count. That is, it may occupy 2 to 256 bytes.
If a non-array string variable consisting of 20 characters is declared, for example, it will occupy
21-byte memory space.
[ 2 ] Numeric Variables
• Non-array integer variables
A non-array integer variable should be formatted with an identifier followed by a percentage sign (%) as shown below.
Syntax:
Example:a%,bcd%
• Array integer variables
An array integer variable should be formatted with an identifier followed by a percentage
sign (%) and a pair of parentheses () as shown below.
Syntax:
Example:e%(10),fg%(2,3),h%(i%,j%)
Where a pair of parentheses indicates an array.
identifier%
identifier%(subscript[,subscript])
• Non-array real variables
A non-array real variable should be formatted with an identifier only as shown below.
Syntax:
Example:a,bcd
identifier
• Array real variables
An array real variable should be formatted with an identifier followed by a pair of parentheses () as shown below.
Syntax:
Example:e(10),fg(2,3),h(i%,j%)
Where a pair of parentheses indicates an array.
Memory Occupation
■
A numeric variable occupies 2 bytes or 6 bytes of the memory space for an integer variable or
a real variable, respectively.
identifier(subscript[,subscript])
66
Page 75
Chapter 5. Data Types
5.2.2Classification of Variables
■ Work Variables
A work variable is intended for general use. You may use it either by declaring with the DIM
statement as a non-array variable or without declaration as an array variable. The following
examples show work variables:
DIM a(10),b%(5),c$(1)
d=100:e%=45
FOR count% = s1% TO s2%
NEXT count%
At the start of a user program, the Interpreter initializes all of the work variables to zero (0) or a
null character string. At the end of the program, all of these variables will be deleted.
Upon execution of the
memory for the array variable. The declared array variable can be deleted by the
statement.
■ Common Variables
A common variable is declared by the COMMON statement. It is used to pass its value to the
chained-to programs.
DIM statement declaring an array variable, the Interpreter allocates the
ERASE
■ Register Variables
A register variable is a unique non-volatile variable supported exclusively by BHT-BASIC. It
will retain its value (by battery backup) even after the program has terminated or the BHT
power has been turned off. Therefore, it should be used to store settings of programs and
other values in the memory.
The Interpreter stores register variables in the register variables area of the memory which is
different from the work variables area.
Like other variables, register variables are classified into two types: string variables and
numeric variables, each of which is subclassified into non-array and array types.
The format of register va riab les is id entic al wi th that of gene ral vari ables . Howe ver, you need to
declare register variables including non-array register variables with
BHT-BASIC can handle array variables up to two-dimensional.
DEFREG statements.
67
Page 76
5.3User-defined Functions
Out of user-defined functions, the SUB and FUNCTION functions can be called from other
files. The
should start with an
The
functions, and character functions, each of which should be defined in the following format:
DEF FN function can be called only in the file where that function is defined and
FN.
DEF FN and FUNCTION functions are classified into three types: integer functions, real
User-defined Function
Integer functions
Real functions
Character functions
■
Setting Character String Length of Returned Values of Character Functions
A character function may return 1 through 255 characters. Note that the default character
string length results in the returned value of 40 characters.
If the returned value of the character string length is always less than 40 characters, you can
use the stack efficiently by setting the actual required value smaller than the default as the
maximum length. Th is is bec au se the I nterpreter positions returned val ues on the s tack during
execution of user-defined functions so as to occupy the memory area by the maximum length
size. To define a function which results in the returned value of one character, for example,
describe as follows:
Format of
FNfunctionname %
FNfunctionname
FNfunctionname $
DEF FNFormat of FUNCTION
DEF FNshort$(i%)[1]
On the other hand, if the returned value is more than 40 characters, it is necessary to set the
actually required length. To define a function which results in the returned values of 128 characters, for example, describe as follows:
DEF FNlong$(i%)[128]
■ D ummy Arguments and Real Arguments
Dummy arguments are u sed fo r d efi nin g user-defined functions. In th e exa mp le be low, i% is a
dummy argument.
DEF FNfunc%(i%)
FNfunc%=i%*5
END DEF
Real arguments are ac tua lly passed to user-defined functions wh en th ose func tio ns are ca lled.
In the example below, 3 is a real argument.
PRINT FNfunc%(3)
68
Page 77
Chapter 5. Data Types
5.4Type Conversion
5.4.1Type Conversion
BHT-BASIC has the type conversion facility which automatically converts a value of one data
type into another data type during value assignment to numeric variables and operations; from
a real number into an integer num ber by roun ding of f, and vice ve rsa, dep ending upon the c onditions.
• The Interpreter automa tica lly co nverts a valu e of a real i nto a n int eger, in any of the following cases:
- Assignment of real expressions to integer variables
- Operands for an arithmetic operator
- Operands for logical operators: AND, OR, NOT, and XOR
- Parameters for functions
- File numbers
In the type conversion from real into integer, the allowable value range of resultant inte-
ger is limited as shown below. If the resultant integer comes out of the limit, a run-time
error will occur.
-32768 ≤ resultantintegervalue ≤ +32767
MOD
• In assig nment s or operati ons fro m integer to real, the type-conv erted re al w ill ha ve hig her
accuracy:
Syntax:
In the above case, the Interpreter applies the type conversion to the evaluated resultant
of the integer expression before assigning the real value to the real variable.
Therefore, a in the following program will result in the value of 184.5.
realvariable = integerexpression
a=123%*1.5
69
Page 78
5.4.2Type Conversion Examples
The following examples show the type conversion from real to integer.
Assignment of Real Expressions to Integer Va riables
■
When assigning the value of the real expression (right side) to the integer variable (left
side), the Interpreter carries out the type conversion.
Syntax:
Example:b% = 123.45
Where b% will become 123.
Operands for an Arithmetic Operator MOD
■
Before executing the MOD operation, the Interpreter converts operands into integers.
integervariable = realexpression
Syntax:
Example:10.5 MOD 3.4
Where the result will become identical with 11MOD3.
Operands for Logical Operators AND, OR, NOT, and XOR
■
Before executing each logical operation, the Interpreter converts operands into integers.
Syntax:
realexpression MOD realexpression
NOT realexpression,
realexpression {AND|OR|XOR} realexpression
Example:10.6 AND 12.45
Where the result will become identical with 11AND12.
Parameters for Functions
■
If parameters i and j of the functions below are real expressions, for example, the
Interpreter converts them into integers before passing them to each function.
The Interpreter also rounds off file numbers to integers.
EOF(fileno),LOC(fileno),LOF(fileno),...
70
Page 79
Chapter 5. Data Types
5.5Scope of Variables
You may scope work varia bles and reg ister var iables to be local or glob al with th e PRIVATE
or GLOBAL statement, respe ct ive ly.
(5)Global variables
A global variable can be accessed by any routine in source files to share information
between those routines. Before access to it, you need to declare it with the
statement.
(6)Local variables
A local variable can on ly be acces se d by any rou tine in a source file where it is defined.
Before access to it, you need to declare it with the
(7)Variables not declared to be global or local
If not declared to be global or local, a variable is closed in each file where it is defined.
A variable used inside the FUNCTION or SUB function without declaration is available
only within a function where it is defined.
You may also share variables betw ee n us er prog ram s whe n one pro gra m ch ain s to an oth er by
declaring variables to be common with the
COMMON statement.
PRIVATE statement.
GLOBAL
5.5.1Global Variables
A global variable can be share d betwe en source fil es in a prog ram. In ea ch file whe re yo u want
to use a particular global variable, write
DEFREG statement.
(Example)
GLOBAL aaa%
GLOBAL bbb$[10]
GLOBAL ccc$(5,3)[30]
GLOBAL DEFREG ddd
GLOBAL DEFREG eee%(5)
(Example 1) To share the variable aa% between Files 1 and 2, define aa% by using the GLO-
BAL
statement in each file as follows:
File 1
GLOBAL aa%GLOBAL aa%
Before access to a global variable, you should define it.
GLOBAL preceding a desired variable name or
File 2
71
Page 80
If used inside the
defined, the variable will also have the same value.
SUB or FUNCTION function in the same file where the global variable is
(Example 2) The variable aa% defined by the
aa% within the
FUNCTION.
File 1
GLOBAL statement will have the same value as
File 2
GLOBAL aa%GLOBAL aa%
DECLARE SUB printaa(x)SUB printaa(x)
FUNCTION addaa(x) print aa%+x
addaa=aa%+xEND SUB
END FUNCTION
aa%=2
print addaa(2)
printaa(2)
If you link Files 1 a nd 2 ab ov e i nto a program file, the variabl e aa% used in those files wi ll ha ve
the same value.
If a same name variable is used in one file where it is declared to be global
■
and in the other file where it is not declared
In those files w here th e va riable is declared to be g lob al b y the GLOBAL st ate ment, al l of those
variables will have the same value. In a file where the variable is not declared, the variable is
available only in each file.
(Example) If in each of Files 1 and 2 the variable aa% is declared by the
and in File 3 the variable aa% is not declared:
File 1
File 2File 3
GLOBAL aa%[50]GLOBAL aa%[50]dim aa%[50]
GLOBAL statement
If you link Files 1, 2, and 3 above into a program file, the variables aa% in Files 1 and 2 will
have the same val ue and a a% in File 3 will be treated as a v ari abl e d ifferent from those in Fil es
1 and 2.
72
Page 81
Chapter 5. Data Types
5.5.2Local Variables
A local variable can be access ed on ly in a fi le where it is defined. Write PRIVATE preceding a
desired variable name or
(Example)
Before access to a local variable, you should define it.
If used inside more than one
able is defined, all of those variables will also have the same value.
SUB or FUNCTION function in the same file where the local vari-
PRIVATE aa%
FUNCTION addaa(x)
addaa=aa%+x
END FUNCTION
SUB printaa(x)
print aa%+x
END SUB
aa%=2
print addaa(2)
printaa(2)
In the above example, the variable aa% used in "addaa" and "printaa" will have the same
value.
■
Variables with overlapping scope
If your program has a global variable and a local variable with the same name, in those files
where the variable is declared with the
the same; in a file where the variable is declared with the
available only in that file.
(Example) If in each of Files 1 and 2 the variable aa% is declared by the
but in File 3 it is not declared by the
File 1
GLOBAL statement, those variables will be treated as
PRIVATE variable, the variable is
GLOBAL statement
GLOBAL statement:
File 2File 3
GLOBAL aa%[50]GLOBAL aa%[50]PRIVATE aa%[50]
If you link Files 1, 2, and 3 above into a program file, the variables aa% in Files 1 and 2 will
have the same val ue and a a% in File 3 will be treated as a v ari abl e d ifferent from those in Fil es
1 and 2.
73
Page 82
5.5.3Variables Not Declared to be Global or Local
If not declared to be global or local, a variable is closed in each file where it is defined. A variable used inside the
function where it is defined.
(Example)
In the above example, all variables aa% used in "addaa," "printaa," and others will be treated
as different ones.
FUNCTION or SUB function without declaration is available only within a
FUNCTION addaa(x)
addaa=aa%+x
END FUNCTION
SUB printaa(x)
print aa%+x
END SUB
aa%=2
print addaa(2)
printaa(2)
74
Page 83
Chapter 5. Data Types
5.5.4Common Variables
A common variable should be declared in a main object beforehand. To share the common
variable by files other than the main object, you need to declare it with the
in each file where the common variable should be available.
File 1
File 2
DECLARE SUB printaa(x)COMMON a%
COMMON a%SUB printaa(x)
a%=2 print a%+x
printaa(5)SUB
To use a% as a common variable in Files 1 and 2, define the variable with the COMMON statement in each file.
If a common var iable de clar ed with the
TION
function in a file w here th e variabl e is def ined, the n the co mmon var iable wi ll have t he
same value.
(Example)
COMMON aa%
COMMON statement is used within the SUB or FUNC-
FUNCTION addaa(x)
addaa=aa%+x
END FUNCTION
SUB printaa(x)
print aa%+x
END SUB
aa%=2
print addaa(2)
printaa(2)
COMMON statement
In the above example, variables aa% used in "addaa" and "printaa" will be treated as same
one.
An expression is defined as a combination of constants, variables, and other expressions
which are connected using operators.
There are two types of expressions--numeric expressions and string expressions.
BHT-BASIC has the following types of operators:
OperatorsDescription
Arithmetic operatorPerforms arithmetic operations.
Relational operatorCompares two values.
Logical operatorCombines multiple tests or Boolean expressions
into a single true/false test.
Function operatorPerforms the built-in or user-defined functions.
String operatorConcatenates or compares character strings.
77
Page 86
6.2Operator Precedence
When an expression contains more than one operator, BHT-BASIC performs the operations in
the standard precedence as shown below.
Precedence
1.Parentheses ( )
The parentheses allow you to override operator precedence; that is, operations
enclosed with parentheses are first carried out.
For improving the read abili ty of an expre ssion , you c an us e p arenthe ses to sep arate
two operators placed in succession.
2.Function operations
3.Arithmetic operations
OperationsArithmetic OperatorsPrecedence
Negation
Multiplication and division
Modulo arithmetic
Addition and subtraction
When more than one operator occurs at the same level of precedence, the BHT-BASIC
resolves the expression by proceeding from left to right.
a=4+5.0/20*2-1
In the above example, the operation order is as follows;
5.0/20 (=0.25)
0.25*2 (=0.5)
4+0.5(=4.5)
4.5-1(=3.5)
79
Page 88
6.3Operators
6.3.1Arithmetic Operators
Arithmetic operators include a negative sign (-) and operators for multiplication (*), division (/),
addition (+), and subtraction (-). They also include modulo operator
MOD.
OperationsArithmetic OperatorsPrecedence
Negation
Multiplication and divis io n
Modulo arithmetic
Addition and subtraction
Modulo Operation (MOD)
■
The MOD operator executes the modulo operation; that is, it divides expression1
by expression2 (see the format below) and returns the remainder.
Syntax:
Where one or more spaces or tab codes should precede and follow the MOD.
If these expressions include real values, the
then executes the division operation. For example, the
as 8 MOD 3 so as to return the remainder "2".
3.4
■
Overflow and Division by Zero
Arithmetic overflow resulting from an operation or division by zero will cause a run-time
error. Such an error may be trapped by error trapping.
expression1 MOD expression2
* and /
MOD
+ and –
MOD first rounds them off to integers and
1
2
3
4
MOD treats express ion 8 MOD
Examples
-a
a*b, a/b
a MOD b
a+b, a-b
80
Page 89
Chapter 6. Expre ssions and Operators
6.3.2Relational Operators
A relational operator com pa res two value s. Depend ing upo n whet her the co mp arison is true or
false, the operator returns true (–1) or false (0).
With the operation result, you can control the program flow.
The relational operators include the following:
Relational OperatorsMeaningsExamples
=
<> or ><
<
>
<=
or =<
>=
or =>
If an expression contains both arithmetic and relational operators, the arithmetic operator has
higher precedence than the relational operator.
Equal to
Not equal to
Less than
Greater than
Less than or equal to
Greater than or equal to
A = B
A <> B
A < B
A > B
A <= B
A >= B
81
Page 90
6.3.3Logical Operators
A logical operator combines multiple tests and manipulates Boolean operands, then returns
the results. It is used, for exam ple, to control the progra m exe cution flow or tes t the val ue of an
INP function bitwise, as shown in the sample below.
IF d<200 AND f<4 THEN ...
WHILE i>10 OR k<0 ...
IF NOT p THEN ...
barcod% = INP(0) AND &h02
Listed below are the four types of logical ope rato rs ava ila ble .
One or more spaces or tab codes should precede and follow the
operators.
In the logical expressions (or operands), the logical operator first carries out the type conversion to integers before performing the logical operation. If the resultant integer value is out of
the range from -32768 to +32767, a run-time error will occur.
If an expression contains logical operators together with arithmetic and relational operators,
the logical operators are given lowest precedence.
NOT
AND
OR
XOR
NOT, AND, OR, and XOR
1
2
3
4
[ 1 ] The NOT operator
The NOT operator reverses data bits by evaluating each bit in an expression and setting the
resultant bits according to the truth table below.
Syntax:
Truth Table for NOT
NOT expression
Bit in ExpressionResultant Bit
0
1
For example, NOT0 = -1 (true).
The NOT operation for an integer has the returned value of negative 1’s complement. The
1
0
NOT X, for instant, is equal to –(X+1).
82
Page 91
Chapter 6. Expre ssions and Operators
[ 2 ] The AND operator
The AND operator ANDs the same order bits in two expressions on either side of the operator,
then sets 1 to the resultant bit if both of these bits are 1.
Syntax:
Truth Table for AND
expression1 AND expression2
Bit in Expression1Bit in Expression2
0
0
1
1
0
1
0
1
Resultant Bit
0
0
0
1
[ 3 ] The OR operator
The OR operator ORes the same order bits in two expressions on either side of the operator,
then sets 1 to the resultant bit if at least one of those bits is 1.
Syntax:
Truth Table for OR
Bit in
Expression 1Bit in Expression 2
expression1 OR expression2
0
0
1
1
Resultant Bit
0
1
0
1
0
1
1
1
[ 4 ] The XOR operator
The XOR operator XORes the same order bits in two expressions on either side of the operator, then sets the resultant bit according to the truth table below.
Syntax:
Truth Table for XOR
Bit in
Expression 1Bit in Expression 2
expression1 XOR expression2
0
0
1
1
0
1
0
1
83
Resultant Bit
0
1
1
0
Page 92
6.3.4Function Operators
The following two types of functions are available in BHT-BASIC, both of which work as function operators:
■
Built-in Functions
Already built in BHT-BASIC, e.g., ABS and INT.
■ User-defined Functions
Defined by using DEFFN (in single-line form), DEFFN...ENDDEF (in block form),
SUB...END SUB, or FUNCTION...END FUNCTION statement.
6.3.5String Operators
A character string operator may concatenate or compare character strings.
Listed below are the types of character string operators available.
The process of combining character strings is called concatenation and is executed
with the plus sign (+). The example below concatenates the character strings,
Listed below are the fonts available on each BHT series.
Screen modeFont sizeLetter type
Single-byte
ANK* mode
Two-byte
Kanji mode
Standard-size ANK charsRegular12 x 1216 x 25
Standard-size Full-widthRegular16 x 1612 x 19
Half-widthR egular8 x 1625 x 19
Small-sizeFull-widthRegular12 x 1216 x 25
Character
enlargement
Double-width24 x 128 x 25
Double-height12 x 2416 x 12
Quadruple24 x 248 x 12
Double-width32 x 166 x 19
Double-height16 x 3212 x 9
Quadruple32 x 326 x 9
Double-width16 x 1612 x 19
Double-height8 x 3225 x 9
Quadruple16 x 3212 x 9
Double-width24 x 128 x 25
Double-height12 x 2416 x 12
Dots (W x H)Chars x Lines
Quadruple24 x 248 x 12
Half-widthR egular6 x 1233 x 25
Double-width12 x 1216 x 25
Double-height6 x 2433 x 12
Quadruple12 x 2416 x 12
*ANK: Alphanumerics and Katakana
88
Page 97
■ Screen mode
The ANK mode displays ANK characters listed in Appendices C1 and C2.
The Kanji mode displays the following characters:
• Half-width: Katakana and alphanumerics
• Full-width: JIS Levels 1 and 2 Kanji, alphabets and symbols
Chapter 7. I/O Facilities
NOTE
■
The standard- and small-size fonts may be displayed.
To display Kanji characters, it is necessary to download Kanji font files listed below.
Even without those files, the half-width alphanumerics and Katakana may be displayed.
Each of the 16-dot and 12-dot font files consists of JIS Level 1 and Level 2 files.
■ Display angle
You may rotate characters to be displayed 180°.
Half-width Kanji characters differ from ANK characters in size.
Font size
• To use standard-size fonts:16-dot font file
• To use small-size fonts:12-dot font file
Switching the screen mode, font size, and display angle
You may switch the sc reen mode, font size, and dis pl ay an gle by using the SCREEN statement
(displaymode parameter). Refer to Chapter 14, SCREEN.
89
Page 98
[ 2 ] Character attributes (Reverse font attribute, enlargement
attribute, tone attribute)
■ Reverse font attribute
Characters may be reversed (highlighted).
Enlargement attribute
■
Characters may be displayed in regular-size, double-width, double-height, and quadruple-size,
as listed in [ 1 ].
■ Tone attribute
Characters may be displayed in bl ack, dark gray, light gray, and white.
Switching the character attributes
You may switch the reverse font attribute, enlargement attribute, and tone attribute by using
the
SCREEN statement ( charaattribute parameter). Refer to Chapter 14, SCREEN.
90
Page 99
Chapter 7. I/O Facilities
7.1.2Coordinates on the LCD
To locate characters on the coordinates of the LCD screen, use the LOCATE statement. To
obtain the current cursor position, use the
The coordinates will differ depending upon the screen mode and font size.
CSRLIN and POS functions.
Single-byte
ANK mode
• Standard-size font
LOCATE 1,1
LOCATE 4,4
LOCATE 4,7
LOCATE 4,10
LOCATE 4,14
Regular
Double-width
LOCATE 16,1
Double-height
Quadruple
LOCATE 16,25
91
Page 100
Two-byte Kanji Mode
• Standard-size font
Be careful about the specification of line numbers in figures below. A single column
shown below represents an area for a half-width character; Double columns represent
an area for a full-width character.
92
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.