home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / C128CPM / MDRAW.LBR / MDRAW.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2019-04-13  |  4.5 KB  |  196 lines

  1. {
  2. Mouse Draw 1.0 11/25/92 (C) 1992 Steve Goldsmith
  3. SG Tools Pro (C) 1992 Steve Goldsmith
  4. SG Tools (C) 1992 Parsec, Inc.
  5.  
  6. This program requires SG Tools from Parsec, Inc. to compile.  SG Tools Pro
  7. is a set of professional add-ons for SG Tools and Turbo Pascal.  You are
  8. free to use the MOUSE.INC and MOUSECUR.INC modules in your own programs
  9. as you wish.  If you use any of my tools or programs a $5.00 payment is
  10. requested to:
  11.  
  12. Steve Goldsmith
  13. 2805 Jamaica Street
  14. Sarasota, FL 34231
  15.  
  16. Send any comments to GEnie mail S.GOLDSMITH2
  17.  
  18. MDRAW.PAS is another 1351 mouse example.  It allows you to move the cursor
  19. around and draw simple pictures.  I created a new module since I released
  20. MOUSE.LBR called MOUSECUR.INC.  MOUSECUR.INC removes mouse cursor logic
  21. from the main program and can be used in VDC bit map or interlace modes.
  22. Cursor plotting is still preformed by the main program.
  23.  
  24. I used the ADM-31 screen codes for cursor plotting and colors.  This was the
  25. easiest way until Parsec releases the VDC Screen Manager for SG Tools.
  26. }
  27. program MouseDraw;
  28.  
  29. {$B-,C-,R-,U-,V-}
  30.  
  31. {SG Tools module to read cia and sid ports}
  32.  
  33. {$I PORT.INC}
  34.  
  35. {SG Tools Pro modules}
  36.  
  37. {$I JOYSTICK.INC}
  38. {$I MOUSE.INC}
  39. {$I MOUSECUR.INC}
  40.  
  41. {codes for adm-31/commodore protocol}
  42.  
  43. const
  44.  
  45.   appClrScr = #$1b#$3a;
  46.   appRvsOn = #$1b#$47#$34;
  47.   appRvsOff = #$1b#$47#$30;
  48.   appTitleColor = #$1b#$1b#$1b#$21;
  49.   appExitColor = #$1b#$1b#$1b#$21;
  50.  
  51. {text data}
  52.  
  53.   appTitle = ' Mouse Draw 1.0 11/25/92 (C) 1992 Steve Goldsmith ';
  54.   appCommands = 'Mouse Port 2, [LEFF] Draw, [RIGHT] Erase, [C] Color [S] Clr Scr, [ESC] exit';
  55.  
  56. {other app related stuff}
  57.  
  58.   appScrWidth = 80;  {screen size}
  59.   appScrHeight = 25;
  60.   appXFeel = 4;      {feel is amount of change needed to move cursor}
  61.   appYFeel = 8;
  62.   appXOverflow = 16; {overflow is the max amount of change which}
  63.   appYOverflow = 16; {prevents cursor movement}
  64.  
  65. type
  66.  
  67.   appDispStr = string[255];
  68.  
  69. var
  70.  
  71.   appCurColor : byte;
  72.  
  73. procedure PlotCursor (X,Y : byte);
  74.  
  75. begin
  76.   Write (#$1b#$3d+Chr (Y+$20)+Chr (X+$20))
  77. end;
  78.  
  79. procedure CenterText (S : appDispStr; Y : byte);
  80.  
  81. begin
  82.   PlotCursor ((appScrWidth-Length (S)) div 2,Y);
  83.   Write (S)
  84. end;
  85.  
  86. procedure PlotStr (X,Y : byte; S : appDispStr);
  87.  
  88. begin
  89.   PlotCursor (X,Y);
  90.   Write (S)
  91. end;
  92.  
  93. procedure DrawScr;
  94.  
  95. var
  96.  
  97.   I : byte;
  98.  
  99. begin
  100.   Write (appClrScr);
  101.   Write (appTitleColor+appRvsOn);
  102.   CenterText (appTitle,0);
  103.   Write (appRvsOff);
  104.   CenterText (appCommands,1);
  105.   for I := 0 to appScrWidth-1 do
  106.   begin
  107.     PlotCursor (I,2);
  108.     Write (appRvsOn+'*'+appRvsOff);
  109.     PlotCursor (I,appScrHeight-3);
  110.     Write (appRvsOn+'*'+appRvsOff)
  111.   end;
  112.   for I := 3 to appScrHeight-4 do
  113.   begin
  114.     PlotCursor (0,I);
  115.     Write (appRvsOn+'*'+appRvsOff);
  116.     PlotCursor (appScrWidth-1,I);
  117.     Write (appRvsOn+'*'+appRvsOff)
  118.   end;
  119.   PlotCursor (mseXCur,mseYCur);
  120.   Write (#27#27#27+Chr ($20+appCurColor))
  121. end;
  122.  
  123. procedure UpdateMouseCur;
  124.  
  125. var
  126.  
  127.   ButtonData : byte;
  128.  
  129. begin
  130.   Inline ($F3); {di                      ;disable hardware interrupt}
  131.   UpdateMouseCurX; {calling the cursor plotting procedures with interrupts}
  132.   UpdateMouseCurY; {disabled stablize sid pots before reading}
  133.   ReadMouse2;
  134.   Inline ($FB); {ei                      ;enable hardware interrupt}
  135.   PlotCursor (mseXCur,mseYCur);
  136.   ButtonData := ReadJoy2;    {get button data}
  137.   if ButtonData and joyFire = 0 then {left button to draw}
  138.     Write (appRvsOn+' '+appRvsOff)
  139.   else
  140.     if ButtonData and JoyUp = 0 then {right button to erase}
  141.       Write (' ')
  142. end;
  143.  
  144. procedure CurColor;
  145.  
  146. begin
  147.   if appCurColor < 15 then
  148.     appCurColor := appCurColor+1
  149.   else
  150.     appCurColor := 1;
  151.   Write (#27#27#27+Chr ($20+appCurColor)+appRvsOn+' '+appRvsOff);
  152.   PlotCursor (mseXCur,mseYCur)
  153. end;
  154.  
  155. procedure Run;
  156.  
  157. var
  158.  
  159.   K : char;
  160.  
  161. begin
  162.   repeat
  163.     repeat
  164.       UpdateMouseCur {process mouse commands}
  165.     until KeyPressed;
  166.   Read (Kbd,K);
  167.   case UpCase (K) of {process keyboard commands}
  168.     'C' : CurColor;
  169.     'S' : DrawScr
  170.   end;
  171.   until K = #27; {escape to exit}
  172. end;
  173.  
  174. procedure Init;
  175.  
  176. begin
  177.   InitMouseCur (1,3,1,3,appScrWidth-2,appScrHeight-4, {init mouse cursor}
  178.   appXFeel,appYFeel,appXOverflow,appYOverflow);
  179.   appCurColor := 1; {init color to white}
  180.   DrawScr           {clear screen and display title}
  181. end;
  182.  
  183. procedure Done;
  184.  
  185. begin
  186.   Write (appExitColor);
  187.   PlotCursor (0,appScrHeight-3)
  188. end;
  189.  
  190.  
  191. begin
  192.   Init;
  193.   Run;
  194.   Done
  195. end.
  196.