TML Pascal Tricks
 Volume Number: 6 Issue Number: 3 Column Tag: Pascal Procedures

# TML Pascal Tricks

By Paul Diegenbach, Amsterdam, the Netherlands

## XCMD - drawing in a Hypercard stack

The attractiveness of Hypercard is for a large part due to it graphical possibilities. Nice cards always mean nice graphics. The Hypertalk language allows drawing on the screen under program control. When we tear the tools menu off the menubar, we can actually see the actions as the tools flop from pen to brush to marquee and so on. Nice to watch, but oh so slow. Ever tried to draw a complicated graph in Hypercard? I tried it in an attempt to simulate the differentiation of an egg to all the different cells an embryo consists of. One of the theories implies the evaluation of some differential equations and then drawing a thousand points on the screen.

The idea was to let students be able to change the parameters in the equations and see the results in a user-friendly environment. The first step was to implement the equation solving in Hypertalk. Too slow, so an XCMD was quickly written. Drawing the results by Hypertalk: still to slow, so why not do the drawing in the XCMD as well? In a first result the drawing looks nice, but as soon as Hypercard updates the screen from its offscreen bitmap, the drawing disappears. The solution to this problem is to copy the drawing in the paste buffer (scrap) and paste it into Hypercard using the paste command from the menu. This combination works fine and quick. The skeleton for the XCMD is given below, in TML-Pascal, with a Fourier-demo in the drawing part to make it less dumb. In this demo we use parameters from Hypercard for the size of the rectangle and for the Fourier coefficients. Although not necessary, it is often handy to give the rectangle parameters. They can easily be estimated by having a temporary field of the same size and asking in the message window ‘put the size of card field tmp into msg’. The Hypercard stack with this demo implemented is on the source disk for this month.

To avoid flicker between the copy and paste, it is convenient to lock the screen before the XCMD is used. Users of other Pascals sometimes need to remove the ParamPtr parameter, that is the first parameter in every call to the glue routines:

```{1}

UNIT PictToScrp;
(******************************************************
This XCMD demodnstrates a method to plot and calculate in Pascal (perhaps
with floating point processor enabled) and then copy and paste the picture
in the card compile and link as follows (assuming Fourier is an existing
stack):

TMLPascal Fourier.p
or:  ( really fast on a mac II)
TMLPascal Fourier.p  -MC68020 -MC68881 -d Elems881=true

Link -w -t ‘STAK’ -c ‘WILD’ 
-m FOURIER -rt XCMD=1282 -sg Fourier 
Fourier.p.o 
“{Libraries}”Runtime.o 
“{Libraries}”Interface.o 
“{TMLPLibraries}”TMLPasLib.o 
“{Libraries}”HyperXLib.o 
-o “Fourier”

Hypercard call :
set the lockscreen to true
-- prevents flicker
Fourier  330,14,480,319,10,7,5,3,4
-- 330,14,480 is the area to draw into
-- 10,7,5,3,4  are the fourier factors times 10
set the lockscreen to false
******************************************************)

INTERFACE

USES MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, PasLibIntf, HyperXCMD;

PROCEDURE Fourier(ParamPtr: XCMDPtr);

IMPLEMENTATION

PROCEDURE PictScrap(ParamPtr: XCMDPtr); FORWARD;

PROCEDURE Fourier(ParamPtr: XCMDPtr);
BEGIN
PictScrap(ParamPtr);
END;

PROCEDURE PictScrap(ParamPtr: XCMDPtr);
VAR
thePoint     : Point;
hPicture     : PicHandle;
rg           : rect;
Piclength    : LONGINT;
xoffset, yoffset: integer;
str          : str255;
xLeft, bot, top, xRight: LONGINT;
one, two, three, four, five: LONGINT;
x, y         : extended;
z1, z2, z3, z4, z5: extended;

PROCEDURE MyDrawing;
{ all your drawing stuff goes here }
VAR
i            : integer;
maxim, offset: extended;

FUNCTION Sinus(x: extended): extended;
BEGIN
Sinus := sin(x) * z1 + sin(2 * x) * z2 + sin(3 * x) * z3 +
sin(4 * x)  * z4 + sin(5 * x) * z5
{ the more, the better }
END;

BEGIN
eraserect(rg);
Framerect(rg); { optional }
offset := top + (bot - top) / 2.0;
z1 := one / 10.0;
z2 := two / 10.0;
z3 := three / 10.0;
z4 := four / 10.0;
z5 := five / 10.0;
x := 0.02 {1 / 50} ;
maxim := Sinus(x);
FOR i := 2 TO 314 DO
BEGIN
IF i MOD 10 = 0 THEN
SendCardMessage(ParamPtr, ‘set cursor to busy’);
x := i / 50;
y := Sinus(x);
IF maxim < y THEN
maxim := y;
END;

x := 1 / 50;
y := Sinus(x);
maxim := 100 / maxim;
SendCardMessage(ParamPtr, ‘set cursor to busy’);
moveto(xLeft + 1, round(y * maxim + offset));
FOR i := 2 TO 314 DO
BEGIN { for two pi }
x := i / 50;
y := Sinus(x);
lineto(i + xLeft + 1, round(y * maxim + offset))
END;
SendCardMessage(ParamPtr, ‘set cursor to busy’);
penpat(ltgray);
moveto(xLeft + 1, round(offset));
lineto(xRight - 2, round(offset));
pennormal
END;

FUNCTION GetParameter(n: integer): LONGINT;
VAR
tmp          : LONGINT;
BEGIN
ZeroToPas(ParamPtr, ParamPtr^.params[n]^, str);
stringToNum(str, tmp);
GetParameter := tmp
END;

BEGIN
IF ParamPtr^.paramCount <> 9 THEN
SendCardMessage(ParamPtr, ‘put “wrong number of parameters” into
msg’)
{ I think a more convenient way of error report than by ParamPtr^.ReturnValue
}
ELSE
BEGIN
{get the drawing rectangle coordinates from hypercard }
xLeft := GetParameter(1);
top := GetParameter(2);
xRight := GetParameter(3);
bot := GetParameter(4);

{ In this example : get Fourier coëfficients from hypercard }
one := GetParameter(5);
two := GetParameter(6);
three := GetParameter(7);
four := GetParameter(8);
five := GetParameter(9);
setrect(rg, xLeft, top, xRight, bot);
xoffset := xLeft + 5;
yoffset := top + 5;
cliprect(rg);
hPicture := OpenPicture(rg);
Showpen;
MyDrawing; { here all your drawing }
closepicture;
Piclength := GethandleSize(handle(hPicture));
IF ZeroScrap + putscrap(Piclength, ‘PICT’, ptr(hPicture^)) =
NoErr THEN
ParamPtr^.ReturnValue := PasToZero(ParamPtr, ‘’)
ELSE
ParamPtr^.ReturnValue := PasToZero(ParamPtr, ‘something wrong’);
SendCardMessage(ParamPtr, ‘choose select tool’);
SendCardMessage(ParamPtr, ‘domenu “Paste Picture”’);
SendCardMessage(ParamPtr, ‘choose browse tool’);
END
END;
END.
```

