apple iigs programming (k fest)

33
An Introduction to An Introduction to Apple Apple IIgs IIgs Programming Programming in a High Level in a High Level Language Language by by Mike Stephens Mike Stephens First Presented at First Presented at Mt Keira Fest 2009 Mt Keira Fest 2009

Upload: polymorph

Post on 21-Jun-2015

1.753 views

Category:

Technology


0 download

DESCRIPTION

My presentation on "An Introduction to Apple IIgs Programming in a High Level Language" presented at Mt Keira Fest 2009.

TRANSCRIPT

Page 1: Apple IIgs Programming (K Fest)

An Introduction toAn Introduction toApple Apple IIgsIIgs Programming Programming

in a High Level in a High Level LanguageLanguage

bybyMike StephensMike Stephens

First Presented atFirst Presented atMt Keira Fest 2009Mt Keira Fest 2009

Page 2: Apple IIgs Programming (K Fest)

Topics To CoverTopics To Cover

What programming languages are available?What programming languages are available? An overview of Complete PascalAn overview of Complete Pascal A quick introduction to PascalA quick introduction to Pascal Your very first program!Your very first program! Introducing the ToolboxIntroducing the Toolbox Using the ToolboxUsing the Toolbox

Page 3: Apple IIgs Programming (K Fest)

What programming languages are What programming languages are available?available?

Page 4: Apple IIgs Programming (K Fest)

BASIC ProgrammingBASIC Programming

ApplesoftApplesoft BASIC with Toolbox extensions BASIC with Toolbox extensions (Interpreted)(Interpreted)

TML BASICTML BASIC MicolMicol Advanced BASICAdvanced BASIC GSoftGSoft BASIC (Interpreted)BASIC (Interpreted)

Page 5: Apple IIgs Programming (K Fest)

ORCA LanguagesORCA Languages

ORCA/Integer BASICORCA/Integer BASIC ORCA/PascalORCA/Pascal ORCA/CORCA/C ORCA/ModulaORCA/Modula--22

Page 6: Apple IIgs Programming (K Fest)

Complete PascalComplete Pascal

My recommendation for anyone wanting to getMy recommendation for anyone wanting to getstarted with high level language programming onstarted with high level language programming onthe Apple the Apple IIgsIIgs isis……..

You guessed it!You guessed it!

Complete Pascal.Complete Pascal.

Page 7: Apple IIgs Programming (K Fest)

An overview of Complete PascalAn overview of Complete Pascal

Page 8: Apple IIgs Programming (K Fest)

Complete PascalComplete Pascal

Positives:Positives: Is freely availableIs freely available Is a compiled languageIs a compiled language Has full access to the Apple Has full access to the Apple IIgsIIgs ToolboxToolbox Has an uncomplicated and easy to learn Has an uncomplicated and easy to learn

development environmentdevelopment environment Has some nice extensions to PascalHas some nice extensions to Pascal

Page 9: Apple IIgs Programming (K Fest)

Complete PascalComplete Pascal

Negatives:Negatives: Has some bugs in the GUI resource editorHas some bugs in the GUI resource editor Produces larger & less efficient compiled code Produces larger & less efficient compiled code

(as compared to ORCA/Pascal)(as compared to ORCA/Pascal) Can not link to assembly code (however, inline Can not link to assembly code (however, inline

assembly code is possible)assembly code is possible) No debuggerNo debugger

Page 10: Apple IIgs Programming (K Fest)

A quick introduction to PascalA quick introduction to Pascal

Page 11: Apple IIgs Programming (K Fest)

Pascal Overview (continued)Pascal Overview (continued)

In Complete Pascal, comments start with In Complete Pascal, comments start with aa (*(* and end with aand end with a *) OR *) OR comments may start comments may start with a with a {{ and end with a and end with a }} ..

Examples of comments:Examples of comments: (* this is a comment *)(* this is a comment *) { so is this! }{ so is this! }

Page 12: Apple IIgs Programming (K Fest)

Pascal OverviewPascal Overview

The basic structure of a Pascal program is:The basic structure of a Pascal program is:PROGRAMPROGRAM ProgramNameProgramName ((FileListFileList));;

CONSTCONST(* Constant declarations *)(* Constant declarations *)

TYPETYPE(* Type declarations *)(* Type declarations *)

VARVAR(* Variable declarations *)(* Variable declarations *)

(* Subprogram definitions *)(* Subprogram definitions *)

BEGINBEGIN(* Executable statements *)(* Executable statements *)

END.END.

Page 13: Apple IIgs Programming (K Fest)

Pascal Overview (continued)Pascal Overview (continued)

Rules for identifiers:Rules for identifiers: Must begin with a letter from the English alphabet.Must begin with a letter from the English alphabet. Can be followed by alphanumeric characters (alphabetic Can be followed by alphanumeric characters (alphabetic

characters and numerals) and possibly the underscore (_).characters and numerals) and possibly the underscore (_). May not contain certain special characters, many of which May not contain certain special characters, many of which

have special meanings in Pascal.have special meanings in Pascal.~ ! @ # $ % ^ & * ( ) + ` ~ ! @ # $ % ^ & * ( ) + ` -- = { } [ ] : = { } [ ] : " ; ' < > ? , . / |" ; ' < > ? , . / |

