COMAL for the C64
COMAL corner ! : C64 section new at 4 mar 99 - see comal download page! 2/4/00
other sources of COMAL from http://www.macharsoft.demon.co.uk: if you're interested in COMAL on other machines : new at 9th jan 2000
C64_COMAL_DOWNLOAD_INDEX_ PAGE: All the C64 COMAL stuff I've got to hand , mostly in ZIPped LNX format - LYNX17 was used to create the LNX sections which were then PKZIP'd ,some archives are just ZIP'd ,there is a read me text file with info about some of what's available. these files are now on a new server 29/5/01
14 COMAL disks : new at 15/4/99 - see comal download page! 2/4/00
A guide to COMAL _ Roy Burford updated the guide and here's the result !
a guide to COMAL_by brian Grainger _ taken from the pages of ICPUG journal
from TRANSACTOR , vol6 , #3 - 1985Is IOK Enough?
from TRANSACTOR , vol6 , #3 - 1985What is COMAL?
from TRANSACTOR , vol6 , #3 - 1985An Introduction to COMAL: Better than BASIC

 back to the front page

from TRANSACTOR , vol6 , #3 - 1985

What is COMAL?

Micheal . J. Erskine
San Angelo , TX

COMAL stands for COMmon Algorithmic Language. It is a general purpose programming language conceived by two Danes in 1973, Borge Christenson and Benedict Lofstedt. It occurred to these gentlemen there existed a need for a high level, highly structured programming language to introduce non-structured thinkers to structured programming concepts.

Initially COMAL was a simple set of enhancements to BASIC, similar to BASIC 4.0. In the 13 years since its inception the language has evolved with the theory of structured programming. Today COMAL resembles BASIC in that COMAL retains some statements COMmon to many Algorithmic Languages; however COMAL is as different from BASIC as a Porsche is from a Model-T Ford. There was also a time when the only automobile one could own came in BASIC black and it was a very nice automobile. Given the exponential rate of growth of the hardware and software industries, is it really that hard to accept the fact that BASIC has become an antique? Is a Porsche a Model-T? Which would you most prefer to use for transportation?

COMAL is not BASIC, but learning COMAL is easier than learning BASIC, especially for a novice programmer. This is because the language was designed by educators for students of computer programming. Yes it is true that BASIC, among others, was designed under similar circumstances; but BASIC was designed before the surge toward structured programming. Giving BASIC and PASCAL due credit COMAL has retained the best features of both languages and has many new tricks of its own thrown in. We build upon what we already know and add to the store of knowledge through the creative process. This is true in any science and any art.

COMAL is easy to learn even though there are over 100 commands, statements, functions and procedures available in the Kernal definition. All these are machine independent. This means a program written using these Kernal commands will run on any computer running COMAL, just by typing it in! Remember the word, "COMmon"? COMAL is now available for the IBM PC series, in Europe. That's COMmon! Commodore 64's can also run COMAL in 2 versions, a disk loaded COMAL 0.14 and a cartridge COMAL 2.00, that's much more COMmon!

In addition to those 100 or so commands available in the Kernal, the programmer can build PROCedures and FUNCtions which effectively re-define the language. For instance, if you need a FUNCtion to figure the standard deviation of an array containing a set of test scores you can write such a FUNCtion and name it find'std'dev then call it using only its name. The operating system will jump to that FUNCtion and execute it (using the parameters you specify, if you wish) and then return, unless that PROCedure or FUNCtion makes subsequent calls. (more on COMAL names later) The cartridge version also allows calling EXTERNAL PROCedures and FUNCtions from disk, executing them, then continuing execution of the running program which called them. Try that in BASIC. GOSUB was not retained from BASIC, for obvious reasons.

For all you C-64 owners who realise the incredible, however often wasted, power of your VIC 11 and SID chips, the library of graphics and sound FUNCtions and PROCedures available will open a whole new world to you. There are 50 graphics "commands" such as GRAPHICSCREEN used to set hi-res or multicolour graphics and 49 others which control graphics and the TURTLE. "Yes, dear I'm playing with the TURTLE again. I can't help it, this LOGO EMULATOR is fascinating!". There are 32 sprite commands like IDENTIFY, DEFINE, SPRITEPOS (x,y) and the biggie ANIMATE. There are 19 sound commands allowing access to every possibility the SID chip can offer. They make programming a tune as easy as copying sheet music! There is a command for reading the joystick, and one for reading paddles. There are 6 light-pen commands and 7 special font commands which allow definition of a special font and placement of the font anywhere on any screen in any mode. I've a listing of a program about 3k long which plays music, uses 11 different sprites and draws with the TURTLE at the same time. The music is flawless and the little man walks across the screen exactly like a cartoon figure and the program contains NO MACHINE LANGUAGE. COMAL is very fast! It is so fast that I'd venture to suggest it may be possible for a clever programmer to write a procedure which makes the SID chip say "Hi, I'm SID and this is COMAL!" It may not be perfect but I'll bet it's understandable. Sorry, the sound, lightpen, joystick and paddle commands are only available in the cartridge version.

