MEGAMAX MODULA-2 - examples

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

tcat
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 110
Joined: Fri May 03, 2013 6:00 am

MEGAMAX MODULA-2 - examples

Postby tcat » Fri Sep 06, 2013 6:53 pm

Hi,

I am making my first steps with MM2 programming environment. I learnt to work with keyboard. menus, resources, events, dialogs and windows, making use of the core MM2 modules. These are really the steps of a beginner.

One sample I wish to share here, is a two window demo application, showing what happens when one window overlaps the other and then is moved, or the other comes to the top, GEM sends events for just certain parts of a window to be redrawn.

Please see picture.
mm2-clip.png

It seems to work as it should except when the top window overlaps with the bottom one, and the bottom comes to the top, the whole window area is redrawn, not just the part that was hidden.

MM2 expects that each module or a symbol has to be imported before use.
I have two floppy MM2 system, the boot disk with MM2 shell and a user disk. Applications are compiled as modules MOD, that can be executed right from the MM2 shell. Can also be later linked to PRG, TOS or ACC, to run from the GEM.

TCAT
You do not have the required permissions to view the files attached to this post.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: MEGAMAX MODULA-2 - examples

Postby Mikefulton » Thu Jan 07, 2016 7:34 am

tcat wrote:It seems to work as it should except when the top window overlaps with the bottom one, and the bottom comes to the top, the whole window area is redrawn, not just the part that was hidden.
TCAT


This is just the way your redraw code is doing things. It's walking the rectangle list of the window, but it's not looking at the RECT of the "dirty" area in the redraw message.

When you walk the window's rectangle list, you're getting the VISIBLE portions of the window, not the "dirty" parts. A topped window will only have one rectangle for the entire window.

If you only want to redraw the "dirty" area, then as you walk the rectangle list you need to calculate the intersection of each rectangle with the one from the redraw message, set the clipping, and draw.

-----
I know it's an old post but it seemed like it could still be relevant.

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 762
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: MEGAMAX MODULA-2 - examples

Postby mfro » Thu Jan 07, 2016 7:42 am

Mikefulton wrote:... It's walking the rectangle list of the window, but it's not looking at the RECT of the "dirty" area in the redraw message....


which can be a perfectly valid design decision (no objection) at times, considering the complexity of the drawing code.

Depending on the drawing logic, drawing only a part of the scene might require clipping, which can dramatically slow down redraw performance. It's a case by case decision what's better.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: MEGAMAX MODULA-2 - examples

Postby Mikefulton » Thu Jan 07, 2016 12:25 pm

mfro wrote:
Mikefulton wrote:... It's walking the rectangle list of the window, but it's not looking at the RECT of the "dirty" area in the redraw message....


which can be a perfectly valid design decision (no objection) at times, considering the complexity of the drawing code.

Depending on the drawing logic, drawing only a part of the scene might require clipping, which can dramatically slow down redraw performance. It's a case by case decision what's better.


Your argument leads me to wonder if you understood. Getting the intersection of the "dirty" area will typically result in a smaller area that needs to be redrawn. The best way to save time on a redraw is to avoid drawing objects you know are completely outside the current clip rectangle, and a smaller (intersected) rectangle means (potentially) that you have fewer things to draw.

BTW, there's really no such thing as "no clipping". When you "turn clipping off" all that really happens is that the clipping rectangle is set to match the screen boundaries. Setting the clip area to a smaller rectangle means that it avoids pushing pixels to the screen, so it should usually be faster. (Most likely the difference would not be perceptible to the viewer, however.)

Can you provide an example of a program where drawing the window was noticeably faster with clipping turned off? That seems unlikely and my guess would be that there was something else going on.

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 762
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: MEGAMAX MODULA-2 - examples

Postby mfro » Thu Jan 07, 2016 2:18 pm

Mikefulton wrote:BTW, there's really no such thing as "no clipping". When you "turn clipping off" all that really happens is that the clipping rectangle is set to match the screen boundaries. Setting the clip area to a smaller rectangle means that it avoids pushing pixels to the screen, so it should usually be faster. (Most likely the difference would not be perceptible to the viewer, however.)

I can't tell for all VDI implementations, but I seriously doubt that for at least the "standard" LineA-based one we all know. Most (if not all) of the VDI output functions just wrap around to the next scanline if you draw off the right screen border with clipping off.

Clipped VDI (v_gtext()) output, for example, gets dramatically slower with clipping enabled. It does clip-checks for every single character if clipping is enabled.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: MEGAMAX MODULA-2 - examples

Postby Mikefulton » Fri Jan 08, 2016 12:16 am

On reflection, you might be right. I may have been thinking about the printer driver stuff, not the screen driver.

tcat
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 110
Joined: Fri May 03, 2013 6:00 am

Re: MEGAMAX MODULA-2 - examples

Postby tcat » Wed Feb 03, 2016 8:06 pm

Hi Folks,

I have been away from ATARI for some time, doing mainly QL stuff. Now I see my old posts raised some interest. I am looking into the code, trying to understand what I meant more than 2 years ago. I share, it is my learning example, possibly far from excellent.

Cheers
Tom

WINDOWS.M module listing ...

Code: Select all

MODULE Windows;


FROM GEMEnv IMPORT RC, InitGem, ExitGem, CurrGemHandle, DeviceHandle, GemHandle,
                   GemError;

FROM GEMGlobals IMPORT GemChar, MouseButton, MButtonSet, SpecialKey,
                       SpecialKeySet, solidFill, hollowFill;
                     
FROM GrafBase   IMPORT Rect, Pnt, Point, Rectangle, ClipRect, TransRect,
                       black, white, red;
FROM AESEvents  IMPORT KeyboardEvent, MessageBuffer, MultiEvent, Event,
                       EventSet, RectEnterMode,
                       windMoved, windSized, windTopped, windRedraw;
                       
FROM AESWindows  IMPORT CreateWindow, OpenWindow, SetWindowSize, DeleteWindow,
                        SetWindowString, SetTopWindow,
                        UpdateWindow, WindowRectList, WindowSize,
                        WindowElement, RListMode, WElementSet, NoWindow,
                        WStringMode, WSizeMode;
                       
FROM AESGraphics IMPORT GrafMouse, MouseForm;
                       
FROM VDIOutputs    IMPORT Bar, Line, GrafText;
FROM VDIControls   IMPORT SetClipping, DisableClipping;
FROM VDIAttributes IMPORT SetFillColor, SetFillType, SetLineColor;
                       
FROM PrgCtrl    IMPORT TermProcess;
FROM Strings    IMPORT String;
FROM SYSTEM     IMPORT ADR, CADR;


VAR     dev     : DeviceHandle;
        gemHdl  : GemHandle;
        success : BOOLEAN;
       
        msg     : MessageBuffer;
        mouse   : Point;
        buttons : MButtonSet;
        keys    : SpecialKeySet;
        clicks  : CARDINAL;
        key     : GemChar;
        events  : EventSet;
       
        windHdl, wind2Hdl : CARDINAL;
        windRect: Rectangle;


PROCEDURE msgBox (msg : String; gemHdl : GemHandle; exitGem : BOOLEAN);
VAR
      gemCh : GemChar;
BEGIN
      KeyboardEvent (gemCh);
      IF exitGem THEN
        ExitGem (gemHdl);
        TermProcess (0);
      END;
     
END msgBox;


PROCEDURE RedrawWindow (handle : CARDINAL ; frame : Rectangle);
VAR
        work : Rectangle;
BEGIN
        work := WindowSize (handle, workSize);
       
        SetLineColor (dev, red);
        SetFillColor (dev, red);
        SetFillType (dev, hollowFill);
       
        Bar (dev, frame);
        WITH frame DO
          Line (dev, Pnt(x,y), Pnt(x+w-1,y+h-1) );
          Line (dev, Pnt(x+w-1,y), Pnt(x,y+h-1) );
        END;
       
        IF handle = windHdl THEN
          GrafText (dev, Pnt(work.x+5, work.y+15), 'Clip1')
        ELSIF handle = wind2Hdl THEN
          GrafText (dev, Pnt(work.x+5, work.y+15), 'Clip2') END;
       
END RedrawWindow;


PROCEDURE RedrawFrame (handle : CARDINAL; frame : Rectangle);
VAR
        clip : Rectangle;
BEGIN
        SetFillType (dev, solidFill);
        SetFillColor (dev, white);
        UpdateWindow (TRUE);
        GrafMouse (mouseOff, NIL);

        clip := WindowRectList (handle, firstElem);
        WHILE clip.w # 0 DO
         
          clip := ClipRect (frame, clip);
          IF clip.w # 0 THEN
            SetClipping (dev, clip);
            Bar (dev, clip);
            RedrawWindow (handle, clip);
          END;
         
          clip := WindowRectList (handle, nextElem);
        END;
       
        DisableClipping (dev);
        GrafMouse (mouseOn, NIL);
        UpdateWindow (FALSE);
       
END RedrawFrame;



BEGIN

  InitGem (RC, dev, success);
  IF success THEN
    gemHdl := CurrGemHandle ();
   
    GrafMouse (arrow, NIL);
    windRect := Rect(20,20,70,70);
   
    CreateWindow ( WElementSet {nameBar, mover}, windRect, windHdl);
    IF windHdl = NoWindow THEN
      msgBox ('Cannot create window!', gemHdl, TRUE) END;
     
    SetWindowString (windHdl, nameStr, CADR ('Sample') );
 
    CreateWindow ( WElementSet {nameBar, mover}, windRect, wind2Hdl);
    IF wind2Hdl = NoWindow THEN
      msgBox ('Cannot create window!', gemHdl, TRUE) END;
     
    SetWindowString (wind2Hdl, nameStr, CADR ('Sample') );
   
    OpenWindow (windHdl, windRect);
    OpenWindow (wind2Hdl, TransRect (windRect, Pnt (40,55)) );
 
    REPEAT
   
      MultiEvent (EventSet {keyboard, mouseButton, message}, 2,
                MButtonSet {msBut1,msBut2}, MButtonSet {msBut1},
                lookForEntry, Rect (0,0,0,0),
                lookForEntry, Rect (0,0,0,0),
                msg, 0, mouse, buttons, keys, key, clicks, events);
     
      IF message IN events THEN
        CASE msg.msgType OF
          windMoved : SetWindowSize (msg.moveHdl, msg.moveFrame) |
          windTopped : SetTopWindow (msg.topHdl) |
          windRedraw : RedrawFrame (msg.rdrwHdl, msg.rdrwFrame) |
           
          ELSE ;
        END;
      END;
     
    UNTIL key.ascii = 'q';
    DeleteWindow (windHdl);
    DeleteWindow (wind2Hdl);
    ExitGem (gemHdl);
     
  END;

END Windows.

MrWeb
Atarian
Atarian
Posts: 1
Joined: Sat Dec 10, 2016 11:58 pm

Re: MEGAMAX MODULA-2 - examples

Postby MrWeb » Sun Dec 11, 2016 1:07 pm

Hey tcat,

I've send you an e-mail via the forums! Unfortunately, I'm not able to send private messages yet. :(
I'm trying to use Megamax Modula-2 as well at the moment, would be glad to get a reply!

best regards
MrWeb

tcat
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 110
Joined: Fri May 03, 2013 6:00 am

Re: MEGAMAX MODULA-2 - examples

Postby tcat » Mon Dec 12, 2016 6:53 pm

Hi MrWeb,

I took some interest in MM-2 as I learnt `Oxyd' was coded using this development tool.
I still consider myself a good starter, not professional coder in MM-2.

You may send your emails to thomas.kral(at)email.cz, while you cannot PM.

You may also follow some old discussion here:
viewtopic.php?f=70&t=25242


Ciao,
Tomas

tcat
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 110
Joined: Fri May 03, 2013 6:00 am

Re: MEGAMAX MODULA-2 - examples

Postby tcat » Fri Dec 29, 2017 6:26 pm

Hi,

Some time ago I was given `TOS-GIMMICKS' from a fellow Atarian, now finding some time to give them a ride under MM2 system.

These little animation tools were coded for TOS magazine in the 90's. As I see `Free Pascal' is getting much attention as it is finding its way to ATARI desktop, I wish to revive MM2 topic slightly.

http://www.successdenied.com/2011/02/to ... schneider/
EDIT - English Google Translate
https://translate.google.com/translate? ... edit-text=

I started with `MAGIC' gimmick demo (sparkling star effect used in Aladin Mac emulator). If you wished to follow, this is how the project is setup.

MAGIC.png

First, files are dragged to `Project Pad' on the left. Pressing `1'..`0' aids quick file selection. Pressing `C' - starts compile (so does a double clicking, or dragging a file onto `Compile' icon).

*.M - main modules, compile very last
*.D - definition modules (analogy to C header files .h), compile them first
*.I - implementation modules, compile as a second step

Module tree, MSSYSTEM -> MSGRAPHI -> MAGIC -> MSINIT, you need to compile in this order.

Resulting modules are placed in USER/MOD folder. Main modules can be executed by double-clicking while in the MM2 shell (also by pressing `A' or clicking `Checkered Flag', this also rebuilds modules if necessary).

`PRG' executable can be linked by pressing `L' or double-clicking `Linken' icon. In Linker parameters (ALT-L), add `MSINIT' module, all other disabled.

I could share `MM2.st' boot disk and `MM2USER.st' user disk with the MAGIC example above, here in the forum or at my GIT repo, not sure what is preferred?

Tom
You do not have the required permissions to view the files attached to this post.
Last edited by tcat on Tue Jan 02, 2018 8:42 pm, edited 2 times in total.

tcat
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 110
Joined: Fri May 03, 2013 6:00 am

Re: MEGAMAX MODULA-2 - examples

Postby tcat » Mon Jan 01, 2018 10:12 am

Hi,

Should you wish to try Modula-2, here is New Year's treat. I have decomposed Thomas Templeman's MM2 development trunk. I made floppy images, that partly follow original distribution on 4/5 floppies (wrote linux makefiles for it).

Please find attached two images.
MOS System boot floppy
MM2.st

User disk, insert after you boot into shell, UPDATE: Jan-2/2018
MM2USER.st


It has my own examples (incl. simple AES,VDI) to get you started. Gepard is default editor.
It runs on real ST with 1 MB(max), 1 floppy, 0 HDD.

Programmer's manual available in the form of definition modules ASCII converted.
MOS - Modula system modules
MOS_modules.zip

GEM - Gem modules
GEM_modules.zip

(I will pass it through Google Translate, anyone willing to proofread English version then?)

1st TOS GIMMICK by the author of OXYD follows here..
The MAGIC cursor ala Aladin, resident program
MM2USER2.st


Happy New Year Folks!
Tomas
You do not have the required permissions to view the files attached to this post.
Last edited by tcat on Tue Jan 02, 2018 8:40 pm, edited 3 times in total.

tcat
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 110
Joined: Fri May 03, 2013 6:00 am

Re: MEGAMAX MODULA-2 - examples

Postby tcat » Tue Jan 02, 2018 8:31 pm

Hi,

I have updated `MENU.M' module sample, as there was not much menu handling, now is. I realised it is user responsibility to call `NormalTitle()' proc to update highlighted menu.

Code: Select all

REPEAT
      MessageEvent (msg);
      IF msg.msgType = menuSelected THEN
        (* menu handling here *)
      END;
      NormalTitle (menu, msg.selTitle, TRUE)
UNTIL msg.selItem = 16;


I am surprised to see, selTitle/selItem are reported as 3/4 for Desktop menu, and 4/17,18,19 and 16 for File menu?

Updated image `MM2USER.st' above.
Tomas

User avatar
viking272
Captain Atari
Captain Atari
Posts: 353
Joined: Mon Oct 13, 2008 12:50 pm
Location: west of London, UK

Re: MEGAMAX MODULA-2 - examples

Postby viking272 » Tue Jan 02, 2018 8:47 pm

Thanks Thomas for the download links. I will take a look over the next week.
Cheers

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2394
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: MEGAMAX MODULA-2 - examples

Postby charles » Tue Jan 02, 2018 9:53 pm

I love mm2 and pascal ,,,thanx thomas
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2394
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: MEGAMAX MODULA-2 - examples

Postby charles » Tue Jan 02, 2018 9:54 pm

or tcat
sorry thought your name was Thomas for some reason ......

it is ,,,, sorry again ..!!! lol

; )
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

tcat
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 110
Joined: Fri May 03, 2013 6:00 am

Re: MEGAMAX MODULA-2 - examples

Postby tcat » Wed Jan 03, 2018 10:18 am

Hi Charles,
T[h]omas is the name, tcat just a nick I picked :-)
T.


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 4 guests