home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / new / amigalibdisks / d991 / aswarmii / source / aswarm.c next >
C/C++ Source or Header  |  1994-04-04  |  60KB  |  2,179 lines

  1. /*
  2.  
  3.    ASwarm II V2.0 - The Original One
  4.  
  5.    Written by Markus "Ill" Illenseer    markus@Techfak.Uni-Bielefeld.de
  6.    and Matthias "Tron" Scheler          tron@uni-paderborn.de
  7.  
  8.    Based upon Jeff Buterworths XSwarm.
  9.  
  10.    Now released as MUI Application.
  11.  
  12.    Please leave this source intact. ASwarm is freely distributable,
  13.    but no longer 'Public Domain'. If you have suggestions or Bug-Reports,
  14.    please contact us.
  15.  
  16.    Read the Manuals for known Bugs and Contact-Adresses.
  17.  
  18. */
  19.  
  20. #include <hardware/cia.h>
  21. #include <hardware/custom.h>
  22. #include <hardware/dmabits.h>
  23. #include <exec/memory.h>
  24. #include <exec/ports.h>
  25. #include <exec/execbase.h>
  26. #include <graphics/displayinfo.h>
  27. #include <graphics/gfxbase.h>
  28. #include <graphics/gfxmacros.h>
  29. #include <intuition/intuitionbase.h>
  30. #include <intuition/gadgetclass.h>
  31. #include <libraries/commodities.h>
  32. #include <libraries/gadtools.h>
  33. #include <libraries/mui.h>
  34. #include <workbench/startup.h>
  35. #include <workbench/icon.h>
  36. #include <workbench/workbench.h>
  37. #include <dos/dosextens.h>
  38. #include <dos/dostags.h>
  39. #include <dos/rdargs.h>
  40.  
  41. #include <clib/diskfont_protos.h>
  42. #include <clib/alib_protos.h>
  43. #include <clib/commodities_protos.h>
  44. #include <clib/dos_protos.h>
  45. #include <clib/exec_protos.h>
  46. #include <clib/graphics_protos.h>
  47. #include <clib/icon_protos.h>
  48. #include <clib/intuition_protos.h>
  49. #include <clib/macros.h>
  50. #include <clib/muimaster_protos.h>
  51.  
  52. #include <string.h>
  53. #include <stdlib.h>
  54.  
  55. #ifdef __SASC /* some stuff for SAS-C */
  56.  
  57. #include <pragmas/muimaster_pragmas.h>
  58. #include <pragmas/commodities_pragmas.h>
  59. #include <pragmas/dos_pragmas.h>
  60. #include <pragmas/exec_sysbase_pragmas.h>
  61. #include <pragmas/graphics_pragmas.h>
  62. #include <pragmas/icon_pragmas.h>
  63. #include <pragmas/intuition_pragmas.h>
  64.  
  65. #define VOID_GETA4  void __interrupt __saveds
  66. #define REGARGS(rv) rv __regargs
  67. #define CHIP(dt)    dt __chip
  68. #define ASM(rv)     rv __saveds __asm
  69. #define REG(r)      register __ ## r
  70.  
  71. CxObj *HotKey(UBYTE *,struct MsgPort *,long);
  72. void NewList(struct List *);
  73.  
  74. UBYTE *Version = "$VER: ASwarm II 2.0 (compiled with SAS/C)";
  75. /* Attention ! ASwarm<ALT SPACE>II ... */
  76.  
  77. void chkabort(void)
  78. {}
  79.  
  80. #else /* some stuff for Dice */
  81.  
  82. #define VOID_GETA4  __stkargs __geta4 void
  83. #define REGARGS(rv) __regargs rv
  84. #define CHIP(dt)    __chip dt
  85. #define ASM(rv)     __geta4 rv
  86. #define REG(r)      __ ## r
  87.  
  88. UBYTE *Version = "$VER: ASwarm II 2.0 (compiled with DICE)";
  89. /* Attention ! ASwarm<ALT SPACE>II ... */
  90.  
  91. void main(LONG,UBYTE **);
  92.  
  93. void wbmain(struct WBStartup *WBS)
  94.  
  95. {
  96.  if (WBS->sm_NumArgs) (void)CurrentDir(WBS->sm_ArgList->wa_Lock);
  97.  
  98.  main(0L,(UBYTE **)WBS);
  99. }
  100.  
  101. #endif
  102.  
  103. /*
  104.  
  105.    Common Definitions
  106.  
  107. */
  108.  
  109. #define custom (*((struct Custom *)0xDFF000L)) /* Hardwarebangers :-) */
  110. #define ciaa   (*((struct CIA *)0xBFE001L))
  111.  
  112. extern struct ExecBase *SysBase;
  113. extern struct DosLibrary *DOSBase;
  114.  
  115. #define FINDPROCPORT (&((struct Process *)SysBase->ThisTask)->pr_MsgPort)
  116.  
  117. struct IntuitionBase *IntuitionBase;
  118. struct GfxBase *GfxBase;
  119.  
  120. struct Library *CxBase,*MUIMasterBase,*IconBase;
  121.  
  122. LONG WBStarted;
  123.  
  124. #define NUMTOOLTYPES 17
  125.  
  126. char *ToolTypeIDs[NUMTOOLTYPES] =
  127.  {"CX_PRIORITY","CX_POPUP","CX_POPKEY","BLANKKEY",
  128.   "TIMEOUT","CLIENTTIMEOUT",
  129.   "DISPLAY","CYCLE","AIM",
  130.   "WASP","BEES","SPEED","TIGHTNESS",
  131.   "MOUSEBLANKMETHOD","VELOCITY","JOYSTICK","FINALTIMEOUT"};
  132.  
  133. /*
  134.  
  135.    MUI stuff
  136.  
  137. */
  138.  
  139. /* Defines for the Guide-Node-entries */
  140. #define GUIDE_FILE         "ASwarm.guide"
  141. #define NODE_MAIN_MAIN     "EDIT"
  142.  
  143. #define NODE_MAIN_HIDE     "HIDE"
  144. #define NODE_MAIN_BLANK    "BLANK"
  145. #define NODE_MAIN_QUIT     "QUIT"
  146.  
  147. #define NODE_COMM_MAIN     "COMM"
  148. #define NODE_COMM_TIMEOUT  "TIME"
  149. #define NODE_COMM_POPKEY   "POPKEY"
  150. #define NODE_COMM_CLTIME   "CLIENT"
  151. #define NODE_COMM_BLANKKEY "BLANKKEY"
  152. #define NODE_COMM_FITIME   "FINAL"
  153. #define NODE_COMM_JOYSTICK "JOYSTICK"
  154.  
  155. #define NODE_SWARM_MAIN  "OPTIONS"
  156. #define NODE_SWARM_SPEED "SPEED"
  157. #define NODE_SWARM_WASPS "WASPS"
  158. #define NODE_SWARM_BEES  "BEES"
  159. #define NODE_SWARM_VELO  "VELO"
  160. #define NODE_SWARM_TIGHT "TIGHT"
  161. #define NODE_SWARM_COLOR "COLOR"
  162. #define NODE_SWARM_AIM   "AIM"
  163.  
  164. #define NODE_DISPLAY_MAIN     "DISPLAY"
  165. #define NODE_DISPLAY_LIST     "SCREEN"
  166. #define NODE_DISPLAY_MOUSE    "MOUSE"
  167.  
  168. APTR AP_ASwarm,WI_Config;
  169. APTR ST_Time,ST_Pop,ST_Client,ST_Blank,ST_Final;
  170. APTR CY_Speed,CY_Mouse;
  171. APTR SL_Wasps,SL_Bees,SL_Velo,SL_Tight;
  172. APTR CM_Cycle,CM_Aim,CM_JoyStick;
  173. APTR LV_Modes;
  174.  
  175. #define ID_OPEN_WINDOW    1L
  176. #define ID_CLOSE_WINDOW   2L
  177. #define ID_BLANK          3L
  178.  
  179. #define ID_TIMEOUT       10L
  180. #define ID_POPKEY        11L
  181. #define ID_CLIENTTIMEOUT 12L
  182. #define ID_BLANKKEY      13L
  183. #define ID_FINALTIMEOUT  14L
  184. #define ID_JOYSTICK      15L
  185.  
  186. #define ID_SPEED         20L
  187. #define ID_MOUSE         21L
  188. #define ID_WASPS         22L
  189. #define ID_BEES          23L
  190. #define ID_VELOCITY      24L
  191. #define ID_TIGHTNESS     25L
  192. #define ID_CYCLE         26L
  193. #define ID_AIM           27L
  194.  
  195. #define ID_MODES         30L
  196.  
  197. #define ID_LOAD_CONFIG   40L
  198. #define ID_SAVE_CONFIG   41L
  199. #define ID_ABOUT         42L
  200. #define ID_DEFAULTS      43L
  201.  
  202. char *CE_Speed[5],*CE_SpeedPreDef[] =
  203.  {
  204.   "Slow Motion","Very Slow","Slow",
  205.   "Normal","Fast","Very Fast","Incredible"
  206.  };
  207. char *CE_MouseBlank[] = {"Hardware","Window",NULL};
  208.  
  209. struct NewMenu NM_Config[] =
  210.  {NM_TITLE,"Project",NULL,0,0L,NULL,
  211.   NM_ITEM,"Load Config","L",0,0L,(APTR)ID_LOAD_CONFIG,
  212.   NM_ITEM,"Save Config","S",0,0L,(APTR)ID_SAVE_CONFIG,
  213.   NM_ITEM,NM_BARLABEL,NULL,0,0L,NULL,
  214.   NM_ITEM,"About ...",NULL,0,0L,(APTR)ID_ABOUT,
  215.   NM_ITEM,NM_BARLABEL,NULL,0,0L,NULL,
  216.   NM_ITEM,"Hide","H",0,0L,(APTR)ID_CLOSE_WINDOW,
  217.   NM_ITEM,"Quit","Q",0,0L,(APTR)MUIV_Application_ReturnID_Quit,
  218.   NM_TITLE,"Edit",NULL,0,0L,NULL,
  219.   NM_ITEM,"Reset To Defaults","D",0,0L,(APTR)ID_DEFAULTS,
  220.   NM_END,NULL,NULL,0,0L,NULL};
  221.  
  222. /*
  223.  
  224.    Definitions for our Commodity
  225.  
  226. */
  227.  
  228. CxObj *Broker,*PopKeyFilter,*BlankKeyFilter;
  229. struct MsgPort *CxPort;
  230. LONG CxPri,CxPopUp;
  231.  
  232.  
  233. UBYTE PopKey[128],BlankKey[128];
  234. LONG JoyStick;
  235.  
  236. #define EVENT_OPEN_WINDOW 4711L /* What is that number for, Tron ? */
  237. #define EVENT_BLANK       4712L
  238.  
  239. #define DEF_CX_PRI 0L
  240. #define DEF_POPKEY   "CONTROL ALT s"     /* Hot Key for the Edit Window */
  241. #define DEF_BLANKKEY "CONTROL ALT b"     /* Hot Key for immediate Blank */
  242.  
  243. LONG TimeLeft,InitTimeLeft,TimeOut,ClientTimeOut,FinalTimeOut;
  244.  
  245. #define MAX_TIMEOUT        3600L
  246. #define MAX_CLIENT_TIMEOUT 60L
  247. #define MAX_FINAL_TIMEOUT  3600L
  248.  
  249. #define DEF_TIMEOUT        60L
  250. #define DEF_CLIENT_TIMEOUT 5L
  251. #define DEF_FINAL_TIMEOUT  0L
  252.  
  253. #define SERVER_PRI 5L                 /* Don't change this, saves live */
  254. #define CLIENT_PRI -40L
  255.  
  256. /*
  257.  
  258.    Definitions for our Blanker Screen
  259.  
  260. */
  261.  
  262. CHIP(UWORD) EmptyPointer[] = {0,0,0,0}; /* Dummy Pointer when using the
  263.                                            One-Pixel-Window-Trick */
  264.  
  265. struct ModeNode
  266.  {
  267.   struct Node mn_Node;
  268.   UWORD mn_Index;
  269.   ULONG mn_DisplayID;
  270.   char mn_Name[DISPLAYNAMELEN];
  271.  };
  272.  
  273. struct List *ModeList;
  274. struct ModeNode *DisplayMode;
  275.  
  276. #define FindMode(l,n) ((struct ModeNode *)FindName(l,n))
  277.  
  278. #define DEF_MODE      HIRES
  279. #define DEF_MODE_NAME "HighRes"
  280.  
  281. /* Mini and Maximum definitions for possible parameters */
  282.  
  283. #define MAX_SPEED     4L
  284. #define MAX_WASPS     10L
  285. #define MAX_BEES      500L
  286. #define MAX_TIGHTNESS 10L
  287. #define MAX_VEL       15L
  288.  
  289. #define DEF_SPEED     4L
  290. #define DEF_WASPS     2L
  291. #define DEF_BEES      25L
  292. #define DEF_TIGHTNESS 5L
  293. #define DEF_VEL       5L
  294.  
  295. char *Template = /* extra extra extra long :-) */
  296.  "CX_PRIORITY/N/K,CX_POPKEY/K,CX_POPUP/S,BLANKKEY/K,SECONDS=TIMEOUT/N/K,"
  297.  "CLIENTTIMEOUT/N/K,DISPLAY/K,CYCLE/S,AIM/S,WASPS/N/K,BEES/N/K,SPEED/N/K,"
  298.  "TIGHTNESS/N/K,MOUSEBLANKMETHOD/K,VELOCITY/N/K,JOYSTICK/S,FINALTIMEOUT/N/K";
  299.  
  300. /*
  301.  
  302.     Definitions for Server/Client Communication
  303.  
  304. */
  305.  
  306. BYTE bsp_TimeOut,bsp_InputSig,bsp_ClientSig;
  307. struct Task *BlankerServerProcess;
  308.  
  309. #define MASK(n) (1L<<(n))
  310.  
  311. struct BlankerClientMsg
  312.  {
  313.   struct Message bcm_Message;
  314.   struct Screen *bcm_Screen;
  315.   LONG bcm_Status;
  316.   ULONG bcm_SigMask;
  317.   LONG bcm_Wasps,bcm_Bees,bcm_Speed,bcm_Tightness,bcm_Velocity;
  318.   LONG bcm_Cycle,bcm_AimMode,bcm_MouseBlank,bcm_FinalTimeOut;
  319.  } BlankerClientMsg;
  320.  
  321. /*
  322.  
  323.    Definitions or Swarm Movement
  324.  
  325. */
  326.  
  327. #define BEEACC  3
  328. #define BEEVELOC 2
  329. #define WASPACC 5
  330. #define WASPVELOC 5
  331. #define BORDER  20
  332. #define WASPVEL