home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LPTHEX.ZIP / LPTHEX.C < prev    next >
C/C++ Source or Header  |  1992-09-23  |  134KB  |  2,979 lines

  1. /*
  2.          This OS/2 Presentation Manager program generates and prints mazes in
  3.     three dimensions.  It demonstrates device independent printing under OS/2
  4.     2.0.
  5.  
  6.          This program was written by James L. Dean.  It was completed on
  7.     August 31, 1992.
  8.  
  9.          Its help facility borrows heavily from the Sorting Algorithm Sample
  10.     in the IBM Developer's Toolkit for OS/2 2.0.  Its printing facility
  11.     borrows heavily from the Print Sample in the IBM Developer's Toolkit for
  12.     OS/2 and David E. Reich's "Programming Printing Under OS/2" in the Winter
  13.     1992 issue of IBM Personal Systems Developer.
  14. */
  15.  
  16. #include <stdio.h>
  17. #define INCL_WIN
  18. #define INCL_HELP
  19. #define INCL_GPI
  20. #define INCL_PM
  21. #define INCL_DOS
  22. #define INCL_SPLDOSPRINT
  23. #define INCL_ERRORS
  24. #include <os2.h>
  25. #include <stdlib.h>
  26. #include <malloc.h>
  27. #include <math.h>
  28. #include <string.h>
  29. #include <memory.h>
  30. #include "lpthex.h"
  31.  
  32. #define RESOLUTION             4
  33. #define NUM_COLORS            16
  34. #define WIDTH_OF_ROOM         15        /* millimeters */
  35. #define WM_PLOT_DONE          WM_USER
  36.  
  37. typedef struct
  38.           {
  39.             unsigned char red;
  40.             unsigned char green;
  41.             unsigned char blue;
  42.           } rgb_rec;
  43.  
  44. typedef struct stack_rec_record
  45.           {
  46.             char          index_1;
  47.             int           index_2;
  48.           } stack_rec;
  49.  
  50. typedef struct
  51.           {
  52.             double x;
  53.             double y;
  54.             double z;
  55.           } vertex_rec;
  56.  
  57.        MRESULT EXPENTRY about_lpthex(HWND,ULONG,MPARAM,MPARAM);
  58. static void             adjust_perspective(volatile int,volatile int,
  59.                          volatile float * volatile,volatile float * volatile,
  60.                          volatile float * volatile,volatile double,
  61.                          volatile double,volatile double,volatile double,
  62.                          volatile double);
  63.        MRESULT EXPENTRY client_window_proc(HWND,ULONG,MPARAM,MPARAM);
  64. static void             destroy_maze(volatile float * volatile *,
  65.                          volatile float * volatile *,
  66.                          volatile float * volatile *,volatile int * volatile *,
  67.                          volatile int * volatile *,
  68.                          volatile unsigned char * volatile *,
  69.                          volatile stack_rec * volatile *);
  70. static ULONG            display_msg(HWND,ULONG,ULONG,BOOL);
  71. static void             draw_line_on_page(int,int,int,int);
  72. static void             evaluate_and_transform(volatile double,volatile double,
  73.                          volatile double,volatile double,volatile int,
  74.                          volatile int,volatile double,volatile double,
  75.                          volatile float * volatile,volatile float * volatile,
  76.                          volatile float * volatile,volatile double *,
  77.                          volatile double *,volatile double *,
  78.                          volatile double *,volatile double *,
  79.                          volatile vertex_rec *,volatile int * volatile,
  80.                          volatile int * volatile);
  81. static double           f(double,double);
  82. static void             generate_maze(void);
  83. static void             hash(int *,int *,int *,int *,int *,int *,int *,int *);
  84. static void             increment(int *,int *,int *,int *,int *,int *,int *,
  85.                          int *);
  86. static void             initialize_help(void);
  87.        int              main(void);
  88. static int              memory_allocated(volatile long,
  89.                          volatile float * volatile *,
  90.                          volatile float * volatile *,
  91.                          volatile float * volatile *,
  92.                          volatile int * volatile *,
  93.                          volatile int * volatile *,
  94.                          volatile unsigned char * volatile *,volatile int,
  95.                          volatile stack_rec * volatile *);
  96. static void             plot(volatile int,volatile int * volatile,
  97.                          volatile int,volatile int * volatile,
  98.                          volatile long,volatile float * volatile,
  99.                          volatile float * volatile,volatile double,
  100.                          volatile double,volatile double,volatile double,
  101.                          volatile unsigned char * volatile);
  102.        MRESULT EXPENTRY printer_setup(HWND,ULONG,MPARAM,MPARAM);
  103. static void             set_point_on_page(int,int);
  104. static void             shade(volatile int,volatile int,
  105.                          volatile float * volatile,volatile float * volatile,
  106.                          volatile float * volatile,
  107.                          volatile unsigned char * volatile,
  108.                          volatile vertex_rec *);
  109. static void             size_maze(void *);
  110. static void             solve_maze(volatile stack_rec * volatile,
  111.                          volatile char * volatile * volatile,int *,int *,
  112.                          volatile int,volatile int);
  113. static void             sort_back_to_front(volatile long,
  114.                          volatile float * volatile,volatile int * volatile,
  115.                          volatile int * volatile);
  116.  
  117.  
  118. static volatile double                              aspect_ratio = 0.0;
  119. static volatile char          * volatile * volatile base_page
  120.  = (volatile char * volatile * volatile) NULL;
  121.        volatile PRQINFO3      * volatile            best_queue_info_ptr
  122.  = (volatile PRQINFO3 * volatile) NULL;
  123. static volatile unsigned char * volatile            color
  124.  = (volatile unsigned char * volatile) NULL;
  125. static volatile char          * volatile            default_queue_buffer
  126.  = (volatile char * volatile) NULL;
  127. static volatile int                                 delta_x [6] [720]
  128.  ={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  129.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  130.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  131.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  132.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  133.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  134.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  135.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  136.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  244.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  245.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  246.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  247.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  248. static volatile int                                 delta_y [6] [720]
  249.  ={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  250.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  251.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  252.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  253.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  254.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  255.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  256.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  257.  0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  364.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  365.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  366.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  367.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  368.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  369.        volatile HDC                                 dev_context_handle
  370.  = (HDC) 0;
  371. static volatile int                                 display_titillator = 0;
  372.        volatile HAB                                 hAB = (HAB) 0;
  373.        volatile HAB                                 habPrint = (HAB) 0;
  374.        volatile BOOL                                help_enabled = (BOOL) 0;
  375.        volatile HPS                                 hPS = (HPS) 0;
  376. static volatile HWND                                hwndClient = (HWND) 0;
  377. static volatile HWND                                hwndFrame = (HWND) 0;
  378. static volatile HWND                                hwndHelpInstance = (HWND) 0;
  379. static volatile int                                 iMaxX = 0;
  380. static volatile int                                 iMaxY = 0;
  381. static volatile CHAR                                lib_name
  382.  [HELP_LIB_NAME_LENGTH] 
  383.  = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  384.  ' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
  385. static volatile vertex_rec                          light = {0.0,0.0,0.0};
  386. static volatile int                                 max_x = 0;
  387. static volatile int                                 max_x_plus_1 = 0;
  388. static volatile int                                 max_y = 0;
  389. static volatile int                                 max_y_plus_1 = 0;
  390. static volatile int                                 num_columns = 0;
  391. static volatile long                                num_primes = 0l;
  392. static volatile int                                 num_rooms_in_maze = 0;
  393. static volatile int                                 num_rows = 0;
  394. static volatile int                                 num_x_divisions = 0;
  395. static volatile int                                 num_x_dots = 0;
  396. static volatile int                                 num_y_divisions = 0;
  397. static volatile int                                 num_y_dots = 0;
  398. static volatile char          * volatile            old_setup_queue_buffer
  399.  = (volatile char * volatile) NULL;
  400. static volatile char          * volatile * volatile page
  401.  = (volatile char * volatile * volatile) NULL;
  402.        volatile HWND                                plot_hwnd = (HWND) 0;
  403. static volatile int                                 r_n [8]
  404.  = {0,0,0,0,0,0,0,0};
  405. static volatile int                                 r_n_seed [7]
  406.  = {0,0,0,0,0,0,0};
  407. static volatile double                              rotation = 0.0;
  408. static volatile char          * volatile            setup_queue_buffer
  409.  = (volatile char * volatile) NULL;
  410.        volatile HEV                                 size_maze_active = (HEV) 0;
  411. static volatile int                                 size_maze_kill = 0;
  412. static volatile ULONG                               size_maze_post_count 
  413.  = (ULONG) 0;
  414. static volatile ULONG                               sizing = (ULONG) 0;
  415. static volatile stack_rec     * volatile            stack
  416.  = (volatile stack_rec * volatile) NULL;
  417. static volatile double                              tilt = 0.0;
  418. static volatile char                                titillator [36]
  419.  ={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  420.  ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
  421. static volatile CHAR                                window_title 
  422.  [HELP_LIB_NAME_LENGTH]
  423.  = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  424.  ' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
  425. static volatile int           * volatile            x_division_index
  426.  = (volatile int * volatile) NULL;
  427. static volatile int                                 x_dot_max = 0;
  428. static volatile double                              x_max = 0.0;
  429. static volatile double                              x_min = 0.0;
  430. static volatile float         * volatile            x_prime
  431.  = (volatile float * volatile) NULL;
  432. static volatile double                              x_prime_max = 0.0;
  433. static volatile int           * volatile            y_division_index
  434.  = (volatile int * volatile) NULL;
  435. static volatile int                                 y_dot_max = 0;
  436. static volatile double                              y_max = 0.0;
  437. static volatile double                              y_min = 0.0;
  438. static volatile float         * volatile            y_prime
  439.  = (volatile float * volatile) NULL;
  440. static volatile double                              y_prime_max = 0.0;
  441. static volatile double                              y_prime_min = 0.0;
  442. static volatile float         * volatile            z_prime
  443.  = (volatile float * volatile) NULL;
  444. static volatile double                              z_prime_max = 0.0;
  445. static volatile double                              z_prime_min = 0.0;
  446.  
  447. int main(void)
  448.   {
  449.            POINTL aptl [TXTBOX_COUNT]
  450.      ={{0l,0l},{0l,0l},{0l,0l},{0l,0l},{0l,0l}};
  451.            ULONG  ctldata = (ULONG) 0;
  452.            HMQ    hmq = (HMQ) 0;
  453.            HPS    hps = (HPS) 0;
  454.            QMSG   qmsg
  455.      ={(HWND) 0,(ULONG) 0,(MPARAM) 0,(MPARAM) 0,(ULONG) 0,{0l,0l}};
  456.     static CHAR   szClientClass [] = "3D Maze";
  457.  
  458.     titillator[0]='\0';
  459.     display_titillator=FALSE;
  460.     DosCreateEventSem((PSZ) NULL,(PHEV) &size_maze_active,(ULONG) 0,(BOOL32) 1);
  461.     hAB=WinInitialize((ULONG) 0);
  462.     hmq=WinCreateMsgQueue(hAB,0l);
  463.     WinRegisterClass(hAB,(PSZ) szClientClass,(PFNWP) client_window_proc,
  464.      (ULONG) CS_SIZEREDRAW,(ULONG) 0);
  465.     ctldata=FCF_STANDARD;
  466.     hwndFrame=WinCreateStdWindow((HWND) HWND_DESKTOP,(ULONG) WS_VISIBLE,
  467.      &ctldata,(PSZ) szClientClass,(PSZ) NULL,(ULONG) 0,(HMODULE) NULL,
  468.      (ULONG) ID_MAINMENU,(PHWND) &hwndClient);
  469.     hps=WinGetPS(hwndFrame);
  470.     GpiQueryTextBox(hps,18,"XXXXXXXXXXXXXXXXXX",TXTBOX_COUNT,aptl);
  471.     WinReleasePS(hps);
  472.     WinSetWindowPos(hwndFrame,(HWND) NULL,0l,0l,
  473.      20*(aptl[TXTBOX_BOTTOMRIGHT].x-aptl[TXTBOX_BOTTOMLEFT].x)/18,
  474.      5*(aptl[TXTBOX_TOPLEFT].y-aptl[TXTBOX_BOTTOMLEFT].y),SWP_SIZE);
  475.     WinStartTimer(hAB,hwndClient,1,300);
  476.     initialize_help();
  477.     while (WinGetMsg((HAB) hAB,(PQMSG) &qmsg,(HWND) NULL,(ULONG) 0,(ULONG) 0))
  478.      WinDispatchMsg((HAB) hAB,(PQMSG) &qmsg);
  479.     if (hwndHelpInstance != 0)
  480.       WinDestroyHelpInstance(hwndHelpInstance);
  481.     WinStopTimer(hAB,hwndClient,1);
  482.     WinDestroyWindow((HWND) hwndFrame);
  483.     WinDestroyMsgQueue((HMQ) hmq);
  484.     WinTerminate((HAB) hAB);
  485.     return(0);
  486.   }
  487.  
  488. MRESULT EXPENTRY client_window_proc(
  489.   HWND   hwnd,
  490.   ULONG  msg,
  491.   MPARAM mp1,
  492.   MPARAM mp2)
  493.     {
  494.       DATETIME     dateSeed
  495.        ={(UCHAR) 0,(UCHAR) 0,(UCHAR) 0,(UCHAR) 0,(UCHAR) 0,(UCHAR) 0,
  496.        (USHORT) 0,(SHORT) 0,(UCHAR) 0};
  497.       DEVOPENSTRUC dev_open_data
  498.        ={(PSZ) NULL,(PSZ) NULL,(PDRIVDATA) NULL,(PSZ) NULL,(PSZ) NULL,
  499.        (PSZ) NULL,(PSZ) NULL,(PSZ) NULL,(PSZ) NULL};
  500.       PHCINFO      forms_info_ptr = (PHCINFO) NULL;
  501.       LONG         form_num = 0l;
  502.       HPS          hps = (HPS) 0;
  503.       ULONG        max_min_pixels = (ULONG) 0;
  504.       ULONG        min_pixels = (ULONG) 0;
  505.       LONG         num_forms = 0l;
  506.       ULONG        num_queue_items_available = (ULONG) 0;
  507.       ULONG        num_queue_items_returned = (ULONG) 0;
  508.       ULONG        queue_buffer_size = (ULONG) 0;
  509.       ULONG        queue_buffer_size_needed = (ULONG) 0;
  510.       PPRQINFO3    queue_info_ptr = (PPRQINFO3) NULL;
  511.       ULONG        queue_item_num = (ULONG) 0;
  512.       ULONG        rc = (ULONG) 0;
  513.       RECTL        rcl = {0l,0l,0l,0l};
  514.       MRESULT      result = (MRESULT) 0;
  515.   
  516.       switch (msg)
  517.         {
  518.           case HM_QUERY_KEYS_HELP:
  519.             result=(MRESULT) HELP_KEYSHELP;
  520.             break;
  521.           case WM_COMMAND:
  522.             switch (COMMANDMSG(&msg)->cmd)
  523.               {
  524.                 case IDM_CANCEL:
  525.                   DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  526.                   if (sizing == (ULONG) 0)
  527.                     {
  528.                       size_maze_kill=TRUE;
  529.                       DosWaitEventSem((HEV) size_maze_active,
  530.                        (ULONG) SEM_INDEFINITE_WAIT);
  531.                     }
  532.                   strcpy((unsigned char *) &titillator[0],"Cancelled!");
  533.                   WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  534.                    FID_MENU),MM_SETITEMATTR,MPFROM2SHORT(IDM_SETUP,TRUE),
  535.                    MPFROM2SHORT(MIA_DISABLED,0));
  536.                   WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  537.                    FID_MENU),MM_SETITEMATTR,MPFROM2SHORT(IDM_PRINT,TRUE),
  538.                    MPFROM2SHORT(MIA_DISABLED,0));
  539.                   WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  540.                    FID_MENU),MM_SETITEMATTR,MPFROM2SHORT(IDM_CANCEL,TRUE),
  541.                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  542.                   break;
  543.                 case IDM_GENERALHELP:
  544.                   if (help_enabled)
  545.                     if (WinSendMsg(hwndHelpInstance,HM_EXT_HELP,NULL,NULL))
  546.                       display_msg(hwndClient,IDMSG_HELPDISPLAYERROR,
  547.                        ((ULONG) MB_OK)|((ULONG) MB_ERROR),FALSE);
  548.                   break;
  549.                 case IDM_HELPINDEX:
  550.                   if (help_enabled)
  551.                     if (WinSendMsg(hwndHelpInstance,HM_HELP_INDEX,NULL,NULL))
  552.                       display_msg(hwndClient,IDMSG_HELPDISPLAYERROR,
  553.                        ((ULONG) MB_OK)|((ULONG) MB_ERROR),FALSE);
  554.                   break;
  555.                 case IDM_HELPPRODUCTINFO:
  556.                   WinDlgBox(HWND_DESKTOP,hwndClient,about_lpthex,(HMODULE) 0,
  557.                    IDD_PRODUCTINFO,NULL);
  558.                   break;
  559.                 case IDM_PRINT:
  560.                   WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  561.                    FID_MENU),MM_SETITEMATTR,MPFROM2SHORT(IDM_SETUP,TRUE),
  562.                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  563.                   WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  564.                    FID_MENU),MM_SETITEMATTR,MPFROM2SHORT(IDM_PRINT,TRUE),
  565.                    MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  566.                   habPrint=WinInitialize((ULONG) 0);
  567.                   dev_open_data.pszLogAddress
  568.                    =(*best_queue_info_ptr).pszName;
  569.                   dev_open_data.pszDriverName
  570.                    =(*best_queue_info_ptr).pszDriverName;
  571.                   dev_open_data.pszDriverName[
  572.                    strcspn(dev_open_data.pszDriverName,".")]='\0';
  573.                   dev_open_data.pdriv=(*best_queue_info_ptr).pDriverData;
  574.                   dev_open_data.pszDataType="PM_Q_STD";
  575.                   dev_open_data.pszComment="LPTHEX";
  576.                   dev_open_data.pszQueueProcName=NULL;
  577.                   dev_open_data.pszQueueProcParams="XFM=0";
  578.                   dev_open_data.pszSpoolerParams=NULL;
  579.                   dev_open_data.pszNetworkParams=NULL;
  580.                   dev_context_handle=DevOpenDC(habPrint,OD_QUEUED,(PSZ) "*",9l,
  581.                    (PDEVOPENDATA) &dev_open_data,(HDC) NULL);
  582.                   num_forms=DevQueryHardcopyCaps(dev_context_handle,0l,0l,
  583.                    (PHCINFO) NULL);
  584.                   forms_info_ptr=(PHCINFO) 
  585.                    malloc(((unsigned int) num_forms)*sizeof(HCINFO));
  586.                   rc=(ULONG) DevQueryHardcopyCaps(
  587.                    dev_context_handle,0l,num_forms,forms_info_ptr);
  588.                   form_num=0;
  589.                   while ((form_num < num_forms)
  590.                   &&     ((((ULONG) forms_info_ptr[form_num].flAttributes)
  591.                             & ((ULONG) HCAPS_CURRENT)) 
  592.                             != ((ULONG) HCAPS_CURRENT)))
  593.                     form_num++;
  594.                   iMaxX=forms_info_ptr[form_num].xPels;
  595.                   iMaxY=forms_info_ptr[form_num].yPels;
  596.                   num_columns
  597.                    =(int) (2*(forms_info_ptr[form_num].xRightClip
  598.                    -forms_info_ptr[form_num].xLeftClip)/(3*WIDTH_OF_ROOM));
  599.                   num_columns=2*num_columns-1;
  600.                   num_rows=(int) ((2.0/sqrt(3.0))
  601.                    *((double) (forms_info_ptr[form_num].yTopClip
  602.                    -forms_info_ptr[form_num].yBottomClip))
  603.                    /((double) WIDTH_OF_ROOM));
  604.                   aspect_ratio
  605.                    =(((double) (forms_info_ptr[form_num].yTopClip
  606.                    -forms_info_ptr[form_num].yBottomClip))
  607.                    /((double) (forms_info_ptr[form_num].xRightClip
  608.                    -forms_info_ptr[form_num].xLeftClip)))
  609.                    /(((double) iMaxY)/((double) iMaxX));
  610.                   free((void *) forms_info_ptr);
  611.                   plot_hwnd=hwnd;
  612.                   if ((num_columns >= 2)
  613.                   &&  (num_rows >= 2))
  614.                     {
  615.                       DosGetDateTime(&dateSeed);
  616.                       r_n_seed[0]=dateSeed.year%10;
  617.                       r_n_seed[1]=dateSeed.month%10;
  618.                       r_n_seed[2]=dateSeed.day%10;
  619.                       r_n_seed[3]=dateSeed.hours%10;
  620.                       r_n_seed[4]=dateSeed.minutes%10;
  621.                       r_n_seed[5]=dateSeed.seconds%10;
  622.                       r_n_seed[6]=dateSeed.hundredths%10;
  623.                       DosResetEventSem((HEV) size_maze_active,
  624.                        (PULONG) &size_maze_post_count);
  625.                       size_maze_kill=FALSE;
  626.                       WinSendMsg(WinWindowFromID(
  627.                        WinQueryWindow(hwnd,QW_PARENT),FID_MENU),
  628.                        MM_SETITEMATTR,MPFROM2SHORT(IDM_CANCEL,TRUE),
  629.                        MPFROM2SHORT(MIA_DISABLED,0));
  630.                       _beginthread(size_maze,(void *) NULL,16384,(void *) NULL);
  631.                     }
  632.                   else
  633.                     {
  634.                       DevCloseDC(dev_context_handle);
  635.                       WinTerminate((HAB) habPrint);
  636.                       DosEnterCritSec();
  637.                       strcpy((unsigned char *) &titillator[0],
  638.                        "No suitable printer!");
  639.                       DosExitCritSec();
  640.                     }
  641.                   break;
  642.                 case IDM_SETUP:
  643.                   titillator[0]='\0';
  644.                   WinDlgBox(HWND_DESKTOP,hwnd,printer_setup,(HMODULE) NULL,
  645.                    IDD_PRINTSETUP,(PVOID) NULL);
  646.                   break;
  647.                 case IDM_TUTORIAL:
  648.                   if (help_enabled)
  649.                     if (WinSendMsg(hwndHelpInstance,HM_KEYS_HELP,NULL,NULL))
  650.                       display_msg(hwndClient,IDMSG_HELPDISPLAYERROR,
  651.                        ((ULONG) MB_OK)|((ULONG) MB_ERROR),FALSE);
  652.                   break;
  653.                 case IDM_USINGHELP:
  654.                   if (help_enabled)
  655.                     if (WinSendMsg(hwndHelpInstance,HM_DISPLAY_HELP,NULL,
  656.                      NULL))
  657.                       display_msg(hwndClient,IDMSG_HELPDISPLAYERROR,
  658.                        ((ULONG) MB_OK)|((ULONG) MB_ERROR),FALSE);
  659.                   break;
  660.                 default:
  661.                   break;
  662.               }
  663.             break;
  664.           case WM_CREATE:
  665.             DosGetDateTime(&dateSeed);
  666.             r_n_seed[0]=dateSeed.year%10;
  667.             r_n_seed[1]=dateSeed.month%10;
  668.             r_n_seed[2]=dateSeed.day%10;
  669.             r_n_seed[3]=dateSeed.hours%10;
  670.             r_n_seed[4]=dateSeed.minutes%10;
  671.             r_n_seed[5]=dateSeed.seconds%10;
  672.             r_n_seed[6]=dateSeed.hundredths%10;
  673.             rotation=0.0;
  674.             tilt=30.0;
  675.             iMaxX=0;
  676.             iMaxY=0;
  677.             color=(volatile unsigned char * volatile) NULL;
  678.             x_division_index=(volatile int * volatile) NULL;
  679.             x_prime=(volatile float * volatile) NULL;
  680.             y_division_index=(volatile int * volatile) NULL;
  681.             y_prime=(volatile float * volatile) NULL;
  682.             z_prime=(volatile float * volatile) NULL;
  683.             base_page=(volatile char * volatile * volatile) NULL;
  684.             page=(volatile char * volatile * volatile) NULL;
  685.             stack=(volatile stack_rec * volatile) NULL;
  686.             default_queue_buffer=(volatile char * volatile) NULL;
  687.             setup_queue_buffer=(volatile char * volatile) NULL;
  688.             queue_buffer_size=(ULONG) 0;
  689.             best_queue_info_ptr=(volatile PRQINFO3 * volatile) NULL;
  690.             num_queue_items_returned=0;
  691.             num_queue_items_available=0;
  692.             queue_buffer_size_needed=0;
  693.             rc=SplEnumQueue((PSZ) NULL,(ULONG) 3,(PVOID) default_queue_buffer,
  694.              (ULONG) queue_buffer_size,(PULONG) &num_queue_items_returned,
  695.              (PULONG) &num_queue_items_available,
  696.              (PULONG) &queue_buffer_size_needed,NULL);
  697.             if ((rc == NO_ERROR)
  698.             ||  (rc == ERROR_MORE_DATA))
  699.               {
  700.                 default_queue_buffer
  701.                  =(volatile char * volatile) malloc(queue_buffer_size_needed);
  702.                 queue_buffer_size=queue_buffer_size_needed;
  703.                 rc=SplEnumQueue((PSZ) NULL,(ULONG) 3,
  704.                  (PVOID) default_queue_buffer,(ULONG) queue_buffer_size,
  705.                  (PULONG) &num_queue_items_returned,
  706.                  (PULONG) &num_queue_items_available,
  707.                  (PULONG) &queue_buffer_size_needed,NULL);
  708.                 if (rc == NO_ERROR)
  709.                   {
  710.                     if (num_queue_items_returned > 0)
  711.                       {
  712.                         queue_info_ptr=(PPRQINFO3) default_queue_buffer;
  713.                         max_min_pixels=0;
  714.                         for (queue_item_num=1; queue_item_num 
  715.                          <= num_queue_items_returned;
  716.                          queue_item_num++)
  717.                           {
  718.                             habPrint=WinInitialize((ULONG) 0);
  719.                             dev_open_data.pszLogAddress
  720.                              =(*queue_info_ptr).pszName;
  721.                             dev_open_data.pszDriverName
  722.                              =(*queue_info_ptr).pszDriverName;
  723.                             dev_open_data.pszDriverName[
  724.                              strcspn(dev_open_data.pszDriverName,".")]='\0';
  725.                             dev_open_data.pdriv=(*queue_info_ptr).pDriverData;
  726.                             dev_open_data.pszDataType="PM_Q_STD";
  727.                             dev_open_data.pszComment="LPTHEX";
  728.                             dev_open_data.pszQueueProcName=NULL;
  729.                             dev_open_data.pszQueueProcParams="XFM=0";
  730.                             dev_open_data.pszSpoolerParams=NULL;
  731.                             dev_open_data.pszNetworkParams=NULL;
  732.                             dev_context_handle=DevOpenDC(habPrint,OD_QUEUED,
  733.                              (PSZ) "*",9l,(PDEVOPENDATA) &dev_open_data,
  734.                              (HDC) NULL);
  735.                             num_forms=DevQueryHardcopyCaps(dev_context_handle,
  736.                              0l,0l,(PHCINFO) NULL);
  737.                             forms_info_ptr=(PHCINFO) 
  738.                              malloc(((unsigned int) num_forms)*sizeof(HCINFO));
  739.                             rc=(ULONG)
  740.                              DevQueryHardcopyCaps(dev_context_handle,0l,
  741.                              num_forms,forms_info_ptr);
  742.                             form_num=0;
  743.                             while ((form_num < num_forms)
  744.                             && ((((ULONG) forms_info_ptr[form_num].flAttributes)
  745.                              & ((ULONG) HCAPS_CURRENT))
  746.                              != ((ULONG) HCAPS_CURRENT)))
  747.                               form_num++;
  748.                             min_pixels=min(
  749.                              ((ULONG) forms_info_ptr[form_num].xPels),
  750.                              ((ULONG) forms_info_ptr[form_num].yPels));
  751.                             if (min_pixels > max_min_pixels)
  752.                               {
  753.                                 max_min_pixels=min_pixels;
  754.                                 best_queue_info_ptr=queue_info_ptr;
  755.                               }
  756.                             free((void *) forms_info_ptr);
  757.                             DevCloseDC(dev_context_handle);
  758.                             WinTerminate((HAB) habPrint);
  759.                             queue_info_ptr++;
  760.                           }
  761.                       }
  762.                     else
  763.                       {
  764.                         DevCloseDC(dev_context_handle);
  765.                         WinTerminate((HAB) habPrint);
  766.                         DosEnterCritSec();
  767.                         strcpy((unsigned char *) &titillator[0],
  768.                          "No queues present!");
  769.                         DosExitCritSec();
  770.                       }
  771.                   }
  772.                 else
  773.                   {
  774.                     DevCloseDC(dev_context_handle);
  775.                     WinTerminate((HAB) habPrint);
  776.                     DosEnterCritSec();
  777.                     strcpy((unsigned char *) &titillator[0],
  778.                      "Queues unavailable!");
  779.                     DosExitCritSec();
  780.                   }
  781.               }
  782.             else
  783.               {
  784.                 DevCloseDC(dev_context_handle);
  785.                 WinTerminate((HAB) habPrint);
  786.                 DosEnterCritSec();
  787.                 strcpy((unsigned char *) &titillator[0],"Queues unavailable!");
  788.                 DosExitCritSec();
  789.               }
  790.             break;
  791.           case WM_DESTROY:
  792.             DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  793.             if (sizing == (ULONG) 0)
  794.               {
  795.                 size_maze_kill=TRUE;
  796.                 DosWaitEventSem((HEV) size_maze_active,
  797.                  (ULONG) SEM_INDEFINITE_WAIT);
  798.               }
  799.             destroy_maze(&x_prime,&y_prime,&z_prime,&x_division_index,
  800.              &y_division_index,&color,&stack);
  801.             if (setup_queue_buffer != (volatile char * volatile) NULL)
  802.               free((void *) setup_queue_buffer);
  803.             if (default_queue_buffer != (volatile char * volatile) NULL)
  804.               free((void *) default_queue_buffer);
  805.             break;
  806.           case WM_PAINT:
  807.             hps=WinBeginPaint(hwnd,(HPS) NULL,(PRECTL) NULL);
  808.             GpiErase(hps);
  809.             if (display_titillator)
  810.               {
  811.                 WinQueryWindowRect(hwnd,&rcl);
  812.                 DosEnterCritSec();
  813.                 WinDrawText(hps,-1,(unsigned char *) &titillator[0],&rcl,
  814.                  CLR_NEUTRAL,CLR_BACKGROUND,((ULONG) DT_CENTER)|
  815.                  ((ULONG) DT_VCENTER)|((ULONG) DT_ERASERECT));
  816.                 DosExitCritSec();
  817.               }
  818.             WinEndPaint(hps);
  819.             break;
  820.           case WM_PLOT_DONE:
  821.             strcpy((unsigned char *) &titillator[0],"Done!");
  822.             WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  823.              FID_MENU),MM_SETITEMATTR,MPFROM2SHORT(IDM_SETUP,TRUE),
  824.              MPFROM2SHORT(MIA_DISABLED,0));
  825.             WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  826.              FID_MENU),MM_SETITEMATTR,MPFROM2SHORT(IDM_PRINT,TRUE),
  827.              MPFROM2SHORT(MIA_DISABLED,0));
  828.             WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  829.              FID_MENU),MM_SETITEMATTR,MPFROM2SHORT(IDM_CANCEL,TRUE),
  830.              MPFROM2SHORT(MIA_DISABLED,MIA_DISABLED));
  831.             break;
  832.           case WM_TIMER:
  833.             display_titillator=!display_titillator;
  834.             WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) NULL);
  835.             break;
  836.           default:
  837.             result=(MRESULT) WinDefWindowProc(hwnd,msg,mp1,mp2);
  838.             break;
  839.         }
  840.       return(result);
  841.     }
  842.  
  843. static void initialize_help()
  844.     {
  845.       HELPINIT hini
  846.        = {(ULONG) 0,(ULONG) 0,(PSZ) NULL,(PHELPTABLE) NULL,(HMODULE) 0,
  847.        (HMODULE) 0,(ULONG) 0,(ULONG) 0,(PSZ) NULL,(ULONG) 0,(PSZ) 0};
  848.  
  849.       help_enabled=FALSE;
  850.       hini.cb=sizeof(HELPINIT);
  851.       hini.ulReturnCode=0;
  852.       hini.pszTutorialName=(PSZ) NULL;
  853.       hini.phtHelpTable=(PHELPTABLE) MAKELONG(LPTHEX_HELP_TABLE,0xFFFF);
  854.       hini.hmodHelpTableModule=0;
  855.       hini.hmodAccelActionBarModule=0;
  856.       hini.idAccelTable=0;
  857.       hini.idActionBar=0;
  858.       if (! WinLoadString(hAB,0,IDS_HELPWINDOWTITLE,HELP_LIB_NAME_LENGTH,
  859.        (PSZ) window_title))
  860.           display_msg(hwndClient,IDMSG_CANNOTLOADSTRING,
  861.            ((ULONG) MB_OK)|((ULONG) MB_ERROR),FALSE);
  862.       else
  863.         {
  864.           hini.pszHelpWindowTitle=(PSZ) window_title;
  865.           hini.fShowPanelId=CMIC_HIDE_PANEL_ID;
  866.           if (! WinLoadString(hAB,0,IDS_HELPLIBRARYNAME,HELP_LIB_NAME_LENGTH,
  867.            (PSZ) lib_name))
  868.             display_msg(hwndClient,IDMSG_CANNOTLOADSTRING,
  869.              ((ULONG) MB_OK)|((ULONG) MB_ERROR),FALSE);
  870.           else
  871.             {
  872.               hini.pszHelpLibraryName=(PSZ) lib_name;
  873.               hwndHelpInstance=WinCreateHelpInstance(hAB,&hini);
  874.               if (hwndHelpInstance == 0 || hini.ulReturnCode)
  875.                 display_msg(hwndFrame,IDMSG_HELPLOADERROR,
  876.                  ((ULONG) MB_OK)|((ULONG) MB_ERROR),TRUE);
  877.               else
  878.                 {
  879.                   if (! WinAssociateHelpInstance(hwndHelpInstance,hwndFrame))
  880.                     display_msg(hwndFrame,IDMSG_HELPLOADERROR,
  881.                      ((ULONG) MB_OK)|((ULONG) MB_ERROR),TRUE);
  882.                   else
  883.                     help_enabled=TRUE;
  884.                 }
  885.             }
  886.         }
  887.       return;
  888.     }
  889.  
  890. MRESULT EXPENTRY about_lpthex(
  891.   HWND   hwnd,
  892.   ULONG  msg,
  893.   MPARAM mp1,
  894.   MPARAM mp2)
  895.     {
  896.       HWND    hwndMenu = (HWND) 0;
  897.       MRESULT result = (MRESULT) 0;
  898.  
  899.       switch (msg)
  900.         {
  901.           case WM_INITDLG:
  902.             hwndMenu=WinWindowFromID(hwnd,FID_SYSMENU);
  903.             WinSendMsg(hwndMenu,MM_DELETEITEM,MPFROM2SHORT(SC_RESTORE,TRUE),
  904.              MPFROMP(NULL));
  905.             WinSendMsg(hwndMenu,MM_DELETEITEM,MPFROM2SHORT(SC_SIZE,TRUE),
  906.              MPFROMP(NULL));
  907.             WinSendMsg(hwndMenu,MM_DELETEITEM,MPFROM2SHORT(SC_MINIMIZE,TRUE),
  908.              MPFROMP(NULL));
  909.             WinSendMsg(hwndMenu,MM_DELETEITEM,MPFROM2SHORT(SC_MAXIMIZE,TRUE),
  910.              MPFROMP(NULL));
  911.             break;
  912.           case WM_COMMAND:
  913.             WinDismissDlg(hwnd,TRUE);
  914.             break;
  915.           default:
  916.             result=WinDefDlgProc(hwnd,msg,mp1,mp2);
  917.             break;
  918.         }
  919.       return(result);
  920.     }
  921.  
  922. static ULONG display_msg(
  923.   HWND  hwndOwner,
  924.   ULONG msg_id,
  925.   ULONG style,
  926.   BOOL  beep)
  927.     {
  928.       CHAR  msg [MAX_MSG_LENGTH]
  929.        = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  930.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  931.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
  932.       ULONG result = (ULONG) 0;
  933.  
  934.       if (! WinLoadMessage(hAB,(HMODULE) NULL,msg_id,MAX_MSG_LENGTH,(PSZ) msg))
  935.         {
  936.           WinAlarm(HWND_DESKTOP,WA_ERROR);
  937.           result=(ULONG) 1;
  938.         }
  939.       else
  940.         {
  941.           if (beep)
  942.             WinAlarm(HWND_DESKTOP,WA_ERROR);
  943.           result=WinMessageBox(HWND_DESKTOP,hwndOwner,msg,(PSZ) NULL,
  944.            IDD_MSGBOX,style);
  945.         }
  946.       return(result);
  947.     }
  948.  
  949. MRESULT EXPENTRY printer_setup(
  950.   HWND   hwnd,
  951.   ULONG  msg,
  952.   MPARAM mp1,
  953.   MPARAM mp2)
  954.     {
  955.       long         driv_data_length = 0l;
  956.       PDRIVDATA    driv_data_ptr = (PDRIVDATA) NULL;
  957.       char         listbox_line [306]
  958.        = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  959.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  960.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  961.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  962.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  963.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  964.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  965.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  966.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  967.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  968.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  969.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  970.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  971.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  972.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  973.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  974.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  975.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  976.        ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  977.        ' ',' '};
  978.       ULONG        num_queue_items_available = (ULONG) 0;
  979.       ULONG        num_queue_items_returned = (ULONG) 0;
  980. /*    PDRIVDATA    old_driv_data_ptr = (PDRIVDATA) NULL;
  981. */    ULONG        queue_buffer_size = (ULONG) 0;
  982.       ULONG        queue_buffer_size_needed = (ULONG) 0;
  983.       PPRQINFO3    queue_info_ptr = (PPRQINFO3) NULL;
  984.       ULONG        queue_item_num = (ULONG) 0;
  985.       ULONG        rc = (ULONG) 0;
  986.       MRESULT      result = (MRESULT) 0;
  987.  
  988.       result=(MRESULT) 0;  
  989.       switch (msg)
  990.         {
  991.           case WM_INITDLG:
  992.             WinSendDlgItemMsg(hwnd,IDD_PSLISTBOX,LM_DELETEALL,(MPARAM) NULL,
  993.              (MPARAM) NULL);
  994.             queue_buffer_size=(ULONG) 0;
  995.             old_setup_queue_buffer=setup_queue_buffer;
  996.             setup_queue_buffer=(volatile char * volatile) NULL;
  997.             num_queue_items_returned=0;
  998.             num_queue_items_available=0;
  999.             queue_buffer_size_needed=0;
  1000.             rc=SplEnumQueue((PSZ) NULL,(ULONG) 3,(PVOID) setup_queue_buffer,
  1001.              (ULONG) queue_buffer_size,(PULONG) &num_queue_items_returned,
  1002.              (PULONG) &num_queue_items_available,
  1003.              (PULONG) &queue_buffer_size_needed,NULL);
  1004.             if ((rc == NO_ERROR)
  1005.             ||  (rc == ERROR_MORE_DATA))
  1006.               {
  1007.                 setup_queue_buffer=(volatile char * volatile)
  1008.                  malloc(queue_buffer_size_needed);
  1009.                 queue_buffer_size=queue_buffer_size_needed;
  1010.                 rc=SplEnumQueue((PSZ) NULL,(ULONG) 3,(PVOID) setup_queue_buffer,
  1011.                  (ULONG) queue_buffer_size,(PULONG) &num_queue_items_returned,
  1012.                  (PULONG) &num_queue_items_available,
  1013.                  (PULONG) &queue_buffer_size_needed,NULL);
  1014.                 if (rc == NO_ERROR)
  1015.                   {
  1016.                     if (num_queue_items_returned > 0)
  1017.                       {
  1018.                         queue_info_ptr=(PPRQINFO3) setup_queue_buffer;
  1019.                         for (queue_item_num=1; queue_item_num 
  1020.                          <= num_queue_items_returned;
  1021.                          queue_item_num++)
  1022.                           {
  1023.                             (*queue_info_ptr).pszDriverName[
  1024.                              strcspn((*queue_info_ptr).pszDriverName,".")]='\0';
  1025.                             strcpy(&listbox_line[0],(*queue_info_ptr).pszName);
  1026.                             strcat(&listbox_line[0],":  ");
  1027.                             strcat(&listbox_line[0],
  1028.                              (*queue_info_ptr).pszComment);
  1029.                             WinSendDlgItemMsg(hwnd,IDD_PSLISTBOX,LM_INSERTITEM,
  1030.                              MPFROMSHORT(LIT_END),MPFROMP(&listbox_line[0]));
  1031.                             if ((best_queue_info_ptr != (PPRQINFO3) NULL)
  1032.                             &&  (strcmp((*queue_info_ptr).pszName,
  1033.                                   (*best_queue_info_ptr).pszName) == 0))
  1034.                               {
  1035.                                 WinSendDlgItemMsg(hwnd,IDD_PSLISTBOX,
  1036.                                  LM_SELECTITEM,MPFROMSHORT((queue_item_num-1)),
  1037.                                  MPFROMLONG(TRUE));
  1038.                                 if (((*best_queue_info_ptr).pDriverData)->cb
  1039.                                  <= ((*queue_info_ptr).pDriverData)->cb)
  1040.                                   memcpy((PSZ) (*queue_info_ptr).pDriverData,
  1041.                                    (PSZ) (*best_queue_info_ptr).pDriverData,
  1042.                                    (unsigned int)
  1043.                                    (((*best_queue_info_ptr).pDriverData)->cb)); 
  1044.                                 else
  1045.                                   {
  1046.                                     driv_data_ptr=(PDRIVDATA) malloc(
  1047.                                      (unsigned int)
  1048.                                      (((*best_queue_info_ptr).pDriverData)->
  1049.                                      cb));
  1050.                                     memcpy((PSZ) driv_data_ptr,
  1051.                                      (PSZ) (*best_queue_info_ptr).pDriverData,
  1052.                                      (unsigned int)
  1053.                                      (((*best_queue_info_ptr).pDriverData)->
  1054.                                      cb)); 
  1055. /*                                   old_driv_data_ptr
  1056.                                       =(*queue_info_ptr).pDriverData;
  1057. */                                  (*queue_info_ptr).pDriverData=driv_data_ptr;
  1058.       /*
  1059.               There is some memory leakage here, but I hesitate to
  1060.          free((void *) old_driv_data_ptr) since I'm not always the one who
  1061.          allocated it and I don't want the overhead of keeping track of who
  1062.          did.
  1063.       */
  1064.                                   }
  1065.                               }
  1066.                             queue_info_ptr++;
  1067.                           }
  1068.                         if (best_queue_info_ptr == (PPRQINFO3) NULL)
  1069.                           WinSendDlgItemMsg(hwnd,IDD_PSLISTBOX,LM_SELECTITEM,
  1070.                            MPFROMSHORT(0),MPFROMLONG(TRUE));
  1071.                       }
  1072.                     else
  1073.                       {
  1074.                         free((void *) setup_queue_buffer);
  1075.                         setup_queue_buffer=old_setup_queue_buffer;
  1076.                         DosEnterCritSec();
  1077.                         strcpy((unsigned char *) &titillator[0],
  1078.                          "No queues present!");
  1079.                         DosExitCritSec();
  1080.                         WinDismissDlg(hwnd,(ULONG) TRUE);
  1081.                       }
  1082.                   }
  1083.                 else
  1084.                   {
  1085.                     free((void *) setup_queue_buffer);
  1086.                     setup_queue_buffer=old_setup_queue_buffer;
  1087.                     DosEnterCritSec();
  1088.                     strcpy((unsigned char *) &titillator[0],
  1089.                      "Queues unavailable!");
  1090.                     DosExitCritSec();
  1091.                     WinDismissDlg(hwnd,(ULONG) TRUE);
  1092.                   }
  1093.               }
  1094.             else
  1095.               {
  1096.                 setup_queue_buffer=old_setup_queue_buffer;
  1097.                 DosEnterCritSec();
  1098.                 strcpy((unsigned char *) &titillator[0],"Queues unavailable!");
  1099.                 DosExitCritSec();
  1100.                 WinDismissDlg(hwnd,(ULONG) TRUE);
  1101.               }
  1102.             break;
  1103.           case WM_COMMAND:
  1104.             switch (COMMANDMSG(&msg)->cmd)
  1105.               {
  1106.                 case DID_OK:
  1107.                   if (old_setup_queue_buffer != (volatile char * volatile) NULL)
  1108.                     free((void *) old_setup_queue_buffer);
  1109.                   best_queue_info_ptr=(PPRQINFO3) setup_queue_buffer;
  1110.                   best_queue_info_ptr
  1111.                    +=SHORT1FROMMP(WinSendDlgItemMsg(hwnd,IDD_PSLISTBOX,
  1112.                    LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),(MPARAM) NULL));
  1113.                   WinDismissDlg(hwnd,(ULONG) TRUE);
  1114.                   break;
  1115.                 case DID_CANCEL:
  1116.                   free((void *) setup_queue_buffer);
  1117.                   setup_queue_buffer=old_setup_queue_buffer;
  1118.                   WinDismissDlg(hwnd,(ULONG) TRUE);
  1119.                   break;
  1120.                 case IDD_PSJOBPROP:
  1121.                   best_queue_info_ptr=(PPRQINFO3) setup_queue_buffer;
  1122.                   best_queue_info_ptr
  1123.                    +=SHORT1FROMMP(WinSendDlgItemMsg(hwnd,IDD_PSLISTBOX,
  1124.                    LM_QUERYSELECTION,MPFROMSHORT(LIT_FIRST),(MPARAM) NULL));
  1125.                   habPrint=WinInitialize((ULONG) 0);
  1126.                   driv_data_length=DevPostDeviceModes(habPrint,
  1127.                    (PDRIVDATA) NULL,(*best_queue_info_ptr).pszDriverName,
  1128.                    ((*best_queue_info_ptr).pDriverData)->szDeviceName,
  1129.                    (PSZ) NULL,(ULONG) DPDM_POSTJOBPROP);
  1130.                   if (driv_data_length > 0)
  1131.                     {
  1132.                       if (driv_data_length
  1133.                        > ((*best_queue_info_ptr).pDriverData)->cb)
  1134.                         {
  1135.                           driv_data_ptr=(PDRIVDATA) 
  1136.                            malloc((unsigned int) driv_data_length);
  1137.                           memcpy((PSZ) driv_data_ptr,
  1138.                            (PSZ) (*best_queue_info_ptr).pDriverData,
  1139.                            (unsigned int)
  1140.                            (((*best_queue_info_ptr).pDriverData)->cb));
  1141. /*                        old_driv_data_ptr=(*best_queue_info_ptr).pDriverData;
  1142. */                        (*best_queue_info_ptr).pDriverData=driv_data_ptr;
  1143.       /*
  1144.               There is some memory leakage here, but I hesitate to
  1145.          free((void *) old_driv_data_ptr) since I'm not always the one who
  1146.          allocated it and I don't want the overhead of keeping track of who
  1147.          did.
  1148.       */
  1149.                         }
  1150.                       DevPostDeviceModes(habPrint,
  1151.                        (*best_queue_info_ptr).pDriverData,
  1152.                        (*best_queue_info_ptr).pszDriverName,
  1153.                        ((*best_queue_info_ptr).pDriverData)->szDeviceName,
  1154.                        (PSZ) NULL,(ULONG) DPDM_POSTJOBPROP);
  1155.                     }
  1156.                   else
  1157.                     WinMessageBox(HWND_DESKTOP,hwnd,
  1158.                      "Job properties cannot be modified.","LPTHEX",
  1159.                      (USHORT) 0,((ULONG) MB_ICONHAND)|((ULONG) MB_OK));
  1160.                   WinTerminate((HAB) habPrint);
  1161.                   break;
  1162.                 default:
  1163.                   break;
  1164.               }
  1165.             break;
  1166.           default:
  1167.             result=(MRESULT) WinDefDlgProc(hwnd,msg,mp1,mp2);
  1168.         }
  1169.       return(result);
  1170.     }
  1171.  
  1172. static void size_maze(
  1173.   void *arg)
  1174.     {
  1175.       if (arg != (void *) NULL) /* suppress msg that arg is not referenced */
  1176.         DosBeep((ULONG) 300,(ULONG) 300);
  1177.       destroy_maze(&x_prime,&y_prime,&z_prime,&x_division_index,
  1178.        &y_division_index,&color,&stack);
  1179.       max_x=8*(num_columns/2)+6;
  1180.       max_x_plus_1=max_x+1;
  1181.       num_x_dots=RESOLUTION*max_x_plus_1;
  1182.       x_dot_max=num_x_dots-1;
  1183.       max_y=4*num_rows;
  1184.       max_y_plus_1=max_y+1;
  1185.       num_y_dots=RESOLUTION*max_y_plus_1;
  1186.       y_dot_max=num_y_dots-1;
  1187.       num_rooms_in_maze=num_rows*num_columns-(num_columns/2);
  1188.       num_x_divisions=num_y_dots+2;
  1189.       num_y_divisions=num_x_dots+2;
  1190.       num_primes=(long) num_x_divisions;
  1191.       num_primes*=((long) num_y_divisions);
  1192.       if (! size_maze_kill)
  1193.         {
  1194.           if (memory_allocated(num_primes,&x_prime,&y_prime,
  1195.            &z_prime,&x_division_index,&y_division_index,&color,
  1196.            num_rooms_in_maze,&stack))
  1197.             {
  1198.               if (! size_maze_kill)
  1199.                 generate_maze();
  1200.               x_min=1.0;
  1201.               x_max=(double) num_x_divisions;
  1202.               y_min=1.0;
  1203.               y_max=(double) num_y_divisions;
  1204.               light.x=1.5;
  1205.               light.y=-1.0;
  1206.               light.z=2.6;
  1207.               if (! size_maze_kill)
  1208.                 evaluate_and_transform(x_min,x_max,y_min,y_max,num_x_divisions,
  1209.                  num_y_divisions,rotation,tilt,x_prime,y_prime,z_prime,
  1210.                  &x_prime_max,&y_prime_min,&y_prime_max,&z_prime_min,
  1211.                  &z_prime_max,&light,x_division_index,y_division_index);
  1212.               if (! size_maze_kill)
  1213.                 shade(num_x_divisions,num_y_divisions,x_prime,y_prime,z_prime,
  1214.                  color,&light);
  1215.               if (! size_maze_kill)
  1216.                 adjust_perspective(num_x_divisions,num_y_divisions,x_prime,
  1217.                  y_prime,z_prime,x_prime_max,y_prime_min,y_prime_max,
  1218.                  z_prime_min,z_prime_max);
  1219.               if (! size_maze_kill)
  1220.                 sort_back_to_front(num_primes,x_prime,x_division_index,
  1221.                  y_division_index);
  1222.               if (! size_maze_kill)
  1223.                 plot(num_x_divisions,x_division_index,num_y_divisions,
  1224.                  y_division_index,num_primes,y_prime,z_prime,y_prime_min,
  1225.                  y_prime_max,z_prime_min,z_prime_max,color);
  1226.             }
  1227.           else
  1228.             {
  1229.               DosEnterCritSec();
  1230.               strcpy((unsigned char *) &titillator[0],"Not enough memory!");
  1231.               DosExitCritSec();
  1232.             }
  1233.         }
  1234.       DosEnterCritSec();
  1235.       DosPostEventSem((HEV) size_maze_active);
  1236.       _endthread();
  1237.     }
  1238.  
  1239. static int memory_allocated(
  1240.   volatile long                     num_primes,
  1241.   volatile float         * volatile *x_prime,
  1242.   volatile float         * volatile *y_prime,
  1243.   volatile float         * volatile *z_prime,
  1244.   volatile int           * volatile *x_division_index,
  1245.   volatile int           * volatile *y_division_index,
  1246.   volatile unsigned char * volatile *color,
  1247.   volatile int                      num_rooms_in_maze,
  1248.   volatile stack_rec     * volatile *stack)
  1249.     {
  1250.                int result = 0;
  1251.       register int y = 0;
  1252.  
  1253.       result=((base_page=(volatile char * volatile * volatile)
  1254.        malloc(((unsigned int) max_y_plus_1)*sizeof(volatile char * volatile)))
  1255.        != NULL);
  1256.       if (result)
  1257.         {
  1258.           for (y=0; ((result) && (y < max_y_plus_1)); y++)
  1259.             result=((base_page[y]=(volatile char * volatile)
  1260.              malloc(((unsigned int) max_x_plus_1)*sizeof(volatile char)))
  1261.              != NULL);
  1262.           if (! result)
  1263.             {
  1264.               --y;
  1265.               while (y > 0)
  1266.                 free((void *) base_page[--y]);
  1267.               free((void *) base_page);
  1268.               base_page=(volatile char * volatile * volatile) NULL;
  1269.             }
  1270.         }
  1271.       if (result)
  1272.         {
  1273.           result=((page=(volatile char * volatile * volatile)
  1274.            malloc(((unsigned int) num_y_dots)*sizeof(volatile char * volatile)))
  1275.            != NULL);
  1276.           if (result)
  1277.             {
  1278.               for (y=0; ((result) && (y < num_y_dots)); y++)
  1279.                 result=((page[y]=(volatile char * volatile)
  1280.                  malloc(((unsigned int) num_x_dots)*sizeof(volatile char)))
  1281.                  != NULL);
  1282.               if (! result)
  1283.                 {
  1284.                   --y;
  1285.                   while (y > 0)
  1286.                     free((void *) page[--y]);
  1287.                   free((void *) page);
  1288.                   page=(volatile char * volatile * volatile) NULL;
  1289.                   for (y=0; y < max_y_plus_1; y++)
  1290.                     free((void *) base_page[y]);
  1291.                   free((void *) base_page);
  1292.                   base_page=(volatile char * volatile * volatile) NULL;
  1293.                 }
  1294.             }
  1295.           else
  1296.             {
  1297.               for (y=0; y < max_y_plus_1; y++)
  1298.                 free((void *) base_page[y]);
  1299.               free((void *) base_page);
  1300.               base_page=(volatile char * volatile * volatile) NULL;
  1301.             }
  1302.         }
  1303.       if (result)
  1304.         {
  1305.           if (! (result=((*x_prime=(volatile float * volatile)
  1306.            malloc(((unsigned int) num_primes)*sizeof(volatile float)))
  1307.            != NULL)))
  1308.             {
  1309.               for (y=0; y < max_y_plus_1; y++)
  1310.                 free((void *) base_page[y]);
  1311.               free((void *) base_page);
  1312.               base_page=(volatile char * volatile * volatile) NULL;
  1313.             }
  1314.         }
  1315.       if (result)
  1316.         {
  1317.           if (! (result=((*y_prime=(volatile float * volatile)
  1318.            malloc(((unsigned int) num_primes)*sizeof(volatile float)))
  1319.            != NULL)))
  1320.             {
  1321.               free((void *) *x_prime);
  1322.               *x_prime=(volatile float * volatile) NULL;
  1323.               for (y=0; y < num_y_dots; y++)
  1324.                 free((void *) page[y]);
  1325.               free((void *) page);
  1326.               page=(volatile char * volatile * volatile) NULL;
  1327.               for (y=0; y < max_y_plus_1; y++)
  1328.                 free((void *) base_page[y]);
  1329.               free((void *) base_page);
  1330.               base_page=(volatile char * volatile * volatile) NULL;
  1331.             }
  1332.         }
  1333.       if (result)
  1334.         {
  1335.           if (! (result=((*z_prime=(volatile float * volatile)
  1336.            malloc(((unsigned int) num_primes)*sizeof(volatile float)))
  1337.            != NULL)))
  1338.             {
  1339.               free((void *) *y_prime);
  1340.               *y_prime=(volatile float * volatile) NULL;
  1341.               free((void *) *x_prime);
  1342.               *x_prime=(volatile float * volatile) NULL;
  1343.               for (y=0; y < num_y_dots; y++)
  1344.                 free((void *) page[y]);
  1345.               free((void *) page);
  1346.               page=(volatile char * volatile * volatile) NULL;
  1347.               for (y=0; y < max_y_plus_1; y++)
  1348.                 free((void *) base_page[y]);
  1349.               free((void *) base_page);
  1350.               base_page=(volatile char * volatile * volatile) NULL;
  1351.             }
  1352.         }
  1353.       if (result)
  1354.         {
  1355.           if (! (result=((*x_division_index=(volatile int * volatile)
  1356.            malloc(((unsigned int) num_primes)*sizeof(volatile int))) != NULL)))
  1357.             {
  1358.               free((void *) *z_prime);
  1359.               *z_prime=(volatile float * volatile) NULL;
  1360.               free((void *) *y_prime);
  1361.               *y_prime=(volatile float * volatile) NULL;
  1362.               free((void *) *x_prime);
  1363.               *x_prime=(volatile float * volatile) NULL;
  1364.               for (y=0; y < num_y_dots; y++)
  1365.                 free((void *) page[y]);
  1366.               free((void *) page);
  1367.               page=(volatile char * volatile * volatile) NULL;
  1368.               for (y=0; y < max_y_plus_1; y++)
  1369.                 free((void *) base_page[y]);
  1370.               free((void *) base_page);
  1371.               base_page=(volatile char * volatile * volatile) NULL;
  1372.             }
  1373.         }
  1374.       if (result)
  1375.         {
  1376.           if (! (result=((*y_division_index=(volatile int * volatile)
  1377.            malloc(((unsigned int) num_primes)*sizeof(volatile int))) != NULL)))
  1378.             {
  1379.               free((void *) *x_division_index);
  1380.               *x_division_index=(volatile int * volatile) NULL;
  1381.               free((void *) *z_prime);
  1382.               *z_prime=(volatile float * volatile) NULL;
  1383.               free((void *) *y_prime);
  1384.               *y_prime=(volatile float * volatile) NULL;
  1385.               free((void *) *x_prime);
  1386.               *x_prime=(volatile float * volatile) NULL;
  1387.               for (y=0; y < num_y_dots; y++)
  1388.                 free((void *) page[y]);
  1389.               free((void *) page);
  1390.               page=(volatile char * volatile * volatile) NULL;
  1391.               for (y=0; y < max_y_plus_1; y++)
  1392.                 free((void *) base_page[y]);
  1393.               free((void *) base_page);
  1394.               base_page=(volatile char * volatile * volatile) NULL;
  1395.             }
  1396.         }
  1397.       if (result)
  1398.         {
  1399.           if (! (result=((*color=(volatile unsigned char * volatile) 
  1400.            malloc(((unsigned int) num_primes)*sizeof(volatile unsigned char)))
  1401.            != NULL)))
  1402.             {
  1403.               free((void *) *y_division_index);
  1404.               *y_division_index=(volatile int * volatile) NULL;
  1405.               free((void *) *x_division_index);
  1406.               *x_division_index=(volatile int * volatile) NULL;
  1407.               free((void *) *z_prime);
  1408.               *z_prime=(volatile float * volatile) NULL;
  1409.               free((void *) *y_prime);
  1410.               *y_prime=(volatile float * volatile) NULL;
  1411.               free((void *) *x_prime);
  1412.               *x_prime=(volatile float * volatile) NULL;
  1413.               for (y=0; y < num_y_dots; y++)
  1414.                 free((void *) page[y]);
  1415.               free((void *) page);
  1416.               page=(volatile char * volatile * volatile) NULL;
  1417.               for (y=0; y < max_y_plus_1; y++)
  1418.                 free((void *) base_page[y]);
  1419.               free((void *) base_page);
  1420.               base_page=(volatile char * volatile * volatile) NULL;
  1421.             }
  1422.         }
  1423.       if (result)
  1424.         {
  1425.           if (! (result=((*stack=(volatile stack_rec * volatile) malloc(
  1426.            ((unsigned int) num_rooms_in_maze)*sizeof(volatile stack_rec)))
  1427.            != NULL)))
  1428.             {
  1429.               free((void *) *color);
  1430.               *color=(volatile unsigned char * volatile) NULL;
  1431.               free((void *) *y_division_index);
  1432.               *y_division_index=(volatile int * volatile) NULL;
  1433.               free((void *) *x_division_index);
  1434.               *x_division_index=(volatile int * volatile) NULL;
  1435.               free((void *) *z_prime);
  1436.               *z_prime=(volatile float * volatile) NULL;
  1437.               free((void *) *y_prime);
  1438.               *y_prime=(volatile float * volatile) NULL;
  1439.               free((void *) *x_prime);
  1440.               *x_prime=(volatile float * volatile) NULL;
  1441.               for (y=0; y < num_y_dots; y++)
  1442.                 free((void *) page[y]);
  1443.               free((void *) page);
  1444.               page=(volatile char * volatile * volatile) NULL;
  1445.               for (y=0; y < max_y_plus_1; y++)
  1446.                 free((void *) base_page[y]);
  1447.               free((void *) base_page);
  1448.               base_page=(volatile char * volatile * volatile) NULL;
  1449.             }
  1450.         }
  1451.       return(result);
  1452.     }
  1453.  
  1454. static void set_point_on_page(
  1455.   int x,
  1456.   int y)
  1457.     {
  1458.       int x_offset = 0;
  1459.       int x_out = 0;
  1460.       int y_offset = 0;
  1461.       int y_out = 0;
  1462.  
  1463.       for (x_offset = 0; x_offset < RESOLUTION; x_offset++)
  1464.         {
  1465.           x_out=x+x_offset;
  1466.           for (y_offset=0; y_offset < RESOLUTION; y_offset++)
  1467.             {
  1468.               y_out=y+y_offset;
  1469.               page[y_out][x_out]='W';
  1470.             }
  1471.         }
  1472.       return;
  1473.     }
  1474.  
  1475.  
  1476. static void draw_line_on_page(
  1477.   int x1,
  1478.   int y1,
  1479.   int x2,
  1480.   int y2)
  1481.     {
  1482.       int error = 0;
  1483.       int error_prime_x = 0;
  1484.       int error_prime_y = 0;
  1485.       int permissible_delta_x = 0;
  1486.       int permissible_delta_y = 0;
  1487.       int x = 0;
  1488.       int x_diff = 0;
  1489.       int y = 0;
  1490.       int y_diff = 0;
  1491.  
  1492.       if (x2 >= x1)
  1493.         permissible_delta_x=1;
  1494.       else
  1495.         permissible_delta_x=-1;
  1496.       if (y2 >= y1)
  1497.         permissible_delta_y=1;
  1498.       else
  1499.         permissible_delta_y=-1;
  1500.       x=x1;
  1501.       y=y1;
  1502.       x_diff=x2-x1;
  1503.       y_diff=y2-y1;
  1504.       set_point_on_page(x,y);
  1505.       while ((x != x2) || (y != y2))
  1506.         {
  1507.           error_prime_x=error+permissible_delta_x*y_diff;
  1508.           error_prime_y=error-permissible_delta_y*x_diff;
  1509.           if (abs(error_prime_x) <= abs(error_prime_y)) 
  1510.             {
  1511.               x+=permissible_delta_x;
  1512.               error=error_prime_x;
  1513.             } 
  1514.           else
  1515.             {
  1516.               y+=permissible_delta_y;
  1517.               error=error_prime_y;
  1518.             }
  1519.           set_point_on_page(x,y);
  1520.         }
  1521.       return;
  1522.     } 
  1523.  
  1524. static void solve_maze(
  1525.   volatile stack_rec * volatile            stack,
  1526.   volatile char      * volatile * volatile base_page,
  1527.            int                  *          num_rooms_in_solution,
  1528.            int                  *          adjacency,
  1529.   volatile int                             max_x,
  1530.   volatile int                             max_y)
  1531.     {
  1532.       int delta_index=0;
  1533.       int passage_found=0;
  1534.       int stack_head=-1;
  1535.       int x=3;
  1536.       int x_next=0;
  1537.       int y=2;
  1538.       int y_next=0;
  1539.  
  1540.       *num_rooms_in_solution=1;
  1541.       *adjacency=0;
  1542.       x=3;
  1543.       y=2;
  1544.       stack_head=-1;
  1545.       base_page[y][x]='S';
  1546.       do
  1547.         {
  1548.           delta_index=0;
  1549.           passage_found=FALSE;
  1550.           do
  1551.             {
  1552.               while ((delta_index < 6) && (! passage_found))
  1553.                 {
  1554.                   x_next=x+delta_x[delta_index][0];
  1555.                   y_next=y+delta_y[delta_index][0];
  1556.                   if (base_page[y_next][x_next] == ' ')
  1557.                     passage_found=TRUE;
  1558.                   else
  1559.                     delta_index++;
  1560.                 }
  1561.               if (! passage_found) 
  1562.                 {
  1563.                   delta_index=(int) (stack[stack_head].index_1);
  1564.                   base_page[y][x]=' ';
  1565.                   x-=delta_x[delta_index][0];
  1566.                   y-=delta_y[delta_index][0];
  1567.                   base_page[y][x]=' ';
  1568.                   x-=delta_x[delta_index][0];
  1569.                   y-=delta_y[delta_index][0];
  1570.                   stack_head--;
  1571.                   delta_index++;
  1572.                 }
  1573.             }
  1574.           while (! passage_found);
  1575.           base_page[y_next][x_next]='S';
  1576.           x_next+=delta_x[delta_index][0];
  1577.           y_next+=delta_y[delta_index][0];
  1578.           if (y_next <= max_y) 
  1579.             {
  1580.               stack_head++;
  1581.               stack[stack_head].index_1=(char) delta_index;
  1582.               base_page[y_next][x_next]='S';
  1583.               x=x_next;
  1584.               y=y_next;
  1585.             }
  1586.         }
  1587.       while (y_next < max_y);
  1588.       x=max_x-3;
  1589.       y=max_y-2;
  1590.       *adjacency=0;
  1591.       while (stack_head >= 0)
  1592.         {
  1593.           for (delta_index=0; delta_index < 6; delta_index++)
  1594.             {
  1595.               x_next=x+delta_x[delta_index][0];
  1596.               y_next=y+delta_y[delta_index][0];
  1597.               if (base_page[y_next][x_next] != 'S')
  1598.                 {
  1599.                   if (base_page[y_next][x_next] == 'W')
  1600.                     {
  1601.                       x_next+=delta_x[delta_index][0];
  1602.                       y_next+=delta_y[delta_index][0];
  1603.                       if (x_next < 0)
  1604.                         (*adjacency)++;
  1605.                       else
  1606.                         if (x_next > max_x)
  1607.                           (*adjacency)++;
  1608.                         else
  1609.                           if (y_next < 0)
  1610.                             (*adjacency)++;
  1611.                           else
  1612.                             if (y_next > max_y)
  1613.                               (*adjacency)++;
  1614.                             else
  1615.                               {
  1616.                                 if (base_page[y_next][x_next] == 'S')
  1617.                                   (*adjacency)++;
  1618.                               }
  1619.                     }
  1620.                 }
  1621.             }
  1622.           x-=(2*delta_x[stack[stack_head].index_1][0]);
  1623.           y-=(2*delta_y[stack[stack_head].index_1][0]);
  1624.           stack_head--;
  1625.           (*num_rooms_in_solution)++;
  1626.         }
  1627.       for (delta_index=0; delta_index < 6; delta_index++)
  1628.         {
  1629.           x_next=x+delta_x[delta_index][0];
  1630.           y_next=y+delta_y[delta_index][0];
  1631.           if (base_page[y_next][x_next] != ' ')
  1632.             {
  1633.               if (base_page[y_next][x_next] == 'W')
  1634.                 {
  1635.                   x_next+=delta_x[delta_index][0];
  1636.                   y_next+=delta_y[delta_index][0];
  1637.                   if (x_next < 0)
  1638.                     (*adjacency)++;
  1639.                   else
  1640.                     if (x_next > max_x)
  1641.                       (*adjacency)++;
  1642.                     else
  1643.                       if (y_next < 0)
  1644.                         (*adjacency)++;
  1645.                       else
  1646.                         if (y_next > max_y)
  1647.                           (*adjacency)++;
  1648.                         else
  1649.                           {
  1650.                             if (base_page[y_next][x_next] == 'S')
  1651.                               (*adjacency)++;
  1652.                           }
  1653.                 }
  1654.             }
  1655.         }
  1656.       return;
  1657.     }
  1658.  
  1659. static void generate_maze()
  1660.     {
  1661.                int       adjacency = 0;
  1662.                int       age = 0;
  1663.                int       column_num = 0;
  1664.                int       counter_0 = 0;
  1665.                int       counter_1 = 0;
  1666.                int       counter_2 = 0;
  1667.                int       counter_3 = 0;
  1668.                int       counter_4 = 0;
  1669.                int       counter_5 = 0;
  1670.                int       counter_6 = 0;
  1671.                int       counter_7 = 0;
  1672.                int       delta_index_1a = 0;
  1673.                int       delta_index_1b = 0;
  1674.                int       delta_index_1c = 0;
  1675.                int       delta_index_1d = 0;
  1676.                int       delta_index_1e = 0;
  1677.                int       delta_index_1f = 0;
  1678.                int       delta_index_2 = 0;
  1679.                int       num_rooms_in_solution = 0;
  1680.                int       passage_found = 0;
  1681.       register int       r_n_index_1 = 0;
  1682.       register int       r_n_index_2 = 0;
  1683.                int       row_num = 0;
  1684.                int       search_complete = 0;
  1685.                int       stack_head = 0;
  1686.                int       tem_int = 0;
  1687.                int       trial_num_mod_600 = 0;
  1688.                int       x = 0;
  1689.                int       x_mod_8 = 0;
  1690.                int       x_next = 0;
  1691.                int       y = 0;
  1692.                int       y_mod_4 = 0;
  1693.                int       y_next = 0;
  1694.                int       y_previous = 0;
  1695.  
  1696.       DosEnterCritSec();
  1697.       strcpy((unsigned char *) &titillator[0],"Generating...");
  1698.       DosExitCritSec();
  1699.       r_n[0]=r_n_seed[0];
  1700.       r_n[1]=r_n_seed[1];
  1701.       r_n[2]=r_n_seed[2];
  1702.       r_n[3]=r_n_seed[3];
  1703.       r_n[4]=r_n_seed[4];
  1704.       r_n[5]=r_n_seed[5];
  1705.       r_n[6]=r_n_seed[6];
  1706.       r_n[7]=0;
  1707.       counter_0=r_n[0];
  1708.       counter_1=r_n[1];
  1709.       counter_2=r_n[2];
  1710.       counter_3=r_n[3];
  1711.       counter_4=r_n[4];
  1712.       counter_5=r_n[5];
  1713.       counter_6=r_n[6];
  1714.       counter_7=r_n[7];
  1715.       hash(&counter_0,&counter_1,&counter_2,&counter_3,&counter_4,&counter_5,
  1716.        &counter_6,&counter_7);
  1717.       delta_y[0][0]=-1;
  1718.       delta_x[0][0]=-2;
  1719.       delta_y[1][0]=1;
  1720.       delta_x[1][0]=-2;
  1721.       delta_y[2][0]=-2;
  1722.       delta_x[2][0]=0;
  1723.       delta_y[3][0]=2;
  1724.       delta_x[3][0]=0;
  1725.       delta_y[4][0]=-1;
  1726.       delta_x[4][0]=2;
  1727.       delta_y[5][0]=1;
  1728.       delta_x[5][0]=2;
  1729.       delta_index_2=0;
  1730.       for (delta_index_1a=0; delta_index_1a < 6; delta_index_1a++)
  1731.         for (delta_index_1b=0; delta_index_1b < 6; delta_index_1b++)
  1732.           if (delta_index_1a != delta_index_1b)
  1733.            for (delta_index_1c=0; delta_index_1c < 6; delta_index_1c++)
  1734.              if ((delta_index_1a != delta_index_1c)
  1735.              &&  (delta_index_1b != delta_index_1c))
  1736.                for (delta_index_1d=0; delta_index_1d < 6; delta_index_1d++)
  1737.                   if ((delta_index_1a != delta_index_1d)
  1738.                   &&  (delta_index_1b != delta_index_1d)
  1739.                   &&  (delta_index_1c != delta_index_1d))
  1740.                     for (delta_index_1e=0; delta_index_1e < 6; 
  1741.                      delta_index_1e++)
  1742.                       if ((delta_index_1a != delta_index_1e)
  1743.                       &&  (delta_index_1b != delta_index_1e)
  1744.                       &&  (delta_index_1c != delta_index_1e)
  1745.                       &&  (delta_index_1d != delta_index_1e))
  1746.                         for (delta_index_1f=0; delta_index_1f < 6; 
  1747.                          delta_index_1f++) 
  1748.                           if ((delta_index_1a != delta_index_1f)
  1749.                           &&  (delta_index_1b != delta_index_1f)
  1750.                           &&  (delta_index_1c != delta_index_1f)
  1751.                           &&  (delta_index_1d != delta_index_1f)
  1752.                           &&  (delta_index_1e != delta_index_1f))
  1753.                             {
  1754.                               delta_x[delta_index_1a][delta_index_2]
  1755.                                =delta_x[0][0];
  1756.                               delta_y[delta_index_1a][delta_index_2]
  1757.                                =delta_y[0][0];
  1758.                               delta_x[delta_index_1b][delta_index_2]
  1759.                                =delta_x[1][0];
  1760.                               delta_y[delta_index_1b][delta_index_2]
  1761.                                =delta_y[1][0];
  1762.                               delta_x[delta_index_1c][delta_index_2]
  1763.                                =delta_x[2][0];
  1764.                               delta_y[delta_index_1c][delta_index_2]
  1765.                                =delta_y[2][0];
  1766.                               delta_x[delta_index_1d][delta_index_2]
  1767.                                =delta_x[3][0];
  1768.                               delta_y[delta_index_1d][delta_index_2]
  1769.                                =delta_y[3][0];
  1770.                               delta_x[delta_index_1e][delta_index_2]
  1771.                                =delta_x[4][0];
  1772.                               delta_y[delta_index_1e][delta_index_2]
  1773.                                =delta_y[4][0];
  1774.                               delta_x[delta_index_1f][delta_index_2]
  1775.                                =delta_x[5][0];
  1776.                               delta_y[delta_index_1f][delta_index_2]
  1777.                                =delta_y[5][0];
  1778.                               delta_index_2++;
  1779.                             };
  1780.       trial_num_mod_600=0;
  1781.       age=3;
  1782.       do
  1783.         {
  1784.           y_mod_4=1;
  1785.           for (y=0; y <= max_y; y++) 
  1786.             {
  1787.               if (y_mod_4 == 1)
  1788.                 {
  1789.                   x_mod_8=1;
  1790.                   for (x=0; x <= max_x; x++)
  1791.                     {
  1792.                       if (((x_mod_8 == 0)
  1793.                         && (y != 0)
  1794.                         && (y != max_y))
  1795.                       ||  (x_mod_8 == 3)
  1796.                       ||  (x_mod_8 == 4)
  1797.                       ||  (x_mod_8 == 5))
  1798.                         base_page[y][x]='W';
  1799.                       else
  1800.                         base_page[y][x]=' ';
  1801.                       x_mod_8++;
  1802.                       if (x_mod_8 >= 8)
  1803.                         x_mod_8=0;
  1804.                     }
  1805.                 } 
  1806.               else
  1807.                 {
  1808.                   if (y_mod_4 == 0 || y_mod_4 == 2)
  1809.                     {
  1810.                       x_mod_8=1;
  1811.                       for (x=0; x <= max_x; x++)
  1812.                         {
  1813.                           if ((x_mod_8 == 2) || (x_mod_8 == 6))
  1814.                             base_page[y][x]='W';
  1815.                           else
  1816.                             base_page[y][x]=' ';
  1817.                           x_mod_8++;
  1818.                           if (x_mod_8 >= 8)
  1819.                             x_mod_8 = 0;
  1820.                         }
  1821.                     }
  1822.                   else
  1823.                     {
  1824.                       x_mod_8=1;
  1825.                       for (x=0; x <= max_x; x++)
  1826.                         {
  1827.                           if ((x_mod_8 == 0)
  1828.                           ||  (x_mod_8 == 1)
  1829.                           ||  (x_mod_8 == 4)
  1830.                           ||  (x_mod_8 == 7))
  1831.                             base_page[y][x]='W';
  1832.                           else
  1833.                             base_page[y][x]=' ';
  1834.                           x_mod_8++;
  1835.                           if (x_mod_8 >= 8)
  1836.                             x_mod_8=0;
  1837.                       }
  1838.                     }
  1839.                 }
  1840.               y_mod_4++;
  1841.               if (y_mod_4 >= 4)
  1842.                 y_mod_4=0;
  1843.             }
  1844.           r_n[0]=counter_0+1;
  1845.           r_n[1]=counter_1+1;
  1846.           r_n[2]=counter_2+1;
  1847.           r_n[3]=counter_3+1;
  1848.           r_n[4]=counter_4+1;
  1849.           r_n[5]=counter_5+1;
  1850.           r_n[6]=counter_6+1;
  1851.           r_n[7]=counter_7+1;
  1852.           column_num=r_n[0];
  1853.           r_n_index_1=0;
  1854.           r_n_index_2=1;
  1855.           while (r_n_index_2 < 8)
  1856.             {
  1857.               tem_int=r_n[r_n_index_2];
  1858.               r_n[r_n_index_1]=tem_int;
  1859.               column_num+=tem_int;
  1860.               if (column_num >= 727)
  1861.                 column_num-=727;
  1862.               r_n_index_1=r_n_index_2;
  1863.               r_n_index_2++;
  1864.             }
  1865.           r_n[7]=column_num;
  1866.           column_num%=num_columns;
  1867.           x=4*column_num+3;
  1868.           row_num=r_n[0];
  1869.           r_n_index_1=0;
  1870.           r_n_index_2=1;
  1871.           while (r_n_index_2 < 8)
  1872.             {
  1873.               tem_int=r_n[r_n_index_2];
  1874.               r_n[r_n_index_1]=tem_int;
  1875.               row_num+=tem_int;
  1876.               if (row_num >= 727)
  1877.                 row_num-=727;
  1878.               r_n_index_1=r_n_index_2;
  1879.               r_n_index_2++;
  1880.             }
  1881.           r_n[7]=row_num;
  1882.           if (column_num%2)
  1883.             {
  1884.               row_num%=(num_rows-1);
  1885.               y=4*row_num+4;
  1886.             }
  1887.           else
  1888.             {
  1889.               row_num%=num_rows;
  1890.               y=4*row_num+2;
  1891.             }
  1892.           base_page[y][x]=' ';
  1893.           stack_head=-1;
  1894.           do
  1895.             {
  1896.               delta_index_1a=0;
  1897.               do
  1898.                 {
  1899.                   delta_index_2=r_n[0];
  1900.                   r_n_index_1=0;
  1901.                   r_n_index_2=1;
  1902.                   while (r_n_index_2 < 8)
  1903.                     {
  1904.                       tem_int=r_n[r_n_index_2];
  1905.                       r_n[r_n_index_1]=tem_int;
  1906.                       delta_index_2+=tem_int;
  1907.                       if (delta_index_2 >= 727)
  1908.                         delta_index_2-=727;
  1909.                       r_n_index_1=r_n_index_2;
  1910.                       r_n_index_2++;
  1911.                     }
  1912.                   r_n[7]=delta_index_2;
  1913.                 }
  1914.               while (delta_index_2 >= 720);
  1915.               passage_found=FALSE;
  1916.               search_complete=FALSE;
  1917.               while (! search_complete)
  1918.                 {
  1919.                   while ((delta_index_1a < 6) && (! passage_found))
  1920.                     {
  1921.                       x_next=x+2*delta_x[delta_index_1a][delta_index_2];
  1922.                       if (x_next <= 0)
  1923.                         delta_index_1a++;
  1924.                       else
  1925.                         if (x_next > max_x)
  1926.                           delta_index_1a++;
  1927.                         else
  1928.                           {
  1929.                             y_next=y+2*delta_y[delta_index_1a][delta_index_2];
  1930.                             if (y_next <= 0)
  1931.                               delta_index_1a++;
  1932.                             else
  1933.                               if (y_next > max_y)
  1934.                                 delta_index_1a++;
  1935.                               else
  1936.                                 if (base_page[y_next][x_next] == 'W')
  1937.                                   passage_found=TRUE;
  1938.                                 else
  1939.                                   delta_index_1a++;
  1940.                           }
  1941.                     }
  1942.                   if (! passage_found)
  1943.                     {
  1944.                       if (stack_head >= 0)
  1945.                         {
  1946.                           delta_index_1a=(int) (stack[stack_head].index_1);
  1947.                           delta_index_2=stack[stack_head].index_2;
  1948.                           x-=2*delta_x[delta_index_1a][delta_index_2];
  1949.                           y-=2*delta_y[delta_index_1a][delta_index_2];
  1950.                           stack_head--;
  1951.                           delta_index_1a++;
  1952.                         }
  1953.                     }
  1954.                   search_complete=((passage_found)
  1955.                    || ((stack_head == -1) && (delta_index_1a >= 6)));
  1956.                 }
  1957.               if (passage_found)
  1958.                 {
  1959.                   stack_head++;
  1960.                   stack[stack_head].index_1=(char) delta_index_1a;
  1961.                   stack[stack_head].index_2=delta_index_2;
  1962.                   base_page[y_next][x_next]=' ';
  1963.                   base_page[(y+y_next)/2][(x+x_next)/2]=' ';
  1964.                   x=x_next;
  1965.                   y=y_next;
  1966.                 }
  1967.             }
  1968.           while (stack_head != -1);
  1969.           base_page[0][3]='S';
  1970.           base_page[max_y][max_x-3]=' ';
  1971.           solve_maze(stack,base_page,&num_rooms_in_solution,&adjacency,max_x,
  1972.            max_y);
  1973.           increment(&counter_0,&counter_1,&counter_2,&counter_3,&counter_4,
  1974.            &counter_5,&counter_6,&counter_7);
  1975.           trial_num_mod_600++;
  1976.           if (trial_num_mod_600 >= 600)
  1977.             {
  1978.               trial_num_mod_600=0;
  1979.               age++;
  1980.             }
  1981.         }
  1982.       while ((! size_maze_kill)
  1983.       &&     ((3*num_rooms_in_solution < num_rooms_in_maze)
  1984.           ||  (2*adjacency > age*num_rooms_in_solution)));
  1985.       for (x = 0; x <= x_dot_max; x++) 
  1986.         for (y = 0; y <= y_dot_max; y++)
  1987.           page[y][x]=' ';
  1988.       y_previous=-1;
  1989.       y_next=1;
  1990.       for (y = 0; y <= max_y; y++)
  1991.         {
  1992.           x=0;
  1993.           for (x_next = 1; x_next <= max_x; x_next++)
  1994.             {
  1995.               if (base_page[y][x] == 'W')
  1996.                 {
  1997.                   if (base_page[y][x_next] == 'W')
  1998.                     draw_line_on_page(RESOLUTION*x,RESOLUTION*y,
  1999.                      RESOLUTION*x_next,RESOLUTION*y);
  2000.                   if (y_previous >= 0)
  2001.                     {
  2002.                       if (base_page[y_previous][x_next] == 'W')
  2003.                         draw_line_on_page(RESOLUTION*x,RESOLUTION*y,
  2004.                          RESOLUTION*x_next,RESOLUTION*y_previous);
  2005.                     }
  2006.                   if (y_next <= max_y) 
  2007.                     {
  2008.                       if (base_page[y_next][x_next] == 'W')
  2009.                         draw_line_on_page(RESOLUTION*x,RESOLUTION*y,
  2010.                          RESOLUTION*x_next,RESOLUTION*y_next);
  2011.                     }
  2012.                 }
  2013.               x=x_next;
  2014.             }
  2015.           y_previous=y;
  2016.           y_next++;
  2017.         }
  2018.       return;
  2019.     }
  2020.  
  2021. static int substitution_high [100] =
  2022.              { 4,1,2,8,8,9,9,6,5,7,2,1,2,9,8,8,6,3,5,1,9,5,4,4,9,8,6,0,8,0,
  2023.                6,0,2,4,1,9,2,0,7,4,7,3,0,0,2,6,8,9,4,0,8,3,2,3,2,5,2,4,6,9,
  2024.                7,9,1,3,5,7,1,1,4,5,8,1,6,0,5,7,8,2,3,3,7,3,5,1,7,5,4,0,3,6,
  2025.                3,7,7,1,9,4,0,5,6,6 
  2026.              };
  2027. static int substitution_low [100] =
  2028.              { 1,2,2,1,5,5,4,6,4,6,4,4,5,6,6,3,0,9,6,5,7,2,0,9,3,4,2,3,9,1,
  2029.                9,9,9,3,8,9,3,4,1,5,0,5,2,7,0,8,8,0,4,5,0,3,6,8,1,7,8,8,7,1,
  2030.                3,2,7,7,1,8,0,3,7,5,2,6,4,0,9,9,7,7,4,6,2,0,0,1,7,3,6,6,1,1,
  2031.                2,4,5,9,8,2,8,8,3,5 
  2032.              };
  2033. static void hash(
  2034.   int *counter_0,
  2035.   int *counter_1,
  2036.   int *counter_2,
  2037.   int *counter_3,
  2038.   int *counter_4,
  2039.   int *counter_5,
  2040.   int *counter_6,
  2041.   int *counter_7)
  2042.     {
  2043.       register int iteration = 0;
  2044.                int seed_0 = 0;
  2045.                int seed_1 = 0;
  2046.                int seed_2 = 0;
  2047.                int seed_3 = 0;
  2048.                int seed_4 = 0;
  2049.                int seed_5 = 0;
  2050.                int seed_6 = 0;
  2051.                int seed_7 = 0;
  2052.       register int substitution_index = 0;
  2053.                int tem_0 = 0;
  2054.                int tem_1 = 0;
  2055.                int tem_2 = 0;
  2056.  
  2057.       seed_0=(*counter_0);
  2058.       seed_1=(*counter_1);
  2059.       seed_2=(*counter_2);
  2060.       seed_3=(*counter_3);
  2061.       seed_4=(*counter_4);
  2062.       seed_5=(*counter_5);
  2063.       seed_6=(*counter_6);
  2064.       seed_7=(*counter_7);
  2065.       for (iteration=1; iteration <= 8; iteration++)
  2066.         {
  2067.           substitution_index=10*seed_1+seed_0;
  2068.           tem_0=substitution_low[substitution_index];
  2069.           tem_1=substitution_high[substitution_index];
  2070.           substitution_index=10*seed_3+seed_2;
  2071.           seed_0=substitution_low[substitution_index];
  2072.           tem_2=substitution_high[substitution_index];
  2073.           substitution_index=10*seed_5+seed_4;
  2074.           seed_2=substitution_low[substitution_index];
  2075.           seed_1=substitution_high[substitution_index];
  2076.           substitution_index=10*seed_7+seed_6;
  2077.           seed_5=substitution_low[substitution_index];
  2078.           seed_7=substitution_high[substitution_index];
  2079.           seed_3=tem_0;
  2080.           seed_6=tem_1;
  2081.           seed_4=tem_2;
  2082.         }
  2083.       (*counter_0)=seed_0;
  2084.       (*counter_1)=seed_1;
  2085.       (*counter_2)=seed_2;
  2086.       (*counter_3)=seed_3;
  2087.       (*counter_4)=seed_4;
  2088.       (*counter_5)=seed_5;
  2089.       (*counter_6)=seed_6;
  2090.       (*counter_7)=seed_7;
  2091.       return;
  2092.     }
  2093.  
  2094. static void increment(
  2095.   int *counter_0,
  2096.   int *counter_1,
  2097.   int *counter_2,
  2098.   int *counter_3,
  2099.   int *counter_4,
  2100.   int *counter_5,
  2101.   int *counter_6,
  2102.   int *counter_7)
  2103.     {
  2104.       register int tem = 0;
  2105.  
  2106.       tem=(*counter_0)+1;
  2107.       if (tem <= 9)
  2108.         (*counter_0)=tem;
  2109.       else
  2110.         {
  2111.           (*counter_0)=0;
  2112.           tem=(*counter_1)+1;
  2113.           if (tem <= 9)
  2114.             (*counter_1)=tem;
  2115.           else
  2116.             {
  2117.               (*counter_1)=0;
  2118.               tem=(*counter_2)+1;
  2119.               if (tem <= 9)
  2120.                 (*counter_2)=tem;
  2121.               else
  2122.                 {
  2123.                   (*counter_2)=0;
  2124.                   tem=(*counter_3)+1;
  2125.                   if (tem <= 9)
  2126.                     (*counter_3)=tem;
  2127.                   else
  2128.                     {
  2129.                       (*counter_3)=0;
  2130.                       tem=(*counter_4)+1;
  2131.                       if (tem <= 9)
  2132.                         (*counter_4)=tem;
  2133.                       else
  2134.                         {
  2135.                           (*counter_4)=0;
  2136.                           tem=(*counter_5)+1;
  2137.                           if (tem <= 9)
  2138.                             (*counter_5)=tem;
  2139.                           else
  2140.                             {
  2141.                               (*counter_5)=0;
  2142.                               tem=(*counter_6)+1;
  2143.                               if (tem <= 9)
  2144.                                 (*counter_6)=tem;
  2145.                               else
  2146.                                 {
  2147.                                   (*counter_6)=0;
  2148.                                   tem=(*counter_7)+1;
  2149.                                   if (tem <= 9)
  2150.                                     (*counter_7)=tem;
  2151.                                   else
  2152.                                     (*counter_7)=0;
  2153.                                 }
  2154.                             }
  2155.                         }
  2156.                     }
  2157.                 }
  2158.             }
  2159.         }
  2160.       return;
  2161.     }
  2162.  
  2163. static void evaluate_and_transform(
  2164.   volatile double                x_min,
  2165.   volatile double                x_max,
  2166.   volatile double                y_min,
  2167.   volatile double                y_max,
  2168.   volatile int                   num_x_divisions,
  2169.   volatile int                   num_y_divisions,
  2170.   volatile double                rotation,
  2171.   volatile double                tilt,
  2172.   volatile float      * volatile x_prime,
  2173.   volatile float      * volatile y_prime,
  2174.   volatile float      * volatile z_prime,
  2175.   volatile double     *          x_prime_max,
  2176.   volatile double     *          y_prime_min,
  2177.   volatile double     *          y_prime_max,
  2178.   volatile double     *          z_prime_min,
  2179.   volatile double     *          z_prime_max,
  2180.   volatile vertex_rec *          light,
  2181.   volatile int        * volatile x_division_index,
  2182.   volatile int        * volatile y_division_index)
  2183.     {
  2184.                double cos_rotation = 0.0;
  2185.                double cos_tilt = 0.0;
  2186.                double magnitude = 0.0;
  2187.                long   prime_num = 0l;
  2188.                double radians = 0.0;
  2189.                double radians_per_degree = 0.0;
  2190.                double sin_rotation = 0.0;
  2191.                double sin_tilt = 0.0;
  2192.                double x = 0.0;
  2193.                double x_delta = 0.0;
  2194.       register int    x_division_num = 0;
  2195.                double x_rotated = 0.0;
  2196.                double y = 0.0;
  2197.                double y_delta = 0.0;
  2198.       register int    y_division_num = 0;
  2199.                double z = 0.0;
  2200.  
  2201.       DosEnterCritSec();
  2202.       strcpy((unsigned char *) &titillator[0],"Evaluating...");
  2203.       DosExitCritSec();
  2204.       radians_per_degree=atan((double) 1.0)/((double) 45.0);
  2205.       radians=tilt*radians_per_degree;
  2206.       cos_tilt=cos(radians);
  2207.       sin_tilt=sin(radians);
  2208.       radians=rotation*radians_per_degree;
  2209.       cos_rotation=cos(radians);
  2210.       sin_rotation=sin(radians);
  2211.       z=f(x_min,y_min);
  2212.       x_rotated=x_min*cos_rotation+y_min*sin_rotation;
  2213.       *y_prime_min=-x_min*sin_rotation+y_min*cos_rotation;
  2214.       *z_prime_min=-x_rotated*sin_tilt+z*cos_tilt;
  2215.       *y_prime_max=*y_prime_min;
  2216.       *z_prime_max=*z_prime_min;
  2217.       *x_prime_max=x_rotated*cos_tilt+z*sin_tilt;
  2218.       x_delta=(double) (num_x_divisions-1);
  2219.       x_delta=(x_max-x_min)/x_delta;
  2220.       y_delta=(double) (num_y_divisions-1);
  2221.       y_delta=(y_max-y_min)/y_delta;
  2222.       x=x_min;
  2223.       prime_num=0l;
  2224.       for (x_division_num=0; 
  2225.        ((! size_maze_kill) && (x_division_num < num_x_divisions));
  2226.        x_division_num++)
  2227.         {
  2228.           y=y_min;
  2229.           for (y_division_num=0; 
  2230.            ((! size_maze_kill) && (y_division_num < num_y_divisions));
  2231.            y_division_num++)
  2232.             {
  2233.               z=f(x,y);
  2234.               z=fabs(z);
  2235.               x_division_index[prime_num]=x_division_num;
  2236.               y_division_index[prime_num]=y_division_num;
  2237.               x_rotated=x*cos_rotation+y*sin_rotation;
  2238.               y_prime[prime_num]=(float) (-x*sin_rotation+y*cos_rotation);
  2239.               x_prime[prime_num]=(float) (x_rotated*cos_tilt+z*sin_tilt);
  2240.               z_prime[prime_num]=(float) (-x_rotated*sin_tilt+z*cos_tilt);
  2241.               if (((double) (x_prime[prime_num])) > *x_prime_max)
  2242.                 *x_prime_max=(double) (x_prime[prime_num]);
  2243.               if (((double) (y_prime[prime_num])) < *y_prime_min)
  2244.                 *y_prime_min=(double) (y_prime[prime_num]);
  2245.               if (((double) (y_prime[prime_num])) > *y_prime_max)
  2246.                 *y_prime_max=(double) (y_prime[prime_num]);
  2247.               if (((double) (z_prime[prime_num])) < *z_prime_min)
  2248.                 *z_prime_min=(double) (z_prime[prime_num]);
  2249.               if (((double) (z_prime[prime_num])) > *z_prime_max)
  2250.                 *z_prime_max=(double) (z_prime[prime_num]);
  2251.               y+=y_delta;
  2252.               prime_num++;
  2253.             }
  2254.           x+=x_delta;
  2255.         }
  2256.       if ((! size_maze_kill))
  2257.         {
  2258.           magnitude=(*light).x*(*light).x;
  2259.           magnitude+=((*light).y*(*light).y);
  2260.           magnitude+=((*light).z*(*light).z);
  2261.           magnitude=sqrt(magnitude);
  2262.           (*light).x/=magnitude;
  2263.           (*light).y/=magnitude;
  2264.           (*light).z/=magnitude;
  2265.         }
  2266.       return;
  2267.     }
  2268.  
  2269. static void shade(
  2270.   volatile int                            num_x_divisions,
  2271.   volatile int                            num_y_divisions,
  2272.   volatile float               * volatile x_prime,
  2273.   volatile float               * volatile y_prime,
  2274.   volatile float               * volatile z_prime,
  2275.   volatile unsigned char       * volatile color,
  2276.   volatile vertex_rec          *          light)
  2277.     {
  2278.                double     magnitude = 0.0;
  2279.                vertex_rec normal = {0.0,0.0,0.0};
  2280.                long       prime_num = 0l;
  2281.                vertex_rec vertex [4]
  2282.        = {{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0}};
  2283.       register int        x_division_num = 0;
  2284.       register int        y_division_num = 0;
  2285.  
  2286.       DosEnterCritSec();
  2287.       strcpy((unsigned char *) &titillator[0],"Shading...");
  2288.       DosExitCritSec();
  2289.       for (x_division_num=0;
  2290.        ((! size_maze_kill) && (x_division_num < num_x_divisions));
  2291.        x_division_num++)
  2292.         {
  2293.           for (y_division_num=0; 
  2294.            ((! size_maze_kill) && (y_division_num < num_y_divisions));
  2295.            y_division_num++)
  2296.             {
  2297.               vertex[0].x=(double) (x_prime[prime_num]);
  2298.               vertex[0].y=(double) (y_prime[prime_num]);
  2299.               vertex[0].z=(double) (z_prime[prime_num]);
  2300.               if (x_division_num < (num_x_divisions-1))
  2301.                 if (y_division_num < (num_y_divisions-1))
  2302.                   {
  2303.                     prime_num+=((long) num_y_divisions);
  2304.                     vertex[1].x=(double) (x_prime[prime_num]);
  2305.                     vertex[1].y=(double) (y_prime[prime_num]);
  2306.                     vertex[1].z=(double) (z_prime[prime_num]);
  2307.                     prime_num++;
  2308.                     vertex[2].x=(double) (x_prime[prime_num]);
  2309.                     vertex[2].y=(double) (y_prime[prime_num]);
  2310.                     vertex[2].z=(double) (z_prime[prime_num]);
  2311.                     prime_num-=((long) num_y_divisions);
  2312.                     vertex[3].x=(double) (x_prime[prime_num]);
  2313.                     vertex[3].y=(double) (y_prime[prime_num]);
  2314.                     vertex[3].z=(double) (z_prime[prime_num]);
  2315.                     prime_num--;
  2316.                   }
  2317.                 else
  2318.                   {
  2319.                     prime_num--;
  2320.                     vertex[1].x=(double) (x_prime[prime_num]);
  2321.                     vertex[1].y=(double) (y_prime[prime_num]);
  2322.                     vertex[1].z=(double) (z_prime[prime_num]);
  2323.                     prime_num+=((long) num_y_divisions);
  2324.                     vertex[2].x=(double) (x_prime[prime_num]);
  2325.                     vertex[2].y=(double) (y_prime[prime_num]);
  2326.                     vertex[2].z=(double) (z_prime[prime_num]);
  2327.                     prime_num++;
  2328.                     vertex[3].x=(double) (x_prime[prime_num]);
  2329.                     vertex[3].y=(double) (y_prime[prime_num]);
  2330.                     vertex[3].z=(double) (z_prime[prime_num]);
  2331.                     prime_num-=((long) num_y_divisions);
  2332.                   }
  2333.               else
  2334.                 if (y_division_num < (num_y_divisions-1))
  2335.                   {
  2336.                     prime_num++;
  2337.                     vertex[1].x=(double) (x_prime[prime_num]);
  2338.                     vertex[1].y=(double) (y_prime[prime_num]);
  2339.                     vertex[1].z=(double) (z_prime[prime_num]);
  2340.                     prime_num-=((long) num_y_divisions);
  2341.                     vertex[2].x=(double) (x_prime[prime_num]);
  2342.                     vertex[2].y=(double) (y_prime[prime_num]);
  2343.                     vertex[2].z=(double) (z_prime[prime_num]);
  2344.                     prime_num--;
  2345.                     vertex[3].x=(double) (x_prime[prime_num]);
  2346.                     vertex[3].y=(double) (y_prime[prime_num]);
  2347.                     vertex[3].z=(double) (z_prime[prime_num]);
  2348.                     prime_num+=((long) num_y_divisions);
  2349.                   }
  2350.                 else
  2351.                   {
  2352.                     prime_num-=((long) num_y_divisions);
  2353.                     vertex[1].x=(double) (x_prime[prime_num]);
  2354.                     vertex[1].y=(double) (y_prime[prime_num]);
  2355.                     vertex[1].z=(double) (z_prime[prime_num]);
  2356.                     prime_num--;
  2357.                     vertex[2].x=(double) (x_prime[prime_num]);
  2358.                     vertex[2].y=(double) (y_prime[prime_num]);
  2359.                     vertex[2].z=(double) (z_prime[prime_num]);
  2360.                     prime_num+=((long) num_y_divisions);
  2361.                     vertex[3].x=(double) (x_prime[prime_num]);
  2362.                     vertex[3].y=(double) (y_prime[prime_num]);
  2363.                     vertex[3].z=(double) (z_prime[prime_num]);
  2364.                     prime_num++;
  2365.                   }
  2366.               normal.x
  2367.                =(vertex[1].y-vertex[0].y)*(vertex[3].z-vertex[0].z)
  2368.                -(vertex[3].y-vertex[0].y)*(vertex[1].z-vertex[0].z)
  2369.                +(vertex[2].y-vertex[1].y)*(vertex[0].z-vertex[1].z)
  2370.                -(vertex[0].y-vertex[1].y)*(vertex[2].z-vertex[1].z)
  2371.                +(vertex[3].y-vertex[2].y)*(vertex[1].z-vertex[2].z)
  2372.                -(vertex[1].y-vertex[2].y)*(vertex[3].z-vertex[2].z)
  2373.                +(vertex[0].y-vertex[3].y)*(vertex[2].z-vertex[3].z)
  2374.                -(vertex[2].y-vertex[3].y)*(vertex[0].z-vertex[3].z);
  2375.               normal.y
  2376.                =(vertex[3].x-vertex[0].x)*(vertex[1].z-vertex[0].z)
  2377.                -(vertex[1].x-vertex[0].x)*(vertex[3].z-vertex[0].z)
  2378.                +(vertex[0].x-vertex[1].x)*(vertex[2].z-vertex[1].z)
  2379.                -(vertex[2].x-vertex[1].x)*(vertex[0].z-vertex[1].z)
  2380.                +(vertex[1].x-vertex[2].x)*(vertex[3].z-vertex[2].z)
  2381.                -(vertex[3].x-vertex[2].x)*(vertex[1].z-vertex[2].z)
  2382.                +(vertex[2].x-vertex[3].x)*(vertex[0].z-vertex[3].z)
  2383.                -(vertex[0].x-vertex[3].x)*(vertex[2].z-vertex[3].z);
  2384.               normal.z
  2385.                =(vertex[1].x-vertex[0].x)*(vertex[3].y-vertex[0].y)
  2386.                -(vertex[3].x-vertex[0].x)*(vertex[1].y-vertex[0].y)
  2387.                +(vertex[2].x-vertex[1].x)*(vertex[0].y-vertex[1].y)
  2388.                -(vertex[0].x-vertex[1].x)*(vertex[2].y-vertex[1].y)
  2389.                +(vertex[3].x-vertex[2].x)*(vertex[1].y-vertex[2].y)
  2390.                -(vertex[1].x-vertex[2].x)*(vertex[3].y-vertex[2].y)
  2391.                +(vertex[0].x-vertex[3].x)*(vertex[2].y-vertex[3].y)
  2392.                -(vertex[2].x-vertex[3].x)*(vertex[0].y-vertex[3].y);
  2393.               if (normal.x < 0.0)
  2394.                 color[prime_num]=NUM_COLORS;
  2395.               else
  2396.                 {
  2397.                   magnitude
  2398.                    =sqrt(normal.x*normal.x+normal.y*normal.y+normal.z*normal.z);
  2399.                   if (magnitude == 0.0)
  2400.                     color[prime_num]=(unsigned char) 0;
  2401.                   else
  2402.                     {
  2403.                       color[prime_num]
  2404.                        =(unsigned char) ((((float) (NUM_COLORS-1))/2.0)*(1.0
  2405.                        +((*light).x*normal.x+(*light).y*normal.y
  2406.                        +(*light).z*normal.z)/magnitude));
  2407.                       if (color[prime_num] >= (unsigned char) (NUM_COLORS-1))
  2408.                         color[prime_num]=(unsigned char) (NUM_COLORS-2);
  2409.                     }
  2410.                 }
  2411.               prime_num++;
  2412.             }
  2413.         }
  2414.       return;
  2415.     }
  2416.  
  2417. static void adjust_perspective(
  2418.   volatile int               num_x_divisions,
  2419.   volatile int               num_y_divisions,
  2420.   volatile float  * volatile x_prime,
  2421.   volatile float  * volatile y_prime,
  2422.   volatile float  * volatile z_prime,
  2423.   volatile double            x_prime_max,
  2424.   volatile double            y_prime_min,
  2425.   volatile double            y_prime_max,
  2426.   volatile double            z_prime_min,
  2427.   volatile double            z_prime_max)  
  2428.     {
  2429.                long       prime_num = 0l;
  2430.                vertex_rec vertex [4]
  2431.        = {{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0}};
  2432.       register int        x_division_num = 0;
  2433.                double     x_eye = 0.0;
  2434.                double     y_center = 0.0;
  2435.       register int        y_division_num = 0;
  2436.                double     z_center = 0.0;
  2437.  
  2438.       DosEnterCritSec();
  2439.       strcpy((unsigned char *) &titillator[0],"Adjusting...");
  2440.       DosExitCritSec();
  2441.       if ((y_prime_max-y_prime_min) > (z_prime_max-z_prime_min))
  2442.         x_eye=1.1*(y_prime_max-y_prime_min)+x_prime_max;
  2443.       else
  2444.         x_eye=1.1*(z_prime_max-z_prime_min)+x_prime_max;
  2445.       if (((y_prime_max-y_prime_min) > (z_prime_max-z_prime_min))
  2446.       ||  (z_prime_max != z_prime_min))
  2447.         {
  2448.           y_center=(y_prime_max+y_prime_min)/2.0;
  2449.           z_center=(z_prime_max+z_prime_min)/2.0;
  2450.           prime_num=0l;
  2451.           for (x_division_num=0; 
  2452.            ((! size_maze_kill) && (x_division_num < num_x_divisions));
  2453.            x_division_num++)
  2454.             {
  2455.               for (y_division_num=0; 
  2456.                ((! size_maze_kill) && (y_division_num < num_y_divisions));
  2457.                y_division_num++)
  2458.                 {
  2459.                   vertex[0].x=(double) (x_prime[prime_num]);
  2460.                   vertex[0].y=(double) (y_prime[prime_num]);
  2461.                   vertex[0].z=(double) (z_prime[prime_num]);
  2462.                   if (x_division_num < (num_x_divisions-1))
  2463.                     if (y_division_num < (num_y_divisions-1))
  2464.                       {
  2465.                         prime_num+=((long) num_y_divisions);
  2466.                         vertex[1].x=(double) (x_prime[prime_num]);
  2467.                         vertex[1].y=(double) (y_prime[prime_num]);
  2468.                         vertex[1].z=(double) (z_prime[prime_num]);
  2469.                         prime_num++;
  2470.                         vertex[2].x=(double) (x_prime[prime_num]);
  2471.                         vertex[2].y=(double) (y_prime[prime_num]);
  2472.                         vertex[2].z=(double) (z_prime[prime_num]);
  2473.                         prime_num-=((long) num_y_divisions);
  2474.                         vertex[3].x=(double) (x_prime[prime_num]);
  2475.                         vertex[3].y=(double) (y_prime[prime_num]);
  2476.                         vertex[3].z=(double) (z_prime[prime_num]);
  2477.                         prime_num--;
  2478.                       }
  2479.                     else
  2480.                       {
  2481.                         prime_num--;
  2482.                         vertex[1].x=(double) (x_prime[prime_num]);
  2483.                         vertex[1].y=(double) (y_prime[prime_num]);
  2484.                         vertex[1].z=(double) (z_prime[prime_num]);
  2485.                         prime_num+=((long) num_y_divisions);
  2486.                         vertex[2].x=(double) (x_prime[prime_num]);
  2487.                         vertex[2].y=(double) (y_prime[prime_num]);
  2488.                         vertex[2].z=(double) (z_prime[prime_num]);
  2489.                         prime_num++;
  2490.                         vertex[3].x=(double) (x_prime[prime_num]);
  2491.                         vertex[3].y=(double) (y_prime[prime_num]);
  2492.                         vertex[3].z=(double) (z_prime[prime_num]);
  2493.                         prime_num-=((long) num_y_divisions);
  2494.                       }
  2495.                   else
  2496.                     if (y_division_num < (num_y_divisions-1))
  2497.                       {
  2498.                         prime_num++;
  2499.                         vertex[1].x=(double) (x_prime[prime_num]);
  2500.                         vertex[1].y=(double) (y_prime[prime_num]);
  2501.                         vertex[1].z=(double) (z_prime[prime_num]);
  2502.                         prime_num-=((long) num_y_divisions);
  2503.                         vertex[2].x=(double) (x_prime[prime_num]);
  2504.                         vertex[2].y=(double) (y_prime[prime_num]);
  2505.                         vertex[2].z=(double) (z_prime[prime_num]);
  2506.                         prime_num--;
  2507.                         vertex[3].x=(double) (x_prime[prime_num]);
  2508.                         vertex[3].y=(double) (y_prime[prime_num]);
  2509.                         vertex[3].z=(double) (z_prime[prime_num]);
  2510.                         prime_num+=((long) num_y_divisions);
  2511.                       }
  2512.                     else
  2513.                       {
  2514.                         prime_num-=((long) num_y_divisions);
  2515.                         vertex[1].x=(double) (x_prime[prime_num]);
  2516.                         vertex[1].y=(double) (y_prime[prime_num]);
  2517.                         vertex[1].z=(double) (z_prime[prime_num]);
  2518.                         prime_num--;
  2519.                         vertex[2].x=(double) (x_prime[prime_num]);
  2520.                         vertex[2].y=(double) (y_prime[prime_num]);
  2521.                         vertex[2].z=(double) (z_prime[prime_num]);
  2522.                         prime_num+=((long) num_y_divisions);
  2523.                         vertex[3].x=(double) (x_prime[prime_num]);
  2524.                         vertex[3].y=(double) (y_prime[prime_num]);
  2525.                         vertex[3].z=(double) (z_prime[prime_num]);
  2526.                         prime_num++;
  2527.                       }
  2528.                   y_prime[prime_num]=(float) (y_center
  2529.                    +(vertex[0].y-y_center)*(x_eye-x_prime_max)
  2530.                    /(x_eye-vertex[0].x));
  2531.                   z_prime[prime_num]=(float) (z_center
  2532.                    +(vertex[0].z-z_center)*(x_eye-x_prime_max)
  2533.                    /(x_eye-vertex[0].x));
  2534.                   x_prime[prime_num]=(float)
  2535.                    (-(vertex[0].x+vertex[1].x+vertex[2].x+vertex[3].x)/4.0);
  2536.                   prime_num++;
  2537.                 }
  2538.             }
  2539.          }
  2540.       return;
  2541.     }
  2542.  
  2543. static void sort_back_to_front(
  2544.   volatile long             num_primes,
  2545.   volatile float * volatile x_prime,
  2546.   volatile int   * volatile x_division_index,
  2547.   volatile int   * volatile y_division_index)
  2548.     {
  2549.                int   finished = 0;
  2550.                long  key_index_1 = 0l;
  2551.                long  key_index_2 = 0l;
  2552.                long  left = 0l;
  2553.                long  right = 0l;
  2554.                float t1 = (float) 0.0;
  2555.       register int   t2 = 0;
  2556.       register int   t3 = 0;
  2557.  
  2558.       DosEnterCritSec();
  2559.       strcpy((unsigned char *) &titillator[0],"Sorting...");
  2560.       DosExitCritSec();
  2561.       left=num_primes/((long) 2);
  2562.       right=num_primes-1l;
  2563.       t1=x_prime[0];
  2564.       t2=x_division_index[0];
  2565.       t3=y_division_index[0];
  2566.       while ((! size_maze_kill) && (right > 0l))
  2567.         {
  2568.           if (left > 0l)
  2569.             {
  2570.               left--;
  2571.               t1=x_prime[left];
  2572.               t2=x_division_index[left];
  2573.               t3=y_division_index[left];
  2574.             }
  2575.           else
  2576.             {
  2577.               t1=x_prime[right];
  2578.               t2=x_division_index[right];
  2579.               t3=y_division_index[right];
  2580.               x_prime[right]=x_prime[0];
  2581.               x_division_index[right]=x_division_index[0];
  2582.               y_division_index[right]=y_division_index[0];
  2583.               right--;
  2584.             }
  2585.           if (right > 0l)
  2586.             {
  2587.               finished=FALSE;
  2588.               key_index_2=left;
  2589.               while (! finished)
  2590.                 {
  2591.                   key_index_1=key_index_2;
  2592.                   key_index_2+=key_index_2;
  2593.                   key_index_2++;
  2594.                   if (key_index_2 > right)
  2595.                     finished=TRUE;
  2596.                   else
  2597.                     {
  2598.                       if (key_index_2 != right)
  2599.                         {
  2600.                           if (x_prime[key_index_2] > x_prime[key_index_2+1])
  2601.                             key_index_2++;
  2602.                         }
  2603.                       if (t1 <= x_prime[key_index_2])
  2604.                         finished=TRUE;
  2605.                       else
  2606.                         {
  2607.                           x_prime[key_index_1]=x_prime[key_index_2];
  2608.                           x_division_index[key_index_1]
  2609.                            =x_division_index[key_index_2];
  2610.                           y_division_index[key_index_1]
  2611.                            =y_division_index[key_index_2];
  2612.                         }
  2613.                     }
  2614.                 }
  2615.               x_prime[key_index_1]=t1;
  2616.               x_division_index[key_index_1]=t2;
  2617.               y_division_index[key_index_1]=t3;
  2618.             }
  2619.         }
  2620.       x_prime[0]=t1;
  2621.       x_division_index[0]=t2;
  2622.       y_division_index[0]=t3;
  2623.       return;
  2624.     }
  2625.  
  2626. static void plot(
  2627.   volatile int                      num_x_divisions,
  2628.   volatile int           * volatile x_division_index,
  2629.   volatile int                      num_y_divisions,
  2630.   volatile int           * volatile y_division_index,
  2631.   volatile long                     num_primes,
  2632.   volatile float         * volatile y_prime, 
  2633.   volatile float         * volatile z_prime,
  2634.   volatile double                   y_prime_min,
  2635.   volatile double                   y_prime_max,
  2636.   volatile double                   z_prime_min,
  2637.   volatile double                   z_prime_max,
  2638.   volatile unsigned char * volatile color)
  2639.     {  
  2640.       POINTL     box [4] = {{0l,0l},{0l,0l},{0l,0l},{0l,0l}};
  2641.       int        box_num = 0;
  2642.       short      color_num = (short) 0;
  2643.       BYTE       jobid = (BYTE) 0;
  2644.       LONG       outdata = 0l;
  2645.       double     pixels_per_unit = 0.0;
  2646.       long       prime_num = 0l;
  2647.       POINTL     ptlPosition = { 0l,0l };
  2648.       long       rgb [NUM_COLORS] 
  2649.        = { 0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l };
  2650.       long       rgb_increment = 0l;
  2651.       SIZEL      sizl = { 0l,0l };
  2652.       long       tint = 0l;
  2653.       vertex_rec vertex [4] 
  2654.        = {{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0}};
  2655.       int        x_division_num = 0;
  2656.       long       x_prime_num = 0l;
  2657.       int        y_division_num = 0;
  2658.       double     y_offset = 0.0;
  2659.       double     y_out_max = 0.0;
  2660.       double     z_offset = 0.0;
  2661.       double     z_out_max = 0.0;
  2662.  
  2663.       DosEnterCritSec();
  2664.       strcpy((unsigned char *) &titillator[0],"Plotting...");
  2665.       DosExitCritSec();
  2666.       sizl.cx=0;
  2667.       sizl.cy=0;
  2668.       hPS=GpiCreatePS(habPrint,dev_context_handle,&sizl,
  2669.        ((ULONG) PU_PELS)|((ULONG) GPIA_ASSOC));
  2670.       if ((ULONG) hPS == (ULONG) GPI_ERROR)
  2671.         {
  2672.           DosEnterCritSec();
  2673.           strcpy((unsigned char *) &titillator[0],"Cannot create PS!");
  2674.           DosExitCritSec();
  2675.         }
  2676.       else
  2677.         {
  2678.           outdata=0;
  2679.           if (DevEscape(dev_context_handle,DEVESC_STARTDOC,8l,
  2680.            (PBYTE) "LPTHEX",&outdata,(PBYTE) NULL) != DEV_OK)
  2681.             {
  2682.               DosEnterCritSec();
  2683.               strcpy((unsigned char *) &titillator[0],"Cannot start doc!");
  2684.               DosExitCritSec();
  2685.             }
  2686.           else
  2687.             {
  2688.               if (! GpiErase(hPS))
  2689.                 {
  2690.                   DosEnterCritSec();
  2691.                   sprintf((unsigned char *) &titillator[0],
  2692.                    "GpiErase error 0x%4X",WinGetLastError(habPrint)%65536);
  2693.                   DosExitCritSec();
  2694.                   size_maze_kill=TRUE;
  2695.                 }
  2696.               if (! size_maze_kill)
  2697.                 {
  2698.                   rgb_increment=0x111111;
  2699.                   tint=0l;
  2700.                   for (color_num=0; color_num < (NUM_COLORS-1); color_num++)
  2701.                     {
  2702.                       rgb[color_num]=tint;
  2703.                       tint+=rgb_increment;
  2704.                     }
  2705.                   rgb[NUM_COLORS-1]=0xff0000;
  2706.                   if (! GpiCreateLogColorTable(hPS,LCOL_RESET,LCOLF_CONSECRGB,
  2707.                    0L,16L,&rgb[0]))
  2708.                     {
  2709.                       DosEnterCritSec();
  2710.                       sprintf((unsigned char *) &titillator[0],
  2711.                        "GpiCreateLogColorTable error 0x%4X",
  2712.                        WinGetLastError(habPrint)%65536);
  2713.                       DosExitCritSec();
  2714.                       size_maze_kill=TRUE;
  2715.                     }
  2716.                 }
  2717.               if (! size_maze_kill)
  2718.                 {
  2719.                   y_out_max=(double) iMaxX;
  2720.                   z_out_max=(double) iMaxY;
  2721.                   if (aspect_ratio*z_out_max*(y_prime_max-y_prime_min)
  2722.                    > y_out_max*(z_prime_max-z_prime_min))
  2723.                     {
  2724.                       pixels_per_unit
  2725.                        =y_out_max/(aspect_ratio*(y_prime_max-y_prime_min));
  2726.                       y_offset=0.0;
  2727.                       z_offset
  2728.                        =(z_out_max-pixels_per_unit
  2729.                        *(z_prime_max-z_prime_min))/2.0;
  2730.                     }
  2731.                   else
  2732.                     if (aspect_ratio*z_out_max*(y_prime_max-y_prime_min)
  2733.                      < y_out_max*(z_prime_max-z_prime_min))
  2734.                       {
  2735.                         pixels_per_unit=z_out_max/(z_prime_max-z_prime_min);
  2736.                         y_offset=(y_out_max
  2737.                          -aspect_ratio*pixels_per_unit
  2738.                          *(y_prime_max-y_prime_min))/2.0;
  2739.                         z_offset=0.0;
  2740.                       }
  2741.                     else
  2742.                       {
  2743.                         pixels_per_unit=1.0;
  2744.                         y_offset=y_out_max/2.0;
  2745.                         z_offset=z_out_max/2.0;
  2746.                       }
  2747.                 }
  2748.               for (x_prime_num=0l;
  2749.                ((! size_maze_kill) && (x_prime_num < num_primes));
  2750.                x_prime_num++)
  2751.                 {
  2752.                   x_division_num=x_division_index[x_prime_num];
  2753.                   if (x_division_num < (num_x_divisions-1))
  2754.                     {
  2755.                       y_division_num=y_division_index[x_prime_num];
  2756.                       if (y_division_num < (num_y_divisions-1))
  2757.                         {
  2758.                           prime_num
  2759.                            =((long) num_y_divisions)*((long) x_division_num)
  2760.                            +((long) y_division_num);
  2761.                           color_num=(short) (color[prime_num]);
  2762.                           if (color_num < NUM_COLORS)
  2763.                             {
  2764.                               vertex[0].y=(double) (y_prime[prime_num]);
  2765.                               vertex[0].z=(double) (z_prime[prime_num]);
  2766.                               prime_num+=((long) num_y_divisions);
  2767.                               vertex[1].y=(double) (y_prime[prime_num]);
  2768.                               vertex[1].z=(double) (z_prime[prime_num]);
  2769.                               prime_num++;
  2770.                               vertex[2].y=(double) (y_prime[prime_num]);
  2771.                               vertex[2].z=(double) (z_prime[prime_num]);
  2772.                               prime_num-=((long) num_y_divisions);
  2773.                               vertex[3].y=(double) (y_prime[prime_num]);
  2774.                               vertex[3].z=(double) (z_prime[prime_num]);
  2775.                               for (box_num=0; box_num < 4; box_num++)
  2776.                                 {
  2777.                                   box[box_num].x=(long) (y_offset
  2778.                                    +pixels_per_unit*aspect_ratio
  2779.                                    *(vertex[box_num].y-y_prime_min));
  2780.                                   box[box_num].y=(long) (z_offset
  2781.                                    +pixels_per_unit
  2782.                                    *(vertex[box_num].z-z_prime_min));
  2783.                                 }
  2784.                               if (GpiBeginPath(hPS,1L))
  2785.                                 {
  2786.                                   ptlPosition.x=box[3].x;
  2787.                                   ptlPosition.y=box[3].y;
  2788.                                   if (GpiMove(hPS,&ptlPosition))
  2789.                                     if (GpiPolyLine(hPS,4l,box) == GPI_ERROR)
  2790.                                       {
  2791.                                         DosEnterCritSec();
  2792.                                         sprintf((unsigned char *) &titillator[0],
  2793.                                          "GpiPolyLine error 0x%4X",
  2794.                                          WinGetLastError(habPrint)%65536);
  2795.                                         DosExitCritSec();
  2796.                                         size_maze_kill=TRUE;
  2797.                                       }
  2798.                                     else
  2799.                                       if (GpiEndPath(hPS))
  2800.                                         if (GpiSetColor(hPS,color_num))
  2801.                                           {
  2802.                                             if (GpiFillPath(hPS,1l,
  2803.                                              FPATH_ALTERNATE) == GPI_ERROR)
  2804.                                               {
  2805.                                                 DosEnterCritSec();
  2806.                                                 sprintf((unsigned char *)
  2807.                                                  &titillator[0],
  2808.                                                  "GpiSetColor error 0x%4X",
  2809.                                                  WinGetLastError(habPrint)
  2810.                                                  %65536);
  2811.                                                 DosExitCritSec();
  2812.                                                 size_maze_kill=TRUE;
  2813.                                               }
  2814.                                           }
  2815.                                         else
  2816.                                           {
  2817.                                             DosEnterCritSec();
  2818.                                             sprintf((unsigned char *)
  2819.                                              &titillator[0],
  2820.                                              "GpiSetColor error 0x%4X",
  2821.                                              WinGetLastError(habPrint)%65536);
  2822.                                             DosExitCritSec();
  2823.                                             size_maze_kill=TRUE;
  2824.                                           }
  2825.                                       else
  2826.                                         {
  2827.                                           DosEnterCritSec();
  2828.                                           sprintf((unsigned char *)
  2829.                                            &titillator[0],
  2830.                                            "GpiEndPath error 0x%4X",
  2831.                                            WinGetLastError(habPrint)%65536);
  2832.                                           DosExitCritSec();
  2833.                                           size_maze_kill=TRUE;
  2834.                                         }
  2835.                                   else
  2836.                                     {
  2837.                                       DosEnterCritSec();
  2838.                                       sprintf((unsigned char *) &titillator[0],
  2839.                                        "GpiMove error 0x%4X",
  2840.                                        WinGetLastError(habPrint)%65536);
  2841.                                       DosExitCritSec();
  2842.                                       size_maze_kill=TRUE;
  2843.                                     }
  2844.                                 }
  2845.                               else
  2846.                                 {
  2847.                                   DosEnterCritSec();
  2848.                                   sprintf((unsigned char *) &titillator[0],
  2849.                                    "GpiBeginPath error 0x%4X",
  2850.                                    WinGetLastError(habPrint)%65536);
  2851.                                   DosExitCritSec();
  2852.                                   size_maze_kill=TRUE;
  2853.                                 }
  2854.                             }
  2855.                         }
  2856.                     }
  2857.                 }
  2858.               if (size_maze_kill)
  2859.                 DevEscape(dev_context_handle,DEVESC_ABORTDOC,0l,(PBYTE) NULL,
  2860.                  &outdata,(PBYTE) NULL);
  2861.               else
  2862.                 {
  2863.                   DevEscape(dev_context_handle,DEVESC_NEWFRAME,0l,(PBYTE) NULL,
  2864.                    &outdata,(PBYTE) NULL);
  2865.                   outdata=2;
  2866.                   DevEscape(dev_context_handle,DEVESC_ENDDOC,0l,(PBYTE) NULL,
  2867.                    &outdata,(PBYTE) &jobid);
  2868.                 }
  2869.             }
  2870.           GpiAssociate(hPS,(HDC) NULL);
  2871.           GpiDestroyPS(hPS);
  2872.         }
  2873.       DevCloseDC(dev_context_handle);
  2874.       WinTerminate((HAB) habPrint);
  2875.       if (! size_maze_kill)
  2876.         {
  2877.           DosEnterCritSec();
  2878.           WinPostMsg(plot_hwnd,(ULONG) WM_PLOT_DONE,(MPARAM) NULL,
  2879.            (MPARAM) NULL);
  2880.           DosExitCritSec();
  2881.         }
  2882.       return;
  2883.     }
  2884.  
  2885. static void destroy_maze(
  2886.   volatile float         * volatile *x_prime,
  2887.   volatile float         * volatile *y_prime,
  2888.   volatile float         * volatile *z_prime,
  2889.   volatile int           * volatile *x_division_index,
  2890.   volatile int           * volatile *y_division_index,
  2891.   volatile unsigned char * volatile *color,
  2892.   volatile stack_rec     * volatile *stack)
  2893.     {
  2894.       int y = 0;
  2895.  
  2896.       if (*stack != (volatile stack_rec * volatile) NULL)
  2897.         {
  2898.           free((void *) *stack);
  2899.           *stack=(volatile stack_rec * volatile) NULL;
  2900.         }
  2901.       if (*color != (unsigned char * volatile) NULL)
  2902.         {
  2903.           free((void *) *color);
  2904.           *color=(volatile unsigned char * volatile) NULL;
  2905.         }
  2906.       if (*y_division_index != (int * volatile) NULL)
  2907.         {
  2908.           free((void *) *y_division_index);
  2909.           *y_division_index=(volatile int * volatile) NULL;
  2910.         }
  2911.       if (*x_division_index != (int * volatile) NULL)
  2912.         {
  2913.           free((void *) *x_division_index);
  2914.           *x_division_index=(volatile int * volatile) NULL;
  2915.         }
  2916.       if (*z_prime != (float * volatile) NULL)
  2917.         {
  2918.           free((void *) *z_prime);
  2919.           *z_prime=(volatile float * volatile) NULL;
  2920.         }
  2921.       if (*y_prime != (float * volatile) NULL)
  2922.         {
  2923.           free((void *) *y_prime);
  2924.           *y_prime=(volatile float * volatile) NULL;
  2925.         }
  2926.       if (*x_prime != (float * volatile) NULL)
  2927.         {
  2928.           free((void *) *x_prime);
  2929.           *x_prime=(volatile float * volatile) NULL;
  2930.         }
  2931.       if (page != (char ** volatile) NULL)
  2932.         {
  2933.           for (y=0; y < num_y_dots; y++)
  2934.             free((void *) (page[y]));
  2935.           free((void *) page);
  2936.           page=(volatile char * volatile * volatile) NULL;
  2937.         }
  2938.       if (base_page != (char ** volatile) NULL)
  2939.         {
  2940.           for (y=0; y < max_y_plus_1; y++)
  2941.             free((void *) (base_page[y]));
  2942.           free((void *) base_page);
  2943.           base_page=(volatile char * volatile * volatile) NULL;
  2944.         }
  2945.       return;
  2946.     }
  2947.  
  2948. static double f(
  2949.   double x,
  2950.   double y)
  2951.     {
  2952.       register int    x_out = 0;
  2953.       register int    y_out = 0;
  2954.                double z = 0.0;
  2955.  
  2956.       y_out=(int) x;
  2957.       if (y_out < 0)
  2958.         z=0.0;
  2959.       else
  2960.         if (y_out > y_dot_max)
  2961.           z=0.0;
  2962.         else
  2963.           {
  2964.             x_out=(int) y;
  2965.             if (x_out < 0)
  2966.               z=0.0;
  2967.             else
  2968.               if (x_out > x_dot_max)
  2969.                 z=0.0;
  2970.               else
  2971.                 if (page[y_out][x_out] == 'W')
  2972.                   z=((double) (5*RESOLUTION));
  2973.                 else
  2974.                   z=0.0;
  2975.           }
  2976.       return(z);
  2977.     }
  2978.  
  2979.