Kyan Pascal Tutorial Manual

Courtesy to all ATARI 8 Bit Users Scanned & Re-Edited by GoodByte in 2005 / (P) 2006 Kyan PASCAL Version 1.0 Kyan Dear Friend: Thank you for purchasin...

5 downloads 317 Views 637KB Size

Courtesy to all ATARI 8 Bit Users

Scanned & Re-Edited by GoodByte in 2005 / (P) 2006

Kyan PASCAL Version 1.0

Kyan Dear Friend: Thank you for purchasing Kyan PASCAL. We believe you will find it to be the most powerful and complete PASCAL implementation available for the Apple II and ATARI family of computers. This manual is intended to help you learn the PASCAL language and master the many features and functions of your Kyan PASCAL compiler. Kyan PASCAL includes all the sophisticated PASCAL functions needed to develop professional quality programs. The built-in assembler, linking/chaining functions, and other advanced features enable you to write very large PASCAL programs and run them at the maximum speed possible on the Apple / ATARI 6502 microprocessor. We believe you will find that KyanPASCAL can satisfy all of your programming needs. Kyan PASCAL is not copy-protected and we recommend that you make and use back-up copies of the software. We also allow you to copy and use Kyan's PASCAL library in any software you develop with no fee or separate license agreement. The only requirement is that you acknowledge Kyan's copyright on this software on your magnetic media and in your documentation. This is all explained in more detail by the enclosed license agreement. Thanks again for purchasing this software from Kyan. If you have any questions or suggestions for improvement, please let us know. We are always striving to improve our software and we welcome comments (both good and bad) from our customers. We hope to hear from you. TEE/sk

Thomas E. Eckmann President Kyan Software

kyan software

1850 union street # 18 3

san francisco, california 9 41 23

Scanned & Re-Edited by GoodByte in 2005 / (P) 2006

( 41 5) 775-2923

2

Kyan PASCAL Version 1.0

LICENSE AGREEMENT When you purchase and use Kyan PASCAL, you acknowledge that: A. Kyan Software Inc. has a valuable proprietary interest in this Program and documentation; you are receiving a limited, non—exclusive license to use the Program and documentation; and, Kyan Software Inc. retains title to the Program and documentation. B. You may not copy or reproduce the Program or documentation for any purpose other than to make backup copies as provided for under U.S. Federal Copyright Law. C. You, your employee and/or agents may not distribute or otherwise make the Program or documentation available to any third party. D. If the Runtime Library or any other portion of this Program is merged into or used in conjunction with another program, it will continue to be the property of Kyan Software Inc. However, Kyan Software Inc. hereby grants you a non-exclusive license to merge or use portions of the Program in conjunction with your own programs provided that you acknowledge Kyan Software's copyright and ownership of these portions in a prominent location on the magnetic media and in the written documentation for your software. (Please contact Kyan Software Inc. for more information). E. This license is effective until terminated. You may terminate it at any time by destroying the Program and documentation with all copies, modifications and merged portions in any form. It will also terminate if you fail to comply with any term or condition of this Agreement. You agree upon such termination to destroy the Program and documentation together with all copies, modifications and merged portions in any form. COPYRIGHT NOTICE Kyan Software believes you should be aware of your rights under the U.S. Federal Copyright Law. We quote for you the provisions of Section 117 of the Copyright Law, which contains limitations on the rights of copying and adaptation given to owners of computer programs: "Not withstanding the provisions of Section 106, it is not an infringement for the owner of a copy of a computer program to make or authorize the making of another copy or adaptation of that computer program provided: (1)

that such new copy or adaptation is created as an essential step in the utilization of the computer program in conjunction with a machine and that it is used in no other manner, or

(2)

that such new copy or adaptation is for archival purposes only and that all archival copies are destroyed in the event that continued possession of the computer program should cease to be rightful. Any exact copies prepared in accordance with the provision of this section may be leased, sold, or otherwise transferred, along with the copy from which such copies were prepared, only as part of the lease, sale, or other transfer of all rights in the program. Adaptations so prepared may be transferred only with authorization of the copyright owner."

SUBJECT TO THOSE LIMITATIONS, KYAN SOFTWARE GRANTS THE PURCHASER OF THIS PRODUCT A LICENSE TO USE THIS SOFTWARE UNDER THE TERMS DESCRIBED IN THE FOLLOWING LICENSE AGREEMENT.

Scanned & Re-Edited by GoodByte in 2005 / (P) 2006

3

Kyan PASCAL Version 1.0

