home *** CD-ROM | disk | FTP | other *** search
- /*=========================================================================
- Star1.c -- This is the root module of the Star Chart program.
- It opens up all windows and initializes all the required tables.
- This module also includes the main IDCMP loop for the program. In
- that loop other modules are called to do the actual processing for
- searching and identifying stars and constellations.
-
- Credits for Star Chart:
- Robert L. Hill of the Orange County, CA. Amiga Friends User Group
- wrote the original version of StarChart in AmigaBasic
- The star data and many of the main functions of this
- version are derived from that program.
-
- Ray R. Larson wrote the c version 1.0 of StarChart, 'intuitionizing'
- and enhancing the speed and functions of the original.
- Version 1.2 (the present version) includes color
- controls, requesters for parameter file loading
- and saving, and use of the system clock in determining
- the time of day and date during startup. 1.2 also uses
- a sixteen color screen instead of the 8 colors used
- in 1.0 and 1.1
-
- Copyright (c) 1986 by Ray R. Larson
-
- This program may be freely distributed and copied, but may not be sold
- without the permission of the author. If you modify or enhance it,
- please include the above credits (and please send me a copy!).
-
- Ray R. Larson
- 6425 Central Ave. #304
- El Cerrito, CA 94530
-
- BitNet LARSON@UCBCMSA
- =========================================================================*/
- /*------------Header file for all of the standard stuff----*/
- /*-------------plus definitions of global structures-------*/
- #include "star.h"
-
- /* macros for checking userport and timerport bits */
- #define USERBIT 1L << w->UserPort->mp_SigBit
- #define TIMERBIT 1L << timerport->mp_SigBit
- /* macros for timer referencing */
- #define SECONDS tr_time.tv_secs
- #define MICROSECONDS tr_time.tv_micro
-
-
- /*------------ External function declarations ------------*/
-
- extern void *OpenLibrary();
- extern struct Screen *OpenScreen();
- extern struct Window *OpenWindow();
- extern struct IntuiMessage *GetMsg();
- extern struct MsgPort *CreatePort();
- extern struct IORequest *CreateExtIO();
-
- /*------------------ extern vars ------------------*/
-
- extern struct star_rec StarTable[];
- extern char *Greek[];
- extern struct cons_rec Constel[];
- extern struct Menu Titles[];
- extern SHORT ErrorMessCount;
-
- /*------------------- global variables -------------------*/
-
- struct GfxBase *GfxBase;
- struct IntuitionBase *IntuitionBase;
- LONG IconBase;
- LONG MathBase;
- LONG MathTransBase;
- struct RastPort *rp;
- struct Gadget *SelectedGadget;
- struct Window *w;
- struct Screen *scr; /* pointer to the custom screen - RRL */
- struct MsgPort *timerport; /* for timing signals */
- struct timerequest timermsg;
- UBYTE DefaultStartFile[140] = "DEFAULT.STAR";
- long mask;
-
- /*------------ Main Screen and Window Definitions ------------*/
-
- /* The main screen */
- struct NewScreen newscr =
- { 0, /* LeftEdge at zero */
- 0, /* TopEdge " */
- 640, /* Width - set later */
- 200, /* Height - non interlace */
- 4, /* depth - set later */
- 0, 1, /* DetailPen and BlockPen */
- HIRES, /* special display mode */
- CUSTOMSCREEN, /* The screen type */
- NULL, /* use the default font */
- (UBYTE *)"Star Chart: Version 1.2 ", /* Screen title */
- NULL, /* No special gadgets */
- NULL, /* Not a custom bitmap */
- };
-
- UBYTE WinTitle[] = "Star Chart : Version 1.2"; /* Window title */
-
- /* new window structure */
- struct NewWindow nw = {
- 0, 0, 640, 200, 0, 1,
-
- /* IDCMP Flags */
-
- MENUPICK
- | MOUSEMOVE
- | MOUSEBUTTONS
- | CLOSEWINDOW
- | GADGETDOWN
- | GADGETUP,
-
- /* Flags */
- WINDOWCLOSE
- | WINDOWDEPTH
- | ACTIVATE
- | REPORTMOUSE
- | RMBTRAP,
-
- NULL, /* First gadget */
- NULL, /* Checkmark */
- &WinTitle[0], /* Window title */
- NULL, /* No custom streen */
- NULL, /* Not a super bitmap window */
- 0, 0, 640, 200, /* Not used, but set up anyway */
- CUSTOMSCREEN
- };
-
-
- /*------------------- color table definitions ------------------*/
-
- UWORD defaultCT[32], CTable[32], *ctabptr;
- struct ColorMap *cmap;
-
- extern struct ViewPort *ViewPortAddress();
- struct ViewPort *vport;
- extern struct ColorMap *GetColorMap();
- extern struct Preferences *GetPrefs();
-
- extern struct WBStartup *WBenchMsg;
-
-
- /*=========================================================================
- Main routine of the StarChart program.
- ========================================================================*/
- main(argc,argv)
- int argc;
- char **argv;
- {
- /*---------------- local vars ---------------*/
- struct IntuiMessage *mes; /* Message pointer */
- ULONG class; /* Message class */
- USHORT code; /* Message code */
- SHORT mx, my; /* Mouse X and Y */
- APTR Iadr, adr; /* IAddress from Intuimessage */
- ULONG flgs; /* temp IDCMP flags */
- SHORT i;
- char *clarg;
- SHORT N_Bitplanes;
- BOOL menus_on, timeout, othermsg, fromWB, UpDateTime();
- struct FileLock *LastDir, *CurrentDir();
-
- /*--------------- Check for WB or command line args -------------*/
-
- fromWB = (argc == 0);
- if (fromWB)
- { if(WBenchMsg->sm_NumArgs > 1)
- strcpy(DefaultStartFile,WBenchMsg->sm_ArgList[1].wa_Name);
- }
- else /* started from CLI */
- { if (argc >= 2)
- strcpy(DefaultStartFile, argv[1]);
- }
-
-
- /*----------- Open up graphics library and Intuition ------------*/
- if ((GfxBase = (struct GfxBase *)
- OpenLibrary("graphics.library", NULL)) == NULL) {
- printf("no graphics library on disk\n");
- CloseThings();
- exit(100);
- }
- mask |= GRAPHICS;
-
- if ((IntuitionBase = (struct IntuitionBase *)
- OpenLibrary("intuition.library", NULL)) == NULL) {
- printf("No intuition library\n");
- CloseThings();
- exit(100);
- }
- mask |= INTUITION;
-
- if ((IconBase = (LONG)OpenLibrary(ICONNAME,NULL))==NULL) {
- printf("No Icon library!");
- CloseThings();
- exit(100);
- }
- mask |= ICONLIB;
-
- if ((MathBase = (LONG)OpenLibrary("mathffp.library",NULL))==NULL) {
- printf("No mathffp library!");
- CloseThings();
- exit(100);
- }
- mask |= MATHLIB;
-
- if ((MathTransBase = (LONG)OpenLibrary("mathtrans.library",NULL))==NULL) {
- printf("No mathtrans library!");
- CloseThings();
- exit(100);
- }
- mask |= MATHTRANS;
-
- if ((timerport = CreatePort(0L,0L)) == NULL) {
- printf("Can't create the timer port\n");
- CloseThings();
- exit(200);
- }
- mask |= TIMEPORT;
-
- /* open up the custom screen */
- if((scr = (struct Screen *)OpenScreen(&newscr)) == NULL)
- { printf("Can't open the custom screen!!\n");
- CloseThings();
- exit (3);
- }
- mask |= SCREEN;
-
- /* Set window pointer to the custom screen */
-
- nw.Screen = scr ;
-
-
- /*----------- open window ----------*/
- if ((w = OpenWindow(&nw)) == NULL) {
- printf("Cannot open window\n");
- CloseThings();
- }
- mask |= WINDOW;
-
- /* ------------- Initialize some Globals, Menus, etc. -------------*/
- /* set the raster port */
- rp = w->RPort;
-
- /* set the viewport address */
- vport = ViewPortAddress(w);
-
- /* copy the default colortable */
- cmap = vport->ColorMap;
- ctabptr = (UWORD *) cmap->ColorTable;
- for (i=0; i < 32; i++)
- defaultCT[i] = CTable[i] = ctabptr[i];
- CTable[0] = 0x05A; /* register 0 is dark blue */
- CTable[1] = 0xFFF; /* register 1 is white */
- CTable[2] = 0x002; /* register 2 is Black (almost) */
- CTable[3] = 0xFFF; /* register 4 is white */
- CTable[4] = 0xEEE; /* register 5 is darker */
- CTable[5] = 0xDDD; /* register 6 is darker */
- CTable[6] = 0xCCC; /* register 7 is darrker */
- CTable[7] = 0xBBB; /* register 8 is darker */
- CTable[8] = 0xAAA; /* register 9 is darker */
- CTable[9] = 0x999; /* register 10 is darker */
- CTable[10] = 0x888; /* register 11 is medium gray */
- CTable[11] = 0xF11; /* reqister 3 is bright red - */
- CTable[12] = 0x00B; /* register 12 is dark blue */
- CTable[13] = 0xF0F; /* register 13 is magenta */
- CTable[14] = 0xFFF; /* register 14 is also white */
- CTable[15] = 0xF80; /* register 15 is Orange */
-
-
- /* change the registers to the new colors */
- LoadRGB4(vport,&CTable,32L);
-
- mask |= COLORMAP;
-
- SetMenuStrip(w,Titles); /* Init the Menus */
- mask |= MENU;
- menus_on = FALSE; /* flag for interpreting mousemoves */
-
- /* initialize the timer port */
- init_timer();
-
- /* set up some other globals(in starglb.c) and display the default stars */
- initialize();
-
- /* build the constellations menu */
- InitConMenu();
-
- /* change to the star pointer sprite */
- do_StarSprite(w);
-
- /* set the timer to go off in 1 second */
- set_timer(&timermsg,1L,0L);
- timeout = FALSE;
-
- /* --------------- main loop -----------------*/
- for (;;)
- {
- othermsg = FALSE;
-
- if (timeout == TRUE)
- {
- timeout = FALSE;
- /* increment the date/time display */
- /* and redisplay stars each 'hour' */
- if(UpdateTime()) DisplayStars();
- set_timer(&timermsg,1L,0L);
- if (ErrorMessCount > 0) /* time the error message */
- { ErrorMessCount--;
- if (ErrorMessCount == 0)
- SetWindowTitles(w,WinTitle,(UBYTE *)-1);
- }
- }
-
- if ((mes = GetMsg(w->UserPort)) == NULL)
- {
- Wait((USERBIT) | (TIMERBIT));
- if (GetMsg(timerport)) timeout = TRUE;
- continue;
- }
-
- if (mes == NULL) continue;
- class = mes->Class;
- code = mes->Code;
- mx = mes->MouseX;
- my = mes->MouseY;
- Iadr = mes->IAddress;
- ReplyMsg(mes);
-
-
- switch (class) {
-
- case CLOSEWINDOW: CloseThings(); exit(NULL); break;
-
- case GADGETUP: /* do nothing for now - except note that*/
- /* the gadget was selected. */
- SelectedGadget = (struct Gadget *)Iadr;
- break;
-
- case MENUPICK: /* Do menu processing (in star2.c) */
- if (code != MENUNULL)
- Do_menu((LONG)MENUNUM(code),
- (LONG)ITEMNUM(code),
- (LONG)SUBNUM(code));
- break;
-
- case GADGETDOWN: /* do nothing for now - except note that*/
- /* the gadget was selected. */
- SelectedGadget = (struct Gadget *)Iadr;
- break;
-
- case MOUSEBUTTONS: /* Handle mouse clicks, i.e. identify star or */
- /* constellations based on the position of the*/
- /* mouse pointer. (In Star5.c) */
- Do_buttons(code,mx,my);
- break;
-
- case MOUSEMOVE: /* Handle mouse moves to see if the pointer is */
- /* in the menu area - if so, permit selection */
- if (my < 10)
- { if (menus_on == FALSE)
- {menus_on = TRUE;
- Forbid();
- w->Flags &= ~RMBTRAP;
- Permit();
- ClearPointer(w);
- }
- }
- else
- if (menus_on)
- { menus_on = FALSE;
- Forbid();
- w->Flags |= RMBTRAP;
- Permit();
- do_StarSprite(w);
- }
- break;
-
-
- } /* end of class switch */
- } /* end of for(ever) loop */
- }/* end of main */
-
- /*========================================================================
- init_timer - opens up the timer device for use.
- ========================================================================*/
- init_timer()
- { return(OpenDevice(TIMERNAME,UNIT_VBLANK,&timermsg,0L));
- }
-
- /*========================================================================
- set_timer - Sets the timer device to respond in the given number of
- seconds and/or microseconds.
- ========================================================================*/
- set_timer(tm,sec,micro)
- struct timerequest *tm;
- ULONG sec,micro;
- {
- tm->tr_node.io_Command = TR_ADDREQUEST;
- tm->SECONDS = sec;
- tm->MICROSECONDS = micro;
- tm->tr_node.io_Flags = 0;
- tm->tr_node.io_Error = 0;
- tm->tr_node.io_Message.mn_ReplyPort = timerport;
- SendIO(tm);
- return (0);
- }
-
- /*========================================================================
- CloseThings - Function that closes everything properly if any failures
- occur before main loop entry,
- ======================================================================*/
- CloseThings()
- {
- /* change the color registers back to default colors */
- if (mask & COLORMAP) LoadRGB4(vport,&defaultCT,32L);
- if (mask & MENU) ClearMenuStrip(w);
- if (mask & WINDOW) CloseWindow(w);
- if (mask & SCREEN) CloseScreen(scr);
- if (mask & ICONLIB) CloseLibrary(IconBase);
- if (mask & MATHLIB) CloseLibrary(MathBase);
- if (mask & MATHTRANS) CloseLibrary(MathTransBase);
- if (mask & TIMEPORT) DeletePort(timerport);
- if (mask & INTUITION) CloseLibrary(IntuitionBase);
- if (mask & GRAPHICS) CloseLibrary(GfxBase);
-
-
- }
-