## Small and Dirty “Write Always”

In the debugging of large programs we were accustomed to put a lot of ‘writeln’s’ in the source text to show what was happening. Although a workable solution on mainframes and mini’s, that’s not so easy in the Macintosh environment, there is not always a window available to write in. The following small subroutine (TML Pascal version) does the trick with some disadvantage: it overwrite all its lines on top of each other at the bottom of the screen in some kind of status line (bit like Online companion), but, sorry, the line is not automatically removed after leaving the program. Dirty isn’t it, so surely for debugging only. An ‘invalrect’ after each multifinder event and at the end of the program is sometimes a solution.

In the program source you write something like :

```--2

if dbg then DQText(‘now in procedure blahblah’)
```

(The clever one’s can write a MPW-script to put it after the first begin in every procedure or function) Dbg is used as a constant (or in a compiler directive).

The procedure (as a Pascal unit) looks like :

```{3}

UNIT DQTextProcedure;
INTERFACE
USES
MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, QDaccess;

{ Tml pascals QDaccess defines:
TYPE  QDGlobalsPtr = ^QDGlobalsRec;
QDGlobalsRec =
record
randSeed   :  LongInt;
screenBits :  BitMap;
arrow      :  Cursor;
dkGray     :  Pattern;
ltGray     :  Pattern;
gray       :  Pattern;
black      :  Pattern;
white      :  Pattern;
ThePort    :  GrafPtr;
end;
function QDGlobals: QDGlobalsPtr;external;}

PROCEDURE DQText(Message: Str255);
IMPLEMENTATION
PROCEDURE DQText(Message: Str255);
VAR
SavedPort    : GrafPtr;
LocalPort    : GrafPort;
TheRect      : Rect;
BEGIN
WITH QDGlobals^ DO
BEGIN
GetPort(SavedPort);
OpenPort(@LocalPort);
SetPort(@LocalPort);
WITH ScreenBits.Bounds DO
{ this is QDGlobals^ s ScreenBits ! }
SetRect(TheRect, Left, Bottom-20, Right, Bottom);
FillRect(TheRect, White);
MoveTo(TheRect.Left, TheRect.Top);
LineTo(TheRect.Right, TheRect.Top);
MoveTo(TheRect.Left+7, TheRect.Bottom-7);
DrawString(Message);
ClosePort(@LocalPort);
SetPort(SavedPort);
END;
END;
END.

PROGRAM tstDQtext;
{ test the dqtext procedure : }
USES MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
PaslibIntf, QDaccess, DQtext;
(*
Link  -t ‘APPL’ -c ‘????’ 
DQtext.p.o 
tstDQtext.p.o 
“{Libraries}”Runtime.o 
“{Libraries}”Interface.o 
“{TMLPLibraries}”TMLPasLib.o 
-o tstDQtext
*)
BEGIN
textbook(NIL); { TML pascal simple window }
writeln(‘ see bottom line’);
writeln(‘ click mouse button’);
PLFlush(output);
DQtext(‘before’);
REPEAT
UNTIL button;
DQtext(‘after mouse button’);
END.
```

