home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / xaes_new / startup.c < prev    next >
C/C++ Source or Header  |  1994-12-24  |  6KB  |  249 lines

  1. /********************************************************************
  2.  *                                                                1.10*
  3.  *    WinLIB PRO Revision II: Initialize and Terminate                *
  4.  *    by Ken Hollis                                                    *
  5.  *                                                                    *
  6.  *    Copyright (c) 1994, Bitgate Software.  All Rights Reserved.        *
  7.  *                                                                    *
  8.  *    These are the startup and termination routines.  These will be    *
  9.  *    fixed for MultiTOS (if they ever get their act together), but    *
  10.  *    as of now, they are not compatible.  I may take a look at        *
  11.  *    Enhanced GEM's routines and incorporate some ideas...            *
  12.  *                                                                    *
  13.  *    (Yes, I have MultiTOS 4.1 and it DOES NOT WORK WITH XAES!!!)    *
  14.  *                                                                    *
  15.  ********************************************************************/
  16.  
  17. #include <stddef.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <tos.h>
  21.  
  22. #include "xaes.h"
  23. #include "nkcc.h"
  24.  
  25. const char __ident_xaes[] = "$Id: XAES Version 1.00 R1 $";
  26.  
  27. MFDB screen;
  28. int GenevaInstalled;
  29.  
  30. int colorsave1, colorsave2, colorsave3;
  31.  
  32. GLOBAL int WInit(int DeskWndDispatcher(WINDOW *, int[]),
  33.                  int MainDispatcher(int[]),
  34.                  int KeyDispatcher(int), char *prgname, char *header,
  35.                  BOOL HandleCallBacks)
  36. {
  37.     int extnd_out[57], attr[10], work_out[57], i;
  38.     static int work_in[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2};
  39.  
  40.     Ap_ID = appl_init();
  41.  
  42.     work_in[0] = graf_handle(&gr_cw, &gr_ch, &gr_bw, &gr_bh);
  43.     v_opnvwk(work_in, &VDIhandle, work_out);
  44.  
  45.     for (i = 0; i < MAX_WINDOWS; i++) {
  46.         owned_winds[i].handle = i;
  47.         owned_winds[i].owner = W_NOTOWNER;
  48.     }
  49.  
  50.     if (CheckMultitask()) {
  51.         form_alert(1, "[1][Sorry, WinLIB does not work|under the MultiTOS|environment.  It may|in a later release, but|not now!][ Oh well ]");
  52.         appl_exit();
  53.         v_clsvwk(VDIhandle);
  54.         exit(FAIL);
  55.     }
  56.  
  57. /* Geneva REALLY does some WIERD shit with VDI.  This is a fix. */
  58.     GenevaInstalled = (find_cookie('Gnva') != NULL) ? TRUE : FALSE;
  59.  
  60.     if (!(WindowChain = malloc(sizeof(WINDOW))))    /* Allocate memory for WindowChain */
  61.         return FALSE;
  62.  
  63.     WindowChain->next = NULL;
  64.     WindowChain->prev = NULL;
  65.  
  66.     wind_get(0, WF_WORKXYWH, &desk.g_x, &desk.g_y, &desk.g_w, &desk.g_h);
  67.     wind_get(0, WF_CURRXYWH, &WindowChain->size.g_x, &WindowChain->size.g_y, &WindowChain->size.g_w, &WindowChain->size.g_h);
  68.  
  69.     WindowChain->WndDispatcher = malloc(sizeof(DeskWndDispatcher));
  70.     WindowChain->WndDispatcher = DeskWndDispatcher;
  71.  
  72.     WindowChain->handle = 0;
  73.     WindowChain->state = W_OPEN | W_DESKTOP;
  74.     WindowChain->tree = NULL;
  75.     WindowChain->wind = NULL;
  76.     WindowChain->timer.status = T_NOTEXIST;
  77.     WindowChain->style = 0;
  78.  
  79.     WindowChain->kind = 0;
  80.  
  81.     VDIhandle = graf_handle(&gr_cw, &gr_ch, &gr_bw, &gr_bh);
  82.  
  83.     _MainDispatcher = malloc(sizeof(MainDispatcher));
  84.     _MainKeyDispatcher = malloc(sizeof(KeyDispatcher));
  85.  
  86.     _MainDispatcher = MainDispatcher;
  87.     _MainKeyDispatcher = KeyDispatcher;
  88.  
  89.     Life = TRUE;
  90.  
  91.     if (gr_cw < 7 || gr_ch < 7) {
  92.         image_w = gr_cw << 1;
  93.         image_h = gr_ch;
  94.         big_img = FAIL;
  95.     } else
  96.         if (gr_ch > 14) {
  97.             image_w = image_h = 16;
  98.             big_img = TRUE;
  99.         } else {
  100.             image_w = 16;
  101.             image_h = 8;
  102.             big_img = FALSE;
  103.         }
  104.  
  105. /* Since there are no internal images yet, there will not be this
  106.    option for the time being. */
  107. /*    init_images(); */
  108.  
  109.     ReadConfig();
  110.  
  111.     vq_extnd(VDIhandle, 1, extnd_out);
  112.     init_mfdb(&screen, NULL, desk.g_w, desk.g_h, 0, work_out[4]);
  113.  
  114.     vqt_attributes(VDIhandle, attr);
  115.     num_planes = extnd_out[4];
  116.     num_colors = work_out[13];
  117.     large_font = attr[7];
  118.     color_font = attr[1];
  119.     small_font = work_out[46];
  120.  
  121.     if (header) {
  122.         prgnameheader = malloc(strlen(header) + 2);
  123.         strcpy(prgnameheader, header);
  124.         strcat(prgnameheader, ": ");
  125.     } else
  126.         prgnameheader = strdup("");
  127.  
  128.     if (AES_VERSION >= 0x0400) {
  129.         shel_write(9, 0, 0x01, NULL, NULL);
  130.         if (_app && prgname)
  131.             menu_register(Ap_ID, prgname);
  132.     }
  133.  
  134.     WindowChain->tree = NULL;
  135.  
  136.     WInitCustomWindow();
  137.     WSetupWinPopups();
  138.  
  139.     nkc_init(NKI_NO200HZ, VDIhandle);
  140.  
  141.     if (HandleCallBacks) {
  142.         XCallInitializeCallback;
  143.         XCallStartupCallback;
  144.     }
  145.  
  146.     colorsave1 = colorsave2 = colorsave3 = 0;
  147.  
  148.     if ((num_colors == 4) && (xaes.config1 & X_MEDEMUL)) {
  149.         colorsave1 = Setcolor(3, 0x333);
  150.         colorsave2 = Setcolor(2, 0x555);
  151.         colorsave3 = Setcolor(1, 0x777);
  152.     }
  153.  
  154. /*    Nice little debugging check by yours truly...  :-) */
  155. #ifdef DEBUG
  156.     if (!(xaes.config1 & X_MEDEMUL)) {
  157.         int cs1, cs2, cs3;
  158.  
  159.         cs1 = Setcolor(3, -1);
  160.         cs2 = Setcolor(2, -1);
  161.         cs3 = Setcolor(1, -1);
  162.  
  163.         if ((cs1 == 0x333) && (cs2 == 0x555) && (cs3 == 0x777))
  164.             form_alert(1, "[3][Hmmm...  These colors look|familiar.  Did XAES|possibly just recently|crash on you?][ Okay ]");
  165.     }
  166. #endif
  167.  
  168.     return TRUE;
  169. }
  170.  
  171. GLOBAL void WBoot()
  172. {
  173.     GlobInits.Initialize = NULL;
  174.     GlobInits.Deinitialize = NULL;
  175.     GlobInits.Startup = NULL;
  176.     GlobInits.Exit = NULL;
  177. }
  178.  
  179. GLOBAL int WTerm(BOOL HandleCallBacks)
  180. {
  181.     WKillAllWindows(K_NO_STOP);
  182.  
  183.     if (prgnameheader)    
  184.         free(prgnameheader);
  185.  
  186.     if (_MainDispatcher)
  187.         free(_MainDispatcher);
  188.  
  189.     if (_MainKeyDispatcher)
  190.         free(_MainKeyDispatcher);
  191.  
  192.     if (WindowChain)
  193.         free(WindowChain);
  194.  
  195.     if (HandleCallBacks) {
  196.         XCallDeinitializeCallback;
  197.         XCallExitCallback;
  198.     }
  199.  
  200.     ClearCallbacks();
  201.  
  202.     vsl_color(VDIhandle, BLACK);
  203.  
  204.     if ((num_colors == 4) && (xaes.config1 & X_MEDEMUL)) {
  205.         Setcolor(3, colorsave1);
  206.         Setcolor(2, colorsave2);
  207.         Setcolor(1, colorsave3);
  208.     }
  209.  
  210.     v_clsvwk(VDIhandle);
  211.     if (!appl_exit()) {
  212.         if (CheckMultitask() || CheckPowerDOS())
  213.             form_alert(1, "[3][Cannot close terminate|parent process!][ Okay ]");
  214.         else
  215.             form_alert(1, "[3][Cannot terminate this|program!][ Okay ]");
  216.  
  217.         return FALSE;
  218.     }
  219.  
  220.     if (nkc_exit())
  221.         form_alert(1, "[3][Cannot terminate:   |NKCC not de-initialized][OK]");
  222.  
  223.     exit(Return);
  224.  
  225.     return TRUE;
  226. }
  227.  
  228. GLOBAL void WDie(int returns)
  229. {
  230.     switch(returns) {
  231.         case FORCE_EXIT:
  232.             if (form_alert(1, "[3][Force exit| |Are you sure?][ Okay | Cancel ]") == 1) {
  233.                 Life = FALSE;
  234.                 Return = 0;
  235.             }
  236.             break;
  237.  
  238.         case FORCE_EXIT_ABS:
  239.             Life = FALSE;
  240.             Return = 0;
  241.             break;
  242.  
  243.         default:
  244.             Life = FALSE;
  245.             Return = returns;
  246.             break;
  247.     }
  248. }
  249.