,ll 6.6
,cs 10
,pl 66
,lm 0.2,0.5
,pn 28
,ju
,hd
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,,
,ft

,ce 1
4-##
,,
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,ce
TYPE DECLARATIONS

Text devices have the base type of character but in addition have line structure. The Procedures Readln, Writeln, and Page and the function Eoln are only valid for text devices. Any other procedures and functions that are available for non-text devices are also available for text devices. ASCII nulls are skipped when reading data from text devices by the device driver. Horizontal tabs are represented by a space in the element buffer. Carriage returns are represented by a space in the element buffer and the eoln function returning true.
 
Interactive devices differ from other devices in that there need not be a valid element for the Eof and Eoln functions. The test is done based on the current flags. This was implemented so that in the situation as depicted below :

    While not Eof do
      begin
        Write ('Enter value : ') ;
        Read (value) ;
        Writeln ('Log is : ', Log(value))
      end ;
 
The first character of value need not be entered before you are told what you are supposed to enter by the Write statement as would be required in standard Pascal. Using this flag in the device descriptor we are able to use the same functions and procedures (reading a string is modified by the interactive flag) for both terminal and disk devices. The interactive attribute has no effect when writing to a device.  

When the buffer variable is used an assumption is made regarding data direction depending on where the buffer variable is used. If the buffer variable is used on the left side of an assignment statement then it is assumed that the data will be written to the device. If the buffer variable is used on the right side of an assignment statement (as part of an expression) then before using the data in the element buffer, the buffer is filled. This is accomplished by executing the get procedure if the element buffer is not valid. 

Most users will not need to define their own custom devices and so all of the details of what a device descriptor and device driver are will be left until chapter 8, for those that need this information. The standard I/O devices (input, output, auxout, and keyboard) are pre-defined and are covered below.

Files are declared by following the reserved words "file" "of" by the type of the file, or by the word "text". Note that "file of text" may be abbreviated to just "text" for compatibility with the ISO standard. A file declaration may also have the words "interactive" and "packed" preceding the word "file". 

As is true with all types, packed has no meaning in this compiler and is ignored. If interactive is specified it will affect the meaning of the EOF and EOLN flags as described above. Interactive is not normally used for files.
,pg
,ce
TYPE DECLARATIONS

file-type = [interactive] [packed] file of (type | text) | text


                           text

                                                type
 
   interactive     packed     file     of  
 
                                                text


STANDARD DEVICES

The standard I/O device "input" is normally attached to the system terminal's keyboard, with buffering done by the operating system similar in action to the command line buffering. This device is capable of input transfers only. Data typed from the terminal is also echoed in the same manner as command line buffering. No actual data is available from this device until a carriage return is entered. The normal character delete and line delete edit functions are available from the terminal, others may be available depending on the operating system.

The compiler B option (as described in chapter 1) will affect the operation of the input device. If the B option is off and the operating system defined break key is hit, then control will return to the operating system when the break function is executed. If the B option is on and the break key is  hit, then control will not return to the operating system but will return true from the break function. This is used when cleanup is required before returning to the operating system, or when you wish to use the break key for some other purpose. The standard input device is implicitly declared as : interactive device of text.

The standard I/O device "output" is normally attached to the system terminal's screen. This device is capable of output transfers only. The standard output device is implicitly declared as : device of text.

The standard I/O device "auxout" is normally attached to the system printer. This device is capable of output transfers only. The standard auxout device is implicitly declared as : device of text.

The standard I/O device "keyboard" is normally attached to the system terminal's keyboard. This device is capable of input transfers only. No buffering is done by this device and there are no special characters recognized. This device does not echo its input to the screen. The standard keyboard device is implicitly declared as : interactive device of char.

The above descriptions are general in nature and more specific information is presented in chapter 3.
,pg
,ce
TYPE DECLARATIONS

POINTERS

In ISO standard Pascal pointers are only used to dynamically create variables on a stack-like structure called a heap. Pointers types are declared by following the caret symbol "^" by the base type of the pointer. NOTE: The caret symbol ^ is also referred to as a circumflex, or in fact may be an up-arrow on some terminals or printers. This symbol will be referred to as a caret in this manual.

The base type of the pointer may be any of the simple types (boolean, integer, hex, character, longinteger, longhex, or real) or may be a user defined type identifier.

The actual pointer variable is compatible with any other pointer variable and with any hex value. The hex value of $0 is used to signify that the pointer does not point to a valid object and the reserved word "nil" is used to represent this $0 value. It is therefore not a good idea to start the heap at location zero.

To access the data object that the pointer points to, follow the pointer name with the caret. For example :

pntr = ^real ;  { pntr points to real values }

pntr := nil ;   { the pointer now points to nothing }

new (pntr) ;    { allocates 4 bytes for a real on the stack
                  and puts the address for it in pntr       }

pntr^ := 4.3 ;  { stores 4.3 at the location pointed to by pntr }

The procedure "new" stores the next available location on the heap into its parameter. It also moves the internal heap pointer up by the size of the type that the pointer points to.

OmegaSoft Pascal allows a number of extensions to make pointers even more powerful. A pointer is essentially a hex value with a special attribute, meaning that any operation that can be used for a hex variable will work for a pointer. For example, suppose you wanted to store strings on the heap. The pointer declaration would be :

line : string [80] ;
pntr : ^line ;

To put the string 'ABC' on the heap you could use :

line := 'ABC' ;
new (pntr) ;
pntr^ := line ;

