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

  1. #include <stdio.h>
  2. #define INCL_WIN
  3. #define INCL_GPI
  4. #define INCL_PM
  5. #define INCL_DOS
  6. #include <os2.h>
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <math.h>
  10. #include "hexmaze.h"
  11.  
  12. #define ERROR_COLOR            CLR_RED
  13. #define NUM_COLORS                  16
  14. #define PIXELS_PER_ROOM             40
  15. #define RESOLUTION                   4
  16. #define WM_PLOT_DONE           WM_USER
  17.  
  18. /* screen constants */
  19. #define WIDTH_OF_SCREEN        8.0
  20. #define HEIGHT_OF_SCREEN       6.0 /* same units as WIDTH_OF_SCREEN */
  21.  
  22. typedef struct
  23.           {
  24.             unsigned char red;
  25.             unsigned char green;
  26.             unsigned char blue;
  27.           } rgb_rec;
  28.  
  29. typedef struct stack_rec_record
  30.           {
  31.             char          index_1;
  32.             int           index_2;
  33.           } stack_rec;
  34.  
  35. typedef struct
  36.           {
  37.             double x;
  38.             double y;
  39.             double z;
  40.           } vertex_rec;
  41.  
  42. static void             adjust_perspective(volatile int,volatile int,
  43.                          volatile float * volatile,volatile float * volatile,
  44.                          volatile float * volatile,volatile double,
  45.                          volatile double,volatile double,volatile double,
  46.                          volatile double);
  47.        MRESULT EXPENTRY client_window_proc(HWND,ULONG,MPARAM,MPARAM);
  48. static void             destroy_maze(volatile float * volatile *,
  49.                          volatile float * volatile *,
  50.                          volatile float * volatile *,volatile int * volatile *,
  51.                          volatile int * volatile *,
  52.                          volatile unsigned char * volatile *,
  53.                          volatile unsigned char * volatile *,
  54.                          volatile stack_rec * volatile *);
  55. static void             draw_line_on_page(int,int,int,int);
  56. static void             evaluate_and_transform(volatile double,volatile double,
  57.                          volatile double,volatile double,volatile int,
  58.                          volatile int,volatile double,volatile double,
  59.                          volatile float * volatile,volatile float * volatile,
  60.                          volatile float * volatile,volatile double *,
  61.                          volatile double *,volatile double *,
  62.                          volatile double *,volatile double *,
  63.                          volatile vertex_rec *,volatile int * volatile,
  64.                          volatile int * volatile,
  65.                          volatile unsigned char * volatile);
  66. static double           f(double,double);
  67. static void             generate_maze(void);
  68. static void             hash(int *,int *,int *,int *,int *,int *,int *,int *);
  69. static void             increment(int *,int *,int *,int *,int *,int *,int *,
  70.                          int *);
  71.        MRESULT EXPENTRY help_proc(HWND,ULONG,MPARAM,MPARAM);
  72.        int              main(void);
  73. static int              memory_allocated(volatile long,
  74.                          volatile float * volatile *,
  75.                          volatile float * volatile *,
  76.                          volatile float * volatile *,
  77.                          volatile int * volatile *,
  78.                          volatile int * volatile *,
  79.                          volatile unsigned char * volatile *,
  80.                          volatile unsigned char * volatile *,volatile int,
  81.                          volatile stack_rec * volatile *);
  82. static void             plot(void *);
  83. static void             set_point_on_page(int,int);
  84. static void             shade(volatile int,volatile int,
  85.                          volatile float * volatile,volatile float * volatile,
  86.                          volatile float * volatile,
  87.                          volatile unsigned char * volatile,
  88.                          volatile vertex_rec *);
  89. static void             size_maze(void *);
  90. static void             sort_back_to_front(volatile long,
  91.                          volatile float * volatile,volatile int * volatile,
  92.                          volatile int * volatile);
  93. static void             solve_maze(volatile stack_rec * volatile,
  94.                          volatile char * volatile * volatile,int *,int *,
  95.                          volatile int,volatile int);
  96.  
  97. static volatile double                              aspect_ratio = 0.0;
  98. static volatile char          * volatile * volatile base_page
  99.  = (volatile char * volatile * volatile) NULL;
  100. static volatile unsigned char * volatile            base_z
  101.  = (volatile unsigned char * volatile) NULL;
  102. static volatile unsigned char * volatile            color
  103.  = (volatile unsigned char * volatile) NULL;
  104. static volatile int                                 delta_x [6] [720]
  105.  ={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  106.  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,
  213.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  214.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  215.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  216.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  217.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  218.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  219.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  220.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  221.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  222.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  223.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  224.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  225. static volatile int                                 delta_y [6] [720]
  226.  ={{0,0,0,0,0,0,0,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,0,
  334.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  335.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  336.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  337.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  338.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  339.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  340.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  341.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  342.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  343.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  344.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  345.  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  346.        volatile HPS                                 hPS = (HPS) 0;
  347. static volatile short                               horizontal_scroll_position
  348.  = (short) 0;
  349. static volatile HWND                                hwndHscroll = (HWND) 0;
  350. static volatile HWND                                hwndVscroll = (HWND) 0;
  351. static volatile int                                 iFatalError = 0;
  352. static volatile int                                 iMaxX = 0;
  353. static volatile int                                 iMaxY = 0;
  354. static volatile vertex_rec                          light = {0.0,0.0,0.0};
  355. static volatile int                                 max_x = 0;
  356. static volatile int                                 max_x_plus_1 = 0;
  357. static volatile int                                 max_y = 0;
  358. static volatile int                                 max_y_plus_1 = 0;
  359. static volatile int                                 num_columns = 0;
  360. static volatile long                                num_primes = 0l;
  361. static volatile int                                 num_rooms_in_maze = 0;
  362. static volatile int                                 num_rows = 0;
  363. static volatile int                                 num_x_divisions = 0;
  364. static volatile int                                 num_x_dots = 0;
  365. static volatile int                                 num_y_divisions = 0;
  366. static volatile int                                 num_y_dots = 0;
  367. static volatile char          * volatile * volatile page
  368.  = (volatile char * volatile * volatile) NULL;
  369.        volatile HEV                                 plot_active = (HEV) 0;
  370. static volatile int                                 plot_command = 0;
  371.        volatile HWND                                plot_hwnd = (HWND) 0;
  372. static volatile int                                 plot_kill = 0;
  373. static volatile ULONG                               plot_post_count = (ULONG) 0;
  374. static volatile ULONG                               plotting = (ULONG) 0;
  375. static volatile int                                 r_n [8]
  376.  = {0,0,0,0,0,0,0,0};
  377. static volatile int                                 r_n_seed [7]
  378.  = {0,0,0,0,0,0,0};
  379. static volatile int                                 resized = 0;
  380. static volatile double                              rotation = 0.0;
  381.        volatile HEV                                 size_maze_active = (HEV) 0;
  382. static volatile int                                 size_maze_kill = 0;
  383. static volatile ULONG                               size_maze_post_count 
  384.  = (ULONG) 0;
  385. static volatile ULONG                               sizing = (ULONG) 0;
  386. static volatile int                                 solve_draw_or_clear = 0;
  387. static volatile stack_rec     * volatile            stack
  388.  = (volatile stack_rec * volatile) NULL;
  389. static volatile double                              tilt = 0.0;
  390. static volatile short                               vertical_scroll_position
  391.  = (short) 0;
  392. static volatile int           * volatile            x_division_index
  393.  = (volatile int * volatile) NULL;
  394. static volatile int                                 x_dot_max = 0;
  395. static volatile double                              x_max = 0.0;
  396. static volatile double                              x_min = 0.0;
  397. static volatile float         * volatile            x_prime
  398.  = (volatile float * volatile) NULL;
  399. static volatile double                              x_prime_max = 0.0;
  400. static volatile int           * volatile            y_division_index
  401.  = (volatile int * volatile) NULL;
  402. static volatile int                                 y_dot_max = 0;
  403. static volatile double                              y_max = 0.0;
  404. static volatile double                              y_min = 0.0;
  405. static volatile float         * volatile            y_prime
  406.  = (volatile float * volatile) NULL;
  407. static volatile double                              y_prime_max = 0.0;
  408. static volatile double                              y_prime_min = 0.0;
  409. static volatile float         * volatile            z_prime
  410.  = (volatile float * volatile) NULL;
  411. static volatile double                              z_prime_max = 0.0;
  412. static volatile double                              z_prime_min = 0.0;
  413.  
  414. int main(void)
  415.   {
  416.            ULONG ctldata = (ULONG) 0;
  417.            HAB   hAB = (HAB) 0;
  418.            HMQ   hmq = (HMQ) 0;
  419.            HWND  hwndClient = (HWND) 0;
  420.            HWND  hwndFrame = (HWND) 0;
  421.            QMSG  qmsg
  422.      ={(HWND) 0,(ULONG) 0,(MPARAM) 0,(MPARAM) 0,(ULONG) 0,{0l,0l}};
  423.     static CHAR  szClientClass [] = "3D Maze";
  424.  
  425.     DosCreateEventSem((PSZ) NULL,(PHEV) &plot_active,(ULONG) 0,(BOOL32) 1);
  426.     DosCreateEventSem((PSZ) NULL,(PHEV) &size_maze_active,(ULONG) 0,(BOOL32) 1);
  427.     hAB=WinInitialize((ULONG) 0);
  428.     hmq=WinCreateMsgQueue(hAB,0l);
  429.     WinRegisterClass(hAB,(PSZ) szClientClass,(PFNWP) client_window_proc,
  430.      (ULONG) CS_SIZEREDRAW,(ULONG) 0);
  431.     ctldata=(((ULONG) FCF_STANDARD) | ((ULONG) FCF_HORZSCROLL) |
  432.     ((ULONG) FCF_VERTSCROLL));
  433.     hwndFrame=WinCreateStdWindow((HWND) HWND_DESKTOP,(ULONG) WS_VISIBLE,
  434.      &ctldata,(PSZ) szClientClass,(PSZ) NULL,(ULONG) 0,(HMODULE) NULL,
  435.      (ULONG) ID_MAINMENU,(PHWND) &hwndClient);
  436.     WinShowWindow((HWND) hwndFrame,(BOOL) TRUE);
  437.     while (WinGetMsg((HAB) hAB,(PQMSG) &qmsg,(HWND) NULL,(ULONG) 0,(ULONG) 0))
  438.      WinDispatchMsg((HAB) hAB,(PQMSG) &qmsg);
  439.     WinDestroyWindow((HWND) hwndFrame);
  440.     WinDestroyMsgQueue((HMQ) hmq);
  441.     WinTerminate((HAB) hAB);
  442.     return(0);
  443.   }
  444.  
  445. MRESULT EXPENTRY client_window_proc(
  446.   HWND   hwnd,
  447.   ULONG  msg,
  448.   MPARAM mp1,
  449.   MPARAM mp2)
  450.     {
  451.       DATETIME dateSeed
  452.        ={(UCHAR) 0,(UCHAR) 0,(UCHAR) 0,(UCHAR) 0,(UCHAR) 0,(UCHAR) 0,
  453.        (USHORT) 0,(SHORT) 0,(UCHAR) 0};
  454.       MRESULT  result = (MRESULT) 0;
  455.   
  456.       switch (msg)
  457.         {
  458.           case WM_CREATE:
  459.             iFatalError=FALSE;
  460.             DosGetDateTime(&dateSeed);
  461.             r_n_seed[0]=dateSeed.year%10;
  462.             r_n_seed[1]=dateSeed.month%10;
  463.             r_n_seed[2]=dateSeed.day%10;
  464.             r_n_seed[3]=dateSeed.hours%10;
  465.             r_n_seed[4]=dateSeed.minutes%10;
  466.             r_n_seed[5]=dateSeed.seconds%10;
  467.             r_n_seed[6]=dateSeed.hundredths%10;
  468.             hwndHscroll=WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  469.              FID_HORZSCROLL);
  470.             WinSendMsg(hwndHscroll,SBM_SETSCROLLBAR,MPFROM2SHORT(0,0),
  471.              MPFROM2SHORT(0,360));
  472.             horizontal_scroll_position=0;
  473.             rotation=(double) (((short) 180)-horizontal_scroll_position);
  474.             hwndVscroll=WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),
  475.              FID_VERTSCROLL);
  476.             WinSendMsg(hwndVscroll,SBM_SETSCROLLBAR,MPFROM2SHORT(60,0),
  477.              MPFROM2SHORT(0,90));
  478.             vertical_scroll_position=60;
  479.             tilt=(double) (((short) 90)-vertical_scroll_position);
  480.             solve_draw_or_clear=(int) 'D';
  481.             iMaxX=0;
  482.             iMaxY=0;
  483.             resized=FALSE;
  484.             plot_command=FALSE;
  485.             aspect_ratio=(HEIGHT_OF_SCREEN/WIDTH_OF_SCREEN)
  486.              /(((double) WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN))
  487.              /((double) WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN)));
  488.             color=(volatile unsigned char * volatile) NULL;
  489.             base_z=(volatile unsigned char * volatile) NULL;
  490.             x_division_index=(volatile int * volatile) NULL;
  491.             x_prime=(volatile float * volatile) NULL;
  492.             y_division_index=(volatile int * volatile) NULL;
  493.             y_prime=(volatile float * volatile) NULL;
  494.             z_prime=(volatile float * volatile) NULL;
  495.             base_page=(volatile char * volatile * volatile) NULL;
  496.             page=(volatile char * volatile * volatile) NULL;
  497.             stack=(volatile stack_rec * volatile) NULL;
  498.             break;
  499.           case WM_HSCROLL:
  500.             switch (SHORT2FROMMP(mp2))
  501.               {
  502.                 case SB_LINELEFT:
  503.                   horizontal_scroll_position--;
  504.                   break;
  505.                 case SB_LINERIGHT:
  506.                   horizontal_scroll_position++;
  507.                   break;
  508.                 case SB_PAGELEFT:
  509.                   horizontal_scroll_position=
  510.                    (volatile short) (((int) horizontal_scroll_position)-10);
  511.                   break;
  512.                 case SB_PAGERIGHT:
  513.                   horizontal_scroll_position=
  514.                    (volatile short) (((int) horizontal_scroll_position)+10);
  515.                   break;
  516.                 case SB_SLIDERPOSITION:
  517.                   horizontal_scroll_position=(volatile short) SHORT1FROMMP(mp2);
  518.                 case SB_ENDSCROLL:
  519.                   plot_command=TRUE;
  520.                   DosQueryEventSem((HEV) plot_active,(PULONG) &plotting);
  521.                   if (plotting == (ULONG) 0)
  522.                     plot_kill=TRUE;
  523.                   DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  524.                   if (sizing == (ULONG) 0)
  525.                     {
  526.                       size_maze_kill=TRUE;
  527.                       DosWaitEventSem((HEV) size_maze_active,
  528.                        (ULONG) SEM_INDEFINITE_WAIT);
  529.                     }
  530.                   if (plot_kill)
  531.                     {
  532.                       DosWaitEventSem((HEV) plot_active,
  533.                        (ULONG) SEM_INDEFINITE_WAIT);
  534.                       WinEndPaint(hPS);
  535.                     }
  536.                   rotation=(double) (((short) 180)-horizontal_scroll_position);
  537.                   if ((2*(2*iMaxX/(3*PIXELS_PER_ROOM)-1)+1 > 2)
  538.                   &&  (((2.0/sqrt(3.0))*aspect_ratio*((double) iMaxY)
  539.                    /((double) PIXELS_PER_ROOM)) > 2.0))
  540.                    {
  541.                       DosResetEventSem((HEV) size_maze_active,
  542.                        (PULONG) &size_maze_post_count);
  543.                       size_maze_kill=FALSE;
  544.                       _beginthread(size_maze,(void *) NULL,16384,(void *) NULL);
  545.                     }
  546.                   switch (solve_draw_or_clear)
  547.                     {
  548.                       case 'C':
  549.                         solve_draw_or_clear='D';
  550.                         break;
  551.                       case 'S':
  552.                         solve_draw_or_clear='B';
  553.                         break;
  554.                       default:
  555.                         break;
  556.                     }
  557.                   WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) FALSE);
  558.                   break;
  559.                 default:
  560.                   break;
  561.               }
  562.             horizontal_scroll_position=(volatile short)
  563.              max(0,min(horizontal_scroll_position,360));
  564.             if (horizontal_scroll_position
  565.              != SHORT1FROMMR(WinSendMsg(hwndHscroll,SBM_QUERYPOS,NULL,NULL)))
  566.               WinSendMsg(hwndHscroll,SBM_SETPOS,
  567.                MPFROMSHORT(horizontal_scroll_position),NULL);
  568.             break;
  569.           case WM_VSCROLL:
  570.             switch (SHORT2FROMMP(mp2))
  571.               {
  572.                 case SB_LINEUP:
  573.                   vertical_scroll_position--;
  574.                   break;
  575.                 case SB_LINEDOWN:
  576.                   vertical_scroll_position++;
  577.                   break;
  578.                 case SB_PAGEUP:
  579.                   vertical_scroll_position=
  580.                    (volatile short) (((int) vertical_scroll_position)-10);
  581.                   break;
  582.                 case SB_PAGEDOWN:
  583.                   vertical_scroll_position=
  584.                    (volatile short) (((int) vertical_scroll_position)+10);
  585.                   break;
  586.                 case SB_SLIDERPOSITION:
  587.                   vertical_scroll_position=(volatile short) SHORT1FROMMP(mp2);
  588.                 case SB_ENDSCROLL:
  589.                   plot_command=TRUE;
  590.                   DosQueryEventSem((HEV) plot_active,(PULONG) &plotting);
  591.                   if (plotting == (ULONG) 0)
  592.                     plot_kill=TRUE;
  593.                   DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  594.                   if (sizing == (ULONG) 0)
  595.                     {
  596.                       size_maze_kill=TRUE;
  597.                       DosWaitEventSem((HEV) size_maze_active,
  598.                        (ULONG) SEM_INDEFINITE_WAIT);
  599.                     }
  600.                   if (plot_kill)
  601.                     {
  602.                       DosWaitEventSem((HEV) plot_active,
  603.                        (ULONG) SEM_INDEFINITE_WAIT);
  604.                       WinEndPaint(hPS);
  605.                     }
  606.                   tilt=(double) (((short) 90)-vertical_scroll_position);
  607.                   if ((2*(2*iMaxX/(3*PIXELS_PER_ROOM)-1)+1 > 2)
  608.                   &&  (((2.0/sqrt(3.0))*aspect_ratio*((double) iMaxY)
  609.                    /((double) PIXELS_PER_ROOM)) > 2.0))
  610.                     {
  611.                       DosResetEventSem((HEV) size_maze_active,
  612.                        (PULONG) &size_maze_post_count);
  613.                       size_maze_kill=FALSE;
  614.                       _beginthread(size_maze,(void *) NULL,16384,(void *) NULL);
  615.                     }
  616.                   switch (solve_draw_or_clear)
  617.                     {
  618.                       case 'C':
  619.                         solve_draw_or_clear='D';
  620.                         break;
  621.                       case 'S':
  622.                         solve_draw_or_clear='B';
  623.                         break;
  624.                       default:
  625.                         break;
  626.                     }
  627.                   WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) FALSE);
  628.                   break;
  629.                 default:
  630.                   break;
  631.               }
  632.             vertical_scroll_position=(volatile short)
  633.              max(0,min(vertical_scroll_position,90));
  634.             if (vertical_scroll_position
  635.              != SHORT1FROMMR(WinSendMsg(hwndVscroll,SBM_QUERYPOS,NULL,NULL)))
  636.               WinSendMsg(hwndVscroll,SBM_SETPOS,
  637.                MPFROMSHORT(vertical_scroll_position),NULL);
  638.             break;
  639.           case WM_COMMAND:
  640.             switch (COMMANDMSG(&msg)->cmd)
  641.               {
  642.                 case IDM_CLEAR:
  643.                   plot_command=TRUE;
  644.                   if (iFatalError)
  645.                     WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) FALSE);
  646.                   else
  647.                     {
  648.                       DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  649.                       DosQueryEventSem((HEV) plot_active,(PULONG) &plotting);
  650.                       if ((sizing == (ULONG) 0)
  651.                       ||  (plotting == (ULONG) 0))
  652.                         DosBeep((ULONG) 60,(ULONG) 333);
  653.                       else
  654.                         {
  655.                           solve_draw_or_clear=(int) 'C';
  656.                           WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) FALSE);
  657.                         }
  658.                     }
  659.                   break;
  660.                 case IDM_NEW:
  661.                   plot_command=TRUE;
  662.                   DosQueryEventSem((HEV) plot_active,(PULONG) &plotting);
  663.                   if (plotting == (ULONG) 0)
  664.                     plot_kill=TRUE;
  665.                   DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  666.                   if (sizing == (ULONG) 0)
  667.                     {
  668.                       size_maze_kill=TRUE;
  669.                       DosWaitEventSem((HEV) size_maze_active,
  670.                        (ULONG) SEM_INDEFINITE_WAIT);
  671.                     }
  672.                   if (plot_kill)
  673.                     {
  674.                       DosWaitEventSem((HEV) plot_active,
  675.                        (ULONG) SEM_INDEFINITE_WAIT);
  676.                       WinEndPaint(hPS);
  677.                     }
  678.                   if ((2*(2*iMaxX/(3*PIXELS_PER_ROOM)-1)+1 > 2)
  679.                   &&  (((2.0/sqrt(3.0))*aspect_ratio*((double) iMaxY)
  680.                    /((double) PIXELS_PER_ROOM)) > 2.0))
  681.                     {
  682.                       DosGetDateTime(&dateSeed);
  683.                       r_n_seed[0]=dateSeed.year%10;
  684.                       r_n_seed[1]=dateSeed.month%10;
  685.                       r_n_seed[2]=dateSeed.day%10;
  686.                       r_n_seed[3]=dateSeed.hours%10;
  687.                       r_n_seed[4]=dateSeed.minutes%10;
  688.                       r_n_seed[5]=dateSeed.seconds%10;
  689.                       r_n_seed[6]=dateSeed.hundredths%10;
  690.                       DosResetEventSem((HEV) size_maze_active,
  691.                        (PULONG) &size_maze_post_count);
  692.                       size_maze_kill=FALSE;
  693.                       _beginthread(size_maze,(void *) NULL,16384,(void *) NULL);
  694.                     }
  695.                   solve_draw_or_clear=(int) 'D';
  696.                   WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) FALSE);
  697.                   break;
  698.                 case IDM_SOLVE:
  699.                   plot_command=TRUE;
  700.                   if (iFatalError)
  701.                     WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) FALSE);
  702.                   else
  703.                     {
  704.                       DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  705.                       DosQueryEventSem((HEV) plot_active,(PULONG) &plotting);
  706.                       if ((sizing == (ULONG) 0)
  707.                       ||  (plotting == (ULONG) 0))
  708.                         DosBeep(60,333);
  709.                       else
  710.                         {
  711.                           if ((2*(2*iMaxX/(3*PIXELS_PER_ROOM)-1)+1 > 2)
  712.                           &&  (((2.0/sqrt(3.0))*aspect_ratio*((double) iMaxY)
  713.                           /((double) PIXELS_PER_ROOM)) > 2.0))
  714.                             solve_draw_or_clear=(int) 'S';
  715.                           WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) FALSE);
  716.                         }
  717.                     }
  718.                   break;
  719.                 case IDM_HELP:
  720.                   WinDlgBox(HWND_DESKTOP,hwnd,(PFNWP) help_proc,(HMODULE) 0,
  721.                    (ULONG) IDD_HELPBOX,(PVOID) NULL);
  722.                   break;
  723.                 default:
  724.                   break;
  725.               }
  726.             break;
  727.           case WM_SIZE:
  728.             DosQueryEventSem((HEV) plot_active,(PULONG) &plotting);
  729.             if (plotting == (ULONG) 0)
  730.               plot_kill=TRUE;
  731.             DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  732.             if (sizing == (ULONG) 0)
  733.               {
  734.                 size_maze_kill=TRUE;
  735.                 DosWaitEventSem((HEV) size_maze_active,
  736.                  (ULONG) SEM_INDEFINITE_WAIT);
  737.               }
  738.             if (plot_kill)
  739.               {
  740.                 DosWaitEventSem((HEV) plot_active,(ULONG) SEM_INDEFINITE_WAIT);
  741.                 WinEndPaint(hPS);
  742.               }
  743.             resized=TRUE;
  744.             solve_draw_or_clear=(int) 'D';
  745.             iMaxX=SHORT1FROMMP(mp2)-1;
  746.             iMaxY=SHORT2FROMMP(mp2)-1;
  747.             if ((2*(2*iMaxX/(3*PIXELS_PER_ROOM)-1)+1 > 2)
  748.             &&  (((2.0/sqrt(3.0))*aspect_ratio*((double) iMaxY)
  749.              /((double) PIXELS_PER_ROOM)) > 2.0))
  750.               {
  751.                 DosGetDateTime(&dateSeed);
  752.                 r_n_seed[0]=dateSeed.year%10;
  753.                 r_n_seed[1]=dateSeed.month%10;
  754.                 r_n_seed[2]=dateSeed.day%10;
  755.                 r_n_seed[3]=dateSeed.hours%10;
  756.                 r_n_seed[4]=dateSeed.minutes%10;
  757.                 r_n_seed[5]=dateSeed.seconds%10;
  758.                 r_n_seed[6]=dateSeed.hundredths%10;
  759.                 DosResetEventSem((HEV) size_maze_active,
  760.                  (PULONG) &size_maze_post_count);
  761.                 size_maze_kill=FALSE;
  762.                 _beginthread(size_maze,(void *) NULL,16384,(void *) NULL);
  763.               }
  764.             break;
  765.           case WM_ERASEBACKGROUND:
  766.             result=(MRESULT) TRUE; 
  767.             break;
  768.           case WM_PAINT:
  769.             DosQueryEventSem((HEV) plot_active,(PULONG) &plotting);
  770.             if (plotting == (ULONG) 0)
  771.               {
  772.                 plot_kill=TRUE;
  773.                 DosWaitEventSem((HEV) plot_active,(ULONG) SEM_INDEFINITE_WAIT);
  774.                 WinEndPaint(hPS);
  775.                 WinInvalidateRect(hwnd,(PRECTL) NULL,(BOOL) FALSE);
  776.               }
  777.             plot_hwnd=hwnd;
  778.             if ((2*(2*iMaxX/(3*PIXELS_PER_ROOM)-1)+1 > 2)
  779.             &&  (((2.0/sqrt(3.0))*aspect_ratio*((double) iMaxY)
  780.              /((double) PIXELS_PER_ROOM)) > 2.0))
  781.               {
  782.                 DosResetEventSem((HEV) plot_active,(PULONG) &plot_post_count);
  783.                 hPS=WinBeginPaint(hwnd,(HPS) NULL,(PRECTL) NULL);
  784.                 plot_kill=FALSE;
  785.                 if ((! resized) && (! plot_command))
  786.                   switch (solve_draw_or_clear)
  787.                     {
  788.                       case 'C':
  789.                         solve_draw_or_clear='D';
  790.                         break;
  791.                       case 'S':
  792.                         solve_draw_or_clear='B';
  793.                         break;
  794.                       default:
  795.                         break;
  796.                     }
  797.                 _beginthread(plot,(void *) NULL,16384,(void *) NULL);
  798.               }
  799.             resized=FALSE;
  800.             plot_command=FALSE;
  801.             break;
  802.           case WM_PLOT_DONE:
  803.             WinEndPaint(hPS);
  804.             break;
  805.           case WM_DESTROY:
  806.             DosQueryEventSem((HEV) plot_active,(PULONG) &plotting);
  807.             if (plotting == (ULONG) 0)
  808.               plot_kill=TRUE;
  809.             DosQueryEventSem((HEV) size_maze_active,(PULONG) &sizing);
  810.             if (sizing == (ULONG) 0)
  811.               {
  812.                 size_maze_kill=TRUE;
  813.                 DosWaitEventSem((HEV) size_maze_active,
  814.                  (ULONG) SEM_INDEFINITE_WAIT);
  815.               }
  816.             if (plot_kill)
  817.               {
  818.                 DosWaitEventSem((HEV) plot_active,(ULONG) SEM_INDEFINITE_WAIT);
  819.                 WinEndPaint(hPS);
  820.               }
  821.             destroy_maze(&x_prime,&y_prime,&z_prime,&x_division_index,
  822.              &y_division_index,&color,&base_z,&stack);
  823.             break;
  824.           default:
  825.             result=(MRESULT) WinDefWindowProc(hwnd,msg,mp1,mp2);
  826.             break;
  827.         }
  828.       return(result);
  829.     }
  830.  
  831. MRESULT EXPENTRY help_proc(
  832.   HWND   hwnd,
  833.   ULONG  msg,
  834.   MPARAM mp1,
  835.   MPARAM mp2)
  836.     {
  837.       MRESULT  result = (MRESULT) 0;
  838.  
  839.       switch (msg)
  840.         {
  841.           case WM_COMMAND:
  842.             switch (COMMANDMSG(&msg)->cmd)
  843.               {
  844.                 case DID_OK:
  845.                 case DID_CANCEL:
  846.                   WinDismissDlg(hwnd,(ULONG) TRUE);
  847.                   break;
  848.                 default:
  849.                   break;
  850.               }
  851.             break;
  852.           default:
  853.             result=(MRESULT) WinDefDlgProc(hwnd,msg,mp1,mp2);
  854.         }
  855.       return(result);
  856.     }
  857.   
  858. static void size_maze(
  859.   void *arg)
  860.     {
  861.       if (arg != (void *) NULL)
  862.         DosBeep((ULONG) 300,(ULONG) 300);
  863.       destroy_maze(&x_prime,&y_prime,&z_prime,&x_division_index,
  864.        &y_division_index,&color,&base_z,&stack);
  865.       num_columns=2*iMaxX/(3*PIXELS_PER_ROOM)-1;
  866.       num_columns=2*num_columns+1;
  867.       max_x=8*(num_columns/2)+6;
  868.       max_x_plus_1=max_x+1;
  869.       num_x_dots=RESOLUTION*max_x_plus_1;
  870.       x_dot_max=num_x_dots-1;
  871.       num_rows=(int) ((2.0/sqrt(3.0))*aspect_ratio*((double) iMaxY)
  872.        /((double) PIXELS_PER_ROOM));
  873.       max_y=4*num_rows;
  874.       max_y_plus_1=max_y+1;
  875.       num_y_dots=RESOLUTION*max_y_plus_1;
  876.       y_dot_max=num_y_dots-1;
  877.       num_rooms_in_maze=num_rows*num_columns-(num_columns/2);
  878.       num_x_divisions=num_y_dots+2;
  879.       num_y_divisions=num_x_dots+2;
  880.       num_primes=(long) num_x_divisions;
  881.       num_primes*=((long) num_y_divisions);
  882.       if (! size_maze_kill)
  883.         {
  884.           if (memory_allocated(num_primes,&x_prime,&y_prime,
  885.            &z_prime,&x_division_index,&y_division_index,&color,&base_z,
  886.            num_rooms_in_maze,&stack))
  887.             {
  888.               if (! size_maze_kill)
  889.                 generate_maze();
  890.               x_min=-1.0;
  891.               x_max=(double) num_y_dots;
  892.               y_min=-1.0;
  893.               y_max=(double) num_x_dots;
  894.               light.x=1.5;
  895.               light.y=-1.0;
  896.               light.z=2.6;
  897.               if (! size_maze_kill)
  898.                 evaluate_and_transform(x_min,x_max,y_min,y_max,num_x_divisions,
  899.                  num_y_divisions,rotation,tilt,x_prime,y_prime,z_prime,
  900.                  &x_prime_max,&y_prime_min,&y_prime_max,&z_prime_min,
  901.                  &z_prime_max,&light,x_division_index,y_division_index,base_z);
  902.               if (! size_maze_kill)
  903.                 shade(num_x_divisions,num_y_divisions,x_prime,y_prime,z_prime,
  904.                  color,&light);
  905.               if (! size_maze_kill)
  906.                 adjust_perspective(num_x_divisions,num_y_divisions,x_prime,
  907.                  y_prime,z_prime,x_prime_max,y_prime_min,y_prime_max,
  908.                  z_prime_min,z_prime_max);
  909.               if (! size_maze_kill)
  910.                 sort_back_to_front(num_primes,x_prime,x_division_index,
  911.                  y_division_index);
  912.             }
  913.           else
  914.             iFatalError=TRUE;
  915.         }
  916.       DosEnterCritSec();
  917.       DosPostEventSem((HEV) size_maze_active);
  918.       _endthread();
  919.     }
  920.  
  921. static int memory_allocated(
  922.   volatile long                     num_primes,
  923.   volatile float         * volatile *x_prime,
  924.   volatile float         * volatile *y_prime,
  925.   volatile float         * volatile *z_prime,
  926.   volatile int           * volatile *x_division_index,
  927.   volatile int           * volatile *y_division_index,
  928.   volatile unsigned char * volatile *color,
  929.   volatile unsigned char * volatile *base_z,
  930.   volatile int                      num_rooms_in_maze,
  931.   volatile stack_rec     * volatile *stack)
  932.     {
  933.                int result = 0;
  934.       register int y = 0;
  935.  
  936.       result=((base_page=(volatile char * volatile * volatile)
  937.        malloc(((unsigned int) max_y_plus_1)*sizeof(volatile char * volatile)))
  938.        != NULL);
  939.       if (result)
  940.         {
  941.           for (y=0; ((result) && (y < max_y_plus_1)); y++)
  942.             result=((base_page[y]=(volatile char * volatile)
  943.              malloc(((unsigned int) max_x_plus_1)*sizeof(volatile char)))
  944.              != NULL);
  945.           if (! result)
  946.             {
  947.               --y;
  948.               while (y > 0)
  949.                 free((void *) base_page[--y]);
  950.               free((void *) base_page);
  951.               base_page=(volatile char * volatile * volatile) NULL;
  952.             }
  953.         }
  954.       if (result)
  955.         {
  956.           result=((page=(volatile char * volatile * volatile)
  957.            malloc(((unsigned int) num_y_dots)*sizeof(volatile char * volatile)))
  958.            != NULL);
  959.           if (result)
  960.             {
  961.               for (y=0; ((result) && (y < num_y_dots)); y++)
  962.                 result=((page[y]=(volatile char * volatile)
  963.                  malloc(((unsigned int) num_x_dots)*sizeof(volatile char)))
  964.                  != NULL);
  965.               if (! result)
  966.                 {
  967.                   --y;
  968.                   while (y > 0)
  969.                     free((void *) page[--y]);
  970.                   free((void *) page);
  971.                   page=(volatile char * volatile * volatile) NULL;
  972.                   for (y=0; y < max_y_plus_1; y++)
  973.                     free((void *) base_page[y]);
  974.                   free((void *) base_page);
  975.                   base_page=(volatile char * volatile * volatile) NULL;
  976.                 }
  977.             }
  978.           else
  979.             {
  980.               for (y=0; y < max_y_plus_1; y++)
  981.                 free((void *) base_page[y]);
  982.               free((void *) base_page);
  983.               base_page=(volatile char * volatile * volatile) NULL;
  984.             }
  985.         }
  986.       if (result)
  987.         {
  988.           if (! (result=((*x_prime=(volatile float * volatile)
  989.            malloc(((unsigned int) num_primes)*sizeof(volatile float)))
  990.            != NULL)))
  991.             {
  992.               for (y=0; y < num_y_dots; y++)
  993.                 free((void *) page[y]);
  994.               free((void *) page);
  995.               page=(volatile char * volatile * volatile) NULL;
  996.               for (y=0; y < max_y_plus_1; y++)
  997.                 free((void *) base_page[y]);
  998.               free((void *) base_page);
  999.               base_page=(volatile char * volatile * volatile) NULL;
  1000.             }
  1001.         }
  1002.       if (result)
  1003.         {
  1004.           if (! (result=((*y_prime=(volatile float * volatile)
  1005.            malloc(((unsigned int) num_primes)*sizeof(volatile float)))
  1006.            != NULL)))
  1007.             {
  1008.               free((void *) *x_prime);
  1009.               *x_prime=(volatile float * volatile) NULL;
  1010.               for (y=0; y < num_y_dots; y++)
  1011.                 free((void *) page[y]);
  1012.               free((void *) page);
  1013.               page=(volatile char * volatile * volatile) NULL;
  1014.               for (y=0; y < max_y_plus_1; y++)
  1015.                 free((void *) base_page[y]);
  1016.               free((void *) base_page);
  1017.               base_page=(volatile char * volatile * volatile) NULL;
  1018.             }
  1019.         }
  1020.       if (result)
  1021.         {
  1022.           if (! (result=((*z_prime=(volatile float * volatile)
  1023.            malloc(((unsigned int) num_primes)*sizeof(volatile float)))
  1024.            != NULL)))
  1025.             {
  1026.               free((void *) *y_prime);
  1027.               *y_prime=(volatile float * volatile) NULL;
  1028.               free((void *) *x_prime);
  1029.               *x_prime=(volatile float * volatile) NULL;
  1030.               for (y=0; y < num_y_dots; y++)
  1031.                 free((void *) page[y]);
  1032.               free((void *) page);
  1033.               page=(volatile char * volatile * volatile) NULL;
  1034.               for (y=0; y < max_y_plus_1; y++)
  1035.                 free((void *) base_page[y]);
  1036.               free((void *) base_page);
  1037.               base_page=(volatile char * volatile * volatile) NULL;
  1038.             }
  1039.         }
  1040.       if (result)
  1041.         {
  1042.           if (! (result=((*x_division_index=(volatile int * volatile)
  1043.            malloc(((unsigned int) num_primes)*sizeof(volatile int))) != NULL)))
  1044.             {
  1045.               free((void *) *z_prime);
  1046.               *z_prime=(volatile float * volatile) NULL;
  1047.               free((void *) *y_prime);
  1048.               *y_prime=(volatile float * volatile) NULL;
  1049.               free((void *) *x_prime);
  1050.               *x_prime=(volatile float * volatile) NULL;
  1051.               for (y=0; y < num_y_dots; y++)
  1052.                 free((void *) page[y]);
  1053.               free((void *) page);
  1054.               page=(volatile char * volatile * volatile) NULL;
  1055.               for (y=0; y < max_y_plus_1; y++)
  1056.                 free((void *) base_page[y]);
  1057.               free((void *) base_page);
  1058.               base_page=(volatile char * volatile * volatile) NULL;
  1059.             }
  1060.         }
  1061.       if (result)
  1062.         {
  1063.           if (! (result=((*y_division_index=(volatile int * volatile)
  1064.            malloc(((unsigned int) num_primes)*sizeof(volatile int))) != NULL)))
  1065.             {
  1066.               free((void *) *x_division_index);
  1067.               *x_division_index=(volatile int * volatile) NULL;
  1068.               free((void *) *z_prime);
  1069.               *z_prime=(volatile float * volatile) NULL;
  1070.               free((void *) *y_prime);
  1071.               *y_prime=(volatile float * volatile) NULL;
  1072.               free((void *) *x_prime);
  1073.               *x_prime=(volatile float * volatile) NULL;
  1074.               for (y=0; y < num_y_dots; y++)
  1075.                 free((void *) page[y]);
  1076.               free((void *) page);
  1077.               page=(volatile char * volatile * volatile) NULL;
  1078.               for (y=0; y < max_y_plus_1; y++)
  1079.                 free((void *) base_page[y]);
  1080.               free((void *) base_page);
  1081.               base_page=(volatile char * volatile * volatile) NULL;
  1082.             }
  1083.         }
  1084.       if (result)
  1085.         {
  1086.           if (! (result=((*color=(volatile unsigned char * volatile) 
  1087.            malloc(((unsigned int) num_primes)*sizeof(volatile unsigned char)))
  1088.            != NULL)))
  1089.             {
  1090.               free((void *) *y_division_index);
  1091.               *y_division_index=(volatile int * volatile) NULL;
  1092.               free((void *) *x_division_index);
  1093.               *x_division_index=(volatile int * volatile) NULL;
  1094.               free((void *) *z_prime);
  1095.               *z_prime=(volatile float * volatile) NULL;
  1096.               free((void *) *y_prime);
  1097.               *y_prime=(volatile float * volatile) NULL;
  1098.               free((void *) *x_prime);
  1099.               *x_prime=(volatile float * volatile) NULL;
  1100.               for (y=0; y < num_y_dots; y++)
  1101.                 free((void *) page[y]);
  1102.               free((void *) page);
  1103.               page=(volatile char * volatile * volatile) NULL;
  1104.               for (y=0; y < max_y_plus_1; y++)
  1105.                 free((void *) base_page[y]);
  1106.               free((void *) base_page);
  1107.               base_page=(volatile char * volatile * volatile) NULL;
  1108.             }
  1109.         }
  1110.       if (result)
  1111.         {
  1112.           if (! (result=((*base_z=(volatile unsigned char * volatile) 
  1113.            malloc(((unsigned int) num_primes)*sizeof(volatile unsigned char)))
  1114.            != NULL)))
  1115.             {
  1116.               free((void *) *color);
  1117.               *color=(volatile unsigned char * volatile) NULL;
  1118.               free((void *) *y_division_index);
  1119.               *y_division_index=(volatile int * volatile) NULL;
  1120.               free((void *) *x_division_index);
  1121.               *x_division_index=(volatile int * volatile) NULL;
  1122.               free((void *) *z_prime);
  1123.               *z_prime=(volatile float * volatile) NULL;
  1124.               free((void *) *y_prime);
  1125.               *y_prime=(volatile float * volatile) NULL;
  1126.               free((void *) *x_prime);
  1127.               *x_prime=(volatile float * volatile) NULL;
  1128.               for (y=0; y < num_y_dots; y++)
  1129.                 free((void *) page[y]);
  1130.               free((void *) page);
  1131.               page=(volatile char * volatile * volatile) NULL;
  1132.               for (y=0; y < max_y_plus_1; y++)
  1133.                 free((void *) base_page[y]);
  1134.               free((void *) base_page);
  1135.               base_page=(volatile char * volatile * volatile) NULL;
  1136.             }
  1137.         }
  1138.       if (result)
  1139.         {
  1140.           if (! (result=((*stack=(volatile stack_rec * volatile) malloc(
  1141.            ((unsigned int) num_rooms_in_maze)*sizeof(volatile stack_rec)))
  1142.            != NULL)))
  1143.             {
  1144.               free((void *) *base_z);
  1145.               *base_z=(volatile unsigned char * volatile) NULL;
  1146.               free((void *) *color);
  1147.               *color=(volatile unsigned char * volatile) NULL;
  1148.               free((void *) *y_division_index);
  1149.               *y_division_index=(volatile int * volatile) NULL;
  1150.               free((void *) *x_division_index);
  1151.               *x_division_index=(volatile int * volatile) NULL;
  1152.               free((void *) *z_prime);
  1153.               *z_prime=(volatile float * volatile) NULL;
  1154.               free((void *) *y_prime);
  1155.               *y_prime=(volatile float * volatile) NULL;
  1156.               free((void *) *x_prime);
  1157.               *x_prime=(volatile float * volatile) NULL;
  1158.               for (y=0; y < num_y_dots; y++)
  1159.                 free((void *) page[y]);
  1160.               free((void *) page);
  1161.               page=(volatile char * volatile * volatile) NULL;
  1162.               for (y=0; y < max_y_plus_1; y++)
  1163.                 free((void *) base_page[y]);
  1164.               free((void *) base_page);
  1165.               base_page=(volatile char * volatile * volatile) NULL;
  1166.             }
  1167.         }
  1168.       return(result);
  1169.     }
  1170.  
  1171. static void set_point_on_page(
  1172.   int x,
  1173.   int y)
  1174.     {
  1175.       int x_offset = 0;
  1176.       int x_out = 0;
  1177.       int y_offset = 0;
  1178.       int y_out = 0;
  1179.  
  1180.       for (x_offset = 0; x_offset < RESOLUTION; x_offset++)
  1181.         {
  1182.           x_out=x+x_offset;
  1183.           for (y_offset=0; y_offset < RESOLUTION; y_offset++)
  1184.             {
  1185.               y_out=y+y_offset;
  1186.               page[y_out][x_out]='W';
  1187.             }
  1188.         }
  1189.       return;
  1190.     }
  1191.  
  1192.  
  1193. static void draw_line_on_page(
  1194.   int x1,
  1195.   int y1,
  1196.   int x2,
  1197.   int y2)
  1198.     {
  1199.       int error = 0;
  1200.       int error_prime_x = 0;
  1201.       int error_prime_y = 0;
  1202.       int permissible_delta_x = 0;
  1203.       int permissible_delta_y = 0;
  1204.       int x = 0;
  1205.       int x_diff = 0;
  1206.       int y = 0;
  1207.       int y_diff = 0;
  1208.  
  1209.       if (x2 >= x1)
  1210.         permissible_delta_x=1;
  1211.       else
  1212.         permissible_delta_x=-1;
  1213.       if (y2 >= y1)
  1214.         permissible_delta_y=1;
  1215.       else
  1216.         permissible_delta_y=-1;
  1217.       x=x1;
  1218.       y=y1;
  1219.       x_diff=x2-x1;
  1220.       y_diff=y2-y1;
  1221.       set_point_on_page(x,y);
  1222.       while ((x != x2) || (y != y2))
  1223.         {
  1224.           error_prime_x=error+permissible_delta_x*y_diff;
  1225.           error_prime_y=error-permissible_delta_y*x_diff;
  1226.           if (abs(error_prime_x) <= abs(error_prime_y)) 
  1227.             {
  1228.               x+=permissible_delta_x;
  1229.               error=error_prime_x;
  1230.             } 
  1231.           else
  1232.             {
  1233.               y+=permissible_delta_y;
  1234.               error=error_prime_y;
  1235.             }
  1236.           set_point_on_page(x,y);
  1237.         }
  1238.       return;
  1239.     } 
  1240.  
  1241. static void solve_maze(
  1242.   volatile stack_rec * volatile            stack,
  1243.   volatile char      * volatile * volatile base_page,
  1244.            int                  *          num_rooms_in_solution,
  1245.            int                  *          adjacency,
  1246.   volatile int                             max_x,
  1247.   volatile int                             max_y)
  1248.     {
  1249.       int delta_index=0;
  1250.       int passage_found=0;
  1251.       int stack_head=-1;
  1252.       int x=3;
  1253.       int x_next=0;
  1254.       int y=2;
  1255.       int y_next=0;
  1256.  
  1257.       *num_rooms_in_solution=1;
  1258.       *adjacency=0;
  1259.       x=3;
  1260.       y=2;
  1261.       stack_head=-1;
  1262.       base_page[y][x]='S';
  1263.       do
  1264.         {
  1265.           delta_index=0;
  1266.           passage_found=FALSE;
  1267.           do
  1268.             {
  1269.               while ((delta_index < 6) && (! passage_found))
  1270.                 {
  1271.                   x_next=x+delta_x[delta_index][0];
  1272.                   y_next=y+delta_y[delta_index][0];
  1273.                   if (base_page[y_next][x_next] == ' ')
  1274.                     passage_found=TRUE;
  1275.                   else
  1276.                     delta_index++;
  1277.                 }
  1278.               if (! passage_found) 
  1279.                 {
  1280.                   delta_index=(int) (stack[stack_head].index_1);
  1281.                   base_page[y][x]=' ';
  1282.                   x-=delta_x[delta_index][0];
  1283.                   y-=delta_y[delta_index][0];
  1284.                   base_page[y][x]=' ';
  1285.                   x-=delta_x[delta_index][0];
  1286.                   y-=delta_y[delta_index][0];
  1287.                   stack_head--;
  1288.                   delta_index++;
  1289.                 }
  1290.             }
  1291.           while (! passage_found);
  1292.           base_page[y_next][x_next]='S';
  1293.           x_next+=delta_x[delta_index][0];
  1294.           y_next+=delta_y[delta_index][0];
  1295.           if (y_next <= max_y) 
  1296.             {
  1297.               stack_head++;
  1298.               stack[stack_head].index_1=(char) delta_index;
  1299.               base_page[y_next][x_next]='S';
  1300.               x=x_next;
  1301.               y=y_next;
  1302.             }
  1303.         }
  1304.       while (y_next < max_y);
  1305.       x=max_x-3;
  1306.       y=max_y-2;
  1307.       *adjacency=0;
  1308.       while (stack_head >= 0)
  1309.         {
  1310.           for (delta_index=0; delta_index < 6; delta_index++)
  1311.             {
  1312.               x_next=x+delta_x[delta_index][0];
  1313.               y_next=y+delta_y[delta_index][0];
  1314.               if (base_page[y_next][x_next] != 'S')
  1315.                 {
  1316.                   if (base_page[y_next][x_next] == 'W')
  1317.                     {
  1318.                       x_next+=delta_x[delta_index][0];
  1319.                       y_next+=delta_y[delta_index][0];
  1320.                       if (x_next < 0)
  1321.                         (*adjacency)++;
  1322.                       else
  1323.                         if (x_next > max_x)
  1324.                           (*adjacency)++;
  1325.                         else
  1326.                           if (y_next < 0)
  1327.                             (*adjacency)++;
  1328.                           else
  1329.                             if (y_next > max_y)
  1330.                               (*adjacency)++;
  1331.                             else
  1332.                               {
  1333.                                 if (base_page[y_next][x_next] == 'S')
  1334.                                   (*adjacency)++;
  1335.                               }
  1336.                     }
  1337.                 }
  1338.             }
  1339.           x-=(2*delta_x[stack[stack_head].index_1][0]);
  1340.           y-=(2*delta_y[stack[stack_head].index_1][0]);
  1341.           stack_head--;
  1342.           (*num_rooms_in_solution)++;
  1343.         }
  1344.       for (delta_index=0; delta_index < 6; delta_index++)
  1345.         {
  1346.           x_next=x+delta_x[delta_index][0];
  1347.           y_next=y+delta_y[delta_index][0];
  1348.           if (base_page[y_next][x_next] != ' ')
  1349.             {
  1350.               if (base_page[y_next][x_next] == 'W')
  1351.                 {
  1352.                   x_next+=delta_x[delta_index][0];
  1353.                   y_next+=delta_y[delta_index][0];
  1354.                   if (x_next < 0)
  1355.                     (*adjacency)++;
  1356.                   else
  1357.                     if (x_next > max_x)
  1358.                       (*adjacency)++;
  1359.                     else
  1360.                       if (y_next < 0)
  1361.                         (*adjacency)++;
  1362.                       else
  1363.                         if (y_next > max_y)
  1364.                           (*adjacency)++;
  1365.                         else
  1366.                           {
  1367.                             if (base_page[y_next][x_next] == 'S')
  1368.                               (*adjacency)++;
  1369.                           }
  1370.                 }
  1371.             }
  1372.         }
  1373.       return;
  1374.     }
  1375.  
  1376. static void generate_maze()
  1377.     {
  1378.                int       adjacency = 0;
  1379.                int       age = 3;
  1380.                int       column_num = 0;
  1381.                int       counter_0 = 0;
  1382.                int       counter_1 = 0;
  1383.                int       counter_2 = 0;
  1384.                int       counter_3 = 0;
  1385.                int       counter_4 = 0;
  1386.                int       counter_5 = 0;
  1387.                int       counter_6 = 0;
  1388.                int       counter_7 = 0;
  1389.                int       delta_index_1a = 0;
  1390.                int       delta_index_1b = 0;
  1391.                int       delta_index_1c = 0;
  1392.                int       delta_index_1d = 0;
  1393.                int       delta_index_1e = 0;
  1394.                int       delta_index_1f = 0;
  1395.                int       delta_index_2 = 0;
  1396.                int       num_rooms_in_solution = 0;
  1397.                int       passage_found = 0;
  1398.       register int       r_n_index_1 = 0;
  1399.       register int       r_n_index_2 = 0;
  1400.                int       row_num = 0;
  1401.                int       search_complete = 0;
  1402.                int       stack_head = 0;
  1403.                int       tem_int = 0;
  1404.                int       trial_num_mod_600 = 0;
  1405.                int       x = 0;
  1406.                int       x_mod_8 = 0;
  1407.                int       x_next = 0;
  1408.                int       y = 0;
  1409.                int       y_mod_4 = 0;
  1410.                int       y_next = 0;
  1411.                int       y_previous = 0;
  1412.  
  1413.       r_n[0]=r_n_seed[0];
  1414.       r_n[1]=r_n_seed[1];
  1415.       r_n[2]=r_n_seed[2];
  1416.       r_n[3]=r_n_seed[3];
  1417.       r_n[4]=r_n_seed[4];
  1418.       r_n[5]=r_n_seed[5];
  1419.       r_n[6]=r_n_seed[6];
  1420.       r_n[7]=0;
  1421.       counter_0=r_n[0];
  1422.       counter_1=r_n[1];
  1423.       counter_2=r_n[2];
  1424.       counter_3=r_n[3];
  1425.       counter_4=r_n[4];
  1426.       counter_5=r_n[5];
  1427.       counter_6=r_n[6];
  1428.       counter_7=r_n[7];
  1429.       hash(&counter_0,&counter_1,&counter_2,&counter_3,&counter_4,&counter_5,
  1430.        &counter_6,&counter_7);
  1431.       delta_y[0][0]=-1;
  1432.       delta_x[0][0]=-2;
  1433.       delta_y[1][0]=1;
  1434.       delta_x[1][0]=-2;
  1435.       delta_y[2][0]=-2;
  1436.       delta_x[2][0]=0;
  1437.       delta_y[3][0]=2;
  1438.       delta_x[3][0]=0;
  1439.       delta_y[4][0]=-1;
  1440.       delta_x[4][0]=2;
  1441.       delta_y[5][0]=1;
  1442.       delta_x[5][0]=2;
  1443.       delta_index_2=0;
  1444.       for (delta_index_1a=0; delta_index_1a < 6; delta_index_1a++)
  1445.         for (delta_index_1b=0; delta_index_1b < 6; delta_index_1b++)
  1446.           if (delta_index_1a != delta_index_1b)
  1447.            for (delta_index_1c=0; delta_index_1c < 6; delta_index_1c++)
  1448.              if ((delta_index_1a != delta_index_1c)
  1449.              &&  (delta_index_1b != delta_index_1c))
  1450.                for (delta_index_1d=0; delta_index_1d < 6; delta_index_1d++)
  1451.                   if ((delta_index_1a != delta_index_1d)
  1452.                   &&  (delta_index_1b != delta_index_1d)
  1453.                   &&  (delta_index_1c != delta_index_1d))
  1454.                     for (delta_index_1e=0; delta_index_1e < 6; 
  1455.                      delta_index_1e++)
  1456.                       if ((delta_index_1a != delta_index_1e)
  1457.                       &&  (delta_index_1b != delta_index_1e)
  1458.                       &&  (delta_index_1c != delta_index_1e)
  1459.                       &&  (delta_index_1d != delta_index_1e))
  1460.                         for (delta_index_1f=0; delta_index_1f < 6; 
  1461.                          delta_index_1f++) 
  1462.                           if ((delta_index_1a != delta_index_1f)
  1463.                           &&  (delta_index_1b != delta_index_1f)
  1464.                           &&  (delta_index_1c != delta_index_1f)
  1465.                           &&  (delta_index_1d != delta_index_1f)
  1466.                           &&  (delta_index_1e != delta_index_1f))
  1467.                             {
  1468.                               delta_x[delta_index_1a][delta_index_2]
  1469.                                =delta_x[0][0];
  1470.                               delta_y[delta_index_1a][delta_index_2]
  1471.                                =delta_y[0][0];
  1472.                               delta_x[delta_index_1b][delta_index_2]
  1473.                                =delta_x[1][0];
  1474.                               delta_y[delta_index_1b][delta_index_2]
  1475.                                =delta_y[1][0];
  1476.                               delta_x[delta_index_1c][delta_index_2]
  1477.                                =delta_x[2][0];
  1478.                               delta_y[delta_index_1c][delta_index_2]
  1479.                                =delta_y[2][0];
  1480.                               delta_x[delta_index_1d][delta_index_2]
  1481.                                =delta_x[3][0];
  1482.                               delta_y[delta_index_1d][delta_index_2]
  1483.                                =delta_y[3][0];
  1484.                               delta_x[delta_index_1e][delta_index_2]
  1485.                                =delta_x[4][0];
  1486.                               delta_y[delta_index_1e][delta_index_2]
  1487.                                =delta_y[4][0];
  1488.                               delta_x[delta_index_1f][delta_index_2]
  1489.                                =delta_x[5][0];
  1490.                               delta_y[delta_index_1f][delta_index_2]
  1491.                                =delta_y[5][0];
  1492.                               delta_index_2++;
  1493.                             };
  1494.       age=3;
  1495.       trial_num_mod_600=0;
  1496.       do
  1497.         {
  1498.           y_mod_4=1;
  1499.           for (y=0; y <= max_y; y++) 
  1500.             {
  1501.               if (y_mod_4 == 1)
  1502.                 {
  1503.                   x_mod_8=1;
  1504.                   for (x=0; x <= max_x; x++)
  1505.                     {
  1506.                       if (((x_mod_8 == 0)
  1507.                         && (y != 0)
  1508.                         && (y != max_y))
  1509.                       ||  (x_mod_8 == 3)
  1510.                       ||  (x_mod_8 == 4)
  1511.                       ||  (x_mod_8 == 5))
  1512.                         base_page[y][x]='W';
  1513.                       else
  1514.                         base_page[y][x]=' ';
  1515.                       x_mod_8++;
  1516.                       if (x_mod_8 >= 8)
  1517.                         x_mod_8=0;
  1518.                     }
  1519.                 } 
  1520.               else
  1521.                 {
  1522.                   if (y_mod_4 == 0 || y_mod_4 == 2)
  1523.                     {
  1524.                       x_mod_8=1;
  1525.                       for (x=0; x <= max_x; x++)
  1526.                         {
  1527.                           if ((x_mod_8 == 2) || (x_mod_8 == 6))
  1528.                             base_page[y][x]='W';
  1529.                           else
  1530.                             base_page[y][x]=' ';
  1531.                           x_mod_8++;
  1532.                           if (x_mod_8 >= 8)
  1533.                             x_mod_8 = 0;
  1534.                         }
  1535.                     }
  1536.                   else
  1537.                     {
  1538.                       x_mod_8=1;
  1539.                       for (x=0; x <= max_x; x++)
  1540.                         {
  1541.                           if ((x_mod_8 == 0)
  1542.                           ||  (x_mod_8 == 1)
  1543.                           ||  (x_mod_8 == 4)
  1544.                           ||  (x_mod_8 == 7))
  1545.                             base_page[y][x]='W';
  1546.                           else
  1547.                             base_page[y][x]=' ';
  1548.                           x_mod_8++;
  1549.                           if (x_mod_8 >= 8)
  1550.                             x_mod_8=0;
  1551.                       }
  1552.                     }
  1553.                 }
  1554.               y_mod_4++;
  1555.               if (y_mod_4 >= 4)
  1556.                 y_mod_4=0;
  1557.             }
  1558.           r_n[0]=counter_0+1;
  1559.           r_n[1]=counter_1+1;
  1560.           r_n[2]=counter_2+1;
  1561.           r_n[3]=counter_3+1;
  1562.           r_n[4]=counter_4+1;
  1563.           r_n[5]=counter_5+1;
  1564.           r_n[6]=counter_6+1;
  1565.           r_n[7]=counter_7+1;
  1566.           column_num=r_n[0];
  1567.           r_n_index_1=0;
  1568.           r_n_index_2=1;
  1569.           while (r_n_index_2 < 8)
  1570.             {
  1571.               tem_int=r_n[r_n_index_2];
  1572.               r_n[r_n_index_1]=tem_int;
  1573.               column_num+=tem_int;
  1574.               if (column_num >= 727)
  1575.                 column_num-=727;
  1576.               r_n_index_1=r_n_index_2;
  1577.               r_n_index_2++;
  1578.             }
  1579.           r_n[7]=column_num;
  1580.           column_num%=num_columns;
  1581.           x=4*column_num+3;
  1582.           row_num=r_n[0];
  1583.           r_n_index_1=0;
  1584.           r_n_index_2=1;
  1585.           while (r_n_index_2 < 8)
  1586.             {
  1587.               tem_int=r_n[r_n_index_2];
  1588.               r_n[r_n_index_1]=tem_int;
  1589.               row_num+=tem_int;
  1590.               if (row_num >= 727)
  1591.                 row_num-=727;
  1592.               r_n_index_1=r_n_index_2;
  1593.               r_n_index_2++;
  1594.             }
  1595.           r_n[7]=row_num;
  1596.           if (column_num%2)
  1597.             {
  1598.               row_num%=(num_rows-1);
  1599.               y=4*row_num+4;
  1600.             }
  1601.           else
  1602.             {
  1603.               row_num%=num_rows;
  1604.               y=4*row_num+2;
  1605.             }
  1606.           base_page[y][x]=' ';
  1607.           stack_head=-1;
  1608.           do
  1609.             {
  1610.               delta_index_1a=0;
  1611.               do
  1612.                 {
  1613.                   delta_index_2=r_n[0];
  1614.                   r_n_index_1=0;
  1615.                   r_n_index_2=1;
  1616.                   while (r_n_index_2 < 8)
  1617.                     {
  1618.                       tem_int=r_n[r_n_index_2];
  1619.                       r_n[r_n_index_1]=tem_int;
  1620.                       delta_index_2+=tem_int;
  1621.                       if (delta_index_2 >= 727)
  1622.                         delta_index_2-=727;
  1623.                       r_n_index_1=r_n_index_2;
  1624.                       r_n_index_2++;
  1625.                     }
  1626.                   r_n[7]=delta_index_2;
  1627.                 }
  1628.               while (delta_index_2 >= 720);
  1629.               passage_found=FALSE;
  1630.               search_complete=FALSE;
  1631.               while (! search_complete)
  1632.                 {
  1633.                   while ((delta_index_1a < 6) && (! passage_found))
  1634.                     {
  1635.                       x_next=x+2*delta_x[delta_index_1a][delta_index_2];
  1636.                       if (x_next <= 0)
  1637.                         delta_index_1a++;
  1638.                       else
  1639.                         if (x_next > max_x)
  1640.                           delta_index_1a++;
  1641.                         else
  1642.                           {
  1643.                             y_next=y+2*delta_y[delta_index_1a][delta_index_2];
  1644.                             if (y_next <= 0)
  1645.                               delta_index_1a++;
  1646.                             else
  1647.                               if (y_next > max_y)
  1648.                                 delta_index_1a++;
  1649.                               else
  1650.                                 if (base_page[y_next][x_next] == 'W')
  1651.                                   passage_found=TRUE;
  1652.                                 else
  1653.                                   delta_index_1a++;
  1654.                           }
  1655.                     }
  1656.                   if (! passage_found)
  1657.                     {
  1658.                       if (stack_head >= 0)
  1659.                         {
  1660.                           delta_index_1a=(int) (stack[stack_head].index_1);
  1661.                           delta_index_2=stack[stack_head].index_2;
  1662.                           x-=2*delta_x[delta_index_1a][delta_index_2];
  1663.                           y-=2*delta_y[delta_index_1a][delta_index_2];
  1664.                           stack_head--;
  1665.                           delta_index_1a++;
  1666.                         }
  1667.                     }
  1668.                   search_complete=((passage_found)
  1669.                    || ((stack_head == -1) && (delta_index_1a >= 6)));
  1670.                 }
  1671.               if (passage_found)
  1672.                 {
  1673.                   stack_head++;
  1674.                   stack[stack_head].index_1=(char) delta_index_1a;
  1675.                   stack[stack_head].index_2=delta_index_2;
  1676.                   base_page[y_next][x_next]=' ';
  1677.                   base_page[(y+y_next)/2][(x+x_next)/2]=' ';
  1678.                   x=x_next;
  1679.                   y=y_next;
  1680.                 }
  1681.             }
  1682.           while (stack_head != -1);
  1683.           base_page[0][3]='S';
  1684.           base_page[max_y][max_x-3]=' ';
  1685.           solve_maze(stack,base_page,&num_rooms_in_solution,&adjacency,max_x,
  1686.            max_y);
  1687.           increment(&counter_0,&counter_1,&counter_2,&counter_3,&counter_4,
  1688.            &counter_5,&counter_6,&counter_7);
  1689.           trial_num_mod_600++;
  1690.           if (trial_num_mod_600 >= 600)
  1691.             {
  1692.               trial_num_mod_600=0;
  1693.               age++;
  1694.             }
  1695.         }
  1696.       while ((! size_maze_kill)
  1697.       &&     ((3*num_rooms_in_solution < num_rooms_in_maze)
  1698.           ||  (2*adjacency > age*num_rooms_in_solution)));
  1699.       for (x = 0; x <= x_dot_max; x++) 
  1700.         for (y = 0; y <= y_dot_max; y++)
  1701.           page[y][x]=' ';
  1702.       y_previous=-1;
  1703.       y_next=1;
  1704.       for (y = 0; y <= max_y; y++)
  1705.         {
  1706.           x=0;
  1707.           for (x_next = 1; x_next <= max_x; x_next++)
  1708.             {
  1709.               if (base_page[y][x] == 'W')
  1710.                 {
  1711.                   if (base_page[y][x_next] == 'W')
  1712.                     draw_line_on_page(RESOLUTION*x,RESOLUTION*y,
  1713.                      RESOLUTION*x_next,RESOLUTION*y);
  1714.                   if (y_previous >= 0)
  1715.                     {
  1716.                       if (base_page[y_previous][x_next] == 'W')
  1717.                         draw_line_on_page(RESOLUTION*x,RESOLUTION*y,
  1718.                          RESOLUTION*x_next,RESOLUTION*y_previous);
  1719.                     }
  1720.                   if (y_next <= max_y) 
  1721.                     {
  1722.                       if (base_page[y_next][x_next] == 'W')
  1723.                         draw_line_on_page(RESOLUTION*x,RESOLUTION*y,
  1724.                          RESOLUTION*x_next,RESOLUTION*y_next);
  1725.                     }
  1726.                 }
  1727.               x=x_next;
  1728.             }
  1729.           y_previous=y;
  1730.           y_next++;
  1731.         }
  1732.       return;
  1733.     }
  1734.  
  1735. static int substitution_high [100] =
  1736.              { 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,
  1737.                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,
  1738.                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,
  1739.                3,7,7,1,9,4,0,5,6,6 
  1740.              };
  1741. static int substitution_low [100] =
  1742.              { 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,
  1743.                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,
  1744.                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,
  1745.                2,4,5,9,8,2,8,8,3,5 
  1746.              };
  1747. static void hash(
  1748.   int *counter_0,
  1749.   int *counter_1,
  1750.   int *counter_2,
  1751.   int *counter_3,
  1752.   int *counter_4,
  1753.   int *counter_5,
  1754.   int *counter_6,
  1755.   int *counter_7)
  1756.     {
  1757.       register int iteration = 0;
  1758.                int seed_0 = 0;
  1759.                int seed_1 = 0;
  1760.                int seed_2 = 0;
  1761.                int seed_3 = 0;
  1762.                int seed_4 = 0;
  1763.                int seed_5 = 0;
  1764.                int seed_6 = 0;
  1765.                int seed_7 = 0;
  1766.       register int substitution_index = 0;
  1767.                int tem_0 = 0;
  1768.                int tem_1 = 0;
  1769.                int tem_2 = 0;
  1770.  
  1771.       seed_0=(*counter_0);
  1772.       seed_1=(*counter_1);
  1773.       seed_2=(*counter_2);
  1774.       seed_3=(*counter_3);
  1775.       seed_4=(*counter_4);
  1776.       seed_5=(*counter_5);
  1777.       seed_6=(*counter_6);
  1778.       seed_7=(*counter_7);
  1779.       for (iteration=1; iteration <= 8; iteration++)
  1780.         {
  1781.           substitution_index=10*seed_1+seed_0;
  1782.           tem_0=substitution_low[substitution_index];
  1783.           tem_1=substitution_high[substitution_index];
  1784.           substitution_index=10*seed_3+seed_2;
  1785.           seed_0=substitution_low[substitution_index];
  1786.           tem_2=substitution_high[substitution_index];
  1787.           substitution_index=10*seed_5+seed_4;
  1788.           seed_2=substitution_low[substitution_index];
  1789.           seed_1=substitution_high[substitution_index];
  1790.           substitution_index=10*seed_7+seed_6;
  1791.           seed_5=substitution_low[substitution_index];
  1792.           seed_7=substitution_high[substitution_index];
  1793.           seed_3=tem_0;
  1794.           seed_6=tem_1;
  1795.           seed_4=tem_2;
  1796.         }
  1797.       (*counter_0)=seed_0;
  1798.       (*counter_1)=seed_1;
  1799.       (*counter_2)=seed_2;
  1800.       (*counter_3)=seed_3;
  1801.       (*counter_4)=seed_4;
  1802.       (*counter_5)=seed_5;
  1803.       (*counter_6)=seed_6;
  1804.       (*counter_7)=seed_7;
  1805.       return;
  1806.     }
  1807.  
  1808. static void increment(
  1809.   int *counter_0,
  1810.   int *counter_1,
  1811.   int *counter_2,
  1812.   int *counter_3,
  1813.   int *counter_4,
  1814.   int *counter_5,
  1815.   int *counter_6,
  1816.   int *counter_7)
  1817.     {
  1818.       register int tem = 0;
  1819.  
  1820.       tem=(*counter_0)+1;
  1821.       if (tem <= 9)
  1822.         (*counter_0)=tem;
  1823.       else
  1824.         {
  1825.           (*counter_0)=0;
  1826.           tem=(*counter_1)+1;
  1827.           if (tem <= 9)
  1828.             (*counter_1)=tem;
  1829.           else
  1830.             {
  1831.               (*counter_1)=0;
  1832.               tem=(*counter_2)+1;
  1833.               if (tem <= 9)
  1834.                 (*counter_2)=tem;
  1835.               else
  1836.                 {
  1837.                   (*counter_2)=0;
  1838.                   tem=(*counter_3)+1;
  1839.                   if (tem <= 9)
  1840.                     (*counter_3)=tem;
  1841.                   else
  1842.                     {
  1843.                       (*counter_3)=0;
  1844.                       tem=(*counter_4)+1;
  1845.                       if (tem <= 9)
  1846.                         (*counter_4)=tem;
  1847.                       else
  1848.                         {
  1849.                           (*counter_4)=0;
  1850.                           tem=(*counter_5)+1;
  1851.                           if (tem <= 9)
  1852.                             (*counter_5)=tem;
  1853.                           else
  1854.                             {
  1855.                               (*counter_5)=0;
  1856.                               tem=(*counter_6)+1;
  1857.                               if (tem <= 9)
  1858.                                 (*counter_6)=tem;
  1859.                               else
  1860.                                 {
  1861.                                   (*counter_6)=0;
  1862.                                   tem=(*counter_7)+1;
  1863.                                   if (tem <= 9)
  1864.                                     (*counter_7)=tem;
  1865.                                   else
  1866.                                     (*counter_7)=0;
  1867.                                 }
  1868.                             }
  1869.                         }
  1870.                     }
  1871.                 }
  1872.             }
  1873.         }
  1874.       return;
  1875.     }
  1876.  
  1877. static void evaluate_and_transform(
  1878.   volatile double                   x_min,
  1879.   volatile double                   x_max,
  1880.   volatile double                   y_min,
  1881.   volatile double                   y_max,
  1882.   volatile int                      num_x_divisions,
  1883.   volatile int                      num_y_divisions,
  1884.   volatile double                   rotation,
  1885.   volatile double                   tilt,
  1886.   volatile float         * volatile x_prime,
  1887.   volatile float         * volatile y_prime,
  1888.   volatile float         * volatile z_prime,
  1889.   volatile double        *          x_prime_max,
  1890.   volatile double        *          y_prime_min,
  1891.   volatile double        *          y_prime_max,
  1892.   volatile double        *          z_prime_min,
  1893.   volatile double        *          z_prime_max,
  1894.   volatile vertex_rec    *          light,
  1895.   volatile int           * volatile x_division_index,
  1896.   volatile int           * volatile y_division_index,
  1897.   volatile unsigned char * volatile base_z)
  1898.     {
  1899.                double cos_rotation = 0.0;
  1900.                double cos_tilt = 0.0;
  1901.                double magnitude = 0.0;
  1902.                long   prime_num = 0l;
  1903.                double radians = 0.0;
  1904.                double radians_per_degree = 0.0;
  1905.                double sin_rotation = 0.0;
  1906.                double sin_tilt = 0.0;
  1907.                double x = 0.0;
  1908.                double x_delta = 0.0;
  1909.       register int    x_division_num = 0;
  1910.                double x_rotated = 0.0;
  1911.                double y = 0.0;
  1912.                double y_delta = 0.0;
  1913.       register int    y_division_num = 0;
  1914.                double z = 0.0;
  1915.  
  1916.       radians_per_degree=atan(1.0)/45.0;
  1917.       radians=tilt*radians_per_degree;
  1918.       cos_tilt=cos(radians);
  1919.       sin_tilt=sin(radians);
  1920.       radians=rotation*radians_per_degree;
  1921.       cos_rotation=cos(radians);
  1922.       sin_rotation=sin(radians);
  1923.       z=fabs(f(x_min,y_min));
  1924.       x_rotated=x_min*cos_rotation+y_min*sin_rotation;
  1925.       *y_prime_min=-x_min*sin_rotation+y_min*cos_rotation;
  1926.       *z_prime_min=-x_rotated*sin_tilt+z*cos_tilt;
  1927.       *y_prime_max=*y_prime_min;
  1928.       *z_prime_max=*z_prime_min;
  1929.       *x_prime_max=x_rotated*cos_tilt+z*sin_tilt;
  1930.       x_delta=(double) (num_x_divisions-1);
  1931.       x_delta=(x_max-x_min)/x_delta;
  1932.       y_delta=(double) (num_y_divisions-1);
  1933.       y_delta=(y_max-y_min)/y_delta;
  1934.       x=x_min;
  1935.       prime_num=0l;
  1936.       for (x_division_num=0; 
  1937.        ((! size_maze_kill) && (x_division_num < num_x_divisions));
  1938.        x_division_num++)
  1939.         {
  1940.           y=y_min;
  1941.           for (y_division_num=0; 
  1942.            ((! size_maze_kill) && (y_division_num < num_y_divisions));
  1943.            y_division_num++)
  1944.             {
  1945.               z=f(x,y);
  1946.               if (z > 0.0)
  1947.                 base_z[prime_num]=(unsigned char) 1;
  1948.               else
  1949.                 if (z < 0.0)
  1950.                   base_z[prime_num]=(unsigned char) 2;
  1951.                 else
  1952.                   base_z[prime_num]=(unsigned char) 0;
  1953.               z=fabs(z);
  1954.               x_division_index[prime_num]=x_division_num;
  1955.               y_division_index[prime_num]=y_division_num;
  1956.               x_rotated=x*cos_rotation+y*sin_rotation;
  1957.               y_prime[prime_num]=(float) (-x*sin_rotation+y*cos_rotation);
  1958.               x_prime[prime_num]=(float) (x_rotated*cos_tilt+z*sin_tilt);
  1959.               z_prime[prime_num]=(float) (-x_rotated*sin_tilt+z*cos_tilt);
  1960.               if (((double) (x_prime[prime_num])) > *x_prime_max)
  1961.                 *x_prime_max=(double) (x_prime[prime_num]);
  1962.               if (((double) (y_prime[prime_num])) < *y_prime_min)
  1963.                 *y_prime_min=(double) (y_prime[prime_num]);
  1964.               if (((double) (y_prime[prime_num])) > *y_prime_max)
  1965.                 *y_prime_max=(double) (y_prime[prime_num]);
  1966.               if (((double) (z_prime[prime_num])) < *z_prime_min)
  1967.                 *z_prime_min=(double) (z_prime[prime_num]);
  1968.               if (((double) (z_prime[prime_num])) > *z_prime_max)
  1969.                 *z_prime_max=(double) (z_prime[prime_num]);
  1970.               y+=y_delta;
  1971.               prime_num++;
  1972.             }
  1973.           x+=x_delta;
  1974.         }
  1975.       if ((! size_maze_kill))
  1976.         {
  1977.           magnitude=(*light).x*(*light).x;
  1978.           magnitude+=((*light).y*(*light).y);
  1979.           magnitude+=((*light).z*(*light).z);
  1980.           magnitude=sqrt(magnitude);
  1981.           (*light).x/=magnitude;
  1982.           (*light).y/=magnitude;
  1983.           (*light).z/=magnitude;
  1984.         }
  1985.       return;
  1986.     }
  1987.  
  1988. static void shade(
  1989.   volatile int                            num_x_divisions,
  1990.   volatile int                            num_y_divisions,
  1991.   volatile float               * volatile x_prime,
  1992.   volatile float               * volatile y_prime,
  1993.   volatile float               * volatile z_prime,
  1994.   volatile unsigned char       * volatile color,
  1995.   volatile vertex_rec          *          light)
  1996.     {
  1997.                double     magnitude = 0.0;
  1998.                vertex_rec normal = {0.0,0.0,0.0};
  1999.                long       prime_num = 0l;
  2000.                vertex_rec vertex [4]
  2001.        = {{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0}};
  2002.       register int        x_division_num = 0;
  2003.       register int        y_division_num = 0;
  2004.  
  2005.       for (x_division_num=0;
  2006.        ((! size_maze_kill) && (x_division_num < num_x_divisions));
  2007.        x_division_num++)
  2008.         {
  2009.           for (y_division_num=0; 
  2010.            ((! size_maze_kill) && (y_division_num < num_y_divisions));
  2011.            y_division_num++)
  2012.             {
  2013.               vertex[0].x=(double) (x_prime[prime_num]);
  2014.               vertex[0].y=(double) (y_prime[prime_num]);
  2015.               vertex[0].z=(double) (z_prime[prime_num]);
  2016.               if (x_division_num < (num_x_divisions-1))
  2017.                 if (y_division_num < (num_y_divisions-1))
  2018.                   {
  2019.                     prime_num+=((long) num_y_divisions);
  2020.                     vertex[1].x=(double) (x_prime[prime_num]);
  2021.                     vertex[1].y=(double) (y_prime[prime_num]);
  2022.                     vertex[1].z=(double) (z_prime[prime_num]);
  2023.                     prime_num++;
  2024.                     vertex[2].x=(double) (x_prime[prime_num]);
  2025.                     vertex[2].y=(double) (y_prime[prime_num]);
  2026.                     vertex[2].z=(double) (z_prime[prime_num]);
  2027.                     prime_num-=((long) num_y_divisions);
  2028.                     vertex[3].x=(double) (x_prime[prime_num]);
  2029.                     vertex[3].y=(double) (y_prime[prime_num]);
  2030.                     vertex[3].z=(double) (z_prime[prime_num]);
  2031.                     prime_num--;
  2032.                   }
  2033.                 else
  2034.                   {
  2035.                     prime_num--;
  2036.                     vertex[1].x=(double) (x_prime[prime_num]);
  2037.                     vertex[1].y=(double) (y_prime[prime_num]);
  2038.                     vertex[1].z=(double) (z_prime[prime_num]);
  2039.                     prime_num+=((long) num_y_divisions);
  2040.                     vertex[2].x=(double) (x_prime[prime_num]);
  2041.                     vertex[2].y=(double) (y_prime[prime_num]);
  2042.                     vertex[2].z=(double) (z_prime[prime_num]);
  2043.                     prime_num++;
  2044.                     vertex[3].x=(double) (x_prime[prime_num]);
  2045.                     vertex[3].y=(double) (y_prime[prime_num]);
  2046.                     vertex[3].z=(double) (z_prime[prime_num]);
  2047.                     prime_num-=((long) num_y_divisions);
  2048.                   }
  2049.               else
  2050.                 if (y_division_num < (num_y_divisions-1))
  2051.                   {
  2052.                     prime_num++;
  2053.                     vertex[1].x=(double) (x_prime[prime_num]);
  2054.                     vertex[1].y=(double) (y_prime[prime_num]);
  2055.                     vertex[1].z=(double) (z_prime[prime_num]);
  2056.                     prime_num-=((long) num_y_divisions);
  2057.                     vertex[2].x=(double) (x_prime[prime_num]);
  2058.                     vertex[2].y=(double) (y_prime[prime_num]);
  2059.                     vertex[2].z=(double) (z_prime[prime_num]);
  2060.                     prime_num--;
  2061.                     vertex[3].x=(double) (x_prime[prime_num]);
  2062.                     vertex[3].y=(double) (y_prime[prime_num]);
  2063.                     vertex[3].z=(double) (z_prime[prime_num]);
  2064.                     prime_num+=((long) num_y_divisions);
  2065.                   }
  2066.                 else
  2067.                   {
  2068.                     prime_num-=((long) num_y_divisions);
  2069.                     vertex[1].x=(double) (x_prime[prime_num]);
  2070.                     vertex[1].y=(double) (y_prime[prime_num]);
  2071.                     vertex[1].z=(double) (z_prime[prime_num]);
  2072.                     prime_num--;
  2073.                     vertex[2].x=(double) (x_prime[prime_num]);
  2074.                     vertex[2].y=(double) (y_prime[prime_num]);
  2075.                     vertex[2].z=(double) (z_prime[prime_num]);
  2076.                     prime_num+=((long) num_y_divisions);
  2077.                     vertex[3].x=(double) (x_prime[prime_num]);
  2078.                     vertex[3].y=(double) (y_prime[prime_num]);
  2079.                     vertex[3].z=(double) (z_prime[prime_num]);
  2080.                     prime_num++;
  2081.                   }
  2082.               normal.x
  2083.                =(vertex[1].y-vertex[0].y)*(vertex[3].z-vertex[0].z)
  2084.                -(vertex[3].y-vertex[0].y)*(vertex[1].z-vertex[0].z)
  2085.                +(vertex[2].y-vertex[1].y)*(vertex[0].z-vertex[1].z)
  2086.                -(vertex[0].y-vertex[1].y)*(vertex[2].z-vertex[1].z)
  2087.                +(vertex[3].y-vertex[2].y)*(vertex[1].z-vertex[2].z)
  2088.                -(vertex[1].y-vertex[2].y)*(vertex[3].z-vertex[2].z)
  2089.                +(vertex[0].y-vertex[3].y)*(vertex[2].z-vertex[3].z)
  2090.                -(vertex[2].y-vertex[3].y)*(vertex[0].z-vertex[3].z);
  2091.               normal.y
  2092.                =(vertex[3].x-vertex[0].x)*(vertex[1].z-vertex[0].z)
  2093.                -(vertex[1].x-vertex[0].x)*(vertex[3].z-vertex[0].z)
  2094.                +(vertex[0].x-vertex[1].x)*(vertex[2].z-vertex[1].z)
  2095.                -(vertex[2].x-vertex[1].x)*(vertex[0].z-vertex[1].z)
  2096.                +(vertex[1].x-vertex[2].x)*(vertex[3].z-vertex[2].z)
  2097.                -(vertex[3].x-vertex[2].x)*(vertex[1].z-vertex[2].z)
  2098.                +(vertex[2].x-vertex[3].x)*(vertex[0].z-vertex[3].z)
  2099.                -(vertex[0].x-vertex[3].x)*(vertex[2].z-vertex[3].z);
  2100.               normal.z
  2101.                =(vertex[1].x-vertex[0].x)*(vertex[3].y-vertex[0].y)
  2102.                -(vertex[3].x-vertex[0].x)*(vertex[1].y-vertex[0].y)
  2103.                +(vertex[2].x-vertex[1].x)*(vertex[0].y-vertex[1].y)
  2104.                -(vertex[0].x-vertex[1].x)*(vertex[2].y-vertex[1].y)
  2105.                +(vertex[3].x-vertex[2].x)*(vertex[1].y-vertex[2].y)
  2106.                -(vertex[1].x-vertex[2].x)*(vertex[3].y-vertex[2].y)
  2107.                +(vertex[0].x-vertex[3].x)*(vertex[2].y-vertex[3].y)
  2108.                -(vertex[2].x-vertex[3].x)*(vertex[0].y-vertex[3].y);
  2109.               if (normal.x < 0.0)
  2110.                 color[prime_num]=NUM_COLORS;
  2111.               else
  2112.                 {
  2113.                   magnitude
  2114.                    =sqrt(normal.x*normal.x+normal.y*normal.y+normal.z*normal.z);
  2115.                   if (magnitude == 0.0)
  2116.                     color[prime_num]=(unsigned char) 0;
  2117.                   else
  2118.                     {
  2119.                       color[prime_num]
  2120.                        =(unsigned char) ((((float) (NUM_COLORS-1))/2.0)*(1.0
  2121.                        +((*light).x*normal.x+(*light).y*normal.y
  2122.                        +(*light).z*normal.z)/magnitude));
  2123.                       if (color[prime_num] >= (unsigned char) (NUM_COLORS-1))
  2124.                         color[prime_num]=(unsigned char) (NUM_COLORS-2);
  2125.                     }
  2126.                 }
  2127.               prime_num++;
  2128.             }
  2129.         }
  2130.       return;
  2131.     }
  2132.  
  2133. static void adjust_perspective(
  2134.   volatile int               num_x_divisions,
  2135.   volatile int               num_y_divisions,
  2136.   volatile float  * volatile x_prime,
  2137.   volatile float  * volatile y_prime,
  2138.   volatile float  * volatile z_prime,
  2139.   volatile double            x_prime_max,
  2140.   volatile double            y_prime_min,
  2141.   volatile double            y_prime_max,
  2142.   volatile double            z_prime_min,
  2143.   volatile double            z_prime_max)  
  2144.     {
  2145.                long       prime_num = 0l;
  2146.                vertex_rec vertex [4]
  2147.        = {{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0}};
  2148.       register int        x_division_num = 0;
  2149.                double     x_eye = 0.0;
  2150.                double     y_center = 0.0;
  2151.       register int        y_division_num = 0;
  2152.                double     z_center = 0.0;
  2153.  
  2154.       if ((y_prime_max-y_prime_min) > (z_prime_max-z_prime_min))
  2155.         x_eye=1.1*(y_prime_max-y_prime_min)+x_prime_max;
  2156.       else
  2157.         x_eye=1.1*(z_prime_max-z_prime_min)+x_prime_max;
  2158.       if (((y_prime_max-y_prime_min) > (z_prime_max-z_prime_min))
  2159.       ||  (z_prime_max != z_prime_min))
  2160.         {
  2161.           y_center=(y_prime_max+y_prime_min)/2.0;
  2162.           z_center=(z_prime_max+z_prime_min)/2.0;
  2163.           prime_num=0l;
  2164.           for (x_division_num=0; 
  2165.            ((! size_maze_kill) && (x_division_num < num_x_divisions));
  2166.            x_division_num++)
  2167.             {
  2168.               for (y_division_num=0; 
  2169.                ((! size_maze_kill) && (y_division_num < num_y_divisions));
  2170.                y_division_num++)
  2171.                 {
  2172.                   vertex[0].x=(double) (x_prime[prime_num]);
  2173.                   vertex[0].y=(double) (y_prime[prime_num]);
  2174.                   vertex[0].z=(double) (z_prime[prime_num]);
  2175.                   if (x_division_num < (num_x_divisions-1))
  2176.                     if (y_division_num < (num_y_divisions-1))
  2177.                       {
  2178.                         prime_num+=((long) num_y_divisions);
  2179.                         vertex[1].x=(double) (x_prime[prime_num]);
  2180.                         vertex[1].y=(double) (y_prime[prime_num]);
  2181.                         vertex[1].z=(double) (z_prime[prime_num]);
  2182.                         prime_num++;
  2183.                         vertex[2].x=(double) (x_prime[prime_num]);
  2184.                         vertex[2].y=(double) (y_prime[prime_num]);
  2185.                         vertex[2].z=(double) (z_prime[prime_num]);
  2186.                         prime_num-=((long) num_y_divisions);
  2187.                         vertex[3].x=(double) (x_prime[prime_num]);
  2188.                         vertex[3].y=(double) (y_prime[prime_num]);
  2189.                         vertex[3].z=(double) (z_prime[prime_num]);
  2190.                         prime_num--;
  2191.                       }
  2192.                     else
  2193.                       {
  2194.                         prime_num--;
  2195.                         vertex[1].x=(double) (x_prime[prime_num]);
  2196.                         vertex[1].y=(double) (y_prime[prime_num]);
  2197.                         vertex[1].z=(double) (z_prime[prime_num]);
  2198.                         prime_num+=((long) num_y_divisions);
  2199.                         vertex[2].x=(double) (x_prime[prime_num]);
  2200.                         vertex[2].y=(double) (y_prime[prime_num]);
  2201.                         vertex[2].z=(double) (z_prime[prime_num]);
  2202.                         prime_num++;
  2203.                         vertex[3].x=(double) (x_prime[prime_num]);
  2204.                         vertex[3].y=(double) (y_prime[prime_num]);
  2205.                         vertex[3].z=(double) (z_prime[prime_num]);
  2206.                         prime_num-=((long) num_y_divisions);
  2207.                       }
  2208.                   else
  2209.                     if (y_division_num < (num_y_divisions-1))
  2210.                       {
  2211.                         prime_num++;
  2212.                         vertex[1].x=(double) (x_prime[prime_num]);
  2213.                         vertex[1].y=(double) (y_prime[prime_num]);
  2214.                         vertex[1].z=(double) (z_prime[prime_num]);
  2215.                         prime_num-=((long) num_y_divisions);
  2216.                         vertex[2].x=(double) (x_prime[prime_num]);
  2217.                         vertex[2].y=(double) (y_prime[prime_num]);
  2218.                         vertex[2].z=(double) (z_prime[prime_num]);
  2219.                         prime_num--;
  2220.                         vertex[3].x=(double) (x_prime[prime_num]);
  2221.                         vertex[3].y=(double) (y_prime[prime_num]);
  2222.                         vertex[3].z=(double) (z_prime[prime_num]);
  2223.                         prime_num+=((long) num_y_divisions);
  2224.                       }
  2225.                     else
  2226.                       {
  2227.                         prime_num-=((long) num_y_divisions);
  2228.                         vertex[1].x=(double) (x_prime[prime_num]);
  2229.                         vertex[1].y=(double) (y_prime[prime_num]);
  2230.                         vertex[1].z=(double) (z_prime[prime_num]);
  2231.                         prime_num--;
  2232.                         vertex[2].x=(double) (x_prime[prime_num]);
  2233.                         vertex[2].y=(double) (y_prime[prime_num]);
  2234.                         vertex[2].z=(double) (z_prime[prime_num]);
  2235.                         prime_num+=((long) num_y_divisions);
  2236.                         vertex[3].x=(double) (x_prime[prime_num]);
  2237.                         vertex[3].y=(double) (y_prime[prime_num]);
  2238.                         vertex[3].z=(double) (z_prime[prime_num]);
  2239.                         prime_num++;
  2240.                       }
  2241.                   y_prime[prime_num]=(float) (y_center
  2242.                    +(vertex[0].y-y_center)*(x_eye-x_prime_max)
  2243.                    /(x_eye-vertex[0].x));
  2244.                   z_prime[prime_num]=(float) (z_center
  2245.                    +(vertex[0].z-z_center)*(x_eye-x_prime_max)
  2246.                    /(x_eye-vertex[0].x));
  2247.                   x_prime[prime_num]=(float)
  2248.                    (-(vertex[0].x+vertex[1].x+vertex[2].x+vertex[3].x)/4.0);
  2249.                   prime_num++;
  2250.                 }
  2251.             }
  2252.          }
  2253.       return;
  2254.     }
  2255.  
  2256. static void sort_back_to_front(
  2257.   volatile long             num_primes,
  2258.   volatile float * volatile x_prime,
  2259.   volatile int   * volatile x_division_index,
  2260.   volatile int   * volatile y_division_index)
  2261.     {
  2262.                int   finished = 0;
  2263.                long  key_index_1 = 0l;
  2264.                long  key_index_2 = 0l;
  2265.                long  left = 0l;
  2266.                long  right = 0l;
  2267.                float t1 = (float) 0.0;
  2268.       register int   t2 = 0;
  2269.       register int   t3 = 0;
  2270.  
  2271.       left=num_primes/((long) 2);
  2272.       right=num_primes-1l;
  2273.       t1=x_prime[0];
  2274.       t2=x_division_index[0];
  2275.       t3=y_division_index[0];
  2276.       while ((! size_maze_kill) && (right > 0l))
  2277.         {
  2278.           if (left > 0l)
  2279.             {
  2280.               left--;
  2281.               t1=x_prime[left];
  2282.               t2=x_division_index[left];
  2283.               t3=y_division_index[left];
  2284.             }
  2285.           else
  2286.             {
  2287.               t1=x_prime[right];
  2288.               t2=x_division_index[right];
  2289.               t3=y_division_index[right];
  2290.               x_prime[right]=x_prime[0];
  2291.               x_division_index[right]=x_division_index[0];
  2292.               y_division_index[right]=y_division_index[0];
  2293.               right--;
  2294.             }
  2295.           if (right > 0l)
  2296.             {
  2297.               finished=FALSE;
  2298.               key_index_2=left;
  2299.               while (! finished)
  2300.                 {
  2301.                   key_index_1=key_index_2;
  2302.                   key_index_2+=key_index_2;
  2303.                   key_index_2++;
  2304.                   if (key_index_2 > right)
  2305.                     finished=TRUE;
  2306.                   else
  2307.                     {
  2308.                       if (key_index_2 != right)
  2309.                         {
  2310.                           if (x_prime[key_index_2] > x_prime[key_index_2+1])
  2311.                             key_index_2++;
  2312.                         }
  2313.                       if (t1 <= x_prime[key_index_2])
  2314.                         finished=TRUE;
  2315.                       else
  2316.                         {
  2317.                           x_prime[key_index_1]=x_prime[key_index_2];
  2318.                           x_division_index[key_index_1]
  2319.                            =x_division_index[key_index_2];
  2320.                           y_division_index[key_index_1]
  2321.                            =y_division_index[key_index_2];
  2322.                         }
  2323.                     }
  2324.                 }
  2325.               x_prime[key_index_1]=t1;
  2326.               x_division_index[key_index_1]=t2;
  2327.               y_division_index[key_index_1]=t3;
  2328.             }
  2329.         }
  2330.       x_prime[0]=t1;
  2331.       x_division_index[0]=t2;
  2332.       y_division_index[0]=t3;
  2333.       return;
  2334.     }
  2335.  
  2336. static void plot(
  2337.   void *arg)
  2338.     {  
  2339.       POINTL     box [4] = {{0l,0l},{0l,0l},{0l,0l},{0l,0l}};
  2340.       int        box_num = 0;
  2341.       short      color_num = (short) 0;
  2342.       double     pixels_per_unit = 0.0;
  2343.       long       prime_num = 0l;
  2344.       POINTL     ptlPosition = { 0l,0l };
  2345.       long       rgb [NUM_COLORS] 
  2346.        = { 0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l,0l };
  2347.       long       rgb_increment = 0l;
  2348.       int        solution = 0;
  2349.       long       tint = 0l;
  2350.       vertex_rec vertex [4] 
  2351.        = {{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0},{0.0,0.0,0.0}};
  2352.       int        x_division_num = 0;
  2353.       long       x_prime_num = 0l;
  2354.       int        y_division_num = 0;
  2355.       double     y_offset = 0.0;
  2356.       double     y_out_max = 0.0;
  2357.       double     z_offset = 0.0;
  2358.       double     z_out_max = 0.0;
  2359.  
  2360.       if (arg != (void *) NULL)
  2361.         DosBeep((ULONG) 300,(ULONG) 300);
  2362.       DosWaitEventSem((HEV) size_maze_active,(ULONG) SEM_INDEFINITE_WAIT);
  2363.       if ((! plot_kill) && (iFatalError))
  2364.         {
  2365.           GpiSetColor(hPS,ERROR_COLOR);
  2366.           ptlPosition.x=0;
  2367.           ptlPosition.y=0;
  2368.           GpiMove(hPS,&ptlPosition);
  2369.           ptlPosition.x=iMaxX;
  2370.           ptlPosition.y=iMaxY;
  2371.           GpiBox(hPS,DRO_FILL,&ptlPosition,(long) 0,(long) 0);
  2372.           DosBeep(60,333);
  2373.         }
  2374.       else
  2375.         {
  2376.           if (! plot_kill)
  2377.             {
  2378.               if ((solve_draw_or_clear == ((int) 'D')) 
  2379.               ||  (solve_draw_or_clear == ((int) 'B')))
  2380.                 GpiErase(hPS);
  2381.               rgb_increment=0x111111;
  2382.               tint=0l;
  2383.               for (color_num=0; color_num < (NUM_COLORS-1); color_num++)
  2384.                 {
  2385.                   rgb[color_num]=tint;
  2386.                   tint+=rgb_increment;
  2387.                 }
  2388.               rgb[NUM_COLORS-1]=0xff0000;
  2389.               GpiCreateLogColorTable(hPS,LCOL_RESET,LCOLF_CONSECRGB,0L,16L,
  2390.                &rgb[0]);
  2391.             }
  2392.           if (! plot_kill)
  2393.             {
  2394.               y_out_max=(double) iMaxX;
  2395.               z_out_max=(double) iMaxY;
  2396.               if (aspect_ratio*z_out_max*(y_prime_max-y_prime_min)
  2397.                > y_out_max*(z_prime_max-z_prime_min))
  2398.                 {
  2399.                   pixels_per_unit
  2400.                    =y_out_max/(aspect_ratio*(y_prime_max-y_prime_min));
  2401.                   y_offset=0.0;
  2402.                   z_offset
  2403.                    =(z_out_max-pixels_per_unit*(z_prime_max-z_prime_min))/2.0;
  2404.                 }
  2405.               else
  2406.                 if (aspect_ratio*z_out_max*(y_prime_max-y_prime_min)
  2407.                  < y_out_max*(z_prime_max-z_prime_min))
  2408.                   {
  2409.                     pixels_per_unit=z_out_max/(z_prime_max-z_prime_min);
  2410.                     y_offset=(y_out_max
  2411.                      -aspect_ratio*pixels_per_unit*(y_prime_max-y_prime_min))/2.0;
  2412.                     z_offset=0.0;
  2413.                   }
  2414.                 else
  2415.                   {
  2416.                     pixels_per_unit=1.0;
  2417.                     y_offset=y_out_max/2.0;
  2418.                     z_offset=z_out_max/2.0;
  2419.                   }
  2420.             }
  2421.           for (x_prime_num=0l; ((! plot_kill) && (x_prime_num < num_primes));
  2422.            x_prime_num++)
  2423.             {
  2424.               x_division_num=x_division_index[x_prime_num];
  2425.               if (x_division_num < (num_x_divisions-1))
  2426.                 {
  2427.                   y_division_num=y_division_index[x_prime_num];
  2428.                   if (y_division_num < (num_y_divisions-1))
  2429.                     {
  2430.                       prime_num
  2431.                        =((long) num_y_divisions)*((long) x_division_num)
  2432.                        +((long) y_division_num);
  2433.                       color_num=(short) (color[prime_num]);
  2434.                       if (color_num < NUM_COLORS)
  2435.                         {
  2436.                           vertex[0].y=(double) (y_prime[prime_num]);
  2437.                           vertex[0].z=(double) (z_prime[prime_num]);
  2438.                           solution=(base_z[prime_num] == (unsigned char) 2);
  2439.                           prime_num+=((long) num_y_divisions);
  2440.                           vertex[1].y=(double) (y_prime[prime_num]);
  2441.                           vertex[1].z=(double) (z_prime[prime_num]);
  2442.                           if (solution)
  2443.                             solution=(base_z[prime_num] == (unsigned char) 2);
  2444.                           prime_num++;
  2445.                           vertex[2].y=(double) (y_prime[prime_num]);
  2446.                           vertex[2].z=(double) (z_prime[prime_num]);
  2447.                           if (solution)
  2448.                             solution=(base_z[prime_num] == (unsigned char) 2);
  2449.                           prime_num-=((long) num_y_divisions);
  2450.                           vertex[3].y=(double) (y_prime[prime_num]);
  2451.                           vertex[3].z=(double) (z_prime[prime_num]);
  2452.                           if (solution)
  2453.                             solution=(base_z[prime_num] == (unsigned char) 2);
  2454.                           if ((solve_draw_or_clear == ((int) 'D')) 
  2455.                           ||  (solve_draw_or_clear == ((int) 'B'))
  2456.                           ||  ((solve_draw_or_clear == ((int) 'S'))
  2457.                             && (solution))
  2458.                           ||  ((solve_draw_or_clear == ((int) 'C'))
  2459.                             && (solution)))
  2460.                             {
  2461.                               if ((solve_draw_or_clear == ((int) 'S'))
  2462.                               ||  ((solve_draw_or_clear == ((int) 'B'))
  2463.                                 && (solution)))
  2464.                                 color_num=(short) (NUM_COLORS-1);
  2465.                               for (box_num=0; box_num < 4; box_num++)
  2466.                                 {
  2467.                                   box[box_num].x=(long) (y_offset
  2468.                                    +pixels_per_unit*aspect_ratio
  2469.                                    *(vertex[box_num].y-y_prime_min));
  2470.                                   box[box_num].y=(long) (z_offset
  2471.                                    +pixels_per_unit
  2472.                                    *(vertex[box_num].z-z_prime_min));
  2473.                                 }
  2474.                               GpiBeginPath(hPS,1L);
  2475.                               ptlPosition.x=box[3].x;
  2476.                               ptlPosition.y=box[3].y;
  2477.                               GpiMove(hPS,&ptlPosition);
  2478.                               GpiPolyLine(hPS,4l,box);
  2479.                               GpiEndPath(hPS);
  2480.                               GpiSetColor(hPS,color_num);
  2481.                               GpiFillPath(hPS,1l,FPATH_ALTERNATE);
  2482.                             }
  2483.                         }
  2484.                     }
  2485.                 }
  2486.             }
  2487.         }
  2488.       DosEnterCritSec();
  2489.       if (! plot_kill)
  2490.         WinPostMsg(plot_hwnd,(ULONG) WM_PLOT_DONE,(MPARAM) NULL,
  2491.          (MPARAM) NULL);
  2492.       DosPostEventSem((HEV) plot_active);
  2493.       _endthread();
  2494.     }
  2495.  
  2496. static void destroy_maze(
  2497.   volatile float         * volatile *x_prime,
  2498.   volatile float         * volatile *y_prime,
  2499.   volatile float         * volatile *z_prime,
  2500.   volatile int           * volatile *x_division_index,
  2501.   volatile int           * volatile *y_division_index,
  2502.   volatile unsigned char * volatile *color,
  2503.   volatile unsigned char * volatile *base_z,
  2504.   volatile stack_rec     * volatile *stack)
  2505.     {
  2506.       int y = 0;
  2507.  
  2508.       if (*stack != (volatile stack_rec * volatile) NULL)
  2509.         {
  2510.           free((void *) *stack);
  2511.           *stack=(volatile stack_rec * volatile) NULL;
  2512.         }
  2513.       if (*base_z != (unsigned char * volatile) NULL)
  2514.         {
  2515.           free((void *) *base_z);
  2516.           *base_z=(volatile unsigned char * volatile) NULL;
  2517.         }
  2518.       if (*color != (unsigned char * volatile) NULL)
  2519.         {
  2520.           free((void *) *color);
  2521.           *color=(volatile unsigned char * volatile) NULL;
  2522.         }
  2523.       if (*y_division_index != (int * volatile) NULL)
  2524.         {
  2525.           free((void *) *y_division_index);
  2526.           *y_division_index=(volatile int * volatile) NULL;
  2527.         }
  2528.       if (*x_division_index != (int * volatile) NULL)
  2529.         {
  2530.           free((void *) *x_division_index);
  2531.           *x_division_index=(volatile int * volatile) NULL;
  2532.         }
  2533.       if (*z_prime != (float * volatile) NULL)
  2534.         {
  2535.           free((void *) *z_prime);
  2536.           *z_prime=(volatile float * volatile) NULL;
  2537.         }
  2538.       if (*y_prime != (float * volatile) NULL)
  2539.         {
  2540.           free((void *) *y_prime);
  2541.           *y_prime=(volatile float * volatile) NULL;
  2542.         }
  2543.       if (*x_prime != (float * volatile) NULL)
  2544.         {
  2545.           free((void *) *x_prime);
  2546.           *x_prime=(volatile float * volatile) NULL;
  2547.         }
  2548.       if (page != (char ** volatile) NULL)
  2549.         {
  2550.           for (y=0; y < num_y_dots; y++)
  2551.             free((void *) (page[y]));
  2552.           free((void *) page);
  2553.           page=(volatile char * volatile * volatile) NULL;
  2554.         }
  2555.       if (base_page != (char ** volatile) NULL)
  2556.         {
  2557.           for (y=0; y < max_y_plus_1; y++)
  2558.             free((void *) (base_page[y]));
  2559.           free((void *) base_page);
  2560.           base_page=(volatile char * volatile * volatile) NULL;
  2561.         }
  2562.       return;
  2563.     }
  2564.  
  2565. static double f(
  2566.   double x,
  2567.   double y)
  2568.     {
  2569.                int    base_x = 0;
  2570.                int    base_y = 0;
  2571.                int    solution = 0;
  2572.       register int    x_next = 0;
  2573.                int    x_offset = 0;
  2574.                int    x_out = 0;
  2575.       register int    y_next = 0;
  2576.                int    y_offset = 0;
  2577.                int    y_out = 0;
  2578.                double z = 0.0;
  2579.  
  2580.       y_out=(int) x;
  2581.       if (y_out < 0)
  2582.         z=0.0;
  2583.       else
  2584.         if (y_out > y_dot_max)
  2585.           z=0.0;
  2586.         else
  2587.           {
  2588.             x_out=(int) y;
  2589.             if (x_out < 0)
  2590.               z=0.0;
  2591.             else
  2592.               if (x_out > x_dot_max)
  2593.                 z=0.0;
  2594.               else
  2595.                 if (page[y_out][x_out] == 'W')
  2596.                   {
  2597.                     solution=FALSE;
  2598.                     base_x=x_out/RESOLUTION;
  2599.                     base_y=y_out/RESOLUTION;
  2600.                     for (y_offset=-4; ((! solution) && (y_offset <= 4));
  2601.                      y_offset++)
  2602.                       for (x_offset=-4; ((! solution) && (x_offset <= 4));
  2603.                        x_offset++)
  2604.                         if (abs(x_offset)+abs(y_offset) <= 4)
  2605.                           {
  2606.                             y_next=base_y+y_offset;
  2607.                             if ((y_next >= 0) && (y_next <= max_y))
  2608.                               {
  2609.                                 x_next=base_x+x_offset;
  2610.                                 if ((x_next >= 0) && (x_next <= max_x))
  2611.                                   {
  2612.                                      if (base_page[y_next][x_next] == 'S')
  2613.                                        solution=TRUE; 
  2614.                                   }
  2615.                               }
  2616.                           };
  2617.                     z=((double) (5*RESOLUTION));
  2618.                     if (solution)
  2619.                       z=-z;
  2620.                   }
  2621.                 else
  2622.                   z=0.0;
  2623.           }
  2624.       return(z);
  2625.     }
  2626.  
  2627.