Showing posts with label Atari Pascal Language System. Show all posts
Showing posts with label Atari Pascal Language System. Show all posts

Saturday, March 16, 2019

STRARRAY

Table of Contents ] [ List of Example Programs ] [ STRARRAY Disk Image ]

STRARRAY is an example program (Listing 10-2) from page 148 of the book "Pascal Primer" by David Fox and Mitchell Waite.

This example shows how to use arrays of STRING variables. When the program runs, it accepts five strings from the user, then displays the entered strings in the reverse order that they were entered as well as the individual strings in reverse order.


The link command looks like:

LINKER V1.0
*D2:STRARRAY,PASLIB/S

When you run the program, it looks like:


Friday, March 15, 2019

INTCONST

Table of Contents ] [ List of Example Programs ] [ INTCONST Disk Image ]

INTCONST is an example program (Listing 9-9) from page 122 of the book "Pascal Primer" by David Fox and Mitchell Waite.

The program takes an INTEGER and attempts to convert it to a STRING. It is the opposite of the VALDEMO example program. It doesn't take any input from the user. It uses the predefined value MAXINT (32767) and converts it to a STRING. This program makes use of the string INSERT procedure. It also uses the ABS function. Since the Atari Pascal built-in ABS() function is buggy, I overrode it with my own simple ABS() function.


The link command looks like:

LINKER V1.0
*D2:INTCONST,PASLIB/S

When you run the program, it looks like:



Thursday, March 14, 2019

VALDEMO

Table of Contents ] [ List of Example Programs ] [ VALDEMO Disk Image ]

VALDEMO is an example program (Listing 9-8) beginning on page 120 of the book "Pascal Primer" by David Fox and Mitchell Waite.

It takes a number as a STRING as input, tests it, and tries to convert it to an INTEGER. 

I ran into a bug with the intrinsic absolute value function ABS() built into the Atari Pascal Language System. After some testing, I wrote my own quick and dirty ABS() function to override the existing buggy one.



The link command looks like:

LINKER V1.0
*D2:VALDEMO,GRSND,PASLIB/S

When you run the program, it looks like:



Wednesday, March 13, 2019

BUG: ABS()

Table of Contents ] [ List of Example Programs ] [ TESTABS Disk Image ]

I was attempting to test an example program that uses the intrinsic ABS() function built into the Atari Pascal Language System. The function doesn't seem to give the correct results.

Here is a simple test program TESTABS.



Given the integer number -151, I'd expect the ABS() function to return an integer value of 151. But it returns 32617.



My own quick and dirty (with no error or range checking) ABS2() function returns what I expected.

I tried passing the ABS() function a negative number < -128. Still, the result is incorrect.

I tried passing the ABS() function a REAL number, but the compiler choked on that, so I commented it out.

I'm not sure if this is a bug or an overflow issue. I need to double check the documentation and do some more testing with this function.

SPACEOUT

Table of Contents ] [ List of Example Programs ] [ SPACEOUT Disk Image ]

SPACEOUT is an example program (Listing 9-6) on page 117 of the book "Pascal Primer" by David Fox and Mitchell Waite.

This example program shows how to use intrinsic Pascal STRING functions and procedures. The LENGTH() function returns the number of characters in a string. The INSERT() procedure will insert a string into another string.


The link command looks like:

LINKER V1.0
*D2:SPACEOUT,PASLIB/S

When you run the program, it looks like:



NOSPACE

Table of Contents ] [ List of Example Programs ] [ NOSPACE Disk Image ]

NOSPACE is an example program (Listing 9-4) on page 116 of the book "Pascal Primer" by David Fox and Mitchell Waite.

This example program shows how to use intrinsic Pascal STRING functions and procedures. The POS() function will return the starting position of a string within a string. The DELETE() procedure will remove a string from within a string. The LENGTH() function returns the number of characters in a string.



The link command looks like:

LINKER V1.0
*D2:NOSPACE,PASLIB/S

When you run the program, it looks like:


Tuesday, March 12, 2019

CENTERDM

Table of Contents ] [ List of Example Programs ] [ CENTERDM Disk Image ]

CENTERDM is an example program (Listing 9-2) on page 113 of the book "Pascal Primer" by David Fox and Mitchell Waite.

The example shows how to use a standard Pascal string processing procedure or function, specifically, the LENGTH() function, with returns an INTEGER that represents the length or number of characters in a string. It will center text on the screen. I modified this Atari Pascal version to use a screen size of 38 rather than 40 do to the default 2 space indentation.


While we include a reference to the STRPROCS INCLUDE FILE the source code file, it doesn't need to be included in the linker command.

The link command looks like:

LINKER V1.0
*D2:CENTERDM,PASLIB/S

When you run the program, it looks like:


BKWDWRIT

Table of Contents ] [ List of Example Programs ] [ BKWDWRIT Disk Image ]