But this would use up 81 bytes of heap space for the 3 byte string, for which only 4 bytes are needed. OmegaSoft Pascal allows an optional parameter to the new procedure which overrides the default size of the base type. Therefore we can specify how much heap space we really need :

new (pntr : length(line) + 1) ;
pntr^ := line ;
,pg
,ce
TYPE DECLARATIONS

The integer expression following the colon in the new procedure specifies the number of bytes needed off of the heap. To move from one string to another pointer arithmetic may be used :

pntr := pntr + hex(length(pntr^) + 1) ;

This extension can save a great deal of space when dealing with variable length structures.

pointer-type = ^ type
pointer-constant = nil | hex-constant

,ce
VARIABLE DECLARATIONS

Variables are normally allocated on the data stack. The first variable declared is allocated immediately below the stack frame, and subsequent variables below that. Since variables are referenced relative to the stack frame, small and often used variables should be allocated first. This will allow those variables to use shorter and faster addressing instructions to access them.

The variable section must not exceed 32K bytes in length or else a compile-time error will occur.

variable-declaration = var [storage1] var-definer { var-definer }
var-definer = identifier {, identifier} : type
                                        [(storage1 | storage2)] ;
storage1 =  [(pcr | entry | external | 
          data [(external | entry)] | varib [(external | entry)])
storage2 = [(data const constant-list |
             at [ < ] address-expression)]
address-expression = ( integer-constant-expression |
                     hex-constant-expression )

constant-list = ( const-element {, const-element} )
const-element = (constant-expression | 
                 constant-expression of constant-expression |
                 constant-list)
,pg
,ce
VARIABLE DECLARATIONS

variable-declaration :

      var           external
 
                    entry

                    pcr

                                       external
                    varib
                                       entry

                                       external
                    data
                                       entry


         identifier          :       type
 
             ,


 
                 at    <     address expression              ;
 
                 external
 
                 entry

                 pcr

                                    external
                 varib
                                    entry

                                    external

                 data               entry

                            const       constant-list


constant list :

        (    const-element          ,     const-element       )


const-element :

                            constant-expression

          constant-expression      of      constant-expression

                               constant-list


There are two methods of modifying the storage requirements for one or more variables. The first method is the specify the storage after each declaration, affecting only that declaration, such as : 

,pg
,ce
VARIABLE DECLARATIONS

var
  abc : integer ;                 {normal stack allocation}
  def : integer entry ;           {entry}
  ghi, jkl : integer external ;   {both external}
  mno : integer ;                 {normal stack allocation}

The second method is to specify the storage after the "var", which affects all the variables in that section. OmegaSoft Pascal allows multiple "var" sections, so you can mix both methods.

var data external
  abc : integer ;
  def : byte ;
  ghi, jkl : real ;               {all of these are data external}

Note that "at" and "data const" cannot be used in the second method.

EXTENDED ADDRESSING

If the type in the variable declaration is followed with the word "at" and then an integer, or hex constant expression then the variable will start at the indicated address. The variable will be accessed using the 6809 extended addressing mode. This mode is useful for placing a variable at a specific location in memory - such as a byte variable for an ACIA or PIA, or an array starting at the start of a RAM or ROM.

DIRECT PAGE ADDRESSING

If the type in the variable declaration is followed with the word "at", the symbol "<", and then an integer or hex constant expression then the variable will start at the indicated address in base page. The variable will be accessed using the 6809 direct page addressing mode. This mode is useful for common variables between Pascal and assembly language or as a way to obtain very fast access of critical global variables.

PCR ADDRESSING

If the type in the variable declaration is followed with the word "pcr" then the variable will be accessed using the 6809 program counter relative addressing  mode. An external reference (XREF) will be issued for the variable using its declared name truncated to 8 characters.

As an example :

initarray : array [1..16] of byte pcr ;

will generate :  xref initarra

and to access the array will use : leax initarra,pcr

This mode is useful for placing tables or other "constant variables" in along with the program, normally by using assembly language and linking it with the Pascal program. In general it is better to put tables or constant variables in data section using data external addressing or by using structured constants.
,pg
,ce
VARIABLE DECLARATIONS

EXTERNAL ADDRESSING

If the type in the variable declaration is followed by the word "external" then it means that the variable is allocated on the stack but declared in another module. An external reference (xref) will be generated using the variable name truncated to 8 characters. As an example :

flag : byte external ;

will generate : xref flag

and to read the flag will use : 

 ldb flag,y

This mode is useful for referencing global variables from the main program (with those defined as entry) from a module. This is an alternative to declaring global variables in every module that uses them and is very attractive when only a few variables need be imported from the main program into the module. External addressing is only valid for global variables.

ENTRY ADDRESSING

If the the type in the variable declaration is followed by the word "entry" then normal stack addressing will be used, but in addition an external definition will be generated for the variable. The external definition (xdef) will use the variable name truncated to 8 characters. As an example :

flag : byte entry ;

will generate :  xdef flag
                flag equ $xxxx

where xxxx is the stack offset to be added to the global stack frame pointer.

This mode is useful for defining global variables in the main program for use in a module with the variable defined as external. This mode can also be used when you need to access a global variable from an assembly language routine by inserting into the code :

 xref flag
   .
 ldx -6,y    {if not always called from the main program}
 ldb flag,y

The entry allocation attribute is automatically applied to the standard I/O devices if declared in the program parameter list.

NOTE : The above two special addressing modes may only be used in the global variable declaration section, not within procedures.