Community Search:
MacTech Search:

## Software Updates via MacUpdate

Tunnelblick 3.8.2a - GUI for OpenVPN.
Tunnelblick is a free, open source graphic user interface for OpenVPN on OS X. It provides easy control of OpenVPN client and/or server connections. It comes as a ready-to-use application with all... Read more
calibre 4.17.0 - Complete e-book library...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital librarian... Read more
MacPilot 11.1.4 - \$15.96
MacPilot gives you the power of UNIX and the simplicity of Macintosh, which means a phenomenal amount of untapped power in your hands! Use MacPilot to unlock over 1,200 features, and access them all... Read more
Transmission 3.00 - Popular BitTorrent c...
Transmission is a fast, easy, and free multi-platform BitTorrent client. Transmission sets initial preferences so things "just work", while advanced features like watch directories, bad peer blocking... Read more
Doom 3 1.3.1 - First-person shooter acti...
A massive demonic invasion has overwhelmed the Union Aerospace Corporation's (UAC) Mars Research Facility, leaving only chaos and horror in its wake. As one of only a few survivors, you must fight... Read more
Box Sync 4.0.8004 - Online synchronizati...
Box Sync gives you a hard-drive in the Cloud for online storage. Note: You must first sign up to use Box. What if the files you need are on your laptop -- but you're on the road with your iPhone? No... Read more
LibreOffice 6.4.4.2 - Free, open-source...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
Day One 4.14 - Maintain a daily journal.
Day One is an easy, great-looking way to use a journal / diary / text-logging application. Day One is well designed and extremely focused to encourage you to write more through quick Menu Bar entry,... Read more
MenuMeters 2.0.7 - CPU, memory, disk, an...
MenuMeters is a set of CPU, memory, disk, and network monitoring tools for Mac OS X. Although there are numerous other programs which do the same thing, none had quite the feature set I was looking... Read more
War Thunder 1.97.2.19 - Multiplayer war...
In War Thunder, aircraft, attack helicopters, ground forces and naval ships collaborate in realistic competitive battles. You can choose from over 1,500 vehicles and an extensive variety of combat... Read more

## Latest Forum Discussions