For the particular programmer COMAL offers 4 loop Fstructures:

(1) LOOP, EXIT, ENDLOOP

(2) FOR, ENDFOR

(3) REPEAT, UNTIL and

(4) WHILE, ENDWHILE.

There are two very powerful decision structures:

(1) IF, THEN, ELIF(else if), ELSE, ENDIF and

(2) CASE OF (variable), WHEN, OTHERWISE, ENDCASE.

The language also has built-in error handling routines which allow a programmer to TRAP an ERRor and REPORT it to the user via the ERRTEXT$ (which is defined by the programmer).

The interactive programming facilities are the equal of, per haps better than, any language on any computer anywhere. You can PRINT AT (row,column), # USING or just plain PRINT. When you're not PRINTing you might INPUT AT (row,column ,number of characters) or place the CURSOR (row,column). If you are inputting data from the screen you will be pleased to find you are not able to leave the line or enter more data than specified in the number of characters. PAGE will clear the screen. KEY$ will check to see if a key was pressed and INKEY$ will wait until a key is pressed. If you PRINT SPC$ (8) eight spaces will be printed, but you can also PRINT TAB (8). TAB (8) won't print the spaces but will move the cursor. You can also set the ZONE 8 and use a comma outside of quotes to skip 8 spaces.

If you want to try your hand at writing a data base, you'll find relative file handling greatly simplified when you CREATE ("a relative file", number of records, record length). You might need to APPEND sequential files or DELETE any file also, or you may want to simply MERGE a couple of programs. COMAL provides easy to use facilities for working with up to eight disk units, dual or single. COMAL works with 1541 FLASH!(tm).

You say, "Well, that's all nice but what if I want to twiddle a bit or two?". Where shall I begin? Commodore's Assembler/Editor makes life much easier. After the code is written, just save it to disk and LINK it to your program, then you can SAVE the program and machine code to disk and they will both LOAD as a single module in subsequent LOADs. You can write several machine language routines and LINK them one at a time and they will not overwrite each other. You can twiddle individual bits with BITAND, BITOR, or BITXOR. COMAL can read and write binary, hexadecimal and ASCII files, and you can use any of the three types as constants in a program. It is possible to write machine language routines as PACKAGES (this is how graphics, sound, etc are included) and USE the package. There are people out there right now writing new packages of commands. After USE a package can be DlSCARDed. You can USE more than one PACKAGE at once, subject to memory constraints.

If you do use up all 30K of work space you can inform your system that a PROC or FUNC is EXTERNAL and the operating system will LOAD and EXECute the routine called then return control to the main program carrying any changes or new data along. If that's not enough for your special menu-driven application, you can CHAIN a program from a running menu program and after it has been RUN for you, you can CHAIN back to the menu program.

The operating/programming environment is a real work of art. It includes what can only be called a programmer's word processor. The screen editor provides commands such as FIND "any string" and CHANGE "any string", "to any other string". There are 304 different error messages. Of those 30 are dynamic. This means they will return messages such as "count:unknown variable", "wrong type of:lNPUT", "wrong type of:READ",etc. In other words the error message contains the name of the offending statement in many cases. The cursor is generally placed on the offending item or near it also. The error messages are non-destructive. After you have corrected the offending section the message will disappear and the over written characters will be placed back on the screen!

The function keys are completely programmable using the DEFKEY function and they may programmed for use in direct mode and program mode. They can be easily reprogrammed from within a running program.

When in direct mode or while running a program you can use the 13 CTRL key functions, including such goodies as a true shades of grey graphics screen dump (CTRL D) and a text screen dump (CTRL P).

There is one other thing you should know about COMAL. There are some very serious programmers who are constantly writing and placing in the public domain some very sophisticated programs. COMAL really is the replacement for BASIC, LOGO and a few others. Take control of your C-64 get COMAL. In the opinion of anyone I've ever spoken with who has written in several languages and then tried COMAL, "COMAL does not have a future, COMAL is the future!"

The Use Of Names in COMAL

I've been working in COMAL for about a year now. Happily, I never had a lot of experience with BASIC and therefore I am not having trouble with "BASIC thinking".

I don't presume to be a very good or experienced programmer but I have seen enough programs to express certain feelings about correct habits when programming in COMAL.

The idea behind COMAL is to be able to write programs which describe the solution to the specific problem being solved and reflect the logical procedures (steps) involved in that solution. In the words of Mr. Christensen, "It is a fact not to be over looked that programming languages are not only used to control computing machinery, but also for COMMUNICATION OF IDEAS." This is a very powerful and wonderful concept.

COMAL allows us to use up to 78 characters in a variable, procedure or function name. If we are to communicate ideas we must use words. The more descriptive and specific our names the better the distant reader of our programs will understand them. This is critical to his or her ability to use the program. A COMAL program should be so descriptive when it is read that no further documentation is necessary! Program flow is documented by forced indentation (upon listing), calculations and most tests should be isolated and identified by the use of functions. Procedures should be used whenever a section of code is used more than once.

The names used to describe these procedures, functions and variables should be very descriptive. In a procedure which names all the colours by assigning a numeric value to a name for each colour one should NOT assign variable names like bg: = 3 when he can say bluegreen: = 3. As a consequence of the above naming we would have two possible statements to change the PENCOLOR at some later time in the program, PENCOLOR(bg) and PENCOLOR(bluegreen). Which would you rather have to remember while you were writing the program? Which would you rather read if I had written the program?

In the same line of logic why should I call a procedure to figure the standard deviation of a set of test scores something like "std'dev(tsO)" when I could call it with a statement like "figure'standard'deviation(test'scoresO)"?

The naming facilities available in COMAL are designed by the authors of the language to support the already excellent names of their statements and commands.

The effective COMAL programmer will carefully select the names in order to describe the PROCedure, FUNCtion or variable AND its use in the program.

He will also remember COMAL is NOT BASIC, not even enhanced BASIC. COMAL is COMAL !!! It's just better than anything else. Why try to describe a Porsche in terms of a Model-T?



Cartridge COMAL 2.0

Library Descriptions

Library (page $80, $AS9A-$BFF1):

A5C1 Sense routine

PACKAGE english:

A686 Init routine

PACKAGE dansk:

A68C Init routine

PACKAGE system:

CA2F Init routine
A80B PROC setprinter(str)
A96A PROC hardcopy(str)
A976 PROC setrecorddelay(int)
A97D PROC setpage(int)
A984 FUNC inkey
A9B6 FUNC free
A9C3 PROC keywords in upper case(int)
A9C6 PROC names in upper case(int)
A9C9 PROC quote'mode(int)
A9E1 FUNC currow
A9E9 FUNC curcol
A9F6 PROC textcolors(int,int,int)
AA34 PROC defkey(int,str)
AA7F PROC showkeys
AB21 PROC bell(int)
AB2D PROC serial(int)
A7FF PROC settime(str)
A805 FUNC getime
A878 PROC getscreen(REF str)
A87B PROC setscreen(REFstr)

Library (page $83, $800F-$C000):

8081 Sense routine

PACKAGE graphics:

8CDC Initroutine
95CB PROC window(real,real,real,real)
8F15 PROC viewport(int,int,int,int)
8CA3 PROC drawto(real,real)
8ADA PROC draw(real,real)
8B06 PROC plot(real,real)
8C7C PROC moveto(real,real)
8AE8 PROC move(real,real)
A62A PROC circletreal real real)
A64F PROC arc(real,real,real,real,real)
A564 PROC arcltreal,real)
A55B PROC arcr(real,real)
9426 PROC textstyle(int,int,int ,int)
9157 PROC plottext(real,real,str)
8D9B PROC pencolor(int)
8DBE PROC textcolor(int)
8FC3 FUNC getcolor(real,real)
A37B PROC fill(real,real)
A380 PROC paint(real,real)
9496 PROC background(int )
9483 PROC textbackground(int)
950B PROC border(int)
951E PROC textborder(int)
8E2A PROC graphicscreen(int)
90FC PROC textscreen
A25D PROC splitscreen
A258 PROC fullscreen
88FA PROC clearscreen
895E PROC clear
A23B PROC showturtle
A248 PROC hideturtle
A20F PROC turtlesize(real)
90A9 FUNC xcor
90D6 FUNC ycor
8CA3 PROC setxy(real real)
904D PROC setheading(real)
9094 FUNC heading
903F PROC left(real)
903C PROC right(real)
901A PROC forward(real)
9017 PROC back(real)
9536 PROC penup
9542 PROC pendown
954E PROC home
9576 PROC wrap
9584 PROC nowrap
A8D7 FUNC inq(int)
AFD7 PROC savescreen(str)
B027 PROC loadscreen(str)
ADF4 PROC printscreen(str,int)

PACKAGE turtle:

8CE2 Init routine
9017 PROC bk(real)
9496 PROC bg(int)
88FA PROC cs
901A PROC fd(real)
A248 PROC ht
903F PROC It(real)
8D9B PROC pc(int)
9542 PROC pd
9536 PROC pu
903C PROC rt(real)
904D PROC seth(real)
A23B PROC st
9483 PROC textbg(int)
95CB PROC window(real,real,real,real)
8F15 PROC viewport(int,int,int,int)
8CA3 PROC drawto(real,real)
8ADA PROC draw(real,real)
8B06 PROC plot(real,real)
8C7C PROC moveto(real,real)
8AE8 PROC move(real,real)
A62A PROC circle(real,real,real)
A64F PROC arc(real,real,real,real,real)
AS64 PROC arcl(real,real)
ASSB PROC arcr(real,real)
9426 PROC textstyle(int,int,int,int)
9157 PROC plottext(real,real,str)
8D9B PROC pencolor(int)
8DBE PROC textcolor(int)
8FC3 FUNC getcolor(real,real)
A37B PROC fill(real,real)
A380 PROC paint(real,real)
9496 PROC background(int)
9483 PROC textbackground(int)
950B PROC border(int)
951E PROC textborder(int)
8E2A PROC graphicscreen(int)
90FC PROC textscreen
A25D PROC splitscreen
A258 PROC fullscreen
88FA PROC clearscreen
895E PROC clear
A23B PROC showturtle
A248 PROC hideturtle
A20F PROC turtlesize(real)
90A9 FUNC xcor
90D6 FUNC ycor
8CA3 PROC setxy(real,real)
904D PROC setheading(real)
9094 FUNC heading
903F PROC left(real)
903C PROC right(real)
901A PROC forward(real)
9017 PROC back(real)
9536 PROC penup
9542 PROC pendown
954E PROC home
9576 PROC wrap
9584 PROC nowrap
A8D7 FUNC inq(int)
AFD7 PROC savescreen(str)
B027 PROC loadscreen(str)
ADF4 PROC printscreen(str,int)

PACKAGE sprites:

98B9 Init routine
9979 PROC define(int,str)
9BOD PROC identify(int,int)
99AC PROC spritecolor(int,int)
99BB PROC spritepos(int,int,int)
9A4A PROC spritesize(int,int,int)
9B46 PROC showsprite(int)
9B52 PROC hidesprite(int)
9A83 PROC spriteback(int,int)
9A93 FUNC spritecollision(int,int)
9A96 FUNC datacollision(int,int)
9ABF PROC priority(int,int)
ABS4 PROC linkshape(int)
AB5A PROC loadshape(int,str)
AB6E PROC saveshape(int,str)
9B6F PROC movesprite(int,int,int,int,int)
9A11 PROC stopsprite(int)
9DFC PROC animate(int,str)
9D13 FUNC moving(int)
9DIF PROC startsprites
9CEB FUNC spritex(int)
9CFF FUNC spritey(int)
9D3F FUNC spriteinq(int,int)
9ECD PROC stampsprite(int)

PACKAGE font:
CA2F Init routine
ABD0 PROC linkfont
ABDF PROC loadfont(str)
AC49 PROC keepfont
ABFI PROC savefont(str)
AC57 PROC getcharacter(int,int REF str)
AC87 PROC putcharacter(int,ini,str)

PACKAGE sound:
B287 Init routine
B2FE PROC note(int,str)
B3DE PROC pulse(int,int)
B3FA PROC gate(int,int)
B412 PROC soundtype(int,int)
B436 PROC ringmod(int,int)
B455 PROC sync(int,int)
B474 PROC adsr(int,int,int,int,int)
B4AD PROC filterfreq(int)
B4CD PROC resonance(int)
B4E6 PROC filter(int,int,int,int)
B508 PROC filtertype(int,int,int,int)
B52C PROC volume(int)
B543 FUNC env3
B549 FUNC osc3
B54F FUNC frequeny(str)
B55B PROC setscore(int,REFint(),REF int(),REF int())
B59F PROC playscore(int,int,int)
B5CD PROC stopplay(int int,int)
B5FC FUNC waitscore(int,int,int)
B2E3 PROC setfrequeny(int,real)

PACKAGE paddles:

CA2F Init routine
B62C PROC paddle(int REF real REF real,REF real,REF real)

PACKAGE Joysticks:

CA2F Init routine
B6B9 PROC joystick(int REF real,REF real)

PACKAGE lightpen:

B77D Init routine
B7FA PROC offset(int,int)
B7DI FUNC penon
B79B PROC readpen(REF real,REF real,REF real)
B820 PROC timeon(int)
B82A PROC delay(int)
B80D PROC accuracy(int,int)