CORONADO ENTERPRISES MODULA-2 TUTORIAL - Version 1.00 (Generic Version) This documentation and the accompanying software, including all of the example programs and text files, are protected under United States Copyright law to protect them from unauthorized commercialization. This entire tutorial is distributed under the "Freeware" concept which means that you are not required to pay for it. You are permitted to copy the disks in their entirety and pass them on to a friend or acquaintance. In fact, you are encouraged to do so. You are permitted to charge a small fee to cover the mechanical costs of duplication, but the software itself must be distributed free of charge, and in its entirety. If you find the tutorial and the accompanying example programs useful, you may, if you desire, pay a small fee to the author to help compensate him for his time and expense in writing it. A payment of $10.00 is suggested as reasonable and sufficient. If you don't feel the tutorial was worth this amount, please do not make any payment, but feel free to send in the questionnaire anyway. Whether or not you send any payment, feel free to write to Coronado Enterprises and ask for the latest list of available tutorials and a list of the known Public Domain libraries that can supply you with this software for the price of copying. Please enclose a self addressed stamped envelope, business size preferred, for a copy of the latest information. See the accompanying "READ.ME" file on the disk for more information. I have no facilities for telephone support of this tutorial and have no plans to institute such. If you find any problems, or if you have any suggestions, please write to me at the address below. Gordon Dodrill - March 16, 1987 Copyright (c) 1987, Coronado Enterprises Coronado Enterprises 12501 Coronado Ave NE Albuquerque, New Mexico 87122 TABLE OF CONTENTS Introduction to the Modula-2 Tutorial Page 1 FIRSTEX.MOD The first example program Part I - Modula-2 is like Pascal Chapter 1 - What is a computer program? Page 5 Chapter 2 - Getting started in Modula-2 Page 8 PUPPYDOG.MOD The minimum Modula-2 program WRITESM.MOD Write something on the monitor MODCOMS.MOD Modula-2 comments GOODFORM.MOD Good formatting example UGLYFORM.MOD Ugly formatting example Chapter 3 - The simple Modula-2 data types Page 13 INTVAR.MOD Integer variables INTMATH.MOD Integer variable math examples CARDMATH.MOD Cardinal variable math examples REALMATH.MOD Real variable math example BOOLMATH.MOD Boolean variable math example CHARDEMO.MOD Character variable demonstration TRANSFER.MOD Transfer between types Chapter 4 - Modula-2 loops and control structures Page 23 LOOPDEMO.MOD Loop demonstration IFDEMO.MOD Conditional branching LOOPIF.MOD Loops and IF's together TEMPCONV.MOD Temperature conversion DUMBCONV.MOD Poor variable names CASEDEMO.MOD CASE demonstration Chapter 5 - Modula-2 procedures Page 29 PROCED1.MOD Simple procedures PROCED2.MOD Procedures with variables PROCED3.MOD Multiple variables PROCED4.MOD Scope of variables PROCED5.MOD Procedure calling procedures FUNCTION.MOD An example function RECURSON.MOD An example with recursion Chapter 6 - Arrays, types, constants, and labels Page 37 ARRAYS.MOD Simple arrays ARRAYS2.MOD Multiple arrays TYPES.MOD Example of types CONSTANT.MOD Example of constants ARAYPASS.MOD Pass Array to Procedure STRINGEX.MOD String Handling Examples Chapter 7 - Overall Program Construction Page 46 OVERPROG.MOD Overall Program Construction MOREPROG.MOD More Program Construction LASTPROG.MOD Scrambled Order of Definitions Chapter 8 - Input/Output and Printing Page 49 SIMPLOUT.MOD Simple Monitor Output SIMPLIN.MOD Simple Keyboard Input FILEIO.MOD File I/O with InOut VARYFILE.MOD Variable Filename Input PRINTFLE.MOD Printer and File Output Chapter 9 - Example Programs Page 58 TIMEDATE.MOD Time and Date Example AREAS.MOD Calculate Areas PC.MOD Printer Control LIST.MOD List Program File Part II - Advanced Topics Chapter 10 - Scalars, subranges, and sets Page 60 ENTYPES.MOD Enumerated Types SUBRANGE.MOD Subranges SETS.MOD A SET example Chapter 11 - Records Page 65 SMALLREC.MOD A Small Record Example BIGREC.MOD A Larger Record Example VARREC.MOD A Variant Record Example Chapter 12 - Pointers and Dynamic Allocation Page 72 POINTERS.MOD Pointer Example DYNREC.MOD A Dynamically Allocated Record LINKLIST.MOD A linked List Part III - Modula-2 extends Pascal Chapter 13 - Modules, Local and Global Page 81 LOCMOD1.MOD Local Module Demonstration LOCMOD2.MOD Local Module Demonstration CIRCLES.DEF Global Module - Definition CIRCLES.MOD Global Module - Implementation GARDEN.MOD Calls Module "MYCALCUL" PROCTYPE.MOD Procedure Type Example Chapter 14 - Machine Dependent Facilities Page 89 TYPEREL.MOD Type relaxation WORDADDR.MOD WORD and ADDRESS example ADRSTUFF.MOD Address manipulation Chapter 15 - Concurrency Page 94 COROUT.MOD A Simple Coroutine COROUT2.MOD Added Features COROUT3.MOD Triple Coroutines INFINITE.MOD Infinite Execution Loop Chapter 16 - Complete example programs Page 99 BAKLIST.MOD Get All filenames From Disk BAKCOPY.MOD Copy files from Fixed to Floppy BAKRSTR.MOD Read Floppy back to Fixed Disk DIRHELPS.DEF Directory help procedures DIRHELPS.MOD BITOPS.DEF Bit Level Operations BITOPS.MOD REAL2MON.DEF Real outputs to the monitor REAL2MON.MOD REAL2FIL.DEF Real outputs to a file REAL2FIL.MOD