PREFACE ............................................................................................................................ 7 INTRODUCTION ................................................................................................................ .8 EDITOR AND COMPILER INSTRUCTIONS ....................................................................... 9 Creating a File, an Example ....................................................................................... 9 End of Editing............................................................................................................ 10 Files, Pathnames, and File Names ........................................................................... 10 Cursor Movement ..................................................................................................... 10 Delete Commands .................................................................................................... 11 Search For and Search/Replace............................................................................... 11 Edit at Line - N.......................................................................................................... 12 Including a File.......................................................................................................... 12 Block Move Commands ........................................................................................... 12 Editing HELLO, an Example ..................................................................................... 12 Compiling a File ....................................................................................................... 13 Apple Compiler Options............................................................................................ 13 ATARI Compiler Options .......................................................................................... 14 Running Files and File Name Extensions ................................................................. 14 Printing a Program ................................................................................................... 14 Compiler Error Messages, an Example .................................................................... 15 To Halt a Program While It Is Running ..................................................................... 15 Apple RAM disk ........................................................................................................ 15 ATARI RAM disk ...................................................................................................... 16 ProDOS .................................................................................................................... 16 DOS 2.5 ................................................................................................................... 17 Help........................................................................................................................... 18 Special Characters - Apple II..................................................................................... 18 List of Editor Commands .......................................................................................... 18 List of Compiler/Assembler Commands ................................................................... 19 Assembler/Compiler Options – ATARI...................................................................... 19 Other Commands ..................................................................................................... 19 PART I : SAMPLE PROGRAMS ........................................................................................ 20 EGO PROGRAM................................................................................................................ Program Statement and Reserved Words ................................................................ Declaration and Program Body ................................................................................ Analysis of Ego ........................................................................................................

20 20 20 20

CONSTRUCTION PROGRAM ........................................................................................... Analysis of Construction ........................................................................................... Algorithm................................................................................................................... Identifiers................................................................................................................... Write and Read Commands ..................................................................................... Input, Output and Printing the Output ....................................................................... Readln ...................................................................................................................... CONST......................................................................................................................

21 21 21 21 22 22 22 22

PROGRAM TO FIND THE AVERAGE ............................................................................... Readln and Writeln ................................................................................................... Real and Integer Data Types ................................................................................... Trunc, Round and Maxint ......................................................................................... Arithmetic Operators ................................................................................................

23 23 24 24 25

SOCIAL SECURITY PROGRAM,....................................................................................... Relational Operators ................................................................................................ The IF-THEN Statement ........................................................................................... The Assignment Statement ......................................................................................

25 25 26 26

ALPHABETIZE PROGRAM ............................................................................................... FirstWord Algorithm .................................................................................................. String and Char Types ............................................................................................. WHILE ......................................................................................................................

26 27 27 28

FACTORIAL PROGRAM ................................................................................................... 28 Analysis of Program ................................................................................................. 28 For Loops and Loop Control Variables...................................................................... 29 BOOLEAN PROGRAM ...................................................................................................... Boolean Data Type ................................................................................................... Div and Mod Operators ............................................................................................ Boolean Operators ...................................................................................................

Scanned & Re-Edited by GoodByte in 2005 / (P) 2006

29 29 29 30

4

Kyan PASCAL Version 1.0

Operator Precedence ............................................................................................... 30 MULTI-DIGIT HEXADECIMAL CONVERSION .................................................................. 30 Algorithm .................................................................................................................. 31 REPEAT UNTIL........................................................................................................ 31 Scalar Types and Boolean Variables ....................................................................... 32 Subrange Types ....................................................................................................... 32 CASE OF.................................................................................................................. 32 The Functions Ord, Pred, Succ, and Chr................................................................... 33 PART II : PROGRAMMING TECHNIQUES ....................................................................... 34 PROCEDURES ................................................................................................................. Declaring and Executing Procedures ....................................................................... Parameter Lists, Actual and Formal ......................................................................... Variable and Value Parameters ................................................................................ Correspondence Between Actual and Formal Parameters .................................................................................. Functions .................................................................................................................. Declaring Functions .................................................................................................. The Function Odd ..................................................................................................... Global and Local Variables ...................................................................................... Nesting of Functions and Procedures ...................................................................... Global and Local Types ............................................................................................ Forward References ................................................................................................. Unconditional Branch: GOTO ...................................................................................

34 34 35 35

ARRAYS ............................................................................................................................ Arrays of Arrays and Multidimensional Arrays........................................................... Adding Two Multidimensional Arrays ....................................................................... The Array As a Parameter ........................................................................................ Program Example1 ................................................................................................... Program Example2 ................................................................................................... End of Line ............................................................................................................... Recursive Functions and Procedures ....................................................................... Copying Arrays .........................................................................................................

40 41 42 42 42 43 44 45 45

RECORDS ......................................................................................................................... Copying a Record ..................................................................................................... Program Absolute..................................................................................................... Program ElapsedTime............................................................................................... Arrays of Records ..................................................................................................... WITH ........................................................................................................................ Variant Records .......................................................................................................

46 46 47 47 48 49 49

36 36 36 37 37 38 39 39 40

SETS ................................................................................................................................. 50 Operations on Sets ................................................................................................... 51 Using Sets to Examine the Members of an Array ..................................................... 52 FILES.................................................................................................................................. File Declaration ........................................................................................................ Writing to a File......................................................................................................... Program Store(List) .................................................................................................. Reading a File .......................................................................................................... Text Files .................................................................................................................. Files of Records ....................................................................................................... Random Files ...........................................................................................................

52 52 53 53 53 54 55 55

POINTER VARIABLES AND LINKED LISTS ..................................................................... Pointers and Nodes .................................................................................................. New .......................................................................................................................... Peek and Poke.......................................................................................................... Linked Lists and NIL ................................................................................................. Dispose ....................................................................................................................

56 56 57 57 58 59

INCLUDE ........................................................................................................................... 59 How to Include Procedures and Functions from other Files ..................................... 59 Including Files, Other Applications............................................................................ 60 THE ASSEMBLED PROGRAM AND ITS USES................................................................. 60 Assembly Language Routines .................................................................................. 60 Assembler Directives ................................................................................................ 60 How to Use Assembly Language Routines to Modify PASCAL Variables................. 61

Scanned & Re-Edited by GoodByte in 2005 / (P) 2006

5

Kyan PASCAL Version 1.0

Predefined Labels..................................................................................................... 62 Passing Parameters through Chain .......................................................................... 62 How to Chain Source Code Files ............................................................................. 62 GRAPHICS (Apple II Only)................................................................................................. 63 High Resolution Graphics ......................................................................................... 63 Line Segments ......................................................................................................... 63 STRING MANIPULATION.................................................................................................. String ........................................................................................................................ Length....................................................................................................................... Concat ...................................................................................................................... Index......................................................................................................................... Substring...................................................................................................................

64 64 64 65 65 65

APPENDIX A COMPILER, ASSEMBLER AND RUN-TIME ERROR MESSAGES.................................... 66 APPENDIX B QUICK GUIDE TO KYAN PASCAL ................................................................................... 69 APPENDIX C SPECIFICATIONS.............................................................................................................. 71 WARRANTY ...................................................................................................................... 73

Scanned & Re-Edited by GoodByte in 2005 / (P) 2006

6

Kyan PASCAL Version 1.0

PREFACE PASCAL, A Programming Language provides beginning programmers with a step-by-step introduction to PASCAL, and advanced programmers with a convenient reference to the language. The first chapter, EDITOR AND COMPILER INSTRUCTIONS, explains how to enter, edit, and compile a PASCAL program. This material must be read prior to actual programming. Readers with no previous experience with PASCAL should read the chapters in order. It is recommended that the example programs be entered, compiled, and run. It is not essential that every line be duplicated from these programs. In fact, rewriting the example programs not only is instructive but also can improve them. Programmers who are already familiar with PASCAL need only read the sections on topics they wish to review. Appendix B provides a quick review of PASCAL vocabulary. Addition by the Re-Editor This manual is brought to you in the intention to keep the knowledge about a great product from former kyan software within the ATARI community. Even after more than 20 years it is fascinating to discover the power of the language and the machine in a setting which matches a state of the art home computer set in the mid eighties of the 20th century.

Scanned & Re-Edited by GoodByte in 2005 / (P) 2006

7

Kyan PASCAL Version 1.0

INTRODUCTION The history of PASCAL goes back to the late 1960s, when Niklaus Wirth, a professor of computer science, decided that a new approach -- a new language -- was needed for teaching programming. Wirth introduced PASCAL as a formal language in 1971. The two principal aims of PASCAL are "..to make available a language suitable to teach programming as a systematic discipline based on certain fundamental concepts clearly and naturally reflected by the language.." and "to develop implementations of this language which are both reliable and efficient on presently available computers" (Jensen and Wirth, "PASCAL User Manual and Report"). PASCAL has become a widely used language for both elementary and advanced programming. Its popularity derives from the clarity of programs written in it and the efficiency with which it can be implemented within the computer. Kyan PASCAL is especially efficient in this regard, because the run time code and the compiler itself are written in assembly language, the language of the microprocessor integrated circuit. Unlike some other compiled languages, Kyan PASCAL includes the necessary tools for advanced programmers who wish to include assembly language routines in their PASCAL programs. PASCAL is a self-documenting and self-structuring language. Top-down programming and modulization are natural outgrowths of its features. These features include, among others, user-defined functions and procedures of which modules are built. Separation of the declaration section from the program body also enforces good programming technique. All the information on constants, types of variables, and names of variables and constants appears, in a single section rather than being spread throughout the program. Kyan PASCAL provides features that help the programmer to find the syntax errors that account for over 90% of the errors in programming. Over 30 error messages for syntax are in the compiler. These not only tell the programmer what types of errors were made but also on which lines the errors occurred. Kyan PASCAL does not stop looking for errors or lose synchronization when an error is found. Instead, although compilation halts, error detection continues and all the errors are displayed at one time. One final reason for using PASCAL is its portability. PASCAL, one of today's most popular languages, is implemented on nearly every computer on the market. Kyan PASCAL is compatible with standard PASCAL. Programs and program modules written in Kyan PASCAL (using standard procedures and functions) will run on a multitude of computers: a programmer can develop software on a home computer, transport it to many other machines, and run the programs immediately.

Scanned & Re-Edited by GoodByte in 2005 / (P) 2006

8

Kyan PASCAL Version 1.0

EDITOR AND COMPILER INSTRUCTIONS Kyan PASCAL consists of two programs: the editor program (ED) and the compiler/assembler program (PC). When your Apple1 (ATARI)2 is booted (to boot the ATARI, push the

Subscribe

© Copyright 2013 - 2019 AZDOC.PL All rights reserved.