May be any of the reserved words (see the TML Pascal II May be any of the reserved words (see the TML Pascal II manual for details).manual for details).

Page 14: Apple IIgs Programming (K Fest)

Pascal Overview (continued)Pascal Overview (continued)

Pascal isPascal is notnot case sensitive!case sensitive! MyProgramMyProgram,, MYPROGRAM, MYPROGRAM,

andand mYpRoGrAmmYpRoGrAm are all equivalent. are all equivalent.

For readability purposes, it is a good idea to use For readability purposes, it is a good idea to use meaningful capitalization.meaningful capitalization.

An identifier can be any length so long as it can fit on one line, however, in Complete Pascal only the first 255 characters are significant.

Page 15: Apple IIgs Programming (K Fest)

Pascal Array TypesPascal Array Types

An array type defines a structure that has a set number of components, and all of the components are of the same type.

Array types in Pascal take the form:Array types in Pascal take the form:

ARRAY[ <INDEX TYPE> ] OF <COMPONENT TYPE>

For example, an array of 100 real numbers:

array[1..100] of real

Page 16: Apple IIgs Programming (K Fest)

Pascal Record TypesPascal Record Types

A record type consists of a specified collection of components called fields, each one capable of being a different type. Each field of a record type must specify its type, and the name of its identifier. For example:

recordyear: integer;month: 1..12;day: 1..31;

end

Page 17: Apple IIgs Programming (K Fest)

Complete Pascal StringsComplete Pascal Strings

A string type is a succession of characters having a dynamic A string type is a succession of characters having a dynamic length attribute and a constant dimension attribute of 1 to 255.length attribute and a constant dimension attribute of 1 to 255.

The current value of the length attribute for a string type is The current value of the length attribute for a string type is returned by the standard function returned by the standard function lengthlength..

A null string is a string type value that has a dynamic length oA null string is a string type value that has a dynamic length of f zero.zero.

For example:For example:

varvarmyStringmyString : string;: string;myLengthmyLength : Integer;: Integer;

myStringmyString := := ‘‘Hello Mt Keira Fest!Hello Mt Keira Fest!’’;;myLengthmyLength := := Length(myStringLength(myString); { ); { myLengthmyLength equals 20 }equals 20 }

Page 18: Apple IIgs Programming (K Fest)

Pascal AssignmentPascal Assignment

Once you have declared a variable, you can store Once you have declared a variable, you can store values in it. This is calledvalues in it. This is called assignmentassignment..

To assign a value to a variable, follow this To assign a value to a variable, follow this syntax:syntax:

variable_namevariable_name :=:= expressionexpression;;

For example:For example:

myFloatmyFloat := 10.559;:= 10.559;

Page 19: Apple IIgs Programming (K Fest)

Pascal Relational OperatorsPascal Relational Operators

The operand types and the corresponding results for The operand types and the corresponding results for Relational operations are shown in the following table: Relational operations are shown in the following table:

Not equal toNot equal to<><>Greater than or equal toGreater than or equal to>=>=Less than or equal toLess than or equal to<=<=Equal toEqual to==Greater thanGreater than>>Less thanLess than<<MeaningOperator

Page 20: Apple IIgs Programming (K Fest)

Complete Pascal Control StatementsComplete Pascal Control Statements

The GOTO statement will pass control to another part The GOTO statement will pass control to another part of the program located in the same block.of the program located in the same block.

The CYCLE statement forces a repetition statement to The CYCLE statement forces a repetition statement to immediately execute the next iteration of a loop.immediately execute the next iteration of a loop.

The LEAVE statement forces the immediate exit from The LEAVE statement forces the immediate exit from a repetition statement loop.a repetition statement loop.

The HALT statement will stop the execution of the The HALT statement will stop the execution of the program immediately. program immediately.

Page 21: Apple IIgs Programming (K Fest)

Pascal ProceduresPascal Procedures

A procedure declaration associates an identifier with a block ofA procedure declaration associates an identifier with a block ofstatements.statements.

A procedure is called by using the procedure identifier and the A procedure is called by using the procedure identifier and the current parameters required by it.current parameters required by it.

An example of a procedure declaration:An example of a procedure declaration:

procedure Num2String (N: integer; procedure Num2String (N: integer; varvar S: string);S: string);varvar V: integer;V: integer;beginbegin

V := V := Abs(NAbs(N););S:='';S:='';repeatrepeat

S:= S:= concat(Chr(Vconcat(Chr(V mod 10 + ord('0')),S);mod 10 + ord('0')),S);V:= V div 10;V:= V div 10;