BKWDWRIT is an example program (Listing 9-1) on page 112 of the book "Pascal Primer" by David Fox and Mitchell Waite.

The example shows how to use a standard Pascal string processing procedure or function, specifically, the LENGTH() function, with returns an INTEGER that represents the length or number of characters in a string.


While we include a reference to the STRPROCS INCLUDE FILE the source code file, it doesn't need to be included in the linker command.

The link command looks like:

LINKER V1.0
*D2:BKWDWRIT,PASLIB/S

When you run the program, it looks like:


LOAN3

Table of Contents ] [ List of Example Programs ] [ LOAN3 Disk Image ]

LOAN3 is an example program (Listing 8-9) that begins on page 106 of the book "Pascal Primer" by David Fox and Mitchell Waite.

This example updates the existing loan examples (LOAN1 and LOAN2) to use a function instead of a procedure call to implement a Power function that will raises X^Y. It handles Y values that are positive, negative, or zero.



The link command looks like:

LINKER V1.0
*D2:LOAN3,FPLIB,PASLIB/S

When you run the program, it looks like:




Back to List Of Example Programs

Back to Table Of Contents

EMPTYBOX

Table of Contents ] [ List of Example Programs ] [ EMPTYBOX Disk Image ]

EMPTYBOX is an example program (Listing 8-5) that appears on page 101 of the book "Pascal Primer" by David Fox and Mitchell Waite.

The program demonstrates how to pass an empty, unassigned pass-by-variable parameter (VAR Result:REAL) to a procedure, which will then populate the parameter and return a value back to the calling procedure.


The link command looks like:

LINKER V1.0
*D2:EMPTYBOX,FPLIB,PASLIB/S

When you run the program, it looks like:

Monday, March 11, 2019

TWOWAYC

Table of Contents ] [ List of Example Programs ] [ TWOWAYC Disk Image ]

TWOWAYC is an example program (Listing 8-4) that appears on page 100 of the book "Pascal Primer" by David Fox and Mitchell Waite. It demonstrates passing a pass-by-address parameter that can be modified in the called procedure.


The link command looks like:

LINKER V1.0
*D2:TWOWAYC,PASLIB/S

When you run the program, it looks like:






Back to List Of Example Programs

Back to Table Of Contents

PARAMDM3

Table of Contents ] [ List of Example Programs ] [ PARAMDM3 Disk Image ]

PARAMDM3 is an example program (Listing 8-3) that appears on page 98 of the book "Pascal Primer" by David Fox and Mitchell Waite. It demonstrates passing multiple  pass-by-value parameters during a procedure call.

It also shows that you can have two different variables with the same name. There is a global Number variable in the main program and a local Number variable in the the RepeatPhrase procedure.

It is very similar to the PARAMDM1  and the PARAMDM2 example programs.



The link command looks like:

LINKER V1.0
*D2:PARAMDM3,PASLIB/S

When you run the program, it looks like:


PARAMDM2

Table of Contents ] [ List of Example Programs ] [ PARAMDM2 Disk Image ]

PARAMDM2 is an example program (Listing 8-2) that appears on page 97 of the book "Pascal Primer" by David Fox and Mitchell Waite. It demonstrates parameter passing during a procedure call and that the passed parameter doesn't change in the calling procedure even if it was changed in the called procedure.

It is not that much different from the PARAMDM1 example program except for some testing code.


The link command looks like:

LINKER V1.0
*D2:PARAMDM2,PASLIB/S

When you run the program, it looks like:



PARAMDM1

Table of Contents ] [ List of Example Programs ] [PARAMDM1 Disk Image ]

PARAMDM1 is an example program (Listing 8-1) that appears on page 96 of the book "Pascal Primer" by David Fox and Mitchell Waite. It demonstrates parameter passing during a procedure call.


The link command looks like:

LINKER V1.0
*D2:PARAMDM1,PASLIB/S

When you run the program, it looks like:


CASEDMO3

Table of Contents ] [ List of Example Programs ] [ CASEDMO3 Disk Image ]

CASEDMO3 is another short example program (Listing 7-7) that appears on page 93 of the book "Pascal Primer" by David Fox and Mitchell Waite. It demonstrates the use of a CASE statement with an BOOLEAN variable.

This example program also uses a standard function ODD().


I ran into an issue when testing this example. The standard ODD function seems to work correctly, but it appears that using a BOOLEAN with a CASE doesn't seem to work in the Atari Pascal Language System. The manual appears to state that only non-real, short, scalar, or constants can be used with a CASE statement.

I'd suggest just using and IF-THEN-ELSE statement instead of a CASE statement when it comes to using BOOLEAN variables.

I added a couple of extra WRITELNs for debugging proposes.

The link command looks like:

LINKER V1.0
*D2:CASEDMO3,PASLIB/S

When you run the program, it looks like:



CASEDMO2