SINoALICE, Yoko Taro and Pokelabo's...
Yoko Taro and developer Pokelabo's SINoALICE has now opened for pre-registration over on the App Store. It's already amassed 1.5 million Android pre-registrations, and it's currently slated to launch on July 1st. [Read more] | Read more »
Masketeers: Idle Has Fallen's lates...
Masketeers: Idle Has Fallen is the latest endeavour from Appxplore, the folks behind Crab War, Thor: War of Tapnarok and Light A Way. It's an idle RPG that's currently available for Android in Early Access and will head to iOS at a later date. [... | Read more »
Evil Hunter Tycoon celebrates 2 million...
Evil Hunter Tycoon has proved to be quite the hit since launching back in March, with its most recent milestone being 2 million downloads. To celebrate the achievement, developer Super Planet has released a new updated called Darkness' Front Yard... | Read more »
Peak's Edge is an intriguing roguel...
Peak's Edge is an upcoming roguelike puzzle game from developer Kenny Sun that's heading for both iOS and Android on June 4th as a free-to-play title. It will see players rolling a pyramid shape through a variety of different levels. [Read more] | Read more »
Clash Royale: The Road to Legendary Aren...
Supercell recently celebrated its 10th anniversary and their best title, Clash Royale, is as good as it's ever been. Even for lapsed players, returning to the game is as easy as can be. If you want to join us in picking the game back up, we've put... | Read more »
The Magic Gladiator class arrives in MU...
The Magic Gladiator class is now available in MU Origin 2 following the most recent patch. It also marks the start of Abyss Season 11 and the introduction of Couple Skills and Couple Dungeons. [Read more] | Read more »
The 5 Best Racing Games
With KartRider Rush+ making a splash this past week, we figured it was high time we updated our list of the best mobile racing games out there. From realistic racing sims to futuristic arcade racers (and even racing management games!), check out... | Read more »
KartRider Rush+ Guide - Tips for new rac...
KartRider Rush+ continues to be a surprisingly refreshing and fun kart racer that's entirely free-to-play. The main reason for this is just how high its skill ceiling is. Check out the video above if you're curious to know what top level play looks... | Read more »
KartRider Rush+ might be good, actually?
It's hard to find good racing games on mobile. Most of them are free-to-play, and free-to-play racers generally suck. Even Nintendo couldn't put together a competent Mario Kart game, opting instead for a weird score chaser that resembles--but feels... | Read more »
LifeAfter, NetEase's popular surviv...
A new map will be making its way into NetEase's popular survival game LifeAfter. The map is set to arrive on May 28th and will introduce a volcano that's teetering on the verge of eruption, bringing a host of added challenges to the game. [Read... | Read more »

## Price Scanner via MacPrices.net

Apple restocks 2019 MacBook Airs starting at...
Apple has clearance, Certified Refurbished, 2019 13″ MacBook Airs available again starting at \$779. Each MacBook features a new outer case, comes with a standard Apple one-year warranty, and is... Read more
Apple restocks clearance Mac minis for only \$...
Apple has restocked Certified Refurbished 2018 4-Core Mac minis for only \$599. Each mini comes with a new outer case plus a standard Apple one-year warranty. Shipping is free: – 3.6GHz Quad-Core... Read more
Apple’s new 2020 13″ MacBook Airs on sale for...
B&H Photo has Apple’s new 2020 13″ 4-Core and 6-Core MacBook Airs on sale today for \$50-\$100 off Apple’s MSRP, starting at \$949. Expedited shipping is free to many addresses in the US. The... Read more
B&H continues to offer clearance 2019 13″...
B&H Photo has clearance 2019 13″ 4-Core MacBook Pros available for up to \$300 off Apple’s original MSRP, with prices starting at \$1149. Expedited shipping is free to many addresses in the US. B... Read more
Memorial Day Weekend Sale: Take \$300 off thes...
Apple resellers are offering \$300 discounts on select 16″ MacBook Pros as part of their Memorial Day Weekend 2020 sales. Prices start at \$2099: – 16″ 2.6GHz 6-Core Space Gray MacBook Pro: \$2099 at... Read more
Best Memorial Day Weekend 2020 Apple AirPods...
Apple resellers are offering discounts ranging up to \$50 off MSRP on AirPods as part of their Memorial Day Weekend 2020 sales. These are the best deals today on various AirPods models. See our... Read more
Memorial Day Weekend Sale: 10″ Apple iPads fo...
Amazon is offering new 10.2″ iPads for \$80-\$100 off Apple’s MSRP as part of their Memorial Day Weekend 2020 sale, with prices starting at only \$249. These are the same iPads sold by Apple in their... Read more
Memorial Day Weekend Sale: 2020 Apple iPhone...
Sprint is offering Apple’s new 2020 64GB iPhone SE for \$0 per month for 18 months as part of their Memorial Day Weekend 2020 sale. New line of service and trade-in required. Offer is valid from 5/22/... Read more
Amazon’s popular \$100 Apple Watch Series 5 di...
Amazon has Apple Watch Series 5 GPS + Cellular models on sale for up to \$100 off Apple’s MSRP today. Shipping is free. These are the same Apple Watch models sold by Apple in their retail and online... Read more
2020 13″ 4-Core MacBook Air on sale for \$949,...
Apple reseller Adorama has the new 2020 13″ 1.1GHz 4-Core Space Gray MacBook Air on sale today for \$949 shipped. Their price is \$50 off Apple’s MSRP, and it’s the lowest price currently available for... Read more

## Jobs Board

Essbase Developer - *Apple* - Theorem, LLC...
Job Summary Apple is seeking an experienced, detail-minded Essbase developer to join our worldwide business development and strategy team. If you are someone who Read more
Senior Software Engineer @ *Apple* - Theore...
Job Summary Apple is looking for a seasoned senior software engineer to join our worldwide business development and strategy team. This is an opportunity to lead a Read more
Cub Foods - *Apple* Valley - Now Hiring Par...
Cub Foods - Apple Valley - Now Hiring Part Time! United States of America, Minnesota, Apple Valley Retail Operations Post Date May 18, 2020 Requisition # 119230 Read more
Senior Practice Manager - *Apple* Hill Eye...
Senior Practice Manager - Apple Hill Eye Center Tracking Code 61713 Job Description Schedule & Location: Full Time Days Apple Hill Medical Center General Read more
Retail Sales Consultant - *Apple* Valley -...
Retail Sales Consultant - Apple Valley - \$500 Hiring Bonus Apply Now...12-30-2019 Address : 7875 150th St W Location : Apple Valley, MN US Req # : 272753BR Job Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.