until V = 0;until V = 0;if V<0 then S := if V<0 then S := ConcatConcat(('(('--',S);',S);

end;end;

Page 22: Apple IIgs Programming (K Fest)

Pascal FunctionsPascal Functions

A function declaration associates an identifier with a block of A function declaration associates an identifier with a block of statements, able statements, able to be called in order to calculate and return a value of the speto be called in order to calculate and return a value of the specified type. cified type.

An example of a function declaration:An example of a function declaration:

function Num2String(N: integer;) : string;function Num2String(N: integer;) : string;varvar V: integer;V: integer;S: string;S: string;beginbegin

V := V := Abs(NAbs(N):):S := '';S := '';repeatrepeat

S := S := concat(Chr(Vconcat(Chr(V mod 10 + ord('0')),S);mod 10 + ord('0')),S);V := V div 10;V := V div 10;

until V = 0;until V = 0;if V<0 then S := if V<0 then S := concatconcat('('--',S);',S);Num2String := S;Num2String := S;

end;end;

Page 23: Apple IIgs Programming (K Fest)

Pascal UnitsPascal Units

Complete Pascal supports the use of Units, Complete Pascal supports the use of Units, which are stand alone modules (or libraries) which are stand alone modules (or libraries) which may define any number of procedures which may define any number of procedures and functions.and functions.

Units are compiled separately.Units are compiled separately. Units are made accessible to a main program or Units are made accessible to a main program or

to other Units via the USES clause.to other Units via the USES clause.

Page 24: Apple IIgs Programming (K Fest)

Your very first program!Your very first program!

Page 25: Apple IIgs Programming (K Fest)

Hello Mt Keira Fest!Hello Mt Keira Fest!

Open Complete Pascal and select Open Complete Pascal and select FileFileNewNewfrom the menu.from the menu.

In the In the Create FileCreate File box, type box, type HelloKFest.pHelloKFest.p and and click click NewNew..

You will then be presented with a new window You will then be presented with a new window in which to type your first Complete Pascal in which to type your first Complete Pascal program.program.

Page 26: Apple IIgs Programming (K Fest)

Hello Mt Keira Fest! (continued)Hello Mt Keira Fest! (continued)

Type in the following:Type in the following:

Program Program HelloKFestHelloKFest;;

beginbegin

writeln(writeln(‘‘HelloHello (Mt) (Mt) K(eira)FestK(eira)Fest!!!!’’););

readlnreadln;;

end.end.

Page 27: Apple IIgs Programming (K Fest)

Compile Your CodeCompile Your Code

You can check the syntax of your code without You can check the syntax of your code without compiling it by clicking compiling it by clicking CompileCompileCheckCheck SyntaxSyntax, , however, most times you will probably just want however, most times you will probably just want to compile to disk by clicking to compile to disk by clicking CompileCompileToTo DiskDisk..

If everything went smoothly, you should have If everything went smoothly, you should have just created your first Complete Pascal textbook just created your first Complete Pascal textbook application!application!

Page 28: Apple IIgs Programming (K Fest)

Running Your ProgramRunning Your Program

You can execute your program by:You can execute your program by: Exiting Complete Pascal and running your program Exiting Complete Pascal and running your program

from the Finder; orfrom the Finder; or From within Complete Pascal click From within Complete Pascal click GSOSGSOSTransferTransfer

and select your and select your HELLOKFESTHELLOKFEST application and application and click click TransferTransfer..

Page 29: Apple IIgs Programming (K Fest)

Introducing the ToolboxIntroducing the Toolbox

Page 30: Apple IIgs Programming (K Fest)

The Apple The Apple IIgsIIgs ToolboxToolbox

The Apple The Apple IIgsIIgs Toolbox is comprised of a number of Toolbox is comprised of a number of specialised tool sets.specialised tool sets.

Each tool set is made up of a number of routines that Each tool set is made up of a number of routines that you can use from within your own programs.you can use from within your own programs.

The Toolbox routines are designed to hide the The Toolbox routines are designed to hide the complexity of dealing with the complexity of dealing with the IIgsIIgs hardware.hardware.

To become really familiar with the Apple To become really familiar with the Apple IIgsIIgs Toolbox, Toolbox, you need to have the 3 Toolbox reference manuals + you need to have the 3 Toolbox reference manuals + the GS/OS manual.the GS/OS manual.

Page 31: Apple IIgs Programming (K Fest)

What Do the Toolsets Provide?What Do the Toolsets Provide?

QuickdrawQuickdraw II II -- Graphics routinesGraphics routines Memory Manager Memory Manager –– allocating/allocating/deallocatingdeallocating

memorymemory Sound Toolset Sound Toolset –– load and play digitized soundsload and play digitized sounds SANE SANE –– floating point routinesfloating point routines Window Manager Window Manager –– create & handle windowscreate & handle windows Event Manager Event Manager –– handle system eventshandle system events Plus more!Plus more!

Page 32: Apple IIgs Programming (K Fest)

Using the ToolboxUsing the Toolbox

Page 33: Apple IIgs Programming (K Fest)

Complete Pascal & the ToolboxComplete Pascal & the Toolbox

Complete Pascal comes complete with interface Complete Pascal comes complete with interface files necessary to hook directly into the Toolbox files necessary to hook directly into the Toolbox routinesroutines

As a rule of thumb, each tool set is defined as a As a rule of thumb, each tool set is defined as a Unit, which you can use from your Unit, which you can use from your programs/units by adding the appropriate tool programs/units by adding the appropriate tool set interface file to the USES clause.set interface file to the USES clause.