Table of Contents ] [ List of Example Programs ] [ CASEDMO2 Disk Image ]

CASEDMO2 is another short example program (Listing 7-6) that appears on page 92 of the book "Pascal Primer" by David Fox and Mitchell Waite. It demonstrates the use of a CASE statement with an INTEGER variable.


Note that while not used in this example, the Atari Pascal Language System has extended the CASE statement by adding an ELSE clause. If the case selecting expression would not result in the execution of a statement with the CASE, the ELSE clause is executed. ELSE simplifies error checking. It is likely that the execution of a similar unmatched CASE statement in UCSD Pascal would cause an undefined result.   

The link command looks like:

LINKER V1.0
*D2:CASEDMO2,PASLIB/S


When you run the program, it looks like:



Sunday, March 10, 2019

CASEDMO1

Table of Contents ] [ List of Example Programs ] [ CASEDMO1 Disk Image ]

CASEDMO1 is a short example program (Listing 7-5) that appears on page 92 of the book "Pascal Primer" by David Fox and Mitchell Waite. It demonstrates the use of a CASE statement with a CHAR variable.


The link command looks like:

LINKER V1.0
*D2:CASEDMO1,D2:PEEKPOKE,GRSND,PASLIB/S

When you run the program, it looks like:



Press the (lower case) keyboard key for the first letter in the word from the list. The program responds with an appropriate response.

What starts out as a simple CASE statement example becomes a little more complicated in the Atari Pascal Language System, do to the "READ CHAR" bug and other idiosyncrasies.

The bug handling code is expecting the user input to be in lower case.

ADVANCES

Table of Contents ] [ List of Example Programs ] [ ADVANCES Disk Image ]

ADVANCES is an example program (Listing 6-3) that begins on page 76 of the book "Pascal Primer" by David Fox and Mitchell Waite. The comments section of the program state that this example program was created by Annie Fox with Pascal programming by David Fox.

This program shows the use of the IF-THEN-ELSE statement.

While this is a rather short program, it reminds me a bit of the programs ELIZA and ABUSE by Don't Ask Computer Software, which simulate conversations.



The link command looks like:

LINKER V1.0
*D2:ADVANCES,PASLIB/S

When you run the program, it looks like:





Back to List Of Example Programs

Back to Table Of Contents

Saturday, March 9, 2019

METRIC2

Table of Contents ] [ List of Example Programs ] [ METRIC2 Disk Image ]

METRIC2 is a Pascal program (Listing 7-4) that appears on page 89 of the book, Pascal Primer, by David Fox and Mitchell Waite. This program has a menu with four options. One option is for exiting the program. The other three options are for performing various conversions from USCS (United States Customary System) to Metric. This program is very similar to METRIC1 from the same book, but it wraps the main program in a REPEAT/UNTIL loop and it adds some error checking around the menu menu item selection.



As with the other samples from this book, all of the programs were originally written for UCSD Pascal on the Apple II platform.

While I was working on porting this program from the Apple II UCSD Pascal version to the Atari Pascal Language System, I got tired of some of the minor annoyances with AtariWriter 80 running under the Altirra emulator. I'm not sure if the issues that I was seeing are with AtariWriter 80 itself, or because I'm using it with Altirra. I decided to switch to a different editor. The editor I chose to use was The Last Word, specifically The Last Word 3.21b.


Along with switching editors, I had to deal with working around the Atari Pascal Language System "READ CHAR" bug.



In addition, the METRIC2 program listing (7-4) as printed on page 89 of the book has a bug. This version of the program declares a global CONST variable type named Conversions. Later in the program, a variable named Conversion is referenced. I renamed the declared variable to Conversion. This may not have been a problem in UCSD Pascal if only the first eight characters are recognized as significant.



 The link command looks like:

LINKER V1.0
*D2:METRIC2,D2:PEEKPOKE,FPLIB,GRSND,PASLIB/S

When you run the program, it looks like:


Friday, March 8, 2019

METRIC1

Table of Contents ] [ List of Example Programs ] [ METRIC1 Disk Image ]

METRIC1 is a Pascal program that begins on page 80 of the book, Pascal Primer, by David Fox and Mitchell Waite. This program has a menu with four options. One option is for exiting the program. The other three options are for performing various conversions from USCS (United States Customary System) to Metric.



As with the other samples from this book, all of the programs were originally written for UCSD Pascal on the Apple II platform.

This is a nice sized program with multiple procedures and a menu to select from.

I ran into into a serious issue when porting this program to the Atari Pascal Language System. If you haven't already done so, please read about the READ CHAR BUG to see why I made some changes to this program.

The Atari Pascal Language System version of the program was created in an Altirra emulator-based Development Environment using the AtariWriter 80 word processor as the source code editor.


The link command looks like:

LINKER V1.0
*D2:METRIC1,D2:PEEKPOKE,FPLIB,GRSND,PASLIB/S

When you run the program, it looks like: